Skip to content

Commit 599b125

Browse files
committed
[GR-70308] Fix Heap Metadata
PullRequest: graal/22317
2 parents 029d311 + d1f5ef2 commit 599b125

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public void build(String imageName, DebugContext debug) {
561561
// We print the heap statistics after the heap was successfully written because this
562562
// could modify objects that will be part of the image heap.
563563
printHeapStatistics(heap.getLayouter().getPartitions());
564-
heap.dumpMetadata();
564+
heap.dumpMetadata(heapLayout);
565565
}
566566
}
567567

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeap.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.Set;
4747
import java.util.function.Predicate;
4848

49+
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
4950
import org.graalvm.nativeimage.ImageSingletons;
5051
import org.graalvm.nativeimage.c.function.RelocatedPointer;
5152
import org.graalvm.word.UnsignedWord;
@@ -812,7 +813,7 @@ public ObjectInfo addLateToImageHeap(Object object, Object reason) {
812813
/**
813814
* Dumps metadata for every object in the image heap.
814815
*/
815-
public void dumpMetadata() {
816+
public void dumpMetadata(ImageHeapLayoutInfo heapLayout) {
816817
String metadataFileName = SubstrateOptions.ImageHeapMetadataDumpFileName.getValue();
817818
if (metadataFileName == null || metadataFileName.isEmpty()) {
818819
// Do not dump metadata if the file name isn't set
@@ -826,11 +827,13 @@ public void dumpMetadata() {
826827
throw VMError.shouldNotReachHere("Image heap metadata directory does not exist: " + metadataDir);
827828
}
828829

830+
long heapLayoutStartOffset = heapLayout.getStartOffset();
831+
829832
try (FileWriter metadataOut = new FileWriter(metadataFile);
830833
BufferedWriter metadataBw = new BufferedWriter(metadataOut)) {
831834
metadataBw.write("class-name,partition,offset-in-heap,size\n");
832835
for (ObjectInfo info : getObjects()) {
833-
String csvLine = info.getClazz().getName() + "," + info.getPartition().getName() + "," + info.getOffset() + "," + info.getSize() + System.lineSeparator();
836+
String csvLine = info.getClazz().getName() + "," + info.getPartition().getName() + "," + (info.getOffset() - heapLayoutStartOffset) + "," + info.getSize() + System.lineSeparator();
834837
metadataBw.write(csvLine);
835838
}
836839
} catch (IOException ex) {

0 commit comments

Comments
 (0)