Skip to content

Commit

Permalink
Only follow pointers into heap in dfs-mark
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncarr0 committed Jul 25, 2019
1 parent 2be850a commit ec2a3af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions runtime/gc/dfs-mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ size_t dfsMarkByMode (GC_state s, pointer root,
assert (objptrIndex < numObjptrs);
// next = *(pointer*)todo;
next = fetchObjptrToPointer (todo, s->heap.start);
if (not isPointer (next)) {
if (not isPointerInHeap (s, next)) {
markNextInNormal:
assert (objptrIndex < numObjptrs);
objptrIndex++;
Expand Down Expand Up @@ -170,7 +170,7 @@ size_t dfsMarkByMode (GC_state s, pointer root,
if (DEBUG_WEAK)
fprintf (stderr, "marking weak "FMTPTR" ",
(uintptr_t)w);
if (isObjptr (w->objptr)) {
if (isObjptrInHeap (s, w->objptr)) {
if (DEBUG_WEAK)
fprintf (stderr, "linking\n");
w->link = s->weaks;
Expand Down Expand Up @@ -216,7 +216,7 @@ size_t dfsMarkByMode (GC_state s, pointer root,
assert (todo == indexSequenceAtObjptrIndex (s, cur, sequenceIndex, objptrIndex));
// next = *(pointer*)todo;
next = fetchObjptrToPointer (todo, s->heap.start);
if (not (isPointer(next))) {
if (not (isPointerInHeap(s, next))) {
markNextInSequence:
assert (sequenceIndex < getSequenceLength (cur));
assert (objptrIndex < numObjptrs);
Expand Down Expand Up @@ -279,7 +279,7 @@ size_t dfsMarkByMode (GC_state s, pointer root,
" offset %u todo "FMTPTR" next = "FMTPTR"\n",
frameOffsets [objptrIndex + 1],
(uintptr_t)todo, (uintptr_t)next);
if (not isPointer (next)) {
if (not isPointerInHeap (s, next)) {
objptrIndex++;
goto markInFrame;
}
Expand Down
6 changes: 2 additions & 4 deletions runtime/gc/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ typedef struct GC_heap {

static inline bool isPointerInOldGen (GC_state s, pointer p);
static inline bool isPointerInNursery (GC_state s, pointer p);
#if ASSERT
static inline bool isPointerInHeap (GC_state s, pointer p);
static inline bool isObjptrInOldGen (GC_state s, objptr op);
#endif
static inline bool isObjptrInNursery (GC_state s, objptr op);
#if ASSERT
static inline bool isObjptrInFromSpace (GC_state s, objptr op);
#endif
static inline bool isObjptrInHeap (GC_state s, objptr op);
static inline bool hasHeapBytesFree (GC_state s, size_t oldGen, size_t nursery);
static inline bool isHeapInit (GC_heap h);

Expand Down
13 changes: 9 additions & 4 deletions runtime/gc/heap_predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ bool isPointerInNursery (GC_state s, pointer p) {
and p <= s->frontier));
}

#if ASSERT
bool isObjptrInOldGen (GC_state s, objptr op) {
pointer p;
if (not (isObjptr(op)))
return TRUE;
p = objptrToPointer (op, s->heap.start);
return isPointerInOldGen (s, p);
}
#endif

bool isObjptrInNursery (GC_state s, objptr op) {
pointer p;
Expand All @@ -36,12 +34,19 @@ bool isObjptrInNursery (GC_state s, objptr op) {
return isPointerInNursery (s, p);
}

#if ASSERT
bool isObjptrInFromSpace (GC_state s, objptr op) {
return (isObjptrInOldGen (s, op)
or isObjptrInNursery (s, op));
}
#endif

bool isObjptrInHeap (GC_state s, objptr op) {
return isObjptrInFromSpace(s, op);
}

bool isPointerInHeap (GC_state s, pointer p) {
return (isPointerInOldGen (s, p)
or isPointerInNursery (s, p));
}

bool hasHeapBytesFree (GC_state s, size_t oldGen, size_t nursery) {
size_t total;
Expand Down

0 comments on commit ec2a3af

Please sign in to comment.