Common JVM Startup Parameters and Their Usage
This article introduces the most frequently used JVM startup parameters, explains their effects on garbage collection, heap configuration, class loading monitoring, and out‑of‑memory handling, and provides example outputs to help developers tune Java applications for large‑scale projects.
Hello, I'm Lei.
When the JVM starts, it uses a set of default parameters that are sufficient for most projects, but large applications often require manual adjustments such as increasing heap size or enabling GC logs to troubleshoot issues.
Parameter Overview
1. -verbose:gc
Enables printing of GC information during JVM startup. Example output:
[Full GC 178K->99K(1984K), 0.0253877 secs]Interpretation: Full GC indicates a full garbage‑collection cycle; 178K and 99K are the memory sizes before and after collection; 1984K is the total heap capacity; the final number is the time taken in seconds.
2. -XX:+PrintGC
Prints GC information similar to the previous flag; no additional description needed.
3. -XX:+PrintGCDetails
Prints detailed GC information. Example output:
–Heap<br/>– def new generation total 13824K, used 11223K [0x27e80000, 0x28d80000, 0x28d80000)<br/>– eden space 12288K, 91% used [0x27e80000, 0x28975f20, 0x28a80000)<br/>– from space 1536K, 0% used [0x28a80000, 0x28a80000, 0x28c00000)<br/>– to space 1536K, 0% used [0x28c00000, 0x28c00000, 0x28d80000)<br/>– tenured generation total 5120K, used 0K [0x28d80000, 0x29280000, 0x34680000)<br/>– the space 5120K, 0% used [0x28d80000, 0x28d80000, 0x28d80200, 0x29280000)<br/>– compacting perm gen total 12288K, used 142K [0x34680000, 0x35280000, 0x38680000)<br/>– the space 12288K, 1% used [0x34680000, 0x346a3a90, 0x346a3c00, 0x35280000)<br/>– ro space 10240K, 44% used [0x38680000, 0x38af73f0, 0x38af7400, 0x39080000)<br/>– rw space 12288K, 52% used [0x39080000, 0x396cdd28, 0x396cde00, 0x39c80000)Interpretation: new generation is the young generation; total shows its total size, used the used memory, and the three hexadecimal values represent the start, current, and end addresses. eden space is where newly created objects are allocated; from space and to space are the survivor spaces used by the copying collector. tenured generation refers to the old generation, and compacting perm denotes the permanent generation.
4. -XX:+PrintGCTimeStamps
Prints timestamps for each GC event. Example output:
289.556: [GC [PSYoungGen: 314113K->15937K(300928K)] 405513K->107901K(407680K), 0.0178568 secs] [Times: user=0.06 sys=0.00, real=0.01 secs]
293.271: [GC [PSYoungGen: 300865K->6577K(310720K)] 392829K->108873K(417472K), 0.0176464 secs] [Times: user=0.06 sys=0.00, real=0.01 secs]Interpretation: The leading number (e.g., 289.556) is the time in seconds since JVM start when the GC occurred. GC indicates a minor (young‑generation) collection; PSYoungGen shows the Parallel Scavenge collector. The memory figures follow the same pattern as before, and the Times section reports user, system, and real time spent.
5. -Xloggc:log/gc.log
Specifies the file path where GC logs are written (e.g., log/gc.log writes to a gc.log file inside the log directory).
6. -XX:+PrintHeapAtGC
Prints heap information after each GC event; the format is similar to the detailed GC output shown earlier.
7. -XX:+TraceClassLoading
Monitors class loading. Example output:
•[Loaded java.lang.Object from shared objects file]
•[Loaded java.io.Serializable from shared objects file]
•[Loaded java.lang.Comparable from shared objects file]
•[Loaded java.lang.CharSequence from shared objects file]
•[Loaded java.lang.String from shared objects file]
•[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
•[Loaded java.lang.reflect.Type from shared objects file]This flag makes it easy to see which classes are being loaded at runtime.
8. -XX:+PrintClassHistogram
Prints a class histogram when triggered (e.g., by Ctrl+Break). Example output:
num #instances #bytes class name
----------------------------------------------
1: 890617 470266000 [B
2: 890643 21375432 java.util.HashMap$Node
3: 890608 14249728 java.lang.Long
4: 13 8389712 [Ljava.util.HashMap$Node;
5: 2062 371680 [C
6: 463 41904 java.lang.ClassThe columns show the index, instance count, total bytes, and class name. Types B and C correspond to byte and char arrays.
9. -Xmx and -Xms
Set the maximum and initial heap size. The JVM starts with the minimum size ( -Xms) and expands toward the maximum ( -Xmx) only after several GC cycles if more memory is needed.
10. -Xmn
Specifies the size of the young generation.
11. -XX:NewRatio
Defines the ratio between young and old generations (e.g., 1:4 means the young generation occupies one‑fifth of the heap).
12. -XX:SurvivorRatio
Sets the ratio between the two survivor spaces and the eden space (e.g., 2:8 means each survivor space is one‑tenth of the eden space).
13. -XX:+HeapDumpOnOutOfMemoryError
Generates a heap dump file when an OutOfMemoryError occurs.
14. -XX:+HeapDumpPath
Specifies the directory path where the heap dump file will be written.
15. -XX:OnOutOfMemoryError
Executes a custom script when an OOM happens (e.g., to generate thread dumps, send alerts, or restart the service).
16. -XX:PermSize and -XX:MaxPermSize
Set the initial and maximum size of the permanent generation; exhausting this space can also cause OOM.
17. -Xss
Sets the thread stack size, typically a few hundred kilobytes per thread.
Summary
The above list covers many commonly used JVM parameters for memory and performance tuning; it is not exhaustive, but these settings are often sufficient for most large‑scale Java projects.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
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.
