声明:
笔者只是一个爱好Minecraft的普通玩家,不太懂如何调试Java,本文所述参数是笔者参考一些帖子综合尝试而来(就是把这些帖子的建议参数都复制过来,然后一遍遍启动MC并删去导致报错的参数,所以并不能保证这些参数都是正确且有效的)。如果本文内容存在错误,欢迎各位进行批评指正,我会在看到评论后尽快更正错误。


本文的写作动机:
笔者发现网上有用Java8,Java20启动我的世界时的JVM参数设置,而关于Java17的则几乎没有,于是在多次尝试后有了本文


此参数调用 G1GC
-Xms20480M -Xmx20480M -XX:+AlwaysPreTouch -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:-OmitStackTraceInFastThrow -Dfile.encoding=UTF-8 -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=150 -XX:GuaranteedSafepointInterval=0 -XX:+UseCountedLoopSafepoints -XX:LoopStripMiningIter=1 -XX:+SafepointTimeout -XX:SafepointTimeoutDelay=1000 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:+ExplicitGCInvokesConcurrent
下面是这些参数的具体作用
-XX:+UnlockExperimentalVMOptions
解锁HotSpot JVM 中的实验性功能相关的选项


内存控制相关:
-Xms20480M -Xmx20480M
分配给MC的内存(根据需要更改)
-XX:+AlwaysPreTouch
内存初始化(针对堆内存,申请并 commit 了InitialRAMPercentage大小后立刻填充 0 让系统真的把内存分配给 JVM)
会让启动更慢,但是性能略有提升()


JVM 日志相关
-XX:+UnlockDiagnosticVMOptions
显示HotSpot JVM 的高级诊断信息
-XX:-OmitStackTraceInFastThrow
关闭堆栈省略


系统属性(环境变量)启动参数
-Dfile.encoding=UTF-8
指定编码为 UTF-8,其实 Java 18 之后默认编码就是 UTF-8 了,这样避免不同操作系统编译带来的差异(Windows 默认是 GB2312,Linux 默认是 UTF-8)


GC 控制相关
-XX:+DisableExplicitGC
关闭显示 GC(System.gc()触发的 FullGC),防止 netty 这种误检测内存泄漏显示调用
-XX:MaxGCPauseMillis=150
这个参数用于设置GC暂停等待时间,单位为毫秒,不要设置过低
-XX:GuaranteedSafepointInterval=0
禁用定时安全点任务
-XX:+UseCountedLoopSafepoints
防止大有界循环带来的迟迟不进入安全点导致 GC STW 时间过长
-XX:LoopStripMiningIter=1
这个不设置为1会报错
-XX:+SafepointTimeout
-XX:SafepointTimeoutDelay=1000
防止其他情况下导致进入安全点时间过长导致 STW 时间过长,这里配置的是 1s
-XX:ParallelGCThreads=8
-XX:ConcGCThreads=2
区分young区的parnew gc线程数和old区的cms线程数(具体见JVM调优-CMS常见参数、线程计算与推荐配置)
-XX:+ExplicitGCInvokesConcurrent
该参数启用后JVM无论什么时候调用系统GC,都执行CMS GC,而不是Full GC。


方法编译
-XX:-DontCompileHugeMethods
JVM 在调用大函数时会使用编译模式而非解释模式运行,进一步提升性能。


参考的贴子
几张性能对比,让你明白高版本 Java 更适合 Minecraft
我所使用的生产 Java 17 启动参数
JVM调优-CMS常见参数、线程计算与推荐配置
G1垃圾回收参数优化
Java 11 到 Java 17 的最佳 HotSpot JVM 选项和开关
换个JVM
等


我使用的JVMAlibaba Dragonwell 17
参考帖子几张性能对比,让你明白高版本 Java 更适合 Minecraft
笔者只是一个爱好Minecraft的普通玩家,不太懂如何调试Java,本文所述参数是笔者参考一些帖子综合尝试而来(就是把这些帖子的建议参数都复制过来,然后一遍遍启动MC并删去导致报错的参数,所以并不能保证这些参数都是正确且有效的)。如果本文内容存在错误,欢迎各位进行批评指正,我会在看到评论后尽快更正错误。


本文的写作动机:
笔者发现网上有用Java8,Java20启动我的世界时的JVM参数设置,而关于Java17的则几乎没有,于是在多次尝试后有了本文


此参数调用 G1GC
-Xms20480M -Xmx20480M -XX:+AlwaysPreTouch -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:-OmitStackTraceInFastThrow -Dfile.encoding=UTF-8 -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=150 -XX:GuaranteedSafepointInterval=0 -XX:+UseCountedLoopSafepoints -XX:LoopStripMiningIter=1 -XX:+SafepointTimeout -XX:SafepointTimeoutDelay=1000 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:+ExplicitGCInvokesConcurrent
下面是这些参数的具体作用
-XX:+UnlockExperimentalVMOptions
解锁HotSpot JVM 中的实验性功能相关的选项


内存控制相关:
-Xms20480M -Xmx20480M
分配给MC的内存(根据需要更改)
-XX:+AlwaysPreTouch
内存初始化(针对堆内存,申请并 commit 了InitialRAMPercentage大小后立刻填充 0 让系统真的把内存分配给 JVM)
会让启动更慢,但是性能略有提升()


JVM 日志相关
-XX:+UnlockDiagnosticVMOptions
显示HotSpot JVM 的高级诊断信息
-XX:-OmitStackTraceInFastThrow
关闭堆栈省略


系统属性(环境变量)启动参数
-Dfile.encoding=UTF-8
指定编码为 UTF-8,其实 Java 18 之后默认编码就是 UTF-8 了,这样避免不同操作系统编译带来的差异(Windows 默认是 GB2312,Linux 默认是 UTF-8)


GC 控制相关
-XX:+DisableExplicitGC
关闭显示 GC(System.gc()触发的 FullGC),防止 netty 这种误检测内存泄漏显示调用
-XX:MaxGCPauseMillis=150
这个参数用于设置GC暂停等待时间,单位为毫秒,不要设置过低
-XX:GuaranteedSafepointInterval=0
禁用定时安全点任务
-XX:+UseCountedLoopSafepoints
防止大有界循环带来的迟迟不进入安全点导致 GC STW 时间过长
-XX:LoopStripMiningIter=1
这个不设置为1会报错
-XX:+SafepointTimeout
-XX:SafepointTimeoutDelay=1000
防止其他情况下导致进入安全点时间过长导致 STW 时间过长,这里配置的是 1s
-XX:ParallelGCThreads=8
-XX:ConcGCThreads=2
区分young区的parnew gc线程数和old区的cms线程数(具体见JVM调优-CMS常见参数、线程计算与推荐配置)
-XX:+ExplicitGCInvokesConcurrent
该参数启用后JVM无论什么时候调用系统GC,都执行CMS GC,而不是Full GC。


方法编译
-XX:-DontCompileHugeMethods
JVM 在调用大函数时会使用编译模式而非解释模式运行,进一步提升性能。


参考的贴子
几张性能对比,让你明白高版本 Java 更适合 Minecraft
我所使用的生产 Java 17 启动参数
JVM调优-CMS常见参数、线程计算与推荐配置
G1垃圾回收参数优化
Java 11 到 Java 17 的最佳 HotSpot JVM 选项和开关
换个JVM
等


我使用的JVMAlibaba Dragonwell 17
参考帖子几张性能对比,让你明白高版本 Java 更适合 Minecraft