Management of the Java Virtual Machine memory area heap (heap)

Source: Internet
Author: User

In the previous section, the memory overflow location in Java and the resolution of the Java Virtual machine stack and the method area of memory anomalies and processing methods are resolved, because the Java Virtual Machine management of the heap is very complex, and the Java Virtual machine in the most important memory area, Therefore, a separate section is presented for analysis.


First to explain the survival of the object??

The concept of what kind of object is a dead object that needs to be recycled by the garbage collector is critical because it affects which object the garbage collector recycles. Objects that can be accessed from gcroot are surviving objects, and objects other than those that are already dead.

GCRoot: Includes four kinds of 1) reference pointer to object 2 stored in Java Virtual machine stack) Reference object in local method stack 3) The constant reference object in the method area (4) The object referenced by the static class property in the method area


GC garbage collector

The garbage collector uses a tag-purge-defragment algorithm to reclaim memory.

The Minor GC and the full Gc,minor GC are the process of recovering from the young generation, which is the process of reclaiming the entire heap and the method area.

Generational collection, in Java virtual machines for the memory area of the heap is reclassified, young Generation (younger generation) and old Generation (older generation)

The younger generation is used to store objects of age that do not reach-xx:pretenuresizethreshold, and older generations are used to store objects older than-xx:pretenuresizethreshold.


Then for the younger generation subdivision, Eden space, from space, tospace three memory areas, the size of the three memory area is defined by-xx:surivorradio. When the minor GC is carried out, the surviving objects in Eden Space and from space are copied to tospace and the older objects are copied to the old generation, and when the old generation is out of space, the full GC is started.


(The concept above is simply described, and it is much more complicated in the actual operation of the JVM, but presumably the principle is this).

Once you understand the basic concepts above, it's easier to look at the garbage collector below. The total garbage collector is divided into seven types: theSerial collector and the Serial old collector, theParallel scavenge collector and Parallelold,parnew collector , CMS collector,G1 (garbage first) collector .


1. TheSerial collector and the Serial old collector, respectively, are used to collect the memory areas of the younger generation and older generations, Serial is a single-threaded garbage collector, All Java threads need to be paused during the run.


2.theparnew collector is actually a multithreaded version of the serial collector (needles for younger generations).


3.Parallel scavenge collector and Parallel old: is a parallel multi-threaded garbage processor, you can specify the maximum garbage collection pause time-xx: Maxgcpausemillis and set the throughput size-xx:gctimeradio.


4.CMS collector (Concurrent Mark Sweep): is a garbage collector for multi-threaded concurrent executions of older generations. Collector to obtain the shortest recovery pause time (mainly for b/S schema on the server)


5.G1 (garbage first) collector : Is the latest garbage collector, suitable for (jdk1.6_update14) The JVM above;G1 divides the entire Java heap (including the Cenozoic and the old) into separate, fixed-sized areas, and tracks the amount of garbage accumulation in these areas, Maintain a spam priority list in the background, prioritizing the most garbage-collected areas each time it is allowed to collect.


In summary, the type of service you want to get maximum throughput is a combination of the Parallel scavenge collector and the Parallel old collector. The best way to implement a real-time system is with the CMS collector (Concurrent Mark Sweep). However, the client is relatively small, or the use of serial better.



Management of the Java Virtual Machine memory area heap (heap)

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.