mirror of
https://github.com/corda/corda.git
synced 2025-01-19 03:06:36 +00:00
fix handling of reachable, moved weak references in postVisit
This commit is contained in:
parent
0a96f4c552
commit
4f794f533e
@ -458,7 +458,9 @@ postVisit(Thread* t, Heap::Visitor* v)
|
||||
if (m->heap->status(*p) == Heap::Unreachable) {
|
||||
// reference is unreachable
|
||||
referenceUnreachable(t, v, p);
|
||||
} else if (m->heap->status(jreferenceTarget(t, *p))
|
||||
} else if (m->heap->status
|
||||
(jreferenceTarget
|
||||
(t, static_cast<object>(m->heap->follow(*p))))
|
||||
== Heap::Unreachable)
|
||||
{
|
||||
// target is unreachable
|
||||
@ -504,7 +506,9 @@ postVisit(Thread* t, Heap::Visitor* v)
|
||||
if (m->heap->status(*p) == Heap::Unreachable) {
|
||||
// reference is unreachable
|
||||
referenceUnreachable(t, v, p);
|
||||
} else if (m->heap->status(jreferenceTarget(t, *p))
|
||||
} else if (m->heap->status
|
||||
(jreferenceTarget
|
||||
(t, static_cast<object>(m->heap->follow(*p))))
|
||||
== Heap::Unreachable)
|
||||
{
|
||||
// target is unreachable
|
||||
|
@ -2,6 +2,7 @@ import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class References {
|
||||
public static void main(String[] args) {
|
||||
@ -9,6 +10,8 @@ public class References {
|
||||
Object b = new Object();
|
||||
Object c = new Object();
|
||||
Object d = new Object();
|
||||
Object e = new Object();
|
||||
Object f = new Object();
|
||||
|
||||
ReferenceQueue q = new ReferenceQueue();
|
||||
|
||||
@ -16,21 +19,54 @@ public class References {
|
||||
Reference br = new WeakReference(b, q);
|
||||
Reference cr = new WeakReference(c, q);
|
||||
Reference dr = new PhantomReference(d, q);
|
||||
Reference er = new MyReference(e, q, "foo");
|
||||
|
||||
WeakHashMap<Key,Object> map = new WeakHashMap();
|
||||
map.put(new Key("foo"), f);
|
||||
|
||||
a = b = c = d = cr = null;
|
||||
a = b = c = d = e = cr = null;
|
||||
|
||||
System.out.println("a: " + ar.get());
|
||||
System.out.println("b: " + br.get());
|
||||
System.out.println("d: " + dr.get());
|
||||
System.out.println("e: " + er.get());
|
||||
System.out.println("f: " + map.get(new Key("foo")));
|
||||
|
||||
System.gc();
|
||||
|
||||
System.out.println("a: " + ar.get());
|
||||
System.out.println("b: " + br.get());
|
||||
System.out.println("d: " + dr.get());
|
||||
System.out.println("e: " + er.get());
|
||||
System.out.println("f: " + map.get(new Key("foo")));
|
||||
|
||||
for (Reference r = q.poll(); r != null; r = q.poll()) {
|
||||
System.out.println("polled: " + r.get());
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyReference extends WeakReference {
|
||||
private final Object foo;
|
||||
|
||||
public MyReference(Object target, ReferenceQueue queue, Object foo) {
|
||||
super(target, queue);
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Key {
|
||||
private final String name;
|
||||
|
||||
public Key(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Key && ((Key) o).name.equals(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user