First, the run-time data area
Program Counter
A bytecode program execution to address records.
java virtual machine stack
Java method when executed, create a stack frame, the local variable table stored, the operand stack references the constant pool information.
When too deep thread request exceeds the maximum stack depth, i.e., a method of nested hierarchical method, throws StackOverflowError.
When the stack for dynamic expansion is not enough space, throws OutofMemoryError.
Native method stacks
Stack method in other languages
stack
The main area of garbage collection.
Divided into two: the old and the new generation's
-Xms: starting size
-Xmx: maximum size
Methods district
Used to store class information has been loaded, constants, static variables after time compiler to compile code.
From JDK1.8 start, remove the permanent generation, and methods yuan into space area, located in local memory, not virtual machine memory.
Runtime constant pool
Region part of the method, Class file constant pool after the class is loaded into this area.
Second, refuse collection
Mainly for garbage collection heap and method area.
Several other areas because as the thread generation and destruction, no garbage collection.
What is garbage?
1. The reference count
Reference count is 0 can be recovered.
Disadvantage, the object can not be recycled circular reference.
2. reachability analysis
With GC Roots as a starting point, unreachable objects can be recycled.
When the recovery?
Reference Type 4: strong references, soft, weak, reference phantom reference.
How recycling? ---- garbage collection algorithm
Clear labeling, finishing mark, copy, generational collection ( the new generation: copy algorithm; old year: Clear mark or tags to organize )
Garbage collection algorithms would do a balance between high response and high throughput.
Serial and parallel GC threads and threads for the user can simultaneously speaking.
Single-threaded multi-threaded, it is the use of several threads for GC thread.
Under Serial ---- serial, single-threaded, client scenario, the default new generation of collectors
Under ParNew ---- serial, multi-threaded, server scenario, the default new generation of collectors
Only these two can be used in conjunction with CMS.
Parallel Scavenge ---- certain priority collector for the new generation
Serial Old ---- Serial old's version
ParNew Old ---- ParNew old's version
CMS ---- Clear labeling algorithm, may produce floating garbage
G1 ---- recovered together with the new generation and the old era. Introduction region, maintains a priority list, according to collect events permit, priority recovery value of the region's largest
Third, the allocation policy
Minor GC and Full GC
minorGC recovery Cenozoic, FullGC old and the new generation's recovery
Memory allocation strategy:
Object limited distribution in Eden: Eden area allocated to the object, if space is not enough to initiate Mnor GC, the object will be put Survivor region, age +1
Large objects directly into the old year: large object will be directly assigned to the old era, the configuration parameters: -XX: PretenureSizeThreshold
Long-term survival of the object into the old year: when the older Survivor region increased to a certain age, the object is moved to the old era. Configuration parameters: -XX: MaxTensuringThreshold
Age determination of dynamic objects: Survivor object when the object of the same age is more than half of the space, which is larger than the object directly into the old age years
Space allocation guarantees:
Before MinorGC, jvm will first check whether old's maximum available contiguous space larger than the new generation of all objects?
If so, then MinorGC security.
If not, whether to allow a security failure? (HandlePromotionFailure value)
If allowed, the old and the maximum continuously available space is larger than the previous year promoted to the average size of the object's old, is performed minorGC
If not, or is less than the space, is performed FullGC
Full GC trigger conditions:
System.gc (), inadequate years old space, space allocation guarantees failure before JDK1.7 insufficient space on behalf of the permanent version, CMS floating garbage old's lead to lack of space
Fourth, the class loading mechanism
Class only loaded when first used
Life cycle: loading, validation, preparation, parsing, initialization, use, unloading
Class loader:
Start class loader, the extension class loader, the application class loader
Only when the father loader fails to load, the loader will load levels.