Skip to content

Commit

Permalink
[Truffle] Use the proper technique to find the correct Ruby context.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 31, 2016
1 parent 4d35ae3 commit 407dd85
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Expand Up @@ -317,8 +317,8 @@ public CoverageManager getCoverageManager() {
return coverageManager;
}

public static RubyContext getLatestInstance() {
return latestInstance;
public static RubyContext getInstance() {
return RubyLanguage.INSTANCE.unprotectedFindContext(RubyLanguage.INSTANCE.unprotectedCreateFindContextNode());
}

public AttachmentsManager getAttachmentsManager() {
Expand Down
Expand Up @@ -29,7 +29,7 @@ public abstract class DebugHelpers {

@Deprecated
public static Object eval(String code, Object... arguments) {
return eval(RubyContext.getLatestInstance(), code, arguments);
return eval(RubyContext.getInstance(), code, arguments);
}

@Deprecated
Expand Down
Expand Up @@ -42,20 +42,18 @@ public class LazyRubyRootNode extends RootNode implements InternalRootNode {
@CompilationFinal private DynamicObject mainObject;
@CompilationFinal private InternalMethod method;

@Child private Node findContextNode;
@Child private DirectCallNode callNode;

public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source,
String[] argumentNames) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
this.source = source;
this.argumentNames = argumentNames;
this.findContextNode = RubyLanguage.INSTANCE.unprotectedCreateFindContextNode();
}

@Override
public Object execute(VirtualFrame frame) {
final RubyContext context = RubyLanguage.INSTANCE.unprotectedFindContext(findContextNode);
final RubyContext context = RubyContext.getInstance();

if (cachedContext == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Expand Down
Expand Up @@ -177,10 +177,7 @@ public RubyContext getContext() {

while (true) {
if (parent == null) {
System.err.println("warning: using global context!");
context = RubyContext.getLatestInstance();
break;
//throw new UnsupportedOperationException("can't get the RubyContext because the parent is null");
context = RubyContext.getInstance();

This comment has been minimized.

Copy link
@eregon

eregon Nov 1, 2016

Member

I think this should still warn as it's very inefficient.

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Nov 1, 2016

Author Contributor

The warning wasn't originally about the inefficiency - it was about using the last context which may not be the one you want.

We'll only use this inefficient case in a few places - during startup when we create a couple of little nodes for doing things like freezing parts of the core library as we load, and when foreign languages create Ruby access nodes. In the latter case there really is no other way to get the correct context. So I don't think it's a problem.

}

if (parent instanceof RubyBaseNode) {
Expand Down

0 comments on commit 407dd85

Please sign in to comment.