[foreign-abi] RFR: JDK-8244601: Cleanup support for upcall handles

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu May 7 11:29:30 UTC 2020


This patch removes the SystemABI::freeUpcallStub routine and, in its place, allows SystemABI::upcallHandle to return
a *stub segment* which can be explicitly closed by the user.

I think having one less method in SystemABI is cleaner - but I'm not 100% sure that using a segment as the return type
is the way to go; I found myself split between returning MemoryAddress and MemorySegment while writing this patch. I
ultimately went for MemorySegment because I think it makes idiomatic code a tad cleaner (look at StdLibTest).

When writing this I also wondered if we couldn't benefit from a separate abstraction for callbacks - something like:

interface UpcallHandle extends AutoCloseable {
   MethodHandle handle();
   MemoryAddress address();
   void close();
}

And then teach SystemABI about this carrier (the translation into a raw address should be relatively painless). But
then we'd still need to support cases where the function pointer is obtained through another native call (in which case
the carrier will just be MemoryAddress). So I'm not sure in the end having this additional abstraction will change
things significantly compared to just having a segment and have the user calling `baseAddress`.

That said, I'm open to suggestions if people feel strongly one way or another.

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

Commit messages:
 - Cleanup support for callbacks

Changes: https://git.openjdk.java.net/panama-foreign/pull/154/files
 Webrev: https://webrevs.openjdk.java.net/panama-foreign/154/webrev.00
  Issue: https://bugs.openjdk.java.net/browse/JDK-JDK-8244601
  Stats: 93 lines in 10 files changed: 27 ins; 34 del; 32 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/154.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/154/head:pull/154

PR: https://git.openjdk.java.net/panama-foreign/pull/154


More information about the panama-dev mailing list