This article is original, according to "in-depth understanding Java Virtual Machine" and some of their own understanding of the collation, simple and look at other people's blog feel less than their own a little bit of painting and record to impress .
Java Memory Model:
An algorithm that determines whether an object is dead (can be recycled)
Description of Method Area (permanent generation) Recycling:
the garbage collection of a permanent generation consists of two main parts: discarded constants and useless classes. Deprecated constants: No object references this constant. Useless class:1, all instances of the class have been reclaimed (no instances of the class exist in the heap). 2. The ClassLoader that loaded the class have been recycled. 3, the class object corresponding to classes do not have any place to quote, can not be anywhere through reflection to access the method of the class
Algorithm for garbage collection: 1, tag-purge algorithm
Contains 2 stages of marking and purging , is the most basic algorithm . Tags are tokens of objects that can already be recycled, and are clear after the tag is complete, and this algorithm is inefficient and produces memory fragmentation . When a program needs to allocate a large contiguous amount of memory in a later run, it may trigger a garbage collection in advance because of a memory fragmentation problem.
The process is as follows:
2. Replication algorithm (one of the algorithms used in the Cenozoic)
In order to solve the efficiency problem of the mark-clear algorithm, the memory is divided into chunks, after the object of an area is marked alive, the surviving object is copied to another piece, and then the previous block is cleared.
In the Cenozoic, the object survival period is very short, and 98% of the object is to die, so in the memory of the partition does not need 1:1 to divide, thehotspot virtual machine By default according to eden-80%, two survivor each 10% divided (8:1), Eden and a piece of survivor space are used to store the new generation of objects, and a piece to replicate the garbage collection of Eden and another survivor of the surviving objects, and then once cleared calls to Eden and the Survivor memory, The next garbage collection, these 2 pieces of Survivor function Exchange. When a survivor is not enough to fit the surviving object, it will enter into the old age by assigning a guarantee mechanism (borrowing memory) to the old age.
The logic of normal objects entering the old age from the Cenozoic:
When a new generation of objects is not recycled after a round of garbage collection, an identifier for this object will increment by +1, and when the object's identity reaches a certain threshold, it will be placed in the old age.
Of the replication algorithm:
3. Marking-Sorting algorithm
Compared to the tag-cleanup algorithm, this algorithm solves the memory fragmentation problem of the tag-cleanup algorithm, which is collated after the recyclable objects have been cleaned up.
Algorithm:
4, generational collection algorithm
The current commercial virtual machines are using this algorithm, in fact, this is an algorithm rather than the previous 3 algorithms in the new generation and the old era of the application of a different algorithm of a strategy, the new generation of the use of replication algorithm, the old age using "mark-clear" or "marker-collation" algorithm.
Garbage collector (Specific implementation of garbage collection algorithm)
The collector for HotSpot version 1.6 Update22 is shown below:
The upper part is the new generation of garbage collector, the following part is the old age of garbage collector, the middle of the connection means that the 2 of the collector can be used together.
1
Java memory model and garbage collection self-summary