Commit 51741bde authored by Simon Marlow's avatar Simon Marlow

move sanity checking code from Storage.c to Sanity.c

parent 70ae60e2
......@@ -670,4 +670,64 @@ checkStaticObjects ( StgClosure* static_objects )
}
}
/* Nursery sanity check */
void
checkNurserySanity( step *stp )
{
bdescr *bd, *prev;
nat blocks = 0;
prev = NULL;
for (bd = stp->blocks; bd != NULL; bd = bd->link) {
ASSERT(bd->u.back == prev);
prev = bd;
blocks += bd->blocks;
}
ASSERT(blocks == stp->n_blocks);
ASSERT(countBlocks(stp->large_objects) == stp->n_large_blocks);
}
/* Full heap sanity check. */
void
checkSanity( rtsBool check_heap )
{
nat g, s;
for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
for (s = 0; s < generations[g].n_steps; s++) {
if (g == 0 && s == 0 && RtsFlags.GcFlags.generations > 1) {
continue;
}
ASSERT(countBlocks(generations[g].steps[s].blocks)
== generations[g].steps[s].n_blocks);
ASSERT(countBlocks(generations[g].steps[s].large_objects)
== generations[g].steps[s].n_large_blocks);
if (check_heap) {
checkHeap(generations[g].steps[s].blocks);
}
checkLargeObjects(generations[g].steps[s].large_objects);
}
}
for (s = 0; s < n_capabilities; s++) {
checkNurserySanity(&nurseries[s]);
}
checkFreeListSanity();
#if defined(THREADED_RTS)
// always check the stacks in threaded mode, because checkHeap()
// does nothing in this case.
checkMutableLists(rtsTrue);
#else
if (check_heap) {
checkMutableLists(rtsFalse);
} else {
checkMutableLists(rtsTrue);
}
#endif
}
#endif /* DEBUG */
......@@ -21,10 +21,12 @@ BEGIN_RTS_PRIVATE
# endif
/* debugging routines */
void checkHeap ( bdescr *bd );
void checkHeapChunk ( StgPtr start, StgPtr end );
void checkLargeObjects ( bdescr *bd );
void checkTSO ( StgTSO* tso );
void checkSanity ( rtsBool check_heap );
void checkNurserySanity ( step *stp );
void checkHeap ( bdescr *bd );
void checkHeapChunk ( StgPtr start, StgPtr end );
void checkLargeObjects ( bdescr *bd );
void checkTSO ( StgTSO* tso );
void checkGlobalTSOList ( rtsBool checkTSOs );
void checkStaticObjects ( StgClosure* static_objects );
void checkStackChunk ( StgPtr sp, StgPtr stack_end );
......@@ -32,7 +34,7 @@ StgOffset checkStackFrame ( StgPtr sp );
StgOffset checkClosure ( StgClosure* p );
void checkMutableList ( bdescr *bd, nat gen );
void checkMutableLists ( rtsBool checkTSOs );
void checkMutableLists ( rtsBool checkTSOs );
void checkBQ (StgTSO *bqe, StgClosure *closure);
......
......@@ -274,9 +274,8 @@ GarbageCollect (rtsBool force_major_gc,
memInventory(DEBUG_gc);
#endif
// check stack sanity *before* GC
IF_DEBUG(sanity, checkFreeListSanity());
IF_DEBUG(sanity, checkMutableLists(rtsTrue));
// check sanity *before* GC
IF_DEBUG(sanity, checkSanity(rtsTrue));
// Initialise all our gc_thread structures
for (t = 0; t < n_gc_threads; t++) {
......@@ -755,8 +754,8 @@ SET_GCT(gc_threads[0]);
// Update the stable pointer hash table.
updateStablePtrTable(major_gc);
// check sanity after GC
IF_DEBUG(sanity, checkSanity());
// check sanity after GC
IF_DEBUG(sanity, checkSanity(rtsTrue));
// extra GC trace info
IF_DEBUG(gc, statDescribeGens());
......
......@@ -1292,60 +1292,6 @@ memInventory (rtsBool show)
}
/* Full heap sanity check. */
void
checkSanity( void )
{
nat g, s;
for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
for (s = 0; s < generations[g].n_steps; s++) {
if (g == 0 && s == 0 && RtsFlags.GcFlags.generations > 1) {
continue;
}
ASSERT(countBlocks(generations[g].steps[s].blocks)
== generations[g].steps[s].n_blocks);
ASSERT(countBlocks(generations[g].steps[s].large_objects)
== generations[g].steps[s].n_large_blocks);
checkHeap(generations[g].steps[s].blocks);
checkLargeObjects(generations[g].steps[s].large_objects);
}
}
for (s = 0; s < n_nurseries; s++) {
ASSERT(countBlocks(nurseries[s].blocks)
== nurseries[s].n_blocks);
ASSERT(countBlocks(nurseries[s].large_objects)
== nurseries[s].n_large_blocks);
}
checkFreeListSanity();
#if defined(THREADED_RTS)
// check the stacks too in threaded mode, because we don't do a
// full heap sanity check in this case (see checkHeap())
checkMutableLists(rtsTrue);
#else
checkMutableLists(rtsFalse);
#endif
}
/* Nursery sanity check */
void
checkNurserySanity( step *stp )
{
bdescr *bd, *prev;
nat blocks = 0;
prev = NULL;
for (bd = stp->blocks; bd != NULL; bd = bd->link) {
ASSERT(bd->u.back == prev);
prev = bd;
blocks += bd->blocks;
}
ASSERT(blocks == stp->n_blocks);
}
// handy function for use in gdb, because Bdescr() is inlined.
extern bdescr *_bdescr( StgPtr p );
......
......@@ -143,9 +143,7 @@ HsInt64 getAllocations (void);
#if defined(DEBUG)
void memInventory (rtsBool show);
void checkSanity (void);
nat countBlocks (bdescr *);
void checkNurserySanity (step *stp);
#endif
/* ----------------------------------------------------------------------------
......
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