Search in sources :

Example 1 with CInterfaceError

use of com.oracle.svm.hosted.c.CInterfaceError in project graal by oracle.

the class CInterfaceInvocationPlugin method makeLocationIdentity.

private static LocationIdentity makeLocationIdentity(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo) {
    LocationIdentity locationIdentity;
    if (accessorInfo.hasLocationIdentityParameter()) {
        ValueNode locationIdentityNode = args[accessorInfo.locationIdentityParameterNumber(true)];
        if (!locationIdentityNode.isConstant()) {
            throw UserError.abort(new CInterfaceError("locationIdentity is not a compile time constant for call to " + method.format("%H.%n(%p)") + " in " + b.getMethod().asStackTraceElement(b.bci()), method).getMessage());
        }
        locationIdentity = (LocationIdentity) SubstrateObjectConstant.asObject(locationIdentityNode.asConstant());
    } else if (accessorInfo.hasUniqueLocationIdentity()) {
        StructFieldInfo fieldInfo = (StructFieldInfo) accessorInfo.getParent();
        assert fieldInfo.getLocationIdentity() != null;
        locationIdentity = fieldInfo.getLocationIdentity();
    } else {
        locationIdentity = CInterfaceLocationIdentity.DEFAULT_LOCATION_IDENTITY;
    }
    return locationIdentity;
}
Also used : CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) LocationIdentity(org.graalvm.word.LocationIdentity) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity)

Example 2 with CInterfaceError

use of com.oracle.svm.hosted.c.CInterfaceError in project graal by oracle.

the class CInterfaceInvocationPlugin method replaceFunctionPointerInvoke.

private boolean replaceFunctionPointerInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, CallingConvention.Type callType) {
    if (!functionPointerType.isAssignableFrom(method.getDeclaringClass())) {
        throw UserError.abort(new CInterfaceError("function pointer invocation method " + method.format("%H.%n(%p)") + " must be in a type that extends " + CFunctionPointer.class.getSimpleName(), method).getMessage());
    }
    assert b.getInvokeKind() == InvokeKind.Interface;
    JavaType[] parameterTypes = method.getSignature().toParameterTypes(null);
    if (callType == SubstrateCallingConventionType.NativeCall) {
        Predicate<JavaType> isValid = t -> t.getJavaKind().isPrimitive() || wordTypes.isWord(t);
        UserError.guarantee(Stream.of(parameterTypes).allMatch(isValid) && isValid.test(method.getSignature().getReturnType(null)), "C function pointer invocation method must have only primitive types or word types for its parameters and return value: " + method.format("%H.%n(%p)"));
    /*
             * We currently do not support automatic conversions for @CEnum because it entails
             * introducing additional invokes without real BCIs in a BytecodeParser context, which
             * does not work too well.
             */
    }
    // We "discard" the receiver from the signature by pretending we are a static method
    assert args.length >= 1;
    ValueNode methodAddress = args[0];
    ValueNode[] argsWithoutReceiver = Arrays.copyOfRange(args, 1, args.length);
    assert argsWithoutReceiver.length == parameterTypes.length;
    Stamp returnStamp;
    if (wordTypes.isWord(b.getInvokeReturnType())) {
        returnStamp = wordTypes.getWordStamp((ResolvedJavaType) b.getInvokeReturnType());
    } else {
        returnStamp = b.getInvokeReturnStamp(null).getTrustedStamp();
    }
    CallTargetNode indirectCallTargetNode = b.add(new IndirectCallTargetNode(methodAddress, argsWithoutReceiver, StampPair.createSingle(returnStamp), parameterTypes, method, callType, InvokeKind.Static));
    if (callType == SubstrateCallingConventionType.JavaCall) {
        b.handleReplacedInvoke(indirectCallTargetNode, b.getInvokeReturnType().getJavaKind());
    } else if (callType == SubstrateCallingConventionType.NativeCall) {
        // Native code cannot throw exceptions, omit exception edge
        InvokeNode invokeNode = new InvokeNode(indirectCallTargetNode, b.bci());
        if (pushKind(method) != JavaKind.Void) {
            b.addPush(pushKind(method), invokeNode);
        } else {
            b.add(invokeNode);
        }
    } else {
        throw shouldNotReachHere("Unsupported type of call: " + callType);
    }
    return true;
}
Also used : Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) LocationIdentity(org.graalvm.word.LocationIdentity) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) WordTypes(org.graalvm.compiler.word.WordTypes) AccessorInfo(com.oracle.svm.hosted.c.info.AccessorInfo) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) AndNode(org.graalvm.compiler.nodes.calc.AndNode) InvokeJavaFunctionPointer(com.oracle.svm.core.annotate.InvokeJavaFunctionPointer) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) UserError(com.oracle.svm.core.util.UserError) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) Predicate(java.util.function.Predicate) OrNode(org.graalvm.compiler.nodes.calc.OrNode) FrameAccess(com.oracle.svm.core.amd64.FrameAccess) CInterfaceWriteNode(com.oracle.svm.core.graal.nodes.CInterfaceWriteNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) Stream(java.util.stream.Stream) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) StructInfo(com.oracle.svm.hosted.c.info.StructInfo) MulNode(org.graalvm.compiler.nodes.calc.MulNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) BytecodeParser(org.graalvm.compiler.java.BytecodeParser) ConstantInfo(com.oracle.svm.hosted.c.info.ConstantInfo) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) AddNode(org.graalvm.compiler.nodes.calc.AddNode) VMError.shouldNotReachHere(com.oracle.svm.core.util.VMError.shouldNotReachHere) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) PointerToInfo(com.oracle.svm.hosted.c.info.PointerToInfo) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) CInterfaceReadNode(com.oracle.svm.core.graal.nodes.CInterfaceReadNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) AccessorKind(com.oracle.svm.hosted.c.info.AccessorInfo.AccessorKind) StampPair(org.graalvm.compiler.core.common.type.StampPair) SubstrateCallingConventionType(com.oracle.svm.core.graal.code.amd64.SubstrateCallingConventionType) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CallingConvention(jdk.vm.ci.code.CallingConvention) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode)

Example 3 with CInterfaceError

use of com.oracle.svm.hosted.c.CInterfaceError in project graal by oracle.

the class RawStructureLayoutPlanner method visitRawStructureInfo.

@Override
protected void visitRawStructureInfo(RawStructureInfo info) {
    if (info.isPlanned()) {
        return;
    }
    ResolvedJavaType type = (ResolvedJavaType) info.getAnnotatedElement();
    for (ResolvedJavaType t : type.getInterfaces()) {
        if (!nativeLibs.isPointerBase(t)) {
            throw UserError.abort("Type " + type + " must not implement " + t);
        }
        if (t.equals(nativeLibs.getPointerBaseType())) {
            continue;
        }
        ElementInfo einfo = nativeLibs.findElementInfo(t);
        if (!(einfo instanceof RawStructureInfo)) {
            throw UserError.abort(new CInterfaceError("Illegal super type " + t + " found", type).getMessage());
        }
        RawStructureInfo rinfo = (RawStructureInfo) einfo;
        rinfo.accept(this);
        assert rinfo.isPlanned();
        if (info.getParentInfo() != null) {
            throw UserError.abort(new CInterfaceError("Only single inheritance of RawStructure types is supported", type).getMessage());
        }
        info.setParentInfo(rinfo);
    }
    for (ElementInfo child : new ArrayList<>(info.getChildren())) {
        if (child instanceof StructFieldInfo) {
            StructFieldInfo fieldInfo = (StructFieldInfo) child;
            StructFieldInfo parentFieldInfo = findParentFieldInfo(fieldInfo, info.getParentInfo());
            if (parentFieldInfo != null) {
                fieldInfo.mergeChildrenAndDelete(parentFieldInfo);
            } else {
                computeSize(fieldInfo);
            }
        }
    }
    planLayout(info);
}
Also used : CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) RawStructureInfo(com.oracle.svm.hosted.c.info.RawStructureInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) ArrayList(java.util.ArrayList) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

CInterfaceError (com.oracle.svm.hosted.c.CInterfaceError)3 StructFieldInfo (com.oracle.svm.hosted.c.info.StructFieldInfo)3 CInterfaceLocationIdentity (com.oracle.svm.core.c.struct.CInterfaceLocationIdentity)2 ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 FrameAccess (com.oracle.svm.core.amd64.FrameAccess)1 InvokeJavaFunctionPointer (com.oracle.svm.core.annotate.InvokeJavaFunctionPointer)1 SubstrateCallingConventionType (com.oracle.svm.core.graal.code.amd64.SubstrateCallingConventionType)1 CInterfaceReadNode (com.oracle.svm.core.graal.nodes.CInterfaceReadNode)1 CInterfaceWriteNode (com.oracle.svm.core.graal.nodes.CInterfaceWriteNode)1 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)1 UserError (com.oracle.svm.core.util.UserError)1 VMError.shouldNotReachHere (com.oracle.svm.core.util.VMError.shouldNotReachHere)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 AccessorInfo (com.oracle.svm.hosted.c.info.AccessorInfo)1 AccessorKind (com.oracle.svm.hosted.c.info.AccessorInfo.AccessorKind)1 ConstantInfo (com.oracle.svm.hosted.c.info.ConstantInfo)1 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)1 EnumLookupInfo (com.oracle.svm.hosted.c.info.EnumLookupInfo)1 EnumValueInfo (com.oracle.svm.hosted.c.info.EnumValueInfo)1