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

Commits on Dec 15, 2016

  1. Copy the full SHA
    a385812 View commit details
  2. Copy the full SHA
    eb2eb01 View commit details
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ConditionProfile;

import java.util.Arrays;

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

@@ -70,11 +70,20 @@ protected Object appendValueFallback(Object store, int index, Object value, int
return newStore;
}

protected Object ensureFallback(Object store, int length) {
final Object[] newStore = ArrayUtils.box(store, length);
final UninitializedArrayBuilderNode newNode = new UninitializedArrayBuilderNode(getContext());
replace(newNode);
newNode.resume(newStore);
return newNode.ensure(newStore, length);
}

private static class UninitializedArrayBuilderNode extends ArrayBuilderNode {

private boolean couldUseInteger = true;
private boolean couldUseLong = true;
private boolean couldUseDouble = true;
private final BranchProfile expandProfile = BranchProfile.create();

public UninitializedArrayBuilderNode(RubyContext context) {
super(context);
@@ -88,13 +97,11 @@ public void resume(Object[] store) {

@Override
public Object start() {
CompilerDirectives.transferToInterpreterAndInvalidate();
return new Object[getContext().getOptions().ARRAY_UNINITIALIZED_SIZE];
}

@Override
public Object start(int length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return new Object[length];
}

@@ -104,10 +111,9 @@ public Object ensure(Object store, int length) {
return store;
}

@TruffleBoundary
@Override
public Object appendArray(Object store, int index, DynamicObject array) {
CompilerDirectives.transferToInterpreterAndInvalidate();

for (Object value : ArrayOperations.toIterable(array)) {
store = appendValue(store, index, value);
index++;
@@ -118,13 +124,12 @@ public Object appendArray(Object store, int index, DynamicObject array) {

@Override
public Object appendValue(Object store, int index, Object value) {
CompilerDirectives.transferToInterpreterAndInvalidate();

screen(value);

Object[] storeArray = (Object[]) store;

if (index >= storeArray.length) {
expandProfile.enter();
storeArray = ArrayUtils.grow(storeArray, ArrayUtils.capacity(getContext(), storeArray.length, index + 1));
}

@@ -134,6 +139,7 @@ public Object appendValue(Object store, int index, Object value) {

@Override
public Object finish(Object store, int length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Object[] storeArray = (Object[]) store;
if (couldUseInteger) {
replace(new IntegerArrayBuilderNode(getContext(), storeArray.length));
@@ -198,15 +204,8 @@ public Object start(int length) {
public Object ensure(Object store, int length) {
if (length > ((int[]) store).length) {
CompilerDirectives.transferToInterpreterAndInvalidate();

final Object[] newStore = ArrayUtils.box((int[]) store);

final UninitializedArrayBuilderNode newNode = new UninitializedArrayBuilderNode(getContext());
replace(newNode);
newNode.resume(newStore);
return newNode.ensure(newStore, length);
return ensureFallback(store, length);
}

return store;
}

@@ -224,7 +223,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {
}

CompilerDirectives.transferToInterpreterAndInvalidate();

return replace(new ObjectArrayBuilderNode(getContext(), expectedLength)).
appendArray(ArrayUtils.box((int[]) store), index, array);
}
@@ -274,8 +272,11 @@ public Object start(int length) {

@Override
public Object ensure(Object store, int length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new UnsupportedOperationException();
if (length > ((long[]) store).length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return ensureFallback(store, length);
}
return store;
}

@Override
@@ -292,7 +293,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {
}

CompilerDirectives.transferToInterpreterAndInvalidate();

return replace(new ObjectArrayBuilderNode(getContext(), expectedLength)).
appendArray(ArrayUtils.box((long[]) store), index, array);
}
@@ -348,11 +348,7 @@ public Object start(int length) {
public Object ensure(Object store, int length) {
if (length > ((double[]) store).length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
final Object[] newStore = ArrayUtils.box((double[]) store);
final UninitializedArrayBuilderNode newNode = new UninitializedArrayBuilderNode(getContext());
replace(newNode);
newNode.resume(newStore);
return newNode.ensure(newStore, length);
return ensureFallback(store, length);
}
return store;
}
@@ -371,7 +367,6 @@ public Object appendArray(Object store, int index, DynamicObject array) {
}

CompilerDirectives.transferToInterpreterAndInvalidate();

return replace(new ObjectArrayBuilderNode(getContext(), expectedLength)).
appendArray(ArrayUtils.box((double[]) store), index, array);
}
@@ -431,7 +426,7 @@ public Object ensure(Object store, int length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
final ArrayBuilderNode newNode = new ObjectArrayBuilderNode(getContext(), length);
replace(newNode, length + " > " + expectedLength + " (expected)");
return newNode.ensure(Arrays.copyOf((Object[]) store, length), length);
return newNode.ensure(ArrayUtils.copyOf((Object[]) store, length), length);
}

return store;
Original file line number Diff line number Diff line change
@@ -156,6 +156,10 @@ public static Object[] box(long[] unboxed, int newLength) {
return boxed;
}

public static Object[] box(Object array, int newLength) {
return boxExtra(array, newLength - Array.getLength(array));
}

public static Object[] box(double[] unboxed, int newLength) {
final Object[] boxed = new Object[newLength];