Thread-id table for engine frames

- frames live in a 256-slot table indexed by thread id, ThreadLocal only on slot collisions
- the single ThreadLocal probed long collision chains in the workers' thread-local maps
This commit is contained in:
Brian Neumann-Fopiano committed 2026-09-28 11:57:02 -04:00
1 parent f2236a8482
commit 34f00d86cf
2 files changed
+85 -16

No files matched your search

@@ -49,6 +49,39 @@ public class EngineThreadStateTest {
assertNull(state.current());
}
@Test
public void threadsSharingATableSlotKeepSeparateFrames() throws InterruptedException {
EngineThreadState state = new EngineThreadState();
IrisEngine.GenerationRuntimeBinding mainBinding = new IrisEngine.GenerationRuntimeBinding(
mock(IrisEngine.class), mock(GenerationRuntime.class));
IrisEngine.GenerationRuntimeBinding otherBinding = new IrisEngine.GenerationRuntimeBinding(
mock(IrisEngine.class), mock(GenerationRuntime.class));
IrisEngine.GenerationRuntimeScope mainScope = state.open(mainBinding);
long slot = Thread.currentThread().threadId() & 255;
AtomicReference<Object> otherSeen = new AtomicReference<>();
AtomicReference<Object> otherAfterClose = new AtomicReference<>(otherBinding);
Thread colliding = null;
while (colliding == null) {
Thread candidate = new Thread(() -> {
IrisEngine.GenerationRuntimeScope scope = state.open(otherBinding);
otherSeen.set(state.binding());
scope.close();
otherAfterClose.set(state.current());
});
if ((candidate.threadId() & 255) == slot) {
colliding = candidate;
}
}
colliding.start();
colliding.join();
assertSame(otherBinding, otherSeen.get());
assertNull(otherAfterClose.get());
assertSame(mainBinding, state.binding());
mainScope.close();
assertNull(state.current());
}
@Test
public void framesAreThreadConfinedAndScopesRejectForeignClose() throws InterruptedException {
EngineThreadState state = new EngineThreadState();