rearrange finalization code in collect to avoid inifinite recursion when finalizer allocates memory

This commit is contained in:
Joel Dice 2009-07-17 09:29:24 -06:00
parent 9c9eb86b2f
commit 3e4336eba4

View File

@ -2762,13 +2762,6 @@ collect(Thread* t, Heap::CollectionType type)
postCollect(m->rootThread);
for (object f = m->finalizeQueue; f; f = finalizerNext(t, f)) {
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
}
m->finalizeQueue = 0;
killZombies(t, m->rootThread);
for (unsigned i = 0; i < m->heapPoolIndex; ++i) {
@ -2781,6 +2774,14 @@ collect(Thread* t, Heap::CollectionType type)
#ifdef VM_STRESS
if (not stress) t->stress = false;
#endif
object f = m->finalizeQueue;
m->finalizeQueue = 0;
for (; f; f = finalizerNext(t, f)) {
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
}
}
void