src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java

Print this page




1211 
1212     private ScriptFunction compileScript(final Source source, final ScriptObject scope, final ErrorManager errMan) {
1213         return getProgramFunction(compile(source, errMan, this._strict), scope);
1214     }
1215 
1216     private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
1217         // start with no errors, no warnings.
1218         errMan.reset();
1219 
1220         Class<?> script = findCachedClass(source);
1221         if (script != null) {
1222             final DebugLogger log = getLogger(Compiler.class);
1223             if (log.isEnabled()) {
1224                 log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
1225             }
1226             return script;
1227         }
1228 
1229         StoredScript storedScript = null;
1230         FunctionNode functionNode = null;
1231         // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation
1232         // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData.
1233         final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types;
1234         final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null;

1235 
1236         if (useCodeStore) {
1237             storedScript = codeStore.load(source, cacheKey);
1238         }
1239 
1240         if (storedScript == null) {
1241             functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();
1242 
1243             if (errMan.hasErrors()) {
1244                 return null;
1245             }
1246 
1247             if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
1248                 getErr().println(new ASTWriter(functionNode));
1249             }
1250 
1251             if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
1252                 getErr().println(new PrintVisitor(functionNode, true, false));
1253             }
1254         }




1211 
1212     private ScriptFunction compileScript(final Source source, final ScriptObject scope, final ErrorManager errMan) {
1213         return getProgramFunction(compile(source, errMan, this._strict), scope);
1214     }
1215 
1216     private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
1217         // start with no errors, no warnings.
1218         errMan.reset();
1219 
1220         Class<?> script = findCachedClass(source);
1221         if (script != null) {
1222             final DebugLogger log = getLogger(Compiler.class);
1223             if (log.isEnabled()) {
1224                 log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
1225             }
1226             return script;
1227         }
1228 
1229         StoredScript storedScript = null;
1230         FunctionNode functionNode = null;
1231         // Don't use code store if optimistic types is enabled but lazy compilation is not.
1232         // This would store a full script compilation with many wrong optimistic assumptions that would
1233         // do more harm than good on later runs with both optimistic types and lazy compilation enabled.
1234         final boolean useCodeStore = codeStore != null && !env._parse_only && (!env._optimistic_types || env._lazy_compilation);
1235         final String cacheKey = useCodeStore ? CodeStore.getCacheKey("script", null) : null;
1236 
1237         if (useCodeStore) {
1238             storedScript = codeStore.load(source, cacheKey);
1239         }
1240 
1241         if (storedScript == null) {
1242             functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();
1243 
1244             if (errMan.hasErrors()) {
1245                 return null;
1246             }
1247 
1248             if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
1249                 getErr().println(new ASTWriter(functionNode));
1250             }
1251 
1252             if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
1253                 getErr().println(new PrintVisitor(functionNode, true, false));
1254             }
1255         }