Java Code Examples for jdk.nashorn.internal.ir.FunctionNode#needsCallee()

The following examples show how to use jdk.nashorn.internal.ir.FunctionNode#needsCallee() . 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: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if various symbols that were provisionally marked as needing a slot ended up unused, and marks them as not
 * needing a slot after all.
 * @param functionNode the function node
 * @return the passed in node, for easy chaining
 */
private static FunctionNode removeUnusedSlots(final FunctionNode functionNode) {
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }
    // Named function expressions that end up not referencing themselves won't need a local slot for the self symbol.
    if(functionNode.isNamedFunctionExpression() && !functionNode.usesSelfSymbol()) {
        final Symbol selfSymbol = functionNode.getBody().getExistingSymbol(functionNode.getIdent().getName());
        if(selfSymbol != null && selfSymbol.isFunctionSelf()) {
            selfSymbol.setNeedsSlot(false);
            selfSymbol.clearFlag(Symbol.IS_VAR);
        }
    }
    return functionNode;
}
 
Example 2
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 3
Source File: RecompilableScriptFunctionData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 4
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if various symbols that were provisionally marked as needing a slot ended up unused, and marks them as not
 * needing a slot after all.
 * @param functionNode the function node
 * @return the passed in node, for easy chaining
 */
private static FunctionNode removeUnusedSlots(final FunctionNode functionNode) {
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }
    // Named function expressions that end up not referencing themselves won't need a local slot for the self symbol.
    if(functionNode.isNamedFunctionExpression() && !functionNode.usesSelfSymbol()) {
        final Symbol selfSymbol = functionNode.getBody().getExistingSymbol(functionNode.getIdent().getName());
        if(selfSymbol != null && selfSymbol.isFunctionSelf()) {
            selfSymbol.setNeedsSlot(false);
            selfSymbol.clearFlag(Symbol.IS_VAR);
        }
    }
    return functionNode;
}
 
Example 5
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    if (functionNode.isMethod() || functionNode.isClassConstructor()) {
        flags |= IS_ES6_METHOD;
    }
    return flags;
}
 
Example 6
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if various symbols that were provisionally marked as needing a slot ended up unused, and marks them as not
 * needing a slot after all.
 * @param functionNode the function node
 * @return the passed in node, for easy chaining
 */
private static FunctionNode removeUnusedSlots(final FunctionNode functionNode) {
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }
    // Named function expressions that end up not referencing themselves won't need a local slot for the self symbol.
    if(functionNode.isNamedFunctionExpression() && !functionNode.usesSelfSymbol()) {
        final Symbol selfSymbol = functionNode.getBody().getExistingSymbol(functionNode.getIdent().getName());
        if(selfSymbol != null && selfSymbol.isFunctionSelf()) {
            selfSymbol.setNeedsSlot(false);
            selfSymbol.clearFlag(Symbol.IS_VAR);
        }
    }
    return functionNode;
}
 
Example 7
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if various symbols that were provisionally marked as needing a slot ended up unused, and marks them as not
 * needing a slot after all.
 * @param functionNode the function node
 * @return the passed in node, for easy chaining
 */
private static FunctionNode removeUnusedSlots(final FunctionNode functionNode) {
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }
    // Named function expressions that end up not referencing themselves won't need a local slot for the self symbol.
    if(functionNode.isNamedFunctionExpression() && !functionNode.usesSelfSymbol()) {
        final Symbol selfSymbol = functionNode.getBody().getExistingSymbol(functionNode.getIdent().getName());
        if(selfSymbol != null && selfSymbol.isFunctionSelf()) {
            selfSymbol.setNeedsSlot(false);
            selfSymbol.clearFlag(Symbol.IS_VAR);
        }
    }
    return functionNode;
}
 
Example 8
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 9
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if various symbols that were provisionally marked as needing a slot ended up unused, and marks them as not
 * needing a slot after all.
 * @param functionNode the function node
 * @return the passed in node, for easy chaining
 */
private static FunctionNode removeUnusedSlots(final FunctionNode functionNode) {
    if (!functionNode.needsCallee()) {
        functionNode.compilerConstant(CALLEE).setNeedsSlot(false);
    }
    if (!(functionNode.hasScopeBlock() || functionNode.needsParentScope())) {
        functionNode.compilerConstant(SCOPE).setNeedsSlot(false);
    }
    // Named function expressions that end up not referencing themselves won't need a local slot for the self symbol.
    if(functionNode.isNamedFunctionExpression() && !functionNode.usesSelfSymbol()) {
        final Symbol selfSymbol = functionNode.getBody().getExistingSymbol(functionNode.getIdent().getName());
        if(selfSymbol != null && selfSymbol.isFunctionSelf()) {
            selfSymbol.setNeedsSlot(false);
            selfSymbol.clearFlag(Symbol.IS_VAR);
        }
    }
    return functionNode;
}
 
Example 10
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 11
Source File: FinalizeTypes.java    From openjdk-8 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: RecompilableScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 13
Source File: RecompilableScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 14
Source File: FunctionSignature.java    From openjdk-jdk8u 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 15
Source File: FunctionSignature.java    From jdk8u60 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 16
Source File: FunctionSignature.java    From openjdk-jdk9 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 17
Source File: FunctionSignature.java    From nashorn 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 18
Source File: FunctionSignature.java    From jdk8u_nashorn 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 19
Source File: FunctionSignature.java    From openjdk-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 20
Source File: FunctionSignature.java    From openjdk-8-source 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());
}