org.jruby.javasupport.util
Class ObjectProxyCache<T,A>
java.lang.Object
org.jruby.javasupport.util.ObjectProxyCache<T,A>
public abstract class ObjectProxyCache<T,A>
- extends java.lang.Object
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
Method Summary |
abstract T |
allocateProxy(java.lang.Object javaObject,
A allocator)
|
T |
get(java.lang.Object javaObject)
|
T |
getOrCreate(java.lang.Object javaObject,
A allocator)
|
void |
put(java.lang.Object javaObject,
T proxy)
|
int |
size()
Returns the approximate size (elements in use) of the cache. |
java.lang.String |
stats()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ObjectProxyCache
public ObjectProxyCache()
ObjectProxyCache
public ObjectProxyCache(ObjectProxyCache.ReferenceType refType)
ObjectProxyCache
public ObjectProxyCache(int numSegments,
int initialSegCapacity,
ObjectProxyCache.ReferenceType refType)
allocateProxy
public abstract T allocateProxy(java.lang.Object javaObject,
A allocator)
get
public T get(java.lang.Object javaObject)
getOrCreate
public T getOrCreate(java.lang.Object javaObject,
A allocator)
put
public void put(java.lang.Object javaObject,
T proxy)
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
public java.lang.String stats()
Copyright © 2002-2009 JRuby Team. All Rights Reserved.