Skip to content

Commit fc5279d

Browse files
committed
[GR-32011] Disallow side-effecting safepoints for killOtherFibers()
* Needs GR-32204 and GR-32205 Truffle fixes. (cherry picked from commit abc994a)
1 parent 90d74f3 commit fc5279d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.concurrent.CountDownLatch;
1616

1717
import com.oracle.truffle.api.TruffleContext;
18+
import com.oracle.truffle.api.TruffleSafepoint;
1819
import org.truffleruby.RubyContext;
1920
import org.truffleruby.RubyLanguage;
2021
import org.truffleruby.core.DummyNode;
@@ -357,11 +358,19 @@ public void killOtherFibers() {
357358

358359
// This method might not be executed on the rootFiber Java Thread but possibly on another Java Thread.
359360

360-
final TruffleContext truffleContext = context.getEnv().getContext();
361-
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
362-
doKillOtherFibers();
363-
return BlockingAction.SUCCESS;
364-
});
361+
// Disallow side-effecting safepoints, the current thread is cleaning up and terminating.
362+
// It can no longer process any exception or guest code.
363+
final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
364+
boolean allowSideEffects = safepoint.setAllowSideEffects(false);
365+
try {
366+
final TruffleContext truffleContext = context.getEnv().getContext();
367+
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
368+
doKillOtherFibers();
369+
return BlockingAction.SUCCESS;
370+
});
371+
} finally {
372+
safepoint.setAllowSideEffects(allowSideEffects);
373+
}
365374
}
366375

367376
private void doKillOtherFibers() {

0 commit comments

Comments
 (0)