JDK-8315811 : Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P3
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 22
  • Submitted: 2023-09-06
  • Updated: 2023-09-07
Related Reports
CSR :  
Description
Summary
-------

Reimplement `sun.reflect.ReflectionFactory::newConstructorForSerialization` with method handles

Problem
-------

Current implementation of `sun.reflect.ReflectionFactory::newConstructorForSerialization` generates bytecode that does not conform verification rules.   Hence VM has a special case to skip verification for all `MagicAccessorImpl` subclasses.  Reimplementing it with method handles allow to remove the old crufty bytecode generator as well as the VM special case in skipping verification for certain classes.

Solution
--------

Reimplement `ReflectionFactory::newConstructorForSerialization` with method handles

Specification
-------------

It's expected that this change has very low compatibility risk.

In case if customers run into any issue, an undocumented system property `-Djdk.reflect.useOldSerializableConstructor=true` can be set to use the old implementation as a workaround.

If `ReflectionFactory::newConstructorForSerialization` is called with `C` class and a constructor whose declaring class is `A` but `A` is not the superclass of `C`, the old implementation returns an ill-formed constructor and if `newInstance` is invoked, the behavior is unspecified.   The new implementation of `ReflectionFactory::newConstructorForSerialization` throws `UnsupportedOperationException` instead.