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);
}
}
}
}
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;
}
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);
}
}
}
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);
}
}
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;
}
Aggregations