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

Print this page




 474         final FunctionNode fn = reparse();
 475         final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope);
 476         final FunctionNode compiledFn = compiler.compile(fn, CompilationPhases.COMPILE_ALL);
 477 
 478         if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) {
 479             compiler.persistClassInfo(cacheKey, compiledFn);
 480         }
 481         return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints());
 482     }
 483 
 484 
 485     /**
 486      * Install this script using the given {@code installer}.
 487      *
 488      * @param script the compiled script
 489      * @return the function initializer
 490      */
 491     private FunctionInitializer install(final StoredScript script) {
 492 
 493         final Map<String, Class<?>> installedClasses = new HashMap<>();

 494         final String   mainClassName   = script.getMainClassName();
 495         final byte[]   mainClassBytes  = script.getClassBytes().get(mainClassName);
 496 
 497         final Class<?> mainClass       = installer.install(mainClassName, mainClassBytes);
 498 
 499         installedClasses.put(mainClassName, mainClass);
 500 
 501         for (final Map.Entry<String, byte[]> entry : script.getClassBytes().entrySet()) {
 502             final String className = entry.getKey();
 503             final byte[] code = entry.getValue();
 504 
 505             if (className.equals(mainClassName)) {
 506                 continue;
 507             }
 508 
 509             installedClasses.put(className, installer.install(className, code));
 510         }
 511 
 512         final Map<Integer, FunctionInitializer> initializers = script.getInitializers();
 513         assert initializers != null;
 514         assert initializers.size() == 1;
 515         final FunctionInitializer initializer = initializers.values().iterator().next();
 516 
 517         final Object[] constants = script.getConstants();
 518         for (int i = 0; i < constants.length; i++) {
 519             if (constants[i] instanceof RecompilableScriptFunctionData) {
 520                 // replace deserialized function data with the ones we already have
 521                 constants[i] = getScriptFunctionData(((RecompilableScriptFunctionData) constants[i]).getFunctionNodeId());




 474         final FunctionNode fn = reparse();
 475         final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope);
 476         final FunctionNode compiledFn = compiler.compile(fn, CompilationPhases.COMPILE_ALL);
 477 
 478         if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) {
 479             compiler.persistClassInfo(cacheKey, compiledFn);
 480         }
 481         return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints());
 482     }
 483 
 484 
 485     /**
 486      * Install this script using the given {@code installer}.
 487      *
 488      * @param script the compiled script
 489      * @return the function initializer
 490      */
 491     private FunctionInitializer install(final StoredScript script) {
 492 
 493         final Map<String, Class<?>> installedClasses = new HashMap<>();
 494         final Map<String, byte[]>   classBytes       = script.getClassBytes();
 495         final String   mainClassName   = script.getMainClassName();
 496         final byte[]   mainClassBytes  = classBytes.get(mainClassName);
 497 
 498         final Class<?> mainClass       = installer.install(mainClassName, mainClassBytes);
 499 
 500         installedClasses.put(mainClassName, mainClass);
 501 
 502         for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) {
 503             final String className = entry.getKey();
 504             final byte[] code = entry.getValue();
 505 
 506             if (className.equals(mainClassName)) {
 507                 continue;
 508             }
 509 
 510             installedClasses.put(className, installer.install(className, code));
 511         }
 512 
 513         final Map<Integer, FunctionInitializer> initializers = script.getInitializers();
 514         assert initializers != null;
 515         assert initializers.size() == 1;
 516         final FunctionInitializer initializer = initializers.values().iterator().next();
 517 
 518         final Object[] constants = script.getConstants();
 519         for (int i = 0; i < constants.length; i++) {
 520             if (constants[i] instanceof RecompilableScriptFunctionData) {
 521                 // replace deserialized function data with the ones we already have
 522                 constants[i] = getScriptFunctionData(((RecompilableScriptFunctionData) constants[i]).getFunctionNodeId());