“This is the third day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Standard parameters non-standard XX command Boolean type Non-Boolean type -xmx-xMS How to view running Yes JVM parameters Jps && Jinfojstat automatic export manual export MAT Analysis Memory overflow Ubuntu IDEA Install jprofiler

#JVM tuning parameters

As we worked further, we gradually found that only the business layer could not meet the requirements. An advanced development prerequisite is JVM performance tuning. Today I’m going to take you on a tour of the JVM.

Standard parameters

Standardized parameters mean that they do not change from JDK version to JDK version. Similar to java-version

The command explain
-help
-server -client
-version -showversion
-cp -classpath

Are not standardized

What is not standardized is that there may be slight changes from version to version.

The command explain
-Xint Explain to perform
-Xcomp Compile native code the first time you use it
-Xmind In mixed mode, the JVM decides whether to compile native code or not

XX command

The de-normalized command above is -x, and the -xx we’ll cover below is also de-normalized. But the commands here are mainly for performance tuning. It is also an unstable command.

Boolean type

Format: -xx :[+-] Indicates whether to enable or disable the name attribute

Example: -xx :+UseConcMarkSweepGC uses the userConc garbage collection mechanism

The Boolean type

Format: -xx := Indicates that the value of name is value

Example: -xx :MarkGCPauseMills = 500 The maximum Gc pause time is 500

-Xmx -Xms

This represents the heap Max and min memory Settings. Although there is only a -x, it belongs to the -xx family of commands

-xms = -xx :InitialHeapSize Initializes the heap size. -xmx = -xx :MaxHeapSize Indicates the maximum heap size

How do I view running JVM parameters

-xx :+PrintFlagsInitail: View some initial values -xx :+PrintFlagsFinal: View the final value – XX: + UnlockExperimentalVMOptions unlock experimental parameters – XX: + UnlockDiagnosticVMOptions unlock diagnostic parameters – XX: + PrintCommandLineFlags print command line parameters

Jps && Jinfo

Similar to Ps on Linux. JPS specifically queries Java process parameters

When we look at the effect of the command above, the generated parameter content is specific to the command. But we are all in the same project in the production environment. Jinfo is to help us see the project parameters in action. Of course, we first need to check the pid of the current process through ps -ef command.

For example, my server now has a Java process whose process ID is 5201314. And at this point I want to see what the maximum size of the heap is and we can do that.

jinfo -flag MaxHeapSize 5201314

[Display effect] : -xx :MaxHeapSize=268594834

Jinfo-flags displays all parameter values

The next step is to check whether to use a garbage collection mechanism + use – Disable

jstat

View JVM statistics, including class loading information, garbage collection information, JIT compilation information

The format is java-options

Options contains the following

The name of the meaning
-class Class loading
-compiler JIT compilation information
-gc Garbage collection mechanism
-gccapacity Heap memory information
-printcompilation

#jmap

Jmap is a tool that can output all the total objects in memory. It is even possible to say that THE HEAP in VM China is output in binary form. Prints a process object.

Automatic export

-XX:+HeapDumpOnOutOfMemoryErro -XX:+HeapDumpPath=./

Manually export