On Fri, 3 Dec 2021 13:05:44 GMT, Alan Bateman <al...@openjdk.org> wrote:
> Deprecate the sun.misc.Unsafe methods that return field offsets. These method > are an impediment to possible future changes. Layout may not be fixed in the > future, the VM should be allowed to re-layout dynamically based on patterns > of usage. We also have the issue of libraries using these methods to get > offsets (sometimes of classes with the same layout as JDK classes) so they > can directly access the fields of privileged classes. It's untenable for > libraries to rely on this going forward. > > The java.lang.invoke.VarHandle API (added in Java 9) provides a strongly > typed reference to a variable that is a safe and a much better alternative to > many cases that use these methods. Deprecating these method provides a gentle > nudge in that directory. Once the Panama memory APIs are permanent then we > can look at terminally deprecating and removing these methods, along with the > accessors. Yes, we have to keep chipping away at this. Most of the on-heap usages that I found could have been replaced with VarHandles a long time ago but many of these projects are still building to old JDK releases and maybe MR JARs are still problematic in the build. The great progress on the memory API in Project Panama means it won't be long before those accessors are needed for off-heap. So yes, a few more releases and we should be able to make more progress. I toyed with including staticFieldBase but I didn't find anything like the usage as the offset methods. Easy to include if you think it's worth doing. ------------- PR: https://git.openjdk.java.net/jdk/pull/6700