Skip to content

Commit 63665ad

Browse files
committed
phrase clearer that the total size shown is not the exact size of the image on disk
1 parent 1537469 commit 63665ad

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/reference-manual/native-image/BuildOutput.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Below is the example output when building a native executable of the `HelloWorld
2424
GraalVM Native Image: Generating 'helloworld' (executable)...
2525
================================================================================
2626
[1/8] Initializing... (2.8s @ 0.15GB)
27-
Java version: 20+34, vendor version: GraalVM CE 20-dev+34.1
27+
Java version: 25+13, vendor version: GraalVM CE 25-dev+13.1
2828
Graal compiler: optimization level: 2, target machine: x86-64-v3
2929
C compiler: gcc (linux, x86_64, 12.2.0)
3030
Garbage collector: Serial GC (max heap size: 80% of RAM)
@@ -49,7 +49,7 @@ GraalVM Native Image: Generating 'helloworld' (executable)...
4949
7.03MB (32.02%) for image heap: 93,301 objects and 5 resources
5050
8.96MB (40.83%) for debug info generated in 1.0s
5151
659.13kB ( 2.93%) for other data
52-
21.96MB in total
52+
21.96MB in total image size, 21.04MB in total file size
5353
--------------------------------------------------------------------------------
5454
Top 10 origins of code area: Top 10 object types in image heap:
5555
4.03MB java.base 1.14MB byte[] for code metadata
@@ -201,6 +201,10 @@ The progress indicator is printed periodically at an increasing interval.
201201
### <a name="stage-creating"></a>Creating Image
202202
In this stage, the native binary is created and written to disk.
203203
Debug info is also generated as part of this stage (if requested).
204+
This section breaks down the total image size as well as [code area](#glossary-code-area) and [image heap](#glossary-image-heap) (see below for more details).
205+
The total image size is calculated before linking by summing the sizes of the code area, image heap, debug information (if requested and embedded in the binary), and other data.
206+
The total file size is the actual size of the image on disk after linking.
207+
Typically, the file size is slightly smaller than the image size due to additional link time optimizations.
204208

205209
#### <a name="glossary-code-area"></a>Code Area
206210
The code area contains machine code produced by the Graal compiler for all reachable methods.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport j
734734
compileQueue.purge();
735735

736736
int numCompilations = codeCache.getOrderedCompilations().size();
737+
int imageDiskFileSize = -1;
737738

738739
try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.WRITE)) {
739740
loader.watchdog.recordActivity();
@@ -755,14 +756,21 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport j
755756

756757
AfterImageWriteAccessImpl afterConfig = new AfterImageWriteAccessImpl(featureHandler, loader, hUniverse, inv, tmpDir, image.getImageKind(), debug);
757758
featureHandler.forEachFeature(feature -> feature.afterImageWrite(afterConfig));
759+
try {
760+
// size changes during linking and afterConfig phase
761+
imageDiskFileSize = (int) inv.getOutputFile().toFile().length();
762+
} catch (Exception e) {
763+
imageDiskFileSize = -1; // we can't read a disk file size
764+
}
758765
}
759766
try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.ARCHIVE_LAYER)) {
760767
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
761768
ImageSingletonsSupportImpl.HostedManagement.persist();
762769
HostedImageLayerBuildingSupport.singleton().archiveLayer(imageName);
763770
}
764771
}
765-
reporter.printCreationEnd(image.getImageFileSize(), heap.getLayerObjectCount(), image.getImageHeapSize(), codeCache.getCodeAreaSize(), numCompilations, image.getDebugInfoSize());
772+
reporter.printCreationEnd(image.getImageFileSize(), heap.getLayerObjectCount(), image.getImageHeapSize(), codeCache.getCodeAreaSize(), numCompilations, image.getDebugInfoSize(),
773+
imageDiskFileSize);
766774
}
767775
}
768776

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void setDebugInfoTimer(Timer timer) {
584584
this.debugInfoTimer = timer;
585585
}
586586

587-
public void printCreationEnd(int imageFileSize, int heapObjectCount, long imageHeapSize, int codeAreaSize, int numCompilations, int debugInfoSize) {
587+
public void printCreationEnd(int imageFileSize, int heapObjectCount, long imageHeapSize, int codeAreaSize, int numCompilations, int debugInfoSize, int imageDiskFileSize) {
588588
recordJsonMetric(ImageDetailKey.IMAGE_HEAP_OBJECT_COUNT, heapObjectCount);
589589
Timer imageTimer = getTimer(TimerCollection.Registry.IMAGE);
590590
Timer writeTimer = getTimer(TimerCollection.Registry.WRITE);
@@ -620,7 +620,11 @@ public void printCreationEnd(int imageFileSize, int heapObjectCount, long imageH
620620
recordJsonMetric(ImageDetailKey.NUM_COMP_UNITS, numCompilations);
621621
l().a(format, ByteFormattingUtil.bytesToHuman(otherBytes), Utils.toPercentage(otherBytes, imageFileSize))
622622
.doclink("other data", "#glossary-other-data").println();
623-
l().a("%9s in total", ByteFormattingUtil.bytesToHuman(imageFileSize)).println();
623+
l().a("%9s in total image size", ByteFormattingUtil.bytesToHuman(imageFileSize));
624+
if (imageDiskFileSize >= 0) {
625+
l().a(", %s in total file size", ByteFormattingUtil.bytesToHuman(imageDiskFileSize));
626+
}
627+
l().println();
624628
printBreakdowns();
625629
ImageSingletons.lookup(ProgressReporterFeature.class).afterBreakdowns();
626630
printRecommendations();

0 commit comments

Comments
 (0)