Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VectorizeSIMD breaks Minecraft under specific conditions. #4849

Closed
brucethemoose opened this issue Aug 28, 2022 · 4 comments
Closed

VectorizeSIMD breaks Minecraft under specific conditions. #4849

brucethemoose opened this issue Aug 28, 2022 · 4 comments
Assignees
Labels

Comments

@brucethemoose
Copy link

brucethemoose commented Aug 28, 2022

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.

@davleopo
Copy link
Member

@brucethemoose thanks we will have a look.

@davleopo davleopo self-assigned this Aug 29, 2022
@fniephaus
Copy link
Member

@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!

@davleopo
Copy link
Member

davleopo commented Sep 6, 2022

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

@davleopo davleopo closed this as completed Sep 6, 2022
@brucethemoose
Copy link
Author

brucethemoose commented Sep 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants