-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
TL;DR
We'd like to include all the type's metadata for types that are registered for reflection as the default behavior in reflect-config.json. The newly included metadata would contain method signatures, inner classes, field metadata, record components, signers, and permitted subclasses. The transitively included classes would be included in the image, but not registered for reflection.
This is inspired by #7753 where we show that roughly 25% of registration entries can be removed when we use the proposed approach here.
Since this is a breaking change, we propose a new schema for inclusion:
{
"type": "app.App"
}as this is anyhow required for proxies and lambdas. The new entry would be equivalent to
{
"name": "app.App",
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"queryAllDeclaredFields": true,
"queryAllPublicMethods": true,
"queryAllPublicConstructors": true,
"queryAllPublicFields": true,
"allDeclaredClasses": true,
"allPublicClasses": true,
"allRecordComponents": true,
"allNestMembers": true,
"allSigners": true,
"allPermittedSubclasses": true
}It should be possible to disable the metadata from a type by disabling certain properties. For example, we can exclude method metadata with:
{
"type": "app.App",
"queryAllDeclaredMethods": false,
"queryAllPublicMethods": false
}Since this change will propagate quickly through the ecosystem, we intend to backport this change to GraalVM for JDK 17 and JDK 21.
The format with name will be kept functional in the foreseeable future due to the number of existing projects that use it. However, the agent will be changed to produce the format with type.
Goals
- Reduce the load of maintaining reachability metadata.
- Allow the development of a programming model aimed to include metadata from user code.
- Simplify reasoning about reflection metadata.
Non-Goals
- Increase image size significantly--10% or more.
- Reduce any of the other performance metrics for Native Image.
Discussion points
-
Should
Class.forName("literal.Type")include all class metadata in the image? Likely not, this would make the programming model unpredictable and bloat the image. -
Should we include the default constructors with the
type? Likely not, although it would reduce the amount of metadata by 10%. -
When merging old and new configs, should the agent (or
native-image-configure) subsume the previous config withtype? This is necessary astypeis always stronger thannameortypewith some elements disabled.
Metadata
Metadata
Labels
Type
Projects
Status