Introduction to the

We all use Java performance management tools more or less when developing Java projects. Sometimes it’s to improve application performance, sometimes it’s to find bugs in Java applications.

Profile Tool is a performance monitoring and debugging tool, which is called profile Tool in English. When you mention this tool, you may think of some very famous paid tools such as JProfile. In fact, the JDK also comes with some performance debugging tools, such as JMC and Jconsole.

JMC is now separate from the JDK version. For details, see my previous article: New features in JDK 14 :JFR,JMC, and JFR Event Streams. Today we’ll focus on using Jconsole.

More highlights:

  • Blockchain from getting started to Giving up series tutorials – with ongoing updates covering cryptography, Hyperledger, Ethereum,Libra, Bitcoin and more
  • Spring Boot 2.X Series tutorials: Learn Spring Boot from Scratch in seven days – continuous updates
  • Spring 5.X Series tutorials: Everything you can think of in Spring5 – constantly updated
  • Java Programmer from Handyman to Expert to God (2020 edition) – Ongoing updates with detailed articles and tutorials

For more, visit www.flydean.com

JConsole

JConsole is a built-in JDK management tool. In the JAVA_HOME/bin directory, run the JConsole command to enable JConsole.

JConsole has two ways of connecting, one to local processes and one to remote programs.

Local connections do not require a password, just select the appropriate JVM program. The premise of local connection is that the user of JConsole must be the same as the user of the Java program, otherwise the JVM cannot be manipulated.

The remote connection is through the JMX protocol, JMX stands for Java Management Extention, now you do the Web may not be very clear about this protocol, if it is a client program, should be exposed to more. To put it simply, JMX is for remote administration. The program exposes the beans to be managed and then connects them over the JMX protocol.

All right, let’s hook up one of our own programs and try it out.

An overview of

JConsole is divided into six sections, overview, memory, threads, classes, VMS, and MBeans.

First take a look at the overview:

The overview shows the heap memory usage, threads, classes, and CPU usage.

memory

We use JDK14 to start the program, let’s look at its memory:

From the figure above, you can see that JConsole can be used to monitor heap memory, some non-heap memory, and further, some items in the memory pool.

Eden, Old, and Survivor Spaces in the G1 garbage collector are familiar.

Young Gen is divided into 1 Eden Space and 2 Suvivor Space. When the object is first created, it is placed in Eden Space. Eden Space and a Suvivor Space are scanned for garbage collection. If an object in Eden Space is still valid during garbage collection, it will be copied to another Suvivor Space.

In this way, the objects that are still valid will be put into Old Gen after multiple scans, indicating that their life cycle is relatively long and garbage collection time can be reduced.

Prior to JDK8, little-changing information such as class definitions, bytecodes, and constants was placed in persistent Perm Gen. However, after JDK8, Perm Gen has been cancelled and is now called Metaspace. Metaspace is not in the Java VIRTUAL machine; it uses local memory. Metaspace can be controlled by -xx :MaxMetaspaceSize.

The Code Cache is used by the JVM to store native Code in the Heap form, so it is called Code Heap. Code Heap is divided into three parts, non-method, Profiled, and non-profiled.

The non-method section contains non-method code, such as compiler buffers and bytecode interpreters. This code is permanently stored in the code cache. The size of the code heap is fixed. Non-methods are controlled using -xx :NonMethodCodeHeapSize.

Profiled means that the Profiled methods are slightly optimized with a short life cycle. Profiled uses -xx :ProfiledCodeHeapSize to control.

Non-profiled methods are stored in optimized, non-profiled methods, and their lifetime is long. Non – profiled using – XX: NonProfiledCodeHeapSize to control.

Finally, a Compressed Class Space, and it is – XX: + UseCompressedOops, – XX: + UseCompressedClassesPointers related. Is actually a compression of a pointer that can use 32bits to represent the previous 64bits pointer.

thread

Threads lists the threads in which the program is currently running, and if you click on the thread information you can also see the stack trace and thread status statistics in the thread, which is very useful.

class

Class is very simple, showing the number of classes loaded.

The VM information

VM Information Displays VM parameters.

MBean

Finally, mBeans expose beans in the JVM that we can view information about or call methods in.

Take JFR as an example, we can call startRecording, stopRecording and other methods of JFR.

conclusion

JConsole is a simple but useful profile tool that you can use to think about performance and efficiency in your code.

Author: Flydean program stuff

Link to this article: www.flydean.com/jdk14-jvm-j…

Source: Flydean’s blog

Welcome to pay attention to my public number: procedures those things, more wonderful waiting for you!