Search in sources :

Example 1 with ObjectInfo

use of com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo in project graal by oracle.

the class MethodPointerInvalidHandlerFeature method markRelocationSitesFromBuffer.

private void markRelocationSitesFromBuffer(RelocatableBuffer buffer, ProgbitsSectionImpl sectionImpl) {
    for (Map.Entry<Integer, RelocatableBuffer.Info> entry : buffer.getSortedRelocations()) {
        final int offset = entry.getKey();
        final RelocatableBuffer.Info info = entry.getValue();
        assert ConfigurationValues.getTarget().arch instanceof AArch64 || checkEmbeddedOffset(sectionImpl, offset, info);
        // Figure out what kind of relocation site it is.
        if (info.getTargetObject() instanceof CFunctionPointer) {
            // References to functions are via relocations to the symbol for the function.
            markFunctionRelocationSite(sectionImpl, offset, info);
        } else {
            // A data relocation.
            if (sectionImpl.getElement() == textSection) {
                // A wrinkle on relocations *from* the text section: they are *always* to
                // constants (in the "constant partition" of the roDataSection).
                markDataRelocationSiteFromText(buffer, sectionImpl, offset, info);
            } else {
                // Relocations from other sections go to the section containing the target.
                // Pass along the information about the target.
                final Object targetObject = info.getTargetObject();
                final ObjectInfo targetObjectInfo = heap.getObjectInfo(targetObject);
                markDataRelocationSite(sectionImpl, offset, info, targetObjectInfo);
            }
        }
    }
}
Also used : AArch64(jdk.vm.ci.aarch64.AArch64) Info(com.oracle.svm.hosted.image.RelocatableBuffer.Info) Info(com.oracle.svm.hosted.image.RelocatableBuffer.Info) ImageHeapLayoutInfo(com.oracle.svm.core.image.ImageHeapLayoutInfo) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LayoutDecisionMap(com.oracle.objectfile.LayoutDecisionMap) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)

Example 2 with ObjectInfo

use of com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo in project graal by oracle.

the class ProgressReporter method calculateHeapBreakdown.

private Map<String, Long> calculateHeapBreakdown(Collection<ObjectInfo> heapObjects) {
    Map<String, Long> classNameToSize = new HashMap<>();
    long stringByteLength = 0;
    for (ObjectInfo o : heapObjects) {
        classNameToSize.merge(o.getClazz().toJavaName(true), o.getSize(), Long::sum);
        Object javaObject = o.getObject();
        if (reportStringBytes && javaObject instanceof String) {
            stringByteLength += Utils.getInternalByteArrayLength((String) javaObject);
        }
    }
    Long byteArraySize = classNameToSize.remove("byte[]");
    if (byteArraySize != null) {
        long remainingBytes = byteArraySize;
        if (stringByteLength > 0) {
            classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + "java.lang.String", stringByteLength);
            remainingBytes -= stringByteLength;
        }
        long codeInfoSize = CodeInfoTable.getImageCodeCache().getTotalByteArraySize();
        if (codeInfoSize > 0) {
            classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("code metadata", "#glossary-code-metadata"), codeInfoSize);
            remainingBytes -= codeInfoSize;
        }
        long metadataByteLength = ImageSingletons.lookup(MethodMetadataDecoder.class).getMetadataByteLength();
        if (metadataByteLength > 0) {
            classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("method metadata", "#glossary-method-metadata"), metadataByteLength);
            remainingBytes -= metadataByteLength;
        }
        if (graphEncodingByteLength > 0) {
            classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("graph encodings", "#glossary-graph-encodings"), graphEncodingByteLength);
            remainingBytes -= graphEncodingByteLength;
        }
        assert remainingBytes >= 0;
        classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("general heap data", "#glossary-general-heap-data"), remainingBytes);
    }
    return classNameToSize;
}
Also used : HashMap(java.util.HashMap) MethodMetadataDecoder(com.oracle.svm.core.reflect.MethodMetadataDecoder) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)

Example 3 with ObjectInfo

use of com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo in project graal by oracle.

the class NativeImageHeapWriter method writeStaticFields.

private void writeStaticFields(RelocatableBuffer buffer) {
    /*
         * Write the values of static fields. The arrays for primitive and object fields are empty
         * and just placeholders. This ensures we get the latest version, since there can be
         * Features registered that change the value of static fields late in the native image
         * generation process.
         */
    ObjectInfo primitiveFields = heap.getObjectInfo(StaticFieldsSupport.getStaticPrimitiveFields());
    ObjectInfo objectFields = heap.getObjectInfo(StaticFieldsSupport.getStaticObjectFields());
    for (HostedField field : heap.getUniverse().getFields()) {
        if (Modifier.isStatic(field.getModifiers()) && field.hasLocation() && field.isRead()) {
            assert field.isWritten() || MaterializedConstantFields.singleton().contains(field.wrapped);
            ObjectInfo fields = (field.getStorageKind() == JavaKind.Object) ? objectFields : primitiveFields;
            writeField(buffer, fields, field, null, null);
        }
    }
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)

Example 4 with ObjectInfo

use of com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo in project graal by oracle.

the class NativeImageHeapWriter method writeObjectHeader.

private void writeObjectHeader(RelocatableBuffer buffer, int index, ObjectInfo obj) {
    mustBeReferenceAligned(index);
    DynamicHub hub = obj.getClazz().getHub();
    assert hub != null : "Null DynamicHub found during native image generation.";
    ObjectInfo hubInfo = heap.getObjectInfo(hub);
    assert hubInfo != null : "Unknown object " + hub.toString() + " found. Static field or an object referenced from a static field changed during native image generation?";
    ObjectHeader objectHeader = Heap.getHeap().getObjectHeader();
    if (NativeImageHeap.useHeapBase()) {
        long targetOffset = hubInfo.getAddress();
        long headerBits = objectHeader.encodeAsImageHeapObjectHeader(obj, targetOffset);
        writeReferenceValue(buffer, index, headerBits);
    } else {
        // The address of the DynamicHub target will be added by the link editor.
        long headerBits = objectHeader.encodeAsImageHeapObjectHeader(obj, 0L);
        addDirectRelocationWithAddend(buffer, index, hub, headerBits);
    }
}
Also used : ObjectHeader(com.oracle.svm.core.heap.ObjectHeader) DynamicHub(com.oracle.svm.core.hub.DynamicHub) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)

Example 5 with ObjectInfo

use of com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo in project graal by oracle.

the class NativeImageHeapWriter method writeHeap.

/**
 * Write the model of the native image heap to the RelocatableBuffers that represent the native
 * image.
 */
@SuppressWarnings("try")
public long writeHeap(DebugContext debug, RelocatableBuffer buffer) {
    try (Indent perHeapIndent = debug.logAndIndent("NativeImageHeap.writeHeap:")) {
        for (ObjectInfo info : heap.getObjects()) {
            assert !heap.isBlacklisted(info.getObject());
            writeObject(info, buffer);
        }
        // Only static fields that are writable get written to the native image heap,
        // the read-only static fields have been inlined into the code.
        writeStaticFields(buffer);
        heap.getLayouter().writeMetadata(buffer.getByteBuffer(), 0);
    }
    return sectionOffsetOfARelocatablePointer;
}
Also used : Indent(org.graalvm.compiler.debug.Indent) ObjectInfo(com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)

Aggregations

ObjectInfo (com.oracle.svm.hosted.image.NativeImageHeap.ObjectInfo)9 HashMap (java.util.HashMap)4 HostedField (com.oracle.svm.hosted.meta.HostedField)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 LayoutDecisionMap (com.oracle.objectfile.LayoutDecisionMap)1 CGlobalDataInfo (com.oracle.svm.core.graal.code.CGlobalDataInfo)1 ObjectHeader (com.oracle.svm.core.heap.ObjectHeader)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 ImageHeapLayoutInfo (com.oracle.svm.core.image.ImageHeapLayoutInfo)1 MethodMetadataDecoder (com.oracle.svm.core.reflect.MethodMetadataDecoder)1 HostedImageHeapConstantPatch (com.oracle.svm.hosted.code.HostedImageHeapConstantPatch)1 HostedPatcher (com.oracle.svm.hosted.code.HostedPatcher)1 Info (com.oracle.svm.hosted.image.RelocatableBuffer.Info)1 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)1 Field (java.lang.reflect.Field)1 ByteBuffer (java.nio.ByteBuffer)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AArch64 (jdk.vm.ci.aarch64.AArch64)1