Search in sources :

Example 6 with CFunctionPointer

use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.

the class NativeBootImage method markFunctionRelocationSite.

private static void markFunctionRelocationSite(final ProgbitsSectionImpl sectionImpl, final int offset, final RelocatableBuffer.Info info) {
    assert info.getTargetObject() instanceof CFunctionPointer : "Wrong type for FunctionPointer relocation: " + info.getTargetObject().toString();
    final int functionPointerRelocationSize = 8;
    assert info.getRelocationSize() == functionPointerRelocationSize : "Function relocation: " + info.getRelocationSize() + " should be " + functionPointerRelocationSize + " bytes.";
    // References to functions are via relocations to the symbol for the function.
    HostedMethod method = ((MethodPointer) info.getTargetObject()).getMethod();
    // A reference to a method. Mark the relocation site using the symbol name.
    sectionImpl.markRelocationSite(offset, functionPointerRelocationSize, RelocationKind.DIRECT, localSymbolNameForMethod(method), false, 0L);
}
Also used : MethodPointer(com.oracle.svm.hosted.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer)

Example 7 with CFunctionPointer

use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.

the class RelocatableBuffer method targetObjectClassification.

protected static String targetObjectClassification(final Object targetObject) {
    final StringBuilder result = new StringBuilder();
    if (targetObject == null) {
        result.append("null");
    } else {
        if (targetObject instanceof CFunctionPointer) {
            result.append("pointer to function");
            if (targetObject instanceof MethodPointer) {
                final MethodPointer mp = (MethodPointer) targetObject;
                final HostedMethod hm = mp.getMethod();
                result.append("  name: ");
                result.append(hm.getName());
            }
        } else {
            result.append("pointer to data");
        }
    }
    return result.toString();
}
Also used : MethodPointer(com.oracle.svm.hosted.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer)

Example 8 with CFunctionPointer

use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.

the class UniverseBuilder method buildHubs.

private void buildHubs() {
    ReferenceMapEncoder referenceMapEncoder = new ReferenceMapEncoder();
    Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
    for (HostedType type : hUniverse.orderedTypes) {
        ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
        referenceMaps.put(type, referenceMap);
        referenceMapEncoder.add(referenceMap);
    }
    ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll(null));
    ObjectLayout ol = ConfigurationValues.getObjectLayout();
    for (HostedType type : hUniverse.orderedTypes) {
        int layoutHelper;
        int monitorOffset = 0;
        int hashCodeOffset = 0;
        if (type.isInstanceClass()) {
            HostedInstanceClass instanceClass = (HostedInstanceClass) type;
            if (instanceClass.isAbstract()) {
                layoutHelper = LayoutEncoding.forAbstract();
            } else if (HybridLayout.isHybrid(type)) {
                HybridLayout<?> hybridLayout = new HybridLayout<>(instanceClass, ol);
                JavaKind kind = hybridLayout.getArrayElementKind();
                layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(kind), ol.getAlignment());
            } else {
                layoutHelper = LayoutEncoding.forInstance(ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
            }
            monitorOffset = instanceClass.getMonitorFieldOffset();
            hashCodeOffset = instanceClass.getHashCodeFieldOffset();
        } else if (type.isArray()) {
            JavaKind kind = type.getComponentType().getStorageKind();
            layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, ol.getArrayBaseOffset(kind), ol.getArrayIndexShift(kind), ol.getAlignment());
            hashCodeOffset = ol.getArrayHashCodeOffset();
        } else if (type.isInterface()) {
            layoutHelper = LayoutEncoding.forInterface();
        } else if (type.isPrimitive()) {
            layoutHelper = LayoutEncoding.forPrimitive();
        } else {
            throw shouldNotReachHere();
        }
        /*
             * The vtable entry values are available only after the code cache layout is fixed, so
             * leave them 0.
             */
        CFunctionPointer[] vtable = new CFunctionPointer[type.vtable.length];
        for (int idx = 0; idx < type.vtable.length; idx++) {
            /*
                 * We install a CodePointer in the vtable; when generating relocation info, we will
                 * know these point into .text
                 */
            vtable[idx] = MethodPointer.factory(type.vtable[idx]);
        }
        // pointer maps in Dynamic Hub
        ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
        assert referenceMap != null;
        long referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
        DynamicHub hub = type.getHub();
        hub.setData(layoutHelper, type.getTypeID(), monitorOffset, hashCodeOffset, type.getAssignableFromMatches(), type.instanceOfBits, vtable, referenceMapIndex, type.isInstantiated());
    }
}
Also used : HashMap(java.util.HashMap) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub) DynamicHubSupport(com.oracle.svm.core.hub.DynamicHubSupport) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

CFunctionPointer (org.graalvm.nativeimage.c.function.CFunctionPointer)8 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)5 MethodPointer (com.oracle.svm.hosted.meta.MethodPointer)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 StructFieldInfo (com.oracle.svm.hosted.c.info.StructFieldInfo)2 HostedType (com.oracle.svm.hosted.meta.HostedType)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)1 ReferenceMapEncoder (com.oracle.svm.core.heap.ReferenceMapEncoder)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 DynamicHubSupport (com.oracle.svm.core.hub.DynamicHubSupport)1 BeforeCompilationAccessImpl (com.oracle.svm.hosted.FeatureImpl.BeforeCompilationAccessImpl)1 HybridLayout (com.oracle.svm.hosted.config.HybridLayout)1 HostedMetaAccess (com.oracle.svm.hosted.meta.HostedMetaAccess)1 JNINativeLinkage (com.oracle.svm.jni.access.JNINativeLinkage)1 CallVariant (com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant)1 JNIInvokeInterface (com.oracle.svm.jni.nativeapi.JNIInvokeInterface)1