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: dedab2c0d208
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8a79e244d8f3
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 11, 2016

  1. [Truffle] Use the store length when specializing an ArrayBuilderNode.

    * Otherwise, a method like Array#select could end up deopting too many times,
      as it might return fewer elements over time.
    * Add a reason for replace().
    eregon committed Dec 11, 2016
    Copy the full SHA
    0050238 View commit details
  2. Copy the full SHA
    8a79e24 View commit details
Showing with 23 additions and 19 deletions.
  1. +23 −19 truffle/src/main/java/org/jruby/truffle/core/array/ArrayBuilderNode.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;

import java.util.Arrays;

import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;

@@ -45,9 +48,9 @@ protected RubyContext getContext() {
return context;
}

protected Object restart(int length) {
protected Object restart(int length, String reason) {
final UninitializedArrayBuilderNode newNode = new UninitializedArrayBuilderNode(getContext());
replace(newNode);
replace(newNode, reason);
return newNode.start(length);
}

@@ -131,18 +134,19 @@ public Object appendValue(Object store, int index, Object value) {

@Override
public Object finish(Object store, int length) {
Object[] storeArray = (Object[]) store;
if (couldUseInteger) {
replace(new IntegerArrayBuilderNode(getContext(), length));
return ArrayUtils.unboxInteger((Object[]) store, length);
replace(new IntegerArrayBuilderNode(getContext(), storeArray.length));
return ArrayUtils.unboxInteger(storeArray, length);
} else if (couldUseLong) {
replace(new LongArrayBuilderNode(getContext(), length));
return ArrayUtils.unboxLong((Object[]) store, length);
replace(new LongArrayBuilderNode(getContext(), storeArray.length));
return ArrayUtils.unboxLong(storeArray, length);
} else if (couldUseDouble) {
replace(new DoubleArrayBuilderNode(getContext(), length));
return ArrayUtils.unboxDouble((Object[]) store, length);
replace(new DoubleArrayBuilderNode(getContext(), storeArray.length));
return ArrayUtils.unboxDouble(storeArray, length);
} else {
replace(new ObjectArrayBuilderNode(getContext(), length));
return store;
replace(new ObjectArrayBuilderNode(getContext(), storeArray.length));
return storeArray;
}
}

@@ -184,7 +188,7 @@ public Object start() {
public Object start(int length) {
if (length > expectedLength) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return restart(length);
return restart(length, length + " > " + expectedLength + " (expected)");
}

return new int[expectedLength];
@@ -262,7 +266,7 @@ public Object start() {
public Object start(int length) {
if (length > expectedLength) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return restart(length);
return restart(length, length + " > " + expectedLength + " (expected)");
}

return new long[expectedLength];
@@ -334,7 +338,7 @@ public Object start() {
public Object start(int length) {
if (length > expectedLength) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return restart(length);
return restart(length, length + " > " + expectedLength + " (expected)");
}

return new double[expectedLength];
@@ -413,7 +417,9 @@ public Object start() {
public Object start(int length) {
if (length > expectedLength) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return restart(length);
final ArrayBuilderNode newNode = new ObjectArrayBuilderNode(getContext(), length);
replace(newNode, length + " > " + expectedLength + " (expected)");
return newNode.start(length);
}

return new Object[expectedLength];
@@ -423,11 +429,9 @@ public Object start(int length) {
public Object ensure(Object store, int length) {
if (length > ((Object[]) store).length) {
CompilerDirectives.transferToInterpreterAndInvalidate();

final UninitializedArrayBuilderNode newNode = new UninitializedArrayBuilderNode(getContext());
replace(newNode);
newNode.resume((Object[]) store);
return newNode.ensure(store, length);
final ArrayBuilderNode newNode = new ObjectArrayBuilderNode(getContext(), length);
replace(newNode, length + " > " + expectedLength + " (expected)");
return newNode.ensure(Arrays.copyOf((Object[]) store, length), length);
}

return store;