diff --git a/src/heap.cpp b/src/heap.cpp index 4c81b0d6ef..a70f176b3e 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -1709,6 +1709,11 @@ class MyHeap: public Heap { } } + virtual bool needsMark(void* p, unsigned offset) { + return needsMark(p) and targetNeedsMark + (mask(*(static_cast(p) + offset))); + } + bool targetNeedsMark(void* target) { return target and not c.gen2.contains(target) diff --git a/src/heap.h b/src/heap.h index 8b4331ca1e..bf4dc5a360 100644 --- a/src/heap.h +++ b/src/heap.h @@ -62,6 +62,7 @@ class Heap: public Allocator { virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords, bool objectMask, unsigned* totalInBytes) = 0; virtual bool needsMark(void* p) = 0; + virtual bool needsMark(void* p, unsigned offset) = 0; virtual void mark(void* p, unsigned offset, unsigned count) = 0; virtual void pad(void* p) = 0; virtual void* follow(void* p) = 0; diff --git a/src/machine.h b/src/machine.h index 4077745d61..cca8a3b564 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1487,7 +1487,10 @@ mark(Thread* t, object o, unsigned offset, unsigned count) inline void mark(Thread* t, object o, unsigned offset) { - mark(t, o, offset, 1); + if (t->m->heap->needsMark(o, offset / BytesPerWord)) { + ACQUIRE_RAW(t, t->m->heapLock); + t->m->heap->mark(o, offset / BytesPerWord, 1); + } } inline void