本文基于两个出发点,描述了业务平台于21年12月启动了对JDK版本升级的适配之路,并回顾了整个升级过程,对升级过程中的问题做了记录。
一、升级版本的选择
二、GC选择及功能适配
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
三、升级JDK11相关组件的升级
|
|
|
|
|
|
|
|
|
|
四、灰度及上线流程的选择
-
代码使用JDK8进行编译,但要求代码可以同时在JDK8及JDK11上运行
-
上线过程中,先将日常及预发环境的版本切换成JDK11和JDK8同时运行,回归测试过程中同时测试JDK11、JDK8版本下的运行情况
-
线上逐步灰度JDK11运行环境的功能,做好监控及线上排查定位。随着几次大促下来后,逐步将所有的容器切换到JDK11,下线JDK8环境的容器。
-
利用运行态的JDK11特性,优化系统性能
-
将编译从JDK8切换到JDK11 ,同时充分JDK11本身的新的特性。
if [ -f /home/admin/logs/jdk11.enable ]; then
export JAVA_HOME=/opt/taobao/install/ajdk11_11.0.14.13/
export JDK11_ENABLE=true
echo "enable jdk11 , use new JAVA_HOME : ${JAVA_HOME}"
fi
if [ "$JDK11_ENABLE" == "true" ]; then
CATALINA_OPTS="${CATALINA_OPTS} -Xlog:gc*:${MIDDLEWARE_LOGS}/gc.log:time"
CATALINA_OPTS="${CATALINA_OPTS} --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED --add-exports=java.base/jdk.internal.loader=jdk.unsupported --patch-module jdk.unsupported=/home/admin/buy2/bin/java9-migration-helper-0.1.jar"
CATALINA_OPTS="${CATALINA_OPTS} -Dio.netty.tryReflectionSetAccessible=true --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED" CATALINA_OPTS="${CATALINA_OPTS} --add-exports=java.base/jdk.internal.util.jar=ALL-UNNAMED --add-exports=java.base/jdk.internal.util.jar=jdk.unsupported"
CATALINA_OPTS="${CATALINA_OPTS} --add-opens=java.base/com.alibaba.wisp.engine=ALL-UNNAMED" CATALINA_OPTS="${CATALINA_OPTS} -XX:CompileCommand=stableif,*::*" test -z "$JPDA_ADDRESS" && export JPDA_ADDRESS=*:8000 #gson兼容 CATALINA_OPTS="${CATALINA_OPTS} -Djava.locale.providers=COMPAT,SPI" else
CATALINA_OPTS="${CATALINA_OPTS} -Xloggc:${MIDDLEWARE_LOGS}/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
CATALINA_OPTS="${CATALINA_OPTS} -XX:-UncommonNullCast -XX:CompileCommand=stableif,*::*" test -z "$JPDA_ADDRESS" && export JPDA_ADDRESS=8000 fiexport G1_ENABLE=false if [ -f /home/admin/logs/g1.enable ]; then export G1_ENABLE=true echo "enable g1" fi if [ "$G1_ENABLE" == "true" ]; then
CATALINA_OPTS="${CATALINA_OPTS} -Xms9500m -Xmx9500m" CATALINA_OPTS="${CATALINA_OPTS} -XX:+UseG1GC"
CATALINA_OPTS="${CATALINA_OPTS} -XX:G1HeapRegionSize=32m" CATALINA_OPTS="${CATALINA_OPTS} -XX:+G1BarrierSkipDCQ"
CATALINA_OPTS="${CATALINA_OPTS} -XX:InitiatingHeapOccupancyPercent=40" CATALINA_OPTS="${CATALINA_OPTS} -XX:-G1UseAdaptiveIHOP"
CATALINA_OPTS="${CATALINA_OPTS} -XX:G1HeapWastePercent=2" else CATALINA_OPTS="${CATALINA_OPTS} -Xms10g -Xmx10g"
CATALINA_OPTS="${CATALINA_OPTS} -Xmn5632m" CATALINA_OPTS="${CATALINA_OPTS} -XX:+CMSScavengeBeforeRemark"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+UseConcMarkSweepGC -XX:CMSMaxAbortablePrecleanTime=5000"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly"
fi
五、二三方包适配及改造
-
版本号格式的变化
-
本地化的优先级变化
-
module化
-
废弃代码清理
-
JDK日志架构变化
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
六、JDK11参数改造
|
|
|
|
|
|
|
|
|
|
|
|
|
|
七、从JDK8升级到JDK11后的性能表现
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
八、G1 GC测试验证
export G1_ENABLE=false
if [ -f /home/admin/logs/g1.enable ]; then
export G1_ENABLE=true
echo "enable g1"
fi
if [ "$G1_ENABLE" == "true" ]; then
CATALINA_OPTS="${CATALINA_OPTS} -Xms9500m -Xmx9500m"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+UseG1GC"
CATALINA_OPTS="${CATALINA_OPTS} -XX:G1HeapRegionSize=32m"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+G1BarrierSkipDCQ"
CATALINA_OPTS="${CATALINA_OPTS} -XX:InitiatingHeapOccupancyPercent=40"
CATALINA_OPTS="${CATALINA_OPTS} -XX:-G1UseAdaptiveIHOP"
CATALINA_OPTS="${CATALINA_OPTS} -XX:G1HeapWastePercent=2"
else
CATALINA_OPTS="${CATALINA_OPTS} -Xms10g -Xmx10g"
CATALINA_OPTS="${CATALINA_OPTS} -Xmn5632m"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+CMSScavengeBeforeRemark"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+UseConcMarkSweepGC -XX:CMSMaxAbortablePrecleanTime=5000"
CATALINA_OPTS="${CATALINA_OPTS} -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly"
fi
展望