jdk.nashorn.internal.ir.LexicalContext Java Examples

The following examples show how to use jdk.nashorn.internal.ir.LexicalContext. 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: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        // NOTE: it is crucial to mark the body of the outer function as needing scope even when we skip
        // parsing a nested function. functionBody() contains code to compensate for the lack of invoking
        // this method when the parser skips a nested function.
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #2
Source File: FindScopeDepths.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static int findScopesToStart(final LexicalContext lc, final FunctionNode fn, final Block block) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break;
        }
        b = iter.next();
    }
    return scopesToStart;
}
 
Example #3
Source File: FindScopeDepths.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
static int findScopesToStart(final LexicalContext lc, final FunctionNode fn, final Block block) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break;
        }
        b = iter.next();
    }
    return scopesToStart;
}
 
Example #4
Source File: Splitter.java    From openjdk-8 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 #5
Source File: FindScopeDepths.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static int findInternalDepth(final LexicalContext lc, final FunctionNode fn, final Block block, final Symbol symbol) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (definedInBlock(b, symbol)) {
            return scopesToStart;
        }
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break; //don't go past body block, but process it
        }
        b = iter.next();
    }
    return -1;
}
 
Example #6
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        // NOTE: it is crucial to mark the body of the outer function as needing scope even when we skip
        // parsing a nested function. functionBody() contains code to compensate for the lack of invoking
        // this method when the parser skips a nested function.
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #7
Source File: FindScopeDepths.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static int findInternalDepth(final LexicalContext lc, final FunctionNode fn, final Block block, final Symbol symbol) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (definedInBlock(b, symbol)) {
            return scopesToStart;
        }
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break; //don't go past body block, but process it
        }
        b = iter.next();
    }
    return -1;
}
 
Example #8
Source File: Parser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        // NOTE: it is crucial to mark the body of the outer function as needing scope even when we skip
        // parsing a nested function. functionBody() contains code to compensate for the lack of invoking
        // this method when the parser skips a nested function.
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #9
Source File: FindScopeDepths.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static int findInternalDepth(final LexicalContext lc, final FunctionNode fn, final Block block, final Symbol symbol) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (definedInBlock(b, symbol)) {
            return scopesToStart;
        }
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break; //don't go past body block, but process it
        }
        b = iter.next();
    }
    return -1;
}
 
Example #10
Source File: FindScopeDepths.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static int findScopesToStart(final LexicalContext lc, final FunctionNode fn, final Block block) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break;
        }
        b = iter.next();
    }
    return scopesToStart;
}
 
Example #11
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        // NOTE: it is crucial to mark the body of the outer function as needing scope even when we skip
        // parsing a nested function. functionBody() contains code to compensate for the lack of invoking
        // this method when the parser skips a nested function.
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #12
Source File: FindScopeDepths.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static int findScopesToStart(final LexicalContext lc, final FunctionNode fn, final Block block) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break;
        }
        b = iter.next();
    }
    return scopesToStart;
}
 
Example #13
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        // NOTE: it is crucial to mark the body of the outer function as needing scope even when we skip
        // parsing a nested function. functionBody() contains code to compensate for the lack of invoking
        // this method when the parser skips a nested function.
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #14
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 #15
Source File: FindScopeDepths.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static int findInternalDepth(final LexicalContext lc, final FunctionNode fn, final Block block, final Symbol symbol) {
    final Block bodyBlock = findBodyBlock(lc, fn, block);
    final Iterator<Block> iter = lc.getBlocks(block);
    Block b = iter.next();
    int scopesToStart = 0;
    while (true) {
        if (definedInBlock(b, symbol)) {
            return scopesToStart;
        }
        if (b.needsScope()) {
            scopesToStart++;
        }
        if (b == bodyBlock) {
            break; //don't go past body block, but process it
        }
        b = iter.next();
    }
    return -1;
}
 
Example #16
Source File: RecompilableScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restores the {@link #getFunctionFlags()} flags to a function node. During on-demand compilation, we might need
 * to restore flags to a function node that was otherwise not subjected to a full compile pipeline (e.g. its parse
 * was skipped, or it's a nested function of a deserialized function.
 * @param lc current lexical context
 * @param fn the function node to restore flags onto
 * @return the transformed function node
 */
public FunctionNode restoreFlags(final LexicalContext lc, final FunctionNode fn) {
    assert fn.getId() == functionNodeId;
    FunctionNode newFn = fn.setFlags(lc, functionFlags);
    // This compensates for missing markEval() in case the function contains an inner function
    // that contains eval(), that now we didn't discover since we skipped the inner function.
    if (newFn.hasNestedEval()) {
        assert newFn.hasScopeBlock();
        newFn = newFn.setBody(lc, newFn.getBody().setNeedsScope(null));
    }
    return newFn;
}
 
Example #17
Source File: FindScopeDepths.java    From hottub 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 #18
Source File: Attr.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 */
Attr(final TemporarySymbols temporarySymbols) {
    super(new LexicalContext());
    this.temporarySymbols = temporarySymbols;
    this.localDefs   = new ArrayDeque<>();
    this.localUses   = new ArrayDeque<>();
    this.returnTypes = new ArrayDeque<>();
}
 
Example #19
Source File: FindScopeDepths.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Block findGlobalBlock(final LexicalContext lc, final Block block) {
    final Iterator<Block> iter = lc.getBlocks(block);
    Block globalBlock = null;
    while (iter.hasNext()) {
        globalBlock = iter.next();
    }
    return globalBlock;
}
 
Example #20
Source File: SplitMethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private int findExternalTarget(final LexicalContext lc, final Label label) {
    final int index = externalTargets.indexOf(label);

    if (index >= 0) {
        return index;
    }

    if (lc.isExternalTarget(splitNode, label)) {
        externalTargets.add(label);
        return externalTargets.size() - 1;
    }
    return -1;
}
 
Example #21
Source File: FindScopeDepths.java    From openjdk-jdk8u-backup 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 #22
Source File: SplitMethodEmitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
void splitAwareGoto(final LexicalContext lc, final Label label) {
    assert splitNode != null;
    final int index = findExternalTarget(lc, label);
    if (index >= 0) {
        loadCompilerConstant(SCOPE);
        checkcast(Scope.class);
        load(index + 1);
        invoke(Scope.SET_SPLIT_STATE);
        loadUndefined(Type.OBJECT);
        _return(functionNode.getReturnType());
        return;
    }
    super.splitAwareGoto(lc, label);
}
 
Example #23
Source File: FoldConstants.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void extractVarNodes(final Block block, final List<Statement> statements) {
    final LexicalContext lc = new LexicalContext();
    block.accept(lc, new NodeVisitor<LexicalContext>(lc) {
        @Override
        public boolean enterVarNode(VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }
    });
}
 
Example #24
Source File: Parser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static void markEval(final LexicalContext lc) {
    final Iterator<FunctionNode> iter = lc.getFunctions();
    boolean flaggedCurrentFn = false;
    while (iter.hasNext()) {
        final FunctionNode fn = iter.next();
        if (!flaggedCurrentFn) {
            lc.setFlag(fn, FunctionNode.HAS_EVAL);
            flaggedCurrentFn = true;
        } else {
            lc.setFlag(fn, FunctionNode.HAS_NESTED_EVAL);
        }
        lc.setBlockNeedsScope(lc.getFunctionBody(fn));
    }
}
 
Example #25
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restores the {@link #getFunctionFlags()} flags to a function node. During on-demand compilation, we might need
 * to restore flags to a function node that was otherwise not subjected to a full compile pipeline (e.g. its parse
 * was skipped, or it's a nested function of a deserialized function.
 * @param lc current lexical context
 * @param fn the function node to restore flags onto
 * @return the transformed function node
 */
public FunctionNode restoreFlags(final LexicalContext lc, final FunctionNode fn) {
    assert fn.getId() == functionNodeId;
    FunctionNode newFn = fn.setFlags(lc, functionFlags);
    // This compensates for missing markEval() in case the function contains an inner function
    // that contains eval(), that now we didn't discover since we skipped the inner function.
    if (newFn.hasNestedEval()) {
        assert newFn.hasScopeBlock();
        newFn = newFn.setBody(lc, newFn.getBody().setNeedsScope(null));
    }
    return newFn;
}
 
Example #26
Source File: FindScopeDepths.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Block findGlobalBlock(final LexicalContext lc, final Block block) {
    final Iterator<Block> iter = lc.getBlocks(block);
    Block globalBlock = null;
    while (iter.hasNext()) {
        globalBlock = iter.next();
    }
    return globalBlock;
}
 
Example #27
Source File: FindScopeDepths.java    From openjdk-jdk8u 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 #28
Source File: SplitMethodEmitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private int findExternalTarget(final LexicalContext lc, final Label label) {
    final int index = externalTargets.indexOf(label);

    if (index >= 0) {
        return index;
    }

    if (lc.isExternalTarget(splitNode, label)) {
        externalTargets.add(label);
        return externalTargets.size() - 1;
    }
    return -1;
}
 
Example #29
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restores the {@link #getFunctionFlags()} flags to a function node. During on-demand compilation, we might need
 * to restore flags to a function node that was otherwise not subjected to a full compile pipeline (e.g. its parse
 * was skipped, or it's a nested function of a deserialized function.
 * @param lc current lexical context
 * @param fn the function node to restore flags onto
 * @return the transformed function node
 */
public FunctionNode restoreFlags(final LexicalContext lc, final FunctionNode fn) {
    assert fn.getId() == functionNodeId;
    FunctionNode newFn = fn.setFlags(lc, functionFlags);
    // This compensates for missing markEval() in case the function contains an inner function
    // that contains eval(), that now we didn't discover since we skipped the inner function.
    if (newFn.hasNestedEval()) {
        assert newFn.hasScopeBlock();
        newFn = newFn.setBody(lc, newFn.getBody().setNeedsScope(null));
    }
    return newFn;
}
 
Example #30
Source File: RecompilableScriptFunctionData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restores the {@link #getFunctionFlags()} flags to a function node. During on-demand compilation, we might need
 * to restore flags to a function node that was otherwise not subjected to a full compile pipeline (e.g. its parse
 * was skipped, or it's a nested function of a deserialized function.
 * @param lc current lexical context
 * @param fn the function node to restore flags onto
 * @return the transformed function node
 */
public FunctionNode restoreFlags(final LexicalContext lc, final FunctionNode fn) {
    assert fn.getId() == functionNodeId;
    FunctionNode newFn = fn.setFlags(lc, functionFlags);
    // This compensates for missing markEval() in case the function contains an inner function
    // that contains eval(), that now we didn't discover since we skipped the inner function.
    if (newFn.hasNestedEval()) {
        assert newFn.hasScopeBlock();
        newFn = newFn.setBody(lc, newFn.getBody().setNeedsScope(null));
    }
    return newFn;
}