Skip to content

Commit

Permalink
[Truffle] Remove options for Array storage types - they all work fine…
Browse files Browse the repository at this point in the history
… now.
  • Loading branch information
chrisseaton committed Sep 25, 2014
1 parent 8d2f6b3 commit 3297394
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ protected RubyContext getContext() {

public static class UninitializedArrayBuilderNode extends ArrayBuilderNode {

private boolean couldUseInteger = RubyContext.ARRAYS_INT;
private boolean couldUseLong = RubyContext.ARRAYS_LONG;
private boolean couldUseDouble = RubyContext.ARRAYS_DOUBLE;
private boolean couldUseInteger = true;
private boolean couldUseLong = true;
private boolean couldUseDouble = true;

public UninitializedArrayBuilderNode(RubyContext context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,4 @@ protected boolean areBothObject(RubyArray a, RubyArray b) {
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
}

protected boolean areIntArraysEnabled() {
return RubyContext.ARRAYS_INT;
}

}
32 changes: 5 additions & 27 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,7 @@ public IndexSetNode(IndexSetNode prev) {
@Specialization(guards = "isNull")
public Object setNullIntegerFixnum(RubyArray array, int index, int value, UndefinedPlaceholder unused) {
if (index == 0) {
if (RubyContext.ARRAYS_INT) {
array.setStore(new int[]{value}, 1);
} else if (RubyContext.ARRAYS_LONG) {
array.setStore(new long[]{value}, 1);
} else {
array.setStore(new Object[]{value}, 1);
}
array.setStore(new int[]{value}, 1);
} else {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
Expand All @@ -657,11 +651,7 @@ public Object setNullIntegerFixnum(RubyArray array, int index, int value, Undefi
@Specialization(guards = "isNull")
public Object setNullLongFixnum(RubyArray array, int index, long value, UndefinedPlaceholder unused) {
if (index == 0) {
if (RubyContext.ARRAYS_LONG) {
array.setStore(new long[]{value}, 1);
} else {
array.setStore(new Object[]{value}, 1);
}
array.setStore(new long[]{value}, 1);
} else {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -1798,7 +1788,7 @@ public RubyArray initialize(RubyArray array, int size, UndefinedPlaceholder defa
return initialize(array, size, NilPlaceholder.INSTANCE);
}

@Specialization(guards = "areIntArraysEnabled")
@Specialization
public RubyArray initialize(RubyArray array, int size, int defaultValue) {
final int[] store = new int[size];
Arrays.fill(store, defaultValue);
Expand Down Expand Up @@ -2599,25 +2589,13 @@ public PushNode(PushNode prev) {

@Specialization(guards = {"isNull", "isSingleIntegerFixnum"})
public RubyArray pushEmptySingleIntegerFixnum(RubyArray array, Object... values) {
if (RubyContext.ARRAYS_INT) {
array.setStore(new int[]{(int) values[0]}, 1);
} else if (RubyContext.ARRAYS_LONG) {
array.setStore(new long[]{(long) values[0]}, 1);
} else {
array.setStore(new Object[]{values[0]}, 1);
}

array.setStore(new int[]{(int) values[0]}, 1);
return array;
}

@Specialization(guards = {"isNull", "isSingleLongFixnum"})
public RubyArray pushEmptySingleIntegerLong(RubyArray array, Object... values) {
if (RubyContext.ARRAYS_LONG) {
array.setStore(new long[]{(long) values[0]}, 1);
} else {
array.setStore(new Object[]{values[0]}, 1);
}

array.setStore(new long[]{(long) values[0]}, 1);
return array;
}

Expand Down
28 changes: 5 additions & 23 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,31 +300,13 @@ public BytesNode(BytesNode prev) {
public RubyArray bytes(RubyString string) {
final byte[] bytes = string.getBytes().bytes();

if (RubyContext.ARRAYS_INT) {
final int[] store = new int[bytes.length];
final int[] store = new int[bytes.length];

for (int n = 0; n < store.length; n++) {
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
} else if (RubyContext.ARRAYS_LONG) {
final long[] store = new long[bytes.length];

for (int n = 0; n < store.length; n++) {
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
} else {
final Object[] store = new Object[bytes.length];

for (int n = 0; n < store.length; n++) {
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
for (int n = 0; n < store.length; n++) {
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
}
}

Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ public class RubyContext extends ExecutionContext {
public static final boolean TRACE = Options.TRUFFLE_TRACE.load();
public static final boolean OBJECTSPACE = Options.TRUFFLE_OBJECTSPACE.load();
public static final boolean EXCEPTIONS_PRINT_JAVA = Options.TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public static final boolean LITERALS_INT = Options.TRUFFLE_LITERALS_INT.load();
public static final int ARRAYS_UNINITIALIZED_SIZE = Options.TRUFFLE_ARRAYS_UNINITIALIZED_SIZE.load();
public static final boolean ARRAYS_INT = Options.TRUFFLE_ARRAYS_INT.load();
public static final boolean ARRAYS_LONG = Options.TRUFFLE_ARRAYS_LONG.load();
public static final boolean ARRAYS_DOUBLE = Options.TRUFFLE_ARRAYS_DOUBLE.load();
public static final boolean ARRAYS_OPTIMISTIC_LONG = Options.TRUFFLE_ARRAYS_OPTIMISTIC_LONG.load();
public static final int ARRAYS_SMALL = Options.TRUFFLE_ARRAYS_SMALL.load();
public static final int HASHES_SMALL = Options.TRUFFLE_HASHES_SMALL.load();
Expand Down
25 changes: 9 additions & 16 deletions core/src/main/java/org/jruby/truffle/runtime/core/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,17 @@ public static RubyArray fromObject(RubyClass arrayClass, Object object) {

final Object store;

if (object instanceof Integer && RubyContext.ARRAYS_INT) {
if (object instanceof Integer) {
store = new int[]{(int) object};
} else if (object instanceof Integer && RubyContext.ARRAYS_LONG) {
store = new long[]{(long) (int) object};
} else if (object instanceof RubyFixnum.IntegerFixnum && RubyContext.ARRAYS_INT) {
} else if (object instanceof RubyFixnum.IntegerFixnum) {
store = new int[]{((RubyFixnum.IntegerFixnum) object).getValue()};
} else if (object instanceof RubyFixnum.IntegerFixnum && RubyContext.ARRAYS_LONG) {
store = new long[]{(long) ((RubyFixnum.IntegerFixnum) object).getValue()};
} else if (object instanceof Long && RubyContext.ARRAYS_LONG) {
} else if (object instanceof Long) {
store = new long[]{(long) object};
} else if (object instanceof RubyFixnum.LongFixnum && RubyContext.ARRAYS_LONG) {
} else if (object instanceof RubyFixnum.LongFixnum) {
store = new long[]{((RubyFixnum.LongFixnum) object).getValue()};
} else if (object instanceof Double && RubyContext.ARRAYS_DOUBLE) {
} else if (object instanceof Double) {
store = new double[]{(double) object};
} else if (object instanceof RubyFloat && RubyContext.ARRAYS_DOUBLE) {
} else if (object instanceof RubyFloat) {
store = new double[]{((RubyFloat) object).getValue()};
} else {
store = new Object[]{object};
Expand All @@ -112,9 +108,9 @@ public static RubyArray fromObjects(RubyClass arrayClass, Object... objects) {
return fromObject(arrayClass, objects[0]);
}

boolean canUseInteger = RubyContext.ARRAYS_INT;
boolean canUseLong = RubyContext.ARRAYS_LONG;
boolean canUseDouble = RubyContext.ARRAYS_DOUBLE;
boolean canUseInteger = true;
boolean canUseLong = true;
boolean canUseDouble = true;

for (Object object : objects) {
if (object instanceof Integer) {
Expand Down Expand Up @@ -249,9 +245,6 @@ public void setStore(Object store, int size) {
assert !(store instanceof int[]) || size <= ((int[]) store).length;
assert !(store instanceof long[]) || size <= ((long[]) store).length;
assert !(store instanceof double[]) || size <= ((double[]) store).length;
assert !(store instanceof int[]) || RubyContext.ARRAYS_INT;
assert !(store instanceof long[]) || RubyContext.ARRAYS_LONG;
assert !(store instanceof double[]) || RubyContext.ARRAYS_DOUBLE;

// TODO: assert that an object array doesn't contain all primitives - performance warning?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public RubyNode visitFalseNode(org.jruby.ast.FalseNode node) {
public RubyNode visitFixnumNode(org.jruby.ast.FixnumNode node) {
final long value = node.getValue();

if (RubyFixnum.fitsIntoInteger(value) && RubyContext.LITERALS_INT) {
if (RubyFixnum.fitsIntoInteger(value)) {
return new FixnumLiteralNode.IntegerFixnumLiteralNode(context, translate(node.getPosition()), (int) value);
} else {
return new FixnumLiteralNode.LongFixnumLiteralNode(context, translate(node.getPosition()), value);
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_TRACE = bool(TRUFFLE, "truffle.trace", true, "Install trace probes needed for set_trace_func.");
public static final Option<Boolean> TRUFFLE_OBJECTSPACE = bool(TRUFFLE, "truffle.object_space", true, "Install safepoints needed for ObjectSpace.");
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_java", false, "Print Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Boolean> TRUFFLE_LITERALS_INT = bool(TRUFFLE, "truffle.literals.int", true, "Use int for Fixnum literals where possible.");
public static final Option<Integer> TRUFFLE_ARRAYS_UNINITIALIZED_SIZE = integer(TRUFFLE, "truffle.arrays.uninitialized_size", 32, "How large an array to allocate when we have no other information to go on.");
public static final Option<Boolean> TRUFFLE_ARRAYS_INT = bool(TRUFFLE, "truffle.arrays.int", true, "Use int[] for Fixnum Array storage where possible.");
public static final Option<Boolean> TRUFFLE_ARRAYS_LONG = bool(TRUFFLE, "truffle.arrays.long", true, "Use long[] for Fixnum Array storage where possible.");
public static final Option<Boolean> TRUFFLE_ARRAYS_DOUBLE = bool(TRUFFLE, "truffle.arrays.double", true, "Use double[] Float for Array storage where possible.");
public static final Option<Boolean> TRUFFLE_ARRAYS_OPTIMISTIC_LONG = bool(TRUFFLE, "truffle.arrays.optimistic.long", true, "If we allocate an int[] for an Array and it has been converted to a long[], directly allocate a long[] next time.");
public static final Option<Integer> TRUFFLE_ARRAYS_SMALL = integer(TRUFFLE, "truffle.arrays.small", 3, "Maximum size of an Array to consider small for optimisations.");
public static final Option<Integer> TRUFFLE_HASHES_SMALL = integer(TRUFFLE, "truffle.hashes.small", 3, "Maximum size of a Hash to consider small for optimisations.");
Expand Down

0 comments on commit 3297394

Please sign in to comment.