Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How do you see the effective value of every JVM flag, both for a given command line and for a JVM that is already running?

For a command line, java -XX:+PrintFlagsFinal -version (with the same options and environment) prints every flag and the value the JVM finally chose. For a running JVM, jcmd <pid> VM.flags shows the flags that differ from the defaults, jcmd <pid> VM.flags -all shows all of them, and jcmd <pid> VM.command_line shows the arguments it was started with. Diagnostic and experimental flags only appear or work after -XX:+UnlockDiagnosticVMOptions or -XX:+UnlockExperimentalVMOptions, and the JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS environment variables can add flags we never see in the start script.

Why this question is asked

When a JVM behaves unexpectedly, the first question is what it is actually running with. The value written in a deployment file is not always the value in effect: ergonomics picks defaults from the hardware, a base image may inject options through environment variables, and a later option can override an earlier one. Interviewers ask this because it is the first step of any tuning or debugging task, and because guessing flag values leads to wrong conclusions. In this answer, we will print the final flags for a command line, read the flags of a running process, see the arguments it started with, unlock the hidden flags, and find options that come from the environment.

1A Quick Recap: Flags, Defaults and Ergonomics

HotSpot, the JVM in OpenJDK, has several hundred -XX options, usually called flags. Each flag has a built-in default. When the JVM starts, a step called ergonomics adjusts some of those defaults based on the machine or container: the collector, the heap size, the number of GC threads. Then the options we pass are applied on top. The final value of a flag can therefore come from three places: the default, ergonomics, or the command line.

That is why reading the start script is not enough. A script might set nothing about the collector, yet the JVM runs Serial GC on a small container and G1 on a large one. We need tools that report the value the JVM really decided on, and ideally where it came from.

2Printing the Final Flags for a Command Line

PrintFlagsFinal prints every flag after all defaults, ergonomics and options have been applied. Adding -version makes the JVM print the table and exit, so it is safe to run anywhere. The important rule is to run it with the same options, in the same container or machine, as the real service, because ergonomics depends on the environment.

Shell
java -XX:MaxRAMPercentage=70 -XX:+PrintFlagsFinal -version | grep -E 'MaxHeapSize|MaxRAMPercentage|UseG1GC |UseSerialGC '
# size_t MaxHeapSize = 751828992 {product} {ergonomic}
# double MaxRAMPercentage = 70.000000 {product} {command line}
# bool UseG1GC = false {product} {default}
# bool UseSerialGC = true {product} {ergonomic}
# (output from a container with a 1 GiB limit and 2 CPUs; check your version for exact spacing)

The last column tells us where each value came from: {default} is the built-in default, {ergonomic} means the JVM chose it from the environment, and {command line} means we set it. Here we can see that 70 percent of 1 GiB became a heap of about 717 MB, and that ergonomics selected the Serial collector, not G1, because a container with only 1 GiB is below the memory threshold for a server-class machine. That is exactly the kind of surprise this command exists to reveal. The related option -XX:+PrintFlagsInitial prints the defaults before anything is applied, which is useful for comparison but not for knowing the effective value.

3Reading the Flags of a Running JVM

For a process that is already running we use jcmd, which connects to the JVM through the attach mechanism. VM.flags lists the flags that were set on the command line or by ergonomics, which is the short and useful list. Adding -all prints the full table in the same format as PrintFlagsFinal. VM.command_line shows the exact arguments the JVM was started with, including options that came from environment variables.

Shell
jcmd -l # 4711 orders.jar (list Java processes and their ids)
jcmd 4711 VM.flags
# -XX:CICompilerCount=2 -XX:InitialHeapSize=16777216 -XX:MaxHeapSize=751828992 -XX:+UseSerialGC ...
jcmd 4711 VM.flags -all | grep MaxMetaspaceSize
# size_t MaxMetaspaceSize = 18446744073709547520 {product} {default} (effectively unlimited)
jcmd 4711 VM.command_line
# VM Arguments:
# jvm_args: -XX:MaxRAMPercentage=70 -Dspring.profiles.active=prod
# java_command: orders.jar
Which tool answers which question
QuestionCommand
Final value for this command line?java <options> -XX:+PrintFlagsFinal -version
Built-in defaults?java -XX:+PrintFlagsInitial -version
Non-default flags of a running JVM?jcmd <pid> VM.flags
Every flag of a running JVM?jcmd <pid> VM.flags -all
Arguments it was started with?jcmd <pid> VM.command_line
Which Java processes exist?jcmd -l

jcmd must run as the same operating system user as the target JVM, and inside a container it must see the same process and temporary directory, which usually means running it inside the container. Some flags are manageable, meaning they can be changed on a running JVM with jcmd <pid> VM.set_flag, but most can only be set at startup, so this is mainly a reading tool. The older jinfo -flags <pid> gives similar output.

4Unlocking Diagnostic and Experimental Flags

Not every flag is shown or accepted by default. HotSpot groups flags into product flags, which are supported, diagnostic flags, meant for troubleshooting, and experimental flags, features that are not yet fully supported. Diagnostic and experimental flags are locked: the JVM refuses to start if we set one without unlocking its group first, and PrintFlagsFinal does not list them.

Shell
java -XX:+PrintNMTStatistics -version
# Error: VM option 'PrintNMTStatistics' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.
java -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version | wc -l
# many more lines than without the unlock options

So if we are looking for a flag that a guide mentions and PrintFlagsFinal does not show it, the usual reason is that it is diagnostic or experimental. The unlock option must come before the flag on the command line.

5Options That Come From the Environment

Two environment variables add options without appearing in the java command. JAVA_TOOL_OPTIONS is read by the JVM itself, for every Java process including tools like jcmd, and the JVM prints a line such as Picked up JAVA_TOOL_OPTIONS: -XX:MaxRAMPercentage=50 on standard error. JDK_JAVA_OPTIONS, available since JDK 9, is read only by the java launcher and is printed as NOTE: Picked up JDK_JAVA_OPTIONS: ... in the same way.

This is the classic reason for a value that makes no sense. A base container image sets JAVA_TOOL_OPTIONS with MaxRAMPercentage=50, the service sets 75 on its command line, and someone wonders which one wins. The rule is that options are applied in order: JAVA_TOOL_OPTIONS first, then JDK_JAVA_OPTIONS, then the command line, so for the same flag the command line wins. When values are unexpected we check the start of the log for Picked up lines, run env inside the container, and then look at VM.command_line and VM.flags, which show the result after everything is combined.

6Follow-up questions

Why does PrintFlagsFinal show a different heap on my laptop than in the pod?

Because ergonomics derives defaults from the memory and CPUs the JVM sees. On a laptop with 32 GB it computes 25 percent of 32 GB; in a pod with a 1 GiB limit it computes 25 percent of 1 GiB. Always run it in the same environment as the service.

Can I see flag values from inside the application?

Yes. The HotSpotDiagnosticMXBean has getVMOption(name), and RuntimeMXBean.getInputArguments() returns the JVM arguments. Spring Boot Actuator exposes some of this through its env and metrics endpoints, and logging the input arguments at startup makes the effective configuration visible to everyone.

What does {ergonomic} mean in the output?

It means the JVM chose the value itself from the environment instead of using the built-in default or a command line option. Heap sizes, the collector choice and CICompilerCount are typical ergonomic values.

7Conclusion

In this answer, we saw that a flag's final value can come from the default, ergonomics or the command line. PrintFlagsFinal with -version shows the result for a given command line and environment, jcmd VM.flags, VM.flags -all and VM.command_line show it for a running process, diagnostic and experimental flags need their unlock options, and JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS add options that are easy to miss.

What to say in the interviewAbout 70 seconds aloud

Open with

For a command line, I run the same java command with -XX:+PrintFlagsFinal and -version, in the same container or machine, because ergonomics depends on the CPUs and memory it sees.

Then, if they want more

It prints every flag with its final value and where it came from: default, ergonomic or command line.

For a running JVM I use jcmd. jcmd -l finds the process id, jcmd pid VM.flags shows the non-default flags, which is usually what I want, VM.flags -all prints everything, and VM.command_line shows the exact arguments it started with. jcmd has to run as the same user and, in a container, inside the same container or with access to the process.

Two things catch people out. Diagnostic and experimental flags are hidden and rejected unless you add UnlockDiagnosticVMOptions or UnlockExperimentalVMOptions first. And options can come from the environment: JAVA_TOOL_OPTIONS, which the JVM announces with a Picked up line on stderr, and JDK_JAVA_OPTIONS for the launcher.

They are applied before the command line, so the command line wins for the same flag, but when a value looks wrong, that is the first place I check.

About this answer

Last updated
12 November 2026
Versions it names
Java 9
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do you see the effective value of every JVM flag, both for a given command line and...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/a9b880340d/