Skip to content

Commit a0c1ccb

Browse files
committed
[GR-15990] Do not store the context in RubyParsingRequestNode
PullRequest: truffleruby/2174
2 parents 91e994f + 3b120d9 commit a0c1ccb

24 files changed

+250
-119
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public void initialize() {
251251
Metrics.printTime("after-load-core");
252252

253253
// Share once everything is loaded
254-
if (options.SHARED_OBJECTS_ENABLED && options.SHARED_OBJECTS_FORCE) {
255-
sharedObjects.startSharing(OptionsCatalog.SHARED_OBJECTS_FORCE.getName() + " being true");
254+
if (language.options.SHARED_OBJECTS_ENABLED && language.options.SHARED_OBJECTS_FORCE) {
255+
sharedObjects.startSharing(language, OptionsCatalog.SHARED_OBJECTS_FORCE.getName() + " being true");
256256
}
257257

258258
if (isPreInitializing()) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ protected boolean patchContext(RubyContext context, Env newEnv) {
302302

303303
LOGGER.fine("patchContext()");
304304
Metrics.printTime("before-patch-context");
305+
final LanguageOptions oldOptions = Objects.requireNonNull(this.options);
306+
final LanguageOptions newOptions = new LanguageOptions(newEnv, newEnv.getOptions());
307+
if (!LanguageOptions.areOptionsCompatibleOrLog(LOGGER, oldOptions, newOptions)) {
308+
return false;
309+
}
310+
305311
boolean patched = context.patchContext(newEnv);
306312
Metrics.printTime("after-patch-context");
307313
return patched;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import java.util.function.Function;
1414

1515
import com.oracle.truffle.api.CompilerDirectives;
16-
import com.oracle.truffle.api.source.SourceSection;
1716
import org.truffleruby.RubyContext;
1817
import org.truffleruby.RubyLanguage;
1918
import org.truffleruby.collections.CachedSupplier;
19+
import org.truffleruby.core.CoreLibrary;
2020
import org.truffleruby.core.array.ArrayUtils;
2121
import org.truffleruby.core.cast.TaintResultNode;
2222
import org.truffleruby.core.klass.RubyClass;
@@ -208,7 +208,7 @@ private static void addMethod(
208208
final LexicalScope lexicalScope = new LexicalScope(context.getRootLexicalScope(), module);
209209

210210
for (String name : names) {
211-
final SharedMethodInfo sharedMethodInfo = makeSharedMethodInfo(context, lexicalScope, module, name, arity);
211+
final SharedMethodInfo sharedMethodInfo = makeSharedMethodInfo(lexicalScope, module, name, arity);
212212

213213
module.fields.addMethod(context, null, new InternalMethod(
214214
context,
@@ -223,10 +223,9 @@ private static void addMethod(
223223
}
224224
}
225225

226-
private static SharedMethodInfo makeSharedMethodInfo(RubyContext context, LexicalScope lexicalScope,
227-
RubyModule module, String name, Arity arity) {
228-
final SourceSection sourceSection = context.getCoreLibrary().sourceSection;
229-
return new SharedMethodInfo(sourceSection, lexicalScope, arity, module, name, 0, "builtin", null);
226+
private static SharedMethodInfo makeSharedMethodInfo(LexicalScope lexicalScope, RubyModule module, String name,
227+
Arity arity) {
228+
return new SharedMethodInfo(CoreLibrary.SOURCE_SECTION, lexicalScope, arity, module, name, 0, "builtin", null);
230229
}
231230

232231
private static Arity createArity(int required, int optional, boolean rest, String keywordAsOptional) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class CoreLibrary {
121121
private final RubyContext context;
122122
private final RubyLanguage language;
123123

124-
public final SourceSection sourceSection = initCoreSourceSection();
124+
public static final SourceSection SOURCE_SECTION = initCoreSourceSection();
125125

126126
public final RubyClass argumentErrorClass;
127127
public final RubyClass arrayClass;
@@ -259,7 +259,7 @@ public class CoreLibrary {
259259
public final String corePath;
260260

261261
@TruffleBoundary
262-
private SourceSection initCoreSourceSection() {
262+
private static SourceSection initCoreSourceSection() {
263263
final Source.SourceBuilder builder = Source.newBuilder(TruffleRuby.LANGUAGE_ID, "", "(core)");
264264
builder.internal(true);
265265

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected boolean watchSignalProc(Object signalString, RubyProc action,
256256
@CachedLibrary(limit = "2") RubyStringLibrary libSignalString) {
257257
if (getContext().getThreadManager().getCurrentThread() != getContext().getThreadManager().getRootThread()) {
258258
// The proc will be executed on the main thread
259-
SharedObjects.writeBarrier(getContext(), action);
259+
SharedObjects.writeBarrier(getLanguage(), action);
260260
}
261261

262262
final RubyContext context = getContext();
@@ -422,7 +422,7 @@ public abstract static class VMSetClassNode extends PrimitiveArrayArgumentsNode
422422
@TruffleBoundary
423423
@Specialization
424424
protected RubyDynamicObject setClass(RubyDynamicObject object, RubyClass newClass) {
425-
SharedObjects.propagate(getContext(), object, newClass);
425+
SharedObjects.propagate(getLanguage(), object, newClass);
426426
synchronized (object) {
427427
object.setMetaClass(newClass);
428428
}

src/main/java/org/truffleruby/core/klass/ClassNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static RubyClass createSingletonClass(RubyContext context, RubyClass rub
236236
true,
237237
rubyClass,
238238
null);
239-
SharedObjects.propagate(context, rubyClass, metaClass);
239+
SharedObjects.propagate(context.getLanguageSlow(), rubyClass, metaClass);
240240
rubyClass.setMetaClass(metaClass);
241241

242242
return rubyClass.getMetaClass();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void include(RubyContext context, Node currentNode, RubyModule module) {
240240
context.getCoreExceptions().argumentError("cyclic include detected", currentNode));
241241
}
242242

243-
SharedObjects.propagate(context, rubyModule, module);
243+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, module);
244244

245245
// We need to include the module ancestors in reverse order for a given inclusionPoint
246246
ModuleChain inclusionPoint = this;
@@ -299,7 +299,7 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
299299
context.getCoreExceptions().argumentError("cyclic prepend detected", currentNode));
300300
}
301301

302-
SharedObjects.propagate(context, rubyModule, module);
302+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, module);
303303

304304
ModuleChain mod = module.fields.start;
305305
final ModuleChain topPrependedModule = start.getParentModule();
@@ -369,7 +369,7 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
369369
boolean autoload) {
370370
checkFrozen(context, currentNode);
371371

372-
SharedObjects.propagate(context, rubyModule, value);
372+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, value);
373373

374374
final String autoloadPath = autoload
375375
? RubyStringLibrary.getUncached().getJavaString(value)
@@ -426,7 +426,7 @@ public void addMethod(RubyContext context, Node currentNode, InternalMethod meth
426426
Set<Object> adjacent = ObjectGraph.newObjectSet();
427427
ObjectGraph.addProperty(adjacent, method);
428428
for (Object object : adjacent) {
429-
SharedObjects.writeBarrier(context, object);
429+
SharedObjects.writeBarrier(context.getLanguageSlow(), object);
430430
}
431431
}
432432

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ protected RubyNode coerceToString(RubyNode name) {
869869
protected Object setClassVariable(RubyModule module, String name, Object value) {
870870
SymbolTable.checkClassVariableName(getContext(), name, module, this);
871871

872-
ModuleOperations.setClassVariable(getContext(), module, name, value, this);
872+
ModuleOperations.setClassVariable(getLanguage(), getContext(), module, name, value, this);
873873

874874
return value;
875875
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.function.Function;
1818

1919
import org.truffleruby.RubyContext;
20+
import org.truffleruby.RubyLanguage;
2021
import org.truffleruby.collections.Memo;
2122
import org.truffleruby.core.array.ArrayUtils;
2223
import org.truffleruby.core.klass.RubyClass;
@@ -625,11 +626,11 @@ public static Object lookupClassVariable(RubyModule module, final String name) {
625626
}
626627

627628
@TruffleBoundary
628-
public static void setClassVariable(final RubyContext context, RubyModule module, final String name,
629-
final Object value, final Node currentNode) {
629+
public static void setClassVariable(RubyLanguage language, RubyContext context, RubyModule module, String name,
630+
Object value, Node currentNode) {
630631
ModuleFields moduleFields = module.fields;
631632
moduleFields.checkFrozen(context, currentNode);
632-
SharedObjects.propagate(context, module, value);
633+
SharedObjects.propagate(language, module, value);
633634

634635
// if the cvar is not already defined we need to take lock and ensure there is only one
635636
// defined in the class tree

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,25 @@ private void threadMain(RubyThread thread, Node currentNode, Supplier<Object> ta
301301
start(thread, Thread.currentThread());
302302
try {
303303
final Object result = task.get();
304-
setThreadValue(context, thread, result);
304+
setThreadValue(thread, result);
305305
// Handlers in the same order as in FiberManager
306306
} catch (KillException e) {
307-
setThreadValue(context, thread, Nil.INSTANCE);
307+
setThreadValue(thread, Nil.INSTANCE);
308308
} catch (RaiseException e) {
309-
setException(context, thread, e.getException(), currentNode);
309+
setException(thread, e.getException(), currentNode);
310310
} catch (DynamicReturnException e) {
311-
setException(context, thread, context.getCoreExceptions().unexpectedReturn(currentNode), currentNode);
311+
setException(thread, context.getCoreExceptions().unexpectedReturn(currentNode), currentNode);
312312
} catch (ExitException e) {
313313
rethrowOnMainThread(currentNode, e);
314-
setThreadValue(context, thread, Nil.INSTANCE);
314+
setThreadValue(thread, Nil.INSTANCE);
315315
} catch (Throwable e) {
316316
final String message = StringUtils
317317
.format("%s terminated with internal error:", Thread.currentThread().getName());
318318
final RuntimeException runtimeException = new RuntimeException(message, e);
319319
// Immediately print internal exceptions, in case they would cause a deadlock
320320
runtimeException.printStackTrace();
321321
rethrowOnMainThread(currentNode, runtimeException);
322-
setThreadValue(context, thread, Nil.INSTANCE);
322+
setThreadValue(thread, Nil.INSTANCE);
323323
} finally {
324324
assert thread.value != null || thread.exception != null;
325325
cleanup(thread, Thread.currentThread());
@@ -336,17 +336,16 @@ private void rethrowOnMainThread(Node currentNode, RuntimeException e) {
336336
});
337337
}
338338

339-
private static void setThreadValue(RubyContext context, RubyThread thread, Object value) {
339+
private void setThreadValue(RubyThread thread, Object value) {
340340
// A Thread is always shared (Thread.list)
341341
assert value != null;
342-
SharedObjects.propagate(context, thread, value);
342+
SharedObjects.propagate(language, thread, value);
343343
thread.value = value;
344344
}
345345

346-
private static void setException(RubyContext context, RubyThread thread, RubyException exception,
347-
Node currentNode) {
346+
private void setException(RubyThread thread, RubyException exception, Node currentNode) {
348347
// A Thread is always shared (Thread.list)
349-
SharedObjects.propagate(context, thread, exception);
348+
SharedObjects.propagate(language, thread, exception);
350349

351350
// We materialize the backtrace eagerly here, as the exception escapes the thread and needs
352351
// to capture the backtrace from this thread.
@@ -370,18 +369,19 @@ private static void setException(RubyContext context, RubyThread thread, RubyExc
370369
}
371370

372371
if (isSystemExit || thread.abortOnException) {
373-
ThreadNodes.ThreadRaisePrimitiveNode.raiseInThread(context, mainThread, exception, currentNode);
372+
ThreadNodes.ThreadRaisePrimitiveNode
373+
.raiseInThread(language, context, mainThread, exception, currentNode);
374374
}
375375
}
376376
thread.exception = exception;
377377
}
378378

379379
// Share the Ruby Thread before it can be accessed concurrently, and before it is added to Thread.list
380380
public void startSharing(RubyThread rubyThread, String reason) {
381-
if (context.getOptions().SHARED_OBJECTS_ENABLED) {
381+
if (language.options.SHARED_OBJECTS_ENABLED) {
382382
// TODO (eregon, 22 Sept 2017): no need if singleThreaded in isThreadAccessAllowed()
383-
context.getSharedObjects().startSharing(reason);
384-
SharedObjects.writeBarrier(context, rubyThread);
383+
context.getSharedObjects().startSharing(language, reason);
384+
SharedObjects.writeBarrier(language, rubyThread);
385385
}
386386
}
387387

0 commit comments

Comments
 (0)