-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation, use subcommands and support multiple import files.
- Loading branch information
1 parent
d535cfc
commit b221fce
Showing
9 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Assisted Configuration of Native Image Builds | ||
|
||
_NOTE: the described agent is currently only supported on Linux._ | ||
|
||
Native images are built ahead of runtime and their build relies on a static analysis of which code will be reachable. However, this analysis cannot always completely predict all usages of the Java Native Interface (JNI), Java reflection, dynamic proxy objects (`java.lang.reflect.Proxy`) or class-path resources (`Class.getResource`). Undetected usages of these dynamic features need to be provided to the `native-image` tool in the form of configuration files. | ||
|
||
In order to make preparing these configuration files easier and more convenient, GraalVM provides an _agent_ that traces all usages of dynamic features of an execution on a regular Java VM. It can be enabled on the command line of the GraalVM `java` command: | ||
|
||
``` | ||
/path/to/graalvm/bin/java -agentlib:native-image-agent=output=/path/to/trace-file.json ... | ||
``` | ||
|
||
During execution, the agent interfaces with the Java VM to intercept all calls that look up classes, methods, fields, resources or request proxy accesses and writes a trace file with the specified path. | ||
|
||
Next, the `native-image-configure` tool can transform the trace file to configuration files for native image builds. This tool itself must first be built with the command `native-image --tool:native-image-configure`. Then, the tool can be used as follows: | ||
|
||
``` | ||
native-image-configure process-trace \ | ||
--jni-output jni-config.json \ | ||
--reflect-output reflect-config.json \ | ||
--proxy-output proxy-config.json \ | ||
--resources-output resource-args.txt \ | ||
/path/to/trace-file.json | ||
``` | ||
|
||
This invocation reads and processes `trace-file.json` and generates the files `jni-config.json`, `reflect-config.json`, `proxy-config.json` and `resource-params.txt` (but not all these arguments must always be specified, see `native-image-configure help`). The `.json` files are stand-alone configuration files, while `resource-args.txt` contains command-line arguments to `native-image`. | ||
|
||
It is advisable to manually review the generated configuration files. Because the agent observes only a single execution, the resulting configurations can be missing elements that are used in code paths that were not executed. It could also make sense to simplify the generated configurations to make any future manual maintenance easier. | ||
|
||
Failed lookups of classes, methods, fields or resources are recorded in the trace, but are not included in the generated configurations by default. Likewise, accesses from inside the Java class library or the Java VM (such as in `java.nio`) are filtered by default. For testing purposes, filtering can be disabled by passing `--no-filter` to `native-image-configure`, but the generated configuration files are likely unsuitable for a build. | ||
|
||
Finally, the generated configuration files can be used in a `native-image` build as follows: | ||
|
||
``` | ||
native-image -H:JNIConfigurationFiles=jni-config.json \ | ||
-H:ReflectionConfigurationFiles=reflect-config.json \ | ||
-H:DynamicProxyConfigurationFiles=proxy-config.json \ | ||
-H:IncludeResources=some/resource/on/classpath.txt \ | ||
-H:IncludeResources=some/other/resource/on/classpath.txt \ | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -637,6 +637,7 @@ | |
"subDir": "src", | ||
"sourceDirs": [ | ||
"src", | ||
"resources", | ||
], | ||
"dependencies": [ | ||
"com.oracle.svm.core", | ||
|
35 changes: 35 additions & 0 deletions
35
substratevm/src/com.oracle.svm.configure/resources/Help.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
GraalVM native-image-configure tool | ||
|
||
This tool can be used to prepare a configuration of JNI, reflection and | ||
resources for a native-image build. | ||
|
||
Usage: native-image-configure process-trace [options] tracefile... | ||
native-image-configure help | ||
|
||
process-trace processes trace file(s) from the agent. | ||
--reflect-output <path> | ||
write a reflection configuration file with the given | ||
path. This file can be later provided to native-image | ||
with -H:ReflectionConfigurationFiles=<path>. | ||
--jni-output <path> | ||
write a JNI configuration file with the given path. | ||
This file can be later provided to native-image with | ||
-H:JNIConfigurationFiles=<path>. | ||
--proxy-output <path> | ||
write a dynamic proxy configuration file at the given | ||
path. This file can be later provided to native-image | ||
with -H:DynamicProxyConfigurationFiles=<path>. | ||
--resources-output <path> | ||
write a file with used resources (getResource) to the | ||
given path. Each line is an option to native-image | ||
for including a specific resource. The paths might | ||
need to be adjusted to the build directory structure. | ||
--no-filter | ||
usage of JNI, reflection and resources in internal | ||
classes does not have to be configured for builds | ||
with native-image and by default, is excluded from | ||
the generated configurations. This option disables | ||
this filter. | ||
|
||
help prints this help message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters