Skip to content

Commit 3297394

Browse files
committed
[Truffle] Remove options for Array storage types - they all work fine now.
1 parent 8d2f6b3 commit 3297394

File tree

8 files changed

+23
-82
lines changed

8 files changed

+23
-82
lines changed

core/src/main/java/org/jruby/truffle/nodes/core/ArrayBuilderNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ protected RubyContext getContext() {
4343

4444
public static class UninitializedArrayBuilderNode extends ArrayBuilderNode {
4545

46-
private boolean couldUseInteger = RubyContext.ARRAYS_INT;
47-
private boolean couldUseLong = RubyContext.ARRAYS_LONG;
48-
private boolean couldUseDouble = RubyContext.ARRAYS_DOUBLE;
46+
private boolean couldUseInteger = true;
47+
private boolean couldUseLong = true;
48+
private boolean couldUseDouble = true;
4949

5050
public UninitializedArrayBuilderNode(RubyContext context) {
5151
super(context);

core/src/main/java/org/jruby/truffle/nodes/core/ArrayCoreMethodNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,4 @@ protected boolean areBothObject(RubyArray a, RubyArray b) {
8484
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
8585
}
8686

87-
protected boolean areIntArraysEnabled() {
88-
return RubyContext.ARRAYS_INT;
89-
}
90-
9187
}

core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,7 @@ public IndexSetNode(IndexSetNode prev) {
639639
@Specialization(guards = "isNull")
640640
public Object setNullIntegerFixnum(RubyArray array, int index, int value, UndefinedPlaceholder unused) {
641641
if (index == 0) {
642-
if (RubyContext.ARRAYS_INT) {
643-
array.setStore(new int[]{value}, 1);
644-
} else if (RubyContext.ARRAYS_LONG) {
645-
array.setStore(new long[]{value}, 1);
646-
} else {
647-
array.setStore(new Object[]{value}, 1);
648-
}
642+
array.setStore(new int[]{value}, 1);
649643
} else {
650644
CompilerDirectives.transferToInterpreter();
651645
throw new UnsupportedOperationException();
@@ -657,11 +651,7 @@ public Object setNullIntegerFixnum(RubyArray array, int index, int value, Undefi
657651
@Specialization(guards = "isNull")
658652
public Object setNullLongFixnum(RubyArray array, int index, long value, UndefinedPlaceholder unused) {
659653
if (index == 0) {
660-
if (RubyContext.ARRAYS_LONG) {
661-
array.setStore(new long[]{value}, 1);
662-
} else {
663-
array.setStore(new Object[]{value}, 1);
664-
}
654+
array.setStore(new long[]{value}, 1);
665655
} else {
666656
CompilerDirectives.transferToInterpreter();
667657
throw new UnsupportedOperationException();
@@ -1798,7 +1788,7 @@ public RubyArray initialize(RubyArray array, int size, UndefinedPlaceholder defa
17981788
return initialize(array, size, NilPlaceholder.INSTANCE);
17991789
}
18001790

1801-
@Specialization(guards = "areIntArraysEnabled")
1791+
@Specialization
18021792
public RubyArray initialize(RubyArray array, int size, int defaultValue) {
18031793
final int[] store = new int[size];
18041794
Arrays.fill(store, defaultValue);
@@ -2599,25 +2589,13 @@ public PushNode(PushNode prev) {
25992589

26002590
@Specialization(guards = {"isNull", "isSingleIntegerFixnum"})
26012591
public RubyArray pushEmptySingleIntegerFixnum(RubyArray array, Object... values) {
2602-
if (RubyContext.ARRAYS_INT) {
2603-
array.setStore(new int[]{(int) values[0]}, 1);
2604-
} else if (RubyContext.ARRAYS_LONG) {
2605-
array.setStore(new long[]{(long) values[0]}, 1);
2606-
} else {
2607-
array.setStore(new Object[]{values[0]}, 1);
2608-
}
2609-
2592+
array.setStore(new int[]{(int) values[0]}, 1);
26102593
return array;
26112594
}
26122595

26132596
@Specialization(guards = {"isNull", "isSingleLongFixnum"})
26142597
public RubyArray pushEmptySingleIntegerLong(RubyArray array, Object... values) {
2615-
if (RubyContext.ARRAYS_LONG) {
2616-
array.setStore(new long[]{(long) values[0]}, 1);
2617-
} else {
2618-
array.setStore(new Object[]{values[0]}, 1);
2619-
}
2620-
2598+
array.setStore(new long[]{(long) values[0]}, 1);
26212599
return array;
26222600
}
26232601

core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -300,31 +300,13 @@ public BytesNode(BytesNode prev) {
300300
public RubyArray bytes(RubyString string) {
301301
final byte[] bytes = string.getBytes().bytes();
302302

303-
if (RubyContext.ARRAYS_INT) {
304-
final int[] store = new int[bytes.length];
303+
final int[] store = new int[bytes.length];
305304

306-
for (int n = 0; n < store.length; n++) {
307-
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
308-
}
309-
310-
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
311-
} else if (RubyContext.ARRAYS_LONG) {
312-
final long[] store = new long[bytes.length];
313-
314-
for (int n = 0; n < store.length; n++) {
315-
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
316-
}
317-
318-
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
319-
} else {
320-
final Object[] store = new Object[bytes.length];
321-
322-
for (int n = 0; n < store.length; n++) {
323-
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
324-
}
325-
326-
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
305+
for (int n = 0; n < store.length; n++) {
306+
store[n] = RubyFixnum.toUnsignedInt(bytes[n]);
327307
}
308+
309+
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
328310
}
329311
}
330312

core/src/main/java/org/jruby/truffle/runtime/RubyContext.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public class RubyContext extends ExecutionContext {
5050
public static final boolean TRACE = Options.TRUFFLE_TRACE.load();
5151
public static final boolean OBJECTSPACE = Options.TRUFFLE_OBJECTSPACE.load();
5252
public static final boolean EXCEPTIONS_PRINT_JAVA = Options.TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
53-
public static final boolean LITERALS_INT = Options.TRUFFLE_LITERALS_INT.load();
5453
public static final int ARRAYS_UNINITIALIZED_SIZE = Options.TRUFFLE_ARRAYS_UNINITIALIZED_SIZE.load();
55-
public static final boolean ARRAYS_INT = Options.TRUFFLE_ARRAYS_INT.load();
56-
public static final boolean ARRAYS_LONG = Options.TRUFFLE_ARRAYS_LONG.load();
57-
public static final boolean ARRAYS_DOUBLE = Options.TRUFFLE_ARRAYS_DOUBLE.load();
5854
public static final boolean ARRAYS_OPTIMISTIC_LONG = Options.TRUFFLE_ARRAYS_OPTIMISTIC_LONG.load();
5955
public static final int ARRAYS_SMALL = Options.TRUFFLE_ARRAYS_SMALL.load();
6056
public static final int HASHES_SMALL = Options.TRUFFLE_HASHES_SMALL.load();

core/src/main/java/org/jruby/truffle/runtime/core/RubyArray.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,17 @@ public static RubyArray fromObject(RubyClass arrayClass, Object object) {
7878

7979
final Object store;
8080

81-
if (object instanceof Integer && RubyContext.ARRAYS_INT) {
81+
if (object instanceof Integer) {
8282
store = new int[]{(int) object};
83-
} else if (object instanceof Integer && RubyContext.ARRAYS_LONG) {
84-
store = new long[]{(long) (int) object};
85-
} else if (object instanceof RubyFixnum.IntegerFixnum && RubyContext.ARRAYS_INT) {
83+
} else if (object instanceof RubyFixnum.IntegerFixnum) {
8684
store = new int[]{((RubyFixnum.IntegerFixnum) object).getValue()};
87-
} else if (object instanceof RubyFixnum.IntegerFixnum && RubyContext.ARRAYS_LONG) {
88-
store = new long[]{(long) ((RubyFixnum.IntegerFixnum) object).getValue()};
89-
} else if (object instanceof Long && RubyContext.ARRAYS_LONG) {
85+
} else if (object instanceof Long) {
9086
store = new long[]{(long) object};
91-
} else if (object instanceof RubyFixnum.LongFixnum && RubyContext.ARRAYS_LONG) {
87+
} else if (object instanceof RubyFixnum.LongFixnum) {
9288
store = new long[]{((RubyFixnum.LongFixnum) object).getValue()};
93-
} else if (object instanceof Double && RubyContext.ARRAYS_DOUBLE) {
89+
} else if (object instanceof Double) {
9490
store = new double[]{(double) object};
95-
} else if (object instanceof RubyFloat && RubyContext.ARRAYS_DOUBLE) {
91+
} else if (object instanceof RubyFloat) {
9692
store = new double[]{((RubyFloat) object).getValue()};
9793
} else {
9894
store = new Object[]{object};
@@ -112,9 +108,9 @@ public static RubyArray fromObjects(RubyClass arrayClass, Object... objects) {
112108
return fromObject(arrayClass, objects[0]);
113109
}
114110

115-
boolean canUseInteger = RubyContext.ARRAYS_INT;
116-
boolean canUseLong = RubyContext.ARRAYS_LONG;
117-
boolean canUseDouble = RubyContext.ARRAYS_DOUBLE;
111+
boolean canUseInteger = true;
112+
boolean canUseLong = true;
113+
boolean canUseDouble = true;
118114

119115
for (Object object : objects) {
120116
if (object instanceof Integer) {
@@ -249,9 +245,6 @@ public void setStore(Object store, int size) {
249245
assert !(store instanceof int[]) || size <= ((int[]) store).length;
250246
assert !(store instanceof long[]) || size <= ((long[]) store).length;
251247
assert !(store instanceof double[]) || size <= ((double[]) store).length;
252-
assert !(store instanceof int[]) || RubyContext.ARRAYS_INT;
253-
assert !(store instanceof long[]) || RubyContext.ARRAYS_LONG;
254-
assert !(store instanceof double[]) || RubyContext.ARRAYS_DOUBLE;
255248

256249
// TODO: assert that an object array doesn't contain all primitives - performance warning?
257250
}

core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ public RubyNode visitFalseNode(org.jruby.ast.FalseNode node) {
837837
public RubyNode visitFixnumNode(org.jruby.ast.FixnumNode node) {
838838
final long value = node.getValue();
839839

840-
if (RubyFixnum.fitsIntoInteger(value) && RubyContext.LITERALS_INT) {
840+
if (RubyFixnum.fitsIntoInteger(value)) {
841841
return new FixnumLiteralNode.IntegerFixnumLiteralNode(context, translate(node.getPosition()), (int) value);
842842
} else {
843843
return new FixnumLiteralNode.LongFixnumLiteralNode(context, translate(node.getPosition()), value);

core/src/main/java/org/jruby/util/cli/Options.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ public class Options {
132132
public static final Option<Boolean> TRUFFLE_TRACE = bool(TRUFFLE, "truffle.trace", true, "Install trace probes needed for set_trace_func.");
133133
public static final Option<Boolean> TRUFFLE_OBJECTSPACE = bool(TRUFFLE, "truffle.object_space", true, "Install safepoints needed for ObjectSpace.");
134134
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.");
135-
public static final Option<Boolean> TRUFFLE_LITERALS_INT = bool(TRUFFLE, "truffle.literals.int", true, "Use int for Fixnum literals where possible.");
136135
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.");
137-
public static final Option<Boolean> TRUFFLE_ARRAYS_INT = bool(TRUFFLE, "truffle.arrays.int", true, "Use int[] for Fixnum Array storage where possible.");
138-
public static final Option<Boolean> TRUFFLE_ARRAYS_LONG = bool(TRUFFLE, "truffle.arrays.long", true, "Use long[] for Fixnum Array storage where possible.");
139-
public static final Option<Boolean> TRUFFLE_ARRAYS_DOUBLE = bool(TRUFFLE, "truffle.arrays.double", true, "Use double[] Float for Array storage where possible.");
140136
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.");
141137
public static final Option<Integer> TRUFFLE_ARRAYS_SMALL = integer(TRUFFLE, "truffle.arrays.small", 3, "Maximum size of an Array to consider small for optimisations.");
142138
public static final Option<Integer> TRUFFLE_HASHES_SMALL = integer(TRUFFLE, "truffle.hashes.small", 3, "Maximum size of a Hash to consider small for optimisations.");

0 commit comments

Comments
 (0)