Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8332770

Convert dynamic proxy to hidden classes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • core-libs
    • None
    • behavioral
    • medium
    • Hide
      Some programs might have relied on dynamic proxy classes being non-hidden, strongly-linked to ClassLoader, or its appearance in stack traces; but these are not specifed by Proxy.

      Other examples include:
      1. Clients may use getName on Proxy classes and use forName to retrieve those classes; this does not work with hidden classes.
      2. Clients may instrument Proxy classes; instrumentations aren't supported by hidden classes.
      Show
      Some programs might have relied on dynamic proxy classes being non-hidden, strongly-linked to ClassLoader, or its appearance in stack traces; but these are not specifed by Proxy. Other examples include: 1. Clients may use getName on Proxy classes and use forName to retrieve those classes; this does not work with hidden classes. 2. Clients may instrument Proxy classes; instrumentations aren't supported by hidden classes.
    • Java API, System or security property
    • SE

      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.

            liach Chen Liang
            mchung Mandy Chung (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: