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: tbd
  • Submitted: 2024-05-23
  • Updated: 2024-10-22
Related Reports
CSR :  
Description
Summary
-------

Reimplement dynamic proxy with hidden classes. This is offered as an experimental option, toggleable with `-Djdk.reflect.useHiddenProxy=true`.

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.

Since we anticipate this to have compatibility risk as Proxy class objects are used by serialization, we do not enable this implementation by default; it has to be opt-in with `-Djdk.reflect.useHiddenProxy=true` to allow early adoptions.

Since the hidden proxy implementation requires `MethodHandle`-based serialization constructor implementation, VM will fail with an error if both `-Djdk.reflect.useHiddenProxy=true` and `-Djdk.reflect.useOldSerializableConstructor=true` are passed.

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.



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