Skip to content

Commit 5975fff

Browse files
committed
feat(build): support JDK 17 on x86
1 parent 154cca1 commit 5975fff

7 files changed

Lines changed: 13 additions & 170 deletions

File tree

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ allprojects {
1616
def arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT)
1717
def javaVersion = JavaVersion.current()
1818
def isArm64 = Architectures.AARCH64.isAlias(arch)
19+
def isCompatibleWith17 = JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)
1920
def archSource = isArm64 ? "arm" : "x86"
2021
def isMac = OperatingSystem.current().isMacOsX()
2122

@@ -43,10 +44,10 @@ ext.archInfo = [
4344
// https://github.com/grpc/grpc-java/pull/11371 , 1.64.x is not supported CentOS 7.
4445
ProtocGenVersion: isArm64 || isMac ? '1.81.0' : '1.60.0'
4546
],
46-
VMOptions: isArm64 ? "${rootDir}/gradle/jdk17/java-tron.vmoptions" : "${rootDir}/gradle/java-tron.vmoptions"
47+
VMOptions: isCompatibleWith17 ? "${rootDir}/gradle/jdk17/java-tron.vmoptions" : "${rootDir}/gradle/java-tron.vmoptions"
4748
]
4849

49-
if (!archInfo.java.is(archInfo.requires.JavaVersion)) {
50+
if (!javaVersion.isCompatibleWith(archInfo.requires.JavaVersion)) {
5051
throw new GradleException("Java ${archInfo.requires.JavaVersion} is required for ${archInfo.name}. Detected version ${archInfo.java}")
5152
}
5253

framework/src/main/java/org/tron/program/FullNode.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.tron.common.application.Application;
77
import org.tron.common.application.ApplicationFactory;
88
import org.tron.common.application.TronApplicationContext;
9-
import org.tron.common.arch.Arch;
109
import org.tron.common.exit.ExitManager;
1110
import org.tron.common.log.LogService;
1211
import org.tron.common.parameter.CommonParameter;
@@ -23,7 +22,6 @@ public class FullNode {
2322
*/
2423
public static void main(String[] args) {
2524
ExitManager.initExceptionHandler();
26-
checkJdkVersion();
2725
Args.setParam(args, "config.conf");
2826
CommonParameter parameter = Args.getInstance();
2927

@@ -66,13 +64,4 @@ public static void main(String[] args) {
6664
}
6765
appT.blockUntilShutdown();
6866
}
69-
70-
private static void checkJdkVersion() {
71-
try {
72-
Arch.throwIfUnsupportedJavaVersion();
73-
} catch (UnsupportedOperationException e) {
74-
System.err.println(e.getMessage());
75-
throw new TronError(e, TronError.ErrCode.JDK_VERSION);
76-
}
77-
}
7867
}

framework/src/test/java/org/tron/core/exception/TronErrorTest.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertThrows;
5-
import static org.junit.Assert.fail;
65
import static org.mockito.ArgumentMatchers.any;
76
import static org.mockito.Mockito.mockStatic;
8-
import static org.mockito.Mockito.never;
9-
import static org.mockito.Mockito.times;
107

118
import ch.qos.logback.classic.LoggerContext;
129
import ch.qos.logback.classic.util.ContextInitializer;
@@ -32,7 +29,6 @@
3229
import org.mockito.junit.MockitoJUnitRunner;
3330
import org.slf4j.LoggerFactory;
3431
import org.tron.common.TestConstants;
35-
import org.tron.common.arch.Arch;
3632
import org.tron.common.log.LogService;
3733
import org.tron.common.parameter.RateLimiterInitialization;
3834
import org.tron.common.utils.ReflectUtils;
@@ -153,58 +149,4 @@ public void shutdownBlockTimeInitTest() {
153149
assertEquals(TronError.ErrCode.AUTO_STOP_PARAMS, thrown.getErrCode());
154150
}
155151

156-
@Test
157-
public void testThrowIfUnsupportedJavaVersion() {
158-
runArchTest("x86_64", "1.8", false);
159-
runArchTest("x86_64", "11", true);
160-
runArchTest("x86_64", "17", true);
161-
runArchTest("aarch64", "17", false);
162-
runArchTest("aarch64", "1.8", true);
163-
runArchTest("aarch64", "11", true);
164-
}
165-
166-
private void runArchTest(String osArch, String javaVersion, boolean expectThrow) {
167-
try (MockedStatic<Arch> mocked = mockStatic(Arch.class)) {
168-
boolean isX86 = "x86_64".equals(osArch);
169-
boolean isArm64 = "aarch64".equals(osArch);
170-
171-
boolean isJava8 = "1.8".equals(javaVersion);
172-
boolean isJava17 = "17".equals(javaVersion);
173-
174-
mocked.when(Arch::isX86).thenReturn(isX86);
175-
mocked.when(Arch::isArm64).thenReturn(isArm64);
176-
177-
mocked.when(Arch::isJava8).thenReturn(isJava8);
178-
mocked.when(Arch::isJava17).thenReturn(isJava17);
179-
180-
mocked.when(Arch::getOsArch).thenReturn(osArch);
181-
mocked.when(Arch::javaSpecificationVersion).thenReturn(javaVersion);
182-
mocked.when(Arch::withAll).thenReturn(String.format(
183-
"Architecture: %s, Java Version: %s", osArch, javaVersion));
184-
185-
mocked.when(Arch::throwIfUnsupportedJavaVersion).thenCallRealMethod();
186-
187-
if (expectThrow) {
188-
UnsupportedOperationException err = assertThrows(
189-
UnsupportedOperationException.class,
190-
Arch::throwIfUnsupportedJavaVersion);
191-
192-
String expectedJavaVersion = isX86 ? "1.8" : "17";
193-
String expectedMessage = String.format(
194-
"Java %s is required for %s architecture."
195-
+ " Detected version %s",
196-
expectedJavaVersion, osArch, javaVersion);
197-
assertEquals(expectedMessage, err.getMessage());
198-
mocked.verify(Arch::withAll, times(1));
199-
} else {
200-
try {
201-
Arch.throwIfUnsupportedJavaVersion();
202-
} catch (Exception e) {
203-
fail("Expected no exception, but got: " + e.getMessage());
204-
}
205-
mocked.verify(Arch::withAll, never());
206-
}
207-
}
208-
}
209-
210152
}

platform/src/main/java/common/org/tron/common/arch/Arch.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,6 @@ public static boolean isArm64() {
6262
return osArch.contains("arm64") || osArch.contains("aarch64");
6363
}
6464

65-
public static boolean isX86() {
66-
return !isArm64();
67-
}
68-
69-
public static boolean isJava8() {
70-
return javaSpecificationVersion().equals("1.8");
71-
}
72-
73-
public static boolean isJava17() {
74-
return javaSpecificationVersion().equals("17");
75-
}
76-
77-
public static void throwIfUnsupportedJavaVersion() {
78-
if ((isX86() && !isJava8()) || (isArm64() && !isJava17())) {
79-
logger.info(withAll());
80-
throw new UnsupportedOperationException(String.format(
81-
"Java %s is required for %s architecture. Detected version %s", isX86() ? "1.8" : "17",
82-
getOsArch(), javaSpecificationVersion()));
83-
}
84-
}
85-
8665
public static void throwIfUnsupportedArm64Exception(String message) {
8766
if (isArm64()) {
8867
throw new UnsupportedOperationException(

platform/src/main/java/arm/org/tron/common/math/MathWrapper.java renamed to platform/src/main/java/common/org/tron/common/math/MathWrapper.java

File renamed without changes.

platform/src/main/java/x86/org/tron/common/math/MathWrapper.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

start.sh.simple

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#
3030
##############################################################################
3131

32+
## Set TCMalloc as the memory allocator
33+
34+
export LD_PRELOAD="/usr/lib64/libtcmalloc.so"
35+
export TCMALLOC_RELEASE_RATE=10
36+
37+
# JDK
38+
#export JAVA_HOME=/home/java-tron/jdk17
39+
#export PATH=$JAVA_HOME/bin:$PATH
40+
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
41+
#JDK
3242

3343
# adjust JVM start
3444
# Set the maximum heap size to 9G, adjust as needed

0 commit comments

Comments
 (0)