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

Commits on Apr 21, 2016

  1. Copy the full SHA
    53ca3c8 View commit details
  2. Copy the full SHA
    fffdd34 View commit details
  3. Copy the full SHA
    f74f362 View commit details
  4. Copy the full SHA
    e132cc3 View commit details
  5. Copy the full SHA
    f57ed6c View commit details
Showing with 30 additions and 231 deletions.
  1. +1 −1 tool/jruby_eclipse
  2. +2 −2 tool/jt.rb
  3. +27 −228 truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
2 changes: 1 addition & 1 deletion tool/jruby_eclipse
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

M2REPO = "#{Dir.home}/.m2/repository"

TRUFFLE_VERSION = "0.11"
TRUFFLE_VERSION = "0.12"

TRUFFLEJARS = %W[
com/oracle/truffle/truffle-api/#{TRUFFLE_VERSION}/truffle-api-#{TRUFFLE_VERSION}.jar
4 changes: 2 additions & 2 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ def self.truffle_version

def self.graal_locations
from_env = ENV['GRAAL_BIN']
yield from_env if from_env
yield File.expand_path(from_env) if from_env

rel_java_bin = "bin/java" # "jre/bin/javao"
%w[dk re].each { |kind|
@@ -52,7 +52,7 @@ def self.graal_locations

def self.find_graal
graal_locations do |location|
return location if File.executable?(File.expand_path(location))
return location if File.executable?(location)
end
raise "couldn't find graal - download it as described in https://github.com/jruby/jruby/wiki/Downloading-GraalVM and extract it into the JRuby repository or parent directory"
end
255 changes: 27 additions & 228 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -802,7 +802,7 @@ public Object eachOther(VirtualFrame frame, DynamicObject array, DynamicObject b
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(n);
LoopNode.reportLoopCount(this, n);
}
}

@@ -1129,7 +1129,7 @@ public Object injectBlockHelper(VirtualFrame frame, DynamicObject array, Dynamic
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(n);
LoopNode.reportLoopCount(this, n);
}
}

@@ -1180,101 +1180,7 @@ public Object injectSymbolHelper(VirtualFrame frame, DynamicObject array, Dynami

}

@CoreMethod(names = "insert", raiseIfFrozenSelf = true, rest = true, required = 1, optional = 1)
public abstract static class InsertNode extends ArrayCoreMethodNode {

@Child private ToIntNode toIntNode;

@Specialization
public Object insertMissingValue(VirtualFrame frame, DynamicObject array, Object idx, NotProvided value, Object[] values) {
return array;
}

@Specialization(guards = { "isNullArray(array)", "wasProvided(value)", "values.length == 0" })
public Object insertNull(DynamicObject array, int idx, Object value, Object[] values) {
CompilerDirectives.transferToInterpreter();
final int index = normalizeInsertIndex(array, idx);
final Object[] store = new Object[index + 1];
Arrays.fill(store, nil());
store[index] = value;
setStoreAndSize(array, store, index + 1);
return array;
}

@Specialization(guards = { "isIntArray(array)", "values.length == 0", "idx >= 0", "isIndexSmallerThanSize(idx,array)", "hasRoomForOneExtra(array)" })
public Object insert(VirtualFrame frame, DynamicObject array, int idx, int value, Object[] values) {
final int index = idx;
final int[] store = (int[]) getStore(array);
System.arraycopy(store, index, store, index + 1, getSize(array) - index);
store[index] = value;
setStoreAndSize(array, store, getSize(array) + 1);
return array;
}

@Specialization
public Object insertBoxed(VirtualFrame frame, DynamicObject array, Object idxObject, Object unusedValue, Object[] unusedRest) {
final Object[] values = RubyArguments.getArguments(frame, 1);
final int idx = toInt(frame, idxObject);

CompilerDirectives.transferToInterpreter();
final int index = normalizeInsertIndex(array, idx);

final int oldSize = getSize(array);
final int newSize = (index < oldSize ? oldSize : index) + values.length;
final Object[] store = ArrayUtils.boxExtra(getStore(array), newSize - oldSize);

if (index >= oldSize) {
Arrays.fill(store, oldSize, index, nil());
} else {
final int dest = index + values.length;
final int len = oldSize - index;
System.arraycopy(store, index, store, dest, len);
}

System.arraycopy(values, 0, store, index, values.length);

setStoreAndSize(array, store, newSize);

return array;
}

private int normalizeInsertIndex(DynamicObject array, int index) {
final int normalizedIndex = normalizeInsertIndex(getSize(array), index);
if (normalizedIndex < 0) {
CompilerDirectives.transferToInterpreter();
String errMessage = "index " + index + " too small for array; minimum: " + Integer.toString(-getSize(array));
throw new RaiseException(coreExceptions().indexError(errMessage, this));
}
return normalizedIndex;
}

private static int normalizeInsertIndex(int length, int index) {
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.UNLIKELY_PROBABILITY, index < 0)) {
return length + index + 1;
} else {
return index;
}
}

protected static boolean isIndexSmallerThanSize(int idx, DynamicObject array) {
return idx <= getSize(array);
}

protected static boolean hasRoomForOneExtra(DynamicObject array) {
return ((int[]) getStore(array)).length > getSize(array);
}

private int toInt(VirtualFrame frame, Object indexObject) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
}
return toIntNode.doInt(frame, indexObject);
}

}

@CoreMethod(names = {"map", "collect"}, needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = { "map", "collect" }, needsBlock = true, returnsEnumeratorIfNoBlock = true)
@ImportStatic(ArrayGuards.class)
public abstract static class MapNode extends YieldingCoreMethodNode {

@@ -1283,108 +1189,32 @@ public DynamicObject mapNull(DynamicObject array, DynamicObject block) {
return createArray(getContext(), null, 0);
}

@Specialization(guards = "isIntArray(array)")
public Object mapIntegerFixnum(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("create(getContext())") ArrayBuilderNode arrayBuilder) {
final int[] store = (int[]) getStore(array);
final int arraySize = getSize(array);
Object mappedStore = arrayBuilder.start(arraySize);

int count = 0;
try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

mappedStore = arrayBuilder.appendValue(mappedStore, n, yield(frame, block, store[n]));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
}
}

return createArray(getContext(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
}

@Specialization(guards = "isLongArray(array)")
public Object mapLongFixnum(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("create(getContext())") ArrayBuilderNode arrayBuilder) {
final long[] store = (long[]) getStore(array);
final int arraySize = getSize(array);
Object mappedStore = arrayBuilder.start(arraySize);

int count = 0;
try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

mappedStore = arrayBuilder.appendValue(mappedStore, n, yield(frame, block, store[n]));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
}
}

return createArray(getContext(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
}

@Specialization(guards = "isDoubleArray(array)")
public Object mapFloat(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Specialization(guards = "strategy.matches(array)", limit = "ARRAY_STRATEGIES")
public Object map(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("create(getContext())") ArrayBuilderNode arrayBuilder) {
final double[] store = (double[]) getStore(array);
final int arraySize = getSize(array);
Object mappedStore = arrayBuilder.start(arraySize);
final ArrayMirror store = strategy.newMirror(array);
final int size = getSize(array);
Object mappedStore = arrayBuilder.start(size);

int count = 0;
int n = 0;
try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

mappedStore = arrayBuilder.appendValue(mappedStore, n, yield(frame, block, store[n]));
for (; n < getSize(array); n++) {
final Object mappedValue = yield(frame, block, store.get(n));
mappedStore = arrayBuilder.appendValue(mappedStore, n, mappedValue);
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
LoopNode.reportLoopCount(this, n);
}
}

return createArray(getContext(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
return createArray(getContext(), arrayBuilder.finish(mappedStore, size), size);
}

@Specialization(guards = "isObjectArray(array)")
public Object mapObject(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("create(getContext())") ArrayBuilderNode arrayBuilder) {
final Object[] store = (Object[]) getStore(array);
final int arraySize = getSize(array);
Object mappedStore = arrayBuilder.start(arraySize);

int count = 0;
try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

mappedStore = arrayBuilder.appendValue(mappedStore, n, yield(frame, block, store[n]));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
}
}

return createArray(getContext(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
}
}

@CoreMethod(names = {"map!", "collect!"}, needsBlock = true, returnsEnumeratorIfNoBlock = true, raiseIfFrozenSelf = true)
@CoreMethod(names = { "map!", "collect!" }, needsBlock = true, returnsEnumeratorIfNoBlock = true, raiseIfFrozenSelf = true)
@ImportStatic(ArrayGuards.class)
public abstract static class MapInPlaceNode extends YieldingCoreMethodNode {

@@ -1395,61 +1225,30 @@ public DynamicObject mapInPlaceNull(DynamicObject array, DynamicObject block) {
return array;
}

@Specialization(guards = "isIntArray(array)")
public Object mapInPlaceFixnumInteger(VirtualFrame frame, DynamicObject array, DynamicObject block) {
final int[] store = (int[]) getStore(array);

int count = 0;
@Specialization(guards = "strategy.matches(array)", limit = "ARRAY_STRATEGIES")
public Object map(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("createWriteNode()") ArrayWriteNormalizedNode writeNode) {
final ArrayMirror store = strategy.newMirror(array);

int n = 0;
try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

write(frame, array, n, yield(frame, block, store[n]));
for (; n < getSize(array); n++) {
writeNode.executeWrite(array, n, yield(frame, block, store.get(n)));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
LoopNode.reportLoopCount(this, n);
}
}


return array;
}

@Specialization(guards = "isObjectArray(array)")
public Object mapInPlaceObject(VirtualFrame frame, DynamicObject array, DynamicObject block) {
final Object[] store = (Object[]) getStore(array);

int count = 0;

try {
for (int n = 0; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

write(frame, array, n, yield(frame, block, store[n]));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
}
}


return array;
protected ArrayWriteNormalizedNode createWriteNode() {
return ArrayWriteNormalizedNodeGen.create(getContext(), getSourceSection(), null, null, null);
}

private Object write(VirtualFrame frame, DynamicObject array, int index, Object value) {
if (writeNode == null) {
CompilerDirectives.transferToInterpreter();
writeNode = insert(ArrayWriteNormalizedNodeGen.create(getContext(), getSourceSection(), null, null, null));
}
return writeNode.executeWrite(array, index, value);
}
}

// TODO: move into Enumerable?