Search in sources :

Example 41 with JavaKind

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

the class JNIJavaCallWrapperMethod method createInvoke.

private static ValueNode createInvoke(JNIGraphKit kit, ResolvedJavaMethod invokeMethod, InvokeKind kind, FrameStateBuilder state, int bci, ValueNode... args) {
    int exceptionEdgeBci = kit.bci();
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(invokeMethod, kind, state, bci, exceptionEdgeBci, args);
    kit.exceptionPart();
    ExceptionObjectNode exceptionObject = kit.exceptionObject();
    kit.retainPendingException(exceptionObject);
    ValueNode exceptionValue = null;
    if (invoke.getStackKind() != JavaKind.Void) {
        exceptionValue = kit.unique(ConstantNode.defaultForKind(invoke.getStackKind()));
    }
    AbstractMergeNode merge = kit.endInvokeWithException();
    ValueNode returnValue = null;
    JavaKind returnKind = invokeMethod.getSignature().getReturnKind();
    if (invoke.getStackKind() != JavaKind.Void) {
        ValueNode[] inputs = { invoke, exceptionValue };
        returnValue = kit.getGraph().addWithoutUnique(new ValuePhiNode(invoke.stamp(NodeView.DEFAULT), merge, inputs));
        state.push(returnKind, returnValue);
    }
    merge.setStateAfter(state.create(bci, merge));
    if (invoke.getStackKind() != JavaKind.Void) {
        state.pop(returnKind);
    }
    return returnValue;
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 42 with JavaKind

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

the class CInterfaceEnumTool method invokeEnumLookup.

private InvokeNode invokeEnumLookup(GraphBuilderTool b, CallTargetFactory callTargetFactory, FrameStateBuilder frameState, int bci, EnumInfo enumInfo, JavaKind parameterKind, ValueNode arg) {
    ValueNode[] args = new ValueNode[2];
    args[0] = ConstantNode.forConstant(snippetReflection.forObject(enumInfo.getRuntimeData()), b.getMetaAccess(), b.getGraph());
    assert !Modifier.isStatic(convertCToJavaMethod.getModifiers()) && convertCToJavaMethod.getSignature().getParameterCount(false) == 1;
    JavaKind expectedKind = convertCToJavaMethod.getSignature().getParameterType(0, null).getJavaKind();
    args[1] = CInterfaceInvocationPlugin.adaptPrimitiveType(b.getGraph(), arg, parameterKind, expectedKind, false);
    ResolvedJavaType convertReturnType = (ResolvedJavaType) convertCToJavaMethod.getSignature().getReturnType(null);
    StampPair returnStamp = StampFactory.forDeclaredType(null, convertReturnType, false);
    MethodCallTargetNode callTargetNode = b.append(callTargetFactory.createMethodCallTarget(InvokeKind.Virtual, convertCToJavaMethod, args, returnStamp, bci));
    Stamp invokeStamp = StampFactory.object(TypeReference.createWithoutAssumptions(convertReturnType));
    InvokeNode invoke = b.append(new InvokeNode(callTargetNode, bci, invokeStamp));
    frameState.push(convertReturnType.getJavaKind(), invoke);
    FrameState stateWithInvoke = frameState.create(bci, invoke);
    frameState.pop(convertReturnType.getJavaKind());
    invoke.setStateAfter(stateWithInvoke);
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 43 with JavaKind

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

the class CInterfaceEnumTool method replaceEnumLookupInvoke.

boolean replaceEnumLookupInvoke(BytecodeParser p, EnumInfo enumInfo, ResolvedJavaMethod method, ValueNode[] args) {
    assert Modifier.isStatic(method.getModifiers()) && method.getSignature().getParameterCount(false) == 1;
    assert args.length == 1;
    JavaKind methodParameterKind = method.getSignature().getParameterType(0, null).getJavaKind();
    InvokeNode invokeNode = invokeEnumLookup(p, CallTargetFactory.from(p), p.getFrameStateBuilder(), p.bci(), enumInfo, methodParameterKind, args[0]);
    Stamp returnStamp = p.getInvokeReturnStamp(null).getTrustedStamp();
    assert returnStamp.getStackKind() == JavaKind.Object && invokeNode.stamp(NodeView.DEFAULT).getStackKind() == JavaKind.Object;
    assert StampTool.typeOrNull(invokeNode.stamp(NodeView.DEFAULT)).isAssignableFrom(StampTool.typeOrNull(returnStamp));
    ValueNode adapted = p.getGraph().unique(new PiNode(invokeNode, returnStamp));
    p.push(CInterfaceInvocationPlugin.pushKind(method), adapted);
    return true;
}
Also used : ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) PiNode(org.graalvm.compiler.nodes.PiNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 44 with JavaKind

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

the class CInterfaceInvocationPlugin method replaceAccessor.

private boolean replaceAccessor(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo, int displacement) {
    StructuredGraph graph = b.getGraph();
    SizableInfo sizableInfo = (SizableInfo) accessorInfo.getParent();
    int elementSize = sizableInfo.getSizeInfo().getProperty();
    boolean isUnsigned = sizableInfo.isUnsigned();
    assert args.length == accessorInfo.parameterCount(true);
    ValueNode base = args[accessorInfo.baseParameterNumber(true)];
    switch(accessorInfo.getAccessorKind()) {
        case ADDRESS:
            {
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                b.addPush(pushKind(method), address);
                return true;
            }
        case GETTER:
            {
                JavaKind resultKind = wordTypes.asKind(b.getInvokeReturnType());
                JavaKind readKind = kindFromSize(elementSize, resultKind);
                if (readKind == JavaKind.Object) {
                    assert resultKind == JavaKind.Object;
                } else if (readKind.getBitCount() > resultKind.getBitCount() && !readKind.isNumericFloat() && resultKind != JavaKind.Boolean) {
                    readKind = resultKind;
                }
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
                Stamp stamp;
                if (readKind == JavaKind.Object) {
                    stamp = b.getInvokeReturnStamp(null).getTrustedStamp();
                } else if (readKind == JavaKind.Float || readKind == JavaKind.Double) {
                    stamp = StampFactory.forKind(readKind);
                } else {
                    stamp = StampFactory.forInteger(readKind.getBitCount());
                }
                ValueNode read = readOp(b, address, locationIdentity, stamp, accessorInfo);
                ValueNode adapted = adaptPrimitiveType(graph, read, readKind, resultKind == JavaKind.Boolean ? resultKind : resultKind.getStackKind(), isUnsigned);
                b.push(pushKind(method), adapted);
                return true;
            }
        case SETTER:
            {
                ValueNode value = args[accessorInfo.valueParameterNumber(true)];
                JavaKind valueKind = value.getStackKind();
                JavaKind writeKind = kindFromSize(elementSize, valueKind);
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
                ValueNode adaptedValue = adaptPrimitiveType(graph, value, valueKind, writeKind, isUnsigned);
                writeOp(b, address, locationIdentity, adaptedValue, accessorInfo);
                return true;
            }
        default:
            throw shouldNotReachHere();
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) ValueNode(org.graalvm.compiler.nodes.ValueNode) LocationIdentity(org.graalvm.word.LocationIdentity) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 45 with JavaKind

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

the class CInterfaceInvocationPlugin method replaceOffsetOf.

private boolean replaceOffsetOf(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo, int displacement) {
    /*
         * A method annotated with @OffsetOf can be static, but does not need to be. If it is
         * non-static, we just ignore the receiver.
         */
    assert args.length == accessorInfo.parameterCount(!method.isStatic());
    JavaKind kind = wordTypes.asKind(b.getInvokeReturnType());
    b.addPush(pushKind(method), ConstantNode.forIntegerKind(kind, displacement, b.getGraph()));
    return true;
}
Also used : JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6