Graal Native Image #248
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#248
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Graal Native Image for JDK 24 has experimental support for the FFM API: https://www.graalvm.org/jdk24/reference-manual/native-image/native-code-interoperability/foreign-interface/
It would be nice if java-gi would support this. To make it work, the java-gi bindings generator must generate a GraalVM “ForeignRegistrationFeature” class that registers all downcall and upcall FunctionDescriptiors used in the module.
Notes:
-H:+UnlockExperimentalVMOptionsand-H:+ForeignAPISupportIn my experience with my own libraries, most cases of reflection can also be covered by an annotation processor, which makes native image easier and means less magic, which I think is cleaner.
At a minimum, an AP seems like a good fit for
GtkTemplate(potentially in combination with a ServiceLoader if early discovery is needed)I'd love to replace the reflection code with an annotation processor 🙂
With early discovery, do you mean that it could be used to register Java classes as GTypes during startup? That would be really useful.
Exactly. An annotation processor can output resource files, which includes the resource files used for the service loader mechanism. This is what AutoService is built on, for example.
At runtime, a different component can then invoke the service loader to automatically discover the classes the annotation processor registered. You can even use the AP to generate a glue class that performs the actual registration and register that instead, which makes this more resilient by not relying on no-arg constructors in user code to generate instances.
Yes the "glue class" would call
GObjects.typeRegisterStaticSimple(),GObjects.typeAddInterfaceStatic()etc with the correct names, types and properties from the annotated class.Using a ServiceLoader for this is really neat. I've been looking at Classgraph to scan the classpath for GObject-derived classes, but a ServiceLoader is just perfect for this.