org.aspectbench.tm.runtime.internal
Class MaybeWeakRef

java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.WeakReference
          extended by org.aspectbench.tm.runtime.internal.MyWeakRef
              extended by 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

Field Summary
 
Fields inherited from class org.aspectbench.tm.runtime.internal.MyWeakRef
expiredQueue
 
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 org.aspectbench.tm.runtime.internal.MyWeakRef
addContainer, checkExpired, hashCode, isExpired, notifyContainers, removeContainer
 
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
 

Constructor Detail

MaybeWeakRef

protected MaybeWeakRef(java.lang.Object ref)

MaybeWeakRef

protected MaybeWeakRef(java.lang.Object ref,
                       java.lang.ref.ReferenceQueue q)
Method Detail

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