Skip to content

Commit 2a99d81

Browse files
committed
[GR-58570] Fix Missing quotation marks around parameterTypes in Reachability Metadata documentation.
PullRequest: graal/18921
2 parents f02ef19 + 664c838 commit 2a99d81

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

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

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Metadata can be provided to the `native-image` builder in the following ways:
4646
* [Resources](#resources)
4747
* [Resource Bundles](#resource-bundles)
4848
* [Serialization](#serialization)
49-
* [Predefined Classes](#predefined-classes)
5049
* [Sample Reachability Metadata](#sample-reachability-metadata)
50+
* [Defining Classes at Run Time](#defining-classes-at-run-time)
5151

5252
## Computing Metadata in Code
5353

@@ -279,8 +279,8 @@ To reflectively invoke methods, the method signature must be added to the `type`
279279
{
280280
"type": "TypeWhoseMethodsAreInvoked",
281281
"methods": [
282-
{"name": "<methodName1>", "parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]},
283-
{"name": "<methodName>", "parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]}
282+
{"name": "<methodName1>", "parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]},
283+
{"name": "<methodName2>", "parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]}
284284
]
285285
}
286286
```
@@ -412,8 +412,8 @@ To call Java methods from JNI, we must provide metadata for the method signature
412412
{
413413
"type": "jni.accessed.Type",
414414
"methods": [
415-
{"name": "<methodName1>", "parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]},
416-
{"name": "<methodName>", "parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]}
415+
{"name": "<methodName1>", "parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]},
416+
{"name": "<methodName2>", "parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]}
417417
]
418418
}
419419
```
@@ -686,35 +686,9 @@ For example, to allow serialization of `org.apache.spark.SparkContext$$anonfun$h
686686
}
687687
```
688688

689-
## Defining Classes at Run Time
690-
691-
Java has support for loading new classes from bytecode at run time, which is not possible in Native Image as all classes must be known at build time (the "closed-world assumption").
692-
693-
To emulate class loading, the [Native Image Agent](AutomaticMetadataCollection.md) can trace dynamically loaded classes and save their bytecode for later use by the `native-image` builder.
694-
At runtime, if there is an attempt to load a class with the same name and bytecode as one of the classes encountered during tracing, the predefined class will be supplied to the application.
695-
696-
> Note: Predefined classes metadata is not meant to be manually written.
697-
698-
Predefined classes metadata should be specified in a _predefined-classes-config.json_ file and conform to the JSON schema defined in
699-
[predefined-classes-config-schema-v1.0.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/predefined-classes-config-schema-v1.0.0.json).
700-
The schema also includes further details and explanations how this configuration works. Here is the example of the predefined-classes-config.json:
701-
```json
702-
[
703-
{
704-
"type": "agent-extracted",
705-
"classes": [
706-
{
707-
"hash": "<class-bytecodes-hash>",
708-
"nameInfo": "<class-name"
709-
}
710-
]
711-
}
712-
]
713-
```
689+
## Sample Reachability Metadata
714690

715-
## Sample ReachabilIty Metadata
716-
717-
See below is a sample reachabilIty metadata configuration that you can use in _reachabilty-metadata.json_:
691+
See below is a sample reachability metadata configuration that you can use in _reachabilty-metadata.json_:
718692

719693
```json
720694
{
@@ -729,7 +703,7 @@ See below is a sample reachabilIty metadata configuration that you can use in _r
729703
"methods": [
730704
{
731705
"name": "method1",
732-
"parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]
706+
"parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]
733707
}
734708
],
735709
"allDeclaredConstructors": true,
@@ -752,7 +726,7 @@ See below is a sample reachabilIty metadata configuration that you can use in _r
752726
"methods": [
753727
{
754728
"name": "method1",
755-
"parameterTypes": ["<param-type1>", "<param-typeI>, <param-typeN>"]
729+
"parameterTypes": ["<param-type1>", "<param-typeI>", "<param-typeN>"]
756730
}
757731
],
758732
"allDeclaredConstructors": true,
@@ -784,7 +758,37 @@ See below is a sample reachabilIty metadata configuration that you can use in _r
784758
}
785759
```
786760

787-
### Further Reading
761+
## Defining Classes at Run Time
762+
763+
Java has support for loading new classes from bytecode at run time, which is not possible in Native Image as all classes must be known at build time (the "closed-world assumption").
764+
To overcome this issue there are the following options:
765+
1. Modify or reconfigure your application (or a third-party library) so that it does not generate classes at runtime or load them via non-built-in class loaders.
766+
2. If the classes must be generated, try to generate them at build time in a static initializer of a dedicated class.
767+
The generated java.lang.Class objects should be stored in static fields and the dedicated class initialized by passing `--initialize-at-build-time=<class_name>` as the build argument.
768+
3. If none of the above is applicable, use the [Native Image Agent](AutomaticMetadataCollection.md) to run the application and collect predefined classes with
769+
`java -agentlib:native-image-agent=config-output-dir=<config-dir>,experimental-class-define-support <application-arguments>`.
770+
At runtime, if there is an attempt to load a class with the same name and bytecode as one of the classes encountered during tracing, the predefined class will be supplied to the application.
771+
772+
Predefined classes metadata is specified in a _predefined-classes-config.json_ file and conform to the JSON schema defined in
773+
[predefined-classes-config-schema-v1.0.0.json](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/predefined-classes-config-schema-v1.0.0.json).
774+
The schema also includes further details and explanations how this configuration works. Here is the example of the predefined-classes-config.json:
775+
```json
776+
[
777+
{
778+
"type": "agent-extracted",
779+
"classes": [
780+
{
781+
"hash": "<class-bytecodes-hash>",
782+
"nameInfo": "<class-name"
783+
}
784+
]
785+
}
786+
]
787+
```
788+
> Note: Predefined classes metadata is not meant to be manually written.
789+
> Note: Predefined classes are the best-effort approach for legacy projects, and they are not guaranteed to work.
790+
791+
## Further Reading
788792

789793
* [Metadata Collection with the Tracing Agent](AutomaticMetadataCollection.md)
790794
* [Native Image Compatibility Guide](Compatibility.md)

0 commit comments

Comments
 (0)