Java Code Examples for jdk.nashorn.internal.ir.RuntimeNode#Request

The following examples show how to use jdk.nashorn.internal.ir.RuntimeNode#Request . 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: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 2
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean specializationCheck(final RuntimeNode.Request request, final Expression node, final List<Expression> args) {
    if (!request.canSpecialize()) {
        return false;
    }

    assert args.size() == 2;
    final Type returnType = node.getType();

    load(args.get(0));
    load(args.get(1));

    Request finalRequest = request;

    //if the request is a comparison, i.e. one that can be reversed
    //it keeps its semantic, but make sure that the object comes in
    //last
    final Request reverse = Request.reverse(request);
    if (method.peekType().isObject() && reverse != null) { //rhs is object
        if (!method.peekType(1).isObject()) { //lhs is not object
            method.swap(); //prefer object as lhs
            finalRequest = reverse;
        }
    }

    method.dynamicRuntimeCall(
            new SpecializedRuntimeNode(
                finalRequest,
                new Type[] {
                    method.peekType(1),
                    method.peekType()
                },
                returnType).getInitialName(),
            returnType,
            finalRequest);

    method.convert(node.getType());
    method.store(node.getSymbol());

    return true;
}
 
Example 3
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Exit a comparison node and do the appropriate replacements. We need to introduce runtime
 * nodes late for comparisons as types aren't known until the last minute
 *
 * Both compares and adds may turn into runtimes node at this level as when we first bump
 * into the op in Attr, we may type it according to what we know there, which may be wrong later
 *
 * e.g. i (int) < 5 -> normal compare
 *     i = object
 *  then the post pass that would add the conversion to the 5 needs to
 *
 * @param binaryNode binary node to leave
 * @param request    runtime request
 * @return lowered cmp node
 */
@SuppressWarnings("fallthrough")
private Node leaveCmp(final BinaryNode binaryNode, final RuntimeNode.Request request) {
    final Expression lhs    = binaryNode.lhs();
    final Expression rhs    = binaryNode.rhs();

    Type widest = Type.widest(lhs.getType(), rhs.getType());

    boolean newRuntimeNode = false, finalized = false;
    switch (request) {
    case EQ_STRICT:
    case NE_STRICT:
        if (lhs.getType().isBoolean() != rhs.getType().isBoolean()) {
            newRuntimeNode = true;
            widest = Type.OBJECT;
            finalized = true;
        }
        //fallthru
    default:
        if (newRuntimeNode || widest.isObject()) {
            return new RuntimeNode(binaryNode, request).setIsFinal(finalized);
        }
        break;
    }

    return binaryNode.setLHS(convert(lhs, widest)).setRHS(convert(rhs, widest));
}
 
Example 4
Source File: MethodEmitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a dynamic call for a runtime node
 *
 * @param name       tag for the invoke dynamic for this runtime node
 * @param returnType return type
 * @param request    RuntimeNode request
 *
 * @return the method emitter
 */
MethodEmitter dynamicRuntimeCall(final String name, final Type returnType, final RuntimeNode.Request request) {
    debug("dynamic_runtime_call", name, "args=", request.getArity(), "returnType=", returnType);
    final String signature = getDynamicSignature(returnType, request.getArity());
    debug("   signature", signature);
    method.visitInvokeDynamicInsn(name, signature, RUNTIMEBOOTSTRAP);
    pushType(returnType);

    return this;
}
 
Example 5
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 6
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 7
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean specializationCheck(final RuntimeNode.Request request, final Expression node, final List<Expression> args) {
    if (!request.canSpecialize()) {
        return false;
    }

    assert args.size() == 2;
    final Type returnType = node.getType();

    load(args.get(0));
    load(args.get(1));

    Request finalRequest = request;

    //if the request is a comparison, i.e. one that can be reversed
    //it keeps its semantic, but make sure that the object comes in
    //last
    final Request reverse = Request.reverse(request);
    if (method.peekType().isObject() && reverse != null) { //rhs is object
        if (!method.peekType(1).isObject()) { //lhs is not object
            method.swap(); //prefer object as lhs
            finalRequest = reverse;
        }
    }

    method.dynamicRuntimeCall(
            new SpecializedRuntimeNode(
                finalRequest,
                new Type[] {
                    method.peekType(1),
                    method.peekType()
                },
                returnType).getInitialName(),
            returnType,
            finalRequest);

    method.convert(node.getType());
    method.store(node.getSymbol());

    return true;
}
 
Example 8
Source File: MethodEmitter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a dynamic call for a runtime node
 *
 * @param name       tag for the invoke dynamic for this runtime node
 * @param returnType return type
 * @param request    RuntimeNode request
 *
 * @return the method emitter
 */
MethodEmitter dynamicRuntimeCall(final String name, final Type returnType, final RuntimeNode.Request request) {
    debug("dynamic_runtime_call", name, "args=", request.getArity(), "returnType=", returnType);
    final String signature = getDynamicSignature(returnType, request.getArity());
    debug("   signature", signature);
    method.visitInvokeDynamicInsn(name, signature, RUNTIMEBOOTSTRAP);
    pushType(returnType);

    return this;
}
 
Example 9
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 10
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean specializationCheck(final RuntimeNode.Request request, final Expression node, final List<Expression> args) {
    if (!request.canSpecialize()) {
        return false;
    }

    assert args.size() == 2;
    final Type returnType = node.getType();

    load(args.get(0));
    load(args.get(1));

    Request finalRequest = request;

    //if the request is a comparison, i.e. one that can be reversed
    //it keeps its semantic, but make sure that the object comes in
    //last
    final Request reverse = Request.reverse(request);
    if (method.peekType().isObject() && reverse != null) { //rhs is object
        if (!method.peekType(1).isObject()) { //lhs is not object
            method.swap(); //prefer object as lhs
            finalRequest = reverse;
        }
    }

    method.dynamicRuntimeCall(
            new SpecializedRuntimeNode(
                finalRequest,
                new Type[] {
                    method.peekType(1),
                    method.peekType()
                },
                returnType).getInitialName(),
            returnType,
            finalRequest);

    method.convert(node.getType());
    method.store(node.getSymbol());

    return true;
}
 
Example 11
Source File: MethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a dynamic call for a runtime node
 *
 * @param name       tag for the invoke dynamic for this runtime node
 * @param returnType return type
 * @param request    RuntimeNode request
 *
 * @return the method emitter
 */
MethodEmitter dynamicRuntimeCall(final String name, final Type returnType, final RuntimeNode.Request request) {
    debug("dynamic_runtime_call", name, "args=", request.getArity(), "returnType=", returnType);
    final String signature = getDynamicSignature(returnType, request.getArity());
    debug("   signature", signature);
    method.visitInvokeDynamicInsn(name, signature, RUNTIMEBOOTSTRAP);
    pushType(returnType);

    return this;
}
 
Example 12
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 13
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 14
Source File: JSONWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 15
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 16
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
    final RuntimeNode.Request req = runtimeNode.getRequest();

    if (req == RuntimeNode.Request.DEBUGGER) {
        enterDefault(runtimeNode);
        type("DebuggerStatement");
        return leave();
    }

    return false;
}
 
Example 17
Source File: RuntimeCallSite.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param request        runtime node request to specialize
 * @param parameterTypes parameter types of the call site
 * @param returnType     return type of the call site
 */
SpecializedRuntimeNode(final RuntimeNode.Request request, final Type[] parameterTypes, final Type returnType) {
    this.request        = request;
    this.parameterTypes = parameterTypes;
    this.returnType     = returnType;
}
 
Example 18
Source File: RuntimeCallSite.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param request        runtime node request to specialize
 * @param parameterTypes parameter types of the call site
 * @param returnType     return type of the call site
 */
SpecializedRuntimeNode(final RuntimeNode.Request request, final Type[] parameterTypes, final Type returnType) {
    this.request        = request;
    this.parameterTypes = parameterTypes;
    this.returnType     = returnType;
}
 
Example 19
Source File: RuntimeCallSite.java    From nashorn with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param request        runtime node request to specialize
 * @param parameterTypes parameter types of the call site
 * @param returnType     return type of the call site
 */
SpecializedRuntimeNode(final RuntimeNode.Request request, final Type[] parameterTypes, final Type returnType) {
    this.request        = request;
    this.parameterTypes = parameterTypes;
    this.returnType     = returnType;
}