Skip to content

Commit 50d6f69

Browse files
authored
feat(architecture): support arm64 based on JDK17 (#6327)
* feat(jvm/JEP-358): enhance NullPointerException handling - update condition to check for NullPointerException instances - maintain compatibility with both pre-Java 14 and Java 14+ versions - address JEP 358 changes to NullPointerException behavior - ensure correct handling of non-empty NPE messages in Java 14+ Refs: JEP 358, JDK-8220715 * feat(jvm/JEP-223): use java.specification.version - use `java.specification.version` instead of parsing `java.version` - ensure consistent version reporting across different Java releases(jdk10+) * feat(jvm/JDK-8176425): Add radix indication in NumberFormatException message * feat(jvm/JEP-277): remove deprecated and marked for removal code * feat(jvm/JEP-286): remove lombok.var * feat(dependencies): update dependencies for jdk17 add javax.jws-api:1.1 and javax.annotation-api:1.3.2, refs:JDK-8190378, JEP 320 remove com.carrotsearch:java-sizeof:0.0.5 bump lombok from 1.18.12 to 1.18.34, refs: [Lombok Changelog](https://projectlombok.org/changelog) bump aspectjrt from 1.18.13 to 1.9.8, refs: [AspectJ Java version compatibility](https://eclipse.dev/aspectj/doc/latest/release/JavaVersionCompatibility.html) * feat(JVM): add jvm options for jdk17 * feat(docker): support ARM64 * feat(db): keep leveldb and rocksdb same behaviors for db operations * feat(db): remove rocksDB compatibility with LevelDB * feat(db): update leveldb and rocksdb for arm * feat(math): add hard-code for arm pow * test(ci):fix test failed * feat(test): add test for hashcode and web3_clientVersion * feat(db): remove leveldb support for arm64 * feat(jdk): X86 platforms strictly restrict JDK 1.8 usage
1 parent 9247853 commit 50d6f69

File tree

102 files changed

+2100
-888
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2100
-888
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,20 @@ TRON enables large-scale development and engagement. With over 2000 transactions
5959

6060
# Building the Source Code
6161

62-
Building java-tron requires `git` package and 64-bit version of `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
62+
Building java-tron requires `git` package
6363

64+
## Operating systems
65+
Make sure you operate on `Linux` or `MacOS` operating systems, other operating systems are not supported yet.
66+
67+
## Architecture
68+
69+
### x86_64
70+
64-bit version of `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet.
71+
72+
### ARM64
73+
64-bit version of `JDK 17` to be installed, other JDK versions are not supported yet.
74+
75+
### build
6476
Clone the repo and switch to the `master` branch
6577

6678
```bash
@@ -77,8 +89,19 @@ $ ./gradlew clean build -x test
7789

7890
# Running java-tron
7991

80-
Running java-tron requires 64-bit version of `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
92+
## Operating systems
93+
Make sure you operate on `Linux` or `MacOS` operating systems, other operating systems are not supported yet.
94+
95+
## Architecture
96+
97+
### X86_64
98+
Requires 64-bit version of `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet.
8199

100+
### ARM64
101+
Requires 64-bit version of `JDK 17` to be installed, other JDK versions are not supported yet.
102+
103+
104+
## Configuration flile
82105
Get the mainnet configuration file: [main_net_config.conf](https://github.com/tronprotocol/tron-deployment/blob/master/main_net_config.conf), other network configuration files can be found [here](https://github.com/tronprotocol/tron-deployment).
83106

84107
## Hardware Requirements
@@ -100,6 +123,7 @@ Recommended:
100123

101124
Full node has full historical data, it is the entry point into the TRON network, it can be used by other processes as a gateway into the TRON network via HTTP and GRPC endpoints. You can interact with the TRON network through full node:transfer assets, deploy contracts, interact with contracts and so on. `-c` parameter specifies a configuration file to run a full node:
102125

126+
### x86_64 JDK 1.8
103127
```bash
104128
$ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
105129
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
@@ -111,6 +135,19 @@ $ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
111135
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
112136
-jar FullNode.jar -c main_net_config.conf >> start.log 2>&1 &
113137
```
138+
### ARM64 JDK 17
139+
```bash
140+
$ nohup java -Xms9G -Xmx9G -XX:+UseZGC \
141+
-Xlog:gc*:file=gc.log:time,uptime,level,tags:filecount=50,filesize=100M \
142+
-XX:ReservedCodeCacheSize=256m \
143+
-XX:+UseCodeCacheFlushing \
144+
-XX:MetaspaceSize=256m \
145+
-XX:MaxMetaspaceSize=512m \
146+
-XX:MaxDirectMemorySize=1g \
147+
-XX:+HeapDumpOnOutOfMemoryError \
148+
-jar FullNode.jar -c main_net_config.conf >> start.log 2>&1 &
149+
```
150+
114151

115152
## Running a super representative node for mainnet
116153

@@ -126,6 +163,7 @@ Fill in the private key of a super representative address into the `localwitness
126163

127164
then run the following command to start the node:
128165

166+
### x86_64 JDK 1.8
129167
```bash
130168
$ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
131169
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
@@ -137,9 +175,22 @@ $ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
137175
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
138176
-jar FullNode.jar --witness -c main_net_config.conf >> start.log 2>&1 &
139177
```
178+
### ARM64 JDK 17
179+
```bash
180+
$ nohup java -Xms9G -Xmx9G -XX:+UseZGC \
181+
-Xlog:gc*:file=gc.log:time,uptime,level,tags:filecount=50,filesize=100M \
182+
-XX:ReservedCodeCacheSize=256m \
183+
-XX:+UseCodeCacheFlushing \
184+
-XX:MetaspaceSize=256m \
185+
-XX:MaxMetaspaceSize=512m \
186+
-XX:MaxDirectMemorySize=1g \
187+
-XX:+HeapDumpOnOutOfMemoryError \
188+
-jar FullNode.jar --witness -c main_net_config.conf >> start.log 2>&1 &
189+
```
140190

141191
## Quick Start Tool
142192

193+
### x86_64 JDK 1.8
143194
An easier way to build and run java-tron is to use `start.sh`. `start.sh` is a quick start script written in the Shell language. You can use it to build and run java-tron quickly and easily.
144195

145196
Here are some common use cases of the scripting tool
@@ -150,6 +201,18 @@ Here are some common use cases of the scripting tool
150201

151202
For more details, please refer to the tool [guide](./shell.md).
152203

204+
### ARM64 JDK 17
205+
You can refer to the [start.sh.simple](start.sh.simple).
206+
207+
```bash
208+
# cp start.sh.simple start.sh
209+
# Usage:
210+
# sh start.sh # Start the java-tron FullNode
211+
# sh start.sh -s # Stop the java-tron FullNode
212+
# sh start.sh [options] # Start with additional java-tron options,such as: -c config.conf -d /path_to_data, etc.
213+
#
214+
```
215+
153216
## Run inside Docker container
154217

155218
One of the quickest ways to get `java-tron` up and running on your machine is by using Docker:

actuator/src/main/java/org/tron/core/vm/VM.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ public static void play(Program program, JumpTable jumpTable) {
108108
} catch (JVMStackOverFlowException | OutOfTimeException e) {
109109
throw e;
110110
} catch (RuntimeException e) {
111-
if (StringUtils.isEmpty(e.getMessage())) {
111+
// https://openjdk.org/jeps/358
112+
// https://bugs.openjdk.org/browse/JDK-8220715
113+
// since jdk 14, the NullPointerExceptions message is not empty
114+
if (e instanceof NullPointerException || StringUtils.isEmpty(e.getMessage())) {
112115
logger.warn("Unknown Exception occurred, tx id: {}",
113116
Hex.toHexString(program.getRootTransactionId()), e);
114117
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));

actuator/src/main/java/org/tron/core/vm/program/invoke/ProgramInvokeImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public boolean equals(Object o) {
314314

315315
@Override
316316
public int hashCode() {
317-
return new Integer(Boolean.valueOf(byTestingSuite).hashCode()
317+
return Boolean.valueOf(byTestingSuite).hashCode()
318318
+ Boolean.valueOf(byTransaction).hashCode()
319319
+ address.hashCode()
320320
+ balance.hashCode()
@@ -326,8 +326,7 @@ public int hashCode() {
326326
+ origin.hashCode()
327327
+ prevHash.hashCode()
328328
+ deposit.hashCode()
329-
+ timestamp.hashCode()
330-
).hashCode();
329+
+ timestamp.hashCode();
331330
}
332331

333332
@Override

actuator/src/main/java/org/tron/core/vm/repository/Type.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean equals(Object obj) {
7373

7474
@Override
7575
public int hashCode() {
76-
return new Integer(type).hashCode();
76+
return type;
7777
}
7878

7979
@Override

actuator/src/main/java/org/tron/core/vm/repository/Value.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public boolean equals(Object obj) {
5858

5959
@Override
6060
public int hashCode() {
61-
return new Integer(type.hashCode() + Objects.hashCode(value)).hashCode();
61+
return type.hashCode() + Objects.hashCode(value);
6262
}
6363
}

build.gradle

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
1+
import org.gradle.nativeplatform.platform.internal.Architectures
12
allprojects {
23
version = "1.0.0"
34
apply plugin: "java-library"
45
ext {
56
springVersion = "5.3.39"
67
}
78
}
9+
def arch = System.getProperty("os.arch").toLowerCase()
10+
def javaVersion = JavaVersion.current()
11+
def isArm64 = Architectures.AARCH64.isAlias(arch)
12+
def archSource = isArm64 ? "arm" : "x86"
13+
14+
ext.archInfo = [
15+
name : arch,
16+
java : javaVersion,
17+
isArm64 : isArm64,
18+
sourceSets: [
19+
main: [
20+
java: [
21+
srcDirs: ["src/main/java/common", "src/main/java/${archSource}"]
22+
]
23+
],
24+
test: [
25+
java: [
26+
srcDirs: ["src/test/java"]
27+
]
28+
]
29+
],
30+
requires: [
31+
JavaVersion: isArm64 ? JavaVersion.VERSION_17 : JavaVersion.VERSION_1_8,
32+
RocksdbVersion: isArm64 ? '7.7.3' : '5.15.10'
33+
],
34+
VMOptions: isArm64 ? "${rootDir}/gradle/jdk17/java-tron.vmoptions" : "${rootDir}/gradle/java-tron.vmoptions"
35+
]
36+
37+
if (!archInfo.java.is(archInfo.requires.JavaVersion)) {
38+
throw new GradleException("Java ${archInfo.requires.JavaVersion} is required for ${archInfo.name}. Detected version ${archInfo.java}")
39+
}
40+
41+
println "Building for architecture: ${archInfo.name}, Java version: ${archInfo.java}"
42+
843

944
subprojects {
1045
apply plugin: "jacoco"
1146
apply plugin: "maven-publish"
1247

1348
sourceCompatibility = JavaVersion.VERSION_1_8
14-
targetCompatibility = JavaVersion.VERSION_1_8
49+
targetCompatibility = JavaVersion.current()
1550

1651
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
1752
jacoco {
@@ -51,10 +86,16 @@ subprojects {
5186
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
5287
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
5388

54-
compileOnly 'org.projectlombok:lombok:1.18.12'
55-
annotationProcessor 'org.projectlombok:lombok:1.18.12'
56-
testCompileOnly 'org.projectlombok:lombok:1.18.12'
57-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
89+
compileOnly 'org.projectlombok:lombok:1.18.34'
90+
annotationProcessor 'org.projectlombok:lombok:1.18.34'
91+
testCompileOnly 'org.projectlombok:lombok:1.18.34'
92+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
93+
94+
// https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8190378
95+
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
96+
// for json-rpc, see https://github.com/briandilley/jsonrpc4j/issues/278
97+
implementation group: 'javax.jws', name: 'javax.jws-api', version: '1.1'
98+
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
5899

59100
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
60101
testImplementation "org.mockito:mockito-core:4.11.0"
@@ -73,6 +114,10 @@ subprojects {
73114
reproducibleFileOrder = true
74115
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
75116
}
117+
tasks.withType(Test).configureEach {
118+
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:environment
119+
environment 'CI', 'true'
120+
}
76121
}
77122

78123
task copyToParent(type: Copy) {

chainbase/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ dependencies {
1010
api project(":common")
1111
api project(":crypto")
1212
api "org.fusesource.jansi:jansi:$jansiVersion"
13-
api group: 'commons-io', name: 'commons-io', version: '2.18.0'
14-
api 'io.github.tronprotocol:zksnark-java-sdk:1.0.0' exclude(group: 'commons-io', module: 'commons-io')
1513
api 'org.reflections:reflections:0.9.11'
1614
}
1715

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.tron.common.storage;
2+
3+
import org.tron.common.setting.RocksDbSettings;
4+
import org.tron.common.utils.StorageUtils;
5+
6+
public class OptionsPicker {
7+
8+
protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
9+
return StorageUtils.getOptionsByDbName(dbName);
10+
}
11+
12+
protected org.rocksdb.Options getOptionsByDbNameForRocksDB(String dbName) {
13+
return RocksDbSettings.getOptionsByDbName(dbName);
14+
}
15+
}

0 commit comments

Comments
 (0)