From 38a4b6ab7bbd5e650f43541d091a52ed2655aff6 Mon Sep 17 00:00:00 2001 From: Ben Gamari <ben@smart-cactus.org> Date: Wed, 6 Mar 2024 17:02:26 -0500 Subject: [PATCH] rts: Fix SET_HDR initialization of retainer set This fixes a regression in retainer set profiling introduced by b0293f78cb6acf2540389e22bdda420d0ab874da. Prior to that commit the heap traversal word would be initialized by `SET_HDR` using `LDV_RECORD_CREATE`. However, the commit added a `doingLDVProfiling` check in `LDV_RECORD_CREATE`, meaning that this initialization no longer happened. Given that this initialization was awkwardly indirectly anyways, I have fixed this by explicitly initializating the heap traversal word to `NULL` in `SET_PROF_HDR`. This is equivalent to the previous behavior, but much more direct. Fixes #24513. --- rts/include/rts/storage/ClosureMacros.h | 32 +++++++++---------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/rts/include/rts/storage/ClosureMacros.h b/rts/include/rts/storage/ClosureMacros.h index dbed34d490d6..b28f0d893f63 100644 --- a/rts/include/rts/storage/ClosureMacros.h +++ b/rts/include/rts/storage/ClosureMacros.h @@ -147,17 +147,10 @@ EXTERN_INLINE StgHalfWord GET_TAG(const StgClosure *con) #if defined(PROFILING) /* The following macro works for both retainer profiling and LDV profiling. For - retainer profiling, 'era' remains 0, so by setting the 'ldvw' field we also set - 'rs' to zero. - - Note that we don't have to bother handling the 'flip' bit properly[1] since the - retainer profiling code will just set 'rs' to NULL upon visiting a closure with - an invalid 'flip' bit anyways. - - See Note [Profiling heap traversal visited bit] for details. - - [1]: Technically we should set 'rs' to `NULL | flip`. + retainer profiling, we set 'trav' to 0, which is an invalid + RetainerSet. */ + /* MP: Various other places use the check era > 0 to check whether LDV profiling is enabled. The use of these predicates here is the reason for including RtsFlags.h in @@ -168,17 +161,14 @@ EXTERN_INLINE StgHalfWord GET_TAG(const StgClosure *con) */ #define SET_PROF_HDR(c, ccs_) \ { \ - (c)->header.prof.ccs = ccs_; \ - if (doingLDVProfiling()) { \ - LDV_RECORD_CREATE((c)); \ - } \ -\ - if (doingRetainerProfiling()) { \ - LDV_RECORD_CREATE((c)); \ - }; \ - if (doingErasProfiling()){ \ - ERA_RECORD_CREATE((c)); \ - }; \ + (c)->header.prof.ccs = ccs_; \ + if (doingLDVProfiling()) { \ + LDV_RECORD_CREATE((c)); \ + } else if (doingRetainerProfiling()) { \ + (c)->header.prof.hp.trav = 0; \ + } else if (doingErasProfiling()){ \ + ERA_RECORD_CREATE((c)); \ + } \ } #else -- GitLab