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);
- }
- csr of
-
JDK-8243287 Removal of Unsafe::defineAnonymousClass
- Resolved