Skip to content

Commit 9163303

Browse files
committed
Move shared objects options to language
1 parent 0db283f commit 9163303

18 files changed

+93
-96
lines changed

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

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

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

257257
if (isPreInitializing()) {

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
@@ -237,7 +237,7 @@ public void include(RubyContext context, Node currentNode, RubyModule module) {
237237
context.getCoreExceptions().argumentError("cyclic include detected", currentNode));
238238
}
239239

240-
SharedObjects.propagate(context, rubyModule, module);
240+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, module);
241241

242242
// We need to include the module ancestors in reverse order for a given inclusionPoint
243243
ModuleChain inclusionPoint = this;
@@ -296,7 +296,7 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
296296
context.getCoreExceptions().argumentError("cyclic prepend detected", currentNode));
297297
}
298298

299-
SharedObjects.propagate(context, rubyModule, module);
299+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, module);
300300

301301
ModuleChain mod = module.fields.start;
302302
final ModuleChain topPrependedModule = start.getParentModule();
@@ -366,7 +366,7 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
366366
boolean autoload) {
367367
checkFrozen(context, currentNode);
368368

369-
SharedObjects.propagate(context, rubyModule, value);
369+
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, value);
370370

371371
final String autoloadPath = autoload
372372
? RubyStringLibrary.getUncached().getJavaString(value)
@@ -423,7 +423,7 @@ public void addMethod(RubyContext context, Node currentNode, InternalMethod meth
423423
Set<Object> adjacent = ObjectGraph.newObjectSet();
424424
ObjectGraph.addProperty(adjacent, method);
425425
for (Object object : adjacent) {
426-
SharedObjects.writeBarrier(context, object);
426+
SharedObjects.writeBarrier(context.getLanguageSlow(), object);
427427
}
428428
}
429429

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ protected Object initialize(RubyThread thread, RubyArray arguments, RubyProc blo
331331
final Object[] args = stores.boxedCopyOfRange(arguments.store, 0, argSize);
332332
final String sharingReason = "creating Ruby Thread " + info;
333333

334-
if (getContext().getOptions().SHARED_OBJECTS_ENABLED) {
334+
if (getLanguage().options.SHARED_OBJECTS_ENABLED) {
335335
getContext().getThreadManager().startSharing(thread, sharingReason);
336-
SharedObjects.shareDeclarationFrame(getContext(), block);
336+
SharedObjects.shareDeclarationFrame(getLanguage(), block);
337337
}
338338

339339
getContext().getThreadManager().initialize(
@@ -643,15 +643,15 @@ public static abstract class ThreadRaisePrimitiveNode extends PrimitiveArrayArgu
643643

644644
@Specialization
645645
protected Object raise(RubyThread thread, RubyException exception) {
646-
raiseInThread(getContext(), thread, exception, this);
646+
raiseInThread(getLanguage(), getContext(), thread, exception, this);
647647
return nil;
648648
}
649649

650650
@TruffleBoundary
651-
public static void raiseInThread(RubyContext context, RubyThread rubyThread, RubyException exception,
652-
Node currentNode) {
651+
public static void raiseInThread(RubyLanguage language, RubyContext context, RubyThread rubyThread,
652+
RubyException exception, Node currentNode) {
653653
// The exception will be shared with another thread
654-
SharedObjects.writeBarrier(context, exception);
654+
SharedObjects.writeBarrier(language, exception);
655655

656656
context.getSafepointManager().pauseRubyThreadAndExecute(
657657
"Thread#raise",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public RubyParsingRequestNode(RubyLanguage language, RubyContext context, Source
7171
@Override
7272
public Object execute(VirtualFrame frame) {
7373
assert RubyLanguage.getCurrentContext() == context;
74+
final RubyLanguage language = getLanguage(RubyLanguage.class);
7475

7576
printTimeMetric("before-script");
7677
try {
@@ -85,8 +86,8 @@ public Object execute(VirtualFrame frame) {
8586

8687
// The return value will be leaked to Java, so share it if the Context API is used.
8788
// We share conditionally on EMBEDDED to avoid sharing return values used in RubyLauncher.
88-
if (context.getOptions().SHARED_OBJECTS_ENABLED && context.getOptions().EMBEDDED) {
89-
SharedObjects.writeBarrier(context, value);
89+
if (language.options.SHARED_OBJECTS_ENABLED && context.getOptions().EMBEDDED) {
90+
SharedObjects.writeBarrier(language, value);
9091
}
9192

9293
return value;

src/main/java/org/truffleruby/language/objects/SingletonClassNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected RubyClass getSingletonClassForInstance(RubyDynamicObject object) {
158158
RubyLibrary.getUncached().freeze(singletonClass);
159159
}
160160

161-
SharedObjects.propagate(context, object, singletonClass);
161+
SharedObjects.propagate(context.getLanguageSlow(), object, singletonClass);
162162
object.setMetaClass(singletonClass);
163163

164164
return singletonClass;

0 commit comments

Comments
 (0)