jdk.nashorn.internal.codegen.types.Range Java Examples

The following examples show how to use jdk.nashorn.internal.codegen.types.Range. 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 openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Symbol setRange(final Expression dest, final Range range) {
    if (range.isUnknown()) {
        return null;
    }

    final Symbol symbol = dest.getSymbol();
    assert symbol != null : dest + " " + dest.getClass() + " has no symbol";
    assert symbol.getRange() != null : symbol + " has no range";
    final Range symRange = RANGE.join(symbol.getRange(), range);

    //anything assigned in the loop, not being the safe loop counter(s) invalidates its entire range
    if (lc.inLoop() && !isLoopCounter(lc.getCurrentLoop(), symbol)) {
        symbol.setRange(Range.createGenericRange());
        return symbol;
    }

    if (!symRange.equals(symbol.getRange())) {
        LOG.fine("Modify range for " + dest + " " + symbol + " from " + symbol.getRange() + " to " + symRange + " (in node = " + dest + ")" );
        symbol.setRange(symRange);
    }

    return null;
}
 
Example #2
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Symbol setRange(final Expression dest, final Range range) {
    if (range.isUnknown()) {
        return null;
    }

    final Symbol symbol = dest.getSymbol();
    assert symbol != null : dest + " " + dest.getClass() + " has no symbol";
    assert symbol.getRange() != null : symbol + " has no range";
    final Range symRange = RANGE.join(symbol.getRange(), range);

    //anything assigned in the loop, not being the safe loop counter(s) invalidates its entire range
    if (lc.inLoop() && !isLoopCounter(lc.getCurrentLoop(), symbol)) {
        symbol.setRange(Range.createGenericRange());
        return symbol;
    }

    if (!symRange.equals(symbol.getRange())) {
        LOG.fine("Modify range for " + dest + " " + symbol + " from " + symbol.getRange() + " to " + symRange + " (in node = " + dest + ")" );
        symbol.setRange(symRange);
    }

    return null;
}
 
Example #3
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Symbol setRange(final Expression dest, final Range range) {
    if (range.isUnknown()) {
        return null;
    }

    final Symbol symbol = dest.getSymbol();
    assert symbol != null : dest + " " + dest.getClass() + " has no symbol";
    assert symbol.getRange() != null : symbol + " has no range";
    final Range symRange = RANGE.join(symbol.getRange(), range);

    //anything assigned in the loop, not being the safe loop counter(s) invalidates its entire range
    if (lc.inLoop() && !isLoopCounter(lc.getCurrentLoop(), symbol)) {
        symbol.setRange(Range.createGenericRange());
        return symbol;
    }

    if (!symRange.equals(symbol.getRange())) {
        LOG.fine("Modify range for " + dest + " " + symbol + " from " + symbol.getRange() + " to " + symRange + " (in node = " + dest + ")" );
        symbol.setRange(symRange);
    }

    return null;
}
 
Example #4
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(@SuppressWarnings("rawtypes") final LiteralNode node) {
    if (node.getType().isInteger()) {
        setRange(node, Range.createRange(node.getInt32()));
    } else if (node.getType().isNumber()) {
        setRange(node, Range.createRange(node.getNumber()));
    } else if (node.getType().isLong()) {
        setRange(node, Range.createRange(node.getLong()));
    } else if (node.getType().isBoolean()) {
        setRange(node, Range.createTypeRange(Type.BOOLEAN));
    } else {
        setRange(node, Range.createGenericRange());
    }
    return node;
}
 
Example #5
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveVarNode(final VarNode node) {
    if (node.isAssignment()) {
        Range range = node.getInit().getSymbol().getRange();
        range = range.isUnknown() ? Range.createGenericRange() : range;

        setRange(node.getName(), range);
    }

    return node;
}
 
Example #6
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(@SuppressWarnings("rawtypes") final LiteralNode node) {
    if (node.getType().isInteger()) {
        setRange(node, Range.createRange(node.getInt32()));
    } else if (node.getType().isNumber()) {
        setRange(node, Range.createRange(node.getNumber()));
    } else if (node.getType().isLong()) {
        setRange(node, Range.createRange(node.getLong()));
    } else if (node.getType().isBoolean()) {
        setRange(node, Range.createTypeRange(Type.BOOLEAN));
    } else {
        setRange(node, Range.createGenericRange());
    }
    return node;
}
 
Example #7
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveADD(final UnaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (!range.getType().isNumeric()) {
       range = Range.createTypeRange(Type.NUMBER);
    }
    setRange(node, range);
    return node;
}
 
Example #8
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #9
Source File: Symbol.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param name  name of symbol
 * @param flags symbol flags
 * @param type  type of this symbol
 * @param slot  bytecode slot for this symbol
 */
protected Symbol(final String name, final int flags, final Type type, final int slot) {
    this.name       = name;
    this.flags      = flags;
    this.type       = type;
    this.slot       = slot;
    this.fieldIndex = -1;
    this.range      = Range.createUnknownRange();
    trace("CREATE SYMBOL");
}
 
Example #10
Source File: Symbol.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param name  name of symbol
 * @param flags symbol flags
 * @param type  type of this symbol
 * @param slot  bytecode slot for this symbol
 */
protected Symbol(final String name, final int flags, final Type type, final int slot) {
    this.name       = name;
    this.flags      = flags;
    this.type       = type;
    this.slot       = slot;
    this.fieldIndex = -1;
    this.range      = Range.createUnknownRange();
    trace("CREATE SYMBOL");
}
 
Example #11
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveASSIGN(final BinaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (range.isUnknown()) {
        range = Range.createGenericRange();
    }

    setRange(node.lhs(), range);
    setRange(node, range);

    return node;
}
 
Example #12
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveASSIGN(final BinaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (range.isUnknown()) {
        range = Range.createGenericRange();
    }

    setRange(node.lhs(), range);
    setRange(node, range);

    return node;
}
 
Example #13
Source File: Symbol.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param name  name of symbol
 * @param flags symbol flags
 * @param type  type of this symbol
 * @param slot  bytecode slot for this symbol
 */
protected Symbol(final String name, final int flags, final Type type, final int slot) {
    this.name       = name;
    this.flags      = flags;
    this.type       = type;
    this.slot       = slot;
    this.fieldIndex = -1;
    this.range      = Range.createUnknownRange();
    trace("CREATE SYMBOL");
}
 
Example #14
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveVarNode(final VarNode node) {
    if (node.isAssignment()) {
        Range range = node.getInit().getSymbol().getRange();
        range = range.isUnknown() ? Range.createGenericRange() : range;

        setRange(node.getName(), range);
    }

    return node;
}
 
Example #16
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveADD(final UnaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (!range.getType().isNumeric()) {
       range = Range.createTypeRange(Type.NUMBER);
    }
    setRange(node, range);
    return node;
}
 
Example #17
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveADD(final UnaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (!range.getType().isNumeric()) {
       range = Range.createTypeRange(Type.NUMBER);
    }
    setRange(node, range);
    return node;
}
 
Example #18
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveASSIGN(final BinaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (range.isUnknown()) {
        range = Range.createGenericRange();
    }

    setRange(node.lhs(), range);
    setRange(node, range);

    return node;
}
 
Example #19
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveVarNode(final VarNode node) {
    if (node.isAssignment()) {
        Range range = node.getInit().getSymbol().getRange();
        range = range.isUnknown() ? Range.createGenericRange() : range;

        setRange(node.getName(), range);
    }

    return node;
}
 
Example #20
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(@SuppressWarnings("rawtypes") final LiteralNode node) {
    if (node.getType().isInteger()) {
        setRange(node, Range.createRange(node.getInt32()));
    } else if (node.getType().isNumber()) {
        setRange(node, Range.createRange(node.getNumber()));
    } else if (node.getType().isLong()) {
        setRange(node, Range.createRange(node.getLong()));
    } else if (node.getType().isBoolean()) {
        setRange(node, Range.createTypeRange(Type.BOOLEAN));
    } else {
        setRange(node, Range.createGenericRange());
    }
    return node;
}
 
Example #21
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #22
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveASSIGN_DIV(final BinaryNode node) {
    return leaveSelfModifyingAssign(node, Range.createTypeRange(Type.NUMBER));
}
 
Example #23
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private Node leaveSelfModifyingAssign(final UnaryNode node, final Range range) {
    setRange(node.rhs(), range);
    setRange(node, range);
    return node;
}
 
Example #24
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private Node leaveSelfModifyingAssign(final BinaryNode node, final Range range) {
    setRange(node.lhs(), range);
    setRange(node, range);
    return node;
}
 
Example #25
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveASSIGN_DIV(final BinaryNode node) {
    return leaveSelfModifyingAssign(node, Range.createTypeRange(Type.NUMBER));
}
 
Example #26
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private Node leaveCmp(final BinaryNode node) {
    setRange(node, Range.createTypeRange(Type.BOOLEAN));
    return node;
}
 
Example #27
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveASSIGN_MOD(final BinaryNode node) {
    return leaveSelfModifyingAssign(node, Range.createTypeRange(Type.NUMBER));
}
 
Example #28
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveBIT_NOT(final UnaryNode node) {
    setRange(node, Range.createTypeRange(Type.INT));
    return node;
}
 
Example #29
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveNOT(final UnaryNode node) {
    setRange(node, Range.createTypeRange(Type.BOOLEAN));
    return node;
}
 
Example #30
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveBIT_NOT(final UnaryNode node) {
    setRange(node, Range.createTypeRange(Type.INT));
    return node;
}