JVM Parameter Types and Hands‑On Experiments
This tutorial explains the three main categories of JVM parameters—standard, X, and XX—demonstrates how to view, modify, and verify them using command‑line tools such as java, jps, and jinfo, and provides step‑by‑step hands‑on labs for each type.
The purpose of this lab is to explain the three major JVM parameter types and demonstrate how to view and set them, which is essential knowledge for JVM tuning.
Standard Parameters
-version – get JDK version
-help – get help information
-showversion – display version and help
Experiment 1 – View Standard Parameters
Run the following commands in the console:
java -versionResult shows JDK version 1.8.0_131.
java -helpDisplays the help document.
java -showversionShows both version and help.
X Parameters
X Parameter Overview
-Xint – pure interpretation mode
-Xcomp – compile to native code before execution
-XMixed – mixed mode (both compilation and interpretation)
Experiment 2 – View and Configure X Parameters
Check current mode:
java -versionSwitch to interpretation mode:
java -Xint -versionSwitch to compilation‑only mode:
java -Xcomp -versionXX Parameters
XX Parameter Overview
XX parameters come in two forms:
Boolean type: -XX:+SomeFlag (enable) or -XX:-SomeFlag (disable). Example: -XX:-PrintGCDetails disables GC detail output.
Key‑value type: -XX:Key=Value . Example: -XX:MetaspaceSize=2000000 sets metaspace size.
Experiment 3 – Check If a Parameter Is Enabled
Create a long‑running Java program (demoXXparam.java) and run it, then use:
jps -lFind the process ID, then query the flag:
jinfo -flag PrintGCDetailsThe output -XX:-PrintGCDetails indicates the flag is disabled.
Experiment 4 – Enable a Parameter
Terminate the program, then restart it with the flag enabled:
java -XX:+PrintGCDetails demoXXparamNow jinfo -flag PrintGCDetails shows -XX:+PrintGCDetails , meaning the flag is active.
Experiment 5 – Key‑Value Parameter Value
Check metaspace size:
jinfo -flag MetaspaceSizeSet metaspace to 128 M:
java -XX:MetaspaceSize=128m demoXXparamVerify the new value with the same jinfo command.
Experiment 6 – Set InitialHeapSize and MaxHeapSize
Set initial heap size:
java -XX:InitialHeapSize=200m demoXXparamSet maximum heap size:
java -XX:MaxHeapSize=200m demoXXparamExperiments 7‑10 – List JVM Flags
Print default flags: java -XX:+PrintFlagsInitial -version
Print final flags (including user‑defined): java -XX:+PrintFlagsFinal -version
Print command‑line flags: java -XX:+PrintCommandLineFlags -version
Print all flags of a running process: jinfo -flags
Experiment Summary
The lab covered how to view basic, X, and XX JVM parameters, how to modify them, and how to use jps and jinfo to inspect running Java processes. These skills form the foundation for JVM performance tuning.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.