Aishwar
Aishwar

Reputation: 9724

Java Max Heap Size (Xmx) not respected based on XX:printFlagsFinal

I configured a Java server to start with -Xmx12288M and -Xmx12288M; however when I go to the Java process and run this: java -XX:+PrintFlagsFinal -version | grep -iE 'MaxHeapSize', I see the value as 4141875200 - which I believe is ~4GB.

I ran jps -vl and I do see -Xmx12288M there. Am I looking at the wrong place for the max heap size the process can use? Or is it actually not using the configured max heap size?

This is running on a 64bit JVM.

Upvotes: 5

Views: 5041

Answers (2)

Amir Afghani
Amir Afghani

Reputation: 38551

Am I looking at the wrong place for the max heap size the process can use?

Yes, you are looking at the wrong place. As @Aishwar points out, running $java -version creates a new Java process. You could :

add the PrintFlagsFinal flag to your servers Java options and read the log file, or simply attach to your java process with a tool like jinfo or JVisualVM and inspect the usage.

Upvotes: 3

Aishwar
Aishwar

Reputation: 9724

Looks like: java -XX:+PrintFlagsFinal -version | grep -iE 'MaxHeapSize' starts a Java process and prints out the settings on it. It does not print the JVM settings from the running Java process.

This worked for me: jinfo <pid-of-running-java-process> | grep 'HeapSize'. This printed:

Non-default VM flags: ...  -XX:InitialHeapSize=12884901888 -XX:MaxHeapSize=12884901888 ...

Upvotes: 10

Related Questions