Skip to content
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

arm64 #55

Closed
wants to merge 10 commits into from
  •  
  •  
  •  
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
55 changes: 45 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
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().isCompatibleWith(JavaVersion.VERSION_17)) {
throw new GradleException("Java 17 or later 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 {
toolVersion = "0.8.12" // see https://www.jacoco.org/jacoco/trunk/doc/changes.html
}
buildscript {
repositories {
mavenCentral()
Expand Down Expand Up @@ -46,30 +69,42 @@ 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'
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:2.13.0"
// see https://github.com/mockito/mockito/releases/tag/v5.0.0
// Mockito 5 update the minimum supported Java version to 11
// Mockito 4 supports Java 8 and above.
testImplementation "org.mockito:mockito-core:4.11.0"
}

task sourcesJar(type: Jar, dependsOn: classes) {
tasks.register('sourcesJar', Jar) {
dependsOn classes
classifier = "sources"
from sourceSets.main.allSource
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
}


tasks.withType(AbstractArchiveTask) {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
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) {
tasks.register('copyToParent', Copy) {
into "$buildDir/libs"
subprojects {
from tasks.withType(Jar)
Expand Down
4 changes: 0 additions & 4 deletions chainbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ description = "chainbase – a decentralized database for blockchain."

// Dependency versions
// ---------------------------------------
def jacocoVersion = "0.8.0"
def jansiVersion = "1.16"
// --------------------------------------

Expand Down Expand Up @@ -41,9 +40,6 @@ test {
}
}

jacoco {
toolVersion = jacocoVersion // See http://www.eclemma.org/jacoco/.
}

jacocoTestReport {
reports {
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 @@ -18,6 +18,7 @@
import static org.fusesource.leveldbjni.JniDBFactory.factory;

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 +31,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 +51,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 @@ -74,6 +72,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 @@ -109,6 +108,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 @@ -134,6 +137,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 @@ -361,6 +386,7 @@ public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
}
}

@Deprecated
@Override
public long getTotal() throws RuntimeException {
resetDbLock.readLock().lock();
Expand All @@ -377,13 +403,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 @@ -403,30 +422,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
Loading