It's weird that there's not already a tutorial for this, so I'm making this one.
Minecraft uses a Java Virtual Machine (JVM) to run its source code on your computer.
By default, Minecraft comes packaged with the OpenJDK JVM, which is the most commonly used JVM, and has been tested to work with Minecraft.
GraalVM is a relatively new JVM which focuses on performance, where OpenJDK JVM falls behind. With all of its new optimizations turned on, it performs considerably better than all currently available JVMs, according to Fine Constant's testing.
So, if you would like to try it out, here's how:
Minecraft Version | Java Version | GraalVM Version |
---|---|---|
21w19a - 1.18.0 and newer | Java 17 or newer | GraalVM 22.0.0.2 |
21w18a - 1.16.5 and older | Java 8 | GraalVM 21.3.1 |
Open the GraalVM link in the table above for your Minecraft version. You should see a GitHub Releases page, like such:
You'll want to scroll down to Assets
, and click on it to open the list of all of the released executables for this version of GraalVM.
This will open a very big list, but don't be intimidated!
The file we want will always start with graalvm-ce-java
, so scroll down until you see that! For this version of GraalVM, it starts right after espresso-llvm-installable-ce-java17-linux-amd64-22.0.0.2.jar.sha256
;
Now, you should find the GraalVM file that matches the Java version you need for Minecraft, and the operating system you are running. I'm modding 1.18.1 and I'm on Windows, so that means I need to find graalvm-ce-java17-windows
- it's just a little further down!
In this case, graalvm-ce-java17-windows-amd64-22.0.0.2.zip
looks like the thing I need! If you were on Mac OS X, you would want graalvm-ce-java17-darwin-amd64-22.0.0.2.tar.gz
! The last version number will change depending on what Java version you need- for instance, my system would need graalvm-ce-java8-windows-amd64-21.3.1.zip
from the link above.
Now that we know we need to download graalvm-ce-java17-windows-amd64-22.0.0.2.zip
- we just click on it!
This fairly large zip file (335MB!) contains the entire JVM needed to run Minecraft, with all of its supporting libraries and executables- in other words, when we extract this zip file, wherever we put the extracted files will be what we need to tell Minecraft to use.
Personally, I'm going to make a new directory called JVM
in my C:
drive (C:\JVM
), and download the zip to there.
Now, just need to extract it.
So, we have GraalVM downloaded to somewhere we can remember. The only thing left to do is configure Minecraft to use it!
The way you tell Minecraft to use GraalVM depends on the Launcher you are using, so below are different sections for the main launchers I could think of.
Unfortunately, CurseForge doesn't actually allow setting the Java version Minecraft will use directly. Instead, each time you launch a modpack, you will have to follow the instructions below for the Official Launcher, as CurseForge will reset the Official Launcher's settings each time you launch a modpack using it.
If this annoys you, I would recommend looking into MultiMC- this problem is exactly why I switched!
Step 2: Hover over the installation you want to modify, and click on the three dots, then click Edit
!
This will open a file browser- we want to go back to where we extracted GraalVM now!
Now, inside here, we're going to navigate into however many folders it takes, until we get here:
We want to go inside bin
, and scrooooooooll on down until you find javaw.exe
.
Click on it, click Open
, and you'll see in the Minecraft launcher that it has taken the place of <Use bundled Java runtime>
.
Use the JVM arguments from step 4 below in the JVM Arguments
field.
MultiMC makes this really easy.
This will open a file browser- we want to go back to where we extracted GraalVM now!
Now, inside here, we're going to navigate into however many folders it takes, until we get here:
We want to go inside bin
, and scrooooooooll on down until you find javaw.exe
.
Click on it, and click Open
.
Use the JVM arguments from step 4 below in the JVM Arguments
field!
Now, we want to set up the JVM arguments to do the following:
Flag | Explanation |
---|---|
-XX:+UnlockExperimentalVMOptions |
Enable experimental JVM options, such as the JIT and optimized GC |
-XX:+UseJVMCICompiler |
Enable the JIT |
-XX:+UseG1GC |
Enable the experimental optimized garbage collector |
-XX:G1NewSizePercent=20 |
Set the lower bound of the GC |
-XX:G1MaxNewSizePercent=60 |
Set the upper bound of the GC |
-XX:G1ReservePercent=20 |
Set the reserved space for the GC |
-XX:MaxGCPauseMillis=50 |
Ask the GC to not pause our program for more than 50ms at a time- this hugely helps with stutters! |
-XX:G1HeapRegionSize=32M |
Optimize the heap region size |
-Xms2G |
Allocate at least 2 gigabytes of memory to minecraft |
-Xmx10G |
In this example, we allow minecraft to consume up to 10 gigabytes of memory. This is the one flag you should probably adjust for your modpack/system, so that's why it's at the end! |
In summary, you should paste this into the JVM Argments
field:
-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1MaxNewSizePercent=60 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M -Xms2G -Xmx10G
We want to make absolutely sure Minecraft is actually using GraalVM- the way we do this is just by looking in the Minecraft log.
When you launch the game, you will automatically have the log opened- scroll up, until you find this line:
If this was not running GraalVM, it would not show from GraalVM Community
here.
The official launcher and others may not show this message at all. In this case, the easiest way to ensure GraalVM is being used is to just start the game, and open the task manager to inspect the details of what's running:
We can see here that C:\JVM\graalvm[...]
is running it!