From 8f8a802bc002879940cc95343f601407f7ffd300 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Wed, 28 Oct 2026 20:56:32 +0100 Subject: [PATCH 1/2] Reset pooled LocalAllocator when attaching a thread Between GetPooledAllocator and AddLocal, the allocator is neither pooled nor registered, so a collection in that window does not reset it. The thread then allocates from holes that the collection may have handed out again. Co-Authored-By: Claude Opus 5.5 --- src/hx/gc/Immix.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index ea5ce8e8c..7678e9d95 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -5818,6 +5818,10 @@ class LocalAllocator : public hx::StackContext void AttachThread(int *inTopOfStack) { + // A pooled allocator is neither pooled nor registered between GetPooledAllocator and AddLocal, + // so a collection in that window does not reset it and its holes may be stale. + Reset(); + #ifndef HXCPP_EXPLICIT_STACK_EXTENT mTopOfStack = mBottomOfStack = inTopOfStack; #endif From 75638f53e26a542aa96524a64e0c680e69e9f82d Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 29 Oct 2026 11:06:47 +0100 Subject: [PATCH 2/2] Reset LocalAllocator when returning it to the pool Pooled allocators now never hold holes, instead of resetting them when a thread attaches. Co-Authored-By: Claude Opus 5.5 --- src/hx/gc/Immix.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index 7678e9d95..c69c19d77 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -3154,6 +3154,9 @@ class GlobalAllocator { if (!mLocalPool[p]) { + // Pooled allocators hold no holes. Between GetPooledAllocator and AddLocal an allocator + // is neither pooled nor registered, so a collection in that window would not reset it. + ClearPooledAlloc(inAlloc); mLocalPool[p] = inAlloc; return true; } @@ -5818,10 +5821,6 @@ class LocalAllocator : public hx::StackContext void AttachThread(int *inTopOfStack) { - // A pooled allocator is neither pooled nor registered between GetPooledAllocator and AddLocal, - // so a collection in that window does not reset it and its holes may be stale. - Reset(); - #ifndef HXCPP_EXPLICIT_STACK_EXTENT mTopOfStack = mBottomOfStack = inTopOfStack; #endif