Java Code Examples for jdk.nashorn.internal.ir.LoopNode#getTest()
The following examples show how to use
jdk.nashorn.internal.ir.LoopNode#getTest() .
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: RangeAnalyzer.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Check for a loop counter. This is currently quite conservative, in that it only handles * x <= counter and x < counter. * * @param node loop node to check * @return */ private static Symbol findLoopCounter(final LoopNode node) { final Expression test = node.getTest(); if (test != null && test.isComparison()) { final BinaryNode binaryNode = (BinaryNode)test; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); //detect ident cmp int_literal if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) { final Symbol symbol = lhs.getSymbol(); final int margin = ((LiteralNode<?>)rhs).getInt32(); final TokenType op = test.tokenType(); switch (op) { case LT: case LE: symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin))); return symbol; case GT: case GE: //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin)); //return symbol; default: break; } } } return null; }
Example 2
Source File: RangeAnalyzer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Check for a loop counter. This is currently quite conservative, in that it only handles * x <= counter and x < counter. * * @param node loop node to check * @return */ private static Symbol findLoopCounter(final LoopNode node) { final Expression test = node.getTest(); if (test != null && test.isComparison()) { final BinaryNode binaryNode = (BinaryNode)test; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); //detect ident cmp int_literal if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) { final Symbol symbol = lhs.getSymbol(); final int margin = ((LiteralNode<?>)rhs).getInt32(); final TokenType op = test.tokenType(); switch (op) { case LT: case LE: symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin))); return symbol; case GT: case GE: //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin)); //return symbol; default: break; } } } return null; }
Example 3
Source File: RangeAnalyzer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Check for a loop counter. This is currently quite conservative, in that it only handles * x <= counter and x < counter. * * @param node loop node to check * @return */ private static Symbol findLoopCounter(final LoopNode node) { final Expression test = node.getTest(); if (test != null && test.isComparison()) { final BinaryNode binaryNode = (BinaryNode)test; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); //detect ident cmp int_literal if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) { final Symbol symbol = lhs.getSymbol(); final int margin = ((LiteralNode<?>)rhs).getInt32(); final TokenType op = test.tokenType(); switch (op) { case LT: case LE: symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin))); return symbol; case GT: case GE: //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin)); //return symbol; default: break; } } } return null; }
Example 4
Source File: OptimisticTypesCalculator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 5
Source File: LocalVariableTypesCalculator.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 6
Source File: OptimisticTypesCalculator.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 7
Source File: LocalVariableTypesCalculator.java From hottub with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 8
Source File: OptimisticTypesCalculator.java From hottub with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 9
Source File: LocalVariableTypesCalculator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 10
Source File: OptimisticTypesCalculator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 11
Source File: LocalVariableTypesCalculator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 12
Source File: OptimisticTypesCalculator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 13
Source File: LocalVariableTypesCalculator.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 14
Source File: OptimisticTypesCalculator.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 15
Source File: LocalVariableTypesCalculator.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }
Example 16
Source File: OptimisticTypesCalculator.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) { final JoinPredecessorExpression test = loopNode.getTest(); if(test != null) { tagNeverOptimistic(test.getExpression()); } }
Example 17
Source File: LocalVariableTypesCalculator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify, final Expression iteratorValues, final boolean iteratorValuesAreObject) { final JoinPredecessorExpression test = loopNode.getTest(); if(isAlwaysFalse(test)) { visitExpressionOnEmptyStack(test); return; } final Label continueLabel = loopNode.getContinueLabel(); final Label breakLabel = loopNode.getBreakLabel(); final Label repeatLabel = modify == null ? continueLabel : new Label(""); final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes; for(;;) { jumpToLabel(loopNode, repeatLabel, beforeLoopTypes); final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes; if(test != null) { visitExpressionOnEmptyStack(test); } if(!isAlwaysTrue(test)) { jumpToLabel(test, breakLabel); } if(iteratorValues instanceof IdentNode) { final IdentNode ident = (IdentNode)iteratorValues; // Receives iterator values; the optimistic type of the iterator values is tracked on the // identifier, but we override optimism if it's known that the object being iterated over will // never have primitive property names. onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT : toLvarType(compiler.getOptimisticType(ident))); } final Block body = loopNode.getBody(); body.accept(this); if(reachable) { jumpToLabel(body, continueLabel); } joinOnLabel(continueLabel); if(!reachable) { break; } if(modify != null) { visitExpressionOnEmptyStack(modify); jumpToLabel(modify, repeatLabel); joinOnLabel(repeatLabel); } if(localVariableTypes.equals(beforeRepeatTypes)) { break; } // Reset the join points and repeat the analysis resetJoinPoint(continueLabel); resetJoinPoint(breakLabel); resetJoinPoint(repeatLabel); } if(isAlwaysTrue(test) && iteratorValues == null) { doesNotContinueSequentially(); } leaveBreakable(loopNode); }