Java Programmer Develop Program JVM Learning notes (3)-JVM performance monitoring

Source: Internet
Author: User

In this paper, the performance monitoring method of JVM is collated.
Continuous update ...

1. JDK command-line tools1.1. JPS: Virtual machine Process Health tool
    • The JVM process Status Tool, which displays all the hotspot virtual machine processes within the system, is used to view the programs currently running in the JVM, including the name of the virtual machine execution main class and the process ID.
1.2. Jstat: Virtual machine Statistics monitoring Tool
    • The JVM Statistics monitoring Tool collects operational data for all aspects of the hotspot virtual machine, including class loading, memory, garbage Collection, JIT compilation, and so on.
1.3. Jinfo:java Configuration Information Tool
    • Configuration info for Java, which displays the virtual machine config information. Virtual machine parameters can be viewed and adjusted in real time, i.e. VM parameters.
1.4. Jmap:java Memory Imaging Tool
    • Memory Map for Java, generating a snapshot of the virtual machine's RAM (heapdump file), viewing the objects of the finalizer thread executing the Finalize method, displaying the details of the heap (such as the collector, parameter configuration, generational status, etc.), Displays statistics about objects in the heap (number of objects, number of classes, total capacity, etc.), etc., but only storage snapshots can run under Windows. In addition, there are other ways to generate a dump file in the event of an Oom exception by using the VM parameter-xx:+heapdumponoutofmemoryerror.
1.5. Jhat: Virtual machine heap Storage Snapshot analysis tool

The JVM Heap analysis Tool, used with Jmap to parse the Heapdump file, establishes a http/html server that allows the user to view the results of the analysis on the browser.

1.6. Jstack:java Stack Trace Tool

Stack Trace for Java, which displays a thread snapshot of the current moment of the virtual machine, also known as a threaddump or Javacore file. That is, the collection of method stacks that each thread is executing, which is commonly used to detect the cause of a thread's long pause, such as the reason for long pauses in threads, deadlocks, dead loops, requests for external resource waits, and so on.

2. JDK Visualization Tools2.1. JConsole
    • Located in the Jdk/bin directory, you can automatically search for all virtual machine processes that are running on your computer after startup, and then you can select a process to monitor.
    • Here is a producer consumer code for testing, that is, pctest, a total of 3 producers and 3 consumers, each production node has a byte[1024] used to account for memory. After you connect, you can see an overview, and then each page can see specific information about it:

    • Configuration adjustments can be made to the VM parameters by looking at the allocation of each area of the memory situation

    • Thread page, you can also see the operation of each of the threads, such as running state, waiting for the lock, hold the lock and so on, you can also detect the deadlock condition

2.2. VisualVM
    • Located in the Jdk/bin directory, you can automatically search for all virtual machine processes that are running on your computer after startup, and then you can select a process to monitor.
    • VISUALVM features and Jconsole are not much worse, but it provides a better-looking interface, which is the case at the start of each process.

    • VISUALVM provides an overview of memory usage, as well as Jconsole, and an overview of threading conditions


    • There are other features that are not covered here.

3. Other3.1 Eclipse Memory Analyzer
    • The Eclipse Memory Analyzer provides more detailed analysis than the previous two, including the case of the reference chain, the various threads, the memory occupied by the object, and so on.
    • You first need to install the Eclipse Memory Analyzer plugin, which is installed through the install from site of Eclipse:

    • or using the producer Consumer program as a sample, configure the following JVM parameters:

      -xmx10m-xms10m-xx:+heapdumponoutofmemoryerror

    • In order to make memory overflow more quickly, the memory of each node is set to 1M size, and an oom error occurs soon after the program runs.

    • As you can see from the above, a heap storage snapshot is generated when the memory overflows

      Dumping heap to java_pid8056.hprof ...

    • Then, in the project directory, you can see the heap storage snapshot

    • Direct double-click to open, you can choose the default to let the plug-in suspicious memory leakage analysis, according to the size of the heap, in a certain time, the results will be as follows:

    • This is the case with the memory used by each thread in the heap, under which there is also the result of the plugin analysis:

    • With details information, you can view specific information

    • The shallow heap represents the space occupied by the object itself, and the retained heap represents how much space can be recovered if the object is given to the GC.

4. References

[1] "in-depth understanding Java Virtual Machine" Second Edition, Zhou Zhiming

Java Programmer Develop Program JVM Learning notes (3)-JVM performance monitoring

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.