Skip to content

Introduce a Field type in reflect-config.json that Includes all Type's Metadata in the Image #7962

@vjovanov

Description

@vjovanov

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

  1. Reduce the load of maintaining reachability metadata.
  2. Allow the development of a programming model aimed to include metadata from user code.
  3. Simplify reasoning about reflection metadata.

Non-Goals

  1. Increase image size significantly--10% or more.
  2. Reduce any of the other performance metrics for Native Image.

Discussion points

  1. 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.

  2. Should we include the default constructors with the type? Likely not, although it would reduce the amount of metadata by 10%.

  3. When merging old and new configs, should the agent (or native-image-configure) subsume the previous config with type? This is necessary as type is always stronger than name or type with some elements disabled.

Metadata

Metadata

Type

No type

Projects

Status

Released

Relationships

None yet

Development

No branches or pull requests

Issue actions