[foreign-memaccess+abi] RFR: 8267989: Exceptions thrown during upcalls should be handled

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon May 31 18:06:31 UTC 2021

On Mon, 31 May 2021 17:39:41 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> Hi,
> This patch regularizes exception handling for exceptions thrown during upcalls. Exceptions thrown during upcalls are now always handled by printing out the stack trace and then calling `System::exit` (see the JBS issue for some motivation).
> I've added some documentation for the exception handling to `CLinker::upcallStub`, as well as a new public `int` constant in `CLinker` which is the error code that is passed to `System::exit`. The returned error code can also be configured by a system property, which for now is mostly useful for testing purposes to make sure we don't get a consistent false positive.
> Thanks,
> Jorn

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/CLinker.java line 239:

> 237:      * the corresponding native stub will be deallocated.
> 238:      * <p>
> 239:      * Any exceptions that occur during an upcall should be handled during the upcall. The target method handle

I think it is best to drop the first sentence, and go straight to the point, which is "The target method handle shoud not...".

Which reminds me, do we want to apply same logic we do for var handle combinators to detect if a method handle contains exceptions in its guts (by looking at signature of direct MH, or by looking for certain combinators).

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 380:

> 378:         if (specializedHandle.type().returnType() == void.class) {
> 379:             if (!upcall) {
> 380:                 closer = empty(methodType(void.class, Throwable.class)); // (Throwable) -> void

Shouldn't ProgrammableUpcallHandler do the same thing?


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

More information about the panama-dev mailing list