Skip to content

Commit

Permalink
Update plugins, update dependencies, set source and target to java 21…
Browse files Browse the repository at this point in the history
…, update matrix ci, fix unit tests.
  • Loading branch information
bernardladenthin committed Mar 8, 2024
1 parent a0905e2 commit 633b091
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/matrixci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 29 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<description>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.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>2.0.5</slf4j.version>
<logback.version>1.4.5</logback.version>
<slf4j.version>2.0.12</slf4j.version>
<logback.version>1.5.3</logback.version>
<argLine>--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</argLine>
</properties>

Expand Down Expand Up @@ -80,8 +80,18 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>21</source>
<target>21</target>
<compilerArgs>
<arg>--add-exports</arg>
<arg>java.base/java.nio=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/sun.nio.ch=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/jdk.internal.misc=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/jdk.internal.ref=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand All @@ -90,6 +100,7 @@
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>@{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</argLine>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -128,7 +139,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -138,22 +149,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<version>3.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<version>0.8.11</version>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
Expand All @@ -179,17 +190,17 @@
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>33.0.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -204,29 +215,29 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.lmdbjava</groupId>
<artifactId>lmdbjava</artifactId>
<version>0.8.2</version>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.jocl</groupId>
<artifactId>jocl</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>com.github.sealedtx</groupId>
Expand All @@ -236,7 +247,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.8.6</version>
<version>3.9.6</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}

// <editor-fold defaultstate="collapsed" desc="ByteBuffer byte array conversion">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,15 @@ 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
byteBufferUtility.freeByteBuffer(bytesAsByteBuffer);

// assert
if (allocateDirect) {
long address = getAddressFromDirectBuffer((DirectBuffer)bytesAsByteBuffer);
assertThat(address, is(equalTo(0L)));
assertThat(isDirectBufferFreed((DirectBuffer)bytesAsByteBuffer), is(true));
}
}

Expand Down Expand Up @@ -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;
}

}

0 comments on commit 633b091

Please sign in to comment.