Skip to content

Fix Immix working memory overflow with big blocks#1339

Open
Tutez64 wants to merge 1 commit intoHaxeFoundation:masterfrom
Tutez64:bugfix/immix-big-blocks-working-memory-overflow
Open

Fix Immix working memory overflow with big blocks#1339
Tutez64 wants to merge 1 commit intoHaxeFoundation:masterfrom
Tutez64:bugfix/immix-big-blocks-working-memory-overflow

Conversation

@Tutez64
Copy link
Copy Markdown

@Tutez64 Tutez64 commented May 7, 2026

Summary

Fixes an overflow in Immix working memory accounting when HXCPP_GC_BIG_BLOCKS is enabled.

The problematic code computes the regular Immix heap size through an int:

int blockSize = mAllBlocks.size() << IMMIX_BLOCK_BITS;

With big blocks, this can overflow once regular heap usage grows past roughly 2 GiB. The fix uses GetWorkingMemory(), which performs the shift through size_t.
This also stores related GC memory tuning thresholds as size_t and parses large environment variable values with strtoull.

Context

In a large OpenFL/hxcpp game, the regular heap consistently failed once it passed 2 GiB with:

Memory exhausted.
try HXCPP_GC_BIG_BLOCKS.

After enabling HXCPP_GC_BIG_BLOCKS, the game no longer crashed immediately, but it froze for a very long time instead, making it unplayable.
With this fix, the same game can continue past that threshold. I was able to reach 12+ GiB of regular heap usage without hitting the previous stall/failure mode.

Repro

HxcppBigBlocksHeapOverflowRepro.zip
It retains many regular hxcpp objects until multi-GiB heap usage.
The repro is not a perfect match for the original game: without the fix, it usually stalls around 7-8 GiB rather than just past 2 GiB. However, it still demonstrates the same failure mode and shows that the fix lets the program continue to the configured target.

Use GetWorkingMemory() instead of recomputing the Immix block size through
an int expression. With HXCPP_GC_BIG_BLOCKS, shifting the block count through
an int overflows once regular heap usage reaches roughly 2 GiB, which can
cause premature memory exhaustion or extremely long GC stalls.

Also store GC memory tuning thresholds as size_t and parse their environment
variables with strtoull so large values are not truncated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant