The HotSpot Runtime Overview says:
The VM loads core classes such as
java.lang.Object
,java.lang.Thread
, etc. at JVM startup. Loading a class requires loading all superclasses and superinterfaces. And classfile verification, which is part of the linking phase, can require loading additional classes.
java.lang.Object
, java.lang.Thread
as soon as it starts.So what kind of Class was loaded and when? Let's take a look at Unified JVM Logging.
Ubuntu 18.04 as well as previous article And I am using OpenJDK 13, please refer to that for the specific construction method.
startup time
First, let's see the rough startup time of the JVM with the variable -Xlog: startuptime
.
$ $JAVA_HOME/bin/java -Xlog:startuptime -version
[0.168s][info][startuptime] StubRoutines generation 1, 0.0257810 secs
[0.229s][info][startuptime] Genesis, 0.0605841 secs
[0.232s][info][startuptime] TemplateTable initialization, 0.0010887 secs
[0.263s][info][startuptime] Interpreter generation, 0.0302811 secs
[0.693s][info][startuptime] StubRoutines generation 2, 0.0152926 secs
[0.697s][info][startuptime] MethodHandles adapters generation, 0.0017809 secs
[0.703s][info][startuptime] Start VMThread, 0.0010136 secs
[0.997s][info][startuptime] Initialize java.lang classes, 0.2923160 secs
[1.018s][info][startuptime] Initialize java.lang.invoke classes, 0.0159241 secs
[3.161s][info][startuptime] Initialize module system, 2.1431533 secs
[3.173s][info][startuptime] Create VM, 3.1052374 secs
openjdk version "13.0.3-internal" 2020-04-14
OpenJDK Runtime Environment (fastdebug build 13.0.3-internal+0-adhoc.root.jdk13u)
OpenJDK 64-Bit Server VM (fastdebug build 13.0.3-internal+0-adhoc.root.jdk13u, mixed mode)
What you can see here is how many classes and modules have been initialized in the Start VM Thread
throat.
[0.997s][info][startuptime] Initialize java.lang classes, 0.2923160 secs
[1.018s][info][startuptime] Initialize java.lang.invoke classes, 0.0159241 secs
[3.161s][info][startuptime] Initialize module system, 2.1431533 secs
load
and ʻinit`Next, set the variables -Xlog: startuptime, class + init, class + load
and try again.
$ $JAVA_HOME/bin/java -Xlog:startuptime,class+init,class+load -version
[0.096s][info][class,load] path: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.159s][info][startuptime] StubRoutines generation 1, 0.0283598 secs
[0.220s][info][startuptime] Genesis, 0.0597463 secs
[0.223s][info][startuptime] TemplateTable initialization, 0.0012748 secs
[0.252s][info][startuptime] Interpreter generation, 0.0291667 secs
[0.284s][info][class,load ] path: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.285s][info][class,load ] path: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.314s][info][class,load ] java.lang.Object source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.321s][info][class,load ] java.io.Serializable source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
...
[0.553s][info][class,load ] java.util.Iterator source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.578s][info][class,load ] java.lang.NullPointerException source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.579s][info][class,load ] java.lang.ArithmeticException source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[0.619s][info][startuptime] StubRoutines generation 2, 0.0132195 secs
[0.622s][info][startuptime] MethodHandles adapters generation, 0.0018546 secs
[0.627s][info][startuptime] Start VMThread, 0.0007446 secs
[0.629s][info][class,init ] 0 Initializing 'java/lang/Object' (0x0000000100001080)
[0.644s][info][class,init ] 1 Initializing 'java/lang/CharSequence'(no method) (0x00000001000016b8)
...
[0.898s][info][class,init ] 135 Initializing 'java/lang/IllegalArgumentException'(no method) (0x000000010002b0e8)
[0.898s][info][startuptime] Initialize java.lang classes, 0.2690178 secs
[0.902s][info][class,init ] 136 Initializing 'java/lang/invoke/MethodHandle' (0x000000010000c560)
...
[0.925s][info][class,init ] 144 Initializing 'java/lang/invoke/MethodHandleNatives' (0x000000010000d2e8)
[0.925s][info][startuptime] Initialize java.lang.invoke classes, 0.0232579 secs
[0.935s][info][class,load ] jdk.internal.module.ModuleBootstrap source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
...
[3.112s][info][class,load ] jdk.internal.module.ModuleBootstrap$SafeModuleFinder source: /vagrant/jdk/jdk13u/build/linux-x86_64-server-fastdebug/jdk/modules/java.base
[3.113s][info][class,init ] 662 Initializing 'jdk/internal/module/ModuleBootstrap$SafeModuleFinder'(no method) (0x000000010008e930)
[3.113s][info][startuptime] Initialize module system, 2.1876125 secs
[3.124s][info][startuptime] Create VM, 3.0688743 secs
openjdk version "13.0.3-internal" 2020-04-14
OpenJDK Runtime Environment (fastdebug build 13.0.3-internal+0-adhoc.root.jdk13u)
OpenJDK 64-Bit Server VM (fastdebug build 13.0.3-internal+0-adhoc.root.jdk13u, mixed mode)
What I found here is actually two stages
and
StubRoutines generation 2`.Start VMThread
663 (0-662) Classes have been initialized.java.lang
136 pieces (0-135)java.lang.invoke
9 (136-144)module system
518 pieces (145-622)If you search the source code for the above text, you'll find where to inspire these two steps.
SystemDictionary :: resolve_well_known_classes
: SystemDictionary
is almost JVM Class management It's working. When this SystemDictionary
is initialized, the so-called ** Well Know Classes ** core Classes are also initialized. A list of Well Known Classes can be found here [https://github.com/openjdk/jdk13u/blob/master/src/hotspot/share/classfile/systemDictionary.hpp#L103), the order is important It seems like.Threads :: create_vm
:java in the throat of
Start VM Thread This is where .lang classes
, java.lang.invoke classes
and module system
are initialized at once. Specifically, with these three functions
Initializes these core Classes when the JVM boots
System Dictionary
initialization)java.lang
Classjava.lang.invoke
Class$ JAVA_HOME / modules
Recommended Posts