Skip to content

feat(architecture): support arm64 based on JDK17 #6327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: release_v4.8.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5ea7b5c
feat(jvm/JEP-358): enhance NullPointerException handling
halibobo1205 Jul 16, 2024
1b60b53
feat(jvm/JEP-223): use java.specification.version
halibobo1205 Jul 25, 2024
c9a241a
feat(jvm/JDK-8176425): Add radix indication in NumberFormatException …
halibobo1205 Mar 15, 2025
4ab433a
feat(jvm/JEP-277): remove deprecated and marked for removal code
halibobo1205 Mar 15, 2025
eb023b2
feat(jvm/JEP-286): remove lombok.var
halibobo1205 Oct 16, 2024
359d36f
feat(dependencies): update dependencies for jdk17
halibobo1205 Aug 2, 2024
9554a25
feat(JVM): add jvm options for jdk17
halibobo1205 Nov 18, 2024
9352bc7
feat(docker): support ARM64
halibobo1205 Dec 4, 2024
e30e2f3
feat(db): keep leveldb and rocksdb same behaviors for db operations
halibobo1205 Nov 20, 2024
1b2e026
feat(db): remove rocksDB compatibility with LevelDB
halibobo1205 Oct 21, 2024
673b90a
feat(db): update leveldb and rocksdb for arm
halibobo1205 Nov 9, 2024
bc8a34d
feat(math): add hard-code for arm pow
halibobo1205 Mar 14, 2025
e826346
test(ci):fix test failed
halibobo1205 May 12, 2025
6494695
feat(db): mark `allKeys`,`allValues`,`getTotal` as `Deprecated` and `…
halibobo1205 Jul 2, 2025
c439fb8
feat(*): remove redundant boxing
halibobo1205 Jul 2, 2025
7a4a82a
feat(db): make market_pair_price_to_order as Constant
halibobo1205 Jul 7, 2025
e874f8a
feat(math): change POW to EXPONENT for better name
halibobo1205 Jul 7, 2025
af88f9b
feat(Market): Unify comparePrice
halibobo1205 Jul 7, 2025
113fef0
feat(db): optimize RocksDB configuration for CI environments to reduc…
halibobo1205 Jul 7, 2025
f1278b1
feat(doc): add main-net notes for hard-code pow
halibobo1205 Jul 14, 2025
e5055a7
feat(test): add test for hashcode and web3_clientVersion
halibobo1205 Jul 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion actuator/src/main/java/org/tron/core/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public static void play(Program program, JumpTable jumpTable) {
} catch (JVMStackOverFlowException | OutOfTimeException e) {
throw e;
} catch (RuntimeException e) {
if (StringUtils.isEmpty(e.getMessage())) {
// https://openjdk.org/jeps/358
// https://bugs.openjdk.org/browse/JDK-8220715
// since jdk 14, the NullPointerExceptions message is not empty
if (e instanceof NullPointerException || StringUtils.isEmpty(e.getMessage())) {
logger.warn("Unknown Exception occurred, tx id: {}",
Hex.toHexString(program.getRootTransactionId()), e);
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return new Integer(Boolean.valueOf(byTestingSuite).hashCode()
return Boolean.valueOf(byTestingSuite).hashCode()
+ Boolean.valueOf(byTransaction).hashCode()
+ address.hashCode()
+ balance.hashCode()
Expand All @@ -326,8 +326,7 @@ public int hashCode() {
+ origin.hashCode()
+ prevHash.hashCode()
+ deposit.hashCode()
+ timestamp.hashCode()
).hashCode();
+ timestamp.hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return new Integer(type).hashCode();
return type;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return new Integer(type.hashCode() + Objects.hashCode(value)).hashCode();
return type.hashCode() + Objects.hashCode(value);
}
}
41 changes: 36 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import org.gradle.nativeplatform.platform.internal.Architectures
allprojects {
version = "1.0.0"
apply plugin: "java-library"
}

static def isX86() {
def arch = System.getProperty("os.arch").toLowerCase()
return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch)
}

static def isArm64() {
def arch = System.getProperty("os.arch").toLowerCase()
return new Architectures.KnownArchitecture("arm64", "aarch64").isAlias(arch)
}

if (isArm64() && !JavaVersion.current().is(JavaVersion.VERSION_17)) {
throw new GradleException("Java 17 is required to build Java-Tron for arm64.\n" +
" Detected version ${JavaVersion.current()}")
}

if (isX86() && !JavaVersion.current().isJava8()) {
throw new GradleException("Java 8 is required to build Java-Tron for x86.\n" +
" Detected version ${JavaVersion.current()}")
}

subprojects {
apply plugin: "jacoco"
apply plugin: "maven-publish"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.current()

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
jacoco {
Expand Down Expand Up @@ -49,10 +70,16 @@ subprojects {
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'

compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'

// https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8190378
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
// for json-rpc, see https://github.com/briandilley/jsonrpc4j/issues/278
implementation group: 'javax.jws', name: 'javax.jws-api', version: '1.1'
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation "org.mockito:mockito-core:4.11.0"
Expand All @@ -71,6 +98,10 @@ subprojects {
reproducibleFileOrder = true
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
}
tasks.withType(Test).configureEach {
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:environment
environment 'CI', 'true'
}
}

task copyToParent(type: Copy) {
Expand Down
15 changes: 15 additions & 0 deletions chainbase/src/main/java/org/tron/common/storage/OptionsPicker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.tron.common.storage;

import org.tron.common.setting.RocksDbSettings;
import org.tron.common.utils.StorageUtils;

public class OptionsPicker {

protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
return StorageUtils.getOptionsByDbName(dbName);
}

protected org.rocksdb.Options getOptionsByDbNameForRocksDB(String dbName) {
return RocksDbSettings.getOptionsByDbName(dbName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import static org.fusesource.leveldbjni.JniDBFactory.factory;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import com.google.common.primitives.Bytes;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -30,18 +32,14 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.google.common.primitives.Bytes;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Logger;
Expand All @@ -54,6 +52,7 @@
import org.tron.common.storage.WriteOptionsWrapper;
import org.tron.common.storage.metric.DbStat;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.PropUtil;
import org.tron.common.utils.StorageUtils;
import org.tron.core.db.common.DbSourceInter;
import org.tron.core.db.common.iterator.StoreIterator;
Expand All @@ -75,6 +74,7 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();
private static final String LEVELDB = "LEVELDB";
private static final org.slf4j.Logger innerLogger = LoggerFactory.getLogger(LEVELDB);
private static final String KEY_ENGINE = "ENGINE";
private Logger leveldbLogger = new Logger() {
@Override
public void log(String message) {
Expand Down Expand Up @@ -110,6 +110,10 @@ public LevelDbDataSourceImpl(String parentPath, String dataBaseName) {

@Override
public void initDB() {
if (!checkOrInitEngine()) {
throw new RuntimeException(
String.format("failed to check database: %s, engine do not match", dataBaseName));
}
resetDbLock.writeLock().lock();
try {
logger.debug("Init DB: {}.", dataBaseName);
Expand All @@ -135,6 +139,28 @@ public void initDB() {
}
}

private boolean checkOrInitEngine() {
String dir = getDbPath().toString();
String enginePath = dir + File.separator + "engine.properties";

if (FileUtil.createDirIfNotExists(dir)) {
if (!FileUtil.createFileIfNotExists(enginePath)) {
return false;
}
} else {
return false;
}

// for the first init engine
String engine = PropUtil.readProperty(enginePath, KEY_ENGINE);
if (engine.isEmpty() && !PropUtil.writeProperty(enginePath, KEY_ENGINE, LEVELDB)) {
return false;
}
engine = PropUtil.readProperty(enginePath, KEY_ENGINE);

return LEVELDB.equals(engine);
}

private void openDatabase(Options dbOptions) throws IOException {
final Path dbPath = getDbPath();
if (dbPath == null || dbPath.getParent() == null) {
Expand Down Expand Up @@ -226,6 +252,7 @@ public void deleteData(byte[] key) {
}

@Deprecated
@VisibleForTesting
@Override
public Set<byte[]> allKeys() {
resetDbLock.readLock().lock();
Expand All @@ -243,6 +270,7 @@ public Set<byte[]> allKeys() {
}

@Deprecated
@VisibleForTesting
@Override
public Set<byte[]> allValues() {
resetDbLock.readLock().lock();
Expand Down Expand Up @@ -362,6 +390,8 @@ public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
}
}

@Deprecated
@VisibleForTesting
@Override
public long getTotal() throws RuntimeException {
resetDbLock.readLock().lock();
Expand All @@ -378,13 +408,6 @@ public long getTotal() throws RuntimeException {
}
}

private void updateByBatchInner(Map<byte[], byte[]> rows) throws Exception {
try (WriteBatch batch = database.createWriteBatch()) {
innerBatchUpdate(rows,batch);
database.write(batch, writeOptions);
}
}

private void updateByBatchInner(Map<byte[], byte[]> rows, WriteOptions options) throws Exception {
try (WriteBatch batch = database.createWriteBatch()) {
innerBatchUpdate(rows,batch);
Expand All @@ -404,30 +427,23 @@ private void innerBatchUpdate(Map<byte[], byte[]> rows, WriteBatch batch) {

@Override
public void updateByBatch(Map<byte[], byte[]> rows, WriteOptionsWrapper options) {
resetDbLock.readLock().lock();
try {
updateByBatchInner(rows, options.level);
} catch (Exception e) {
try {
updateByBatchInner(rows, options.level);
} catch (Exception e1) {
throw new RuntimeException(e);
}
} finally {
resetDbLock.readLock().unlock();
}
this.updateByBatch(rows, options.level);
}

@Override
public void updateByBatch(Map<byte[], byte[]> rows) {
this.updateByBatch(rows, writeOptions);
}

private void updateByBatch(Map<byte[], byte[]> rows, WriteOptions options) {
resetDbLock.readLock().lock();
try {
updateByBatchInner(rows);
updateByBatchInner(rows, options);
} catch (Exception e) {
try {
updateByBatchInner(rows);
updateByBatchInner(rows, options);
} catch (Exception e1) {
throw new RuntimeException(e);
throw new RuntimeException(e1);
}
} finally {
resetDbLock.readLock().unlock();
Expand Down
Loading