Skip to content

Commit f56476e

Browse files
committed
Fix: make heap root computation thread safe
1 parent 45e4c2d commit f56476e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotStackFramesRetriever.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.truffle.polyglot;
4242

43+
import java.util.ArrayList;
4344
import java.util.List;
4445
import java.util.concurrent.CompletableFuture;
4546
import java.util.concurrent.ExecutionException;
@@ -65,13 +66,17 @@ static void populateHeapRoots(PolyglotContextImpl context, List<Object> heapRoot
6566
future = context.threadLocalActions.submit(null, PolyglotEngineImpl.ENGINE_ID, new ThreadLocalAction(false, false) {
6667
@Override
6768
protected void perform(Access access) {
69+
List<Object> threadHeapRoots = new ArrayList<>();
6870
Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<>() {
6971
@Override
7072
public Object visitFrame(FrameInstance frameInstance) {
71-
populateHeapRootsFromFrame(context, frameInstance, heapRoots);
73+
populateHeapRootsFromFrame(context, frameInstance, threadHeapRoots);
7274
return null;
7375
}
7476
});
77+
synchronized (heapRoots) {
78+
heapRoots.addAll(threadHeapRoots);
79+
}
7580
}
7681
}, false);
7782
} else {

0 commit comments

Comments
 (0)