mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
fix ordering of weak reference and finalization processing
This commit is contained in:
parent
da844719ab
commit
0a32a7b7af
41
src/vm.cpp
41
src/vm.cpp
@ -763,6 +763,26 @@ collect(Machine* m, Heap::CollectionType type)
|
||||
}
|
||||
|
||||
Thread* t = m->rootThread;
|
||||
|
||||
object p = m->weakReferences;
|
||||
m->weakReferences = 0;
|
||||
while (p) {
|
||||
object o = jreferenceTarget(t, p);
|
||||
object followed = m->heap->follow(o);
|
||||
if (followed == o) {
|
||||
// object has not been collected
|
||||
object x = p;
|
||||
p = weakReferenceNext(t, x);
|
||||
weakReferenceNext(t, x) = m->weakReferences;
|
||||
m->weakReferences = x;
|
||||
} else {
|
||||
jreferenceTarget(t, p) = followed;
|
||||
object x = p;
|
||||
p = weakReferenceNext(t, x);
|
||||
weakReferenceNext(t, x) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (object* f = &(m->finalizers); *f;) {
|
||||
object o = finalizerTarget(t, *f);
|
||||
if (m->heap->follow(o) == o) {
|
||||
@ -783,21 +803,6 @@ collect(Machine* m, Heap::CollectionType type)
|
||||
for (object* f = &(m->doomed); *f; f = &finalizerNext(t, *f)) {
|
||||
v->visit(f);
|
||||
}
|
||||
|
||||
for (object p = m->weakReferences; p;) {
|
||||
object o = jreferenceTarget(t, p);
|
||||
object followed = m->heap->follow(o);
|
||||
if (followed == o) {
|
||||
// object has not been collected
|
||||
jreferenceTarget(t, p) = 0;
|
||||
} else {
|
||||
jreferenceTarget(t, p) = followed;
|
||||
}
|
||||
|
||||
object last = p;
|
||||
p = weakReferenceNext(t, p);
|
||||
weakReferenceNext(t, last) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual unsigned sizeInWords(object o) {
|
||||
@ -931,6 +936,12 @@ collect(Machine* m, Heap::CollectionType type)
|
||||
}
|
||||
m->doomed = 0;
|
||||
|
||||
for (object p = m->weakReferences; p;) {
|
||||
jreferenceTarget(t, p) = 0;
|
||||
object x = p;
|
||||
p = weakReferenceNext(t, x);
|
||||
weakReferenceNext(t, x) = 0;
|
||||
}
|
||||
m->weakReferences = 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user