You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/BuildConfiguration.md
+41-62Lines changed: 41 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -18,22 +18,17 @@ Native Image supports a wide range of options to configure a native image build
18
18
19
19
## Embedding a Configuration File
20
20
21
-
A recommended way to provide configuration is to embed a
22
-
**native-image.properties** file into a project JAR file. The Native Image builder
23
-
will automatically pick up all configuration options provided anywhere below the
24
-
resource location `META-INF/native-image/` and use it to construct
25
-
`native-image` command line arguments.
26
-
27
-
To avoid a situation when constituent parts of a project are built
28
-
with overlapping configurations, it is recommended to use "subdirectories" within
29
-
`META-INF/native-image`. That way a JAR file built from multiple maven projects
30
-
cannot suffer from overlapping `native-image` configurations. For example:
21
+
A recommended way to provide configuration is to embed a **native-image.properties** file into a project JAR file.
22
+
The Native Image builder will automatically pick up all configuration options provided anywhere below the resource location `META-INF/native-image/` and use it to construct `native-image` command line arguments.
23
+
24
+
To avoid a situation when constituent parts of a project are built with overlapping configurations, it is recommended to use "subdirectories" within `META-INF/native-image`.
25
+
That way a JAR file built from multiple maven projects cannot suffer from overlapping `native-image` configurations.
26
+
For example:
31
27
*_foo.jar_ has its configurations in `META-INF/native-image/foo_groupID/foo_artifactID`
32
28
*_bar.jar_ has its configurations in `META-INF/native-image/bar_groupID/bar_artifactID`
33
29
34
-
The JAR file that contains `foo` and `bar` will then contain both configurations
35
-
without conflicting with one another. Therefore the recommended layout for
36
-
storing native image configuration data in JAR files is the following:
30
+
The JAR file that contains `foo` and `bar` will then contain both configurations without conflicting with one another.
31
+
Therefore the recommended layout for storing native image configuration data in JAR files is the following:
37
32
```
38
33
META-INF/
39
34
└── native-image
@@ -42,12 +37,9 @@ META-INF/
42
37
└── native-image.properties
43
38
```
44
39
45
-
Note that the use of `${.}` in a _native-image.properties_ file expands to the
46
-
resource location that contains that exact configuration file. This can be
47
-
useful if the _native-image.properties_ file wants to refer to resources within
48
-
its "subfolder", for example, `-H:SubstitutionResources=${.}/substitutions.json`.
49
-
Always make sure to use the option variants that take resources, i.e., use
50
-
`-H:ResourceConfigurationResources` instead of `-H:ResourceConfigurationFiles`.
40
+
Note that the use of `${.}` in a _native-image.properties_ file expands to the resource location that contains that exact configuration file.
41
+
This can be useful if the _native-image.properties_ file wants to refer to resources within its "subfolder", for example, `-H:SubstitutionResources=${.}/substitutions.json`.
42
+
Always make sure to use the option variants that take resources, i.e., use `-H:ResourceConfigurationResources` instead of `-H:ResourceConfigurationFiles`.
51
43
Other options that are known to work in this context are:
52
44
*`-H:DynamicProxyConfigurationResources`
53
45
*`-H:JNIConfigurationResources`
@@ -56,16 +48,14 @@ Other options that are known to work in this context are:
56
48
*`-H:SubstitutionResources`
57
49
*`-H:SerializationConfigurationResources`
58
50
59
-
By having such a composable _native-image.properties_ file, building an image
60
-
does not require any additional arguments specified on command line. It is
61
-
sufficient to just run the following command:
51
+
By having such a composable _native-image.properties_ file, building an image does not require any additional arguments specified on command line.
52
+
It is sufficient to just run the following command:
To debug which configuration data gets applied for the image building, use `native-image --verbose`. This will show from where `native-image` picks up the
67
-
configurations to construct the final composite configuration command line
68
-
options for the native image builder.
57
+
To debug which configuration data gets applied for the image building, use `native-image --verbose`.
58
+
This will show from where `native-image` picks up the configurations to construct the final composite configuration command line options for the native image builder.
Use this property if your project requires custom `native-image` command line options to build correctly. For example, the `native-image-configure-examples/configure-at-runtime-example` has `Args = --initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access` in its `native-image.properties` file to ensure the class `com.fasterxml.jackson.annotation.JsonProperty$Access` gets initialized at image build time.
82
+
Use this property if your project requires custom `native-image` command line options to build correctly.
83
+
For example, the `native-image-configure-examples/configure-at-runtime-example` has `Args = --initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access` in its `native-image.properties` file to ensure the class `com.fasterxml.jackson.annotation.JsonProperty$Access` gets initialized at image build time.
93
84
94
85
**JavaArgs**
95
86
96
-
Sometimes it can be necessary to provide custom options to the JVM that runs the
97
-
native image builder. The `JavaArgs` property can be used in this case.
87
+
Sometimes it can be necessary to provide custom options to the JVM that runs the native image builder.
88
+
The `JavaArgs` property can be used in this case.
98
89
99
90
**ImageName**
100
91
101
-
This property can be used to specify a user-defined name for the image. If
102
-
`ImageName` is not used, a name gets automatically chosen:
92
+
This property can be used to specify a user-defined name for the image.
93
+
If `ImageName` is not used, a name gets automatically chosen:
103
94
*`native-image -jar <name.jar>` has a default image name `<name>`
104
95
*`native-image -cp ... fully.qualified.MainClass` has a default image name `fully.qualified.mainclass`
105
96
106
-
Note that using `ImageName` does not prevent the user to override the name later via command line. For example, if `foo.bar` contains `ImageName=foo_app`:
97
+
Note that using `ImageName` does not prevent the user to override the name later via command line.
98
+
For example, if `foo.bar` contains `ImageName=foo_app`:
107
99
*`native-image -jar foo.bar` generates the image `foo_app` but
108
100
*`native-image -jar foo.bar application` generates the image `application`
109
101
110
102
### Order of Arguments Evaluation
111
-
The arguments passed to `native-image` are evaluated left-to-right. This also
112
-
extends to arguments that get passed indirectly via `META-INF/native-image`
113
-
based native image configuration. Suppose you have a JAR file that contains
114
-
_native-image.properties_ with `Args = -H:Optimize=0`. Then by using the
115
-
`-H:Optimize=2` option after `-cp <jar-file>` you can override the setting that
116
-
comes from the JAR file.
103
+
The arguments passed to `native-image` are evaluated left-to-right.
104
+
This also extends to arguments that get passed indirectly via `META-INF/native-image` based native image configuration.
105
+
Suppose you have a JAR file that contains _native-image.properties_ with `Args = -H:Optimize=0`.
106
+
Then by using the `-H:Optimize=2` option after `-cp <jar-file>` you can override the setting that comes from the JAR file.
117
107
118
108
### Specifying Default Options for Native Image
119
-
If there is a need to pass some options for every image build unconditionally, for
120
-
example, to always generate an image in verbose mode (`--verbose`), you can
121
-
make use of the `NATIVE_IMAGE_CONFIG_FILE` environment variable.
122
-
If it is set to a Java properties file, the Native Image builder will use the
123
-
default setting defined in there on each invocation. Write a
124
-
configuration file and export
125
-
`NATIVE_IMAGE_CONFIG_FILE=$HOME/.native-image/default.properties` in
126
-
`~/.bash_profile`. Every time `native-image` gets used, it will implicitly use
127
-
the arguments specified as `NativeImageArgs`, plus the arguments specified on the
128
-
command line. Here is an example of a configuration file, saved as
129
-
`~/.native-image/default.properties`:
109
+
If there is a need to pass some options for every image build unconditionally, for example, to always generate an image in verbose mode (`--verbose`), you can make use of the `NATIVE_IMAGE_CONFIG_FILE` environment variable.
110
+
If it is set to a Java properties file, the Native Image builder will use the default setting defined in there on each invocation.
111
+
Write a configuration file and export `NATIVE_IMAGE_CONFIG_FILE=$HOME/.native-image/default.properties` in `~/.bash_profile`.
112
+
Every time `native-image` gets used, it will implicitly use the arguments specified as `NativeImageArgs`, plus the arguments specified on the command line.
113
+
Here is an example of a configuration file, saved as `~/.native-image/default.properties`:
The native image build runs on the Java HotSpot VM and uses the memory management of the underlying platform.
147
131
The usual Java HotSpot command-line options for garbage collection apply to the native image builder.
148
132
149
-
During the native image build, the representation of a whole program is created to
150
-
figure out which classes and methods will be used at run time. It is a
151
-
computationally intensive process. The default values for memory usage at image build time are:
133
+
During the native image build, the representation of a whole program is created to figure out which classes and methods will be used at run time.
134
+
It is a computationally intensive process.
135
+
The default values for memory usage at image build time are:
152
136
```
153
137
-Xss10M \
154
138
-Xms1G \
@@ -164,21 +148,16 @@ Check other related options to the native image builder from the `native-image -
164
148
165
149
## Runtime vs Build-Time Initialization
166
150
167
-
Building your application into a native image allows you to decide which parts
168
-
of your application should be run at image build time and which parts have to
169
-
run at image run time.
151
+
Building your application into a native image allows you to decide which parts of your application should be run at image build time and which parts have to run at image run time.
170
152
171
-
All class-initialization code (static initializers and static
172
-
field initialization) of the application you build an image for is executed
173
-
at image run time by default. Sometimes it is beneficial to allow class
174
-
initialization code to get executed at image build time for faster startup (e.g.,
175
-
if some static fields get initialized to run-time independent data). This can be
176
-
controlled with the following `native-image` options:
153
+
All class-initialization code (static initializers and static field initialization) of the application you build an image for is executed at image run time by default.
154
+
Sometimes it is beneficial to allow class initialization code to get executed at image build time for faster startup (e.g., if some static fields get initialized to run-time independent data).
155
+
This can be controlled with the following `native-image` options:
177
156
178
157
*`--initialize-at-build-time=<comma-separated list of packages and classes>`
179
158
*`--initialize-at-run-time=<comma-separated list of packages and classes>`
180
159
181
-
In addition to that, arbitrary computations are allowed at build time that can be put into `ImageSingletons` that are
182
-
accessible at image run time. For more information please have a look at [Native Image configuration examples](https://github.com/graalvm/graalvm-demos/tree/master/native-image-configure-examples).
160
+
In addition to that, arbitrary computations are allowed at build time that can be put into `ImageSingletons` that are accessible at image run time.
161
+
For more information please have a look at [Native Image configuration examples](https://github.com/graalvm/graalvm-demos/tree/master/native-image-configure-examples).
183
162
184
163
For more information, continue reading to the [Class Initialization in Native Image](ClassInitialization.md) guide.
Native Image provides an API for the C language for initializing isolates and attaching threads for use with the entry point feature that is demonstrated [here](README.md#images-and-entry-points).
9
+
Native Image provides an API for the C language for initializing isolates and attaching threads for use with the entry point feature that is demonstrated [here](README.md/#images-and-entry-points).
10
10
The C API is available when Native Image is built as a shared library and its declarations are included in the header file that is generated during the build.
11
11
12
12
```c
@@ -79,6 +79,4 @@ int graal_detach_thread(graal_isolatethread_t* thread);
79
79
*/
80
80
int graal_tear_down_isolate(graal_isolatethread_t* thread);
81
81
```
82
-
In addition to the C level API, there is also a way to initialize an isolate
83
-
from Java and thus use Java and Native Image to
84
-
[implement native methods in Java](ImplementingNativeMethodsInJavaWithSVM.md).
82
+
In addition to the C level API, there is also a way to initialize an isolate from Java and thus use Java and Native Image to [implement native methods in Java](ImplementingNativeMethodsInJavaWithSVM.md).
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/ClassInitialization.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,9 @@ Access to the static fields that were initialized at build time is transparent t
19
19
Specifying class initialization policies can be complicated due to the following constraints that come from class initialization semantics:
20
20
21
21
* When a class is initialized, all super classes and super interfaces with default methods must also be initialized.
22
-
Interfaces without default methods, however, are not initialized. To describe this, a short-term "relevant supertype" is used furhter, and a relevant subtype for subtypes of classes and interfaces with default methods.
22
+
Interfaces without default methods, however, are not initialized.
23
+
To describe this, a short-term "relevant supertype" is used furhter, and a relevant subtype for subtypes of classes and interfaces with default methods.
24
+
23
25
* Relevant supertypes of types initialized at build time must also be initialized at build time.
24
26
* Relevant subtypes of types initialized at run time must also be initialized at run time.
25
27
* No instances classes that are initialized at run time must be present in the image.
@@ -31,7 +33,8 @@ To enjoy the complete out-of-the-box experience of Native Image and still get th
31
33
*[Explicitly Specifying Class Initialization](#explicitly-specifying-class-initialization)
32
34
33
35
To track which classes were initialized and why, one can use the flag `-H:+PrintClassInitialization`.
34
-
This flag greatly helps to configure the image build to work as intended. The goal is to have as many classes as possible initialized at build time, yet keep the correct semantics of the program.
36
+
This flag greatly helps to configure the image build to work as intended.
37
+
The goal is to have as many classes as possible initialized at build time, yet keep the correct semantics of the program.
35
38
36
39
## Build-Time Initialization of Native Image Runtime
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/DynamicProxy.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,12 @@ Dynamic proxy classes are generated from a list of interfaces.
12
12
Native Image does not provide machinery for generating and interpreting bytecodes at run time.
13
13
Therefore all dynamic proxy classes need to be generated at native image build time.
14
14
15
-
See also the [guide on assisted configuration of Java resources and other dynamic features](BuildConfiguration.md#assisted-configuration-of-native-image-builds).
15
+
See also the [guide on assisted configuration of Java resources and other dynamic features](BuildConfiguration.md/#assisted-configuration-of-native-image-builds).
16
16
17
17
## Automatic Detection
18
18
19
-
Native Image employs a simple static analysis that detects calls to `java.lang.reflect.Proxy.newProxyInstance(ClassLoader, Class<?>[], InvocationHandler)` and `java.lang.reflect.Proxy.getProxyClass(ClassLoader, Class<?>[])`, then tries to determine the list of interfaces that define dynamic proxies automatically. Given the list of interfaces, Native Image generates proxy classes at image build time and adds them to the native image heap.
19
+
Native Image employs a simple static analysis that detects calls to `java.lang.reflect.Proxy.newProxyInstance(ClassLoader, Class<?>[], InvocationHandler)` and `java.lang.reflect.Proxy.getProxyClass(ClassLoader, Class<?>[])`, then tries to determine the list of interfaces that define dynamic proxies automatically.
20
+
Given the list of interfaces, Native Image generates proxy classes at image build time and adds them to the native image heap.
20
21
In addition to generating the dynamic proxy class, the constructor of the generated class that takes a `java.lang.reflect.InvocationHandler` argument, i.e., the one reflectively invoked by `java.lang.reflect.Proxy.newProxyInstance(ClassLoader, Class<?>[], InvocationHandler)`, is registered for reflection so that dynamic proxy instances can be allocated at run time.
21
22
22
23
The analysis is limited to situations where the list of interfaces comes from a constant array or an array that is allocated in the same method.
Along with all the options listed in the [Options](Options.md)
10
-
guide, Native Image also distinguishes hosted and runtime options.
9
+
Along with all the options listed in the [Options](Options.md) guide, Native Image also distinguishes hosted and runtime options.
11
10
12
11
* Hosted options: configure a native image build, i.e., influence what is put into the image and how the image is built.
13
12
These are set using the prefix `-H:` on the command line.
@@ -19,15 +18,11 @@ For developer documentation on how to define and use options, read the documenta
19
18
## List of Useful Options
20
19
21
20
### Graph Dumping
22
-
Native Image re-used the GraalVM options for graph dumping, logging, counters,
23
-
and everything else in the GraalVM debug environment. These GraalVM options can
24
-
be used both as hosted options (if you want to dump graphs of the native image
25
-
builder), and as runtime options (if you want to dump graphs during dynamic
21
+
Native Image re-used the GraalVM options for graph dumping, logging, counters, and everything else in the GraalVM debug environment.
22
+
These GraalVM options can be used both as hosted options (if you want to dump graphs of the native image builder), and as runtime options (if you want to dump graphs during dynamic
26
23
compilation at runtime).
27
24
28
-
The GraalVM compiler options that work as expected include `Dump`, `DumpOnError`, `Log`,
29
-
`MethodFilter`, and the options to specify file names and ports for the dump
30
-
handlers.
25
+
The GraalVM compiler options that work as expected include `Dump`, `DumpOnError`, `Log`, `MethodFilter`, and the options to specify file names and ports for the dump handlers.
31
26
32
27
For example:
33
28
* To dump the compiler graphs of the native image builder: `-H:Dump= -H:MethodFilter=ClassName.MethodName`.
0 commit comments