Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5219

Provide GraalVM metadata and substitutions

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.2.0
    • Affects Version/s: None
    • Component/s: GraalVM, Integrations
    • None
    • Fully Compatible
    • Needed
    • Hide

      Let's specify the following in our What's new:

      We added reachability metadata needed when GraalVM native image is used. This metadata is intended to spare application developers from collecting reachability metadata needed because of using the driver libraries.

      However, we do not include libjnidispatch and libmongocrypt resource entries, because we would have to specify entries for all supported platforms, a.k.a. targets, which significantly affects the size of native executables built using GraalVM native image. Please use this resource-config.json as an example on how to specify them explicitly if your application depends on org.mongodb:mongodb-crypt.

      Show
      Let's specify the following in our What's new: We added reachability metadata needed when GraalVM native image is used. This metadata is intended to spare application developers from collecting reachability metadata needed because of using the driver libraries. However, we do not include libjnidispatch and libmongocrypt resource entries, because we would have to specify entries for all supported platforms, a.k.a. targets, which significantly affects the size of native executables built using GraalVM native image. Please use this resource-config.json as an example on how to specify them explicitly if your application depends on org.mongodb:mongodb-crypt .

      To compile a Java application using Mongo into a native executable with GraalVM, you need:
       

      • a set of metadata configuring the compiler
      • a set of substitutions that transform the code during the native compilation

      The substitutions are there to reduce the footprint of the resulting executable and workaround features not supported by the native compiler.

      This issue is about migrating substitutions and metadata available in the Quarkus Mongo extension to the Mongo Java client project. It will simplify the maintenance and will prevent changes from breaking native compilation. 

      The idea would be to:

      • include the substitutions (files attached to this issue). You will need an additional (in the provided scope) dependency: org.graalvm.sdk:graal-sdk
      • add a META-INF/mongo/native-image.properties file in one of the artifact with the following metadata:

      Add the resource: com.mongodb.spi.dns.DnsClientProvider

      Register for reflection

      • com.mongodb.client.model.changestream.ChangeStreamDocument
      • com.mongodb.client.model.changestream.UpdateDescription
      • org.bson.types.ObjectId

      Initialize at runtime:

      • org.bson.types.ObjectId 
      • com.mongodb.internal.dns.DefaultDnsResolver

       
      The GraalVM gradle plugin should allow adding a few tests to make sure it works as expected.
        
      PS: I'm the main author of the MongoDB substitution and metadata from the Quarkus extension.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            clement.escoffier@gmail.com clement escoffier
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: