src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java
Print this page
@@ -1226,14 +1226,15 @@
return script;
}
StoredScript storedScript = null;
FunctionNode functionNode = null;
- // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation
- // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData.
- final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types;
- final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null;
+ // Don't use code store if optimistic types is enabled but lazy compilation is not.
+ // This would store a full script compilation with many wrong optimistic assumptions that would
+ // do more harm than good on later runs with both optimistic types and lazy compilation enabled.
+ final boolean useCodeStore = codeStore != null && !env._parse_only && (!env._optimistic_types || env._lazy_compilation);
+ final String cacheKey = useCodeStore ? CodeStore.getCacheKey("script", null) : null;
if (useCodeStore) {
storedScript = codeStore.load(source, cacheKey);
}