Fix Immix working memory overflow with big blocks#1339
Open
Tutez64 wants to merge 1 commit intoHaxeFoundation:masterfrom
Open
Fix Immix working memory overflow with big blocks#1339Tutez64 wants to merge 1 commit intoHaxeFoundation:masterfrom
Tutez64 wants to merge 1 commit intoHaxeFoundation:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an overflow in Immix working memory accounting when
HXCPP_GC_BIG_BLOCKSis enabled.The problematic code computes the regular Immix heap size through an
int:With big blocks, this can overflow once regular heap usage grows past roughly 2 GiB. The fix uses
GetWorkingMemory(), which performs the shift throughsize_t.This also stores related GC memory tuning thresholds as
size_tand parses large environment variable values withstrtoull.Context
In a large OpenFL/hxcpp game, the regular heap consistently failed once it passed 2 GiB with:
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.