Java 25 JVM options that still matter
JVM tuning advice ages quickly. Flags for PermGen, ParNew GC and the old PrintGCDetails logging system still appear in tutorials even though they no longer belong in a modern Java 25 configuration.
The best Java 25 JVM options are the ones that solve a specific operational problem. Start with JVM defaults, measure the application, and add flags only when you have a reason to change memory sizing, garbage collection, logging or diagnostics.
25 useful Java 25 JVM options
-Xmssets the initial Java heap size.-Xmxsets the maximum Java heap size.-Xsssets the stack size for Java threads.-XX:InitialRAMPercentagesizes the initial heap as a percentage of available memory.-XX:MaxRAMPercentagesizes the maximum heap as a percentage of available memory.-XX:ActiveProcessorCountoverrides the number of processors the JVM uses for sizing and ergonomics.-XX:+UseG1GCselects the G1 garbage collector.-XX:+UseZGCselects the low-latency Z Garbage Collector.-XX:+UseSerialGCselects Serial GC for small or constrained workloads.-XX:+UseParallelGCselects the throughput-oriented Parallel collector.-XX:MaxGCPauseMillissupplies a soft pause-time target to collectors such as G1.-XX:InitiatingHeapOccupancyPercentinfluences when concurrent collection work begins.-XX:+UseStringDeduplicationallows supported collectors to deduplicate equivalent String backing data.-XX:+HeapDumpOnOutOfMemoryErrorwrites a heap dump after an out-of-memory failure.-XX:HeapDumpPathcontrols where heap dumps are written.-XX:+ExitOnOutOfMemoryErrorterminates the JVM after anOutOfMemoryError.-XX:+CrashOnOutOfMemoryErrorforces a fatal JVM crash after anOutOfMemoryError.-Xlog:gc*enables detailed garbage-collection logging through unified JVM logging.-Xlog:safepointlogs JVM safepoint activity.-Xlog:class+loadlogs class loading.-XX:NativeMemoryTrackingenables JVM native-memory accounting.-XX:StartFlightRecordingstarts Java Flight Recorder when the JVM starts.-XX:FlightRecorderOptionsconfigures Java Flight Recorder behavior.-Duser.timezonedefines the application's default JVM timezone.-Djava.library.pathsupplies locations for native libraries loaded by the JVM.
Heap sizing with Xms and Xmx
The two JVM options developers encounter most often are -Xms and -Xmx. This example starts with a 768 MB heap and permits it to grow to 2 GB:
java -Xms768m -Xmx2g -jar app.jar
Modern JVM options let you control memory, garbage collection, diagnostics and runtime behavior.
Container-aware heap sizing
For containerized applications, percentage-based heap sizing is often more portable than hard-coding a heap size for every deployment.
java \
-XX:InitialRAMPercentage=25 \
-XX:MaxRAMPercentage=75 \
-jar app.jarThe JVM derives its heap sizing from the memory available to the Java process. This is useful when the same image runs under different container memory limits.
Java 25 garbage collector options
Do not copy old collector flags such as -XX:+UseParNewGC into Java 25 command lines. Modern Java provides several supported collectors for different workload goals:
-XX:+UseG1GC
-XX:+UseZGC
-XX:+UseParallelGC
-XX:+UseSerialGCG1 is a strong general-purpose collector. ZGC targets very low pause times and in modern JDK releases uses its generational implementation. Parallel GC emphasizes throughput, while Serial GC can be appropriate for very small heaps or constrained environments.
Modern GC logging with -Xlog
Legacy flags such as -XX:+PrintGCDetails, -XX:+PrintGCDateStamps and related print options have been replaced by the JVM's unified logging framework.
A practical Java 25 GC logging configuration is:
java \
-Xlog:gc*:file=gc.log:time,uptime,level,tags \
-jar app.jarFor interactive troubleshooting, you can send GC details directly to the console:
java -Xlog:gc* -jar app.jarHeap dumps on OutOfMemoryError
For production troubleshooting, a heap dump can provide the evidence needed to find retained objects and memory leaks:
java \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/var/log/myapp \
-jar app.jarMake sure the destination has enough free disk space and that heap dumps are handled securely because they can contain application data.
Java Flight Recorder
Java Flight Recorder is built into modern OpenJDK releases and is one of the most useful tools for low-overhead production diagnostics.
java \
-XX:StartFlightRecording=filename=app.jfr,dumponexit=true \
-jar app.jarYou can inspect the resulting recording with JDK Mission Control or the JDK's jfr command-line tool.
Native Memory Tracking
The Java heap is not the JVM's only consumer of memory. Native Memory Tracking helps investigate memory used by class metadata, threads, code caches and other JVM subsystems.
java -XX:NativeMemoryTracking=summary -jar app.jarAfter the JVM starts, inspect native memory with jcmd:
jcmd <pid> VM.native_memory summaryInspect Java 25 JVM flags
You can still ask HotSpot to display the final values of its JVM flags:
java -XX:+PrintFlagsFinal -versionThis is useful when you need to see both explicitly configured values and values selected by JVM ergonomics.
Java 25 flags you should remove from old scripts
Several options found in older JVM tuning guides are obsolete or removed and should not be carried forward into Java 25 configurations:
-XX:PermSizeand-XX:MaxPermSize, because PermGen was replaced by Metaspace long ago.-XX:+UseParNewGC, an obsolete collector selection flag.-XX:+PrintGCDetailsand related legacy GC print flags, which have been superseded by unified-Xloglogging.- Old tuning recipes that manually size every young-generation region without first measuring the modern collector's behavior.
A sensible Java 25 production starting point
A production command line should remain intentionally small. For example:
java \
-XX:MaxRAMPercentage=75 \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/var/log/myapp \
-Xlog:gc*:file=/var/log/myapp/gc.log:time,uptime,level,tags \
-XX:StartFlightRecording=filename=/var/log/myapp/app.jfr,dumponexit=true \
-jar app.jarDo not treat a long JVM command line as proof of optimization. Java 25 has sophisticated runtime ergonomics. Start with defaults, collect measurements with JFR, GC logs and application metrics, and tune only the settings that address an observed problem.
Cameron McKenzie is an AWS Certified AI Practitioner, Machine Learning Engineer, Solutions Architect and author of many popular books in the software development and Cloud Computing space. His growing YouTube channel training devs in Java, Spring, AI and ML has well over 30,000 subscribers.
| Git, GitHub & GitHub Copilot Certification Made Easy |
|---|
| Want to get certified on the most popular AI, ML & DevOps technologies of the day? These five resources will help you get GitHub certified in a hurry.
Get certified in the latest AI, ML and DevOps technologies. Advance your career today. |
Learn Git and GitHub fast!