Skip to content

Commit 117800e

Browse files
committed
[GR-44830] Revert "Avoid using the SafepointManager if there is only the root and reference processing threads"
* This reverts commit 9b08749. * There is no need for this anymore since TruffleSafepoint is fast and needs no invalidation (unlike SafepointManager). * Manual Thread#interrupt() can be lost with TruffleSafepoint (GR-44830), due to `TruffleSafepoint.Interrupter#THREAD_INTERRUPT` resetting the interrupt flag if a safepoint was run while inside setBlockedWithException(). * With this the 2 usages left of Thread#interrupt() in truffleruby are only there to set the interrupt flag after `catch (InterruptedException e)`.
1 parent ebef274 commit 117800e

File tree

2 files changed

+4
-56
lines changed

2 files changed

+4
-56
lines changed

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

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.truffleruby.annotations.SuppressFBWarnings;
1818
import org.truffleruby.core.thread.RubyThread;
1919
import org.truffleruby.core.thread.ThreadManager;
20-
import org.truffleruby.language.control.KillException;
2120
import org.truffleruby.language.control.RaiseException;
2221

2322
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -73,7 +72,6 @@ public ReferenceProcessingService<R, T> service() {
7372
public static class ReferenceProcessor {
7473
protected final ReferenceQueue<Object> processingQueue = new ReferenceQueue<>();
7574

76-
private volatile boolean shutdown = false;
7775
protected RubyThread processingThread;
7876
protected final RubyContext context;
7977

@@ -121,40 +119,13 @@ protected void createProcessingThread(ReferenceProcessingService<?, ?> service)
121119

122120
threadManager.initialize(newThread, DummyNode.INSTANCE, THREAD_NAME, sharingReason, () -> {
123121
while (true) {
124-
final PhantomProcessingReference<?, ?> reference = threadManager
125-
.runUntilResult(DummyNode.INSTANCE, () -> {
126-
try {
127-
return (PhantomProcessingReference<?, ?>) processingQueue.remove();
128-
} catch (InterruptedException interrupted) {
129-
if (shutdown) {
130-
throw new KillException(DummyNode.INSTANCE);
131-
} else {
132-
throw interrupted;
133-
}
134-
}
135-
});
122+
final PhantomProcessingReference<?, ?> reference = threadManager.runUntilResult(DummyNode.INSTANCE,
123+
() -> (PhantomProcessingReference<?, ?>) processingQueue.remove());
136124
reference.service().processReference(context, language, reference);
137125
}
138126
});
139127
}
140128

141-
public boolean shutdownProcessingThread() {
142-
final Thread javaThread = processingThread == null ? null : processingThread.thread;
143-
if (javaThread == null) {
144-
return false;
145-
}
146-
147-
shutdown = true;
148-
javaThread.interrupt();
149-
150-
context.getThreadManager().runUntilResultKeepStatus(DummyNode.INSTANCE, t -> t.join(1000), javaThread);
151-
return true;
152-
}
153-
154-
public RubyThread getProcessingThread() {
155-
return processingThread;
156-
}
157-
158129
@TruffleBoundary
159130
protected final void drainReferenceQueues() {
160131
final RubyLanguage language = context.getLanguageSlow();

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -662,33 +662,10 @@ public void checkNoRunningThreads() {
662662
@TruffleBoundary
663663
public void killAndWaitOtherThreads() {
664664
// Kill all Ruby Threads and Fibers
665-
666-
// The logic below avoids using the SafepointManager if there is
667-
// only the current thread and the reference processing thread.
668-
final RubyThread currentThread = language.getCurrentThread();
669-
boolean otherThreads = false;
670-
RubyThread referenceProcessingThread = null;
671-
for (RubyThread thread : runningRubyThreads) {
672-
if (thread == currentThread) {
673-
// no need to kill the current thread
674-
} else if (thread == context.getReferenceProcessor().getProcessingThread()) {
675-
referenceProcessingThread = thread;
676-
} else {
677-
otherThreads = true;
678-
break;
679-
}
680-
}
681-
682-
if (!otherThreads && referenceProcessingThread != null) {
683-
if (!context.getReferenceProcessor().shutdownProcessingThread()) {
684-
otherThreads = true;
685-
}
686-
}
687-
688-
if (otherThreads) {
665+
if (runningRubyThreads.size() > 1) {
689666
doKillOtherThreads();
690667
}
691-
context.fiberManager.killOtherFibers(currentThread);
668+
context.fiberManager.killOtherFibers(language.getCurrentThread());
692669

693670
// Wait and join all Java threads we created
694671
for (Thread thread : rubyManagedThreads) {

0 commit comments

Comments
 (0)