JVM arguments for Minecraft
-Xmx, -Xms, G1GC, ZGC, Aikar's flags: how to configure Java so Minecraft runs more smoothly.
Minecraft runs on the Java Virtual Machine (JVM), which manages memory and code execution. The default JVM settings aren't tuned for the game: Minecraft gets 2 GB of RAM, uses an old garbage collector and skips many of the optimizations available in modern Java versions. Changing a few startup arguments (JVM flags) can eliminate lag spikes, improve smoothness and let the game use more of the available memory. This guide explains every important argument and gives you ready-made configurations to copy.
What JVM arguments are
JVM arguments are parameters passed to the Java virtual machine when a program starts. They control memory allocation, the choice of garbage collector, JIT compilation and dozens of other settings. For Minecraft, three groups matter most: RAM allocation (-Xmx, -Xms), the garbage collector (G1GC, ZGC, Shenandoah) and additional optimization flags.
You set JVM arguments in your Minecraft launcher. In the official launcher: Installations > Edit > More Options > JVM Arguments. In launchers like MultiMC, Prism Launcher, ATLauncher and CurseForge: instance settings > Java > JVM Arguments (or a similar field).
-Xmx and -Xms: RAM allocation
-Xmx sets the maximum amount of RAM the JVM can use. -Xms sets the initial allocation. By default, Minecraft uses -Xmx2G (2 GB). That's often not enough, especially with mods, a higher render distance or on servers.
Recommended values:
| Scenario | -Xmx (max RAM) | System RAM |
|---|---|---|
| Vanilla, no mods | 3-4 GB | 8 GB+ |
| Sodium + a few mods | 4-6 GB | 8 GB+ |
| Modpack (50+ mods) | 6-8 GB | 16 GB+ |
| Heavy modpack (200+ mods) | 8-12 GB | 16-32 GB |
| Server (10-20 players) | 6-8 GB | 16 GB+ |
Important rule: -Xms should equal -Xmx. So if you set -Xmx4G, set -Xms4G too. The reason: the JVM then doesn't have to grow the heap dynamically during play, which eliminates the lag spikes caused by memory reallocation. Aikar's flags follow this rule.
Warning: Don't allocate more RAM than you need! More RAM = more garbage for the garbage collector to clean up = longer GC pauses. 4 GB for vanilla and 6-8 GB with mods are safe values. 16 GB for Minecraft without a heavy modpack is a recipe for lag spikes.
Garbage collector: G1GC, ZGC, Shenandoah
The garbage collector (GC) is the part of Java responsible for freeing unused objects from memory. Minecraft creates millions of short-lived objects (chunks, entities, rendering buffers) that the GC has to clean up regularly. While the GC is working, the game can "stutter": those are GC lag spikes.
G1GC (Garbage-First Garbage Collector)
The default GC in Java 9+. It splits the heap into regions and cleans up the ones with the most garbage first. It strikes a good balance between throughput and pause length. Aikar's flags tune G1GC specifically for Minecraft.
ZGC (Z Garbage Collector)
A modern GC available since Java 15 (stable since 17). It guarantees pauses under 1 ms regardless of heap size. That means zero GC lag spikes. The downside: it uses more CPU than G1GC and needs 10-15% more RAM. On machines with 16+ GB of RAM and 4+ CPU cores, it's an excellent choice.
Shenandoah GC
Similar to ZGC, with ultra-low pauses. It's available in OpenJDK (not in Oracle JDK). It uses slightly less CPU than ZGC, but it's also less "proven" with Minecraft. A good alternative if you use OpenJDK and want minimal pauses.
Aikar's flags: the gold standard
Aikar's flags are a set of JVM arguments created by Daniel Ennis (Aikar), a developer of Paper MC (a Minecraft server). These flags tune G1GC specifically for the way Minecraft uses memory: lots of short-lived objects, frequent allocations of large regions (chunks) and the need for short pauses.
The full set of Aikar's flags (for 4 GB of RAM):
-Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1
Change -Xms4G -Xmx4G to the right value for your scenario (for example -Xms6G -Xmx6G for a modpack). Leave the rest of the flags as they are.
What the individual flags do:
- +UseG1GC: selects the G1 garbage collector
- MaxGCPauseMillis=200: target GC pauses under 200 ms
- +AlwaysPreTouch: allocates all the memory at once instead of on demand. Eliminates lag spikes when the heap grows
- G1NewSizePercent=30, G1MaxNewSizePercent=40: 30-40% of the heap goes to short-lived objects (chunks, buffers). Minecraft creates a lot of them
- G1HeapRegionSize=8M: the size of the G1 regions. 8 MB is optimal for Minecraft
- InitiatingHeapOccupancyPercent=15: the GC starts cleaning early (at 15% occupancy) instead of waiting for the heap to fill up
- MaxTenuringThreshold=1: objects move to the old generation quickly, because in Minecraft few objects live longer than a few seconds
- SurvivorRatio=32: a small survivor space, because objects either die quickly or live a long time
Alternative flags with ZGC (Java 21+)
If you use Java 21 or newer and have 16+ GB of RAM in your system, ZGC can give better results than G1GC with Aikar's flags:
-Xms4G -Xmx4G -XX:+UseZGC -XX:+ZGenerational -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+PerfDisableSharedMem
-XX:+ZGenerational (since Java 21) turns on generational ZGC, which is even more efficient than classic ZGC. Generational ZGC treats short-lived objects differently from long-lived ones, which fits Minecraft perfectly.
ZGC is simpler to configure: it doesn't need dozens of flags like G1GC, because it tunes its parameters automatically. The downside: it uses more RAM (~15%) and more CPU. If you have 8 GB of RAM in your system and give Minecraft 4 GB, ZGC may be too "hungry": stick with G1GC and Aikar's flags.
How to set the flags in popular launchers
Official Minecraft Launcher
- Open the launcher and go to the "Installations" tab
- Click "..." next to your profile and choose "Edit"
- Click "More Options"
- In the "JVM Arguments" field, delete the default text and paste Aikar's flags
- Click "Save"
Prism Launcher / MultiMC
- Right-click your instance > "Edit Instance"
- Go to the "Settings" tab > "Java"
- Check "Override" next to "JVM Arguments"
- Paste Aikar's flags (without -Xmx and -Xms: you set those in the separate "Minimum memory" and "Maximum memory" fields)
- Set the right amount of RAM in the memory allocation fields
CurseForge / ATLauncher
- Go to the settings (gear icon)
- Find the "Java" or "Minecraft" section
- Set the RAM in the "Allocated Memory" field
- Paste the extra flags into the "Additional Arguments" or "JVM Arguments" field
Which Java version to choose
Minecraft 1.20.5+ requires Java 21. Older versions run on Java 17 or even 8. Whatever the requirement, use the newest compatible Java version:
- Minecraft 1.20.5+: Java 21 (GraalVM CE 21 or Adoptium 21)
- Minecraft 1.17-1.20.4: Java 17 (but 21 works too)
- Minecraft 1.16 and older: Java 8 (some modpacks need exactly 8)
GraalVM Community Edition is a Java distribution from Oracle with a better JIT compiler. It gives 5-15% more FPS than standard OpenJDK thanks to more aggressive code optimization at runtime. It's free and easy to install (download it from graalvm.org, unpack it and point your launcher to the path of java.exe).
Checking that the flags work
After setting the flags, launch Minecraft and press F3. The debug screen shows information about the JVM, including the Java version and how much RAM is allocated. Make sure that:
- The Java version is the one you set (for example "Java 21.0.2")
- The allocated RAM matches -Xmx (for example "Mem: 45% 1812/4096MB" means a 4 GB maximum)
- There are no frequent lag spikes (FPS drops every few seconds). If there are, your garbage collector may be badly configured or you've allocated too much RAM
If you still have performance problems after applying the flags, check our tips in 20 ways to get more FPS and our graphics settings guide. JVM flags are an important piece of the puzzle, but not the only one: an optimization mod and the right graphics settings together do much more than Java arguments alone.
Tip: If you run a Minecraft server (Paper, Purpur, Fabric), Aikar's flags matter even more than on the client. A server handles many players, chunks and entities at once, so GC optimization drastically improves TPS (ticks per second). On a server with 20 players, the difference between the default flags and Aikar's can mean 15 vs 20 TPS.