* Without an identity-based weak key hash table, we must look up
* with a key of a weak reference that matches on referent identity.
* If there is no matching entry, we reuse the same weak reference
* in the new ImplRef, so register it with our reference queue.
*/
Reference lookupKey = new WeakKey(impl, reapQueue);
synchronized (lock) {
ImplRef implRef = (ImplRef) weakImplTable.get(lookupKey);
if (implRef == null) {
implRef = new ImplRef(lookupKey);
weakImplTable.put(lookupKey, implRef);
if (reaper == null) {
reaper = (Thread) AccessController.doPrivileged(
new NewThreadAction(new Reaper(), "Reaper", true));
reaper.start();
/*
* We are now interested in special assistance from the
* local garbage collector for aggressively collecting
* unreachable remote objects, so that they do not keep
* the VM alive indefinitely.
*
* Without guaranteed access to something like the
* sun.misc.GC API, however, we currently have no
* practical way of getting such special assistance.
*/
}
} else {
/*
* Clear the weak reference used for lookup, so that it will
* not generate spurious reference queue notifications later.
*/
lookupKey.clear();
}
implRef.addTarget(target);
return implRef;
}