8162955: Activate anonymous class loading for small sources
Reviewed-by: sundar
This commit is contained in:
parent
9541a3a9ec
commit
08076a7b14
@ -302,6 +302,16 @@ Nashorn provides a fixed sized runtime event queue for debugging purposes.
|
||||
See -Dnashorn.debug for methods to access the event queue.
|
||||
The default value is 1024.
|
||||
|
||||
SYSTEM PROPERTY: -Dnashorn.anonymous.classes.threshold=<value>
|
||||
|
||||
Nashorn can use anonymous classes for loading compiled scripts, depending
|
||||
on the --anonymous-classes=[auto|true|false] option. Anonymous classes load
|
||||
faster, but the loaded classes get less optimization applied to them and
|
||||
therefore usually run slower. In the default "auto" setting, scripts are
|
||||
loaded as anonymous classes if the script size does not exceed 512 bytes.
|
||||
The above system property allows to set this threshold to a user defined
|
||||
value.
|
||||
|
||||
===============
|
||||
2. The loggers.
|
||||
===============
|
||||
|
@ -1502,7 +1502,7 @@ public final class Context {
|
||||
final URL url = source.getURL();
|
||||
final CodeSource cs = new CodeSource(url, (CodeSigner[])null);
|
||||
final CodeInstaller installer;
|
||||
if (!env.useAnonymousClasses(isEval) || env._persistent_cache || !env._lazy_compilation) {
|
||||
if (!env.useAnonymousClasses(source.getLength()) || env._persistent_cache || !env._lazy_compilation) {
|
||||
// Persistent code cache and eager compilation preclude use of VM anonymous classes
|
||||
final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
|
||||
installer = new NamedContextCodeInstaller(this, cs, loader);
|
||||
|
@ -222,7 +222,7 @@ public final class ScriptEnvironment {
|
||||
/** Timing */
|
||||
public final Timing _timing;
|
||||
|
||||
/** Whether to use anonymous classes. See {@link #useAnonymousClasses(boolean)}. */
|
||||
/** Whether to use anonymous classes. See {@link #useAnonymousClasses(int)}. */
|
||||
private final AnonymousClasses _anonymousClasses;
|
||||
private enum AnonymousClasses {
|
||||
AUTO,
|
||||
@ -230,6 +230,12 @@ public final class ScriptEnvironment {
|
||||
ON
|
||||
}
|
||||
|
||||
/** Size threshold up to which we use anonymous classes in {@link AnonymousClasses#AUTO} setting */
|
||||
private final int _anonymous_classes_threshold;
|
||||
|
||||
/** Default value for anonymous class threshold */
|
||||
private final static int DEFAULT_ANON_CLASS_THRESHOLD = 512;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -327,6 +333,8 @@ public final class ScriptEnvironment {
|
||||
throw new RuntimeException("Unsupported value for anonymous classes: " + anonClasses);
|
||||
}
|
||||
|
||||
this._anonymous_classes_threshold = Options.getIntProperty(
|
||||
"nashorn.anonymous.classes.threshold", DEFAULT_ANON_CLASS_THRESHOLD);
|
||||
|
||||
final String language = options.getString("language");
|
||||
if (language == null || language.equals("es5")) {
|
||||
@ -462,11 +470,12 @@ public final class ScriptEnvironment {
|
||||
|
||||
/**
|
||||
* Returns true if compilation should use anonymous classes.
|
||||
* @param isEval true if compilation is an eval call.
|
||||
* @param sourceLength length of source being compiled.
|
||||
* @return true if anonymous classes should be used
|
||||
*/
|
||||
public boolean useAnonymousClasses(final boolean isEval) {
|
||||
return _anonymousClasses == AnonymousClasses.ON || (_anonymousClasses == AnonymousClasses.AUTO && isEval);
|
||||
public boolean useAnonymousClasses(final int sourceLength) {
|
||||
return _anonymousClasses == AnonymousClasses.ON
|
||||
|| (_anonymousClasses == AnonymousClasses.AUTO && sourceLength <= _anonymous_classes_threshold);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user