From 633b091068bb01e148ca5c51ebeef34f98142bab Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Sat, 9 Mar 2024 00:03:29 +0100 Subject: [PATCH] Update plugins, update dependencies, set source and target to java 21, update matrix ci, fix unit tests. --- .github/workflows/matrixci.yml | 6 +-- README.md | 2 +- pom.xml | 47 ++++++++++++------- .../ByteBufferUtility.java | 18 +++---- .../ByteBufferUtilityTest.java | 29 ++++++++++-- 5 files changed, 65 insertions(+), 37 deletions(-) diff --git a/.github/workflows/matrixci.yml b/.github/workflows/matrixci.yml index d9d7cbf..22b96e5 100644 --- a/.github/workflows/matrixci.yml +++ b/.github/workflows/matrixci.yml @@ -18,17 +18,13 @@ jobs: # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs matrix: # https://github.com/actions/setup-java#supported-distributions - javaversion: [ '11', '17', '19'] + javaversion: [ '21' ] javadistribution: ['adopt', 'adopt-openj9', 'corretto', 'liberica', 'microsoft', 'temurin', 'zulu'] # internally 'adopt-hotspot' is the same as 'adopt' # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources os: [macos-latest, ubuntu-latest, windows-latest] exclude: - javadistribution: 'microsoft' os: 'macos-latest' - - javadistribution: 'adopt-openj9' - javaversion: '19' - - javadistribution: 'microsoft' - javaversion: '19' runs-on: ${{ matrix.os }} steps: diff --git a/README.md b/README.md index a554730..879b828 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The main goal is to generate as fast as possible (Bitcoin/Altcoin) addresses usi Copyright (c) 2017-2024 Bernard Ladenthin. ## Requirments -* Java 11 or newer. Java 8 is not supported anymore. +* Java 21 or newer. Java 8, 11, 17 is not supported anymore. ## Quickstart 1. Download the binary (jar) from https://github.com/bernardladenthin/BitcoinAddressFinder/releases diff --git a/pom.xml b/pom.xml index 71c9399..8d67f99 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ Free high performance tool for fast scanning random Bitcoin, Bitcoin Cash, Bitcoin SV, Litecoin, Dogecoin, Dash, Zcash (and many more) private keys and finding addresses with balance. UTF-8 - 2.0.5 - 1.4.5 + 2.0.12 + 1.5.3 --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED @@ -80,8 +80,18 @@ org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 21 + 21 + + --add-exports + java.base/java.nio=ALL-UNNAMED + --add-exports + java.base/sun.nio.ch=ALL-UNNAMED + --add-exports + java.base/jdk.internal.misc=ALL-UNNAMED + --add-exports + java.base/jdk.internal.ref=ALL-UNNAMED + @@ -90,6 +100,7 @@ 1 false + @{argLine} --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED @@ -128,7 +139,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 + 3.2.5 org.apache.maven.plugins @@ -138,22 +149,22 @@ org.apache.maven.plugins maven-assembly-plugin - 3.4.2 + 3.6.0 org.apache.maven.plugins maven-enforcer-plugin - 3.1.0 + 3.4.1 org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.12.1 org.jacoco jacoco-maven-plugin - 0.8.8 + 0.8.11 org.eluder.coveralls @@ -179,17 +190,17 @@ org.bitcoinj bitcoinj-core - 0.16.1 + 0.16.2 com.google.guava guava - 31.1-jre + 33.0.0-jre com.google.code.gson gson - 2.10 + 2.10.1 org.slf4j @@ -204,29 +215,29 @@ org.projectlombok lombok - 1.18.24 + 1.18.30 provided org.lmdbjava lmdbjava - 0.8.2 + 0.9.0 org.jocl jocl - 2.0.4 + 2.0.5 commons-io commons-io - 2.11.0 + 2.15.1 commons-codec commons-codec - 1.15 + 1.16.1 com.github.sealedtx @@ -236,7 +247,7 @@ org.apache.maven maven-artifact - 3.8.6 + 3.9.6 diff --git a/src/main/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtility.java b/src/main/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtility.java index 35149f1..4e8925f 100644 --- a/src/main/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtility.java +++ b/src/main/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtility.java @@ -19,9 +19,8 @@ package net.ladenthin.bitcoinaddressfinder; import java.nio.ByteBuffer; -import jdk.internal.ref.Cleaner; +import jdk.internal.misc.Unsafe; import org.bouncycastle.util.encoders.Hex; -import sun.nio.ch.DirectBuffer; public class ByteBufferUtility { @@ -45,15 +44,16 @@ public void freeByteBuffer(ByteBuffer byteBuffer) { if (byteBuffer == null) { return; } - if (! (byteBuffer instanceof DirectBuffer)) { + + if (!byteBuffer.isDirect()) { return; } - DirectBuffer directBuffer = (DirectBuffer) byteBuffer; - - Cleaner cleaner = directBuffer.cleaner(); - if (cleaner != null) { - cleaner.clean(); - } + + Unsafe u = Unsafe.getUnsafe(); + // https://bugs.openjdk.org/browse/JDK-8171377 + // https://openjdk.org/jeps/8323072 + // https://stackoverflow.com/questions/3496508/deallocating-direct-buffer-native-memory-in-java-for-jogl/26777380 + u.invokeCleaner(byteBuffer); } // diff --git a/src/test/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtilityTest.java b/src/test/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtilityTest.java index a3a5ce7..1d4668d 100644 --- a/src/test/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtilityTest.java +++ b/src/test/java/net/ladenthin/bitcoinaddressfinder/ByteBufferUtilityTest.java @@ -94,8 +94,7 @@ public void freeByteBuffer_freeAGivenByteBuffer_noExceptionThrown(boolean alloca // pre assert if (allocateDirect) { - long address = getAddressFromDirectBuffer((DirectBuffer)bytesAsByteBuffer); - assertThat(address, is(not(equalTo(0L)))); + assertThat(isDirectBufferFreed((DirectBuffer)bytesAsByteBuffer), is(false)); } // act @@ -103,8 +102,7 @@ public void freeByteBuffer_freeAGivenByteBuffer_noExceptionThrown(boolean alloca // assert if (allocateDirect) { - long address = getAddressFromDirectBuffer((DirectBuffer)bytesAsByteBuffer); - assertThat(address, is(equalTo(0L))); + assertThat(isDirectBufferFreed((DirectBuffer)bytesAsByteBuffer), is(true)); } } @@ -235,4 +233,27 @@ private long getAddressFromDirectBuffer(DirectBuffer directBuffer) throws Illega return addressField.getLong(deallocator); } + private boolean isDirectBufferFreed(DirectBuffer directBuffer) throws IllegalArgumentException, NoSuchFieldException, SecurityException, IllegalAccessException { + // does not work with newer JVMs (21) anymore + boolean testWithAddress = false; + boolean addressTest = true; + + Cleaner cleaner = directBuffer.cleaner(); + + Field nextField = cleaner.getClass().getDeclaredField("next"); + nextField.setAccessible(true); + Object next = nextField.get(cleaner); + + Field prevField = cleaner.getClass().getDeclaredField("prev"); + prevField.setAccessible(true); + Object prev = prevField.get(cleaner); + + if (testWithAddress) { + long address = getAddressFromDirectBuffer((DirectBuffer)directBuffer); + addressTest = address == 0L; + } + + return next == prev && addressTest; + } + }