From 3e4336eba4e0bdf845f4372b03a4b98b2fd2b6f4 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 17 Jul 2009 09:29:24 -0600 Subject: [PATCH] rearrange finalization code in collect to avoid inifinite recursion when finalizer allocates memory --- src/machine.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 2fb5fbb1cc..7843a1bb30 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -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