org.aspectbench.tm.runtime.internal
Class MaybeWeakRef
java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.WeakReference
org.aspectbench.tm.runtime.internal.MyWeakRef
org.aspectbench.tm.runtime.internal.MaybeWeakRef
public class MaybeWeakRef
- extends MyWeakRef
Weak ref implementation that allows the reference to be strengthened if necessary.
Equality is reference identity of referents. Hashcode is identityHashCode of referent,
even after referent expires.
Weak references are canonicalised to guarantee they all expire at the same time and only
appear in the reference queue (if any) once.
- Author:
- Pavel Avgustinov
Constructor Summary |
protected |
MaybeWeakRef(java.lang.Object ref)
|
protected |
MaybeWeakRef(java.lang.Object ref,
java.lang.ref.ReferenceQueue q)
|
Method Summary |
void |
cleanup()
|
boolean |
equals(java.lang.Object obj)
Only one PersistentWeakRef is ever constructed for a particular object. |
static MyWeakRef |
getWeakRef(java.lang.Object o)
Really, we want these to be canonical. |
void |
strengthen(java.lang.Object obj)
Strengthen a weak ref by keeping a strong ref in addition. |
void |
weaken()
Weaken the reference by dropping the strong link to the referent. |
Methods inherited from class java.lang.ref.Reference |
clear, enqueue, get, isEnqueued |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
MaybeWeakRef
protected MaybeWeakRef(java.lang.Object ref)
MaybeWeakRef
protected MaybeWeakRef(java.lang.Object ref,
java.lang.ref.ReferenceQueue q)
getWeakRef
public static MyWeakRef getWeakRef(java.lang.Object o)
- Really, we want these to be canonical. Of course, it just so happens that
the current codegen guarantees them to be canonical (they are constructed
once per ITD object, which is guaranteed fresh), so we can dispense with
the expensive map.
equals
public boolean equals(java.lang.Object obj)
- Only one PersistentWeakRef is ever constructed for a particular object. Thus,
this PWR is equal to obj iff they are the same weak reference, or if obj is
the referent of this.
- Overrides:
equals
in class MyWeakRef
strengthen
public void strengthen(java.lang.Object obj)
- Strengthen a weak ref by keeping a strong ref in addition. Referent must be
passed as an argument to avoid race conditions with the GC.
weaken
public void weaken()
- Weaken the reference by dropping the strong link to the referent.
cleanup
public void cleanup()
- Overrides:
cleanup
in class MyWeakRef