Package org.jruby.javasupport.util
Class ObjectProxyCache<T,A>
java.lang.Object
org.jruby.javasupport.util.ObjectProxyCache<T,A>
Maps Java objects to their proxies. Combines elements of WeakHashMap and
ConcurrentHashMap to permit unsynchronized reads. May be configured to
use either Weak (the default) or Soft references.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classprivate static interfacestatic enum(package private) static classprivate static final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static intprivate static final floatprivate static final intprivate static final intprivate final intprivate static final Loggerprivate static final intprivate static final intprivate final ObjectProxyCache.ReferenceTypeprivate final intprivate final ObjectProxyCache.Segment<T,A>[] private final intprivate static final int -
Constructor Summary
ConstructorsConstructorDescriptionObjectProxyCache(int numSegments, int initialSegCapacity, ObjectProxyCache.ReferenceType refType) -
Method Summary
Modifier and TypeMethodDescriptionabstract TallocateProxy(Object javaObject, A allocator) getOrCreate(Object javaObject, A allocator) private static intprivate static intnextId()voidprivate ObjectProxyCache.Segment<T,A> segmentFor(int hash) intsize()Returns the approximate size (elements in use) of the cache.stats()
-
Field Details
-
LOG
-
DEFAULT_SEGMENTS
private static final int DEFAULT_SEGMENTS- See Also:
-
DEFAULT_SEGMENT_SIZE
private static final int DEFAULT_SEGMENT_SIZE- See Also:
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR- See Also:
-
MAX_CAPACITY
private static final int MAX_CAPACITY- See Also:
-
MAX_SEGMENTS
private static final int MAX_SEGMENTS- See Also:
-
VULTURE_RUN_FREQ_SECONDS
private static final int VULTURE_RUN_FREQ_SECONDS- See Also:
-
_nextId
private static int _nextId -
referenceType
-
segments
-
segmentShift
private final int segmentShift -
segmentMask
private final int segmentMask -
id
private final int id
-
-
Constructor Details
-
ObjectProxyCache
public ObjectProxyCache() -
ObjectProxyCache
-
ObjectProxyCache
public ObjectProxyCache(int numSegments, int initialSegCapacity, ObjectProxyCache.ReferenceType refType)
-
-
Method Details
-
nextId
private static int nextId() -
allocateProxy
-
get
-
getOrCreate
-
put
-
hash
-
segmentFor
-
size
public int size()Returns the approximate size (elements in use) of the cache. The sizes of the segments are summed. No effort is made to synchronize across segments, so the value returned may differ from the actual size at any point in time.- Returns:
-
stats
-