RFR 7149320: Move sun.misc.VM.booted() to end of System.initializeSystemClass()

David Holmes david.holmes at oracle.com
Tue Feb 28 04:50:23 UTC 2012


Hi Mike,

The problem with changing initialization order is that you can never 
enumerate all the possible initialization paths. I don't see anything 
problematic with the move in relation to Thread.currentThread() or 
ThreadGroup.add(). But the call to setJavaLangAccess requires 
initialization of SharedSecrets which in turn requires initialization of 
Unsafe which in turn initializes sun.reflect.Reflection which in turn 
initializes a bunch of Collection classes - and suddenly we may have a 
whole swag of classes now being initialized before the VM appears to be 
booted.

If you then throw into the mix the possibility of different system 
properties affecting initialization actions, or the existence of an 
agent, then who knows what might actually happen.

Cheers,
David
-----


On 28/02/2012 1:57 PM, Mike Duigou wrote:
> Hello all;
>
> This issue is a patch for review that I have split out of a larger issue I'll be submitting later.
>
> WEBREV @ http://cr.openjdk.java.net/~mduigou/7149320/0/webrev/
>
> sun.misc.VM.booted() is currently called before setJavaLangAccess(). For code which uses the JavaLangAccess shared secrets it's convenient to be able to check whether the secrets are initialized without having to call sun.misc.SharedSecrets.getJavaLangAccess() every time the secrets are used and checking for null. In particular with the static inner class holder idiom it would be desirable to do :
>
> static class Holder {
>    final sun.misc.JavaLangAccess ACCESS = sun.misc.SharedSecrets.getJavaLangAccess();
> }
>
> ...
>
> if(sun.misc.VM.isBooted()&&  Holder.ACCESS...
>
> In my research on this issue I was unable to determine why sun.misc.VM.booted() isn't the currently the last activity in System.initSystemClass(). Neither of the two tasks which currently follow it depend upon booted state in any way that I could determine. I am tempted, thinking about it, to add a comment to System.initSystemClass before the call to sun.misc.VM.booted() asking future maintainers to leave boot() as the last activity or explain why not.
>
> I have done JTReg runs on linux x86, linux x64 and Solaris 64 which incorporated this change without any problems encountered. It's rather difficult to write a unit test for this issue as it requires a class that is initialized after java.lang.System but before java.lang.System.initSystemClass() and uses JavaLangAccess.
>
> Thanks,
>
> Mike



More information about the core-libs-dev mailing list