OpenJDK17一些JVM参数变化

0

由于租用的服务器内存比较小,所以配置了一下网站的JVM参数看下有没有什么优化空间。
但是配置后发现启动不了,首先提示下面错误:

Unrecognized VM option 'PrintGCDateStamps'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

这个是由于PrintGCDateStamps配置已经废弃了,所以改为-Xlog:gc::utctime

然后还有配置日志的参数也改了:

-Xloggc is deprecated. Will use -Xlog:gc:./logs/gc.log instead.
Unrecognized option: -JAR
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

这个就比较人性化了,直接提示该使用那个参数替换。

还有很多参数都被废弃了:

[0.002s][warning][gc] -XX:+PrintGC is deprecated. Will use -Xlog:gc instead.
[0.002s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.

所以直接这样配置即可:

JAVA_OPTS_GC="-XX:+UseG1GC -Xlog:gc:./logs/gc.log:time,level"

我的完整启动脚本:

#!/bin/bash

cd /data/www
JAVA_OPTS_GC="-XX:+UseG1GC -Xlog:gc:./logs/gc.log:time,level"
JAVA_OPTS_MEM="-server -Xms256m -Xmx512m -XX:NewRatio=1 -XX:SurvivorRatio=2"
JAVA_OPTS_EXT="-Dfile.encoding=UTF-8 -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
JAVA_OPTS_APP="-Dspring.profiles.active=release"
JAVA_OPTS="$JAVA_OPTS_GC $JAVA_OPTS_MEM $JAVA_OPTS_EXT $JAVA_OPTS_APP"
/usr/bin/nohup /data/software/jdk-17.0.2/bin/java $JAVA_OPTS -jar ./lib/${project.artifactId}-${project.version}.jar

GC信息:

[2022-05-17T07:52:02.941+0800][info] Using G1
[2022-05-17T07:52:07.818+0800][info] GC(0) Pause Young (Concurrent Start) (Metadata GC Threshold) 94M->12M(258M) 38.292ms
[2022-05-17T07:52:07.818+0800][info] GC(1) Concurrent Mark Cycle
[2022-05-17T07:52:07.869+0800][info] GC(1) Pause Remark 13M->13M(256M) 5.594ms
[2022-05-17T07:52:07.869+0800][info] GC(1) Pause Cleanup 13M->13M(256M) 0.005ms
[2022-05-17T07:52:07.873+0800][info] GC(1) Concurrent Mark Cycle 55.044ms
[2022-05-17T07:52:11.226+0800][info] GC(2) Pause Young (Concurrent Start) (Metadata GC Threshold) 80M->17M(256M) 83.308ms
[2022-05-17T07:52:11.226+0800][info] GC(3) Concurrent Mark Cycle
[2022-05-17T07:52:11.313+0800][info] GC(3) Pause Remark 21M->21M(256M) 6.364ms
[2022-05-17T07:52:11.321+0800][info] GC(3) Pause Cleanup 21M->21M(256M) 0.008ms
[2022-05-17T07:52:11.324+0800][info] GC(3) Concurrent Mark Cycle 97.990ms
[2022-05-17T07:52:12.886+0800][info] GC(4) Pause Young (Normal) (G1 Evacuation Pause) 128M->19M(256M) 55.674ms
[2022-05-17T07:52:26.481+0800][info] GC(5) Pause Young (Normal) (G1 Evacuation Pause) 128M->24M(256M) 64.671ms
[2022-05-17T07:53:26.217+0800][info] GC(6) Pause Young (Concurrent Start) (Metadata GC Threshold) 55M->26M(256M) 107.440ms
[2022-05-17T07:53:26.218+0800][info] GC(7) Concurrent Mark Cycle
[2022-05-17T07:53:26.286+0800][info] GC(7) Pause Remark 28M->28M(256M) 9.705ms
[2022-05-17T07:53:26.309+0800][info] GC(7) Pause Cleanup 28M->28M(256M) 0.011ms
[2022-05-17T07:53:26.310+0800][info] GC(7) Concurrent Mark Cycle 92.023ms
[2022-05-17T07:54:34.545+0800][info] GC(8) Pause Young (Concurrent Start) (G1 Evacuation Pause) 128M->55M(256M) 182.173ms
[2022-05-17T07:54:34.545+0800][info] GC(9) Concurrent Mark Cycle
[2022-05-17T07:54:34.614+0800][info] GC(9) Pause Remark 56M->56M(256M) 12.662ms
[2022-05-17T07:54:34.614+0800][info] GC(9) Pause Cleanup 56M->56M(256M) 0.008ms
[2022-05-17T07:54:34.615+0800][info] GC(9) Concurrent Mark Cycle 69.632ms