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

Commits on Dec 9, 2016

  1. [Truffle] Integrate the null Array strategy with other strategies.

    * Avoids special cases for isNullArray().
    * As efficient when compiled thanks to getSize() returning 0.
    eregon committed Dec 9, 2016
    Copy the full SHA
    2ac33b5 View commit details
  2. [Truffle] Remove ArrayStrategy.of(array, value).

    * Instead, make LongArrayMirror.set() more flexible.
    eregon committed Dec 9, 2016
    Copy the full SHA
    5d8ead2 View commit details
Showing with 152 additions and 449 deletions.
  1. +1 −1 spec/truffle/specs/truffle/array/append_spec.rb
  2. +7 −30 truffle/src/main/java/org/jruby/truffle/core/array/ArrayAppendManyNode.java
  3. +7 −18 truffle/src/main/java/org/jruby/truffle/core/array/ArrayAppendOneNode.java
  4. +1 −7 truffle/src/main/java/org/jruby/truffle/core/array/ArrayDropTailNode.java
  5. +3 −16 truffle/src/main/java/org/jruby/truffle/core/array/ArrayDupNode.java
  6. +0 −8 truffle/src/main/java/org/jruby/truffle/core/array/ArrayGeneralizeNode.java
  7. +1 −7 truffle/src/main/java/org/jruby/truffle/core/array/ArrayGetTailNode.java
  8. +0 −5 truffle/src/main/java/org/jruby/truffle/core/array/ArrayGuards.java
  9. +54 −167 truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
  10. +7 −14 truffle/src/main/java/org/jruby/truffle/core/array/ArrayReadNormalizedNode.java
  11. +1 −10 truffle/src/main/java/org/jruby/truffle/core/array/ArrayReadSliceNormalizedNode.java
  12. +1 −7 truffle/src/main/java/org/jruby/truffle/core/array/ArraySliceNode.java
  13. +55 −45 truffle/src/main/java/org/jruby/truffle/core/array/ArrayStrategy.java
  14. +1 −7 truffle/src/main/java/org/jruby/truffle/core/array/ArrayToObjectArrayNode.java
  15. +4 −29 truffle/src/main/java/org/jruby/truffle/core/array/ArrayWriteNormalizedNode.java
  16. +5 −1 truffle/src/main/java/org/jruby/truffle/core/array/LongArrayMirror.java
  17. +0 −73 truffle/src/main/java/org/jruby/truffle/core/array/LongIntArrayMirror.java
  18. +1 −1 truffle/src/main/java/org/jruby/truffle/core/cast/SplatCastNode.java
  19. +3 −3 truffle/src/main/java/org/jruby/truffle/language/dispatch/RubyCallNode.java
2 changes: 1 addition & 1 deletion spec/truffle/specs/truffle/array/append_spec.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def storage(ary)

it "empty array has null storage" do
ary = []
storage(ary).should == "fallback"
storage(ary).should == "null"
end

it "supports transitions from null storage" do
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import com.oracle.truffle.api.profiles.ConditionProfile;
import org.jruby.truffle.language.RubyNode;

import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
import static org.jruby.truffle.core.array.ArrayHelpers.setSize;
import static org.jruby.truffle.core.array.ArrayHelpers.setStoreAndSize;

@@ -31,39 +30,17 @@ public abstract class ArrayAppendManyNode extends RubyNode {

public abstract DynamicObject executeAppendMany(DynamicObject array, DynamicObject other);

// Append into an empty array

// TODO CS 12-May-15 differentiate between null and empty but possibly having enough space

@Specialization(guards = { "isEmptyArray(array)", "isNullArray(other)" })
public DynamicObject appendManyNullNull(DynamicObject array, DynamicObject other) {
return array;
}

@Specialization(guards = { "isEmptyArray(array)", "strategy.matches(other)" }, limit = "ARRAY_STRATEGIES")
public DynamicObject appendManyEmpty(DynamicObject array, DynamicObject other,
@Cached("of(other)") ArrayStrategy strategy) {
final int otherSize = getSize(other);
Object store = strategy.newMirror(other).copyArrayAndMirror(otherSize).getArray();
setStoreAndSize(array, store, otherSize);
return array;
}

@Specialization(guards = "isEmptyArray(other)")
public DynamicObject appendManyOtherEmpty(DynamicObject array, DynamicObject other) {
return array;
}

// Append of a compatible type

@Specialization(guards = { "strategy.matches(array)", "otherStrategy.matches(other)",
"strategy.canStore(otherStrategy.type())" }, limit = "ARRAY_STRATEGIES")
"generalized.equals(strategy)" }, limit = "ARRAY_STRATEGIES")
public DynamicObject appendManySameType(DynamicObject array, DynamicObject other,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("of(other)") ArrayStrategy otherStrategy,
@Cached("strategy.generalize(otherStrategy)") ArrayStrategy generalized,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final int oldSize = getSize(array);
final int otherSize = getSize(other);
final int oldSize = strategy.getSize(array);
final int otherSize = otherStrategy.getSize(other);
final int newSize = oldSize + otherSize;
final ArrayMirror storeMirror = strategy.newMirror(array);
final ArrayMirror otherStoreMirror = otherStrategy.newMirror(other);
@@ -83,14 +60,14 @@ public DynamicObject appendManySameType(DynamicObject array, DynamicObject other
// Generalizations

@Specialization(guards = { "strategy.matches(array)", "otherStrategy.matches(other)",
"!strategy.canStore(otherStrategy.type())" }, limit = "ARRAY_STRATEGIES")
"!generalized.equals(strategy)" }, limit = "ARRAY_STRATEGIES")
public DynamicObject appendManyGeneralize(DynamicObject array, DynamicObject other,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("of(other)") ArrayStrategy otherStrategy,
@Cached("strategy.generalize(otherStrategy)") ArrayStrategy generalized,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final int oldSize = getSize(array);
final int otherSize = getSize(other);
final int oldSize = strategy.getSize(array);
final int otherSize = otherStrategy.getSize(other);
final int newSize = oldSize + otherSize;
final ArrayMirror newStoreMirror = generalized.newArray(newSize);
strategy.newMirror(array).copyTo(newStoreMirror, 0, 0, oldSize);
Original file line number Diff line number Diff line change
@@ -34,23 +34,11 @@ public static ArrayAppendOneNode create() {

public abstract DynamicObject executeAppendOne(DynamicObject array, Object value);

// Append into an empty array

@Specialization(guards = { "isNullArray(array)", "strategy.specializesFor(value)" }, limit = "ARRAY_STRATEGIES")
public DynamicObject appendOneEmpty(DynamicObject array, Object value,
@Cached("forValue(value)") ArrayStrategy strategy) {
final ArrayMirror storeMirror = strategy.newArray(1);
storeMirror.set(0, value);
strategy.setStore(array, storeMirror.getArray());
setSize(array, 1);
return array;
}

// Append of the correct type

@Specialization(guards = { "strategy.matches(array)", "strategy.accepts(value)" }, limit = "ARRAY_STRATEGIES")
public DynamicObject appendOneSameType(DynamicObject array, Object value,
@Cached("of(array, value)") ArrayStrategy strategy,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final ArrayMirror storeMirror = strategy.newMirror(array);
final int oldSize = Layouts.ARRAY.getSize(array);
@@ -71,14 +59,15 @@ public DynamicObject appendOneSameType(DynamicObject array, Object value,
// Append forcing a generalization

@Specialization(guards = {
"currentStrategy.matches(array)", "!currentStrategy.accepts(value)", "generalizedStrategy.accepts(value)",
"strategy.matches(array)", "!strategy.accepts(value)", "valueStrategy.specializesFor(value)",
}, limit = "ARRAY_STRATEGIES")
public DynamicObject appendOneGeneralize(DynamicObject array, Object value,
@Cached("of(array, value)") ArrayStrategy currentStrategy,
@Cached("currentStrategy.generalizeFor(value)") ArrayStrategy generalizedStrategy) {
final int oldSize = Layouts.ARRAY.getSize(array);
@Cached("of(array)") ArrayStrategy strategy,
@Cached("forValue(value)") ArrayStrategy valueStrategy,
@Cached("strategy.generalize(valueStrategy)") ArrayStrategy generalizedStrategy) {
final int oldSize = strategy.getSize(array);
final int newSize = oldSize + 1;
final ArrayMirror currentMirror = currentStrategy.newMirror(array);
final ArrayMirror currentMirror = strategy.newMirror(array);
final int oldCapacity = currentMirror.getLength();
final int newCapacity = newSize > oldCapacity ? ArrayUtils.capacityForOneMore(getContext(), oldCapacity) : oldCapacity;
final ArrayMirror storeMirror = generalizedStrategy.newArray(newCapacity);
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

@@ -32,16 +31,11 @@ public ArrayDropTailNode(RubyContext context, SourceSection sourceSection, int i
this.index = index;
}

@Specialization(guards = "isNullArray(array)")
public DynamicObject getHeadNull(DynamicObject array) {
return createArray(null, 0);
}

@Specialization(guards = "strategy.matches(array)", limit = "ARRAY_STRATEGIES")
public DynamicObject dropTail(DynamicObject array,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("createBinaryProfile()") ConditionProfile indexLargerThanSize) {
final int size = Layouts.ARRAY.getSize(array);
final int size = strategy.getSize(array);
if (indexLargerThanSize.profile(index >= size)) {
return createArray(null, 0);
} else {
Original file line number Diff line number Diff line change
@@ -15,9 +15,6 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.objects.AllocateObjectNode;

@@ -28,24 +25,14 @@
@ImportStatic(ArrayGuards.class)
public abstract class ArrayDupNode extends RubyNode {

@Child private AllocateObjectNode allocateNode;

public ArrayDupNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateNode = AllocateObjectNode.create();
}
@Child private AllocateObjectNode allocateNode = AllocateObjectNode.create();

public abstract DynamicObject executeDup(VirtualFrame frame, DynamicObject array);

@Specialization(guards = "isNullArray(from)")
public DynamicObject dupNull(DynamicObject from) {
return allocateNode.allocateArray(coreLibrary().getArrayClass(), null, 0);
}

@Specialization(guards = "strategy.matches(from)", limit = "ARRAY_STRATEGIES")
public DynamicObject dupOther(DynamicObject from,
public DynamicObject dup(DynamicObject from,
@Cached("of(from)") ArrayStrategy strategy) {
final int size = Layouts.ARRAY.getSize(from);
final int size = strategy.getSize(from);
Object store = strategy.newMirror(from).copyArrayAndMirror().getArray();
return allocateNode.allocateArray(coreLibrary().getArrayClass(), store, size);
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

@@ -38,13 +37,6 @@ public static ArrayGeneralizeNode create(RubyContext context) {

public abstract Object[] executeGeneralize(DynamicObject array, int requiredCapacity);

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

@Specialization(guards = "strategy.matches(array)", limit = "ARRAY_STRATEGIES")
public Object[] generalize(DynamicObject array, int requiredCapacity,
@Cached("of(array)") ArrayStrategy strategy,
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

@@ -32,16 +31,11 @@ public ArrayGetTailNode(RubyContext context, SourceSection sourceSection, int in
this.index = index;
}

@Specialization(guards = "isNullArray(array)")
public DynamicObject getTailNull(DynamicObject array) {
return createArray(null, 0);
}

@Specialization(guards = "strategy.matches(array)", limit = "ARRAY_STRATEGIES")
public DynamicObject getTail(DynamicObject array,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("createBinaryProfile()") ConditionProfile indexLargerThanSize) {
final int size = Layouts.ARRAY.getSize(array);
final int size = strategy.getSize(array);
if (indexLargerThanSize.profile(index >= size)) {
return createArray(null, 0);
} else {
Original file line number Diff line number Diff line change
@@ -20,11 +20,6 @@ public class ArrayGuards {

// Storage strategies

public static boolean isNullArray(DynamicObject array) {
assert RubyGuards.isRubyArray(array);
return Layouts.ARRAY.getStore(array) == null;
}

public static boolean isIntArray(DynamicObject array) {
assert RubyGuards.isRubyArray(array);
return Layouts.ARRAY.getStore(array) instanceof int[];
Loading