Search in sources :

Example 36 with JavaType

use of jdk.vm.ci.meta.JavaType in project graal by oracle.

the class BytecodeParser method lookupType.

protected JavaType lookupType(int cpi, int bytecode) {
    maybeEagerlyResolve(cpi, bytecode);
    JavaType result = constantPool.lookupType(cpi, bytecode);
    assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaType;
    return result;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 37 with JavaType

use of jdk.vm.ci.meta.JavaType in project graal by oracle.

the class BytecodeParser method appendInvoke.

protected Invoke appendInvoke(InvokeKind initialInvokeKind, ResolvedJavaMethod initialTargetMethod, ValueNode[] args) {
    ResolvedJavaMethod targetMethod = initialTargetMethod;
    InvokeKind invokeKind = initialInvokeKind;
    if (initialInvokeKind.isIndirect()) {
        ResolvedJavaType contextType = this.frameState.getMethod().getDeclaringClass();
        ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(initialInvokeKind, args[0], initialTargetMethod, contextType);
        if (specialCallTarget != null) {
            invokeKind = InvokeKind.Special;
            targetMethod = specialCallTarget;
        }
    }
    JavaKind resultType = targetMethod.getSignature().getReturnKind();
    if (!parsingIntrinsic() && DeoptALot.getValue(options)) {
        append(new DeoptimizeNode(DeoptimizationAction.None, RuntimeConstraint));
        frameState.pushReturn(resultType, ConstantNode.defaultForKind(resultType, graph));
        return null;
    }
    JavaType returnType = targetMethod.getSignature().getReturnType(method.getDeclaringClass());
    if (graphBuilderConfig.eagerResolving() || parsingIntrinsic()) {
        returnType = returnType.resolve(targetMethod.getDeclaringClass());
    }
    if (invokeKind.hasReceiver()) {
        args[0] = emitExplicitExceptions(args[0]);
    }
    if (initialInvokeKind == InvokeKind.Special && !targetMethod.isConstructor()) {
        emitCheckForInvokeSuperSpecial(args);
    }
    InlineInfo inlineInfo = null;
    try {
        currentInvoke = new CurrentInvoke(args, invokeKind, returnType);
        if (tryNodePluginForInvocation(args, targetMethod)) {
            if (TraceParserPlugins.getValue(options)) {
                traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)"));
            }
            return null;
        }
        if (invokeKind.hasReceiver() && args[0].isNullConstant()) {
            append(new DeoptimizeNode(InvalidateRecompile, NullCheckException));
            return null;
        }
        if (!invokeKind.isIndirect() || (UseGuardedIntrinsics.getValue(options) && !GeneratePIC.getValue(options))) {
            if (tryInvocationPlugin(invokeKind, args, targetMethod, resultType, returnType)) {
                if (TraceParserPlugins.getValue(options)) {
                    traceWithContext("used invocation plugin for %s", targetMethod.format("%h.%n(%p)"));
                }
                return null;
            }
        }
        if (invokeKind.isDirect()) {
            inlineInfo = tryInline(args, targetMethod);
            if (inlineInfo == SUCCESSFULLY_INLINED) {
                return null;
            }
        }
    } finally {
        currentInvoke = null;
    }
    int invokeBci = bci();
    JavaTypeProfile profile = getProfileForInvoke(invokeKind);
    ExceptionEdgeAction edgeAction = getActionForInvokeExceptionEdge(inlineInfo);
    boolean partialIntrinsicExit = false;
    if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
        partialIntrinsicExit = true;
        ResolvedJavaMethod originalMethod = intrinsicContext.getOriginalMethod();
        BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor();
        if (intrinsicCallSiteParser != null) {
            // When exiting a partial intrinsic, the invoke to the original
            // must use the same context as the call to the intrinsic.
            invokeBci = intrinsicCallSiteParser.bci();
            profile = intrinsicCallSiteParser.getProfileForInvoke(invokeKind);
            edgeAction = intrinsicCallSiteParser.getActionForInvokeExceptionEdge(inlineInfo);
        } else {
            // so the bci must be set to unknown, so that the inliner patches it later.
            assert intrinsicContext.isPostParseInlined();
            invokeBci = BytecodeFrame.UNKNOWN_BCI;
            profile = null;
            edgeAction = graph.method().getAnnotation(Snippet.class) == null ? ExceptionEdgeAction.INCLUDE_AND_HANDLE : ExceptionEdgeAction.OMIT;
        }
        if (originalMethod.isStatic()) {
            invokeKind = InvokeKind.Static;
        } else {
            // The original call to the intrinsic must have been devirtualized
            // otherwise we wouldn't be here.
            invokeKind = InvokeKind.Special;
        }
        Signature sig = originalMethod.getSignature();
        returnType = sig.getReturnType(method.getDeclaringClass());
        resultType = sig.getReturnKind();
        assert intrinsicContext.allowPartialIntrinsicArgumentMismatch() || checkPartialIntrinsicExit(intrinsicCallSiteParser == null ? null : intrinsicCallSiteParser.currentInvoke.args, args);
        targetMethod = originalMethod;
    }
    Invoke invoke = createNonInlinedInvoke(edgeAction, invokeBci, args, targetMethod, invokeKind, resultType, returnType, profile);
    if (partialIntrinsicExit) {
        // This invoke must never be later inlined as it might select the intrinsic graph.
        // Until there is a mechanism to guarantee that any late inlining will not select
        // the intrinsic graph, prevent this invoke from being inlined.
        invoke.setUseForInlining(false);
    }
    return invoke;
}
Also used : InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) Snippet(org.graalvm.compiler.api.replacements.Snippet) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) Signature(jdk.vm.ci.meta.Signature) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 38 with JavaType

use of jdk.vm.ci.meta.JavaType in project graal by oracle.

the class BytecodeParser method createExceptionDispatch.

private void createExceptionDispatch(ExceptionDispatchBlock block) {
    lastInstr = finishInstruction(lastInstr, frameState);
    assert frameState.stackSize() == 1 : frameState;
    if (block.handler.isCatchAll()) {
        assert block.getSuccessorCount() == 1;
        appendGoto(block.getSuccessor(0));
        return;
    }
    JavaType catchType = block.handler.getCatchType();
    if (graphBuilderConfig.eagerResolving()) {
        catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF);
    }
    if (catchType instanceof ResolvedJavaType) {
        TypeReference checkedCatchType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) catchType);
        if (graphBuilderConfig.getSkippedExceptionTypes() != null) {
            for (ResolvedJavaType skippedType : graphBuilderConfig.getSkippedExceptionTypes()) {
                if (skippedType.isAssignableFrom(checkedCatchType.getType())) {
                    BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
                    ValueNode exception = frameState.stack[0];
                    FixedNode trueSuccessor = graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode));
                    FixedNode nextDispatch = createTarget(nextBlock, frameState);
                    append(new IfNode(graph.addOrUniqueWithInputs(createInstanceOf(checkedCatchType, exception)), trueSuccessor, nextDispatch, 0));
                    return;
                }
            }
        }
        BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
        ValueNode exception = frameState.stack[0];
        /* Anchor for the piNode, which must be before any LoopExit inserted by createTarget. */
        BeginNode piNodeAnchor = graph.add(new BeginNode());
        ObjectStamp checkedStamp = StampFactory.objectNonNull(checkedCatchType);
        PiNode piNode = graph.addWithoutUnique(new PiNode(exception, checkedStamp));
        frameState.pop(JavaKind.Object);
        frameState.push(JavaKind.Object, piNode);
        FixedNode catchSuccessor = createTarget(block.getSuccessor(0), frameState);
        frameState.pop(JavaKind.Object);
        frameState.push(JavaKind.Object, exception);
        FixedNode nextDispatch = createTarget(nextBlock, frameState);
        piNodeAnchor.setNext(catchSuccessor);
        IfNode ifNode = append(new IfNode(graph.unique(createInstanceOf(checkedCatchType, exception)), piNodeAnchor, nextDispatch, 0.5));
        assert ifNode.trueSuccessor() == piNodeAnchor;
        piNode.setGuard(ifNode.trueSuccessor());
    } else {
        handleUnresolvedExceptionType(catchType);
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) PiNode(org.graalvm.compiler.nodes.PiNode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 39 with JavaType

use of jdk.vm.ci.meta.JavaType in project graal by oracle.

the class FrameStateBuilder method initializeForMethodStart.

public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) {
    int javaIndex = 0;
    int index = 0;
    ResolvedJavaMethod method = getMethod();
    ResolvedJavaType originalType = method.getDeclaringClass();
    if (!method.isStatic()) {
        // add the receiver
        FloatingNode receiver = null;
        StampPair receiverStamp = null;
        if (plugins != null) {
            receiverStamp = plugins.getOverridingStamp(tool, originalType, true);
        }
        if (receiverStamp == null) {
            receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true);
        }
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                receiver = plugin.interceptParameter(tool, index, receiverStamp);
                if (receiver != null) {
                    break;
                }
            }
        }
        if (receiver == null) {
            receiver = new ParameterNode(javaIndex, receiverStamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(receiver);
        javaIndex = 1;
        index = 1;
    }
    Signature sig = method.getSignature();
    int max = sig.getParameterCount(false);
    ResolvedJavaType accessingClass = originalType;
    for (int i = 0; i < max; i++) {
        JavaType type = sig.getParameterType(i, accessingClass);
        if (eagerResolve) {
            type = type.resolve(accessingClass);
        }
        JavaKind kind = type.getJavaKind();
        StampPair stamp = null;
        if (plugins != null) {
            stamp = plugins.getOverridingStamp(tool, type, false);
        }
        if (stamp == null) {
            stamp = StampFactory.forDeclaredType(assumptions, type, false);
        }
        FloatingNode param = null;
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                param = plugin.interceptParameter(tool, index, stamp);
                if (param != null) {
                    break;
                }
            }
        }
        if (param == null) {
            param = new ParameterNode(index, stamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(param);
        javaIndex++;
        if (kind.needsTwoSlots()) {
            locals[javaIndex] = TWO_SLOT_MARKER;
            javaIndex++;
        }
        index++;
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 40 with JavaType

use of jdk.vm.ci.meta.JavaType in project graal by oracle.

the class SubstrateGraphKit method loadArguments.

public List<ValueNode> loadArguments(JavaType[] paramTypes) {
    List<ValueNode> arguments = new ArrayList<>();
    int numOfParams = paramTypes.length;
    int javaIndex = 0;
    for (int i = 0; i < numOfParams; i++) {
        JavaType type = paramTypes[i];
        JavaKind kind = type.getJavaKind();
        assert frameState.loadLocal(javaIndex, kind) != null;
        arguments.add(frameState.loadLocal(javaIndex, kind));
        javaIndex += kind.getSlotCount();
    }
    return arguments;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ValueNode(org.graalvm.compiler.nodes.ValueNode) ArrayList(java.util.ArrayList) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaType (jdk.vm.ci.meta.JavaType)45 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)35 ValueNode (org.graalvm.compiler.nodes.ValueNode)22 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)15 JavaKind (jdk.vm.ci.meta.JavaKind)14 Signature (jdk.vm.ci.meta.Signature)11 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)8 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)7 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)6 ArrayList (java.util.ArrayList)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)6 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)5 StampPair (org.graalvm.compiler.core.common.type.StampPair)5 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)4 ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)4 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)4 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)4