Skip to content

Commit bc03833

Browse files
committed
Add details for why the reference processing thread is started
1 parent 3233ad2 commit bc03833

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public synchronized FinalizerReference addFinalizer(Object object, FinalizerRefe
111111

112112
finalizerReference.addFinalizer(owner, action, root);
113113

114-
referenceProcessor.processReferenceQueue();
114+
referenceProcessor.processReferenceQueue(owner);
115115
return finalizerReference;
116116
}
117117

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public ReferenceProcessor(RubyContext context) {
113113
this.context = context;
114114
}
115115

116-
protected void processReferenceQueue() {
116+
protected void processReferenceQueue(Class<?> owner) {
117117
if (context.getOptions().SINGLE_THREADED) {
118118

119119
drainReferenceQueue();
@@ -132,18 +132,19 @@ protected void processReferenceQueue() {
132132
*/
133133

134134
if (processingThread == null && !context.isPreInitializing() && context.isInitialized() && !context.isFinalizing()) {
135-
createProcessingThread();
135+
createProcessingThread(owner);
136136
}
137137

138138
}
139139
}
140140

141-
protected void createProcessingThread() {
141+
protected void createProcessingThread(Class<?> owner) {
142142
final ThreadManager threadManager = context.getThreadManager();
143143
processingThread = threadManager.createBootThread(threadName());
144144
context.send(processingThread, "internal_thread_initialize");
145+
final String sharingReason = "creating " + threadName() + " thread for " + owner.getSimpleName();
145146

146-
threadManager.initialize(processingThread, null, threadName(), () -> {
147+
threadManager.initialize(processingThread, null, threadName(), sharingReason, () -> {
147148
while (true) {
148149
final ProcessingReference<?> reference = (ProcessingReference<?>) threadManager.runUntilResult(null, processingQueue::remove);
149150

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ private void setupNativeThreadSupport(TruffleNFIPlatform nfi, NativeConfiguratio
228228
pthread_kill = nfi.getFunction("pthread_kill", "(" + pthread_t + ",sint32):sint32");
229229
}
230230

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

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,14 @@ public DynamicObject initialize(DynamicObject thread, DynamicObject arguments, D
279279
final SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(block).getSourceSection();
280280
final String info = getContext().fileLine(sourceSection);
281281
final Object[] args = boxedCopyNode.execute(Layouts.ARRAY.getStore(arguments), Layouts.ARRAY.getSize(arguments));
282+
final String sharingReason = "creating Ruby Thread " + info;
282283

283284
if (getContext().getOptions().SHARED_OBJECTS_ENABLED) {
284-
getContext().getThreadManager().startSharing(thread, "creating Ruby Thread " + info);
285+
getContext().getThreadManager().startSharing(thread, sharingReason);
285286
SharedObjects.shareDeclarationFrame(getContext(), block);
286287
}
287288

288-
getContext().getThreadManager().initialize(thread, this, info,
289+
getContext().getThreadManager().initialize(thread, this, info, sharingReason,
289290
() -> ProcOperations.rootCall(block, args));
290291
return nil();
291292
}

0 commit comments

Comments
 (0)