Package org.htmlunit.corejs.javascript
Class ClassCache
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ClassCache
-
- All Implemented Interfaces:
java.io.Serializable
public class ClassCache extends java.lang.Object implements java.io.Serializable
Cache of generated classes and data structures to access Java runtime from JavaScript.- Since:
- Rhino 1.5 Release 5
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ClassCache.CacheKey
CacheKey is a combination of class and securityContext.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Object
AKEY
private Scriptable
associatedScope
private boolean
cachingIsEnabled
private java.util.Map<JavaAdapter.JavaAdapterSignature,java.lang.Class<?>>
classAdapterCache
private java.util.Map<ClassCache.CacheKey,JavaMembers>
classTable
private int
generatedClassSerial
private java.util.Map<java.lang.Class<?>,java.lang.Object>
interfaceAdapterCache
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description ClassCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
associate(ScriptableObject topScope)
Associate ClassCache object with the given top-level scope.(package private) void
cacheInterfaceAdapter(java.lang.Class<?> cl, java.lang.Object iadapter)
void
clearCaches()
Empty caches of generated Java classes and Java reflection information.static ClassCache
get(Scriptable scope)
Search for ClassCache object in the given scope.(package private) Scriptable
getAssociatedScope()
(package private) java.util.Map<ClassCache.CacheKey,JavaMembers>
getClassCacheMap()
(package private) java.lang.Object
getInterfaceAdapter(java.lang.Class<?> cl)
(package private) java.util.Map<JavaAdapter.JavaAdapterSignature,java.lang.Class<?>>
getInterfaceAdapterCacheMap()
boolean
isCachingEnabled()
Check if generated Java classes and Java reflection information is cached.boolean
isInvokerOptimizationEnabled()
Deprecated.The method always returns false.int
newClassSerialNumber()
Internal engine method to return serial number for generated classes to ensure name uniqueness.void
setCachingEnabled(boolean enabled)
Set whether to cache some values.void
setInvokerOptimizationEnabled(boolean enabled)
Deprecated.The method does nothing.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
AKEY
private static final java.lang.Object AKEY
-
cachingIsEnabled
private volatile boolean cachingIsEnabled
-
classTable
private transient java.util.Map<ClassCache.CacheKey,JavaMembers> classTable
-
classAdapterCache
private transient java.util.Map<JavaAdapter.JavaAdapterSignature,java.lang.Class<?>> classAdapterCache
-
interfaceAdapterCache
private transient java.util.Map<java.lang.Class<?>,java.lang.Object> interfaceAdapterCache
-
generatedClassSerial
private int generatedClassSerial
-
associatedScope
private Scriptable associatedScope
-
-
Method Detail
-
get
public static ClassCache get(Scriptable scope)
Search for ClassCache object in the given scope. The method first callsScriptableObject.getTopLevelScope(Scriptable scope)
to get the top most scope and then tries to locate associated ClassCache object in the prototype chain of the top scope.- Parameters:
scope
- scope to search for ClassCache object.- Returns:
- previously associated ClassCache object or a new instance of ClassCache if no ClassCache object was found.
- See Also:
associate(ScriptableObject topScope)
-
associate
public boolean associate(ScriptableObject topScope)
Associate ClassCache object with the given top-level scope. The ClassCache object can only be associated with the given scope once.- Parameters:
topScope
- scope to associate this ClassCache object with.- Returns:
- true if no previous ClassCache objects were embedded into the scope and this ClassCache were successfully associated or false otherwise.
- See Also:
get(Scriptable scope)
-
clearCaches
public void clearCaches()
Empty caches of generated Java classes and Java reflection information.
-
isCachingEnabled
public final boolean isCachingEnabled()
Check if generated Java classes and Java reflection information is cached.
-
setCachingEnabled
public void setCachingEnabled(boolean enabled)
Set whether to cache some values.By default, the engine will cache the results of
Class.getMethods()
and similar calls. This can speed execution dramatically, but increases the memory footprint. Also, with caching enabled, references may be held to objects past the lifetime of any real usage.If caching is enabled and this method is called with a
false
argument, the caches will be emptied.Caching is enabled by default.
- Parameters:
enabled
- if true, caching is enabled- See Also:
clearCaches()
-
getClassCacheMap
java.util.Map<ClassCache.CacheKey,JavaMembers> getClassCacheMap()
- Returns:
- a map from classes to associated JavaMembers objects
-
getInterfaceAdapterCacheMap
java.util.Map<JavaAdapter.JavaAdapterSignature,java.lang.Class<?>> getInterfaceAdapterCacheMap()
-
isInvokerOptimizationEnabled
@Deprecated public boolean isInvokerOptimizationEnabled()
Deprecated.The method always returns false.
-
setInvokerOptimizationEnabled
@Deprecated public void setInvokerOptimizationEnabled(boolean enabled)
Deprecated.The method does nothing. Invoker optimization is no longer used by Rhino. On modern JDK like 1.4 or 1.5 the disadvantages of the optimization like increased memory usage or longer initialization time overweight small speed increase that can be gained using generated proxy class to replace reflection.
-
newClassSerialNumber
public final int newClassSerialNumber()
Internal engine method to return serial number for generated classes to ensure name uniqueness.
-
getInterfaceAdapter
java.lang.Object getInterfaceAdapter(java.lang.Class<?> cl)
-
cacheInterfaceAdapter
void cacheInterfaceAdapter(java.lang.Class<?> cl, java.lang.Object iadapter)
-
getAssociatedScope
Scriptable getAssociatedScope()
-
-