Hi Peter,
On 5/04/2019 5:37 pm, Peter Levart wrote:
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?
That's what the earlier class comment is about:
* @implNote
*
* The JVM injects hardware-specific values into all the static fields
* of this class during JVM initialization. The static initialization
* block exists to prevent the fields from being considered constant
* variables, so the field values will be not be compiled directly into
* any class that uses them.
*/
Cheers,
David
Reading the patch further uncovers the secret:
3645 // initialize the hardware-specific constants needed by Unsafe
3646 initialize_class(vmSymbols::jdk_internal_misc_UnsafeConstants(),
CHECK);
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