Skip to content

Commit

Permalink
feat(jdk17): adjust jvm for jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 committed Oct 31, 2024
1 parent 333d25c commit 74bcee1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
11 changes: 8 additions & 3 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions gradle/jdk17/java-tron.vmoptions
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
38 changes: 32 additions & 6 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand Down

0 comments on commit 74bcee1

Please sign in to comment.