Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-58477] Simplify unsafe allocation, field registration and serialization reachability metadata #10178

Closed
wants to merge 2 commits into from

Conversation

graalvmbot
Copy link
Collaborator

This PR removes the following fields from reachability-metadata.json. Those fields were evaluated to have only a minimal impact on the resulting image size (see #9679). Each modification is contained in its own commit to facilitate reviewing.

Field registration
All reflectively-accessed types now have all their fields registered for runtime access by default. This means that the following JSON registration now enables all fields of the given type to be accessed using Field.get, Field.set, and similar methods:

{
  "reflection": [
    {
      "type": "fully.qualified.ClassName"
    }
  ]
}

Registering a type for reflection through RuntimeReflection.register(clazz) will have the same effect.

In some cases, it is possible that including all fields of reflectively-accessed types for reflection can trigger a significant image size increase by making certain fields reachable. If this is not desired, users can opt-out of the automatic field registration by setting the existing "allDeclaredFields" and/or "allPublicFields" fields to false. Individual fields can then be registered by specifying them inside the "fields" field as is currently the case. An example follows:

{
  "reflection": [
    {
      "type": "fully.qualified.ClassName",
      "allDeclaredFields": false,
      "allPublicFields": false,
      "fields": [
        {
          "name": "individuallyRegisteredField"
        }
      ]
    }
  ]
}

When registering a type through features, a new API call RuntimeReflection.register(clazz, false) will be added, enabling users to opt out of automatic field access registration. Individual fields will then be able to be registered using RuntimeReflection.register(field).

"unsafeAllocated"

All reflectively-accessible classes are now registered for unsafe allocation. In effect, the following JSON registration:

{
  "reflection": [
    {
      "type": "registered.class.Name",
    }
  ]
}

will become equivalent to:

{
  "reflection": [
    {
      "type": "registered.class.Name",
      "unsafeAllocated": true
    }
  ]
}

In the same fashion, calling RuntimeReflection.register(clazz) from a feature will make clazz unsafe-allocatable at run-time.

"customConstructorClass"

All serializable types can now be serialized with all possible constructors, removing the need for this extra field. Similarly to "unsafeAllocated" above, the following JSON registration:

{
  "serialization": [
    {
      "type": "fully.qualified.ClassName"
    }
  ]
}

wille become equivalent to:

{
  "serialization": [
    {
      "type": "fully.qualified.ClassName",
      "customConstructorClass": "super.constructor.ClassName"
    }
  ]
}

Calling RuntimeSerialization.register(clazz) will also register all possible serialization constructors, and RuntimeSerialization.registerWithTargetConstructorClass(clazz, constructor) will become functionally equivalent to RuntimeSerialization.register(clazz).

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 28, 2024
@loicottet loicottet self-assigned this Nov 28, 2024
@graalvmbot graalvmbot force-pushed the lottet/GR-58477-simplify-metadata branch 4 times, most recently from d4b6305 to 865366f Compare November 29, 2024 15:25
@graalvmbot graalvmbot force-pushed the lottet/GR-58477-simplify-metadata branch 2 times, most recently from cd76a75 to 4ba5326 Compare December 1, 2024 16:16
@zakkak
Copy link
Collaborator

zakkak commented Dec 2, 2024

@loicottet FYI I have tested this with Quarkus core's integration tests in quarkusio/quarkus#44864 (comment)

@loicottet
Copy link
Member

This PR is now split into the following individual PRs for each change:

We will not merge the automatic field registration yet because of some issues we found with the semantics of the change, however we also opened #10215, which introduces a "serializable" flag to replace the "serialization" section of reachability-metadata.json.

@loicottet loicottet closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants