RFR: 8221477: Inject os/cpu-specific constants into Unsafe from JVM

Peter Levart peter.levart at gmail.com
Fri Apr 5 07:37:20 UTC 2019

Hi Andrew,

For a casual reader (like me) the comments in the UnsafeConstants for 
each field:

   69      * @implNote
   70      * The actual value for this field is injected by the JVM.

...make one wonder what is actually going on regarding the static 
initializer at the end of the class. Is it actually executed? Is it 
there just to silence the javac and prevent fields from becoming 
compile-time constants?

Reading the patch further uncovers the secret:

3645   // initialize the hardware-specific constants needed by Unsafe
3646 initialize_class(vmSymbols::jdk_internal_misc_UnsafeConstants(), 
3647   jdk_internal_misc_UnsafeConstants::set_unsafe_constants();

If my understanding is correct, then the static initializer *is* 
executed and then the fields' values are overwritten with injected values.

So perhaps it might be nice to write that down in the javadoc like:

   69      * @implNote
   70      * The actual value for this field is injected by the JVM 
immediately after the class initialization.

Or something similar in the class-level javadoc.

Just for the peace of mind of casual readers or perhaps someone that 
might later add a field to this class and try to initialize it in the 
static initializer, although I think this class is reserved for injected 
fields only...

Regards, Peter

On 4/4/19 5:19 PM, Andrew Dinn wrote:
> New webrev is now available. Re-reviews welcome.
> JIRA:   https://bugs.openjdk.java.net/browse/JDK-8221477
> Webrev: http://cr.openjdk.java.net/~adinn/8221477/webrev.03
> This version should address all comments from Thomas, David and Coleen.
> Testing
> Tier1 test passed.
> Submit test passed.
> regards,
> Andrew Dinn
> -----------
> Senior Principal Software Engineer
> Red Hat UK Ltd
> Registered in England and Wales under Company Registration No. 03798903
> Directors: Michael Cunningham, Michael ("Mike") O'Neill, Eric Shander

More information about the core-libs-dev mailing list