graal icon indicating copy to clipboard operation
graal copied to clipboard

GraalVM native with kotlin issue

Open GrapeBaBa opened this issue 1 year ago • 3 comments

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:

  • GraalVM version (latest snapshot builds can be found here), or commit id if built from source: [e.g. EE 19.3, CE 20.0, CE 20.1.0-dev-20200304_0848]
  • JDK major version: graal-jdk-21.0.2
  • OS: macOS or linux
  • Architecture: amd64

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.

GrapeBaBa avatar Feb 06 '24 05:02 GrapeBaBa

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/

oubidar-Abderrahim avatar Feb 06 '24 14:02 oubidar-Abderrahim

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 avatar Feb 06 '24 18:02 vjovanov

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 avatar Feb 07 '24 03:02 GrapeBaBa

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 avatar Feb 25 '24 07:02 GrapeBaBa

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

GrapeBaBa avatar Feb 25 '24 07:02 GrapeBaBa

-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.

vjovanov avatar Feb 26 '24 09:02 vjovanov

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?

GrapeBaBa avatar Mar 01 '24 06:03 GrapeBaBa

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

vjovanov avatar Mar 02 '24 00:03 vjovanov