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

Remove sun.misc.Unsafe::defineAnonymousClass

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source, binary
    • Compatibility Risk:
      medium
    • Compatibility Risk Description:
      Hide
      Hidden classes (JEP 371) was added in Java 15 to replace VM anonymous
      class and discussions happened on OpenJDK mailing lists. Only few
      customers depend on `Unsafe::defineAnonymousClass`, and they are expected to well aware of VM anonymous class going away.
      Show
      Hidden classes (JEP 371) was added in Java 15 to replace VM anonymous class and discussions happened on OpenJDK mailing lists. Only few customers depend on `Unsafe::defineAnonymousClass`, and they are expected to well aware of VM anonymous class going away.
    • Scope:
      JDK

      Description

      Summary

      Remove sun.misc.Unsafe::defineAnonymousClass

      Problem

      sun.misc.Unsafe::defineAnonymousClass was deprecated in JDK 15 and deprecated for removal in JDK 16. The API replacement is java.lang.invoke.MethodHandles.Lookup::defineHiddenClass and java.lang.invoke.MethodHandles.Lookup::defineHiddenClassWithClassData.

      Solution

      Remove sun.misc.Unsafe::defineAnonymousClass from jdk.unsupported module.

      Specification

      Remove sun.misc.Unsafe::defineAnonymousClass:

      -     /**
      -      * Defines a class but does not make it known to the class loader or system dictionary.
      -      * <p>
      -      * For each CP entry, the corresponding CP patch must either be null or have
      -      * the a format that matches its tag:
      -      * <ul>
      -      * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
      -      * <li>Utf8: a string (must have suitable syntax if used as signature or name)
      -      * <li>Class: any java.lang.Class object
      -      * <li>String: any object (not just a java.lang.String)
      -      * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
      -      * </ul>
      -      *
      -      * @deprecated Use {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClass(byte[], boolean, MethodHandles.Lookup.ClassOption...)}
      -      * or {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClassWithClassData(byte[], Object, boolean, MethodHandles.Lookup.ClassOption...)}
      -      * instead.
      -      *
      -      * @param hostClass context for linkage, access control, protection domain, and class loader
      -      * @param data      bytes of a class file
      -      * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
      -      */
      -     @ForceInline
      -     @Deprecated(since = "15", forRemoval = true)
      -     @SuppressWarnings("removal")
      -     public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
      -         return theInternalUnsafe.defineAnonymousClass(hostClass, data, cpPatches);
      -     }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              mchung Mandy Chung
              Reviewed By:
              Alan Bateman, Harold Seigel, Paul Sandoz, Vladimir Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: