Skip to content

Commit

Permalink
[Truffle] Better way to detect Truffle::Boot.run_jruby_root.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 23, 2016
1 parent 7c6780e commit b334c08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 13 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Expand Up @@ -118,6 +118,7 @@
import org.jruby.truffle.language.loader.SourceLoader;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.objects.FreezeNode;
import org.jruby.truffle.language.objects.FreezeNodeGen;
import org.jruby.truffle.language.objects.SingletonClassNode;
Expand Down Expand Up @@ -242,6 +243,7 @@ public class CoreLibrary {
private final DynamicObject rubiniusFFIPointerClass;
private final DynamicObject signalModule;
private final DynamicObject truffleModule;
private final DynamicObject truffleBootModule;
private final DynamicObject truffleInteropModule;
private final DynamicObject bigDecimalClass;
private final DynamicObject encodingCompatibilityErrorClass;
Expand Down Expand Up @@ -282,6 +284,7 @@ public class CoreLibrary {
private final Map<Errno, DynamicObject> errnoClasses = new HashMap<>();

@CompilationFinal private InternalMethod basicObjectSendMethod;
@CompilationFinal private InternalMethod truffleBootRunJRubyRootMethod;

@CompilationFinal private GlobalVariableStorage loadPathStorage;
@CompilationFinal private GlobalVariableStorage loadedFeaturesStorage;
Expand Down Expand Up @@ -337,6 +340,10 @@ public SingletonClassNode getSingletonClassNode() {
return singletonClassNode;
}

public DynamicObject getSingletonClass(Object object) {
return singletonClassNode.executeSingletonClass(object);
}

@Override
public Object execute(VirtualFrame frame) {
return nil();
Expand Down Expand Up @@ -586,7 +593,7 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "String");
final DynamicObject attachments = defineModule(truffleModule, "Attachments");
defineModule(attachments, "Internal");
defineModule(truffleModule, "Boot");
truffleBootModule = defineModule(truffleModule, "Boot");
defineModule(truffleModule, "Fixnum");
defineModule(truffleModule, "Safe");
defineModule(truffleModule, "System");
Expand Down Expand Up @@ -803,6 +810,7 @@ public void addCoreMethods(PrimitiveManager primitiveManager) {
coreMethodNodeManager.allMethodInstalled();

basicObjectSendMethod = getMethod(basicObjectClass, "__send__");
truffleBootRunJRubyRootMethod = getMethod(node.getSingletonClass(truffleBootModule), "run_jruby_root");
}

private InternalMethod getMethod(DynamicObject module, String name) {
Expand Down Expand Up @@ -1452,6 +1460,10 @@ public boolean isSend(InternalMethod method) {
return callTarget == basicObjectSendMethod.getCallTarget();
}

public boolean isRunJRubyRootMethod(SharedMethodInfo info) {
return info == truffleBootRunJRubyRootMethod.getSharedMethodInfo();
}

public DynamicObjectFactory getIntRangeFactory() {
return intRangeFactory;
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
Expand All @@ -27,6 +28,7 @@
import org.jruby.truffle.language.backtrace.InternalRootNode;
import org.jruby.truffle.language.exceptions.DisablingBacktracesNode;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.util.Memo;

import java.util.ArrayList;
Expand Down Expand Up @@ -221,16 +223,17 @@ private boolean ignoreFrame(FrameInstance frameInstance) {
return false;
}

// Ignore the call to run_jruby_root
// TODO CS 2-Feb-16 should find a better way to detect this than a string
final RootNode rootNode = callNode.getRootNode();

final String name = callNode.getRootNode().getName();

if (name != null && name.equals("run_jruby_root")) {
return true;
// Ignore the call to Truffle::Boot.run_jruby_root
if (rootNode instanceof RubyRootNode) {
SharedMethodInfo sharedMethodInfo = ((RubyRootNode) rootNode).getSharedMethodInfo();
if (context.getCoreLibrary().isRunJRubyRootMethod(sharedMethodInfo)) {
return true;
}
}

if (callNode.getRootNode() instanceof InternalRootNode) {
if (rootNode instanceof InternalRootNode) {
return true;
}

Expand Down

0 comments on commit b334c08

Please sign in to comment.