Search in sources :

Example 1 with StructFieldInfo

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

the class RawStructureLayoutPlanner method planLayout.

/**
 * Compute the offsets of each field.
 */
private void planLayout(RawStructureInfo info) {
    /* Inherit from the parent type. */
    int currentOffset = info.getParentInfo() != null ? info.getParentInfo().getSizeInfo().getProperty() : 0;
    List<StructFieldInfo> fields = new ArrayList<>();
    for (ElementInfo child : info.getChildren()) {
        if (child instanceof StructFieldInfo) {
            fields.add((StructFieldInfo) child);
        } else if (child instanceof StructBitfieldInfo) {
            throw UserError.abort("StructBitfield is currently not supported by RawStructures!");
        }
    }
    /*
         * Sort fields in field size descending order. Note that prior to this, the fields are
         * already sorted in alphabetical order.
         */
    fields.sort((f1, f2) -> f2.getSizeInfo().getProperty() - f1.getSizeInfo().getProperty());
    for (StructFieldInfo finfo : fields) {
        assert findParentFieldInfo(finfo, info.getParentInfo()) == null;
        int fieldSize = finfo.getSizeInfo().getProperty();
        currentOffset = alignOffset(currentOffset, fieldSize);
        assert currentOffset % fieldSize == 0;
        finfo.getOffsetInfo().setProperty(currentOffset);
        currentOffset += fieldSize;
    }
    info.getSizeInfo().setProperty(currentOffset);
    info.setPlanned();
}
Also used : ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) ArrayList(java.util.ArrayList) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo)

Example 2 with StructFieldInfo

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

the class JNIFunctionTablesFeature method buildInvokesInitializer.

private JNIStructFunctionsInitializer<JNIInvokeInterface> buildInvokesInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
    HostedType invokes = access.getMetaAccess().lookupJavaType(JNIInvocationInterface.class);
    HostedMethod[] methods = invokes.getDeclaredMethods();
    int index = 0;
    int[] offsets = new int[methods.length];
    CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(invokeInterfaceMetadata, method.getName());
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = getStubFunctionPointer(access, method);
        index++;
    }
    VMError.guarantee(index == offsets.length && index == pointers.length);
    return new JNIStructFunctionsInitializer<>(JNIInvokeInterface.class, offsets, pointers, unimplemented);
}
Also used : HostedType(com.oracle.svm.hosted.meta.HostedType) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 3 with StructFieldInfo

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

the class JNIFunctionTablesFeature method buildFunctionsInitializer.

private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
    Class<JNIFunctions> clazz = JNIFunctions.class;
    HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
    HostedMethod[] methods = functions.getDeclaredMethods();
    int index = 0;
    int count = methods.length + generatedMethods.length;
    // Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
    // NewObject: array, va_list, varargs
    count += (jniKinds.size() * 3 + 1) * 3;
    int[] offsets = new int[count];
    CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = getStubFunctionPointer(access, method);
        index++;
    }
    for (ResolvedJavaMethod accessor : generatedMethods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
        AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
        AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
        HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = MethodPointer.factory(hostedMethod);
        index++;
    }
    for (CallVariant variant : CallVariant.values()) {
        CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
        String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
        CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
        for (JavaKind kind : jniKinds) {
            String[] prefixes = { "Call", "CallStatic" };
            for (String prefix : prefixes) {
                StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
                offsets[index] = field.getOffsetInfo().getProperty();
                pointers[index] = trampoline;
                index++;
            }
            StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
            offsets[index] = field.getOffsetInfo().getProperty();
            pointers[index] = nonvirtualTrampoline;
            index++;
        }
        StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = trampoline;
        index++;
    }
    VMError.guarantee(index == offsets.length && index == pointers.length);
    return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
Also used : CallVariant(com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) HostedType(com.oracle.svm.hosted.meta.HostedType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 4 with StructFieldInfo

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

the class JNIJavaCallWrapperMethod method getJNIValueOffsetOf.

private StructFieldInfo getJNIValueOffsetOf(ResolvedJavaType jniValueType, JavaKind kind) {
    String name = String.valueOf(kind.isObject() ? 'l' : Character.toLowerCase(kind.getTypeChar()));
    StructInfo structInfo = (StructInfo) nativeLibs.findElementInfo(jniValueType);
    for (ElementInfo elementInfo : structInfo.getChildren()) {
        if (elementInfo instanceof StructFieldInfo) {
            StructFieldInfo fieldInfo = (StructFieldInfo) elementInfo;
            if (name.equals(fieldInfo.getName())) {
                return fieldInfo;
            }
        }
    }
    throw VMError.shouldNotReachHere();
}
Also used : StructInfo(com.oracle.svm.hosted.c.info.StructInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo)

Example 5 with StructFieldInfo

use of com.oracle.svm.hosted.c.info.StructFieldInfo 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)

Aggregations

StructFieldInfo (com.oracle.svm.hosted.c.info.StructFieldInfo)7 ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)3 ArrayList (java.util.ArrayList)3 CInterfaceError (com.oracle.svm.hosted.c.CInterfaceError)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 HostedType (com.oracle.svm.hosted.meta.HostedType)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 CFunctionPointer (org.graalvm.nativeimage.c.function.CFunctionPointer)2 LocationIdentity (org.graalvm.word.LocationIdentity)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 CInterfaceLocationIdentity (com.oracle.svm.core.c.struct.CInterfaceLocationIdentity)1 CInterfaceReadNode (com.oracle.svm.core.graal.nodes.CInterfaceReadNode)1 VaListNextArgNode (com.oracle.svm.core.graal.nodes.VaListNextArgNode)1 RawStructureInfo (com.oracle.svm.hosted.c.info.RawStructureInfo)1 StructBitfieldInfo (com.oracle.svm.hosted.c.info.StructBitfieldInfo)1 StructInfo (com.oracle.svm.hosted.c.info.StructInfo)1