Let's introduce the process of class loading:
We are writing the source file Java, compiled into a class bytecode file via the Javac tool below the JDK bin, and then run through the Java command under the bin to invoke the JVM parsing class file.
When Java is actually running, it relies on bytecode, which is why Java is cross-platform because the JVM is capable of cross-platform, as long as there is a JVM where Java can run.
The process of a JVM loaded in a class file: Load, prepare, parse.
The JVM completes the class loading process through the ClassLoader, specifically
1. Start the class loader first, complete the base class loading lib under Rt.jar (C + +)
2. Through the expansion class loader, complete the extension class under the Ext directory of the extension class (Java writing)
3. Finally, our own class loading process is done through the application loader.
Note: The ClassLoader is completed by a parent-delegation mechanism. (Simply said: A class loaded display in the Application class loader, find the upper level expansion class loader, and then continue to look for the Startup class loader, if the top-level has the right to load, then load, if not found will continue to the next level, the advantage is to prevent others to write the system preset core class, to ensure the security of operation, For example, if we write the same class string, it will break the built-in string class load if we do not adopt a parent-delegate mechanism. )
Example:
Package Com;public class Loaderdemo {/** * @param args */public static void main (string[] args) {System.out.println (Loader Demo.class.getClassLoader (). GetClass (). GetName ()); System.out.println (LoaderDemo.class.getClassLoader (). GetParent (). GetClass (). GetName ()); System.out.println (LoaderDemo.class.getClassLoader (). GetParent (). GetParent (). GetClass (). GetName ());}}
I get the current class loader and their parent class loader through the code;
We can see clearly, the current class loader is Appclassloader, the parent class loader is ext, the top-level because it is written by bootclassloader,c++ we do not get, it throws an exception.
------------------------------------------------------------------------------------------------------
The above is the process of the class record, then how does our memory differ?
Java Memory Mode model:
Java memory is basically a heap and non-heap, subdivision can be divided into 5 parts. When our JVM loads the class bytecode through the ClassLoader into memory
JAVA Stack stack: the base data type and the reference address of the object.
Heap Heap: instantiated objects (new) and array objects.
Method Area: Meta-data information, constants, and so on.
Native method Stack && program counter Register: a stack frame generated at the time of thread creation or method generation.
Heap: Subdivided into Cenozoic, Laosheng generation and persistent generations.
New generation: The object of storage.
Laosheng Generation: The new generation of long-term non-recycled objects, that is, the life cycle of the object.
Durable generation: The region with the longest life cycle, which is rarely recycled by GC. (Store class and meta information.) )
The so-called garbage collection mechanism: In fact, the object is collected in the heap space, the JVM through a graph to determine whether the object has the condition of recycling. When an object is not referenced by any object, the JVM's GC is ready to be recycled. Recycling, priority to recover the JVM in the new generation of objects, and then the family is Laosheng generation, durable generation basically do not recycle.
GC algorithm: Generational processing. Process above
FULLGC and GC Differences:
GC: Typically only the Cenozoic region objects are recycled.
FULLGC: Recovery of the Cenozoic and Laosheng generation areas. System.GC is actually FULLGC, should be less called, try not to use, by the JVM to complete the best. Even though the SYSTEM.GC may not be recovered at once, the JVM has a characteristic algorithm to perform the computation.
"Javase" Java memory mode and class loading mechanism, GC simple principle