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

remove terminally deprecated sun.misc.Unsafe.defineClass

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Compatibility Kind:
      source, binary
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Code depending on Unsafe.defineClass will need to up updated to use MethodHandles.Lookup.defineClass.
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      Summary

      Remove the terminally deprecated method sun.misc.Unsafe.defineClass.

      There is a public supported replacement since Java 9, MethodHandles.Lookup.defineClass, and there has been much outreach explaining this public method and encouraging developers responsible for key libraries and applications to use it.

      Specification

      diff -r 3c0a12972165 src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
      --- a/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java    Thu Mar 15 08:11:01 2018 -0700
      +++ b/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java    Thu Mar 15 09:51:00 2018 -0700
      @@ -811,25 +811,6 @@
           /// random trusted operations from JNI:
      
           /**
      -     * Tells the VM to define a class, without security checks.  By default, the
      -     * class loader and protection domain come from the caller's class.
      -     *
      -     * @deprecated Use {@link java.lang.invoke.MethodHandles.Lookup#defineClass MethodHandles.Lookup#defineClass}
      -     * to define a class to the same class loader and in the same runtime package
      -     * and {@linkplain java.security.ProtectionDomain protection domain} of a
      -     * given {@code Lookup}'s {@linkplain java.lang.invoke.MethodHandles.Lookup#lookupClass() lookup class}.
      -     *
      -     * @see java.lang.invoke.MethodHandles.Lookup#defineClass(byte[])
      -     */
      -    @Deprecated(since="9", forRemoval=true)
      -    @ForceInline
      -    public Class<?> defineClass(String name, byte[] b, int off, int len,
      -                                ClassLoader loader,
      -                                ProtectionDomain protectionDomain) {
      -        return theInternalUnsafe.defineClass(name, b, off, len, loader, protectionDomain);
      -    }
      -
      -    /**
            * 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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psandoz Paul Sandoz
                Reporter:
                smarks Stuart Marks
                Reviewed By:
                Alan Bateman, Mandy Chung
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: