summaryrefslogtreecommitdiff
path: root/includes/rts/storage
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2020-04-10 02:40:32 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-06-01 06:32:56 -0400
commit2ee4f36c779674f7237d730460ca83aec9a6808a (patch)
tree117b74a6664904f97f07d4f9f370db23bb13dd64 /includes/rts/storage
parent6947231abd8c33840860ad51699b76efd4725f0e (diff)
downloadhaskell-2ee4f36c779674f7237d730460ca83aec9a6808a.tar.gz
Cleanup OVERWRITING_CLOSURE logic
The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those.
Diffstat (limited to 'includes/rts/storage')
-rw-r--r--includes/rts/storage/ClosureMacros.h81
1 files changed, 49 insertions, 32 deletions
diff --git a/includes/rts/storage/ClosureMacros.h b/includes/rts/storage/ClosureMacros.h
index ade8b34631..964537de77 100644
--- a/includes/rts/storage/ClosureMacros.h
+++ b/includes/rts/storage/ClosureMacros.h
@@ -510,24 +510,16 @@ INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, W_ n)
-------------------------------------------------------------------------- */
-#if defined(PROFILING)
-#define ZERO_SLOP_FOR_LDV_PROF 1
-#else
-#define ZERO_SLOP_FOR_LDV_PROF 0
-#endif
-
-#if defined(DEBUG) && !defined(THREADED_RTS)
-#define ZERO_SLOP_FOR_SANITY_CHECK 1
-#else
-#define ZERO_SLOP_FOR_SANITY_CHECK 0
-#endif
-
-#if ZERO_SLOP_FOR_LDV_PROF || ZERO_SLOP_FOR_SANITY_CHECK
-#define OVERWRITING_CLOSURE(c) overwritingClosure(c)
-#define OVERWRITING_CLOSURE_OFS(c,n) overwritingClosureOfs(c,n)
+#if defined(PROFILING) || defined(DEBUG)
+#define OVERWRITING_CLOSURE(c) \
+ overwritingClosure(c)
+#define OVERWRITING_CLOSURE_MUTABLE(c, off) \
+ overwritingMutableClosureOfs(c, off)
#else
-#define OVERWRITING_CLOSURE(c) /* nothing */
-#define OVERWRITING_CLOSURE_OFS(c,n) /* nothing */
+#define OVERWRITING_CLOSURE(c) \
+ do { (void) sizeof(c); } while(0)
+#define OVERWRITING_CLOSURE_MUTABLE(c, off) \
+ do { (void) sizeof(c); (void) sizeof(off); } while(0)
#endif
#if defined(PROFILING)
@@ -535,21 +527,43 @@ void LDV_recordDead (const StgClosure *c, uint32_t size);
RTS_PRIVATE bool isInherentlyUsed ( StgHalfWord closure_type );
#endif
-EXTERN_INLINE void overwritingClosure_ (StgClosure *p,
- uint32_t offset /* in words */,
- uint32_t size /* closure size, in words */,
- bool inherently_used USED_IF_PROFILING
- );
-EXTERN_INLINE void overwritingClosure_ (StgClosure *p, uint32_t offset, uint32_t size, bool inherently_used USED_IF_PROFILING)
+EXTERN_INLINE void
+zeroSlop (
+ StgClosure *p,
+ uint32_t offset, /*< offset to start zeroing at, in words */
+ uint32_t size, /*< total closure size, in words */
+ bool inherently_used /*< whether to call LDV_recordDead */
+ );
+
+EXTERN_INLINE void
+zeroSlop (StgClosure *p, uint32_t offset, uint32_t size,
+ bool inherently_used USED_IF_PROFILING)
{
-#if ZERO_SLOP_FOR_LDV_PROF && !ZERO_SLOP_FOR_SANITY_CHECK
// see Note [zeroing slop when overwriting closures], also #8402
- if (era <= 0) return;
+
+ const bool want_to_zero_immutable_slop = false
+ // Sanity checking (-DS) is enabled
+ || RTS_DEREF(RtsFlags).DebugFlags.sanity
+#if defined(PROFILING)
+ // LDV profiler is enabled
+ || era > 0
#endif
+ ;
+
+ const bool can_zero_immutable_slop =
+ // Only if we're running single threaded.
+ RTS_DEREF(RtsFlags).ParFlags.nCapabilities <= 1;
+
+ const bool zero_slop_immutable =
+ want_to_zero_immutable_slop && can_zero_immutable_slop;
+
+ if(!zero_slop_immutable)
+ return;
// For LDV profiling, we need to record the closure as dead
#if defined(PROFILING)
- if (!inherently_used) { LDV_recordDead(p, size); };
+ if (!inherently_used)
+ LDV_recordDead(p, size);
#endif
for (uint32_t i = offset; i < size; i++) {
@@ -563,8 +577,8 @@ EXTERN_INLINE void overwritingClosure (StgClosure *p)
#if defined(PROFILING)
ASSERT(!isInherentlyUsed(get_itbl(p)->type));
#endif
- overwritingClosure_(p, sizeofW(StgThunkHeader), closure_sizeW(p),
- /*inherently_used=*/false);
+ zeroSlop(p, sizeofW(StgThunkHeader), closure_sizeW(p),
+ /*inherently_used=*/false);
}
// Version of 'overwritingClosure' which overwrites only a suffix of a
@@ -574,8 +588,11 @@ EXTERN_INLINE void overwritingClosure (StgClosure *p)
//
// Note: As this calls LDV_recordDead() you have to call LDV_RECORD_CREATE()
// on the final state of the closure at the call-site
-EXTERN_INLINE void overwritingClosureOfs (StgClosure *p, uint32_t offset);
-EXTERN_INLINE void overwritingClosureOfs (StgClosure *p, uint32_t offset)
+EXTERN_INLINE void
+overwritingMutableClosureOfs (StgClosure *p, uint32_t offset);
+
+EXTERN_INLINE void
+overwritingMutableClosureOfs (StgClosure *p, uint32_t offset)
{
// Since overwritingClosureOfs is only ever called by:
//
@@ -586,7 +603,7 @@ EXTERN_INLINE void overwritingClosureOfs (StgClosure *p, uint32_t offset)
// we can safely set inherently_used = true, which means LDV_recordDead
// won't be invoked below. Since these closures are inherenlty used we don't
// need to track their destruction.
- overwritingClosure_(p, offset, closure_sizeW(p), /*inherently_used=*/true);
+ zeroSlop(p, offset, closure_sizeW(p), /*inherently_used=*/true);
}
// Version of 'overwritingClosure' which takes closure size as argument.
@@ -596,5 +613,5 @@ EXTERN_INLINE void overwritingClosureSize (StgClosure *p, uint32_t size)
#if defined(PROFILING)
ASSERT(!isInherentlyUsed(get_itbl(p)->type));
#endif
- overwritingClosure_(p, sizeofW(StgThunkHeader), size, /*inherently_used=*/false);
+ zeroSlop(p, sizeofW(StgThunkHeader), size, /*inherently_used=*/false);
}