Removed deprecated options, support for JDK 24.

Flags cuc dep trai by meowice uwu
This commit is contained in:
MeowIce authored and GitHub committed 2025-08-02 12:56:08 +07:00
1 parent 73d9da5361
commit aa49e742b0
1 file changed
+64 -29
+64 -29
View File
@@ -1,18 +1,45 @@
# Welcome !
Glad you are here ! In this repository, I'll give you the Java flags I use to run my Minecraft server (with 80-90 players) at its best.
Hewwo there, I'm glad you are here ! This instruction will guide you to use MeowIce's Flags to make your Minecraft server run as it best ^^
## Compatibility
These flags are only compatible with:
- Java 17+,
My flags are only compatible and tested with:
- Java 24+,
- GraalVM JVM,
- Linux.
# The flags
- Linux,
- Minecraft 1.20+
> [!TIP]
> Using MeowIce's Flags with [Leaf](https://github.com/Winds-Studio/Leaf) as server software can boost more performance !
# TL;DR: The flags
## G1GC version (for server below 32GB allocated heap)
> [!NOTE]
> This is recommended for servers allocated below 32GB RAM with basic resource usage. Balanced between memory usage and performance.
`--add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:SurvivorRatio=32 -XX:G1HeapWastePercent=5 -XX:MaxTenuringThreshold=1 -XX:+PerfDisableSharedMem -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:+UseNUMA -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:NmethodSweepActivity=1 -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:AllocatePrefetchStyle=3 -XX:+AlwaysActAsServerClassMachine -XX:+UseTransparentHugePages -XX:LargePageSizeInBytes=2M -XX:+UseLargePages -XX:+EagerJVMCI -XX:+UseStringDeduplication -XX:+UseAES -XX:+UseAESIntrinsics -XX:+UseFMA -XX:+UseLoopPredicate -XX:+RangeCheckElimination -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseThreadPriorities -XX:+OmitStackTraceInFastThrow -XX:+RewriteBytecodes -XX:+RewriteFrequentPairs -XX:+UseFPUForSpilling -XX:+UseFastStosb -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXMMForArrayCopy -XX:+UseXmmI2D -XX:+UseXmmI2F -XX:+UseXmmLoadAndClearUpper -XX:+UseXmmRegToRegMoveAll -XX:+EliminateLocks -XX:+DoEscapeAnalysis -XX:+AlignVector -XX:+OptimizeFill -XX:+EnableVectorSupport -XX:+UseCharacterCompareIntrinsics -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs -XX:UseAVX=2 -XX:UseSSE=4 -XX:+UseFastJNIAccessors -XX:+UseInlineCaches -XX:+SegmentedCodeCache -Djdk.nio.maxCachedBufferSize=262144 -Dgraal.UsePriorityInlining=true -Dgraal.Vectorization=true -Dgraal.OptDuplication=true -Dgraal.DetectInvertedLoopsAsCounted=true -Dgraal.LoopInversion=true -Dgraal.VectorizeHashes=true -Dgraal.EnterprisePartialUnroll=true -Dgraal.VectorizeSIMD=true -Dgraal.StripMineNonCountedLoops=true -Dgraal.SpeculativeGuardMovement=true -Dgraal.TuneInlinerExploration=1 -Dgraal.LoopRotation=true -Dgraal.OptWriteMotion=true -Dgraal.CompilerConfiguration=enterprise
`--add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:SurvivorRatio=32 -XX:G1HeapWastePercent=5 -XX:MaxTenuringThreshold=1 -XX:+PerfDisableSharedMem -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:+UseNUMA -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:NmethodSweepActivity=1 -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:AllocatePrefetchStyle=3 -XX:+AlwaysActAsServerClassMachine -XX:+UseTransparentHugePages -XX:LargePageSizeInBytes=2M -XX:+UseLargePages -XX:+EagerJVMCI -XX:+UseStringDeduplication -XX:+UseAES -XX:+UseAESIntrinsics -XX:+UseFMA -XX:+UseLoopPredicate -XX:+RangeCheckElimination -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseThreadPriorities -XX:+OmitStackTraceInFastThrow -XX:+RewriteBytecodes -XX:+RewriteFrequentPairs -XX:+UseFPUForSpilling -XX:+UseFastStosb -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXMMForArrayCopy -XX:+UseXmmI2D -XX:+UseXmmI2F -XX:+UseXmmLoadAndClearUpper -XX:+UseXmmRegToRegMoveAll -XX:+EliminateLocks -XX:+DoEscapeAnalysis -XX:+AlignVector -XX:+OptimizeFill -XX:+EnableVectorSupport -XX:+UseCharacterCompareIntrinsics -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs -XX:UseAVX=2 -XX:UseSSE=4 -XX:+UseFastJNIAccessors -XX:+UseInlineCaches -XX:+SegmentedCodeCache -Djdk.nio.maxCachedBufferSize=262144 -Djdk.graal.UsePriorityInlining=true -Djdk.graal.Vectorization=true -Djdk.graal.OptDuplication=true -Djdk.graal.DetectInvertedLoopsAsCounted=true -Djdk.graal.LoopInversion=true -Djdk.graal.VectorizeHashes=true -Djdk.graal.EnterprisePartialUnroll=true -Djdk.graal.VectorizeSIMD=true -Djdk.graal.StripMineNonCountedLoops=true -Djdk.graal.SpeculativeGuardMovement=true -Djdk.graal.TuneInlinerExploration=1 -Djdk.graal.LoopRotation=true -Djdk.graal.CompilerConfiguration=enterprise
`
## ZGC version (for server with 32GB+ allocated heap)
> [!NOTE]
> This is recommended for servers with more than 32GB of allocated memory and many CPU cores, allowing for minimizing the delay between each GC run with a larger heap size in an intensive environment.
> [!WARNING]
> Only use this if you have more than 10 CPU cores; using ZGC on systems with fewer than 8 cores may cause a significant performance impact !
`--add-modules=jdk.incubator.vector -XX:+UseZGC -XX:-ZProactive -XX:SoftMaxHeapSize=$((Memory - 2048))M -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:+PerfDisableSharedMem -XX:+UseNUMA -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:NmethodSweepActivity=1 -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:AllocatePrefetchStyle=1 -XX:+AlwaysActAsServerClassMachine -XX:+UseTransparentHugePages -XX:LargePageSizeInBytes=2M -XX:+UseLargePages -XX:+EagerJVMCI -XX:+UseStringDeduplication -XX:+UseAES -XX:+UseAESIntrinsics -XX:+UseFMA -XX:+UseLoopPredicate -XX:+RangeCheckElimination -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseThreadPriorities -XX:+OmitStackTraceInFastThrow -XX:+RewriteBytecodes -XX:+RewriteFrequentPairs -XX:+UseFPUForSpilling -XX:+UseFastStosb -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXMMForArrayCopy -XX:+UseXmmI2D -XX:+UseXmmI2F -XX:+UseXmmLoadAndClearUpper -XX:+UseXmmRegToRegMoveAll -XX:+EliminateLocks -XX:+DoEscapeAnalysis -XX:+AlignVector -XX:+OptimizeFill -XX:+EnableVectorSupport -XX:+UseCharacterCompareIntrinsics -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs -XX:UseAVX=2 -XX:UseSSE=4 -XX:+UseFastJNIAccessors -XX:+UseInlineCaches -XX:+SegmentedCodeCache -Djdk.nio.maxCachedBufferSize=262144 -Djdk.graal.UsePriorityInlining=true -Djdk.graal.Vectorization=true -Djdk.graal.OptDuplication=true -Djdk.graal.DetectInvertedLoopsAsCounted=true -Djdk.graal.LoopInversion=true -Djdk.graal.VectorizeHashes=true -Djdk.graal.EnterprisePartialUnroll=true -Djdk.graal.VectorizeSIMD=true -Djdk.graal.StripMineNonCountedLoops=true -Djdk.graal.SpeculativeGuardMovement=true -Djdk.graal.TuneInlinerExploration=1 -Djdk.graal.LoopRotation=true -Djdk.graal.CompilerConfiguration=enterprise`
# What is MeowIce's Flags ?
MeowIce's Flags aimed to blend Aikar's Flags optimization with new JVM features to further boost the overall performance, while allowing it to use advanced CPU instructions to accelerate some workloads.
> [!NOTE]
> Hey don't forget to leave a star !
> <img width="756" height="157" alt="image" src="https://github.com/user-attachments/assets/4db8d2e9-e2fa-448e-9a52-7af7a6c7369a" />
# Why would I have to... switch ?
Almost 99% of Minecraft servers use Aikar's Flags and it is recommended by many people (some use nothing !). But why use other flags ?
The answer is that we have now developed to Minecraft 1.21.x and Java 22 (at the time of writing this) and Aikar's Flags **was written mainly to optimize Minecraft's Garbage Collector** and Java at that time (around 2018 - 2020). Later Java versions (from Java 17 and above) have added many optimization items for JVM. So I wrote a separate flag to support optimizations and integrates new features of Java 17+ while still keeping Aikar's flags to optimize GC. <ins>There's no risk in trying my flags !</ins>
# Explainations
Almost 99% of Minecraft servers use Aikar's Flags, and it is recommended by many people (some use nothing !). But why use other flags ?
The answer is: We have now developed to Minecraft 1.21.x and Java 24 (at the time of writing this), and Aikar's Flags **was written mainly to optimize Minecraft's Garbage Collector** and Java version at that time (Java 8 and Java 11, around 2018 - 2020). Later Java versions (from Java 17 and above) have added many optimization options for the JVM. So I wrote a separate flag to support these optimizations and integrate new features of Java 17+ while still keeping Aikar's flags mainly to optimize GC. <ins>There's no risk in trying my flags !</ins>
# Why GraalVM but not AdoptiumJDK or OpenJDK ?
GraalVM with better JIT performance and more aggressive optimizations compared to traditional `HotSpot C2` found in many JDKs (including OpenJDK and AdoptiumJDK (aka. Eclipse Temurin)). This change makes inlining, loop unrolling, escape analysis, and vectorization work better while maintaining lower CPU usage.
Furthermore, the GraalVM compiler compiles plugins and server code faster and smarter, adapting to actual usage and environment on the fly.
> [!TIP]
> GraalVM allows you to inspect memory usage and trace down naughty plugins using VisualVM !
# Flags explanation
- `--add-modules=jdk.incubator.vector` Enables advanced vector computation capabilities for Pufferfish/Purpur 1.18+. Useful for optimizing chunk loading and rendering.
- ` -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:SurvivorRatio=32 -XX:G1HeapWastePercent=5 -XX:MaxTenuringThreshold=1 -XX:+PerfDisableSharedMem -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1RSetUpdatingPauseTimePercent=0` These are very generic G1GC flags, based on [Aikar's Flags](https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/).
- `-XX:+UseNUMA` Enables NUMA or (Non Uniform Memory Access) for supported architecture.
@@ -60,35 +87,43 @@ The answer is that we have now developed to Minecraft 1.21.x and Java 22 (at the
- `-XX:+UseInlineCaches` Use Inline Caches for virtual calls
- `-XX:+SegmentedCodeCache` Enables the segmented code cache, which improves code cache management.
## GraalVM Compiler Specific Flags
- `-Djdk.nio.maxCachedBufferSize=262144` Sets the maximum size for cached direct buffers.
- `-Dgraal.UsePriorityInlining=true` Enables priority inlining in the Graal compiler.
- `-Dgraal.Vectorization=true` Enables vectorization in the Graal compiler.
- `-Dgraal.OptDuplication=true` Enables optimization duplication in the Graal compiler.
- `-Dgraal.DetectInvertedLoopsAsCounted=true` Enables detection of inverted loops as counted loops.
- `-Dgraal.LoopInversion=true` Enables loop inversion in the Graal compiler.
- `-Dgraal.VectorizeHashes=true` Enables vectorization of hash computations.
- `-Dgraal.VectorizeSIMD=true` Enables SIMD (Single Instruction - Multiple Data) vectorization.
- `-Dgraal.StripMineNonCountedLoops=true` Enables strip mining of non-counted loops.
- `-Dgraal.SpeculativeGuardMovement=true` Enables speculative guard movement in the Graal compiler.
- `-Dgraal.TuneInlinerExploration=1` Tunes the inliner exploration parameter in the Graal compiler.
- `-Dgraal.LoopRotation=true -Dgraal.UseCountedLoopSafepoints=true -Dgraal.EnterprisePartialUnroll=true` Loops related.
# Small test
- `-Djdk.nio.maxCachedBufferSize=262144` Sets the maximum size for cached direct buffers.
- `-Djdk.graal.UsePriorityInlining=true` Enables priority inlining in the Graal compiler.
- `-Djdk.graal.Vectorization=true` Enables vectorization in the Graal compiler.
- `-Djdk.graal.OptDuplication=true` Enables optimization duplication in the Graal compiler.
- `-Djdk.graal.DetectInvertedLoopsAsCounted=true` Enables detection of inverted loops as counted loops.
- `-Djdk.graal.LoopInversion=true` Enables loop inversion in the Graal compiler.
- `-Djdk.graal.VectorizeHashes=true` Enables vectorization of hash computations.
- `-Djdk.graal.VectorizeSIMD=true` Enables SIMD (Single Instruction - Multiple Data) vectorization.
- `-Djdk.graal.StripMineNonCountedLoops=true` Enables strip mining of non-counted loops.
- `-Djdk.graal.SpeculativeGuardMovement=true` Enables speculative guard movement in the Graal compiler.
- `-Djdk.graal.TuneInlinerExploration=1` Tunes the inliner exploration parameter in the Graal compiler.
- `-Djdk.graal.LoopRotation=true` Enables loop rotation in the Graal compiler.
- `-Djdk.graal.UseCountedLoopSafepoints=true` Enables safepoint insertion in counted loops.
- `-Djdk.graal.EnterprisePartialUnroll=true` Enables partial unrolling optimizations in enterprise mode.
- `-Djdk.graal.CompilerConfiguration=enterprise` Enables Enterprise mode optimizations in the Graal compiler.
# Comparison
I have made a comparison with one of my customers' servers.
## Spark
Aikar's Flags and Adoptium JDK:
![image](https://github.com/user-attachments/assets/93e5ab90-708f-4d8a-8979-fa03e5cb6a56)
<img width="1909" height="398" alt="image" src="https://github.com/user-attachments/assets/eae32edc-f162-4b33-9246-2443933621ac" />
![image](https://github.com/user-attachments/assets/efb29f29-8512-4fda-a5e6-f038109c5270)
MeowIce's Flags and GraalVM:
![image](https://github.com/user-attachments/assets/8acd1d80-847d-403d-bb40-7f06c2074d02)
![image](https://github.com/user-attachments/assets/e99e1d94-4fd0-497e-a5f5-bf8c5fdba9a8)
<img width="1920" height="423" alt="image" src="https://github.com/user-attachments/assets/dcd97360-d73e-49f3-a4b2-1869bb581686" />
## TPS
With only Aikar's flags and OpenJDK:
<img width="1405" height="202" alt="image" src="https://github.com/user-attachments/assets/42e6dab1-76ed-4c1b-b320-d4d0a3407cf1" />
With MeowIce's flags and GraalVM:
<img width="1296" height="255" alt="image" src="https://github.com/user-attachments/assets/c8280ebd-f51e-43fb-a16a-62340c8829ca" />
### Sources
- [Java Flags Benchmarked](https://github.com/brucethemoose/Minecraft-Performance-Flags-Benchmarks)
- [Obydux GraalVM Flags](https://github.com/Obydux/Minecraft-GraalVM-Flags/)
- [Optimize MC Server on RedHat](https://www.redhat.com/en/blog/optimizing-rhel-8-run-java-implementation-minecraft-server)
### Read more
- [Hướng dẫn: Cấu hình để giảm lag và tối ưu server Minecraft để đạt hiệu năng tốt nhất](https://minecraftvn.net/cau-hinh-de-giam-lag-va-toi-uu-server-minecraft-de-dat-hieu-nang-tot-nhat.t46151/)
### My Optimization service:
- [Dịch vụ tối ưu, fix lag máy chủ Minecraft](https://minecraftvn.net/toi-uu-fix-lag-cuc-cang-may-chu-minecraft.t47454/)