Commit 30f7137d authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

rts: Zero shrunk array slop in vanilla RTS

But only when profiling or DEBUG are enabled.

Fixes #17572.
parent fb81f2ed
......@@ -630,7 +630,11 @@
#else
#define OVERWRITING_CLOSURE_SIZE(c, size) /* nothing */
#define OVERWRITING_CLOSURE(c) /* nothing */
#define OVERWRITING_CLOSURE_MUTABLE(c, off) /* nothing */
/* This is used to zero slop after shrunk arrays. It is important that we do
* this whenever profiling is enabled as described in Note [slop on the heap]
* in Storage.c. */
#define OVERWRITING_CLOSURE_MUTABLE(c, off) \
if (TO_W_(RtsFlags_ProfFlags_doHeapProfile(RtsFlags)) != 0) { foreign "C" overwritingMutableClosureOfs(c "ptr", off); }
#endif
// Memory barriers.
......
......@@ -953,14 +953,19 @@ accountAllocation(Capability *cap, W_ n)
* profiler, see Note [skipping slop in the heap profiler].
*
* In general we zero:
*
* - Pinned object alignment slop, see MEMSET_SLOP_W in allocatePinned.
* - Large object alignment slop, see MEMSET_SLOP_W in allocatePinned.
* This is necessary even in the vanilla RTS since the user may trigger a heap
* census via +RTS -hT even when not linking against the profiled RTS.
*
* Only when profiling we zero:
* - Shrunk array slop, see OVERWRITING_CLOSURE_MUTABLE.
*
* Note that this is necessary even in the vanilla (e.g. non-profiling) RTS
* since the user may trigger a heap census via +RTS -hT, which can be used
* even when not linking against the profiled RTS. Failing to zero slop
* due to array shrinking has resulted in a few nasty bugs (#17572, #9666).
* However, since array shrink may result in large amounts of slop (unlike
* alignment), we take care to only zero such slop when heap profiling or DEBUG
* are enabled.
*
* When performing LDV profiling or using a (single threaded) debug RTS we zero
* slop even when overwriting immutable closures, see Note [zeroing slop when
* overwriting closures].
......
......@@ -561,6 +561,8 @@ wanteds os = concat
,structField C "StgCompactNFDataBlock" "owner"
,structField C "StgCompactNFDataBlock" "next"
,structField_ C "RtsFlags_ProfFlags_doHeapProfile"
"RTS_FLAGS" "ProfFlags.doHeapProfile"
,structField_ C "RtsFlags_ProfFlags_showCCSOnException"
"RTS_FLAGS" "ProfFlags.showCCSOnException"
,structField_ C "RtsFlags_DebugFlags_apply"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment