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: 477d6a6ed625
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 016c15a276e3
Choose a head ref
  • 4 commits
  • 11 files changed
  • 1 contributor

Commits on Feb 14, 2016

  1. Copy the full SHA
    a46cb33 View commit details
  2. Copy the full SHA
    530b0f4 View commit details
  3. 5
    Copy the full SHA
    673a4c3 View commit details
  4. Copy the full SHA
    016c15a View commit details
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails

final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, sequence, method.unsupportedOperationBehavior());

return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode, false);
}

public void allMethodInstalled() {
20 changes: 8 additions & 12 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -2242,12 +2242,10 @@ public MaxBlock(RubyContext context) {

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "max", false, null, false, false, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
}), false));
}

public FrameDescriptor getFrameDescriptor() {
@@ -2362,12 +2360,10 @@ public MinBlock(RubyContext context) {

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "min", false, null, false, false, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
}), false));
}

public FrameDescriptor getFrameDescriptor() {
Original file line number Diff line number Diff line change
@@ -1295,7 +1295,7 @@ public DynamicObject method(VirtualFrame frame, Object self, DynamicObject name)
final SharedMethodInfo info = methodMissing.getSharedMethodInfo().withName(normalizedName);

final RubyNode newBody = new CallMethodMissingWithStaticName(getContext(), info.getSourceSection(), name);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), new FrameDescriptor(nil()), info, newBody);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), new FrameDescriptor(nil()), info, newBody, false);
final CallTarget newCallTarget = Truffle.getRuntime().createCallTarget(newRootNode);

final DynamicObject module = getContext().getCoreLibrary().getMetaClass(self);
Original file line number Diff line number Diff line change
@@ -264,7 +264,7 @@ protected CallTarget method2proc(DynamicObject methodObject) {
final RootNode oldRootNode = ((RootCallTarget) method.getCallTarget()).getRootNode();

final SetReceiverNode setReceiverNode = new SetReceiverNode(getContext(), sourceSection, Layouts.METHOD.getReceiver(methodObject), method.getCallTarget());
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getSharedMethodInfo(), setReceiverNode);
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getSharedMethodInfo(), setReceiverNode, false);
return Truffle.getRuntime().createCallTarget(newRootNode);
}

Original file line number Diff line number Diff line change
@@ -432,7 +432,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = SequenceNode.sequence(getContext(), sourceSection, checkArity, accessInstanceVariable);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence, false);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, accessorName, module, visibility, callTarget);

@@ -1143,7 +1143,7 @@ private DynamicObject defineMethod(DynamicObject module, String name, DynamicObj

final RubyNode body = NodeUtil.cloneNode(rootNode.getBody());
final RubyNode newBody = new CallMethodWithProcBody(getContext(), info.getSourceSection(), Layouts.PROC.getDeclarationFrame(proc), body);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), rootNode.getFrameDescriptor(), info, newBody);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), rootNode.getFrameDescriptor(), info, newBody, false);
final CallTarget newCallTarget = Truffle.getRuntime().createCallTarget(newRootNode);

final InternalMethod method = InternalMethod.fromProc(info, name, module, Visibility.PUBLIC, proc, newCallTarget);
Original file line number Diff line number Diff line change
@@ -148,13 +148,9 @@ protected DynamicObject createProc(VirtualFrame frame, DynamicObject symbol) {
sourceSection, null, Arity.AT_LEAST_ONE, Layouts.SYMBOL.getString(symbol),
true, ArgumentDescriptor.ANON_REST, false, false, false);

final RubyRootNode rootNode = new RubyRootNode(
getContext(), sourceSection,
new FrameDescriptor(nil()),
sharedMethodInfo,
SequenceNode.sequence(getContext(), sourceSection,
CheckArityNode.create(getContext(), sourceSection, Arity.AT_LEAST_ONE),
new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol))));
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, SequenceNode.sequence(getContext(), sourceSection,
CheckArityNode.create(getContext(), sourceSection, Arity.AT_LEAST_ONE),
new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol))), false);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = RubyArguments.getMethod(frame.getArguments());
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ public class LazyRubyRootNode extends RootNode implements InternalRootNode {
@Child private Node findContextNode;
@Child private DirectCallNode callNode;

public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source, String[] argumentNames) {
public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source,
String[] argumentNames) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
this.source = source;
this.argumentNames = argumentNames;
@@ -55,7 +56,7 @@ public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescri
@Override
public Object execute(VirtualFrame frame) {
if (findContextNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
CompilerDirectives.transferToInterpreter();
findContextNode = insert(RubyLanguage.INSTANCE.unprotectedCreateFindContextNode());
}

@@ -73,14 +74,19 @@ public Object execute(VirtualFrame frame) {
final SourceSection sourceSection = (SourceSection) frame.getArguments()[getIndex("section")];
final DynamicObject block = (DynamicObject) frame.getArguments()[getIndex("block")];

final RootNode rootNode = new AttachmentsManager.AttachmentRootNode(RubyLanguage.class, cachedContext, sourceSection, null, block);
final RootNode rootNode = new AttachmentsManager.AttachmentRootNode(RubyLanguage.class, cachedContext,
sourceSection, null, block);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

callNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget));
callNode.forceInlining();
} else {
final TranslatorDriver translator = new TranslatorDriver(context);
final RubyRootNode rootNode = translator.parse(context, source, UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, argumentNames, null, true, null);

final RubyRootNode rootNode = translator.parse(context, source, UTF8Encoding.INSTANCE,
ParserContext.TOP_LEVEL, argumentNames, null, true, null);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

callNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget));
@@ -93,12 +99,14 @@ public Object execute(VirtualFrame frame) {
}

if (method == null) {
final MaterializedFrame callerFrame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();
final MaterializedFrame callerFrame = Truffle.getRuntime().getCallerFrame()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();

return callNode.call(frame, new Object[] { callerFrame });
}

return callNode.call(frame,
RubyArguments.pack(null, null, method, DeclarationContext.TOP_LEVEL, null, mainObject, null, frame.getArguments()));
return callNode.call(frame, RubyArguments.pack(null, null, method, DeclarationContext.TOP_LEVEL, null,
mainObject, null, frame.getArguments()));
}

private int getIndex(String name) {
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ public String toString(DynamicObject object) {
} else if (RubyGuards.isRubyModule(object)) {
return Layouts.MODULE.getFields(object).toString();
} else {
return String.format("DynamicObject@%x<logicalClass=%s>", System.identityHashCode(object), Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName());
return String.format("DynamicObject@%x<logicalClass=%s>", System.identityHashCode(object),
Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName());
}
}

58 changes: 26 additions & 32 deletions truffle/src/main/java/org/jruby/truffle/language/RubyRootNode.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.language;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.ExecutionContext;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -20,36 +19,37 @@
import org.jruby.truffle.RubyLanguage;
import org.jruby.truffle.language.methods.SharedMethodInfo;

/**
* The root node in an AST for a method. Unlike {@link RubyNode}, this has a single entry point,
* {@link #execute}, which Truffle knows about and can create a {@link CallTarget} from.
*/
public class RubyRootNode extends RootNode {

private final RubyContext context;
private final SharedMethodInfo sharedMethodInfo;
@Child private RubyNode body;
private final boolean needsDeclarationFrame;

public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body) {
this(context, sourceSection, frameDescriptor, sharedMethodInfo, body, false);
}
@Child private RubyNode body;

public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body, boolean needsDeclarationFrame) {
public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor,
SharedMethodInfo sharedMethodInfo, RubyNode body, boolean needsDeclarationFrame) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
assert body != null;
this.context = context;
this.body = body;
this.sharedMethodInfo = sharedMethodInfo;
this.needsDeclarationFrame = needsDeclarationFrame;
this.body = body;

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(this);
}
}

public RubyRootNode withBody(RubyNode body) {
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, body, needsDeclarationFrame);
@Override
public Object execute(VirtualFrame frame) {
context.getSafepointManager().poll(this);
return body.execute(frame);
}

@Override
public ExecutionContext getExecutionContext() {
return context;
}

@Override
@@ -58,16 +58,26 @@ public boolean isCloningAllowed() {
}

@Override
public Object execute(VirtualFrame frame) {
context.getSafepointManager().poll(this);
return body.execute(frame);
public Node copy() {
final RubyRootNode cloned = (RubyRootNode) super.copy();

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(cloned);
}

return cloned;
}

@Override
public String toString() {
return sharedMethodInfo.toString();
}

public RubyRootNode withBody(RubyNode body) {
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, body,
needsDeclarationFrame);
}

public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}
@@ -76,24 +86,8 @@ public RubyNode getBody() {
return body;
}

@Override
public ExecutionContext getExecutionContext() {
return context;
}

public boolean needsDeclarationFrame() {
return needsDeclarationFrame;
}

@Override
public Node copy() {
final RubyRootNode cloned = (RubyRootNode) super.copy();

if (context.getCallGraph() != null) {
context.getCallGraph().registerRootNode(cloned);
}

return cloned;
}

}

This file was deleted.

Loading