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

Jorn Vernee jvernee at openjdk.java.net
Wed Jun 2 12:33:46 UTC 2021


On Wed, 2 Jun 2021 12:26:20 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
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Eagerly check whether upcall target throws any exceptions.
>   
>   Adapt the existing exception check done by MemoryHandles to be more lenient towards bound method handles which might or might not throw an exception, and re-use that check.

I've now added the eager exception checking to upcallStub.

As discussed offline, this reuses the exception check done for the VarHandle adapters, but makes the check more lenient towards BoundMetrhodHandles that might or might not throw an exception. The current check was too conservative toward rejecting such handles, because it rejects a BoundMehtodHandle that contained any MethodHandle field that could throw an exception. But, such an exception might be caught be an exclosing method handle. (see also https://bugs.openjdk.java.net/browse/JDK-8268031)

Instead, when a filter used for a var handle combinator throws a checked a exception when invoked, it is caught, and an IllegalStateException is thrown instead (with the original exception as the cause).

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

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


More information about the panama-dev mailing list