jdk.nashorn.internal.ir.FunctionNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.FunctionNode. 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: ApplySpecialization.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasApplies(final FunctionNode functionNode) {
    try {
        functionNode.accept(new SimpleNodeVisitor() {
            @Override
            public boolean enterFunctionNode(final FunctionNode fn) {
                return fn == functionNode;
            }

            @Override
            public boolean enterCallNode(final CallNode callNode) {
                if (isApply(callNode)) {
                    throw HAS_APPLIES;
                }
                return true;
            }
        });
    } catch (final AppliesFoundException e) {
        return true;
    }

    log.fine("There are no applies in ", DebugLogger.quote(functionNode.getName()), " - nothing to do.");
    return false; // no applies
}
 
Example #2
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
    start(functionNode, false);

    if (functionNode.isLazy()) {
        return false;
    }

    //an outermost function in our lexical context that is not a program (runScript)
    //is possible - it is a function being compiled lazily
    if (functionNode.isDeclared()) {
        final Iterator<Block> blocks = lc.getBlocks();
        if (blocks.hasNext()) {
            defineSymbol(blocks.next(), functionNode.getIdent().getName(), IS_VAR);
        }
    }

    returnTypes.push(functionNode.getReturnType());
    pushLocalsFunction();

    return true;
}
 
Example #3
Source File: RecompilableScriptFunctionData.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor - public as scripts use it
 *
 * @param functionNode       functionNode that represents this function code
 * @param installer          installer for code regeneration versions of this function
 * @param allocatorClassName name of our allocator class, will be looked up dynamically if used as a constructor
 * @param allocatorMap       allocator map to seed instances with, when constructing
 */
public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) {
    super(functionNode.isAnonymous() ?
            "" :
            functionNode.getIdent().getName(),
          functionNode.getParameters().size(),
          functionNode.isStrict(),
          false,
          true);

    this.functionNode       = functionNode;
    this.source             = functionNode.getSource();
    this.token              = tokenFor(functionNode);
    this.installer          = installer;
    this.allocatorClassName = allocatorClassName;
    this.allocatorMap       = allocatorMap;
}
 
Example #4
Source File: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveFunctionNode(final FunctionNode functionNode) {
    final FunctionNode finalizedFunction;
    if (isUnparsedFunction(functionNode)) {
        finalizedFunction = functionNode;
    } else {
        finalizedFunction =
           markProgramBlock(
           removeUnusedSlots(
           createSyntheticInitializers(
           finalizeParameters(
                   lc.applyTopFlags(functionNode))))
                   .setThisProperties(lc, thisProperties.pop().size()));
    }
    return finalizedFunction;
}
 
Example #5
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the AST to cache in this function
 * @param astToCache the new AST to cache
 */
public void setCachedAst(final FunctionNode astToCache) {
    assert astToCache.getId() == functionNodeId; // same function
    assert !(cachedAst instanceof SerializedAst); // Can't overwrite serialized AST

    final boolean isSplit = astToCache.isSplit();
    // If we're caching a split function, we're doing it in the eager pass, hence there can be no other
    // cached representation already. In other words, isSplit implies cachedAst == null.
    assert !isSplit || cachedAst == null; //

    final FunctionNode symbolClonedAst = cloneSymbols(astToCache);
    final Reference<FunctionNode> ref = new SoftReference<>(symbolClonedAst);
    cachedAst = ref;

    // Asynchronously serialize split functions.
    if (isSplit) {
        astSerializerExecutorService.execute(() -> {
            cachedAst = new SerializedAst(symbolClonedAst, ref);
        });
    }
}
 
Example #6
Source File: ApplySpecialization.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasApplies(final FunctionNode functionNode) {
    try {
        functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
            @Override
            public boolean enterFunctionNode(final FunctionNode fn) {
                return fn == functionNode;
            }

            @Override
            public boolean enterCallNode(final CallNode callNode) {
                if (isApply(callNode)) {
                    throw HAS_APPLIES;
                }
                return true;
            }
        });
    } catch (final AppliesFoundException e) {
        return true;
    }

    log.fine("There are no applies in ", DebugLogger.quote(functionNode.getName()), " - nothing to do.");
    return false; // no applies
}
 
Example #7
Source File: FinalizeTypes.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
    if (functionNode.isLazy()) {
        return false;
    }

    // If the function doesn't need a callee, we ensure its __callee__ symbol doesn't get a slot. We can't do
    // this earlier, as access to scoped variables, self symbol, etc. in previous phases can all trigger the
    // need for the callee.
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    // Similar reasoning applies to __scope__ symbol: if the function doesn't need either parent scope and none of
    // its blocks create a scope, we ensure it doesn't get a slot, but we can't determine whether it needs a scope
    // earlier than this phase.
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }

    return true;
}
 
Example #8
Source File: Lower.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example #9
Source File: TypeMap.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
MethodType getCallSiteType(final FunctionNode functionNode) {
    assert this.functionNodeId == functionNode.getId();
    final Type[] types = paramTypes;
    MethodType mt = MethodType.methodType(returnType.getTypeClass());
    if (needsCallee) {
        mt = mt.appendParameterTypes(ScriptFunction.class);
    }

    mt = mt.appendParameterTypes(Object.class); //this

    for (final Type type : types) {
        if (type == null) {
            return null; // not all parameter information is supplied
        }
        mt = mt.appendParameterTypes(type.getTypeClass());
    }

    return mt;
}
 
Example #10
Source File: FoldConstants.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
 
Example #11
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
    if (functionNode.isLazy()) {
        return false;
    }

    // If the function doesn't need a callee, we ensure its __callee__ symbol doesn't get a slot. We can't do
    // this earlier, as access to scoped variables, self symbol, etc. in previous phases can all trigger the
    // need for the callee.
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    // Similar reasoning applies to __scope__ symbol: if the function doesn't need either parent scope and none of
    // its blocks create a scope, we ensure it doesn't get a slot, but we can't determine whether it needs a scope
    // earlier than this phase.
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }

    return true;
}
 
Example #12
Source File: FoldConstants.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
 
Example #13
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveFunctionNode(final FunctionNode functionNode) {
    try {
        if(emittedMethods.add(functionNode.getName())) {
            method.end(); // wrap up this method
            unit   = lc.popCompileUnit(functionNode.getCompileUnit());
            method = lc.popMethodEmitter(method);
            LOG.info("=== END ", functionNode.getName());
        }

        final FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.EMITTED);
        newFunctionObject(newFunctionNode, functionNode);
        return newFunctionNode;
    } catch (final Throwable t) {
        Context.printStackTrace(t);
        final VerifyError e = new VerifyError("Code generation bug in \"" + functionNode.getName() + "\": likely stack misaligned: " + t + " " + functionNode.getSource().getName());
        e.initCause(t);
        throw e;
    }
}
 
Example #14
Source File: Splitter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static List<FunctionNode> directChildren(final FunctionNode functionNode) {
    final List<FunctionNode> dc = new ArrayList<>();
    functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
        @Override
        public boolean enterFunctionNode(final FunctionNode child) {
            if (child == functionNode) {
                return true;
            }
            if (lc.getParentFunction(child) == functionNode) {
                dc.add(child);
            }
            return false;
        }
    });
    return dc;
}
 
Example #15
Source File: AssignSymbols.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This has to run before fix assignment types, store any type specializations for
 * parameters, then turn them into objects for the generic version of this method.
 *
 * @param functionNode functionNode
 */
private FunctionNode finalizeParameters(final FunctionNode functionNode) {
    final List<IdentNode> newParams = new ArrayList<>();
    final boolean isVarArg = functionNode.isVarArg();

    final Block body = functionNode.getBody();
    for (final IdentNode param : functionNode.getParameters()) {
        final Symbol paramSymbol = body.getExistingSymbol(param.getName());
        assert paramSymbol != null;
        assert paramSymbol.isParam() : paramSymbol + " " + paramSymbol.getFlags();
        newParams.add(param.setSymbol(paramSymbol));

        // parameters should not be slots for a function that uses variable arity signature
        if (isVarArg) {
            paramSymbol.setNeedsSlot(false);
        }
    }

    return functionNode.setParameters(lc, newParams);
}
 
Example #16
Source File: MethodEmitter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - internal use from ClassEmitter only
 * @see ClassEmitter#method
 *
 * @param classEmitter the class emitter weaving the class this method is in
 * @param method       a method visitor
 * @param functionNode a function node representing this method
 */
MethodEmitter(final ClassEmitter classEmitter, final MethodVisitor method, final FunctionNode functionNode) {
    this.context      = classEmitter.getContext();
    this.classEmitter = classEmitter;
    this.method       = method;
    this.functionNode = functionNode;
    this.stack        = null;
    this.log          = context.getLogger(CodeGenerator.class);
    this.debug        = log.isEnabled();
}
 
Example #17
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private FunctionNode restoreFunctionNode(final FunctionNode functionNode, final long lastToken) {
final Block newBody = restoreBlock(lc.getFunctionBody(functionNode));

return lc.pop(functionNode).
    setBody(lc, newBody).
    setLastToken(lc, lastToken).
    setState(lc, errors.hasErrors() ? CompilationState.PARSE_ERROR : CompilationState.PARSED).
    snapshot(lc);
}
 
Example #18
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - internal use from ClassEmitter only
 * @see ClassEmitter#method
 *
 * @param classEmitter the class emitter weaving the class this method is in
 * @param method       a method visitor
 * @param functionNode a function node representing this method
 */
MethodEmitter(final ClassEmitter classEmitter, final MethodVisitor method, final FunctionNode functionNode) {
    this.context      = classEmitter.getContext();
    this.classEmitter = classEmitter;
    this.method       = method;
    this.functionNode = functionNode;
    this.stack        = null;
    this.log          = context.getLogger(CodeGenerator.class);
    this.debug        = log.isEnabled();
}
 
Example #19
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean skipFunctionBody(final FunctionNode functionNode) {
    if (reparsedFunction == null) {
        // Not reparsing, so don't skip any function body.
        return false;
    }
    // Skip to the RBRACE of this function, and continue parsing from there.
    final RecompilableScriptFunctionData data = reparsedFunction.getScriptFunctionData(functionNode.getId());
    if (data == null) {
        // Nested function is not known to the reparsed function. This can happen if the FunctionNode was
        // in dead code that was removed. Both FoldConstants and Lower prune dead code. In that case, the
        // FunctionNode was dropped before a RecompilableScriptFunctionData could've been created for it.
        return false;
    }
    final ParserState parserState = (ParserState)data.getEndParserState();
    assert parserState != null;

    stream.reset();
    lexer = parserState.createLexer(source, lexer, stream, scripting && !env._no_syntax_extensions);
    line = parserState.line;
    linePosition = parserState.linePosition;
    // Doesn't really matter, but it's safe to treat it as if there were a semicolon before
    // the RBRACE.
    type = SEMICOLON;
    k = -1;
    next();

    return true;
}
 
Example #20
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
    if (functionNode.isLazy()) {
        // Must do it now; can't postpone it until leaveFunctionNode()
        newFunctionObject(functionNode, functionNode);
        return false;
    }

    final String fnName = functionNode.getName();
    // NOTE: we only emit the method for a function with the given name once. We can have multiple functions with
    // the same name as a result of inlining finally blocks. However, in the future -- with type specialization,
    // notably -- we might need to check for both name *and* signature. Of course, even that might not be
    // sufficient; the function might have a code dependency on the type of the variables in its enclosing scopes,
    // and the type of such a variable can be different in catch and finally blocks. So, in the future we will have
    // to decide to either generate a unique method for each inlined copy of the function, maybe figure out its
    // exact type closure and deduplicate based on that, or just decide that functions in finally blocks aren't
    // worth it, and generate one method with most generic type closure.
    if(!emittedMethods.contains(fnName)) {
        LOG.info("=== BEGIN ", fnName);

        assert functionNode.getCompileUnit() != null : "no compile unit for " + fnName + " " + Debug.id(functionNode);
        unit = lc.pushCompileUnit(functionNode.getCompileUnit());
        assert lc.hasCompileUnits();

        method = lc.pushMethodEmitter(unit.getClassEmitter().method(functionNode));
        // new method - reset last line number
        lastLineNumber = -1;
        // Mark end for variable tables.
        method.begin();
    }

    return true;
}
 
Example #21
Source File: FunctionSignature.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a function signature given a function node, using as much
 * type information for parameters and return types that is available
 *
 * @param functionNode the function node
 */
public FunctionSignature(final FunctionNode functionNode) {
    this(
        true,
        functionNode.needsCallee(),
        functionNode.getReturnType(),
        (functionNode.isVarArg() && !functionNode.isProgram()) ?
            null :
            functionNode.getParameters());
}
 
Example #22
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Define symbols for all variable declarations at the top of the function scope. This way we can get around
 * problems like
 *
 * while (true) {
 *   break;
 *   if (true) {
 *     var s;
 *   }
 * }
 *
 * to an arbitrary nesting depth.
 *
 * see NASHORN-73
 *
 * @param functionNode the FunctionNode we are entering
 * @param body the body of the FunctionNode we are entering
 */
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
    // This visitor will assign symbol to all declared variables.
    body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
        @Override
        protected boolean enterDefault(final Node node) {
            // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
            // This will also prevent visiting nested functions (as FunctionNode is an expression).
            return !(node instanceof Expression);
        }

        @Override
        public Node leaveVarNode(final VarNode varNode) {
            final IdentNode ident  = varNode.getName();
            final boolean blockScoped = varNode.isBlockScoped();
            if (blockScoped && lc.inUnprotectedSwitchContext()) {
                throwUnprotectedSwitchError(varNode);
            }
            final Block block = blockScoped ? lc.getCurrentBlock() : body;
            final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
            if (varNode.isFunctionDeclaration()) {
                symbol.setIsFunctionDeclaration();
            }
            return varNode.setName(ident.setSymbol(symbol));
        }
    });
}
 
Example #23
Source File: FindScopeDepths.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static Block findBodyBlock(final LexicalContext lc, final FunctionNode fn, final Block block) {
    final Iterator<Block> iter = lc.getBlocks(block);
    while (iter.hasNext()) {
        final Block next = iter.next();
        if (fn.getBody() == next) {
            return next;
        }
    }
    return null;
}
 
Example #24
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCallNode(final CallNode callNode) {
    // AccessSpecializer - call return type may change the access for this location
    final Node function = callNode.getFunction();
    if (function instanceof FunctionNode) {
        return setTypeOverride(callNode, ((FunctionNode)function).getReturnType());
    }
    return callNode;
}
 
Example #25
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns AST as JSON compatible string.
 *
 * @param context context
 * @param code code to be parsed
 * @param name name of the code source (used for location)
 * @param includeLoc tells whether to include location information for nodes or not
 * @return JSON string representation of AST of the supplied code
 */
public static String parse(final Context context, final String code, final String name, final boolean includeLoc) {
    final Parser       parser     = new Parser(context.getEnv(), sourceFor(name, code), new Context.ThrowErrorManager(), context.getEnv()._strict, context.getLogger(Parser.class));
    final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
    try {
        final FunctionNode functionNode = parser.parse(); //symbol name is ":program", default
        functionNode.accept(jsonWriter);
        return jsonWriter.getString();
    } catch (final ParserException e) {
        e.throwAsEcmaException();
        return null;
    }
}
 
Example #26
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Define symbols for all variable declarations at the top of the function scope. This way we can get around
 * problems like
 *
 * while (true) {
 *   break;
 *   if (true) {
 *     var s;
 *   }
 * }
 *
 * to an arbitrary nesting depth.
 *
 * see NASHORN-73
 *
 * @param functionNode the FunctionNode we are entering
 * @param body the body of the FunctionNode we are entering
 */
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
    // This visitor will assign symbol to all declared variables.
    body.accept(new SimpleNodeVisitor() {
        @Override
        protected boolean enterDefault(final Node node) {
            // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
            // This will also prevent visiting nested functions (as FunctionNode is an expression).
            return !(node instanceof Expression);
        }

        @Override
        public Node leaveVarNode(final VarNode varNode) {
            final IdentNode ident  = varNode.getName();
            final boolean blockScoped = varNode.isBlockScoped();
            if (blockScoped && lc.inUnprotectedSwitchContext()) {
                throwUnprotectedSwitchError(varNode);
            }
            final Block block = blockScoped ? lc.getCurrentBlock() : body;
            final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
            if (varNode.isFunctionDeclaration()) {
                symbol.setIsFunctionDeclaration();
            }
            return varNode.setName(ident.setSymbol(symbol));
        }
    });
}
 
Example #27
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void fixScopeSlot(final FunctionNode functionNode) {
    // TODO hack to move the scope to the expected slot (needed because split methods reuse the same slots as the root method)
    if (functionNode.compilerConstant(SCOPE).getSlot() != SCOPE.slot()) {
        method.load(Type.typeFor(ScriptObject.class), SCOPE.slot());
        method.storeCompilerConstant(SCOPE);
    }
}
 
Example #28
Source File: CompilationPhase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final Set<CompileUnit> unitSet = CompileUnit.createCompileUnitSet();
    final Map<CompileUnit, CompileUnit> unitMap = new HashMap<>();

    // Ensure that the FunctionNode's compile unit is the first in the list of new units. Install phase
    // will use that as the root class.
    createCompileUnit(fn.getCompileUnit(), unitSet, unitMap, compiler, phases);

    final FunctionNode newFn = transformFunction(fn, new ReplaceCompileUnits() {
        @Override
        CompileUnit getReplacement(final CompileUnit oldUnit) {
            final CompileUnit existing = unitMap.get(oldUnit);
            if (existing != null) {
                return existing;
            }
            return createCompileUnit(oldUnit, unitSet, unitMap, compiler, phases);
        }

        @Override
        public Node leaveFunctionNode(final FunctionNode fn2) {
            return super.leaveFunctionNode(
                    // restore flags for deserialized nested function nodes
                    compiler.getScriptFunctionData(fn2.getId()).restoreFlags(lc, fn2));
        };
    });
    compiler.replaceCompileUnits(unitSet);
    return newFn;
}
 
Example #29
Source File: Compiler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Compiler(
        final Context context,
        final CodeInstaller installer,
        final Source source,
        final ErrorManager errors,
        final boolean isStrict,
        final boolean isOnDemand,
        final RecompilableScriptFunctionData compiledFunction,
        final TypeMap types,
        final Map<Integer, Type> invalidatedProgramPoints,
        final Object typeInformationFile,
        final int[] continuationEntryPoints,
        final ScriptObject runtimeScope) {
    this.context                  = context;
    this.env                      = context.getEnv();
    this.installer                = installer;
    this.constantData             = new ConstantData();
    this.compileUnits             = CompileUnit.createCompileUnitSet();
    this.bytecode                 = new LinkedHashMap<>();
    this.log                      = initLogger(context);
    this.source                   = source;
    this.errors                   = errors;
    this.sourceName               = FunctionNode.getSourceName(source);
    this.onDemand                 = isOnDemand;
    this.compiledFunction         = compiledFunction;
    this.types                    = types;
    this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new HashMap<Integer, Type>() : invalidatedProgramPoints;
    this.typeInformationFile      = typeInformationFile;
    this.continuationEntryPoints  = continuationEntryPoints == null ? null: continuationEntryPoints.clone();
    this.typeEvaluator            = new TypeEvaluator(this, runtimeScope);
    this.firstCompileUnitName     = firstCompileUnitName();
    this.strict                   = isStrict;

    this.optimistic = env._optimistic_types;
}
 
Example #30
Source File: RecompilableScriptFunctionData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check whether a certain name is a global symbol, i.e. only exists as defined
 * in outermost scope and not shadowed by being parameter or assignment in inner
 * scopes
 *
 * @param functionNode function node to check
 * @param symbolName symbol name
 * @return true if global symbol
 */
public boolean isGlobalSymbol(final FunctionNode functionNode, final String symbolName) {
    RecompilableScriptFunctionData data = getScriptFunctionData(functionNode.getId());
    assert data != null;

    do {
        if (data.hasInternalSymbol(symbolName)) {
            return false;
        }
        data = data.getParent();
    } while(data != null);

    return true;
}