Memory Partitioning
1. Java memory is mainly divided into methods stack, method area, heap.
2. The memory on the method stack is automatically released;
3. The class's meta-information, static variables, and constants are mainly loaded on the method area. The area is also known as the persistent generation (Perm Gen), the default is the minimum 16M, the maximum 64M. Configuration parameter-xx:permsize=16m-xx:maxpermsize=64m;
4. The heap is managed on a generational basis and is mainly divided into the Cenozoic (New gen) and the older generation (old Gen or Tenuring Gen).
1) The Cenozoic is divided into Eden space,s0,s1 three block area.
2) Eden is the birthplace of the new object (the original object was Adam and Eve's birth?). )。
3) S0 and S1 are 2 blocks in the same size area, together, also known as Survivor Space, the 2 blocks are the distributing center of Living objects for garbage collection, and each recycle is always moved from one region to another, and the next time it is moved from another region to this area.
4) Heap Size default value: Minimum 1/64 physical memory, Max 1/4 physical memory, 32-bit machine up to 2G
5) configuration parameters:-xms64m (min)-xmx64m (max)-xmn16m (Cenozoic size)
Gc
1. GC is divided into the new generation GC and the old generation GC, the new generation GC is also called minor GC. When the old generation GC is triggered, the new generation GC is also triggered, which is called full GC;
1. The GC algorithm mainly includes replication (Copying), Mark-Erase (mark-sweep), marker-Compression (mark-compact);
2. The algorithm used by the Minor GC is replication (Copying), and its main three ways are:
1) Serial GC (Serial GC) suspend application, single threaded mode, configuration parameter-XX:+USERSERIALGC
2) Parallel Recovery GC (Parallel scavenge) suspend application, multi-threaded mode, configuration method-XX:USEPARALLELGC
3) Parallel GC (PARNEW) with the old generation CMS GC, CMS GC is with the application concurrent, multi-threaded, configuration mode-XX:USEPARNEWGC
3. The old generation GC algorithm mainly uses the flag-clear (mark-sweep), flag-Compression (MARK-COMPACT), its main three ways are:
1) Serial GC suspended application, single-threaded mode, the algorithm is mark-sweep-compact, configuration parameters-XX:+USERSERIALGC;
2) Parallel GC suspend application, multi-threaded way, algorithm for mark-compact, configuration mode-XX:USEPARALLELGC;
3) Concurrent CMS (Concurrent mark-sweep GC) and application concurrent multithreading, the algorithm is mark-sweep, configuration parameters-XX:+USECONCMARKSWEEPGC;
View Tools
0. JPS viewing Java process information
1.JMap command JMAP-HEAP [PID], Statistics Java memory usage, JDK comes with;
2.JStat command Jstat-gcutil [PID] 5s, not 5 seconds output Java memory usage and GC number and time, the JDK comes with
3.jstack command jstack-l PID, output process stack information, JDK comes with
Reference: https://my.oschina.net/feichexia/blog/196575
http://blog.csdn.net/imxiangzi/article/details/47123849
Java Memory management and GC learning "GC"