[GR-58477] Simplify unsafe allocation, field registration and serialization reachability metadata #10178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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 tofalse
. Individual fields can then be registered by specifying them inside the"fields"
field as is currently the case. An example follows: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 usingRuntimeReflection.register(field)
."unsafeAllocated"
All reflectively-accessible classes are now registered for unsafe allocation. In effect, the following JSON registration:
will become equivalent to:
In the same fashion, calling
RuntimeReflection.register(clazz)
from a feature will makeclazz
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:wille become equivalent to:
Calling
RuntimeSerialization.register(clazz)
will also register all possible serialization constructors, andRuntimeSerialization.registerWithTargetConstructorClass(clazz, constructor)
will become functionally equivalent toRuntimeSerialization.register(clazz)
.