Skip to content

Commit 5e652cd

Browse files
committed
Add details about app resources to build output.
1 parent 340293c commit 5e652cd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ GraalVM Native Image: Generating 'helloworld' (executable)...
2929
[6/7] Compiling methods... [**] (3.7s @ 2.38GB)
3030
[7/7] Creating image... (2.1s @ 1.04GB)
3131
3.69MB (27.19%) for code area: 6,955 compilation units
32-
5.86MB (43.18%) for image heap: 80,528 objects
32+
5.86MB (43.18%) for image heap: 80,528 objects and 5 resources
3333
3.05MB (22.46%) for debug info generated in 1.0s
3434
997.25KB ( 7.18%) for other data
3535
13.57MB in total
@@ -133,12 +133,15 @@ The code area contains machine code produced by the Graal compiler for all reach
133133
Therefore, reducing the number of [reachable methods](#glossary-reachability) also reduces the size of the code area.
134134
135135
#### <a name="glossary-image-heap"></a>Image Heap
136-
The image heap contains reachable objects such as static application data, metadata, and `byte[]` for different purposes.
136+
The image heap contains reachable objects such as static application data, metadata, and `byte[]` for different purposes (see below).
137137
138138
##### <a name="glossary-general-heap-data"></a>General Heap Data Stored in `byte[]`
139139
The total size of all `byte[]` objects that are neither used for `java.lang.String`, nor [code metadata](#glossary-code-metadata), nor [reflection metadata](#glossary-reflection-metadata), nor [graph encodings](#glossary-graph-encodings).
140140
Therefore, this can also include `byte[]` objects from application code.
141141
142+
##### <a name="glossary-embedded-resources"></a>Embedded Resources Stored in `byte[]`
143+
The total size of all `byte[]` objects used for storing resources (e.g., files accessed via `Class.getResource()`) within the native image. The number of resources is shown in the [Image Heap](#glossary-image-heap) section.
144+
142145
##### <a name="glossary-code-metadata"></a>Code Metadata Stored in `byte[]`
143146
The total size of all `byte[]` objects used for metadata for the [code area](#glossary-code-area).
144147
Therefore, reducing the number of [reachable methods](#glossary-reachability) also reduces the size of this metadata.

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
import com.oracle.svm.core.annotate.AutomaticFeature;
6969
import com.oracle.svm.core.code.CodeInfoTable;
7070
import com.oracle.svm.core.heap.Heap;
71+
import com.oracle.svm.core.jdk.Resources;
72+
import com.oracle.svm.core.jdk.resources.ResourceStorageEntry;
7173
import com.oracle.svm.core.option.HostedOptionValues;
7274
import com.oracle.svm.core.reflect.ReflectionMetadataDecoder;
7375
import com.oracle.svm.core.util.VMError;
@@ -389,8 +391,9 @@ public void printCreationEnd(int imageSize, int numHeapObjects, long imageHeapSi
389391
String format = "%9s (%5.2f%%) for ";
390392
l().a(format, Utils.bytesToHuman(codeCacheSize), codeCacheSize / (double) imageSize * 100)
391393
.doclink("code area", "#glossary-code-area").a(":%,9d compilation units", numCompilations).println();
394+
int numResources = Resources.singleton().resources().size();
392395
l().a(format, Utils.bytesToHuman(imageHeapSize), imageHeapSize / (double) imageSize * 100)
393-
.doclink("image heap", "#glossary-image-heap").a(": %,8d objects", numHeapObjects).println();
396+
.doclink("image heap", "#glossary-image-heap").a(":%,8d objects and %,d resources", numHeapObjects, numResources).println();
394397
if (debugInfoSize > 0) {
395398
DirectPrinter l = l().a(format, Utils.bytesToHuman(debugInfoSize), debugInfoSize / (double) imageSize * 100)
396399
.doclink("debug info", "#glossary-debug-info");
@@ -502,6 +505,16 @@ private Map<String, Long> calculateHeapBreakdown(Collection<ObjectInfo> heapObje
502505
classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("reflection metadata", "#glossary-reflection-metadata"), metadataByteLength);
503506
remainingBytes -= metadataByteLength;
504507
}
508+
long resourcesByteLength = 0;
509+
for (ResourceStorageEntry resourceList : Resources.singleton().resources().getValues()) {
510+
for (byte[] resource : resourceList.getData()) {
511+
resourcesByteLength += resource.length;
512+
}
513+
}
514+
if (resourcesByteLength > 0) {
515+
classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("embedded resources", "#glossary-embedded-resources"), resourcesByteLength);
516+
remainingBytes -= resourcesByteLength;
517+
}
505518
if (graphEncodingByteLength > 0) {
506519
classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linkStrategy.asDocLink("graph encodings", "#glossary-graph-encodings"), graphEncodingByteLength);
507520
remainingBytes -= graphEncodingByteLength;

0 commit comments

Comments
 (0)