Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 91ec95faf278
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b36d85d9e42e
Choose a head ref
  • 16 commits
  • 33 files changed
  • 1 contributor

Commits on Mar 31, 2016

  1. Copy the full SHA
    44a40ef View commit details
  2. Copy the full SHA
    43f79d5 View commit details
  3. Copy the full SHA
    340be51 View commit details
  4. [Truffle] Shorten line.

    chrisseaton committed Mar 31, 2016
    Copy the full SHA
    f3e9cf6 View commit details
  5. Copy the full SHA
    aa7facc View commit details
  6. Copy the full SHA
    e7748f6 View commit details
  7. Copy the full SHA
    36869bf View commit details
  8. Copy the full SHA
    8bd3351 View commit details
  9. Copy the full SHA
    b5f1521 View commit details
  10. Copy the full SHA
    d8e3afb View commit details
  11. Copy the full SHA
    940886c View commit details
  12. Copy the full SHA
    e9b9dad View commit details
  13. Copy the full SHA
    bd936ba View commit details
  14. Copy the full SHA
    2a1cd71 View commit details
  15. Copy the full SHA
    8d07814 View commit details
  16. Copy the full SHA
    b36d85d View commit details
Showing with 372 additions and 384 deletions.
  1. +10 −64 truffle/src/main/java/org/jruby/truffle/core/format/FormatNode.java
  2. +0 −1 truffle/src/main/java/org/jruby/truffle/core/format/LiteralFormatNode.java
  3. +8 −7 ...rg/jruby/truffle/core/format/{write/bytes/Write8Node.java → convert/Integer16BigToBytesNode.java}
  4. +7 −8 ...ruffle/core/format/{write/bytes/Write16LittleNode.java → convert/Integer16LittleToBytesNode.java}
  5. +7 −8 ...ruby/truffle/core/format/{write/bytes/Write32BigNode.java → convert/Integer32BigToBytesNode.java}
  6. +7 −8 ...ruffle/core/format/{write/bytes/Write32LittleNode.java → convert/Integer32LittleToBytesNode.java}
  7. +9 −8 ...ruby/truffle/core/format/{write/bytes/Write64BigNode.java → convert/Integer64BigToBytesNode.java}
  8. +9 −8 ...ruffle/core/format/{write/bytes/Write64LittleNode.java → convert/Integer64LittleToBytesNode.java}
  9. +14 −14 truffle/src/main/java/org/jruby/truffle/core/format/convert/ToStringNode.java
  10. +54 −0 truffle/src/main/java/org/jruby/truffle/core/format/format/FormatFloatHumanReadableNode.java
  11. +49 −70 truffle/src/main/java/org/jruby/truffle/core/format/format/FormatFloatNode.java
  12. +33 −12 truffle/src/main/java/org/jruby/truffle/core/format/format/FormatIntegerNode.java
  13. +25 −16 truffle/src/main/java/org/jruby/truffle/core/format/pack/PackTreeBuilder.java
  14. +28 −18 truffle/src/main/java/org/jruby/truffle/core/format/printf/PrintfTreeBuilder.java
  15. +3 −2 truffle/src/main/java/org/jruby/truffle/core/format/read/array/ReadStringNode.java
  16. +8 −11 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadBase64StringNode.java
  17. +29 −14 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadBinaryStringNode.java
  18. +3 −5 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadBitStringNode.java
  19. +3 −4 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadHexStringNode.java
  20. +4 −4 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadMIMEStringNode.java
  21. +4 −9 truffle/src/main/java/org/jruby/truffle/core/format/read/bytes/ReadUUStringNode.java
  22. +0 −36 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/Write16BigNode.java
  23. +2 −2 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteBERNode.java
  24. +3 −3 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteBase64StringNode.java
  25. +5 −6 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteBinaryStringNode.java
  26. +7 −10 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteBitStringNode.java
  27. +15 −10 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteByteNode.java
  28. +1 −5 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteBytesNode.java
  29. +4 −5 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteHexStringNode.java
  30. +4 −4 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteMIMEStringNode.java
  31. +5 −6 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WritePaddedBytesNode.java
  32. +6 −6 truffle/src/main/java/org/jruby/truffle/core/format/write/bytes/WriteUUStringNode.java
  33. +6 −0 truffle/src/main/java/org/jruby/truffle/core/symbol/SymbolTable.java
74 changes: 10 additions & 64 deletions truffle/src/main/java/org/jruby/truffle/core/format/FormatNode.java
Original file line number Diff line number Diff line change
@@ -20,32 +20,25 @@
import org.jruby.truffle.core.array.ArrayUtils;
import org.jruby.truffle.core.format.exceptions.TooFewArgumentsException;
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.util.ByteList;

import java.util.Arrays;

/**
* The root of the pack nodes.
* <p>
* Contains methods to change the state of the parser which is stored in the
* frame.
*/
@ImportStatic(FormatGuards.class)
public abstract class FormatNode extends Node {

private final RubyContext context;

private final ConditionProfile writeMoreThanZeroBytes = ConditionProfile.createBinaryProfile();
private final ConditionProfile tooFewArgumentsProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile sourceRangeProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile codeRangeIncreasedProfile = ConditionProfile.createBinaryProfile();

public FormatNode(RubyContext context) {
this.context = context;
}

public abstract Object execute(VirtualFrame frame);

/**
* Get the length of the source array.
*/
public int getSourceLength(VirtualFrame frame) {
try {
return frame.getInt(FormatFrameDescriptor.SOURCE_LENGTH_SLOT);
@@ -54,9 +47,6 @@ public int getSourceLength(VirtualFrame frame) {
}
}

/**
* Get the current position we are reading from in the source array.
*/
protected int getSourcePosition(VirtualFrame frame) {
try {
return frame.getInt(FormatFrameDescriptor.SOURCE_POSITION_SLOT);
@@ -65,26 +55,18 @@ protected int getSourcePosition(VirtualFrame frame) {
}
}

/**
* Set the current position we will read from next in the source array.
*/
protected void setSourcePosition(VirtualFrame frame, int position) {
frame.setInt(FormatFrameDescriptor.SOURCE_POSITION_SLOT, position);
}

/**
* Advanced the position we are reading from in the source array by one
* element.
*/
protected int advanceSourcePosition(VirtualFrame frame) {
return advanceSourcePosition(frame, 1);
}

protected int advanceSourcePosition(VirtualFrame frame, int count) {
final int sourcePosition = getSourcePosition(frame);

if (sourcePosition + count > getSourceLength(frame)) {
CompilerDirectives.transferToInterpreter();
if (tooFewArgumentsProfile.profile(sourcePosition + count > getSourceLength(frame))) {
throw new TooFewArgumentsException();
}

@@ -102,7 +84,7 @@ protected int advanceSourcePositionNoThrow(VirtualFrame frame, int count, boolea

final int sourceLength = getSourceLength(frame);

if (sourcePosition + count > sourceLength) {
if (sourceRangeProfile.profile(sourcePosition + count > sourceLength)) {
if (consumePartial) {
setSourcePosition(frame, sourceLength);
}
@@ -115,9 +97,6 @@ protected int advanceSourcePositionNoThrow(VirtualFrame frame, int count, boolea
return sourcePosition;
}

/**
* Get the output array we are writing to.
*/
protected Object getOutput(VirtualFrame frame) {
try {
return frame.getObject(FormatFrameDescriptor.OUTPUT_SLOT);
@@ -126,19 +105,11 @@ protected Object getOutput(VirtualFrame frame) {
}
}

/**
* Set the output array we are writing to. This should never be used in the
* compiled code - having to change the output array to resize is is a
* deoptimizing action.
*/
protected void setOutput(VirtualFrame frame, Object output) {
CompilerAsserts.neverPartOfCompilation();
frame.setObject(FormatFrameDescriptor.OUTPUT_SLOT, output);
}

/**
* Get the current position we are writing to the in the output array.
*/
protected int getOutputPosition(VirtualFrame frame) {
try {
return frame.getInt(FormatFrameDescriptor.OUTPUT_POSITION_SLOT);
@@ -147,9 +118,6 @@ protected int getOutputPosition(VirtualFrame frame) {
}
}

/**
* Set the current position we are writing to in the output array.
*/
protected void setOutputPosition(VirtualFrame frame, int position) {
frame.setInt(FormatFrameDescriptor.OUTPUT_POSITION_SLOT, position);
}
@@ -174,61 +142,39 @@ protected void setStringCodeRange(VirtualFrame frame, CodeRange codeRange) {
try {
final int existingCodeRange = frame.getInt(FormatFrameDescriptor.STRING_CODE_RANGE_SLOT);

if (codeRange.toInt() > existingCodeRange) {
if (codeRangeIncreasedProfile.profile(codeRange.toInt() > existingCodeRange)) {
frame.setInt(FormatFrameDescriptor.STRING_CODE_RANGE_SLOT, codeRange.toInt());
}
} catch (FrameSlotTypeException e) {
throw new IllegalStateException(e);
}
}

/**
* Set the output to be tainted.
*/
protected void setTainted(VirtualFrame frame) {
frame.setBoolean(FormatFrameDescriptor.TAINT_SLOT, true);
}

/**
* Write a single byte.
*/
protected void writeByte(VirtualFrame frame, byte value) {
byte[] output = ensureCapacity(frame, 1);
final byte[] output = ensureCapacity(frame, 1);
final int outputPosition = getOutputPosition(frame);
output[outputPosition] = value;
setOutputPosition(frame, outputPosition + 1);
setStringCodeRange(frame, value >= 0 ? CodeRange.CR_7BIT : CodeRange.CR_VALID);
increaseStringLength(frame, 1);
}

/**
* Write an array of bytes to the output.
*/
protected void writeBytes(VirtualFrame frame, byte... values) {
writeBytes(frame, values, 0, values.length);
}

/**
* Write a {@link ByteList} to the output.
*/
protected void writeBytes(VirtualFrame frame, ByteList values) {
writeBytes(frame, values.getUnsafeBytes(), values.begin(), values.length());
writeBytes(frame, values, values.length);
}

/**
* Write a range of an array of bytes to the output.
*/
protected void writeBytes(VirtualFrame frame, byte[] values, int valuesStart, int valuesLength) {
protected void writeBytes(VirtualFrame frame, byte[] values, int valuesLength) {
byte[] output = ensureCapacity(frame, valuesLength);
final int outputPosition = getOutputPosition(frame);
System.arraycopy(values, valuesStart, output, outputPosition, valuesLength);
System.arraycopy(values, 0, output, outputPosition, valuesLength);
setOutputPosition(frame, outputPosition + valuesLength);
increaseStringLength(frame, valuesLength);
}

/**
* Write null bytes to the output.
*/
protected void writeNullBytes(VirtualFrame frame, int length) {
if (writeMoreThanZeroBytes.profile(length > 0)) {
ensureCapacity(frame, length);
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.util.ByteList;

public class LiteralFormatNode extends FormatNode {

Original file line number Diff line number Diff line change
@@ -7,28 +7,29 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.core.format.write.bytes;
package org.jruby.truffle.core.format.convert;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
})
public abstract class Write8Node extends FormatNode {
public abstract class Integer16BigToBytesNode extends FormatNode {

public Write8Node(RubyContext context) {
public Integer16BigToBytesNode(RubyContext context) {
super(context);
}

@Specialization
public Object doWrite(VirtualFrame frame, long value) {
writeByte(frame, (byte) value);
return null;
public byte[] encode(long value) {
return new byte[]{
(byte) (value >>> 8),
(byte) value
};
}

}
Original file line number Diff line number Diff line change
@@ -7,30 +7,29 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.core.format.write.bytes;
package org.jruby.truffle.core.format.convert;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
})
public abstract class Write16LittleNode extends FormatNode {
public abstract class Integer16LittleToBytesNode extends FormatNode {

public Write16LittleNode(RubyContext context) {
public Integer16LittleToBytesNode(RubyContext context) {
super(context);
}

@Specialization
public Object write(VirtualFrame frame, long value) {
writeBytes(frame,
public byte[] encode(long value) {
return new byte[]{
(byte) value,
(byte) (value >>> 8));
return null;
(byte) (value >>> 8)
};
}

}
Original file line number Diff line number Diff line change
@@ -7,32 +7,31 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.core.format.write.bytes;
package org.jruby.truffle.core.format.convert;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
})
public abstract class Write32BigNode extends FormatNode {
public abstract class Integer32BigToBytesNode extends FormatNode {

public Write32BigNode(RubyContext context) {
public Integer32BigToBytesNode(RubyContext context) {
super(context);
}

@Specialization
public Object write(VirtualFrame frame, long value) {
writeBytes(frame,
public byte[] encode(long value) {
return new byte[]{
(byte) (value >>> 24),
(byte) (value >>> 16),
(byte) (value >>> 8),
(byte) value);
return null;
(byte) value
};
}

}
Original file line number Diff line number Diff line change
@@ -7,32 +7,31 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.core.format.write.bytes;
package org.jruby.truffle.core.format.convert;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
})
public abstract class Write32LittleNode extends FormatNode {
public abstract class Integer32LittleToBytesNode extends FormatNode {

public Write32LittleNode(RubyContext context) {
public Integer32LittleToBytesNode(RubyContext context) {
super(context);
}

@Specialization
public Object write(VirtualFrame frame, long value) {
writeBytes(frame,
public byte[] encode(long value) {
return new byte[]{
(byte) value,
(byte) (value >>> 8),
(byte) (value >>> 16),
(byte) (value >>> 24));
return null;
(byte) (value >>> 24)
};
}

}
Original file line number Diff line number Diff line change
@@ -7,36 +7,37 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.core.format.write.bytes;
package org.jruby.truffle.core.format.convert;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.MissingValue;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
})
public abstract class Write64BigNode extends FormatNode {
public abstract class Integer64BigToBytesNode extends FormatNode {

public Write64BigNode(RubyContext context) {
public Integer64BigToBytesNode(RubyContext context) {
super(context);
}

@Specialization
public Object write(VirtualFrame frame, long value) {
writeBytes(frame,
public byte[] encode(long value) {
return new byte[]{
(byte) (value >>> 56),
(byte) (value >>> 48),
(byte) (value >>> 40),
(byte) (value >>> 32),
(byte) (value >>> 24),
(byte) (value >>> 16),
(byte) (value >>> 8),
(byte) value);
return null;
(byte) value
};
}

}
Loading