JDK-8332770 : Convert dynamic proxy to hidden classes
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 24
  • Submitted: 2024-05-23
  • Updated: 2024-05-23
Related Reports
CSR :  
Description
Summary
-------

Reimplement dynamic proxy with hidden classes.

Problem
-------

1. Dynamic proxies are implementation artifacts, yet they show up in stacktraces;
2. Dynamic proxies are defined to ClassLoaders, and their life is bound to the class loader; it would be too costly to create new ClassLoaders to allow easy unloading of Dynamic proxies.
3. Dynamic proxies cannot easily access the Method objects for the methods it implement, and need extra code to setup.

Solution
--------

Change dynamic proxies implementation to be hidden classes, being hidden in stacktraces and flexible in unloading. (Full unloading support needs further cache implementation update.) As hidden classes, they now access the Method objects via classdata, avoiding extra computations and allowing implementation classes to reach the physical classfile limits later.

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

There is no change to Proxy specification. The new implementation still conforms to those specification, such as serialization, system protection domain, and dynamic module.

Since there are some observable behavior changes, an undocumented system property `-Djdk.reflect.useLegacyProxyImpl=true` can be set to use the old implementation. In addition, if `-Djdk.reflect.useOldSerializableConstructor=true` is set, the implementation will automatically switch to the old one since old serializable constructors are not compatible with hidden classes.

A release note will be created for this change.

Comments
From [~alanb] on the pull request: If we are doing this change then doing it early in a release and putting into effort to outreach to frameworks will be important.
23-05-2024