Java class loading mechanism

java class loading mechanism has seven stages
when the java compiled, will generate a class, you need to run when it is necessary to start JVM bytecode virtual machine execution class file
when the JVM bytecode virtual machine execution class, when there are several stages load verification destroy ready to resolve initialization call
load
is to load data into memory, to create a class of objects within the JVM memory space opened up
verification jvm loaded the class byte code creates class as the object itself and is ready to call the bytecode verifier . jvm they meet the specification can be executed bytecodes jvm.
jvm specification: jvm will byte stream file checksum.
check logic: int jvm also for other types of objects within a class parameter calibrating
prepared
jvm core working
memory allocation java objects in variables class variables and member variables
class variables modified static variables
and member variables are modified in a class which
allocates memory in jvm preparation phase variable will
resolve
jvm after allocating memory, interfaces will field class method calls for resolution. the main task is to be able to directly call up the memory
initialization

  • Encounter new, getstatic, putstatic, when invokestatic these four byte code instructions, if the class is not been initialized, you need to trigger its initialization. This generates four instructions of the most common scenario is the Java code: using the new keyword to instantiate an object when reading or setting a static field of a class (the final modification, the result has been placed in a constant pool of static compiler except) when the field, as well as calling a static method of class time.
  • When using java.lang.reflect package approach to reflect the class called, if the class is not been initialized, you need to trigger its initialization.
  • When initializing a class, if you find the parent class has not been initialized, you need to trigger initialization of the parent class.
  • When the virtual machine starts, the user needs to specify a main class to be executed (contains main () method of the class), the virtual machine to initialize this master class.
  • When using JDK1.7 support dynamic languages, if a final example of the analysis result java.lang.invoke.MethodHandle REF_getstatic, REF_putstatic, REF_invokeStatic the method handle, and this handle corresponding to the class the method is not initialized, it is necessary to trigger the its initialization.


Use
When completed initialization jvm jvm can execute program code
written off
when the execution finished, jvm will perform recovery mechanisms to destroy class objects

More technical information may concern: gzitcast

Guess you like

Origin www.cnblogs.com/heimaguangzhou/p/11491910.html