Skip to content

Commit b92dfbb

Browse files
committed
[GR-15990] Move the SafepointManager Assumption to RubyLanguage
* Only store the language in RubyRootNode, WhileRepeatingBaseNode
1 parent 7d025e8 commit b92dfbb

22 files changed

+90
-61
lines changed

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class RubyContext {
100100
@CompilationFinal private TruffleFile rubyHomeTruffleFile;
101101
@CompilationFinal private boolean hadHome;
102102

103-
private final SafepointManager safepointManager = new SafepointManager(this);
103+
private final SafepointManager safepointManager;
104104
private final InteropManager interopManager = new InteropManager(this);
105105
private final CodeLoader codeLoader = new CodeLoader(this);
106106
private final FeatureLoader featureLoader;
@@ -165,6 +165,7 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
165165

166166
options = createOptions(env, language.options);
167167

168+
safepointManager = new SafepointManager(this, language);
168169
frozenStringLiterals = new FrozenStringLiterals(this, language);
169170
coreExceptions = new CoreExceptions(this, language);
170171
encodingManager = new EncodingManager(this, language);

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.Objects;
1414
import java.util.concurrent.atomic.AtomicLong;
15+
import java.util.concurrent.locks.ReentrantLock;
1516

1617
import com.oracle.truffle.api.CompilerDirectives;
1718
import com.oracle.truffle.api.instrumentation.AllocationReporter;
@@ -115,7 +116,7 @@
115116
StandardTags.ReadVariableTag.class,
116117
StandardTags.WriteVariableTag.class,
117118
})
118-
public class RubyLanguage extends TruffleLanguage<RubyContext> {
119+
public final class RubyLanguage extends TruffleLanguage<RubyContext> {
119120

120121
public static final String PLATFORM = String.format(
121122
"%s-%s%s",
@@ -138,6 +139,11 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
138139
.createAssumption("single RubyContext per RubyLanguage instance");
139140
public final CyclicAssumption traceFuncUnusedAssumption = new CyclicAssumption("set_trace_func is not used");
140141

142+
private final ReentrantLock safepointLock = new ReentrantLock();
143+
@CompilationFinal private Assumption safepointAssumption = Truffle
144+
.getRuntime()
145+
.createAssumption("SafepointManager");
146+
141147
public final CoreMethodAssumptions coreMethodAssumptions;
142148
public final CoreStrings coreStrings;
143149
public final CoreSymbols coreSymbols;
@@ -222,6 +228,20 @@ public void invalidateTracingAssumption() {
222228
tracingAssumption = tracingCyclicAssumption.getAssumption();
223229
}
224230

231+
public Assumption getSafepointAssumption() {
232+
return safepointAssumption;
233+
}
234+
235+
public void invalidateSafepointAssumption(String reason) {
236+
safepointLock.lock();
237+
safepointAssumption.invalidate(reason);
238+
}
239+
240+
public void resetSafepointAssumption() {
241+
safepointAssumption = Truffle.getRuntime().createAssumption("SafepointManager");
242+
safepointLock.unlock();
243+
}
244+
225245
@Override
226246
protected void initializeMultipleContexts() {
227247
// TODO Make Symbol.all_symbols per context, by having a SymbolTable per context and creating new symbols with

src/main/java/org/truffleruby/builtins/CoreMethodNodeManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void addCoreMethod(RubyModule module, MethodDetails methodDetails) {
145145

146146
final Function<SharedMethodInfo, RootCallTarget> callTargetFactory = sharedMethodInfo -> {
147147
final RubyNode methodNode = createCoreMethodNode(nodeFactory, annotation, sharedMethodInfo);
148-
return createCallTarget(context, sharedMethodInfo, methodNode, split);
148+
return createCallTarget(language, sharedMethodInfo, methodNode, split);
149149
};
150150

151151
addMethods(module, isModuleFunc, onSingleton, names, arity, visibility, callTargetFactory);
@@ -173,7 +173,7 @@ public void addLazyCoreMethod(
173173
final NodeFactory<? extends RubyNode> nodeFactory = loadNodeFactory(nodeFactoryName);
174174
final CoreMethod annotation = nodeFactory.getNodeClass().getAnnotation(CoreMethod.class);
175175
final RubyNode methodNode = createCoreMethodNode(nodeFactory, annotation, sharedMethodInfo);
176-
return createCallTarget(context, sharedMethodInfo, methodNode, finalSplit);
176+
return createCallTarget(language, sharedMethodInfo, methodNode, finalSplit);
177177
};
178178

179179
addMethods(module, isModuleFunc, onSingleton, names, arity, visibility, callTargetFactory);
@@ -235,10 +235,10 @@ private static Arity createArity(int required, int optional, boolean rest, Strin
235235
: new Arity(required, optional, rest, 0, new String[]{ keywordAsOptional }, true, false);
236236
}
237237

238-
private static RootCallTarget createCallTarget(RubyContext context, SharedMethodInfo sharedMethodInfo,
238+
private static RootCallTarget createCallTarget(RubyLanguage language, SharedMethodInfo sharedMethodInfo,
239239
RubyNode methodNode, Split split) {
240240
final RubyRootNode rootNode = new RubyRootNode(
241-
context,
241+
language,
242242
sharedMethodInfo.getSourceSection(),
243243
null,
244244
sharedMethodInfo,

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.truffleruby.language.RubyGuards;
7272
import org.truffleruby.language.RubyNode;
7373
import org.truffleruby.language.RubyRootNode;
74+
import org.truffleruby.language.SafepointManager;
7475
import org.truffleruby.language.Visibility;
7576
import org.truffleruby.language.arguments.RubyArguments;
7677
import org.truffleruby.language.backtrace.Backtrace;
@@ -1484,7 +1485,7 @@ public abstract static class CheckThreadInterrupt extends CoreMethodArrayArgumen
14841485

14851486
@Specialization
14861487
protected Object checkInts() {
1487-
getContext().getSafepointManager().poll(this);
1488+
SafepointManager.poll(getLanguage(), this);
14881489
return nil;
14891490
}
14901491
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.truffleruby.builtins.Primitive;
2323
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
2424
import org.truffleruby.collections.WeakValueCache;
25+
import org.truffleruby.language.SafepointManager;
2526

2627
@CoreModule("GC")
2728
public abstract class GCNodes {
@@ -68,7 +69,7 @@ protected Object force() {
6869

6970
do {
7071
System.gc();
71-
getContext().getSafepointManager().poll(this);
72+
SafepointManager.poll(getLanguage(), this);
7273
} while (cache.get(key) != null);
7374

7475
return nil;

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ private InternalMethod createMissingMethod(Object self, Object name, String norm
13131313

13141314
final RubyNode newBody = new CallMethodMissingWithStaticName(name);
13151315
final RubyRootNode newRootNode = new RubyRootNode(
1316-
getContext(),
1316+
getLanguage(),
13171317
info.getSourceSection(),
13181318
new FrameDescriptor(nil),
13191319
info,

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected RootCallTarget methodCallTarget(InternalMethod method) {
304304

305305
final SetReceiverNode setReceiverNode = new SetReceiverNode(method.getCallTarget());
306306
final RootNode newRootNode = new RubyRootNode(
307-
getContext(),
307+
getLanguage(),
308308
sourceSection,
309309
oldRootNode.getFrameDescriptor(),
310310
method.getSharedMethodInfo(),

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ private void createAccessor(RubyModule module, String name, MaterializedFrame ca
436436
final RubyNode body = Translator
437437
.createCheckArityNode(language, arity, accessInstanceVariable);
438438
final RubyRootNode rootNode = new RubyRootNode(
439-
getContext(),
439+
language,
440440
sourceSection,
441441
null,
442442
sharedMethodInfo,
@@ -1214,7 +1214,7 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
12141214
final RubyNode body = NodeUtil.cloneNode(rootNode.getBody());
12151215
final RubyNode newBody = new CallMethodWithProcBody(proc.declarationFrame, body);
12161216
final RubyRootNode newRootNode = new RubyRootNode(
1217-
getContext(),
1217+
getLanguage(),
12181218
info.getSourceSection(),
12191219
rootNode.getFrameDescriptor(),
12201220
info,

src/main/java/org/truffleruby/core/mutex/ConditionVariableNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.truffleruby.core.thread.ThreadManager;
2626
import org.truffleruby.core.thread.ThreadStatus;
2727
import org.truffleruby.language.Nil;
28+
import org.truffleruby.language.SafepointManager;
2829
import org.truffleruby.language.Visibility;
2930
import org.truffleruby.language.objects.AllocateHelperNode;
3031

@@ -169,7 +170,7 @@ private void awaitSignal(RubyConditionVariable self, RubyThread thread, long dur
169170
* the safepoint, and acquire it again before resuming waiting. */
170171
condLock.unlock();
171172
try {
172-
getContext().getSafepointManager().pollFromBlockingCall(this);
173+
SafepointManager.pollFromBlockingCall(getLanguage(), this);
173174
} finally {
174175
condLock.lock();
175176
}

src/main/java/org/truffleruby/core/symbol/SymbolNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static RubyProc createProc(RubyContext context, RubyLanguage language,
176176
declarationFrame.setObject(context.getCoreLibrary().emptyDeclarationSpecialVariableSlot, variables);
177177

178178
final RubyRootNode rootNode = new RubyRootNode(
179-
context,
179+
language,
180180
sourceSection,
181181
new FrameDescriptor(nil),
182182
sharedMethodInfo,

0 commit comments

Comments
 (0)