replacements for Unsafe

Remi Forax forax at univ-mlv.fr
Wed Apr 29 11:37:18 UTC 2020


Hi Jochen,
Per the Java spec, calling an empty static method of the inner class works.

Rémi

----- Mail original -----
> De: "Jochen Theodorou" <blackdrag at gmx.org>
> À: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Envoyé: Mercredi 29 Avril 2020 13:23:47
> Objet: replacements for Unsafe

> Hi,
> 
> when jigsaw started there was a lot of talk about providing alternatives
> to what Unsafe offers. Today I am facing a problem I cannot solve
> anymore it seems with this.
> 
> My problem is that I need to ensure the static block of an inner class
> has been executed before I do something, because the static block
> contains setup data the class will need and influence what I do with the
> class. Of course this might be not the best choice, I am just trying to
> keep certain functionality.
> 
> In the past I would have used Unsafe#ensureClassInitialized, but this
> method has not found a replacement yet if I read JDK-8235521 :
> Replacement API for Unsafe::ensureClassInitialized correctly.
> 
> Also because of Unsafe#getUnsafe, checking for the platform loader for
> the caller (which is not the case for me) I cannot get the unsafe object
> itself "properly".
> 
> Now I am wondering what alternatives exist. Are there any?
> 
> bye Jochen


More information about the jigsaw-dev mailing list