We continue with the previous section [JVM Tutorials and Tuning], which parameter types do the JVM have? This chapter introduces how to view JVM runtime parameters. This is important because when we tune JVM parameters, we first need to know what values the system is currently running on and then tune accordingly.

1. – XX: + PrintFlagsInitial initial value (see) 2. – XX: + PrinFlagsFinal (see the final value) 3. – XX: + UnlockExperimentalVMOptions (unlock experimental parameters) 4. – XX: + UnlockDiagnosticVMOptions (unlock diagnostic parameters) 5. – XX: + PrintCommandLineFlags (print command line parameters)

PrinFlagsFinal

Bool attribute name: UseG1GC value: false So you can see that G1GC is not used.

InitialHeapSize := 130023424 indicates the value size of the initial heap.

Note := indicates the default value := modified by the user or JVM

demonstrate

You can see that there are a lot of parameters. Interested partners can try their own.

So which process is the parameter we just saw? The answer is: the value of the process parameter when executing Java -xx :+PrinFlagsFinal -version.

If we wanted to view the value of a JVM parameter at run time, how would we do that? This is jinfo that we’re going to talk about later, but before we do that, let’s take a look at JPS.

jps

JPS is similar to PS in Linux and is also used to view system processes. However, it is specifically used to view Java processes. Let’s briefly demonstrate the use of JPS

How to use it?

For more JPS parameter commands, see here

jinfo

So how do we check the parameter values of a running JVM? So jinfo is fine.

For example, how do we see what the maximum memory value of Tomcat is? So we need to know the command first, and then find the corresponding PID.

In the figure, 23789 is the Tomcat process PID, check the memory size command: MaxHeapSize. You can see that the maximum heap size is 268435456

You can see the parameters that we assigned manually, as well as the default values.

  • Viewing the maximum memory

  • Check the garbage collector

Jstat views JVM statistics

  • Class loading
  • Garbage collection
  • The JIT compiler

Garbage collection is very useful because we can see very clearly how the size of each chunk in the memory structure changes.

The command format

Options: – class, – the compiler – gc – printcompilation

Let’s take a look at the Jstat documentation.

Let’s introduce a few commands.

Class loading

jstat -class 3176 1000 10

The following 1000 indicates every 1000ms, and 10 indicates a total of 10 outputs

Let’s look at how the -class command is described in the documentation.

What do they mean?

  • Loaded: Indicates the number of classes Loaded
  • Bytes: indicates the number of kBs loaded
  • The number of Unloaded
  • Bytes: indicates the number of kBs uninstalled
  • Time: Time spent loading and unloading

Garbage collection

Commands: -gc, -gcutil, -gccause, -gcnew, -gcold

Enter jstat -gc 3176 1000 3

Similarly, the following means that every 1000ms, a total of 3 printings

Let’s also look at the -gc command in the documentation

Let’s summarize the -gc output.

  • S0C, S1C, S0U, and S1U: indicates the total quantity and usage of S0 and S1
  • EC, EU: total amount and usage in Eden
  • OC and OU: total volume and usage of the Old area
  • MC, MU: total Metaspace area and usage
  • CCSC and CCSU: total amount and usage of compressed space
  • YGC, YGCT: YoungGC times and time
  • Number and time of FGC and FGCT: FullGC
  • GCT: Total GC time

The JIT compiler

Commands: -compiler, -printcompilation

Let’s demonstrate JIT compilation.

What does all this mean? Let’s take a look at our documentation.

  • Compiled: Indicates how many compilation tasks are completed
  • Failed: indicates the number of Failed compilation tasks
  • Invalid: indicates an Invalid compilation task
  • Time: indicates the Time taken to execute the compilation task.
  • FailedType: compilation type of the last failed compilation.
  • FailedMethod: Name and method of the class that failed the last compilation.

Small partners can combine with the above demonstration pattern, to understand what is the meaning.

You can understand, the effect in the actual work is not very big.

All the above are introduced with JDK1.8. Here is a brief introduction to this area, and more details will be introduced later. Friends can try to use the command on the computer and observe the print result. Commands for JVM parameters are covered in more detail in the documentation. Interested partners, you can go to check. Portal: docs.oracle.com/javase/8/do…

In the next chapter, we’ll look at the JVM’s memory structure and memory overflow. Interested partners, you can pay attention to ~

recommended

  • Why learn about the JVM Virtual Machine?

  • What are the parameter types for the JVM?

At the end of the article

Github: github.com/CoderMerlin… Gitee: gitee.com/573059382/c… Welcome to follow and star~