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

Commits on Apr 23, 2016

  1. Copy the full SHA
    4c36bdb View commit details
  2. [Truffle] Use SnippetNode for redo_coerced.

    It's not as simple as just a call - there is also the symbol which would need extra logic.
    chrisseaton committed Apr 23, 2016
    Copy the full SHA
    f98eb65 View commit details
  3. Copy the full SHA
    950b58b View commit details

Commits on Apr 24, 2016

  1. Copy the full SHA
    d7e6464 View commit details
  2. Copy the full SHA
    f0a21fe View commit details
48 changes: 36 additions & 12 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -221,14 +221,22 @@ public DynamicObject mulIntegerFixnum(DynamicObject array, int count,
}

@Specialization(guards = "isRubyString(string)")
public Object mulObject(VirtualFrame frame, DynamicObject array, DynamicObject string) {
return ruby("join(sep)", "sep", string);
public Object mulObject(
VirtualFrame frame,
DynamicObject array,
DynamicObject string,
@Cached("createMethodCall()") CallDispatchHeadNode callNode) {
return callNode.call(frame, array, "join", null, string);
}

@Specialization(guards = { "!isInteger(object)", "!isRubyString(object)" })
public Object mulObjectCount(VirtualFrame frame, DynamicObject array, Object object) {
public Object mulObjectCount(
VirtualFrame frame,
DynamicObject array,
Object object,
@Cached("new()") SnippetNode snippetNode) {
if (respondToToStr(frame, object)) {
return ruby("join(sep.to_str)", "sep", object);
return snippetNode.execute(frame, "join(sep.to_str)", "sep", object);
} else {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
@@ -1290,8 +1298,12 @@ public Object max(VirtualFrame frame, DynamicObject array, NotProvided blockNotP
}

@Specialization
public Object max(VirtualFrame frame, DynamicObject array, DynamicObject block) {
return ruby("array.max_internal(&block)", "array", array, "block", block);
public Object max(
VirtualFrame frame,
DynamicObject array,
DynamicObject block,
@Cached("createMethodCall()") CallDispatchHeadNode callNode) {
return callNode.call(frame, array, "max_internal", block);
}

}
@@ -1408,8 +1420,12 @@ public Object min(VirtualFrame frame, DynamicObject array, NotProvided blockNotP
}

@Specialization
public Object min(VirtualFrame frame, DynamicObject array, DynamicObject block) {
return ruby("array.min_internal(&block)", "array", array, "block", block);
public Object min(
VirtualFrame frame,
DynamicObject array,
DynamicObject block,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "array.min_internal(&block)", "array", array, "block", block);
}

}
@@ -1582,8 +1598,12 @@ private DynamicObject finishPack(int formatLength, BytesResult result) {
"!isLong(format)",
"!isNil(format)"
})
public Object pack(DynamicObject array, Object format) {
return ruby("pack(format.to_str)", "format", format);
public Object pack(
VirtualFrame frame,
DynamicObject array,
Object format,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "pack(format.to_str)", "format", format);
}

@TruffleBoundary
@@ -3188,8 +3208,12 @@ public Object sortUsingRubinius(
}

@Specialization(guards = { "!isNullArray(array)", "!isSmall(array)" })
public Object sortUsingRubinius(VirtualFrame frame, DynamicObject array, NotProvided block) {
return ruby("sorted = dup; Rubinius.privately { sorted.isort!(0, right) }; sorted", "right", getSize(array));
public Object sortUsingRubinius(
VirtualFrame frame,
DynamicObject array,
NotProvided block,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "sorted = dup; Rubinius.privately { sorted.isort!(0, right) }; sorted", "right", getSize(array));
}

private int castSortValue(Object value) {
Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@
*/
package org.jruby.truffle.core.cast;

import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
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.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;

@NodeChild(value = "child", type = RubyNode.class)
public abstract class ToPathNode extends RubyNode {
@@ -30,8 +32,11 @@ public DynamicObject coerceRubyString(DynamicObject path) {
}

@Specialization(guards = "!isRubyString(object)")
public DynamicObject coerceObject(VirtualFrame frame, Object object) {
return (DynamicObject) ruby("Rubinius::Type.coerce_to_path(object)", "object", object);
public DynamicObject coerceObject(
VirtualFrame frame,
Object object,
@Cached("new()") SnippetNode snippetNode) {
return (DynamicObject) snippetNode.execute(frame, "Rubinius::Type.coerce_to_path(object)", "object", object);
}

}
29 changes: 21 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/core/hash/HashNodes.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
@@ -85,7 +86,11 @@ public ConstructNode(RubyContext context, SourceSection sourceSection) {

@ExplodeLoop
@Specialization(guards = "isSmallArrayOfPairs(args)")
public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] args) {
public Object construct(
VirtualFrame frame,
DynamicObject hashClass,
Object[] args,
@Cached("new()") SnippetNode snippetNode) {
final DynamicObject array = (DynamicObject) args[0];

final Object[] store = (Object[]) Layouts.ARRAY.getStore(array);
@@ -98,18 +103,18 @@ public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] ar
final Object pair = store[n];

if (!RubyGuards.isRubyArray(pair)) {
return constructFallback(frame, hashClass, args);
return snippetNode.execute(frame, "_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

final DynamicObject pairArray = (DynamicObject) pair;
final Object pairStore = Layouts.ARRAY.getStore(pairArray);

if (pairStore != null && pairStore.getClass() != Object[].class) {
return constructFallback(frame, hashClass, args);
return snippetNode.execute(frame, "_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

if (Layouts.ARRAY.getSize(pairArray) != 2) {
return constructFallback(frame, hashClass, args);
return snippetNode.execute(frame, "_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

final Object[] pairObjectStore = (Object[]) pairStore;
@@ -127,8 +132,12 @@ public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] ar
}

@Specialization(guards = "!isSmallArrayOfPairs(args)")
public Object constructFallback(VirtualFrame frame, DynamicObject hashClass, Object[] args) {
return ruby("_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
public Object constructFallback(
VirtualFrame frame,
DynamicObject hashClass,
Object[] args,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

public boolean isSmallArrayOfPairs(Object[] args) {
@@ -769,8 +778,12 @@ public DynamicObject replaceBuckets(DynamicObject self, DynamicObject from) {
}

@Specialization(guards = "!isRubyHash(other)")
public Object replaceBuckets(VirtualFrame frame, DynamicObject self, Object other) {
return ruby("replace(Rubinius::Type.coerce_to other, Hash, :to_hash)", "other", other);
public Object replaceBuckets(
VirtualFrame frame,
DynamicObject self,
Object other,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "replace(Rubinius::Type.coerce_to other, Hash, :to_hash)", "other", other);
}

private void copyOtherFields(DynamicObject self, DynamicObject from) {
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
@@ -26,6 +27,7 @@
import org.jruby.truffle.core.cast.BooleanCastNode;
import org.jruby.truffle.core.cast.BooleanCastNodeGen;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
@@ -120,8 +122,12 @@ public Object mul(DynamicObject a, DynamicObject b) {
}

@Specialization(guards = {"!isInteger(b)", "!isLong(b)", "!isDouble(b)", "!isRubyBignum(b)"})
public Object mul(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("redo_coerced :*, other", "other", b);
public Object mul(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "redo_coerced :*, other", "other", b);
}

}
@@ -189,8 +195,12 @@ public Object mod(DynamicObject a, DynamicObject b) {
}

@Specialization(guards = {"!isInteger(b)", "!isLong(b)", "!isRubyBignum(b)"})
public Object mod(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("redo_coerced :%, other", "other", b);
public Object mod(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "redo_coerced :%, other", "other", b);
}

}
@@ -218,8 +228,12 @@ public boolean less(DynamicObject a, DynamicObject b) {
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessCoerced(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("b, a = math_coerce other, :compare_error; a < b", "other", b);
public Object lessCoerced(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "b, a = math_coerce other, :compare_error; a < b", "other", b);
}

}
@@ -247,8 +261,12 @@ public boolean lessEqual(DynamicObject a, DynamicObject b) {
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessEqualCoerced(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("b, a = math_coerce other, :compare_error; a <= b", "other", b);
public Object lessEqualCoerced(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "b, a = math_coerce other, :compare_error; a <= b", "other", b);
}
}

@@ -319,8 +337,12 @@ public boolean greaterEqual(DynamicObject a, DynamicObject b) {
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterEqualCoerced(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("b, a = math_coerce other, :compare_error; a >= b", "other", b);
public Object greaterEqualCoerced(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "b, a = math_coerce other, :compare_error; a >= b", "other", b);
}
}

@@ -347,8 +369,12 @@ public boolean greater(DynamicObject a, DynamicObject b) {
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterCoerced(VirtualFrame frame, DynamicObject a, Object b) {
return ruby("b, a = math_coerce other, :compare_error; a > b", "other", b);
public Object greaterCoerced(
VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame, "b, a = math_coerce other, :compare_error; a > b", "other", b);
}
}

Loading