Skip to content
New issue

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

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

Already on GitHub? # to your account

WIP: Graal native-image build of Java Schnorr Example #29

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

msgilligan
Copy link
Member

@msgilligan msgilligan commented Mar 20, 2024

To build native image use:

./gradlew secp-examples-java:nativeCompile

Currently requires Graal JDK 25-ea

@msgilligan msgilligan requested a review from schildbach March 20, 2024 15:17
@msgilligan
Copy link
Member Author

msgilligan commented Mar 20, 2024

It also looks like some additional build configuration will be required:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md

Update: The PR now includes this work (a somewhat rushed job of it, I must admit) but should build and run on AMD64 machines.

@msgilligan msgilligan force-pushed the msgilligan/graaltest branch from c0bc17a to e33c9c7 Compare March 20, 2024 20:18
@schildbach
Copy link
Member

As already mentioned elsewhere, I was able to build and run this successfully:

$ LD_LIBRARY_PATH=/nix/store/1c403w3lffz5p21lqqcvryh56ib0i28q-secp256k1-0.4.1/lib time -v secp256k1-examples-java/build/schnorrRunning secp256k1-jdk Schnorr example...
Is the signature valid? true
Secret Key: c6bf161b6530f588451b3790140722eb6de756164efc49baa1387f16b9089dac
Public Key (as ECPoint): 70176dcf4283032d089003785fce826ed7fa8e58c6a6a82ac27db4378d46ce50
Signature: 7ec2637314505842493670018a2e9b67ac0f63faf207640da4c206c2b2e89dcdaf0349608d40bec4c9f18ea2028eee70defd2e5bae1b7cada886ae88cfa7badd
	Command being timed: "secp256k1-examples-java/build/schnorr"
	User time (seconds): 0.00
	System time (seconds): 0.00
	Percent of CPU this job got: 100%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 19520
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 1225
	Voluntary context switches: 12
	Involuntary context switches: 1
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

@msgilligan msgilligan force-pushed the msgilligan/graaltest branch 2 times, most recently from ae1f7e3 to 0cd5fae Compare April 15, 2024 14:57
@msgilligan
Copy link
Member Author

msgilligan commented Mar 14, 2025

Looks like Graal JDK 25 will be the one: oracle/graal#8113 (comment)

Once we have a JDK 25-ea and a Gradle that can build for it, we should rebase and update this PR.

Update: The build can be done under JDK 23/24 with only native-image running under JDK 25 (-ea)

This is now rebased for JDK 25-ea and can compile because only native-image
is run on JDK 25 and it is not run directly from Gradle.

To build native image use:

./gradlew secp-examples-java:nativeCompile

Running does not work on aarch64-macOS and has not been tested on Linux.


Note: the Arena.ofConfined() change should probably not be merged to `master`,
but is currently necessary to work with native-image.

# Conflicts:
#	secp-examples-java/src/main/java/org/bitcoinj/secp/examples/ForeignRegistrationFeature.java
#	secp-integration-test/src/test/java/org/bitcoinj/secp/integration/package-info.java
#	secp256k1-examples-java/build.gradle
@msgilligan msgilligan force-pushed the msgilligan/graaltest branch from 0cd5fae to ce2d38c Compare March 20, 2025 23:53
@msgilligan
Copy link
Member Author

msgilligan commented Mar 21, 2025

Current error on aarch64-darwin and aarch64-linux is:

$ ./secp-examples-java/build/schnorr 
Running secp256k1-jdk Schnorr example...
Exception in thread "main" java.util.NoSuchElementException: Default Provider not found.
	at org.bitcoinj.secp.api.Secp256k1Provider.lambda$find$2(Secp256k1Provider.java:59)
	at java.base@25/java.util.Optional.orElseThrow(Optional.java:403)
	at org.bitcoinj.secp.api.Secp256k1Provider.find(Secp256k1Provider.java:59)
	at org.bitcoinj.secp.api.Secp256k1.get(Secp256k1.java:84)
	at org.bitcoinj.secp.examples.Schnorr.main(Schnorr.java:37)
	at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

I suspect the native-image command needs to be updated to use --module-path (or similar) properly.

I haven't tested on x86_64.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants