Skip to content

Commit 3233ad2

Browse files
committed
Log when sharing starts with the reason when --shared-objects-debug is passed
1 parent 9b445b0 commit 3233ad2

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void initialize() {
262262

263263
// Share once everything is loaded
264264
if (options.SHARED_OBJECTS_ENABLED && options.SHARED_OBJECTS_FORCE) {
265-
sharedObjects.startSharing();
265+
sharedObjects.startSharing(OptionsCatalog.SHARED_OBJECTS_FORCE.getName() + " being true");
266266
}
267267

268268
if (isPreInitializing()) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void setupNativeThreadSupport(TruffleNFIPlatform nfi, NativeConfiguratio
229229
}
230230

231231
public void initialize(DynamicObject rubyThread, Node currentNode, String info, Supplier<Object> task) {
232-
startSharing(rubyThread);
232+
startSharing(rubyThread, "creating Ruby Thread " + info);
233233

234234
Layouts.THREAD.setSourceLocation(rubyThread, info);
235235

@@ -308,16 +308,16 @@ private static void setException(RubyContext context, DynamicObject thread, Dyna
308308
}
309309

310310
// Share the Ruby Thread before it can be accessed concurrently, and before it is added to Thread.list
311-
public void startSharing(DynamicObject rubyThread) {
311+
public void startSharing(DynamicObject rubyThread, String reason) {
312312
if (context.getOptions().SHARED_OBJECTS_ENABLED) {
313313
// TODO (eregon, 22 Sept 2017): no need if singleThreaded in isThreadAccessAllowed()
314-
context.getSharedObjects().startSharing();
314+
context.getSharedObjects().startSharing(reason);
315315
SharedObjects.writeBarrier(context, rubyThread);
316316
}
317317
}
318318

319319
public void startForeignThread(DynamicObject rubyThread, Thread javaThread) {
320-
startSharing(rubyThread);
320+
startSharing(rubyThread, "creating a foreign thread");
321321
start(rubyThread, javaThread);
322322
}
323323

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,15 @@ public abstract static class ThreadInitializeNode extends PrimitiveArrayArgument
276276
public DynamicObject initialize(DynamicObject thread, DynamicObject arguments, DynamicObject block,
277277
@Cached("of(arguments)") ArrayStrategy strategy,
278278
@Cached("strategy.boxedCopyNode()") ArrayOperationNodes.ArrayBoxedCopyNode boxedCopyNode) {
279+
final SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(block).getSourceSection();
280+
final String info = getContext().fileLine(sourceSection);
281+
final Object[] args = boxedCopyNode.execute(Layouts.ARRAY.getStore(arguments), Layouts.ARRAY.getSize(arguments));
282+
279283
if (getContext().getOptions().SHARED_OBJECTS_ENABLED) {
280-
getContext().getThreadManager().startSharing(thread);
284+
getContext().getThreadManager().startSharing(thread, "creating Ruby Thread " + info);
281285
SharedObjects.shareDeclarationFrame(getContext(), block);
282286
}
283287

284-
final Object[] args = boxedCopyNode.execute(Layouts.ARRAY.getStore(arguments), Layouts.ARRAY.getSize(arguments));
285-
final SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(block).getSourceSection();
286-
final String info = getContext().fileLine(sourceSection);
287288
getContext().getThreadManager().initialize(thread, this, info,
288289
() -> ProcOperations.rootCall(block, args));
289290
return nil();

src/main/java/org/truffleruby/language/objects/shared/SharedObjects.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ public boolean isSharing() {
3737
return sharing;
3838
}
3939

40-
public void startSharing() {
40+
public void startSharing(String reason) {
4141
if (!sharing) {
4242
sharing = true;
43+
if (context.getOptions().SHARED_OBJECTS_DEBUG) {
44+
RubyLanguage.LOGGER.info("starting sharing due to " + reason);
45+
}
4346
shareContextRoots(context);
4447
}
4548
}

0 commit comments

Comments
 (0)