Top Description Inners Fields Constructors Methods
org.jruby.javasupport.util

public abstract Class ObjectProxyCache<T, A>

extends Object
Class Inheritance
Type Parameters
<T>
the T
<A>
the A
Imports
org.jruby.util.log.Logger, .LoggerFactory, java.lang.ref.ReferenceQueue, .SoftReference, .WeakReference, java.util.concurrent.locks.ReentrantLock

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.

Author
Bill Dortch

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static interface
public static enum
pack-priv static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static int
private static final float
private static final int
private static final int
private final int
private static final Logger
private static final int
private static final int
private final ObjectProxyCache.ReferenceType
private final int
private final ObjectProxyCache.Segment<T, A>[]
private final int
private static final int

Constructor Summary

AccessConstructor and Description
public
public
public
ObjectProxyCache(int numSegments, int initialSegCapacity, ObjectProxyCache.ReferenceType refType)

Method Summary

Modifier and TypeMethod and Description
public abstract T
allocateProxy(Object javaObject, A allocator)

public T
get(Object javaObject)

public T
getOrCreate(Object javaObject, A allocator)

private static int
hash(Object javaObject)

private static synchronized int
public void
put(Object javaObject, T proxy)

private ObjectProxyCache.Segment<T, A>
segmentFor(int hash)

public int
size()

Returns the approximate size (elements in use) of the cache.

public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_nextIdback to summary
private static int _nextId
DEFAULT_LOAD_FACTORback to summary
private static final float DEFAULT_LOAD_FACTOR
DEFAULT_SEGMENT_SIZEback to summary
private static final int DEFAULT_SEGMENT_SIZE
DEFAULT_SEGMENTSback to summary
private static final int DEFAULT_SEGMENTS
idback to summary
private final int id
LOGback to summary
private static final Logger LOG
MAX_CAPACITYback to summary
private static final int MAX_CAPACITY
MAX_SEGMENTSback to summary
private static final int MAX_SEGMENTS
referenceTypeback to summary
private final ObjectProxyCache.ReferenceType referenceType
segmentMaskback to summary
private final int segmentMask
segmentsback to summary
private final ObjectProxyCache.Segment<T, A>[] segments
segmentShiftback to summary
private final int segmentShift
VULTURE_RUN_FREQ_SECONDSback to summary
private static final int VULTURE_RUN_FREQ_SECONDS

Constructor Detail

ObjectProxyCacheback to summary
public ObjectProxyCache()
ObjectProxyCacheback to summary
public ObjectProxyCache(ObjectProxyCache.ReferenceType refType)
ObjectProxyCacheback to summary
public ObjectProxyCache(int numSegments, int initialSegCapacity, ObjectProxyCache.ReferenceType refType)

Method Detail

allocateProxyback to summary
public abstract T allocateProxy(Object javaObject, A allocator)
getback to summary
public T get(Object javaObject)
getOrCreateback to summary
public T getOrCreate(Object javaObject, A allocator)
hashback to summary
private static int hash(Object javaObject)
nextIdback to summary
private static synchronized int nextId()
putback to summary
public void put(Object javaObject, T proxy)
segmentForback to summary
private ObjectProxyCache.Segment<T, A> segmentFor(int hash)
sizeback to summary
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.

statsback to summary
public String stats()
org.jruby.javasupport.util back to summary

pack-priv Class ObjectProxyCache.Entry<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final ObjectProxyCache.Entry<T>
pack-priv final ObjectProxyCache.EntryRef<Object>
pack-priv final ObjectProxyCache.EntryRef<T>

Constructor Summary

AccessConstructor and Description
pack-priv
Entry(Object object, int hash, T proxy, ObjectProxyCache.ReferenceType type, ObjectProxyCache.Entry<T> next, ReferenceQueue<Object> queue)

pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static final <T> ObjectProxyCache.Entry<T>[]
newArray(int size)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hashback to summary
pack-priv final int hash
nextback to summary
pack-priv final ObjectProxyCache.Entry<T> next
objectRefback to summary
pack-priv final ObjectProxyCache.EntryRef<Object> objectRef
proxyRefback to summary
pack-priv final ObjectProxyCache.EntryRef<T> proxyRef

Constructor Detail

Entryback to summary
pack-priv Entry(Object object, int hash, T proxy, ObjectProxyCache.ReferenceType type, ObjectProxyCache.Entry<T> next, ReferenceQueue<Object> queue)
Entryback to summary
pack-priv Entry(ObjectProxyCache.EntryRef<Object> objectRef, int hash, ObjectProxyCache.EntryRef<T> proxyRef, ObjectProxyCache.Entry<T> next)

Method Detail

newArrayback to summary
pack-priv static final <T> ObjectProxyCache.Entry<T>[] newArray(int size)
Annotations
@SuppressWarnings:unchecked
org.jruby.javasupport.util back to summary

private Interface ObjectProxyCache.EntryRef<T>

Known Direct Implementers
org.jruby.javasupport.util.ObjectProxyCache.WeakEntryRef, org.jruby.javasupport.util.ObjectProxyCache.SoftEntryRef

Method Summary

Modifier and TypeMethod and Description
public T
get()

public int
hash()

Method Detail

getback to summary
public T get()
hashback to summary
public int hash()
org.jruby.javasupport.util back to summary

public final Enum ObjectProxyCache.ReferenceType

extends Enum<ObjectProxyCache.ReferenceType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ObjectProxyCache.ReferenceType
public static final ObjectProxyCache.ReferenceType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ObjectProxyCache.ReferenceType
public static ObjectProxyCache.ReferenceType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

SOFTback to summary
public static final ObjectProxyCache.ReferenceType SOFT
WEAKback to summary
public static final ObjectProxyCache.ReferenceType WEAK

Constructor Detail

ReferenceTypeback to summary
private ReferenceType()

Method Detail

valueOfback to summary
public static ObjectProxyCache.ReferenceType valueOf(String name)
valuesback to summary
public static ObjectProxyCache.ReferenceType[] values()
org.jruby.javasupport.util back to summary

pack-priv Class ObjectProxyCache.Segment<T, A>

extends ReentrantLock
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final ObjectProxyCache<T, A>
pack-priv volatile ObjectProxyCache.Entry<T>[]
pack-priv final ReferenceQueue<Object>
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Segment(int capacity, ObjectProxyCache<T, A> cache)

Method Summary

Modifier and TypeMethod and Description
private int
private void
pack-priv T
get(Object object, int hash)

pack-priv T
getOrCreate(Object object, int hash, A allocator)

pack-priv static final <T, A> ObjectProxyCache.Segment<T, A>[]
newArray(int size)

pack-priv void
put(Object object, int hash, T proxy)

private ObjectProxyCache.Entry<T>[]
private void
remove(ObjectProxyCache.Entry<T>[] table, int hash, ObjectProxyCache.Entry<T> e)

Inherited from java.util.concurrent.locks.ReentrantLock:
getHoldCountgetOwnergetQueuedThreadsgetQueueLengthgetWaitingThreadsgetWaitQueueLengthhasQueuedThreadhasQueuedThreadshasWaitersisFairisHeldByCurrentThreadisLockedlocklockInterruptiblynewConditiontoStringtryLocktryLockunlock

Field Detail

cacheback to summary
pack-priv final ObjectProxyCache<T, A> cache
entryTableback to summary
pack-priv volatile ObjectProxyCache.Entry<T>[] entryTable
referenceQueueback to summary
pack-priv final ReferenceQueue<Object> referenceQueue
tableSizeback to summary
pack-priv int tableSize
thresholdback to summary
pack-priv int threshold

Constructor Detail

Segmentback to summary
pack-priv Segment(int capacity, ObjectProxyCache<T, A> cache)

Method Detail

countback to summary
private int count()
expungeback to summary
private void expunge()
getback to summary
pack-priv T get(Object object, int hash)
getOrCreateback to summary
pack-priv T getOrCreate(Object object, int hash, A allocator)
newArrayback to summary
pack-priv static final <T, A> ObjectProxyCache.Segment<T, A>[] newArray(int size)
Annotations
@SuppressWarnings:unchecked
putback to summary
pack-priv void put(Object object, int hash, T proxy)
rehashback to summary
private ObjectProxyCache.Entry<T>[] rehash()
removeback to summary
private void remove(ObjectProxyCache.Entry<T>[] table, int hash, ObjectProxyCache.Entry<T> e)
org.jruby.javasupport.util back to summary

private final Class ObjectProxyCache.SoftEntryRef<T>

extends SoftReference<T>
implements ObjectProxyCache.EntryRef<T>
Class Inheritance
All Implemented Interfaces
org.jruby.javasupport.util.ObjectProxyCache.EntryRef

Field Summary

Modifier and TypeField and Description
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
SoftEntryRef(int hash, T rawObject, ReferenceQueue<Object> queue)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.ref.SoftReference:
get

Field Detail

hashback to summary
pack-priv final int hash

Constructor Detail

SoftEntryRefback to summary
pack-priv SoftEntryRef(int hash, T rawObject, ReferenceQueue<Object> queue)

Method Detail

hashback to summary
public int hash()

Implements org.jruby.javasupport.util.ObjectProxyCache.EntryRef.hash.

org.jruby.javasupport.util back to summary

private final Class ObjectProxyCache.WeakEntryRef<T>

extends WeakReference<T>
implements ObjectProxyCache.EntryRef<T>
Class Inheritance
All Implemented Interfaces
org.jruby.javasupport.util.ObjectProxyCache.EntryRef

Field Summary

Modifier and TypeField and Description
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
WeakEntryRef(int hash, T rawObject, ReferenceQueue<Object> queue)

Method Summary

Modifier and TypeMethod and Description
public int

Field Detail

hashback to summary
pack-priv final int hash

Constructor Detail

WeakEntryRefback to summary
pack-priv WeakEntryRef(int hash, T rawObject, ReferenceQueue<Object> queue)

Method Detail

hashback to summary
public int hash()

Implements org.jruby.javasupport.util.ObjectProxyCache.EntryRef.hash.