oracle/graal

`VectorizeSIMD` breaks Minecraft under specific conditions.

brucethemoose opened this issue ยท 4 comments

Describe the issue
GraalVM EE's VectorizeSIMD optimization crashes Minecraft or breaks rendering under specific circumstances. Disabling the VectorizeSIMD flag fixes the issue, as does disabling compilation of specific methods, like net.minecraft.class_4604.method_23092

More details

I first ran into this issue with the Sodium and Iris mods in a "default" GraalVM EE environment. After playing for a minute or so, all entities turn invisible (notice their shadows on the ground):

invisible

Disabling VectorizeSIMD or the compilation of net.minecraft.class_4604.method_23092 fixes this issue.

At first, I thought this was an issue specific to those modifications, but as I started forcing compilation with very low CompileThresholdScaling values or -Xcomp and narrowing down the issue to a more specific chain of methods, I discovered the affected methods were base Minecraft methods, and this bug started manifesting itself without the Iris modification. Specifically, with just the "Sodium" and "Fabric" Minecraft modifications, all entities turn invisible, as in the above screenshot. With just the "Fabric" modding API, and the specific graal arguments from below, the whole application hangs on the frame entities turn invisible:

-XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -Dgraal.UsePriorityInlining=false -Dgraal.VectorizeSIMD=true -Dgraal.PrintCompilation=true -XX:CompileThresholdScaling=0.05 -Xcomp -XX:JVMCIThreads=1 -XX:-UseDynamicNumberOfCompilerThreads -Dgraal.LogFile=fabriccrash.log -Dgraal.TraceBytecodeParserLevel=0 -Dgraal.GraalCompileOnly=net.minecraft.class_1159.method_22672,net.minecraft.class_1159.method_22673,net.minecraft.class_1159.method_22871,net.minecraft.class_1162.<init>,net.minecraft.class_1162.method_22674,net.minecraft.class_4604.<init>,net.minecraft.class_4604.handler*,net.minecraft.class_4604.method_23088,net.minecraft.class_4604.method_23091,net.minecraft.class_4604.method_23092,java.lang.Object.<init>,net.minecraft.class_1159.<init>

net/Minecraft/class_4604.method_23092 (which is documented in the below link) seems to be the final and exact compilation that breaks or crashes rendering (as it is the final compiled method in the attached logs), but this bug will not manifest itself without the other specified compiled methods.

A side note: Minecraft classes/methods are obfuscated, and they show up as jibberish in the graal compilation log. But modding APIs (such as Fabric, which I was testing with) map, name and document these obfuscated classes so modders can use them, as you can see in the documentation here

This is relevant because the methods I narrowed this issue down to with Dgraal.CompileOnly use the Fabric method/class names... but this bug also manifests itself in environments without the "Fabric" mod (such as Forge), so it cannot be a "Fabric" mod bug. Hence I am fairly certain it could manifest in the base game as well, without any mods. But this is difficult to test, as I would have to "reverse map" these methods to the base game in order for the Graal compilation filter to recognize them.

Cross-platform steps to reproduce the issue

  1. Install the "PolyMC" Minecraft launcher. It is available on Github, or in some repos (like the AUR): https://github.com/PolyMC/PolyMC
  2. Import the following instance into it: Iris-Sodium.zip
  3. Run the Minecraft client instance with the specified GraalVM flags.
  4. Create a new "superflat" world for testing. If the game doesn't crash upon loading, all entities (like monsters and villagers) will be invisible.
  5. Disable VectorizeSIMD, and the issue will not persist.

Describe GraalVM and your environment:

  • GraalVM version: EE 22.2.0
  • JDK major version: 17
  • OS: Windows 10
  • Architecture: AMD64

Logs + Dumps
Invisible entities: sodiumwithsimd.zip

Same setup with VectorizeSIMD disabled: sodiumwithoutsimd.zip

Crash upon loading world with the "Fabric" API: fabrichangwithsimd.zip

Same setup with VectorizeSIMD disabled: fabricwthoutsimd.zip

Let me know if I can provide any more information for debugging.

@brucethemoose thanks we will have a look.

@brucethemoose We've just published a guest blog post on how to compile the Minecraft server to native with GraalVM Native Image. Would be fun to see how a native Minecraft server performs in your benchmarks. Feel free to share any results with us!

@brucethemoose we have identified the problem and a fix will be shipped in 22.3.
Thanks for your efforts.

Thanks!

And I am looking into this @fniephaus , but its tricky, as my script's performance metrics rely on server mods (which generate chunks and spawn players as a "load" that can be measured) , or on the vanilla client.