Java JVM Garbage Collection

Source: Internet
Author: User

One, garbage collection acts on the "heap" and "Non-heap (method area)" Two threads share the part.
1. Heap:
The heap's main storage is "generated objects" and "open arrays".
The interview may ask if all the objects are present on the heap. The answer is no, the current development of virtual machine optimization technology, where the escape analysis (if the object generated in a method is not used by other methods or threads, it is not escaped), if the object does not escape, then the object will be allocated to the stack space. In addition, some people on the internet listed Tlab, but Tlab is on the Eden.
  
For example, we analyze the composition of the next pair, the heap is divided into "young" and "old" two parts, among which young is divided into one "Eden" and Two "Survivor".
1) Most of the "objects" will be assigned to Eden, and if Eden space is not enough, the minor GC will be launched, and the surviving objects in Eden and one of the survivor will survive and not be promoted to old, and copied to another survivor.
If there is not enough space in the survivor, the remaining objects will be copied to the old zone. (limitations of which, see 4))
Note: At any time, only one of the two Survivor is used, and the default is Eden:survivor=8:1.
2) Large objects (which require very long contiguous space, such as long strings, arrays) are directly assigned to the old area.
3) in 1), after Minor GC, the original object in survivor if it is still there, then his "age" will be +1, if the Age value >15 (set by the-xx:maxtenuringthreshold), will be promoted to the old area.
Or, in Survivor, objects of the same age occupy more than half of their space, at which point older than the former will be promoted directly to the old area.
4) The promotion or copy to the old area is the premise that old has enough contiguous space to accommodate the size of all objects in young, and if not enough, the full GC will be performed in old.

2, non-heap (method area)
The main actions for method area recycling are constant pool cleanup and type unloading
1) Constant Pool
Include: constant, symbol reference for "class (interface), method, character"
The above, if not referenced, can be recycled.
2) Type Uninstall
(1) No more instances exist
(2) The corresponding ClassLoader is unloaded
(3) The Java.lang.Class object is no longer referenced, or there is no reflection operation.
After that, the "can" is recycled.

Second, with the review of the virtual runtime data
1. Program counter
2. Java Virtual machine stack (thread private, method heap out is destroyed)
Each method has a real stack, which includes "local variable table", "Operand stack", "Dynamic Link", "Method exit" and so on.
The table of local variables includes:
1) basic data type, int long, etc.
2) References to Objects
3) ReturnAddress Type
3. The local method stack (thread private) is used by the native method
4, Heap (will be garbage collected)
5, non-heap (will be garbage collected)

Forest Wood
Blog Address: http://blog.csdn.net/wolinxuebin/
Reference: "In-depth understanding of Java Virtual machines" Zhou Zhiming

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java JVM Garbage Collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.