Management of memory region heap of Java Virtual Machine

Source: Internet
Author: User

Management of memory region heap of Java Virtual Machine

In the previous section, Java locates memory overflow and resolves memory exceptions and handling methods in the Java Virtual Machine stack and method area, because the management of heap by Java virtual machine is very complicated and the most important memory area of Java virtual machine, a separate section is proposed for analysis.


Why does the object survive ??

The concept of an object that is dead requires the Garbage Collector to recycle is crucial because it affects which object the Garbage Collector recycles. Objects that can be accessed from GCRoot are surviving objects, and other objects are dead objects.

GCRoot: four types of objects: (1) Objects pointed to by reference pointers stored in the Java Virtual Machine stack (2) Objects pointed to by reference in the local method stack (3) constant reference objects in the Method Area (4) objects referenced by static class attributes in the Method Area


GC Garbage Collector

The garbage collector uses the Mark-clear-Sort Algorithm to recycle memory.

Minor GC and Full GC, Minor GC are the process of recycling the young generation, and Full GC is the process of recycling the whole heap and the method area.

Generational collection: the memory areas of the heap are further divided into: Young Generation and Old Generation)

The young generation is used to store objects whose ages do not reach-XX: PretenureSizeThreshold. The old generation is used to store objects whose ages exceed-XX: PretenureSizeThreshold.


Further subdivided for the young generation, the memory areas Eden Space, From Space, and ToSpace are defined by-XX: SurivorRadio. During Minor GC, the surviving objects in Eden Space and From Space are copied to ToSpace, and the objects older than age are copied to the old generation, when the space of the old generation is insufficient, start Full GC.


(The above concept is just a simple description. It is much more complicated in the actual running process of JVM, but the general principle is like this ).

After learning about the above basic concepts, it is easier to look at the following garbage collector. There are seven types of Garbage collectors: Serial collector and Serial Old collector, Parallel Scavenge collector and Parallel Old, ParNew collector, CMS collector, and G1 (Garbage First) Collector.


1.The Serial collector and Serial Old collector are used to collect memory areas of the young generation and the Old generation respectively. Serial is a single-threaded Garbage Collector and all Java threads need to be suspended during running.


2. The ParNew collector is actually a multi-threaded version of the Serial collector (for the young generation ).


3. Parallel Scavenge collector and Parallel Old: a Parallel multi-threaded garbage processor that specifies the maximum garbage collection pause time-XX: MaxGCPauseMillis and sets the throughput size-XX: GCTimeRadio.


4. CMS collector (Concurrent Mark Sweep): A Garbage Collector for Concurrent execution of multiple threads in the old age. Collectors that target the shortest recovery pause time (mainly used on servers in B/S architecture)


5. g1 (Garbage First) COLLECTOR: it is the latest Garbage Collector and is suitable for JVM (JDK 1.6 _ update14) and later. G1 will heap the entire Java (including the new generation and old generation) it is divided into multiple independent regions with a fixed size and tracks the degree of garbage accumulation in these areas. A Garbage priority list is maintained in the background, each time based on the time allowed for collection, areas with the highest garbage collection priority.


In short, to obtain the maximum throughput, useParallel Scavenge collector and Parallel OldCollector combination. It is best to use real-time systemsCMS collector (Concurrent Mark Sweep ). However, because the client is relatively small, it is better to use Serial.



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.