RFR: 7903597: Slim down RuntimeHelper

Jorn Vernee jvernee at openjdk.org
Fri Dec 1 18:07:45 UTC 2023


On Fri, 1 Dec 2023 16:58:12 GMT, Jorn Vernee <jvernee 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/resources/org/openjdk/jextract/impl/resources/RuntimeHelper.java.template line 67:

> 65:         try {
> 66:             return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType());
> 67:         } catch (ReflectiveOperationException ex) {

I've left this `upcallHandle` method since we use it to initialize a class-level constant in the FI classes. It's useful to have the try/catch be out-of-line like this so we don't have to emit `static` blocks.

test/jtreg/generator/testLinkageErrors/TestLinkageErrors.java line 70:

> 68:         assertThrowsULE(() -> x$SEGMENT(), "x");
> 69:         assertThrowsULE(() -> y$SEGMENT(), "y");
> 70:         assertThrowsULE(() -> pt$SEGMENT(), "pt");

I've cleaned up this test code a bit, since I had to change the check to look at the exception's cause as well, as we are now throwing the linkage error from the holder class, it can be wrapped into an ExceptionInInitializerError.

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

PR Review Comment: https://git.openjdk.org/jextract/pull/150#discussion_r1412388466
PR Review Comment: https://git.openjdk.org/jextract/pull/150#discussion_r1412365903


More information about the jextract-dev mailing list