RFR: 7903597: Slim down RuntimeHelper

Jorn Vernee jvernee at openjdk.org
Fri Dec 1 22:34:28 UTC 2023


On Fri, 1 Dec 2023 22:11:12 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Remove some of the helper methods in RuntimeHelper. They can be moved inline in the generated code.
>> 
>> Also: I've elected to move the `System.load(Library)` directives we generated inside RuntimeHelper into the first header class, in order to have it more localized to the actual code that a user sees. That also makes RuntimeHelper more 'dumb'. Only the package declaration is now injected into the template, which makes it easier for users to combined multiple extraction runs (they can just discard one of the generated RuntimeHelpers).
>
> src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java line 248:
> 
>> 246:     }
>> 247: 
>> 248:     void emitLoadLibraries(List<String> libraries) {
> 
> To be fair, moving forward I'm not too convinced about  keeping this section. That is, perhaps it would be better to give up trying to use static jextract options to configure which library is loaded at runtime, and use a loader lookup. The client code can then side-effect the classloader by making sure the correct library is loaded.

Right, I was thinking of dropping it, but I've kept it for now, since we also fall back to the default lookup, and I'm not sure how important that is.

> src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java line 299:
> 
>> 297:         appendLines(STR."""
>> 298:             \{MEMBER_MODS} MemorySegment \{mangledName}() {
>> 299:                 class Holder {
> 
> I was ambivalent on this - but it's probably better to make it consistent with the strategy we use for functions, as you have done.

Yeah, if we wanted to remove `requireNonNull` we need to make the symbol lookup lazy in case it is not an a particular version of the library.

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/150#discussion_r1412628977
PR Review Comment: https://git.openjdk.org/jextract/pull/150#discussion_r1412628643


More information about the jextract-dev mailing list