From 74bcee1f22cfb90617e6bc0525e9bb066f27e3fc Mon Sep 17 00:00:00 2001 From: halibobo1205 Date: Thu, 31 Oct 2024 15:35:09 +0800 Subject: [PATCH] feat(jdk17): adjust jvm for jdk17 --- framework/build.gradle | 11 ++++++--- gradle/jdk17/java-tron.vmoptions | 8 +++++++ plugins/build.gradle | 10 +++++++-- start.sh | 38 +++++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 gradle/jdk17/java-tron.vmoptions diff --git a/framework/build.gradle b/framework/build.gradle index 4519f93e44d..0256026a62b 100644 --- a/framework/build.gradle +++ b/framework/build.gradle @@ -227,9 +227,14 @@ def createScript(project, mainClass, name) { } } } - -applicationDistribution.from("../gradle/java-tron.vmoptions") { - into "bin" +if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") { + into "bin" + } +} else { + applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") { + into "bin" + } } //distZip { // doLast { diff --git a/gradle/jdk17/java-tron.vmoptions b/gradle/jdk17/java-tron.vmoptions new file mode 100644 index 00000000000..1c49ca93787 --- /dev/null +++ b/gradle/jdk17/java-tron.vmoptions @@ -0,0 +1,8 @@ +-XX:+UseZGC +-Xlog:gc*:file=gc-%t.log:time,uptime,level,tags:filecount=50,filesize=100M +-XX:ReservedCodeCacheSize=256m +-XX:+UseCodeCacheFlushing +-XX:MetaspaceSize=256m +-XX:MaxMetaspaceSize=512m +-XX:MaxDirectMemorySize=1g +-XX:+HeapDumpOnOutOfMemoryError \ No newline at end of file diff --git a/plugins/build.gradle b/plugins/build.gradle index b85a435dc30..9ad5b210e47 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -130,8 +130,14 @@ def createScript(project, mainClass, name) { } } } -applicationDistribution.from("../gradle/java-tron.vmoptions") { - into "bin" +if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") { + into "bin" + } +} else { + applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") { + into "bin" + } } createScript(project, 'org.tron.plugins.ArchiveManifest', 'ArchiveManifest') createScript(project, 'org.tron.plugins.Toolkit', 'Toolkit') diff --git a/start.sh b/start.sh index 89f13cf25a7..9aecec88244 100644 --- a/start.sh +++ b/start.sh @@ -355,17 +355,43 @@ startService() { exit fi - nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \ - -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ - -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ - -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ - -XX:NewRatio=2 -jar \ - $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + runService checkPid echo "info: start java-tron with pid $pid on $HOSTNAME" echo "info: if you need to stop the service, execute: sh start.sh --stop" } +runService() { + # check the java version is jdk8 or jdk17 + java_version=$($JAVACMD -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }') + if [[ $java_version =~ '1.8' ]]; then + echo 'info: java version is jdk8' + nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \ + -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ + -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ + -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ + -XX:NewRatio=2 -jar \ + $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + elif [[ $java_version =~ '17' ]]; then + # check the gc log directory. if not exists, create it + if [[ ! -d 'gc' ]]; then + mkdir -p 'gc' + fi + + nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX \ + -XX:+UseZGC \ + -Xlog:gc*:file=gc/gc-%t.log:time,uptime,level,tags:filecount=50,filesize=100M \ + -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ + -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ + -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ + -jar $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + + else + echo 'warn: java version is not jdk8 or jdk17' + exit + fi +} + rebuildManifest() { if [[ $REBUILD_MANIFEST = false ]]; then echo 'info: disable rebuild manifest!'