JVM Arguments
Which JVM arguments can help optimize xiaozi craft?
WARNING
Do not mix Java 21 arguments with Java 25+ arguments.
Java 21 arguments
Using generational ZGC on Java 21 can improve game performance significantly.
-XX:+UseZGC -XX:+ZGenerational -XX:+AlwaysPreTouchUse the G1GC memory manager
-XX:+UseG1GCDisable adaptive sizing policy
After disabling it, the JVM will no longer resize the young generation, old generation, or survivor spaces automatically. On heavily modded game servers, object promotion patterns are often predictable, so manual sizing can provide more stable GC behavior.
-XX:-UseAdaptiveSizePolicyDisable the fast-throw optimization that omits stack traces
The JVM may omit stack traces when the same exception is thrown repeatedly from the same location. This option forces a full stack trace every time, which is useful when debugging mod conflicts or plugin issues.
-XX:-OmitStackTraceInFastThrowAllow ambiguous process command strings
On Windows, ProcessBuilder can reject ambiguous command strings such as paths with spaces and missing quotes. This flag relaxes that behavior.
-Djdk.lang.Process.allowAmbiguousCommands=trueIgnore invalid Minecraft certificates
Some mods or core modifications can break the original Minecraft jar signature checks. Enabling this option prevents crashes caused by certificate validation failures.
-Dfml.ignoreInvalidMinecraftCertificates=TrueIgnore mod patch discrepancy warnings and errors
When Forge patches Minecraft classes, conflicts between mods or version mismatches can trigger errors. This option forces those discrepancies to be ignored, which may help in experimental environments but can also cause unstable behavior.
-Dfml.ignorePatchDiscrepancies=TrueDisable Log4j2 message lookups
This is a mitigation for the Log4Shell vulnerability and prevents dangerous lookups such as ${jndi:...} from being evaluated inside log messages.
-Dlog4j2.formatMsgNoLookups=trueSet the initial heap percentage used by the young generation
-XX:G1NewSizePercent=5Set the maximum heap percentage the young generation can grow to
-XX:G1MaxNewSizePercent=50Set the target maximum GC pause time in milliseconds
G1 tries to keep each GC pause near this soft target by adjusting region and generation behavior.
-XX:G1GCauseTimeMillis=200Control the mixed GC target count
-XX:G1MixedGCCountTarget=4Java 25 and later
Compact object headers reduce object header size and can lower heap memory usage on Java 25 and later.
-XX:+UseCompactObjectHeadersSet the number of concurrent GC threads
Default: about one quarter of the available CPU cores.
-XX:ConcGCThreads=NSet sensitivity to sudden allocation spikes
Useful for modded servers where mob spawning, redstone activity, or chunk loading may create sudden memory pressure.
-XX:ZAllocationSpikeTolerance=5Set the ZGC soft heap limit below -Xmx
ZGC will try to keep heap usage under this value and only use the full -Xmx limit when necessary.
-XX:SoftMaxHeapSize
-Xmx8G -XX:SoftMaxHeapSize=7GTouch all memory pages at startup
This reduces runtime allocation latency and avoids pause spikes caused by page faults, although startup becomes slower.
-XX:+AlwaysPreTouchWARNING
Use large pages carefully
Large pages can improve throughput and reduce CPU cost, but JVM startup may fail if the operating system cannot provide suitable memory regions.
Known workarounds:
- Make sure the operating system has enough clean memory.
- On virtual machines, adjust memory allocation strategy if needed.
- On physical machines, verify that enough RAM is available.
- Consider transparent huge pages instead.
-XX:+UseTransparentHugePages-XX:+UseLargePagesWARNING
Arguments you must not use
With Java 25+ ZGC, do not set -XX:ZCollectionInterval. ZGC already contains its own scheduling strategy, and forcing collection intervals can cause severe periodic lag spikes.
WARNING
Heap size examples
-Xmx is the maximum heap size and -Xms is the initial heap size.
Important notes:
-Xmsmust be less than or equal to-Xmx.- Use practical values such as 1G, 2G, 4G, 8G, 16G, 32G, or 64G when possible.
- Do not set memory options in both the launcher and the instance JVM configuration at the same time.
Wrong example:
-Xms8G -Xmx1GCorrect example:
-Xms8G -Xmx8G