Java 类jdk.nashorn.internal.ir.debug.ASTWriter 实例源码

项目:openjdk-jdk10    文件:CompilationPhase.java   
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
项目:openjdk9    文件:CompilationPhase.java   
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
项目:lookaside_java-1.8.0-openjdk    文件:CompilationPhase.java   
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getFlag(FunctionNode.IS_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getFlag(FunctionNode.IS_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
项目:jdk8u_nashorn    文件:CompilationPhase.java   
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getFlag(FunctionNode.IS_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getFlag(FunctionNode.IS_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
项目:OpenJSharp    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:openjdk-jdk10    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getDebugFlag(FunctionNode.DEBUG_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getDebugFlag(FunctionNode.DEBUG_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:openjdk9    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getDebugFlag(FunctionNode.DEBUG_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getDebugFlag(FunctionNode.DEBUG_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:kaziranga    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:jdk8u_nashorn    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:infobip-open-jdk-8    文件:Parser.java   
private void printAST(final FunctionNode functionNode) {
    if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
        env.getErr().println(new ASTWriter(functionNode));
    }

    if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
        env.getErr().println(new PrintVisitor(functionNode, true, false));
    }
}
项目:OLD-OpenJDK8    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, new Source(fileName, new File(fileName)), errors).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            //null - pass no code installer - this is compile only
            new Compiler(env).compile(functionNode);
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:nashorn-backport    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, new Source(fileName, new File(fileName)), errors).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            //null - pass no code installer - this is compile only
            new Compiler(env).compile(functionNode);
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:nashorn    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, new Source(fileName, new File(fileName)), errors).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            //null - pass no code installer - this is compile only
            new Compiler(env).compile(functionNode);
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:OpenJSharp    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        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;

    if (useCodeStore) {
        storedScript = codeStore.load(source, cacheKey);
    }

    if (storedScript == null) {
        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = new Compiler(
                this,
                env,
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = install(storedScript, source, installer);
    }

    cacheClass(source, script);
    return script;
}
项目:OpenJSharp    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            new Compiler(
                   context,
                   env,
                   null, //null - pass no code installer - this is compile only
                   functionNode.getSource(),
                   context.getErrorManager(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:openjdk-jdk10    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            Compiler.forNoInstallerCompilation(
                   context,
                   functionNode.getSource(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:openjdk9    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            Compiler.forNoInstallerCompilation(
                   context,
                   functionNode.getSource(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:kaziranga    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = 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);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = new Compiler(
                this,
                env,
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}
项目:kaziranga    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            new Compiler(
                   context,
                   env,
                   null, //null - pass no code installer - this is compile only
                   functionNode.getSource(),
                   context.getErrorManager(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:lookaside_java-1.8.0-openjdk    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = 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);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = Compiler.forInitialCompilation(
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}
项目:lookaside_java-1.8.0-openjdk    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            Compiler.forNoInstallerCompilation(
                   context,
                   functionNode.getSource(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:jdk8u_nashorn    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = 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);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = Compiler.forInitialCompilation(
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}
项目:jdk8u_nashorn    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            Compiler.forNoInstallerCompilation(
                   context,
                   functionNode.getSource(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:infobip-open-jdk-8    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        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;

    if (useCodeStore) {
        storedScript = codeStore.load(source, cacheKey);
    }

    if (storedScript == null) {
        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = new Compiler(
                this,
                env,
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = install(storedScript, source, installer);
    }

    cacheClass(source, script);
    return script;
}
项目:infobip-open-jdk-8    文件:Shell.java   
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            new Compiler(
                   context,
                   env,
                   null, //null - pass no code installer - this is compile only
                   functionNode.getSource(),
                   context.getErrorManager(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
项目:OLD-OpenJDK8    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    GlobalObject global = null;
    Class<?> script;

    if (env._class_cache_size > 0) {
        global = (GlobalObject)Context.getGlobalTrusted();
        script = global.findCachedClass(source);
        if (script != null) {
            Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile.");
            return script;
        }
    }

    final FunctionNode functionNode = new Parser(env, source, errMan, strict).parse();
    if (errors.hasErrors()) {
        return null;
    }

    if (env._print_ast) {
        getErr().println(new ASTWriter(functionNode));
    }

    if (env._print_parse) {
        getErr().println(new PrintVisitor(functionNode));
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = url == null ? null : new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    final Compiler compiler = new Compiler(installer, strict);

    final FunctionNode newFunctionNode = compiler.compile(functionNode);
    script = compiler.install(newFunctionNode);

    if (global != null) {
        global.cacheClass(source, script);
    }

    return script;
}
项目:nashorn-backport    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    GlobalObject global = null;
    Class<?> script;

    if (env._class_cache_size > 0) {
        global = (GlobalObject)Context.getGlobalTrusted();
        script = global.findCachedClass(source);
        if (script != null) {
            Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile.");
            return script;
        }
    }

    final FunctionNode functionNode = new Parser(env, source, errMan, strict).parse();
    if (errors.hasErrors()) {
        return null;
    }

    if (env._print_ast) {
        getErr().println(new ASTWriter(functionNode));
    }

    if (env._print_parse) {
        getErr().println(new PrintVisitor(functionNode));
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = url == null ? null : new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    final Compiler compiler = new Compiler(installer, strict);

    final FunctionNode newFunctionNode = compiler.compile(functionNode);
    script = compiler.install(newFunctionNode);

    if (global != null) {
        global.cacheClass(source, script);
    }

    return script;
}
项目:nashorn    文件:Context.java   
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    GlobalObject global = null;
    Class<?> script;

    if (env._class_cache_size > 0) {
        global = (GlobalObject)Context.getGlobalTrusted();
        script = global.findCachedClass(source);
        if (script != null) {
            Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile.");
            return script;
        }
    }

    final FunctionNode functionNode = new Parser(env, source, errMan, strict).parse();
    if (errors.hasErrors()) {
        return null;
    }

    if (env._print_ast) {
        getErr().println(new ASTWriter(functionNode));
    }

    if (env._print_parse) {
        getErr().println(new PrintVisitor(functionNode));
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = url == null ? null : new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    final Compiler compiler = new Compiler(installer, strict);

    final FunctionNode newFunctionNode = compiler.compile(functionNode);
    script = compiler.install(newFunctionNode);

    if (global != null) {
        global.cacheClass(source, script);
    }

    return script;
}