Skip to content

Commit 930a96c

Browse files
committed
feat(JVM): add jvm options for jdk17
1 parent 6755869 commit 930a96c

File tree

5 files changed

+92
-12
lines changed

5 files changed

+92
-12
lines changed

build.gradle

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1+
import org.gradle.nativeplatform.platform.internal.Architectures
12
allprojects {
23
version = "1.0.0"
34
apply plugin: "java-library"
45
}
56

7+
static def isX86() {
8+
def arch = System.getProperty("os.arch").toLowerCase()
9+
return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch)
10+
}
11+
12+
static def isArm64() {
13+
def arch = System.getProperty("os.arch").toLowerCase()
14+
return new Architectures.KnownArchitecture("arm64", "aarch64").isAlias(arch)
15+
}
16+
17+
if (isArm64() && !JavaVersion.current().is(JavaVersion.VERSION_17)) {
18+
throw new GradleException("Java 17 is required to build Java-Tron for arm64.\n" +
19+
" Detected version ${JavaVersion.current()}")
20+
}
21+
22+
if (isX86() && !JavaVersion.current().isJava8()) {
23+
throw new GradleException("Java 8 is required to build Java-Tron for x86.\n" +
24+
" Detected version ${JavaVersion.current()}")
25+
}
26+
627
subprojects {
728
apply plugin: "jacoco"
829
apply plugin: "maven-publish"
930

1031
sourceCompatibility = JavaVersion.VERSION_1_8
11-
targetCompatibility = JavaVersion.VERSION_1_8
32+
targetCompatibility = JavaVersion.current()
1233

1334
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
1435
jacoco {

framework/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,17 @@ def createScript(project, mainClass, name) {
203203
}
204204
}
205205
}
206-
207-
applicationDistribution.from("../gradle/java-tron.vmoptions") {
208-
into "bin"
206+
if (JavaVersion.current().is(JavaVersion.VERSION_17)) {
207+
applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") {
208+
into "bin"
209+
}
210+
} else if (JavaVersion.current().isJava8()){
211+
applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") {
212+
into "bin"
213+
}
214+
} else {
215+
throw new GradleException("Java 8 or Java17 is supported to build Java-Tron.\n" +
216+
" Detected version ${JavaVersion.current()}")
209217
}
210218
//distZip {
211219
// doLast {

gradle/jdk17/java-tron.vmoptions

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-XX:+UseZGC
2+
-Xlog:gc*:file=gc.log:time,uptime,level,tags:filecount=50,filesize=100M
3+
-XX:ReservedCodeCacheSize=256m
4+
-XX:+UseCodeCacheFlushing
5+
-XX:MetaspaceSize=256m
6+
-XX:MaxMetaspaceSize=512m
7+
-XX:MaxDirectMemorySize=1g
8+
-XX:+HeapDumpOnOutOfMemoryError

plugins/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,17 @@ def createScript(project, mainClass, name) {
127127
}
128128
}
129129
}
130-
applicationDistribution.from("../gradle/java-tron.vmoptions") {
131-
into "bin"
130+
if (JavaVersion.current().is(JavaVersion.VERSION_17)) {
131+
applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") {
132+
into "bin"
133+
}
134+
} else if (JavaVersion.current().isJava8()){
135+
applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") {
136+
into "bin"
137+
}
138+
} else {
139+
throw new GradleException("Java 8 or Java17 is supported to build Java-Tron.\n" +
140+
" Detected version ${JavaVersion.current()}")
132141
}
133142
createScript(project, 'org.tron.plugins.ArchiveManifest', 'ArchiveManifest')
134143
createScript(project, 'org.tron.plugins.Toolkit', 'Toolkit')

start.sh

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,51 @@ startService() {
355355
exit
356356
fi
357357

358-
nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \
359-
-XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \
360-
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
361-
-XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \
362-
-XX:NewRatio=2 -jar \
363-
$JAR_NAME $FULL_START_OPT >>start.log 2>&1 &
358+
runService
364359
checkPid
365360
echo "info: start java-tron with pid $pid on $HOSTNAME"
366361
echo "info: if you need to stop the service, execute: sh start.sh --stop"
367362
}
368363

364+
runService() {
365+
arch=$(uname -m)
366+
java_version=$($JAVACMD -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }')
367+
368+
if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then
369+
echo "Architecture: x86_64/amd64"
370+
if [[ $java_version =~ '1.8' ]]; then
371+
echo 'Using required JDK8 for x86_64/amd64 architecture'
372+
nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \
373+
-XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \
374+
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
375+
-XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \
376+
-XX:NewRatio=2 -jar \
377+
$JAR_NAME $FULL_START_OPT >>start.log 2>&1 &
378+
else
379+
echo "Error: x86_64/amd64 architecture requires JDK8. Current version: $java_version"
380+
exit 1
381+
fi
382+
elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then
383+
echo "Architecture: ARM64"
384+
if [[ $java_version =~ '17' ]]; then
385+
echo 'Using required JDK17 for ARM architecture'
386+
nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX \
387+
-XX:+UseZGC \
388+
-Xlog:gc*:file=gc.log:time,uptime,level,tags:filecount=50,filesize=100M \
389+
-XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \
390+
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
391+
-XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \
392+
-jar $JAR_NAME $FULL_START_OPT >>start.log 2>&1 &
393+
else
394+
echo "Error: ARM architecture requires JDK17. Current version: $java_version"
395+
exit 1
396+
fi
397+
else
398+
echo "Error: Unsupported architecture: $arch"
399+
exit 1
400+
fi
401+
}
402+
369403
rebuildManifest() {
370404
if [[ $REBUILD_MANIFEST = false ]]; then
371405
echo 'info: disable rebuild manifest!'

0 commit comments

Comments
 (0)