Skip to content

Commit 20f25fc

Browse files
committed
[GR-26546] Replace the RubyContext field from RubyContextSourceNode with ContextReference
PullRequest: truffleruby/2057
2 parents ae2d4ce + 6bfbb65 commit 20f25fc

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected boolean watchSignalProc(RubyString signalString, RubyProc action) {
270270

271271
final RubyThread rootThread = context.getThreadManager().getRootThread();
272272
final FiberManager fiberManager = rootThread.fiberManager;
273-
final ThreadManager threadManager = getContext().getThreadManager();
273+
final ThreadManager threadManager = context.getThreadManager();
274274

275275
// Workaround: we need to register with Truffle (which means going multithreaded),
276276
// so that NFI can get its context to call pthread_kill() (GR-7405).

src/main/java/org/truffleruby/core/cast/TaintResultNode.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ public TaintResultNode(boolean taintFromSelf, int taintFromParameter, RubyNode m
3737
this.taintFromSelf = taintFromSelf;
3838
this.taintFromParameter = taintFromParameter;
3939
this.method = method;
40-
this.rubyLibrarySource = RubyLibrary.getFactory().createDispatched(getRubyLibraryCacheLimit());
4140
}
4241

4342
public TaintResultNode() {
4443
this(false, -1, null);
4544
}
4645

4746
public Object maybeTaint(Object source, Object result) {
48-
if (taintProfile.profile(rubyLibrarySource.isTainted(source))) {
47+
if (taintProfile.profile(isTainted(source))) {
4948
if (rubyLibraryResult == null) {
5049
CompilerDirectives.transferToInterpreterAndInvalidate();
5150
rubyLibraryResult = insert(RubyLibrary.getFactory().createDispatched(getRubyLibraryCacheLimit()));
@@ -56,6 +55,14 @@ public Object maybeTaint(Object source, Object result) {
5655
return result;
5756
}
5857

58+
private boolean isTainted(Object result) {
59+
if (rubyLibrarySource == null) {
60+
CompilerDirectives.transferToInterpreterAndInvalidate();
61+
rubyLibrarySource = insert(RubyLibrary.getFactory().createDispatched(getRubyLibraryCacheLimit()));
62+
}
63+
return rubyLibrarySource.isTainted(result);
64+
}
65+
5966
@Override
6067
public Object execute(VirtualFrame frame) {
6168
final Object result;

src/main/java/org/truffleruby/language/RubyContextSourceNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.language;
1111

12+
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1213
import org.truffleruby.RubyContext;
1314
import org.truffleruby.RubyLanguage;
1415

@@ -60,15 +61,15 @@ protected void setSourceLength(int sourceLength) {
6061

6162
// Context
6263

63-
@CompilationFinal private RubyContext context;
64+
@CompilationFinal private ContextReference<RubyContext> contextReference;
6465

6566
@Override
6667
public RubyContext getContext() {
67-
if (context == null) {
68+
if (contextReference == null) {
6869
CompilerDirectives.transferToInterpreterAndInvalidate();
69-
context = RubyLanguage.getCurrentContext();
70+
contextReference = lookupContextReference(RubyLanguage.class);
7071
}
7172

72-
return context;
73+
return contextReference.get();
7374
}
7475
}

0 commit comments

Comments
 (0)