oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.4k stars 1.64k forks source link

GraalVM native with kotlin issue #8319

Open GrapeBaBa opened 9 months ago

GrapeBaBa commented 9 months ago

Describe the issue Our project https://github.com/optimism-java/hildr using https://github.com/libp2p/jvm-libp2p as dependency. When build as a jar, it works fine. After build as native, a method https://github.com/libp2p/jvm-libp2p/blob/24982eee203f72a96769fc103195c9807c61f425/libp2p/src/main/kotlin/io/libp2p/pubsub/PubsubApiImpl.kt#L64 seems not be called and no exception thrown.

Steps to reproduce the issue Please include both build steps as well as run steps

  1. clone https://github.com/optimism-java/hildr
  2. follow here

Describe GraalVM and your environment:

More details Add any other information about the problem here. Especially important are stack traces or log output. Feel free to link to gists or to screenshots if necessary.

oubidar-Abderrahim commented 9 months ago

Hi, Thank you for reaching out, did you try generating the configuration files using our Tracing agent? If not, please do so and check this doc for details: https://www.graalvm.org/22.3/reference-manual/native-image/metadata/AutomaticMetadataCollection/

vjovanov commented 9 months ago

Thanks for reporting this issue, adding more instructions would help reproduce this issue: which subproject, how to run, etc. Also, does this happen with the statically linked binary or with the regular one?

I would run the build with the latest GraalVM version (snapshot ideally) and add the flag -H:ThrowMissingRegistrationErrors= to see if it fails. Also, it would be good to have the output of -H:+PrintClassInitialization.

GrapeBaBa commented 9 months ago

Thanks for reporting this issue, adding more instructions would help reproduce this issue: which subproject, how to run, etc. Also, does this happen with the statically linked binary or with the regular one?

I would run the build with the latest GraalVM version (snapshot ideally) and add the flag -H:ThrowMissingRegistrationErrors= to see if it fails. Also, it would be good to have the output of -H:+PrintClassInitialization.

will do and feedback.

GrapeBaBa commented 8 months ago

Hi, Thank you for reaching out, did you try generating the configuration files using our Tracing agent? If not, please do so and check this doc for details: https://www.graalvm.org/22.3/reference-manual/native-image/metadata/AutomaticMetadataCollection/

Yes, we generated the files and works fine. Only this code seems not execution when compile to native.

GrapeBaBa commented 8 months ago

Thanks for reporting this issue, adding more instructions would help reproduce this issue: which subproject, how to run, etc. Also, does this happen with the statically linked binary or with the regular one?

I would run the build with the latest GraalVM version (snapshot ideally) and add the flag -H:ThrowMissingRegistrationErrors= to see if it fails. Also, it would be good to have the output of -H:+PrintClassInitialization.

@vjovanov it is easy to build and run, however it need some env config which include API key, how can I share it to you. And does this flag-H:ThrowMissingRegistrationErrors= need pass class name? I am using Oracle GraalVM 21.0.2+13.1 right now.

If only for build the native and don't run it, you can do below.

clone hildr
cd hildr
./gradlew :hildr-node:buildBinary

The native image gradle task is here https://github.com/optimism-java/hildr/blob/main/hildr-node/build.gradle#L349

Add -H:+PrintClassInitialization in my laptop , I see this info in the file class_initialization_report_20240225_163709.csv, it seems the class is initialized.
io.libp2p.pubsub.PubsubApiImpl, BUILD_TIME, class proven as side-effect free before analysis io.libp2p.pubsub.PubsubApiImpl$1, BUILD_TIME, class proven as side-effect free before analysis io.libp2p.pubsub.PubsubApiImpl$PublisherImpl, BUILD_TIME, class proven as side-effect free before analysis io.libp2p.pubsub.PubsubApiImpl$SubscriptionImpl, BUILD_TIME, class proven as side-effect free before analysis io.libp2p.pubsub.PubsubApiImpl$onNewMessage$1, BUILD_TIME, class proven as side-effect free before analysis io.libp2p.pubsub.PubsubApiImpl$validationResultReduce$1, BUILD_TIME, class proven as side-effect free before analysis

vjovanov commented 8 months ago

-H:ThrowMissingRegistrationErrors= is a build-time flag that throws when there is missing reflection metadata. It can be used in conjunction with -H:MissingRegistrationReportingMode=Warn to print missing elements, or -H:MissingRegistrationReportingMode=Exit to hard fail on missing elements.

GrapeBaBa commented 8 months ago

I feel it is possible a problem with network layer since it is a p2p library based UDP. Is there anything I need to pay attention to in such case?

vjovanov commented 8 months ago

Is the reflection configured properly? No exceptions when you use: -H:ThrowMissingRegistrationErrors=?

If no exceptions, you can send me the keys over the community slack: Slack channels