In the previous section, the memory overflow location in Java and the solution for 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 basic memory area, Therefore, a separate section is presented for analysis.
First to explain the survival of the object??
What objects are already dead objects that need to be recycled by the garbage collector. This concept is crucial. Because it affects which object the garbage collector recycles. The object that can be visited from gcroot is the surviving object, and the object outside is the dead object.
GCRoot: Contains four kinds of 1) stored in the Java Virtual Machine stack reference pointer to object 2) in the local method stack reference point to the object 3) in the method area of the constant reference object 4) in the method area of the static Class property refers to the object
GC garbage collector
The garbage collector uses the tag-purge-defragment algorithm to reclaim memory.
Minor GC and full GC. Minor GC is the process of recycling young generations. The full GC is the process of reclaiming the entire heap and the method area.
Collection of generations. In a Java virtual machine, 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 performed, the surviving objects in Eden Space and from space are copied to Tospace, and the objects older than the spring festival are copied to the old generation. When the old generation space is insufficient, start the full GC.
(The concept is simply a descriptive narrative that is much more complex in the actual implementation of the JVM, but presumably the principle is this).
Once you understand the basic concepts above, it's easier to look at the following garbage collector. The total garbage collector is divided into seven types: theSerial collector and the Serial old collector. Parallel Scavenge Collectors and Parallelold,parnew collector , CMS collector,G1 (garbage first) collector .
1.Serial collector and Serial old collector. Used to collect the memory areas of the younger generation and the old age, serial is a single-threaded garbage collector. All Java threads need to be paused during execution.
2.theparnew collector is actually the multithreaded version number of the serial collector (pin for younger generations).
3.Parallel scavenge collector and Parallel old: is a parallel multi-threaded garbage processor, 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 multithreaded concurrency running in the old age. 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 junk priority list in the background, prioritizing the most garbage-collected areas each time you agree to collect them.
In summary, the type of service 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 to use a CMS collector (Concurrent Mark Sweep).
Just because the client is smaller, it is better to use serial.
Management of the Java Virtual Machine memory area heap (heap)