Skip to content

Commit 13e14ce

Browse files
committed
new LinkedBlockingQueue() needs to be behind a TruffleBoundary
1 parent 2daa744 commit 13e14ce

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.concurrent.atomic.AtomicBoolean;
1919
import java.util.concurrent.locks.Lock;
2020

21+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2122
import org.truffleruby.RubyContext;
2223
import org.truffleruby.RubyLanguage;
2324
import org.truffleruby.core.InterruptMode;
@@ -40,6 +41,7 @@
4041

4142
public class RubyThread extends RubyDynamicObject implements ObjectGraphNode {
4243

44+
// All fields are explicitly initialized in the constructor to make the ordering clear
4345
public final ThreadLocalGlobals threadLocalGlobals;
4446
public volatile InterruptMode interruptMode;
4547
public volatile ThreadStatus status;
@@ -59,8 +61,7 @@ public class RubyThread extends RubyDynamicObject implements ObjectGraphNode {
5961
public final AtomicBoolean wakeUp;
6062
volatile int priority;
6163
public ThreadLocalBuffer ioBuffer;
62-
// Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
63-
public final Queue<SafepointAction> pendingSafepointActions = new LinkedBlockingQueue<>();
64+
public final Queue<SafepointAction> pendingSafepointActions;
6465
Object threadGroup;
6566
String sourceLocation;
6667
Object name;
@@ -97,6 +98,8 @@ public RubyThread(
9798
this.wakeUp = new AtomicBoolean(false);
9899
this.priority = Thread.NORM_PRIORITY;
99100
this.ioBuffer = ThreadLocalBuffer.NULL_BUFFER;
101+
// Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
102+
this.pendingSafepointActions = newLinkedBlockingQueue();
100103
this.threadGroup = threadGroup;
101104
this.sourceLocation = sourceLocation;
102105
this.name = Nil.INSTANCE;
@@ -110,4 +113,9 @@ public void getAdjacentObjects(Set<Object> reachable) {
110113
ObjectGraph.addProperty(reachable, name);
111114
}
112115

116+
@TruffleBoundary
117+
private static LinkedBlockingQueue<SafepointAction> newLinkedBlockingQueue() {
118+
return new LinkedBlockingQueue<>();
119+
}
120+
113121
}

0 commit comments

Comments
 (0)