JDK-8243287 : Removal of Unsafe::defineAnonymousClass
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-04-21
  • Updated: 2022-11-02
  • Resolved: 2021-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b23Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8267178 :  
JDK-8267179 :  
Description
This issue tracks all the tasks to be completed for the removal of `sun.misc.Unsafe::defineAnonymousClass` 

Comments
Changeset: e14b0268 Author: Harold Seigel <hseigel@openjdk.org> Date: 2021-05-13 12:46:54 +0000 URL: https://git.openjdk.java.net/jdk/commit/e14b0268411bba8eb01bf6c477cc8743a53ffd1c
13-05-2021

I'm fine with the removal, although I want to mention that Nashorn uses this facility too[0], and when I tried to replace it with the hidden classes facility the issue we run into was that hidden classes' methods didn't show up in stack traces the way anonymous classes' methods did[1]. Since Nashorn uses anonymous classes to install compiled JavaScript application code, it is important to be able to report stack traces from them. It unfortunately can't just use StackWalker, as it has to post-edit traces of already thrown exceptions. So ensuring JDK-8212620 is implemented as well, and/or maybe having a `MethodHandles.Lookup.ClassOption` to specify the class should show up in stack traces would be important to implement alongside the removal. It's not a show-stopper, Nashorn will be able to gracefully fail over to ordinary class loading in absence of anonymous class loading, but I'd really like to be able to transition to using hidden classes if we could get them to show up in stack traces. [0] https://github.com/openjdk/nashorn/blob/main/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/Context.java#L329 [1] https://mail.openjdk.java.net/pipermail/nashorn-dev/2020-October/007578.html
11-05-2021

There are many regression tests added for `Unsafe::defineAnonymousClass`. We should convert the regression tests for `Unsafe::defineAnonymousClass` to use `Lookup::defineHiddenClass` where appropriate or unless the same test exists for hidden class [1]. [1] http://hg.openjdk.java.net/valhalla/valhalla/rev/3ff43480c2a2
28-04-2021