Skip to content

Commit

Permalink
fix for bug in assertions: traverseAndCheck was checking too much
Browse files Browse the repository at this point in the history
traverseAndCheck is used to verify (in debug mode) that
make_entangled/manage_entangled have pinned and suspected the
entanglement region. But, it was checking too much -- it was
checking all immutable objects reachable, even those outside the
entanglement region. This patch fixes that.
  • Loading branch information
shwestrick committed Feb 20, 2024
1 parent 2f8d349 commit 249ec8f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions runtime/gc/decheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,35 @@ void traverseAndCheck(
GC_state s,
__attribute__((unused)) objptr *opp,
objptr op,
__attribute__((unused)) void *rawArgs)
void *rawArgs)
{

GC_header header = getHeader(objptrToPointer(op, NULL));
pointer p = objptrToPointer (op, NULL);
assert (pinType(header) == PIN_ANY);
assert (!isFwdHeader(header));
if (isMutableH(s, header)) {

uint32_t requiredUnpinDepth = *(uint32_t*)rawArgs;
uint32_t actualUnpinDepth = unpinDepthOfH(header);
uint32_t currentDepth = HM_getObjptrDepth(op);

assert (actualUnpinDepth <= requiredUnpinDepth);

if (currentDepth <= requiredUnpinDepth) {
/* This object is an ancestor of the current thread, so the object is
* disentangled from the current thread's perspective. No futher checks
* are required. (If this object is mutable and has a down-pointer, it might
* be a suspect, but I don't need it to be a suspect for entanglement.)
*/
return;
}
else if (isMutableH(s, header)) {
assert (ES_contains(NULL, op));
}
else {
uint32_t requiredUnpinDepthForReachable = actualUnpinDepth;
struct GC_foreachObjptrClosure echeckClosure =
{.fun = traverseAndCheck, .env = NULL};
{.fun = traverseAndCheck, .env = &requiredUnpinDepthForReachable};
foreachObjptrInObject(s, p, &trueObjptrPredicateClosure, &echeckClosure, FALSE);
}
}
Expand Down Expand Up @@ -432,11 +449,13 @@ void make_entangled(
assert(ES_contains(NULL, new_ptr));
}

traverseAndCheck(s, &new_ptr, new_ptr, NULL);
uint32_t requiredUnpinDepth = mea->unpinDepth;
traverseAndCheck(s, &new_ptr, new_ptr, &requiredUnpinDepth);

assert (!mutable || ES_contains(NULL, new_ptr));
}


objptr manage_entangled(
GC_state s,
objptr ptr,
Expand Down Expand Up @@ -486,18 +505,22 @@ objptr manage_entangled(
Trace0(EVENT_MANAGE_ENTANGLED_ENTER);
make_entangled(s, &ptr, ptr, (void*) &mea);
Trace0(EVENT_MANAGE_ENTANGLED_LEAVE);

uint32_t requiredUnpinDepth = newUnpinDepth;
traverseAndCheck(s, &ptr, ptr, &requiredUnpinDepth);
}
else {
if (isMutableH(s, header) && !ES_contains(NULL, ptr)) {
HM_HierarchicalHeap lcaHeap = HM_HH_getHeapAtDepth(s, getThreadCurrent(s), unpinDepth);
ES_add(s, HM_HH_getSuspects(lcaHeap), ptr);
assert(ES_contains(NULL, ptr));
}
traverseAndCheck(s, &ptr, ptr, NULL);

uint32_t requiredUnpinDepth = unpinDepth;
traverseAndCheck(s, &ptr, ptr, &requiredUnpinDepth);
}


traverseAndCheck(s, &ptr, ptr, NULL);
return ptr;
// GC_header header = getRacyHeader(objptrToPointer(ptr, NULL));
// bool mutable = isMutableH(s, header);
Expand Down

0 comments on commit 249ec8f

Please sign in to comment.