Skip to content

Commit 3f7796b

Browse files
authored
support JDK 21
support JDK 21
2 parents 878193e + d97090a commit 3f7796b

File tree

9 files changed

+67
-13
lines changed

9 files changed

+67
-13
lines changed

.github/workflows/build-and-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
uses: actions/setup-java@v4
145145
with:
146146
distribution: 'temurin'
147-
java-version: '17'
147+
java-version: '21'
148148
cache: 'maven'
149149

150150
- name: Build with Maven

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Support the project with XDAG donations:
3838

3939
### **1. Requirements**
4040

41-
- **JDK**: v17 or later
41+
- **JDK**: v21 or later
4242
- **Maven**: v3.9.9 or later
4343
- **CMake**: v3.5 or later
4444
- **GCC/Compiler**: GCC v4.8 or later (v7+ recommended for best performance)
@@ -115,7 +115,7 @@ To include `xdagj-native-randomx` in your project, add the following dependency
115115
<dependency>
116116
<groupId>io.xdag</groupId>
117117
<artifactId>xdagj-native-randomx</artifactId>
118-
<version>0.2.3</version>
118+
<version>0.2.4</version>
119119
</dependency>
120120
```
121121

pom.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.xdag</groupId>
88
<artifactId>xdagj-native-randomx</artifactId>
9-
<version>0.2.3</version>
9+
<version>0.2.4</version>
1010

1111
<name>xdagj-native-randomx</name>
1212
<description>A Java RandomX Library For XDAGJ</description>
@@ -17,8 +17,8 @@
1717
<!-- Build properties -->
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
20-
<maven.compiler.source>17</maven.compiler.source>
21-
<maven.compiler.target>17</maven.compiler.target>
20+
<maven.compiler.source>21</maven.compiler.source>
21+
<maven.compiler.target>21</maven.compiler.target>
2222

2323
<!-- Dependency versions -->
2424
<commons-lang3.version>3.17.0</commons-lang3.version>
@@ -81,6 +81,14 @@
8181
<configuration>
8282
<source>${maven.compiler.source}</source>
8383
<target>${maven.compiler.target}</target>
84+
<annotationProcessorPaths>
85+
<path>
86+
<groupId>org.projectlombok</groupId>
87+
<artifactId>lombok</artifactId>
88+
<version>${lombok.version}</version>
89+
</path>
90+
<!-- Add other annotation processors if needed -->
91+
</annotationProcessorPaths>
8492
</configuration>
8593
</plugin>
8694

@@ -91,6 +99,7 @@
9199
<configuration>
92100
<redirectTestOutputToFile>true</redirectTestOutputToFile>
93101
<printSummary>true</printSummary>
102+
<argLine>--enable-preview</argLine>
94103
</configuration>
95104
</plugin>
96105

@@ -151,6 +160,9 @@
151160
<groupId>org.apache.maven.plugins</groupId>
152161
<artifactId>maven-javadoc-plugin</artifactId>
153162
<version>${maven-javadoc-plugin.version}</version>
163+
<configuration>
164+
<source>${maven.compiler.source}</source>
165+
</configuration>
154166
<executions>
155167
<execution>
156168
<id>attach-javadocs</id>

src/main/java/io/xdag/crypto/randomx/Example.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
*/
3434
public class Example {
3535

36+
/**
37+
* Default constructor for the Example class.
38+
* This constructor is intentionally empty as this class primarily serves as a demonstration
39+
* with static methods or through its main method.
40+
*/
41+
public Example() {
42+
// Default constructor
43+
}
44+
3645
/**
3746
* Main method demonstrating the RandomX hashing process.
3847
* Shows initialization of RandomX components and hash calculation.

src/main/java/io/xdag/crypto/randomx/RandomXFlag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public enum RandomXFlag {
117117
* Each bit in the input value corresponds to a specific flag.
118118
*
119119
* @param flags The combined integer value of multiple flags
120-
* @return A set of RandomXFlag enums corresponding to the enabled bits
120+
* @return A set of RandomXFlag enums corresponding to the enabled bits.
121121
*/
122122
public static Set<RandomXFlag> fromValue(int flags) {
123123
EnumSet<RandomXFlag> result = EnumSet.noneOf(RandomXFlag.class);

src/main/java/io/xdag/crypto/randomx/RandomXLibraryLoader.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
final class RandomXLibraryLoader {
4141

4242
private static boolean isLoaded = false;
43-
private static String loadedLibraryPath = null; // Store the path of the loaded library for logging
43+
private static Path loadedLibraryPath = null; // Store the path of the loaded library
4444

4545
// Private constructor to prevent instantiation
4646
private RandomXLibraryLoader() {}
@@ -53,16 +53,19 @@ private RandomXLibraryLoader() {}
5353
*
5454
* @throws UnsatisfiedLinkError if the library cannot be loaded for any reason.
5555
* @throws Exception for other unexpected errors during loading.
56+
* @return Path to the loaded native library file, or null if already loaded or failed before critical point.
5657
*/
57-
public static synchronized void load() throws Exception {
58+
public static synchronized Path load() throws Exception {
5859
if (isLoaded) {
5960
log.info("Native library already loaded from: {}", loadedLibraryPath);
60-
return;
61+
return loadedLibraryPath; // Return cached path
6162
}
6263

64+
Path tempLibFilePath = null;
6365
try {
64-
File tempFile = extractAndLoadNativeLibrary();
65-
loadedLibraryPath = tempFile.getAbsolutePath();
66+
File tempFile = extractAndLoadNativeLibrary(); // This method now returns File
67+
tempLibFilePath = tempFile.toPath();
68+
loadedLibraryPath = tempLibFilePath; // Cache the path
6669

6770
String tempLibDir = tempFile.getParent();
6871
if (tempLibDir != null) {
@@ -79,10 +82,12 @@ public static synchronized void load() throws Exception {
7982

8083
isLoaded = true;
8184
log.info("RandomX native library loaded successfully via RandomXLibraryLoader from: {}", loadedLibraryPath);
85+
return loadedLibraryPath;
8286

8387
} catch (UnsatisfiedLinkError ule) { // Catch specifically from System.load()
8488
log.error("Failed to load native library (UnsatisfiedLinkError from System.load()): {}: {}",
85-
(loadedLibraryPath != null ? loadedLibraryPath : "<path not determined>"), ule.getMessage(), ule);
89+
(loadedLibraryPath != null ? loadedLibraryPath : (tempLibFilePath != null ? tempLibFilePath : "<path not determined>")),
90+
ule.getMessage(), ule);
8691
logLibraryPaths(); // Log paths for diagnostics
8792
throw ule; // Re-throw to be handled by RandomXNative's static block
8893
} catch (Exception e) {

src/main/java/io/xdag/crypto/randomx/RandomXNative.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
* This class registers the native methods after the library is successfully loaded.
3434
*/
3535
public class RandomXNative {
36+
/**
37+
* Private constructor to prevent instantiation.
38+
* This class provides static JNA mappings and should not be instantiated.
39+
*/
40+
private RandomXNative() {
41+
throw new UnsupportedOperationException("This is a JNA mapping class and cannot be instantiated");
42+
}
43+
3644
static {
3745
try {
3846
// Step 1: Initialize the library using the loader.

src/main/java/io/xdag/crypto/randomx/RandomXTemplate.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@
3838
@ToString
3939
@Slf4j
4040
public class RandomXTemplate implements AutoCloseable {
41+
/**
42+
* Private constructor to be used by the Lombok generated builder.
43+
* Direct instantiation is discouraged; use the builder pattern.
44+
*/
45+
private RandomXTemplate(boolean miningMode, Set<RandomXFlag> flags, RandomXCache cache, RandomXDataset dataset, RandomXVM vm, byte[] currentKey) {
46+
this.miningMode = miningMode;
47+
this.flags = flags;
48+
this.cache = cache;
49+
this.dataset = dataset;
50+
this.vm = vm;
51+
this.currentKey = currentKey;
52+
}
53+
4154
/** Flag indicating if the template is in mining mode */
4255
@Getter
4356
private final boolean miningMode;

src/main/java/io/xdag/crypto/randomx/RandomXUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
*/
3434
public final class RandomXUtils {
3535

36+
/**
37+
* Private constructor to prevent instantiation of this utility class.
38+
*/
39+
private RandomXUtils() {
40+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
41+
}
42+
3643
/**
3744
* The size of a RandomX hash in bytes (usually 32 bytes).
3845
*/

0 commit comments

Comments
 (0)