-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Replace sun.misc.Unsafe used in LazyVals with VarHandles #24109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a82a297
to
5aafc89
Compare
I actually wonder: is that worth it? It seems to bring additional complexity to the transformation. Sure, we need one call for every
IMO that is really worth it, but for a different reason: it removes the last reference to the (We can drop the |
It's an obvious improvement so I wanted to take it. Unfortunately, even without this we still had to introduce complexity in the MoveStatics phase (directly linking to the LazyVals phase), so we are not doing that much more (1st commit vs 2nd commit). I'll try running some benchmark tests to see if it's worth it.
Right, I hadn't even thought about that (we still reference the nested classes but now I realize that's not an issue). Weirdly, even with the objCAS2 call, the warnings disappeared for me. |
5aafc89
to
74429df
Compare
a35121d
to
9032701
Compare
9032701
to
bb1b2ca
Compare
@sjrd Issues with CI took me a little more time than I anticipated, so I haven't done the promised benchmarks yet. Still I am willing to remove the initialization optimization if it complicates things too much. I did test whether this works with native image though (it does). |
Just a few small tweaks left:[x] maybe inline objCAS2 (should give us more freedom, allow us to backport into 3.3 in the worst case scenario (hopefully not))EDIT: done
This PR replaces the use of the deprecated Unsafe with VarHandles, available in java 9+. Important thing about VarHandles is that for private members (like our val dictating the value/resolution progress of the lazy val), the findVarHandle method must be called from the class containing the val, otherwise we end up with an error. This meant that some custom logic had to be added to the MoveStatics phase, which would usually move static constructor to the companion object (which we do not want for the VarHandles here).
Only the newer implementation was adjusted, the one available under
-Ylegacy-lazy-vals
was left untouched.This PR also effectively drops support for java 8, with java 17 being the new required version. As part of that:
-release
/-java-target-version
is now 17 (earlier versions will throw an error). -Xunchecked-java-output-version was left untouched.-release 8
were removed for projects that were using that. Projects that were usingjavax.xml.bind
(dropped in java 11) were removed altogether (playJson and betterfiles)