org.mozilla.javascript
Class ClassCache
java.lang.Object
org.mozilla.javascript.ClassCache
public class ClassCache
extends java.lang.Object
Cache of generated classes and data structures to access Java runtime
from JavaScript.
- Igor Bukanov
- Rhino 1.5 Release 5
boolean | associate(ScriptableObject topScope) - Associate ClassCache object with the given top-level scope.
|
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.
|
boolean | isCachingEnabled() - Check if generated Java classes and Java reflection information
is cached.
|
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) - To optimize invocation of reflected Java methods, the engine generates
special glue classes that will call the methods directly.
|
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.
topScope
- scope to associate this ClassCache object with.
- true if no prevous ClassCache objects were embedded into
the scope and this ClassCache were successfully associated
or false otherwise.
get(Scriptable scope)
clearCaches
public void clearCaches()
Empty caches of generated Java classes and Java reflection information.
get
public static ClassCache get(Scriptable scope)
Search for ClassCache object in the given scope.
The method first calls
ScriptableObject.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.
scope
- scope to search for ClassCache object.
- previously associated ClassCache object or a new instance of
ClassCache if no ClassCache object was found.
associate(ScriptableObject topScope)
isCachingEnabled
public final boolean isCachingEnabled()
Check if generated Java classes and Java reflection information
is cached.
newClassSerialNumber
public final int newClassSerialNumber()
Internal engine method to return serial number for generated classes
to ensure name uniqueness.
setCachingEnabled
public void setCachingEnabled(boolean enabled)
Set whether to cache some values.
By default, the engine will cache generated classes and
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.
enabled
- if true, caching is enabled
clearCaches()
setInvokerOptimizationEnabled
public void setInvokerOptimizationEnabled(boolean enabled)
To optimize invocation of reflected Java methods, the engine generates
special glue classes that will call the methods directly. By default
the optimization is enabled since it allows to speedup method invocation
compared with calling Method.invoke by factor 2-2.5 under JDK
1.4.2 and by factor 10-15 under JDK 1.3.1. If increase memory
consumption is too high or the optimization brings no benefits in a
particular VM, then the optimization can be disabled.
enabled
- if true, invoke optimization is enabled.