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

Commits on Oct 21, 2015

  1. Copy the full SHA
    cb95a82 View commit details
  2. Copy the full SHA
    aeed212 View commit details
  3. [Truffle] Set up the proper DeclarationContext and method for LazyRub…

    …yRootNode.
    
    * Also re-enable the assertion in RubyArguments.pack().
    eregon committed Oct 21, 2015
    Copy the full SHA
    1e621d6 View commit details
Original file line number Diff line number Diff line change
@@ -12,20 +12,24 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.RubyLanguage;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.truffle.translator.TranslatorDriver.ParserContext;

public class LazyRubyRootNode extends RootNode {

private final Source source;

@CompilationFinal private RubyContext cachedContext;
@CompilationFinal private DynamicObject mainObject;
@CompilationFinal private InternalMethod method;

@Child private Node findContextNode;
@Child private DirectCallNode callNode;
@@ -36,37 +40,37 @@ public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescri
}

@Override
public Object execute(VirtualFrame virtualFrame) {
public Object execute(VirtualFrame frame) {
if (findContextNode == null) {
CompilerDirectives.transferToInterpreter();

CompilerDirectives.transferToInterpreterAndInvalidate();
findContextNode = insert(RubyLanguage.INSTANCE.unprotectedCreateFindContextNode());
}

final RubyContext context = RubyLanguage.INSTANCE.unprotectedFindContext(findContextNode);

if (cachedContext == null) {
CompilerDirectives.transferToInterpreter();

CompilerDirectives.transferToInterpreterAndInvalidate();
cachedContext = context;
}

if (callNode == null || context != cachedContext) {
CompilerDirectives.transferToInterpreter();
CompilerDirectives.transferToInterpreterAndInvalidate();

final TranslatorDriver translator = new TranslatorDriver(context);

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

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

callNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget));
callNode.forceInlining();

mainObject = context.getCoreLibrary().getMainObject();
method = new InternalMethod(rootNode.getSharedMethodInfo(), rootNode.getSharedMethodInfo().getName(),
context.getCoreLibrary().getObjectClass(), Visibility.PUBLIC, false, callTarget, null);
}

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

}
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ public final class RubyArguments {
public static final int RUNTIME_ARGUMENT_COUNT = 6;

public static Object[] pack(InternalMethod method, MaterializedFrame declarationFrame, MaterializedFrame callerFrame, Object self, DynamicObject block, DeclarationContext declarationContext, Object[] arguments) {
assert method != null;
assert self != null;
assert block == null || RubyGuards.isRubyProc(block);
assert declarationContext != DeclarationContext.METHOD || method != null;
assert declarationContext != null;
assert arguments != null;

28 changes: 14 additions & 14 deletions truffle/src/test/java/org/jruby/truffle/tck/RubyTckTest.java
Original file line number Diff line number Diff line change
@@ -33,29 +33,29 @@ public void checkVM() {
protected PolyglotEngine prepareVM() throws Exception {
final Source source = Source.fromText(
"def sum(a, b)\n"
+ " a + b\n"
+ " a + b\n"
+ "end\n"
+ "def fourty_two\n"
+ " 42\n"
+ " 42\n"
+ "end\n"
+ "def ret_nil\n"
+ " nil\n"
+ " nil\n"
+ "end\n"
+ "$invocations = 0\n"
+ "def count_invocations\n"
+ " $invocations += 1\n"
+ " $invocations += 1\n"
+ "end\n"
+ "def apply_numbers(f)\n"
+ " Truffle::Interop.execute(f, 18, 32) + 10\n"
+ " Truffle::Interop.execute(f, 18, 32) + 10\n"
+ "end\n"
+ "def compound_object\n"
+ " object = Object.new\n"
+ " def object.fourtyTwo; 42; end\n"
+ " def object.plus(a, b); a + b; end\n"
+ " def object.returnsNull; nil; end\n"
+ " def object.returnsThis; self; end\n"
+ " object\n"
+ "end\n"
+ " obj = Object.new\n"
+ " def obj.fourtyTwo; 42; end\n"
+ " def obj.plus(a, b); a + b; end\n"
+ " def obj.returnsNull; nil; end\n"
+ " def obj.returnsThis; self; end\n"
+ " obj\n"
+ "end\n"
+ "def identity(value)\n"
+ " value\n"
+ "end\n"
@@ -65,8 +65,8 @@ protected PolyglotEngine prepareVM() throws Exception {
+ "Truffle::Interop.export(\"count_invocations\", method(:count_invocations))\n"
+ "Truffle::Interop.export(\"apply_numbers\", method(:apply_numbers))\n"
+ "Truffle::Interop.export(\"compound_object\", method(:compound_object))\n"
+ "Truffle::Interop.export(\"identity\", method(:identity))\n", "test")
.withMimeType(mimeType());
+ "Truffle::Interop.export(\"identity\", method(:identity))\n",
"test").withMimeType(mimeType());
PolyglotEngine engine = PolyglotEngine.buildNew().build();
engine.eval(source);
return engine;