edu.vub.at.objects.symbiosis
Class JMethodCache

java.lang.Object
  extended byedu.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

Nested Class Summary
private static class JMethodCache.CacheKey
           
 
Field Summary
static JMethodCache _INSTANCE_
           
private  java.util.Map cache_
           
 
Constructor Summary
private JMethodCache()
           
 
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
 

Field Detail

_INSTANCE_

public static final JMethodCache _INSTANCE_

cache_

private final java.util.Map cache_
Constructor Detail

JMethodCache

private JMethodCache()
Method Detail

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