< prev index next >

src/jdk/nashorn/internal/codegen/CompilationPhase.java

Print this page
rev 1901 : 8135251: Use Unsafe.defineAnonymousClass for loading Nashorn script code
Reviewed-by: hannesw, lagergren, sundar


 466     }
 467 
 468     /**
 469      * Bytecode generation:
 470      *
 471      * Generate the byte code class(es) resulting from the compiled FunctionNode
 472      */
 473     static final CompilationPhase BYTECODE_GENERATION_PHASE = new BytecodeGenerationPhase();
 474 
 475     private static final class InstallPhase extends CompilationPhase {
 476         @Override
 477         FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
 478             final DebugLogger log = compiler.getLogger();
 479 
 480             final Map<String, Class<?>> installedClasses = new LinkedHashMap<>();
 481 
 482             boolean first = true;
 483             Class<?> rootClass = null;
 484             long length = 0L;
 485 
 486             final CodeInstaller       codeInstaller = compiler.getCodeInstaller();
 487             final Map<String, byte[]> bytecode      = compiler.getBytecode();

 488 
 489             for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
 490                 final String className = entry.getKey();
 491                 //assert !first || className.equals(compiler.getFirstCompileUnit().getUnitClassName()) : "first=" + first + " className=" + className + " != " + compiler.getFirstCompileUnit().getUnitClassName();
 492                 final byte[] code = entry.getValue();
 493                 length += code.length;
 494 
 495                 final Class<?> clazz = codeInstaller.install(className, code);
 496                 if (first) {
 497                     rootClass = clazz;
 498                     first = false;
 499                 }
 500                 installedClasses.put(className, clazz);
 501             }
 502 
 503             if (rootClass == null) {
 504                 throw new CompilationException("Internal compiler error: root class not found!");
 505             }
 506 
 507             final Object[] constants = compiler.getConstantData().toArray();




 466     }
 467 
 468     /**
 469      * Bytecode generation:
 470      *
 471      * Generate the byte code class(es) resulting from the compiled FunctionNode
 472      */
 473     static final CompilationPhase BYTECODE_GENERATION_PHASE = new BytecodeGenerationPhase();
 474 
 475     private static final class InstallPhase extends CompilationPhase {
 476         @Override
 477         FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
 478             final DebugLogger log = compiler.getLogger();
 479 
 480             final Map<String, Class<?>> installedClasses = new LinkedHashMap<>();
 481 
 482             boolean first = true;
 483             Class<?> rootClass = null;
 484             long length = 0L;
 485 
 486             final CodeInstaller origCodeInstaller = compiler.getCodeInstaller();
 487             final Map<String, byte[]> bytecode = compiler.getBytecode();
 488             final CodeInstaller codeInstaller = bytecode.size() > 1 ? origCodeInstaller.getMultiClassCodeInstaller() : origCodeInstaller;
 489 
 490             for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
 491                 final String className = entry.getKey();
 492                 //assert !first || className.equals(compiler.getFirstCompileUnit().getUnitClassName()) : "first=" + first + " className=" + className + " != " + compiler.getFirstCompileUnit().getUnitClassName();
 493                 final byte[] code = entry.getValue();
 494                 length += code.length;
 495 
 496                 final Class<?> clazz = codeInstaller.install(className, code);
 497                 if (first) {
 498                     rootClass = clazz;
 499                     first = false;
 500                 }
 501                 installedClasses.put(className, clazz);
 502             }
 503 
 504             if (rootClass == null) {
 505                 throw new CompilationException("Internal compiler error: root class not found!");
 506             }
 507 
 508             final Object[] constants = compiler.getConstantData().toArray();


< prev index next >