Some JVM operations, such as GC (), Runfinalization (), exit (), are not mentioned in the source Java doc, possibly because they are not recommended for proactive invocation. And these methods are just runtime.getruntime () call, the two do not distinguish the bottom of the direct view, the main methods and functions are listed. Below we focus on how the class is initialized. First, at the beginning, we can look at the following code:
private static native void registerNatives();static { registerNatives();}
The static code block in the class calls a native method Registernatives (), which can be guessed that the method should be an ingress method, and take a look at the comment: by statically initializing the Register native method, This method causes the VM to complete the initialization work by calling the Initializesystemclass method. Sure enough, then let's look at the Initializesystemclass method:
PrivateStaticvoidInitializesystemclass() {Initialize Props props =New Properties (); InitProperties (props); Sun.misc.VM.saveAndRemoveProperties (props);Gets the system-related newline character lineseparator = Props.getproperty ("Line.separator"); Sun.misc.Version.init ();Create an instance object of in, out, err, respectively, and initialize with setXX0 () to view the SetXX0 () method, which is a native method that manages the system's standard flow to objects within the class FileInputStream Fdin =New FileInputStream (FileDescriptor.in); FileOutputStream fdout =New FileOutputStream (FileDescriptor.Out); FileOutputStream Fderr =New FileOutputStream (FILEDESCRIPTOR.ERR); SetIn0 (New Bufferedinputstream (Fdin)); SetOut0 (New PrintStream (New Bufferedoutputstream (Fdout,128),true)); SetErr0 (new printstream (new bufferedoutputstream (FDERR, Span class= "Hljs-number" >128), true)); //load the zip package to get java.util.zip.ZipFile this class so that after loading Licoux use LoadLibrary ( "zip"); //set the platform-related signal processing terminator.setup (); //initialize SUN.MISC related environment variables sun.misc.VM.initializeOSEnvironment (); //the main thread does not add the same threads to the same thread group, we must implement it ourselves here. Note Half a day did not understand, look at the code is the main thread himself added to their own thread group ... Thread current = Thread.CurrentThread (); Current.getthreadgroup (). Add (current); //register a shared secret key? Note is not clear, the method is to instantiate a javalangaccess setjavalangaccess (); The //subsystem can invoke sun.misc.VM.isBooted () at initialization time to ensure that nothing is done before the application class loader starts. Booted () is actually changing the state so that isbooted () becomes true. Sun.misc.VM.booted ();}
At this point, the system is basically finished, but there are a lot of low-level things do not understand (setjavalangaccess ()), to be resolved later.