When debugging Java application OutOfMemory (OOM) errors or verifying JVM ergonomics inside Docker containers, knowing how the JVM evaluates heap limits, garbage collectors, and system environment variables is critical. The -XshowSettings:vm flag prints active JVM settings to terminal stderr.
Inspect Active JVM Settings (java -XshowSettings:vm)
$ java -XshowSettings:vm -version
VM Settings:
Max. Heap Size (Estimated): 4.00G
Using VM: OpenJDK 64-Bit Server VM
# Print ALL settings including locale, system properties, and security providers:
$ java -XshowSettings:all -versionOverriding Heap Limits with _JAVA_OPTIONS
The _JAVA_OPTIONS environment variable forces JVM arguments onto every Java process launched in the active shell environment:
# Export global JVM options override
export _JAVA_OPTIONS="-Xms512m -Xmx2g"
# Run any Java app - JVM prints notification acknowledging _JAVA_OPTIONS
java -jar my_service.jar
# Picked up _JAVA_OPTIONS: -Xms512m -Xmx2g
Comments and corrections