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

Commits on Apr 7, 2016

  1. Copy the full SHA
    a888c72 View commit details
  2. [Truffle] Fix typo.

    eregon committed Apr 7, 2016
    Copy the full SHA
    84dd31e View commit details
  3. Copy the full SHA
    83b8d31 View commit details
  4. Copy the full SHA
    81a1f80 View commit details
  5. Copy the full SHA
    7e4756a View commit details
  6. Copy the full SHA
    88e6e6a View commit details
  7. Copy the full SHA
    e7e1541 View commit details
Original file line number Diff line number Diff line change
@@ -777,7 +777,7 @@ public void initializeAfterBasicMethodsAdded() {
try {
final RubyRootNode rootNode = context.getCodeLoader().parse(context.getSourceCache().getSource(getCoreLoadPath() + "/core.rb"), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, node);
final CodeLoader.DeferredCall deferredCall = context.getCodeLoader().prepareExecute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, context.getCoreLibrary().getMainObject());
deferredCall.getCallTarget().call(deferredCall.getArguments());
deferredCall.callWithoutCallNode();
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject st
final Source source = Source.fromText(code.toString(), "(eval)");
final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, code.getEncoding(), ParserContext.EVAL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.EVAL, DeclarationContext.INSTANCE_EVAL, rootNode, null, receiver);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -604,7 +604,7 @@ public Object evalNoBindingUncached(VirtualFrame frame, DynamicObject source, No
final MaterializedFrame topFrame = Layouts.BINDING.getFrame(binding);
RubyArguments.setSelf(topFrame.getArguments(), RubyArguments.getSelf(frame));
final CodeLoader.DeferredCall deferredCall = doEvalX(source, binding, "(eval)", 1, true);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);

}

@@ -625,7 +625,7 @@ public Object evalNilBinding(VirtualFrame frame, DynamicObject source, DynamicOb
public Object evalBinding(VirtualFrame frame, DynamicObject source, DynamicObject binding, NotProvided filename,
NotProvided lineNumber, @Cached("create()") IndirectCallNode callNode) {
final CodeLoader.DeferredCall deferredCall = doEvalX(source, binding, "(eval)", 1, false);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}

@Specialization(guards = {
@@ -664,7 +664,7 @@ public Object evalBindingFilename(VirtualFrame frame, DynamicObject source, Dyna
public Object evalBindingFilenameLine(VirtualFrame frame, DynamicObject source, DynamicObject binding, DynamicObject filename,
int lineNumber, @Cached("create()") IndirectCallNode callNode) {
final CodeLoader.DeferredCall deferredCall = doEvalX(source, binding, filename.toString(), lineNumber, false);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -40,9 +40,8 @@
import org.jruby.truffle.language.arguments.ArgumentDescriptorUtils;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.CallMethodNode;
import org.jruby.truffle.language.methods.CallMethodNodeGen;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.CallBoundMethodNode;
import org.jruby.truffle.language.methods.CallBoundMethodNodeGen;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.LogicalClassNode;
import org.jruby.truffle.language.objects.LogicalClassNodeGen;
@@ -96,25 +95,18 @@ public int arity(DynamicObject method) {
@CoreMethod(names = { "call", "[]" }, needsBlock = true, rest = true)
public abstract static class CallNode extends CoreMethodArrayArgumentsNode {

@Child CallBoundMethodNode callBoundMethodNode;
@Child ProcOrNullNode procOrNullNode;
@Child CallMethodNode callMethodNode;

public CallNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
callBoundMethodNode = CallBoundMethodNodeGen.create(context, sourceSection, null, null, null);
procOrNullNode = ProcOrNullNodeGen.create(context, sourceSection, null);
callMethodNode = CallMethodNodeGen.create(context, sourceSection, null, null);
}

@Specialization
protected Object call(VirtualFrame frame, DynamicObject method, Object[] arguments, Object block) {
final InternalMethod internalMethod = Layouts.METHOD.getMethod(method);
final Object[] frameArguments = packArguments(method, internalMethod, arguments, block);

return callMethodNode.executeCallMethod(frame, internalMethod, frameArguments);
}

private Object[] packArguments(DynamicObject method, InternalMethod internalMethod, Object[] arguments, Object block) {
return RubyArguments.pack(null, null, internalMethod, DeclarationContext.METHOD, null, Layouts.METHOD.getReceiver(method), procOrNullNode.executeProcOrNull(block), arguments);
return callBoundMethodNode.executeCallBoundMethod(frame, method, arguments, procOrNullNode.executeProcOrNull(block));
}

}
Original file line number Diff line number Diff line change
@@ -649,7 +649,7 @@ public Object classEval(VirtualFrame frame, DynamicObject module, DynamicObject
@Specialization(guards = {"isRubyString(code)", "isRubyString(file)"})
public Object classEval(VirtualFrame frame, DynamicObject module, DynamicObject code, DynamicObject file, int line, NotProvided block, @Cached("create()") IndirectCallNode callNode) {
final CodeLoader.DeferredCall deferredCall = classEvalSource(module, code, file.toString(), line);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}

@Specialization(guards = "wasProvided(code)")
@@ -664,7 +664,7 @@ public Object classEval(VirtualFrame frame, DynamicObject module, DynamicObject

private Object classEvalSource(VirtualFrame frame, DynamicObject module, DynamicObject code, String file, @Cached("create()") IndirectCallNode callNode) {
final CodeLoader.DeferredCall deferredCall = classEvalSource(module, code, file, 1);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -64,7 +64,6 @@
import org.jruby.util.ByteList;
import org.jruby.util.Memo;
import org.jruby.util.unsafe.UnsafeHolder;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -832,7 +831,7 @@ public boolean load(VirtualFrame frame, DynamicObject file, boolean wrap, @Cache
try {
final RubyRootNode rootNode = getContext().getCodeLoader().parse(getContext().getSourceCache().getSource(StringOperations.getString(getContext(), file)), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, getContext().getCoreLibrary().getMainObject());
callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
deferredCall.call(frame, callNode);
} catch (IOException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreLibrary().loadErrorCannotLoad(file.toString(), this));
@@ -890,7 +889,7 @@ public Object runJRubyRootNode(VirtualFrame frame, @Cached("create()")IndirectCa
null,
coreLibrary().getMainObject());

return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
return deferredCall.call(frame, callNode);
}
}

@@ -1021,14 +1020,17 @@ public RequireCoreNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(feature)")
public boolean requireRelative(VirtualFrame frame, DynamicObject feature, @Cached("create()") IndirectCallNode callNode) {
if (!(getContext().getCoreLibrary().isLoadingRubyCore() || getContext().getOptions().PLATFORM_SAFE_LOAD)) {
throw new RaiseException(getContext().getCoreLibrary().internalErrorUnsafe(this));
final CoreLibrary coreLibrary = getContext().getCoreLibrary();
if (!(coreLibrary.isLoadingRubyCore() || getContext().getOptions().PLATFORM_SAFE_LOAD)) {
throw new RaiseException(coreLibrary.internalErrorUnsafe(this));
}

final CodeLoader codeLoader = getContext().getCodeLoader();
final String path = coreLibrary.getCoreLoadPath() + "/" + feature.toString() + ".rb";
try {
final RubyRootNode rootNode = getContext().getCodeLoader().parse(getContext().getSourceCache().getSource(getContext().getCoreLibrary().getCoreLoadPath() + "/" + feature.toString() + ".rb"), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, getContext().getCoreLibrary().getMainObject());
deferredCall.getCallTarget().call(deferredCall.getArguments());
final RubyRootNode rootNode = codeLoader.parse(getContext().getSourceCache().getSource(path), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
final CodeLoader.DeferredCall deferredCall = codeLoader.prepareExecute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, coreLibrary.getMainObject());
deferredCall.callWithoutCallNode();
} catch (IOException e) {
throw new RuntimeException(e);
}
129 changes: 18 additions & 111 deletions truffle/src/main/java/org/jruby/truffle/interop/ForeignExecuteNode.java
Original file line number Diff line number Diff line change
@@ -9,16 +9,13 @@
*/
package org.jruby.truffle.interop;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.AcceptMessage;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.Node.Child;
import com.oracle.truffle.api.object.DynamicObject;
@@ -28,9 +25,11 @@
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyObjectType;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.methods.CallBoundMethodNode;
import org.jruby.truffle.language.methods.CallBoundMethodNodeGen;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.yield.CallBlockNode;
import org.jruby.truffle.language.yield.CallBlockNodeGen;

@AcceptMessage(value = "EXECUTE", receiverType = RubyObjectType.class, language = RubyLanguage.class)
public final class ForeignExecuteNode extends ForeignExecuteBaseNode {
@@ -60,123 +59,31 @@ private HelperNode getHelperNode() {
})
protected static abstract class HelperNode extends RubyNode {

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

public abstract Object executeCall(VirtualFrame frame, Object receiver, Object[] arguments);

@Specialization(
guards = {
"isRubyProc(proc)",
"proc == cachedProc"
},
limit = "getCacheLimit()"
)
protected Object callProcCached(
VirtualFrame frame,
DynamicObject proc,
Object[] arguments,
@Cached("proc") DynamicObject cachedProc,
@Cached("create(getProcCallTarget(cachedProc))") DirectCallNode callNode) {
return callNode.call(
frame,
RubyArguments.pack(
Layouts.PROC.getDeclarationFrame(cachedProc),
null,
Layouts.PROC.getMethod(cachedProc),
DeclarationContext.METHOD,
null,
Layouts.PROC.getSelf(cachedProc),
null,
arguments));
@Specialization(guards = "isRubyProc(proc)")
protected Object callProc(VirtualFrame frame, DynamicObject proc, Object[] arguments,
@Cached("createCallBlockNode()") CallBlockNode callBlockNode) {
Object self = Layouts.PROC.getSelf(proc);
return callBlockNode.executeCallBlock(frame, proc, self, null, arguments);
}

@Specialization(
guards = "isRubyProc(proc)",
contains = "callProcCached"
)
protected Object callProcUncached(
VirtualFrame frame,
DynamicObject proc,
Object[] arguments,
@Cached("create()") IndirectCallNode callNode) {
return callNode.call(
frame,
getProcCallTarget(proc),
RubyArguments.pack(
Layouts.PROC.getDeclarationFrame(proc),
null,
Layouts.PROC.getMethod(proc),
DeclarationContext.METHOD,
null,
Layouts.PROC.getSelf(proc),
null,
arguments));
protected CallBlockNode createCallBlockNode() {
return CallBlockNodeGen.create(getContext(), getSourceSection(), DeclarationContext.BLOCK, null, null, null, null);
}

protected CallTarget getProcCallTarget(DynamicObject proc) {
return Layouts.PROC.getCallTargetForType(proc);
@Specialization(guards = "isRubyMethod(method)")
protected Object callMethod(VirtualFrame frame, DynamicObject method, Object[] arguments,
@Cached("createCallBoundMethodNode()") CallBoundMethodNode callBoundMethodNode) {
return callBoundMethodNode.executeCallBoundMethod(frame, method, arguments, null);
}

@Specialization(
guards = {
"isRubyMethod(method)",
"method == cachedMethod"
},
limit = "getCacheLimit()"
)
protected Object callMethodCached(
VirtualFrame frame,
DynamicObject method,
Object[] arguments,
@Cached("method") DynamicObject cachedMethod,
@Cached("getMethod(cachedMethod)") InternalMethod cachedInternalMethod,
@Cached("create(cachedInternalMethod.getCallTarget())") DirectCallNode callNode) {
return callNode.call(
frame,
RubyArguments.pack(
null,
null,
cachedInternalMethod,
DeclarationContext.METHOD,
null,
Layouts.METHOD.getReceiver(cachedMethod),
null,
arguments));
}

@Specialization(
guards = "isRubyMethod(method)",
contains = "callMethodCached"
)
protected Object callMethodUncached(
VirtualFrame frame,
DynamicObject method,
Object[] arguments,
@Cached("create()") IndirectCallNode callNode) {
final InternalMethod internalMethod = getMethod(method);
return callNode.call(
frame,
internalMethod.getCallTarget(),
RubyArguments.pack(
null,
null,
internalMethod,
DeclarationContext.METHOD,
null,
Layouts.METHOD.getReceiver(method),
null,
arguments));
}

protected InternalMethod getMethod(DynamicObject method) {
return Layouts.METHOD.getMethod(method);
}

protected int getCacheLimit() {
return getContext().getOptions().INTEROP_EXECUTE_CACHE;
protected CallBoundMethodNode createCallBoundMethodNode() {
return CallBoundMethodNodeGen.create(getContext(), getSourceSection(), null, null, null);
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
@@ -136,7 +138,7 @@ public Object inline(Node currentNode, Frame frame, String expression, Object...
evalFrame,
RubyArguments.getSelf(evalFrame));

return deferredCall.getCallTarget().call(deferredCall.getArguments());
return deferredCall.callWithoutCallNode();
}

public static class DeferredCall {
@@ -149,13 +151,14 @@ public DeferredCall(CallTarget callTarget, Object[] arguments) {
this.arguments = arguments;
}

public CallTarget getCallTarget() {
return callTarget;
public Object call(VirtualFrame frame, IndirectCallNode callNode) {
return callNode.call(frame, callTarget, arguments);
}

public Object[] getArguments() {
return arguments;
public Object callWithoutCallNode() {
return callTarget.call(arguments);
}

}

}
Loading