jdk.nashorn.internal.codegen.Compiler Java Examples

The following examples show how to use jdk.nashorn.internal.codegen.Compiler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecompilableScriptFunctionData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #2
Source File: RecompilableScriptFunctionData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #3
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #4
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #5
Source File: RecompilableScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #6
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #7
Source File: RecompilableScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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
}
 
Example #8
Source File: Context.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: RecompilableScriptFunctionData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #10
Source File: Context.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: AllocationStrategy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #13
Source File: FunctionNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: AllocationStrategy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #16
Source File: AllocationStrategy.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: RecompilableScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #18
Source File: AllocationStrategy.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: Shell.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: FunctionNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #21
Source File: Shell.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: FunctionNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #23
Source File: FunctionNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #24
Source File: Shell.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: Context.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: RecompilableScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #27
Source File: AllocationStrategy.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #28
Source File: FunctionNode.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #29
Source File: FunctionNode.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #30
Source File: Context.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}