VisualVM is a free, integrated visualization tool with multiple JDK command-line tools that provides you with powerful analytics and performance analysis and tuning of your Java applications. These features include generating and analyzing massive amounts of data, tracking memory leaks, monitoring the garbage collector, performing memory and CPU analysis, and it also supports browsing and manipulation on MBeans.
In memory analysis, the biggest benefit of Java VISUALVM is that you can analyze GC (gabage Collection) trends and memory consumption details by installing a visual GC plug-in.
A Visual GC (monitor garbage collector)
Java VisualVM Default does not install the Visual GC plug-in, requires manual installation ,the JDK installation directory of the bin mesh double-click jvisualvm.exe, you can open the Java VisualVM, click the menu bar tools, plug-in installation visual GC
650) this.width=650; "title=" capture. PNG "alt=" wkiom1vueqiyixcuaamngjdlluu385.jpg "src=" http://s3.51cto.com/wyfs02/M00/6C/E1/ Wkiom1vueqiyixcuaamngjdlluu385.jpg "/>
Restart Java visualvm,visual GC interface automatically opens to see the generation of heap memory in the JVM after installation is complete
650) this.width=650; "title=" capture. PNG "alt=" wkiom1vufh3qodwoaar5bowpusq180.jpg "src=" http://s3.51cto.com/wyfs02/M00/6C/E1/ Wkiom1vufh3qodwoaar5bowpusq180.jpg "/>
After the monitored program has been running for some time, the visual GC displays the following
650) this.width=650; "title=" capture. PNG "alt=" wkiom1vuih3zwsspaaxs4jukdgs487.jpg "src=" http://s3.51cto.com/wyfs02/M02/6C/E2/ Wkiom1vuih3zwsspaaxs4jukdgs487.jpg "/>
To understand the diagram above, some basic concepts of the Java Virtual machine must be understood:
Heap : JVM-managed memory called Heap
Generational: According to the life cycle length of the object, the heap is divided into 3 generations:Young,old and permanent, according to the characteristics of different generations to adopt different collection algorithms, weaknesses are also.
Young (younger generation)
The young generation is divided into three districts. One Eden area, two survivor districts. Most objects are generated in the Eden area. When the Eden Zone is full, the surviving objects will be copied to the Survivor area (one of two), and when the survivor area is full, the surviving objects of this area will be copied to another survivor area, when the survivor is full, Objects that are copied from the first survivor area and that are still alive will be duplicated in the old Age zone (tenured). It is important to note that the two districts of survivor are symmetrical and have no relationship, so the same district may have objects copied from Eden, and objects copied from the previous survivor, and copied to the old quarter only from the first survivor. Moreover, there is always an empty survivor area.
Tenured (old generation)
Older generations store objects that survive from younger generations. In general, older generations are storing long-term objects.
Perm (persistent generation)
Used to store static files, now Java classes, methods, and so on. The persistence generation has no significant impact on garbage collection, but some applications may dynamically generate or invoke some classes, such as Hibernate, at which point a large, persistent generation space is required to store the new class in these runs. The persistent generation size is set by-xx:maxpermsize=.
Basic concepts of GC
GC is divided into full GC and minor GC, which will cause GC when each chunk is filled.
Scavenge GC
In general, when a new object is generated and the Eden application space fails, the scavenge GC is triggered, the heap Eden Zone is GC, the non-surviving objects are cleared, and the surviving objects are moved to the survivor area. Then tidy up the two districts of survivor.
Full GC
Organize the entire heap, including young, tenured and perm. The full GC is slower than the scavenge GC, so the full GC should be minimized as much as possible. The full GC may be caused by the following reasons:
memory overflow out of memory, refers to the program in the application of the RAM, there is not enough memory space for its use, there is an out-of-memory; for example, an integer is applied, but a long can be stored to save it.
memory leak memories leak, refers to the program after the application of memory, can not release the requested memory space, a memory leak damage may be ignored, but the memory leak accumulation of serious consequences, no matter how much memory, sooner or later will be occupied. In fact, it is not recycled after the memory space has been used.
Other features of the two Java VISUALVM
1. Monitoring interface (CPU, class, heap, thread)
650) this.width=650; "title=" capture. PNG "alt=" wkiol1vuhwezuqlhaaptvdlu7j8689.jpg "src=" http://s3.51cto.com/wyfs02/M01/6C/DD/ Wkiol1vuhwezuqlhaaptvdlu7j8689.jpg "/>
2. Threading Interface
650) this.width=650; "title=" capture. PNG "alt=" wkiom1vuhl7zciihaapgdcktjf8605.jpg "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/ Wkiom1vuhl7zciihaapgdcktjf8605.jpg "/>
3.Profile Interface (profiling)
Click the CPU button to perform the CPU analysis view method
650) this.width=650; "title=" capture. PNG "alt=" wkiol1vuimhx3i-aaauzhlsza2c463.jpg "src=" http://s3.51cto.com/wyfs02/M00/6C/DD/ Wkiol1vuimhx3i-aaauzhlsza2c463.jpg "/>
Click the memory button to perform a memory analysis view class
650) this.width=650; "title=" capture. PNG "alt=" wkiol1vuimndkaqdaapq9qzatvg045.jpg "src=" http://s3.51cto.com/wyfs02/M01/6C/DD/ Wkiol1vuimndkaqdaapq9qzatvg045.jpg "/>
4. Heap dump and thread dump operations
dump file is the memory image of the process, you can save the execution state of the program through the debugger to the dump file, heap dump dump file content as shown
650) this.width=650; "title=" capture. PNG "alt=" wkiol1vujjeyw26xaaqawgdndus206.jpg "src=" http://s3.51cto.com/wyfs02/M02/6C/DD/ Wkiol1vujjeyw26xaaqawgdndus206.jpg "/>
This article is from the "dream belongs to the brave-Skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1651384
Java program Profiling Tools Java VisualVM (Visual GC)-A must-have tool for programmers