Skip to content

Commit 88eff2b

Browse files
Tutez64dimensionscape
authored andcommitted
Fix Immix working memory overflow with big blocks
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. HaxeFoundation/hxcpp#1339 Fixes #20
1 parent 412f7e8 commit 88eff2b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎Changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ The first libhxcpp version. It is based on hxcpp 4.3 (the changes listed under 4
190190
* Fixed a Raspberry Pi running a 64-bit system building with the 32-bit rpi hardfp profile into bin/RPi: it builds as Linux ARM64 (hxcpp #959)
191191
* Added FreeBSD, OpenBSD and NetBSD hosts: they build with the system clang through the Linux toolchain, into BSD, BSD64 or BSDArm64 (hxcpp #1089)
192192
* Fixed building on Linux with musl, such as Alpine: Sys.cpp included xlocale.h, which musl doesn't have (hxcpp #1165)
193+
* Fixed HXCPP_GC_BIG_BLOCKS stalling or running out of memory once the heap passed 2 GiB: the large allocation target was computed in an int (hxcpp #1339)
193194
* Added the libhxcpp define: a build that uses the library gets -D libhxcpp=<version>. Compare it with version("x.y.z"); a plain string comparison compares text
194195
* Added separate Linux ARMv7 and ARM64 build architectures (hxcpp #1355)
195196
* Fixed AndroidCompat.cpp closing its extern "C" section in the wrong place (hxcpp #1404)

‎src/hx/gc/Immix.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,11 +3657,11 @@ class GlobalAllocator
36573657
#if defined(SHOW_MEM_EVENTS_VERBOSE) || defined(SHOW_FRAGMENTATION_BLOCKS)
36583658
if (inJustBorrowing)
36593659
{
3660-
GCLOG("Borrow Blocks %d = %d k\n", mAllBlocks.size(), (mAllBlocks.size() << IMMIX_BLOCK_BITS)>>10);
3660+
GCLOG("Borrow Blocks %d = %d k\n", mAllBlocks.size(), (int)(GetWorkingMemory() >> 10));
36613661
}
36623662
else
36633663
{
3664-
GCLOG("Blocks %d = %d k\n", mAllBlocks.size(), (mAllBlocks.size() << IMMIX_BLOCK_BITS)>>10);
3664+
GCLOG("Blocks %d = %d k\n", mAllBlocks.size(), (int)(GetWorkingMemory() >> 10));
36653665
}
36663666
#endif
36673667

@@ -5398,7 +5398,7 @@ class GlobalAllocator
53985398
#endif
53995399

54005400
// Large alloc target
5401-
int blockSize = mAllBlocks.size()<<IMMIX_BLOCK_BITS;
5401+
size_t blockSize = GetWorkingMemory();
54025402
if (blockSize > mLargeAllocSpace)
54035403
mLargeAllocSpace = blockSize;
54045404
mLargeAllocForceRefresh = mLargeAllocated + mLargeAllocSpace;

0 commit comments

Comments
 (0)