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

Commits on Nov 30, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    be51d65 View commit details
  2. Copy the full SHA
    4c75955 View commit details
  3. Copy the full SHA
    2ee4aba View commit details
  4. Copy the full SHA
    28ab20b View commit details
  5. Copy the full SHA
    5dae500 View commit details
  6. Copy the full SHA
    27e32a3 View commit details
  7. [Truffle] ArrayAppend{One,Many}Node don't need a context or a section.

    * Remove most constructors in ArrayNodes.
    eregon committed Nov 30, 2016
    Copy the full SHA
    3f3aa1e View commit details
  8. Copy the full SHA
    15b7a58 View commit details
  9. Copy the full SHA
    66c47d5 View commit details
  10. [Truffle] Warn against running the JRuby+Truffle launcher with JRuby+…

    …Truffle.
    
    * It's not a good recipe for fast startup.
    * See #4346.
    eregon committed Nov 30, 2016
    Copy the full SHA
    357f40d View commit details
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 == "null"
storage(ary).should == "fallback"
end

it "supports transitions from null storage" do
5 changes: 4 additions & 1 deletion spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -27,7 +27,10 @@ class MSpecScript
-Xtruffle.graal.warn_unless=false
]
core_path = "#{JRUBY_DIR}/truffle/src/main/ruby"
flags << "-Xtruffle.core.load_path=#{core_path}" if File.directory?(core_path)
if File.directory?(core_path)
flags << "-Xtruffle.core.load_path=#{core_path}"
flags << "-Xtruffle.backtraces.hide_core_files=false"
end
set :flags, flags
end

6 changes: 5 additions & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@

# Recommended: function jt { ruby tool/jt.rb "$@"; }

abort "Do not run #{$0} with JRuby+Truffle itself, use MRI or some other Ruby." if RUBY_ENGINE == "jruby+truffle"

require 'fileutils'
require 'json'
require 'timeout'
@@ -1035,7 +1037,9 @@ def test_specs(command, *args)
if args.first == 'fast'
args.shift
options += %w[--excl-tag slow]
options << "-T-Xtruffle.backtraces.limit=4" unless args[-2..-1] == %w[-t ruby]
if args[-2..-1] != %w[-t ruby] and !args.delete('--backtrace')
options << "-T-Xtruffle.backtraces.limit=4"
end
end

if args.delete('--graal')
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@
import com.oracle.truffle.api.dsl.Specialization;
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.RubyContext;
import org.jruby.truffle.language.RubyNode;

import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
@@ -31,10 +29,6 @@
@ImportStatic(ArrayGuards.class)
public abstract class ArrayAppendManyNode extends RubyNode {

public ArrayAppendManyNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

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

// Append into an empty array
Original file line number Diff line number Diff line change
@@ -16,9 +16,7 @@
import com.oracle.truffle.api.dsl.Specialization;
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;

import static org.jruby.truffle.core.array.ArrayHelpers.setSize;
@@ -30,8 +28,8 @@
@ImportStatic(ArrayGuards.class)
public abstract class ArrayAppendOneNode extends RubyNode {

public ArrayAppendOneNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
public static ArrayAppendOneNode create() {
return ArrayAppendOneNodeGen.create(null, null);
}

public abstract DynamicObject executeAppendOne(DynamicObject array, Object value);
55 changes: 10 additions & 45 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -171,12 +171,7 @@ public abstract static class MulNode extends ArrayCoreMethodNode {

@Child private KernelNodes.RespondToNode respondToToStrNode;
@Child private ToIntNode toIntNode;
@Child private AllocateObjectNode allocateObjectNode;

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

protected abstract Object executeMul(VirtualFrame frame, DynamicObject array, int count);

@@ -253,12 +248,7 @@ public abstract static class IndexNode extends ArrayCoreMethodNode {
@Child protected ArrayReadSliceDenormalizedNode readSliceNode;
@Child protected ArrayReadSliceNormalizedNode readNormalizedSliceNode;
@Child protected CallDispatchHeadNode fallbackNode;
@Child protected AllocateObjectNode allocateObjectNode;

public IndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateObjectNode = AllocateObjectNode.create();
}
@Child protected AllocateObjectNode allocateObjectNode = AllocateObjectNode.create();

@Specialization
public Object index(DynamicObject array, int index, NotProvided length) {
@@ -687,12 +677,7 @@ public Object compactObjects(DynamicObject array) {
@ImportStatic(ArrayGuards.class)
public abstract static class ConcatNode extends CoreMethodNode {

@Child private ArrayAppendManyNode appendManyNode;

public ConcatNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendManyNode = ArrayAppendManyNodeGen.create(context, sourceSection, null, null);
}
@Child private ArrayAppendManyNode appendManyNode = ArrayAppendManyNodeGen.create(null, null);

@CreateCast("other") public RubyNode coerceOtherToAry(RubyNode other) {
return ToAryNodeGen.create(null, null, other);
@@ -710,14 +695,9 @@ public DynamicObject concat(DynamicObject array, DynamicObject other) {
@ImportStatic(ArrayGuards.class)
public abstract static class DeleteNode extends YieldingCoreMethodNode {

@Child private KernelNodes.SameOrEqualNode equalNode;
@Child private KernelNodes.SameOrEqualNode equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(null);
@Child private IsFrozenNode isFrozenNode;

public DeleteNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(null);
}

@Specialization(guards = "isNullArray(array)")
public Object deleteNull(VirtualFrame frame, DynamicObject array, Object value, NotProvided block) {
return nil();
@@ -821,10 +801,6 @@ public abstract static class EachNode extends YieldingCoreMethodNode {

@Child private CallDispatchHeadNode toEnumNode;

public EachNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isNullArray(array)")
public Object eachNull(VirtualFrame frame, DynamicObject array, DynamicObject block) {
return array;
@@ -955,7 +931,7 @@ private long toLong(VirtualFrame frame, Object indexObject) {
}
final Object result = toIntNode.executeIntOrLong(frame, indexObject);
if (result instanceof Integer) {
return (long) (int) result;
return (int) result;
} else {
return (long) result;
}
@@ -966,11 +942,10 @@ private long toLong(VirtualFrame frame, Object indexObject) {
@CoreMethod(names = "include?", required = 1)
public abstract static class IncludeNode extends ArrayCoreMethodNode {

@Child private KernelNodes.SameOrEqualNode equalNode;
@Child private KernelNodes.SameOrEqualNode equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(null);

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(null);
}

@Specialization(guards = "isNullArray(array)")
@@ -1519,17 +1494,12 @@ private int toInt(VirtualFrame frame, Object indexObject) {
}

@CoreMethod(names = "<<", raiseIfFrozenSelf = true, required = 1)
public abstract static class LeftShiftNode extends ArrayCoreMethodNode {

@Child private ArrayAppendOneNode appendOneNode;
public abstract static class AppendNode extends ArrayCoreMethodNode {

public LeftShiftNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendOneNode = ArrayAppendOneNodeGen.create(context, sourceSection, null, null);
}
@Child private ArrayAppendOneNode appendOneNode = ArrayAppendOneNode.create();

@Specialization
public DynamicObject leftShift(DynamicObject array, Object value) {
public DynamicObject append(DynamicObject array, Object value) {
return appendOneNode.executeAppendOne(array, value);
}

@@ -1538,12 +1508,7 @@ public DynamicObject leftShift(DynamicObject array, Object value) {
@CoreMethod(names = { "push", "__append__" }, rest = true, optional = 1, raiseIfFrozenSelf = true)
public abstract static class PushNode extends ArrayCoreMethodNode {

@Child private ArrayAppendOneNode appendOneNode;

public PushNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendOneNode = ArrayAppendOneNodeGen.create(context, sourceSection, null, null);
}
@Child private ArrayAppendOneNode appendOneNode = ArrayAppendOneNode.create();

@Specialization(guards = "rest.length == 0")
public DynamicObject pushZero(DynamicObject array, NotProvided unusedValue, Object[] rest) {
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public static ObjectArrayMirror reflect(Object[] array) {

public static ArrayMirror reflect(Object array) {
if (array == null) {
return new EmptyArrayMirror();
return EmptyArrayMirror.INSTANCE;
} else if (array instanceof int[]) {
return reflect((int[]) array);
} else if (array instanceof long[]) {
Original file line number Diff line number Diff line change
@@ -36,11 +36,21 @@ public boolean isDefaultValue(Object value) {
throw unsupported();
}

public abstract boolean matches(DynamicObject array);
public final boolean matches(DynamicObject array) {
return matchesStore(Layouts.ARRAY.getStore(array));
}

protected abstract boolean matchesStore(Object store);

public abstract ArrayMirror newArray(int size);

public abstract ArrayMirror newMirror(DynamicObject array);
public final ArrayMirror newMirror(DynamicObject array) {
return newMirrorFromStore(Layouts.ARRAY.getStore(array));
}

protected ArrayMirror newMirrorFromStore(Object store) {
throw unsupported();
}

@Override
public abstract String toString();
@@ -75,6 +85,24 @@ protected RuntimeException unsupported() {
ObjectArrayStrategy.INSTANCE
};

private static ArrayStrategy ofStore(Object store) {
CompilerAsserts.neverPartOfCompilation();

if (store == null) {
return FallbackArrayStrategy.INSTANCE;
} else if (store instanceof int[]) {
return IntArrayStrategy.INSTANCE;
} else if (store instanceof long[]) {
return LongArrayStrategy.INSTANCE;
} else if (store instanceof double[]) {
return DoubleArrayStrategy.INSTANCE;
} else if (store.getClass() == Object[].class) {
return ObjectArrayStrategy.INSTANCE;
} else {
throw new UnsupportedOperationException(store.getClass().getName());
}
}

public static ArrayStrategy of(DynamicObject array) {
CompilerAsserts.neverPartOfCompilation();

@@ -150,8 +178,8 @@ public boolean isDefaultValue(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isIntArray(array);
public boolean matchesStore(Object store) {
return store instanceof int[];
}

@Override
@@ -172,8 +200,8 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new IntegerArrayMirror((int[]) Layouts.ARRAY.getStore(array));
protected ArrayMirror newMirrorFromStore(Object store) {
return new IntegerArrayMirror((int[]) store);
}

@Override
@@ -213,8 +241,8 @@ public boolean isDefaultValue(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isLongArray(array);
public boolean matchesStore(Object store) {
return store instanceof long[];
}

@Override
@@ -223,8 +251,8 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new LongArrayMirror((long[]) Layouts.ARRAY.getStore(array));
public ArrayMirror newMirrorFromStore(Object store) {
return new LongArrayMirror((long[]) store);
}

@Override
@@ -264,8 +292,8 @@ public boolean isDefaultValue(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isDoubleArray(array);
public boolean matchesStore(Object store) {
return store instanceof double[];
}

@Override
@@ -274,8 +302,8 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new DoubleArrayMirror((double[]) Layouts.ARRAY.getStore(array));
public ArrayMirror newMirrorFromStore(Object store) {
return new DoubleArrayMirror((double[]) store);
}

@Override
@@ -315,8 +343,8 @@ public boolean isDefaultValue(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isObjectArray(array);
public boolean matchesStore(Object store) {
return store != null && store.getClass() == Object[].class;
}

@Override
@@ -325,8 +353,8 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new ObjectArrayMirror((Object[]) Layouts.ARRAY.getStore(array));
public ArrayMirror newMirrorFromStore(Object store) {
return new ObjectArrayMirror((Object[]) store);
}

@Override
@@ -349,13 +377,13 @@ public boolean accepts(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isLongArray(array);
public boolean matchesStore(Object store) {
return store instanceof long[];
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new LongIntArrayMirror((long[]) Layouts.ARRAY.getStore(array));
public ArrayMirror newMirrorFromStore(Object store) {
return new LongIntArrayMirror((long[]) store);
}

@Override
@@ -376,8 +404,8 @@ public boolean accepts(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
return ArrayGuards.isObjectArray(array);
public boolean matchesStore(Object store) {
return store != null && store.getClass() == Object[].class;
}

@Override
@@ -386,8 +414,8 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
return new ObjectArrayMirror((Object[]) Layouts.ARRAY.getStore(array));
public ArrayMirror newMirrorFromStore(Object store) {
return new ObjectArrayMirror((Object[]) store);
}

@Override
@@ -409,7 +437,7 @@ public boolean accepts(Object value) {
}

@Override
public boolean matches(DynamicObject array) {
public boolean matchesStore(Object store) {
return false;
}

@@ -424,13 +452,13 @@ public ArrayMirror newArray(int size) {
}

@Override
public ArrayMirror newMirror(DynamicObject array) {
public ArrayMirror newMirrorFromStore(Object store) {
throw unsupported();
}

@Override
public String toString() {
return "null";
return "fallback";
}

}
Original file line number Diff line number Diff line change
@@ -97,15 +97,11 @@ public Object writeWithinGeneralize(DynamicObject array, int index, Object value

@Specialization(guards = "isExtendingByOne(array, index)")
public Object writeExtendByOne(DynamicObject array, int index, Object value,
@Cached("createArrayAppendOneNode()") ArrayAppendOneNode appendNode) {
@Cached("create()") ArrayAppendOneNode appendNode) {
appendNode.executeAppendOne(array, value);
return value;
}

protected ArrayAppendOneNode createArrayAppendOneNode() {
return ArrayAppendOneNodeGen.create(getContext(), null, null, null);
}

// Writing beyond the end of an array - may need to generalize to Object[] or otherwise extend

@Specialization(guards = {
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@

public class EmptyArrayMirror extends BasicArrayMirror {

public static final ArrayMirror INSTANCE = new EmptyArrayMirror();

@Override
public int getLength() {
return 0;
@@ -28,12 +30,12 @@ public void set(int index, Object value) {

@Override
public ArrayMirror copyArrayAndMirror() {
return new EmptyArrayMirror();
return INSTANCE;
}

@Override
public ArrayMirror copyArrayAndMirror(int newLength) {
return new EmptyArrayMirror();
return INSTANCE;
}

@Override
@@ -53,7 +55,7 @@ public void copyTo(Object[] destination, int sourceStart, int destinationStart,
@Override
public ArrayMirror extractRange(int start, int end) {
assert start == 0 && end == 0;
return new EmptyArrayMirror();
return INSTANCE;
}

@Override
Original file line number Diff line number Diff line change
@@ -11,8 +11,15 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyBaseNode;
import org.jruby.truffle.language.backtrace.BacktraceFormatter.FormattingFlags;

import com.oracle.truffle.api.nodes.Node;

public class Backtrace {

private final Activation[] activations;
@@ -31,4 +38,28 @@ public Throwable getJavaThrowable() {
return javaThrowable;
}

@Override
public String toString() {
RubyContext context = null;
if (activations.length > 0) {
Activation activation = activations[0];
Node node = activation.getCallNode();
if (node != null && node instanceof RubyBaseNode) {
context = ((RubyBaseNode) node).getContext();
}
}

if (context != null) {
final BacktraceFormatter backtraceFormatter = new BacktraceFormatter(context, EnumSet.of(FormattingFlags.INCLUDE_CORE_FILES));
final StringBuilder builder = new StringBuilder();
for (String line : backtraceFormatter.formatBacktrace(context, null, this)) {
builder.append("\n");
builder.append(line);
}
return builder.toString().substring(1);
} else {
return "";
}
}

}
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ private DynamicObject translate(IllegalArgumentException exception) {
message = exception.toString();
}

return coreExceptions().argumentError(message, this);
return coreExceptions().argumentError(message, this, exception);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -400,7 +400,7 @@ public RubyNode visitArgsPushNode(ArgsPushParseNode node) {

final RubyNode args = node.getFirstNode().accept(this);
final RubyNode value = node.getSecondNode().accept(this);
final RubyNode ret = ArrayAppendOneNodeGen.create(context, fullSourceSection,
final RubyNode ret = ArrayAppendOneNodeGen.create(
KernelNodesFactory.DupNodeFactory.create(context, fullSourceSection, new RubyNode[] { args }),
value);