当前位置: 首页>>代码示例>>Java>>正文


Java Compiler类代码示例

本文整理汇总了Java中jdk.nashorn.internal.codegen.Compiler的典型用法代码示例。如果您正苦于以下问题:Java Compiler类的具体用法?Java Compiler怎么用?Java Compiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Compiler类属于jdk.nashorn.internal.codegen包,在下文中一共展示了Compiler类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCompiler

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
Compiler getCompiler(final FunctionNode functionNode, final MethodType actualCallSiteType,
        final ScriptObject runtimeScope, final Map<Integer, Type> invalidatedProgramPoints,
        final int[] continuationEntryPoints) {
    final TypeMap typeMap = typeMap(actualCallSiteType);
    final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
    final Object typeInformationFile = OptimisticTypesPersistence.getLocationDescriptor(source, functionNodeId, paramTypes);
    final Context context = Context.getContextTrusted();
    return new Compiler(
            context,
            context.getEnv(),
            getInstallerForNewCode(),
            functionNode.getSource(),  // source
            context.getErrorManager(),
            isStrict() | functionNode.isStrict(), // is strict
            true,       // is on demand
            this,       // compiledFunction, i.e. this RecompilableScriptFunctionData
            typeMap,    // type map
            getEffectiveInvalidatedProgramPoints(invalidatedProgramPoints, typeInformationFile), // invalidated program points
            typeInformationFile,
            continuationEntryPoints, // continuation entry points
            runtimeScope); // runtime scope
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:RecompilableScriptFunctionData.java

示例2: getCompiler

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
Compiler getCompiler(final FunctionNode functionNode, final MethodType actualCallSiteType,
        final ScriptObject runtimeScope, final Map<Integer, Type> invalidatedProgramPoints,
        final int[] continuationEntryPoints) {
    final TypeMap typeMap = typeMap(actualCallSiteType);
    final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
    final Object typeInformationFile = OptimisticTypesPersistence.getLocationDescriptor(source, functionNodeId, paramTypes);
    return Compiler.forOnDemandCompilation(
            getInstallerForNewCode(),
            functionNode.getSource(),  // source
            isStrict() | functionNode.isStrict(), // is strict
            this,       // compiledFunction, i.e. this RecompilableScriptFunctionData
            typeMap,    // type map
            getEffectiveInvalidatedProgramPoints(invalidatedProgramPoints, typeInformationFile), // invalidated program points
            typeInformationFile,
            continuationEntryPoints, // continuation entry points
            runtimeScope); // runtime scope
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:RecompilableScriptFunctionData.java

示例3: install

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
@Override
public Class<?> install(final String className, final byte[] bytecode) {
    usageCount++;
    bytesDefined += bytecode.length;
    final String   binaryName = Compiler.binaryName(className);
    return loader.installClass(binaryName, bytecode, codeSource);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:Context.java

示例4: compileTypeSpecialization

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) {
    // We're creating an empty script object for holding local variables. AssignSymbols will populate it with
    // explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and
    // CompilationEnvironment#declareLocalSymbol()).

    if (log.isEnabled()) {
        log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType);
    }

    final boolean persistentCache = usePersistentCodeCache() && persist;
    String cacheKey = null;
    if (persistentCache) {
        final TypeMap typeMap = typeMap(actualCallSiteType);
        final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
        cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes);
        final CodeInstaller<ScriptEnvironment> newInstaller = getInstallerForNewCode();
        final StoredScript script = newInstaller.loadScript(source, cacheKey);

        if (script != null) {
            Compiler.updateCompilationId(script.getCompilationId());
            return installStoredScript(script, newInstaller);
        }
    }

    final FunctionNode fn = reparse();
    final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope);
    final FunctionNode compiledFn = compiler.compile(fn,
            isSerialized() ? CompilationPhases.COMPILE_ALL_SERIALIZED : CompilationPhases.COMPILE_ALL);

    if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) {
        compiler.persistClassInfo(cacheKey, compiledFn);
    }
    return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:RecompilableScriptFunctionData.java

示例5: install

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
@Override
public Class<?> install(final String className, final byte[] bytecode) {
    usageCount++;
    bytesDefined += bytecode.length;
    NAMED_INSTALLED_SCRIPT_COUNT.increment();
    return loader.installClass(Compiler.binaryName(className), bytecode, codeSource);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Context.java

示例6: compileTypeSpecialization

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) {
    // We're creating an empty script object for holding local variables. AssignSymbols will populate it with
    // explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and
    // CompilationEnvironment#declareLocalSymbol()).

    if (log.isEnabled()) {
        log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType);
    }

    final boolean persistentCache = persist && usePersistentCodeCache();
    String cacheKey = null;
    if (persistentCache) {
        final TypeMap typeMap = typeMap(actualCallSiteType);
        final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
        cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes);
        final CodeInstaller newInstaller = getInstallerForNewCode();
        final StoredScript script = newInstaller.loadScript(source, cacheKey);

        if (script != null) {
            Compiler.updateCompilationId(script.getCompilationId());
            return script.installFunction(this, newInstaller);
        }
    }

    final FunctionNode fn = reparse();
    final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope);
    final FunctionNode compiledFn = compiler.compile(fn,
            fn.isCached() ? CompilationPhases.COMPILE_ALL_CACHED : CompilationPhases.COMPILE_ALL);

    if (persist && !compiledFn.hasApplyToCallSpecialization()) {
        compiler.persistClassInfo(cacheKey, compiledFn);
    }
    return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:RecompilableScriptFunctionData.java

示例7: getAllocatorClassName

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
private String getAllocatorClassName() {
    if (allocatorClassName == null) {
        // These classes get loaded, so an interned variant of their name is most likely around anyway.
        allocatorClassName = Compiler.binaryName(ObjectClassGenerator.getClassName(fieldCount, dualFields)).intern();
    }
    return allocatorClassName;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:AllocationStrategy.java

示例8: compileTypeSpecialization

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) {
    // We're creating an empty script object for holding local variables. AssignSymbols will populate it with
    // explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and
    // CompilationEnvironment#declareLocalSymbol()).

    if (log.isEnabled()) {
        log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType);
    }

    final boolean persistentCache = persist && usePersistentCodeCache();
    String cacheKey = null;
    if (persistentCache) {
        final TypeMap typeMap = typeMap(actualCallSiteType);
        final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
        cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes);
        final CodeInstaller<ScriptEnvironment> newInstaller = getInstallerForNewCode();
        final StoredScript script = newInstaller.loadScript(source, cacheKey);

        if (script != null) {
            Compiler.updateCompilationId(script.getCompilationId());
            return script.installFunction(this, newInstaller);
        }
    }

    final FunctionNode fn = reparse();
    final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope);
    final FunctionNode compiledFn = compiler.compile(fn,
            isSerialized() ? CompilationPhases.COMPILE_ALL_SERIALIZED : CompilationPhases.COMPILE_ALL);

    if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) {
        compiler.persistClassInfo(cacheKey, compiledFn);
    }
    return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints());
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:35,代码来源:RecompilableScriptFunctionData.java

示例9: FunctionNode

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
private FunctionNode(
    final FunctionNode functionNode,
    final long lastToken,
    final int flags,
    final String name,
    final Type returnType,
    final CompileUnit compileUnit,
    final EnumSet<CompilationState> compilationState,
    final Block body,
    final List<IdentNode> parameters,
    final FunctionNode snapshot,
    final Compiler.Hints hints) {
    super(functionNode);
    this.lineNumber       = functionNode.lineNumber;
    this.flags            = flags;
    this.name             = name;
    this.returnType       = returnType;
    this.compileUnit      = compileUnit;
    this.lastToken        = lastToken;
    this.compilationState = compilationState;
    this.body             = body;
    this.parameters       = parameters;
    this.snapshot         = snapshot;
    this.hints            = hints;

    // the fields below never change - they are final and assigned in constructor
    this.source          = functionNode.source;
    this.ident           = functionNode.ident;
    this.namespace       = functionNode.namespace;
    this.declaredSymbols = functionNode.declaredSymbols;
    this.kind            = functionNode.kind;
    this.firstToken      = functionNode.firstToken;
    this.thisProperties  = functionNode.thisProperties;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:35,代码来源:FunctionNode.java

示例10: setHints

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
/**
 * Set compiler hints for this function
 * @param lc    lexical context
 * @param hints compiler hints
 * @return new function if hints changed
 */
public FunctionNode setHints(final LexicalContext lc, final Compiler.Hints hints) {
    if (this.hints == hints) {
        return this;
    }
    return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:13,代码来源:FunctionNode.java

示例11: compileScripts

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:50,代码来源:Shell.java

示例12: compile

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:75,代码来源:Context.java

示例13: getCompiler

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
Compiler getCompiler(final FunctionNode fn, final MethodType actualCallSiteType, final RewriteException e) {
    return data.getCompiler(fn, actualCallSiteType, e.getRuntimeScope(), invalidatedProgramPoints, getEntryPoints(e));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:CompiledFunction.java

示例14: compileScripts

import jdk.nashorn.internal.codegen.Compiler; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:61,代码来源:Shell.java


注:本文中的jdk.nashorn.internal.codegen.Compiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。