JDK-8307575 : Migrate the serialization constructor accessors to Method Handles
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 21
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2023-05-06
  • Updated: 2023-08-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
The serialization constructor in ReflectionFactory is the only one whose accessor is still magic-based (JDK-8305104). They are not used before java.lang.invoke is ready; thus, it's totally safe to migrate them (used by serialization and sun.reflect.ReflectionFactory::newConstructorForSerialization) to exclusively methodhandle-based accessors.

A prototype exists as part of https://github.com/openjdk/jdk/pull/1830 which I have tweaked since the introduction of methodhandle accessors and added extra comments and assertions.

With this migration, hidden classes can be serialized as regular objects (in particular, proxies), and it will simplify the removal of old core reflection implementation.
Comments
Sure, go ahead. Just beware that this might impact Valhalla if Value Objects are going to share the new-dup-<init> sequence with Identity Objects: https://mail.openjdk.org/pipermail/valhalla-dev/2023-August/011481.html
31-08-2023

[~liach] It's a good idea to reimplement the serialization constructor accessor with method handles, which allows us to remove the VM hacks as described in [1]. This requires thorough testing and therefore I decided to implement it to tease out issues and fixed them. This is my branch ready for review: https://github.com/openjdk/jdk/compare/master...mlchung:jdk:reflect-serializable-ctor It seems that the easiest is to create a PR and add you as a contributor. What do you think? [1] https://bugs.openjdk.org/browse/JDK-8305104?focusedCommentId=14570146&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14570146
24-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13853 Date: 2023-05-06 16:55:16 +0000
06-05-2023