edu.vub.at.objects.symbiosis
Class JMethodCache
java.lang.Object
edu.vub.at.objects.symbiosis.JMethodCache
- public final class JMethodCache
- extends java.lang.Object
A singleton object that represents a method cache. It is used to speed up
the symbiosis with Java. Every time a JavaMethod is successfully created from
an array of java.lang.reflect.Method objects, it is stored in the cache.
The cache uses weak references such that JavaMethod instances can be safely recollected
when they are no longer used. Note that this caching scheme only works because:
- Java classes are unmodifyable at runtime
- JavaMethod objects are constant, so may be safely shared between different actors
The method cache is implemented as a hash map, mapping pairs
[ java.lang.Class class, java.lang.String methodname, boolean isStatic ] => soft ref to JavaMethod
If a JavaMethod has been garbage collected, its entry is removed from the cache.
Soft references rather than weak references are used to point to the JavaMethod entries.
Soft references are like weak references, but normally only get reclaimed when the
JVM runs low on memory. Hence, they are much more suitable for caching.
The cache is synchronized to ensure proper synchronization between different actors.
- Author:
- tvcutsem
Method Summary |
JavaMethod |
get(java.lang.Class cls,
java.lang.String methName,
boolean isStatic)
Retrieve a JavaMethod entry from the cache. |
void |
put(java.lang.Class cls,
java.lang.String methName,
boolean isStatic,
JavaMethod entry)
Add a JavaMethod instance to the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_INSTANCE_
public static final JMethodCache _INSTANCE_
cache_
private final java.util.Map cache_
JMethodCache
private JMethodCache()
put
public void put(java.lang.Class cls,
java.lang.String methName,
boolean isStatic,
JavaMethod entry)
- Add a JavaMethod instance to the cache.
get
public JavaMethod get(java.lang.Class cls,
java.lang.String methName,
boolean isStatic)
- Retrieve a JavaMethod entry from the cache.
- Returns:
- the entry, or null if the cache does not contain the entry