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: d6a583dc29bc
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fd7eefe1ea19
Choose a head ref
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 25, 2015

  1. Copy the full SHA
    d7ea103 View commit details
  2. Copy the full SHA
    afef369 View commit details
  3. Copy the full SHA
    3c3ba12 View commit details
  4. Copy the full SHA
    0d18e92 View commit details
  5. [Truffle] code formatting

    pitr-ch committed Aug 25, 2015
    Copy the full SHA
    fd7eefe View commit details
Original file line number Diff line number Diff line change
@@ -1591,7 +1591,7 @@ public DynamicObject initialize(DynamicObject array, int size, double defaultVal
Layouts.ARRAY.setSize(array, size);
return array;
}

@Specialization(guards = "size < 0")
public DynamicObject initializeNegative(DynamicObject array, int size, double defaultValue, NotProvided block) {
CompilerDirectives.transferToInterpreter();
@@ -3086,7 +3086,7 @@ public DynamicObject pushLongFixnumSingleLongFixnum(DynamicObject array, long va

@Specialization(guards = "isDoubleArray(array)")
public DynamicObject pushFloat(VirtualFrame frame, DynamicObject array, Object unusedValue, Object[] unusedRest) {
// TODO CS 5-Feb-15 hack to get things working with empty double[] store
// TODO CS 5-Feb-15 hack to get things working with empty double[] store
if (Layouts.ARRAY.getSize(array) != 0) {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -222,7 +222,6 @@ public Object writeWithinDouble(DynamicObject array, int index, Object value) {
public boolean writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, boolean value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -233,7 +232,6 @@ public boolean writeExtendByOne(VirtualFrame frame, DynamicObject array, int ind
public int writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((int[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -244,7 +242,6 @@ public int writeExtendByOne(VirtualFrame frame, DynamicObject array, int index,
public int writeExtendByOneIntIntoLong(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((long[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -255,7 +252,6 @@ public int writeExtendByOneIntIntoLong(VirtualFrame frame, DynamicObject array,
public long writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, long value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((long[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -266,7 +262,6 @@ public long writeExtendByOne(VirtualFrame frame, DynamicObject array, int index,
public double writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, double value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((double[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -277,18 +272,16 @@ public double writeExtendByOne(VirtualFrame frame, DynamicObject array, int inde
public DynamicObject writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, DynamicObject value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@Specialization(
guards={"isRubyArray(array)", "isObjectArray(array)", "isExtendingByOne(array, index)"}
guards={"isRubyArray(array)", "isObjectArray(array)", "isExtendingByOne(array, index)"}
)
public int writeObjectExtendByOne(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -307,7 +300,6 @@ public Object writeBeyondPrimitive(VirtualFrame frame, DynamicObject array, int
}

objectStore[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
@@ -324,7 +316,6 @@ public Object writeBeyondObject(VirtualFrame frame, DynamicObject array, int ind
}

objectStore[index] = value;
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@NodeChild(value="requiredCapacity", type=RubyNode.class)
@NodeChild(value = "array", type = RubyNode.class),
@NodeChild(value = "requiredCapacity", type = RubyNode.class)
})
@ImportStatic(ArrayGuards.class)
public abstract class GeneralizeArrayNode extends RubyNode {
@@ -34,45 +34,39 @@ public GeneralizeArrayNode(RubyContext context, SourceSection sourceSection) {

public abstract Object executeGeneralize(VirtualFrame frame, DynamicObject array, int requiredCapacity);

// TODO CS 9-Feb-15 should use ArrayUtils.capacity?

@Specialization(
guards={"isRubyArray(array)", "isNullArray(array)"}
guards = { "isRubyArray(array)", "isNullArray(array)" }
)
public DynamicObject generalizeNull(DynamicObject array, int requiredCapacity) {
Object store = new Object[requiredCapacity];
Layouts.ARRAY.setStore(array, store);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return array;
}

@Specialization(
guards={"isRubyArray(array)", "isIntArray(array)"}
guards = { "isRubyArray(array)", "isIntArray(array)" }
)
public DynamicObject generalizeInt(DynamicObject array, int requiredCapacity) {
final int[] intStore = (int[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
final int[] store = (int[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(store, ArrayUtils.capacity(store.length, requiredCapacity) - store.length));
return array;
}

@Specialization(
guards={"isRubyArray(array)", "isLongArray(array)"}
guards = { "isRubyArray(array)", "isLongArray(array)" }
)
public DynamicObject generalizeLong(DynamicObject array, int requiredCapacity) {
final long[] intStore = (long[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
final long[] store = (long[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(store, ArrayUtils.capacity(store.length, requiredCapacity) - store.length));
return array;
}

@Specialization(
guards={"isRubyArray(array)", "isDoubleArray(array)"}
guards = { "isRubyArray(array)", "isDoubleArray(array)" }
)
public DynamicObject generalizeDouble(DynamicObject array, int requiredCapacity) {
final double[] intStore = (double[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
final double[] store = (double[]) Layouts.ARRAY.getStore(array);
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(store, ArrayUtils.capacity(store.length, requiredCapacity) - store.length));
return array;
}

Original file line number Diff line number Diff line change
@@ -168,6 +168,7 @@ public static Object[] box(double[] unboxed, int newLength) {
}

public static Object[] boxExtra(int[] unboxed, int extra) {
assert extra >= 0: "extra is not negative";
final Object[] boxed = new Object[unboxed.length + extra];

for (int n = 0; n < unboxed.length; n++) {
@@ -178,6 +179,7 @@ public static Object[] boxExtra(int[] unboxed, int extra) {
}

public static Object[] boxExtra(long[] unboxed, int extra) {
assert extra >= 0: "extra is not negative";
final Object[] boxed = new Object[unboxed.length + extra];

for (int n = 0; n < unboxed.length; n++) {
@@ -188,6 +190,7 @@ public static Object[] boxExtra(long[] unboxed, int extra) {
}

public static Object[] boxExtra(double[] unboxed, int extra) {
assert extra >= 0: "extra is not negative";
final Object[] boxed = new Object[unboxed.length + extra];

for (int n = 0; n < unboxed.length; n++) {
@@ -198,6 +201,7 @@ public static Object[] boxExtra(double[] unboxed, int extra) {
}

public static Object[] boxExtra(Object array, int extra) {
assert extra >= 0: "extra is not negative";
CompilerAsserts.neverPartOfCompilation();

if (array == null) {
@@ -353,7 +357,6 @@ public static long[] longCopyOf(int[] ints, int newLength) {
return longs;
}

@TruffleBoundary
public static int capacity(int current, int needed) {
if (needed < 16) {
return 16;