Skip to content

Commit b418e19

Browse files
committed
[GR-33602] Improve and fix ProgressReporter (#3955).
PullRequest: graal/10428
2 parents 4b9898c + acd9085 commit b418e19

File tree

10 files changed

+321
-100
lines changed

10 files changed

+321
-100
lines changed

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

Lines changed: 149 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,169 @@ permalink: /reference-manual/native-image/BuildOutput/
66
---
77
# Native Image Build Output
88

9-
## Glossary
9+
This page provides documentation for the build output of GraalVM Native Image.
10+
11+
## HelloWorld Example Output
12+
```
13+
================================================================================
14+
GraalVM Native Image: Generating 'helloworld'...
15+
================================================================================
16+
[1/7] Initializing... (4.8s @ 0.21GB)
17+
Version info: 'GraalVM dev Java 11 CE'
18+
1 user-provided feature(s)
19+
- HelloWorld$MyFeature
20+
[2/7] Performing analysis... [*******] (11.1s @ 0.48GB)
21+
2,546 (83.20%) of 3,060 classes reachable
22+
3,187 (60.39%) of 5,277 fields reachable
23+
11,554 (72.39%) of 15,960 methods reachable
24+
27 classes, 0 fields, and 135 methods registered for reflection
25+
57 classes, 60 fields, and 51 methods registered for JNI access
26+
[3/7] Building universe... (0.7s @ 0.64GB)
27+
[4/7] Parsing methods... [*] (0.7s @ 0.86GB)
28+
[5/7] Inlining methods... [****] (1.5s @ 0.75GB)
29+
[6/7] Compiling methods... [***] (8.1s @ 2.37GB)
30+
[7/7] Creating image... (1.7s @ 2.68GB)
31+
10.27MB in total (35.5% code area, 57.0% image heap, and 7.5% other data)
32+
3.65MB for code area: 6,913 compilation units
33+
5.85MB for image heap: 1,530 classes and 80,316 objects
34+
790.29KB for other data
35+
--------------------------------------------------------------------------------
36+
Top 10 packages in code area: Top 10 object types in image heap:
37+
606.18KB java.util 1.64MB byte[] for general heap data
38+
282.69KB java.lang 713.25KB java.lang.String
39+
222.47KB java.util.regex 544.73KB java.lang.Class
40+
219.55KB java.text 449.33KB byte[] for java.lang.String
41+
193.17KB com.oracle.svm.jni 363.56KB java.util.HashMap$Node
42+
149.84KB java.util.concurrent 192.14KB java.util.HashMap$Node[]
43+
113.51KB java.math 139.14KB java.lang.String[]
44+
103.51KB com.oracle.svm.core.reflect 139.04KB char[]
45+
97.83KB sun.text.normalizer 130.59KB j.u.c.ConcurrentHashMap$Node
46+
88.63KB c.oracle.svm.core.genscavenge 103.92KB s.u.l.LocaleObjec~e$CacheEntry
47+
... 108 additional packages ... 719 additional object types
48+
(use GraalVM Dashboard to see all)
49+
--------------------------------------------------------------------------------
50+
1.0s spent in 15 GCs | Peak RSS: 3.00GB | CPU load: ~606.03%
51+
--------------------------------------------------------------------------------
52+
Produced artifacts:
53+
/Users/janedoe/helloworld/helloworld (executable)
54+
/Users/janedoe/helloworld/helloworld.build_artifacts.txt
55+
================================================================================
56+
Finished generating 'helloworld' in 30.1s.
57+
```
1058

11-
### <a name="glossary-user-provided-features">User-provided features
59+
## Build Stages
1260

13-
### <a name="glossary-reflection-classes">Classes registered for reflection
61+
### <a name="stage-initializing"></a>Initializing
62+
In this stage, the Native Image build process is set up and [`Features`][jdoc_feature] are initialized.
1463

15-
### <a name="glossary-reachability"/>Reachable classes and methods
64+
#### <a name="glossary-version-info"></a>Version Info
65+
The version info of the Native Image process.
66+
This string is also used for the `java.vm.version` property within the generated image.
67+
Please report this version info when you [file issues][new_issue].
1668

17-
### <a name="glossary-runtime-methods"/>Runtime compiled methods
69+
#### <a name="glossary-user-provided-features"></a>User-provided Features
70+
All [`Features`][jdoc_feature] that are provided by the user or implicitly registered for the user, for example, by a framework.
71+
GraalVM Native Image deploys a number of internal features, which are excluded from this list.
1872

19-
### <a name="glossary-code-area"/>Code Area
73+
### <a name="stage-analysis"></a>Performing Analysis
74+
In this stage, a [points-to analysis][oopsla19_initialize_once_start_fast] is performed.
75+
The progress indicator visualizes the number of analysis iterations.
76+
A large number of iterations can indicate problems in the analysis likely caused by misconfiguration or a misbehaving feature.
2077

21-
### <a name="glossary-image-heap"/>Image Heap
78+
#### <a name="glossary-reachability"></a>Reachable Classes, Fields, and Methods
79+
The number of classes, fields, and methods that are reachable versus the total number of classes and methods loaded as part of the build process.
80+
A significantly larger number of loaded classes that are not reachable can indicate a configuration problem.
81+
To reduce overhead, please ensure that the classpath only contains entries that are needed for building the application.
2282

23-
### <a name="glossary-peak-rss"/>Peak RSS
83+
#### <a name="glossary-reflection-registrations"></a>Reflection Registrations
84+
The number of classes, fields, and methods that are registered for reflection.
85+
Large numbers can cause significant reflection overheads, slow down the build process, and increase the size of the native image (see [method metadata](#glossary-method-metadata)).
2486

25-
### <a name="glossary-cpu-load"/>CPU load
87+
#### <a name="glossary-jni-access-registrations"></a>JNI Access Registrations
88+
The number of classes, fields, and methods that are registered for [JNI][doc_jni] access.
2689

90+
#### <a name="glossary-runtime-methods"></a>Runtime Compiled Methods
91+
The number of methods marked for runtime compilation.
92+
This number is only shown if runtime compilation is built into the image, for example, when building a [Truffle][truffle] language.
93+
Runtime compiled methods account for [graph encodings](#glossary-graph-encodings) in the image heap.
2794

28-
## Build Stages
95+
### <a name="stage-universe"></a>Building Universe
96+
In this stage, a universe with all classes, fields, and methods is built, which is then used to create the native image.
97+
98+
### <a name="stage-parsing"></a>Parsing Methods
99+
In this stage, the Graal compiler parses all reachable methods.
100+
The progress indicator is printed periodically at an increasing interval.
101+
102+
### <a name="stage-inlining"></a>Inlining Methods
103+
In this stage, trivial method inlining is performed.
104+
The progress indicator visualizes the number of inlining iterations.
105+
106+
### <a name="stage-compiling"></a>Compiling Methods
107+
In this stage, the Graal compiler compiles all reachable methods to machine code.
108+
The progress indicator is printed periodically at an increasing interval.
109+
110+
### <a name="stage-creating"></a>Creating Image
111+
In this stage, the native image is created and written to disk.
112+
Debug info is also generated as part of this stage (if requested).
113+
114+
#### <a name="glossary-code-area"></a>Code Area
115+
The code area contains machine code produced by the Graal compiler for all reachable methods.
116+
Therefore, reducing the number of reachable methods also reduces the size of the code area.
117+
118+
#### <a name="glossary-image-heap"></a>Image Heap
119+
The image heap contains reachable objects such as static data, classes initialized at run-time, and `byte[]` for different purposes.
120+
121+
##### <a name="glossary-general-heap-data"></a>General Heap Data Stored in `byte[]`
122+
The total size of all `byte[]` objects that are neither used for `java.lang.String`, nor [graph encodings](#glossary-graph-encodings), nor [method metadata](#glossary-method-metadata).
123+
This typically dominates
124+
125+
##### <a name="glossary-graph-encodings"></a>Graph Encodings Stored in `byte[]`
126+
The total size of all `byte[]` objects used for graph encodings.
127+
These encodings are a result of [runtime compiled methods](#glossary-runtime-methods).
128+
Therefore, reducing the number of such methods also reduces the size of corresponding graph encodings.
129+
130+
##### <a name="glossary-method-metadata"></a>Method Metadata Stored in `byte[]`
131+
The total size of all `byte[]` objects used for method metadata, a type of reflection metadata.
132+
To reduce the amount of method metadata, reduce the number of [classes registered for reflection](#glossary-reflection-classes).
133+
134+
#### <a name="glossary-other-data"></a>Other Data
135+
The amount of data in the image that is neither in the [code area](#glossary-code-area) nor in the [image heap](#glossary-image-heap).
136+
This data typically contains internal information for Native Image but it can also contain other information such as debug info.
137+
138+
### Resource Usage Statistics
29139

30-
### <a name="step-initializing"/>Initializing
140+
#### <a name="glossary-garbage-collection"></a>Garbage Collections
141+
The total number of garbage collections and total time spent in all garbage collectors.
142+
A large number of collections or time spent in collectors usually indicates that the system is under memory pressure.
143+
Increase the amount of available memory to reduce the time to build the image.
31144

32-
### <a name="step-analysis"/>Performing analysis
145+
#### <a name="glossary-peak-rss"></a>Peak RSS
146+
Peak [resident set size][rss_wiki] as reported by the operating system.
147+
This value indicates the maximum amount of memory consumed by the build process.
148+
If the [GC statistics](#glossary-garbage-collection) do not show any problems, the amount of available memory of the system can be reduced to a value closer to the peak RSS.
33149

34-
### <a name="step-universe"/>Building universe
150+
#### <a name="glossary-cpu-load"></a>CPU load
151+
The CPU time used by the process divided by the total time to build the image in percent.
152+
Increase the number of CPU threads to reduce the time to build the image.
35153

36-
### <a name="step-parsing"/>Parsing methods
154+
## Build Output Options
37155

38-
### <a name="step-inlining"/>Inlining methods
156+
Run `native-image --expert-options-all | grep "BuildOutput"` to see all build output options:
157+
158+
```
159+
-H:±BuildOutputBreakdowns Show code and heap breakdowns as part of the build output. Default: + (enabled).
160+
-H:±BuildOutputColorful Colorize build output. Default: + (enabled).
161+
-H:±BuildOutputGCWarnings Print GC warnings as part of build output. Default: + (enabled).
162+
-H:±BuildOutputLinks Show links in build output. Default: + (enabled).
163+
-H:±BuildOutputPrefix Prefix build output with '<pid>:<image name>'. Default: - (disabled).
164+
-H:±BuildOutputProgress Report progress in build output. Default: + (enabled).
165+
-H:±BuildOutputUseNewStyle Use new build output style. Default: + (enabled).
166+
```
39167

40-
### <a name="step-compiling"/>Compiling methods
41168

42-
### <a name="step-creation"/>Creating image
169+
[jdoc_feature]: https://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/hosted/Feature.html
170+
[doc_jni]: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/JNI.md
171+
[new_issue]: https://github.com/oracle/graal/issues/new
172+
[oopsla19_initialize_once_start_fast]: https://dl.acm.org/doi/10.1145/3360610
173+
[rss_wiki]: https://en.wikipedia.org/wiki/Resident_set_size
174+
[truffle]: https://github.com/oracle/graal/tree/master/truffle

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,7 @@ def get_build_args(self):
21812181
build_args = [
21822182
'--macro:' + GraalVmNativeProperties.macro_name(self.subject.native_image_config),
21832183
'-H:NumberOfThreads=' + str(self.parallelism),
2184+
'-H:+BuildOutputPrefix',
21842185
]
21852186
if self.subject.native_image_config.is_polyglot:
21862187
build_args += ["--macro:truffle", "--language:all"]

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeReflectionSupport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ public interface RuntimeReflectionSupport extends ReflectionRegistry {
5454
Set<?> getHidingMethods();
5555

5656
int getReflectionClassesCount();
57+
58+
int getReflectionMethodsCount();
59+
60+
int getReflectionFieldsCount();
5761
}

substratevm/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ This changelog summarizes major changes to GraalVM Native Image.
1212
* (GR-35152) Add -H:DisableURLProtocols to allow specifying URL protocols that must never be included in the image.
1313
* (GR-35085) Custom prologue/epilogue/handleException customizations of @CEntryPoint must be annotated with @Uninterruptible. The synthetic methods created for entry points are now implicitly annotated with @Uninterruptible too.
1414
* (GR-34935) More compiler optimization phases are run before static analysis: Conditional Elimination (to remove redundant conditions) and Escape Analysis.
15-
* (GR-33602) Enable new user-friendly build output mode. The old output can be restored with `-H:-BuildOutputUseNewStyle`. Run `native-image --expert-options-all | grep "BuildOutput` to see all options for the new output.
15+
* (GR-33602) Enable [new user-friendly build output mode](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md). The old output can be restored with `-H:-BuildOutputUseNewStyle`.

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/GraalFeature.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,11 @@ public static String buildSourceReference(FrameState startState) {
640640
return sourceReferenceBuilder.toString();
641641
}
642642

643+
@Override
644+
public void afterAnalysis(AfterAnalysisAccess access) {
645+
ProgressReporter.singleton().setNumRuntimeCompiledMethods(methods.size());
646+
}
647+
643648
@Override
644649
@SuppressWarnings("try")
645650
public void beforeCompilation(BeforeCompilationAccess c) {
@@ -649,8 +654,6 @@ public void beforeCompilation(BeforeCompilationAccess c) {
649654
printCallTree();
650655
}
651656

652-
ProgressReporter.singleton().printRuntimeCompileMethods(methods.size(), config.getMethods().size());
653-
654657
if (Options.PrintStaticTruffleBoundaries.getValue()) {
655658
printStaticTruffleBoundaries();
656659
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private int buildImage(ImageClassLoader classLoader) {
300300
ForkJoinPool compilationExecutor = null;
301301

302302
ProgressReporter reporter = new ProgressReporter(parsedHostedOptions);
303-
303+
boolean wasSuccessfulBuild = false;
304304
try (StopTimer ignored = totalTimer.start()) {
305305
Timer classlistTimer = new Timer("classlist", false);
306306
try (StopTimer ignored1 = classlistTimer.start()) {
@@ -423,6 +423,7 @@ private int buildImage(ImageClassLoader classLoader) {
423423
generator = new NativeImageGenerator(classLoader, optionParser, mainEntryPointData, reporter);
424424
generator.run(entryPoints, javaMainSupport, imageName, classlistTimer, imageKind, SubstitutionProcessor.IDENTITY,
425425
compilationExecutor, analysisExecutor, optionParser.getRuntimeOptionNames());
426+
wasSuccessfulBuild = true;
426427
} catch (InterruptImageBuilding e) {
427428
if (analysisExecutor != null) {
428429
analysisExecutor.shutdownNow();
@@ -472,7 +473,7 @@ private int buildImage(ImageClassLoader classLoader) {
472473
} finally {
473474
totalTimer.print();
474475
if (imageName != null && generator != null) {
475-
reporter.printEpilog(generator, imageName, totalTimer, parsedHostedOptions);
476+
reporter.printEpilog(imageName, generator, wasSuccessfulBuild, totalTimer, parsedHostedOptions);
476477
}
477478
NativeImageGenerator.clearSystemPropertiesForImage();
478479
ImageSingletonsSupportImpl.HostedManagement.clear();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ public long getSize() {
12781278
}
12791279

12801280
private boolean acceptObjectInfo(ObjectInfo objectInfo) {
1281-
/* This condiiton rejects filler partition objects. */
1281+
/* This condition rejects filler partition objects. */
12821282
return (objectInfo.getPartition().getStartOffset() > 0);
12831283
}
12841284

0 commit comments

Comments
 (0)