public abstract class ObjectProxyCache<T,A>
extends java.lang.Object
Note that both Java objects and their proxies are held by weak/soft references; because proxies (currently) keep strong references to their Java objects, if we kept strong references to them the Java objects would never be gc'ed. This presents a problem in the case where a user passes a Rubified Java object out to Java but keeps no reference in Ruby to the proxy; if the object is returned to Ruby after its proxy has been gc'ed, a new (and possibly very wrong, in the case of JRuby-defined subclasses) proxy will be created. Use of soft references may help reduce the likelihood of this occurring; users may be advised to keep Ruby-side references to prevent it occurring altogether.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ObjectProxyCache.Entry<T> |
private static interface |
ObjectProxyCache.EntryRef<T> |
static class |
ObjectProxyCache.ReferenceType |
(package private) static class |
ObjectProxyCache.Segment<T,A> |
private static class |
ObjectProxyCache.SoftEntryRef<T> |
private static class |
ObjectProxyCache.WeakEntryRef<T> |
| Modifier and Type | Field and Description |
|---|---|
private static int |
_nextId |
private static float |
DEFAULT_LOAD_FACTOR |
private static int |
DEFAULT_SEGMENT_SIZE |
private static int |
DEFAULT_SEGMENTS |
private int |
id |
private static Logger |
LOG |
private static int |
MAX_CAPACITY |
private static int |
MAX_SEGMENTS |
private ObjectProxyCache.ReferenceType |
referenceType |
private int |
segmentMask |
private ObjectProxyCache.Segment<T,A>[] |
segments |
private int |
segmentShift |
private java.lang.Thread |
vulture |
private static int |
VULTURE_RUN_FREQ_SECONDS |
| Constructor and Description |
|---|
ObjectProxyCache() |
ObjectProxyCache(int numSegments,
int initialSegCapacity,
ObjectProxyCache.ReferenceType refType) |
ObjectProxyCache(ObjectProxyCache.ReferenceType refType) |
| Modifier and Type | Method and Description |
|---|---|
abstract T |
allocateProxy(java.lang.Object javaObject,
A allocator) |
T |
get(java.lang.Object javaObject) |
T |
getOrCreate(java.lang.Object javaObject,
A allocator) |
private static int |
hash(java.lang.Object javaObject) |
private static int |
nextId() |
void |
put(java.lang.Object javaObject,
T proxy) |
private ObjectProxyCache.Segment<T,A> |
segmentFor(int hash) |
int |
size()
Returns the approximate size (elements in use) of the cache.
|
java.lang.String |
stats() |
private static final Logger LOG
private static final int DEFAULT_SEGMENTS
private static final int DEFAULT_SEGMENT_SIZE
private static final float DEFAULT_LOAD_FACTOR
private static final int MAX_CAPACITY
private static final int MAX_SEGMENTS
private static final int VULTURE_RUN_FREQ_SECONDS
private static int _nextId
private final ObjectProxyCache.ReferenceType referenceType
private final ObjectProxyCache.Segment<T,A>[] segments
private final int segmentShift
private final int segmentMask
private java.lang.Thread vulture
private final int id
public ObjectProxyCache()
public ObjectProxyCache(ObjectProxyCache.ReferenceType refType)
public ObjectProxyCache(int numSegments,
int initialSegCapacity,
ObjectProxyCache.ReferenceType refType)
private static int nextId()
public T get(java.lang.Object javaObject)
public void put(java.lang.Object javaObject,
T proxy)
private static int hash(java.lang.Object javaObject)
private ObjectProxyCache.Segment<T,A> segmentFor(int hash)
public int size()
public java.lang.String stats()