RFR: 8261397: Try Catch Method Failing to Work When Dividing An Integer By 0
Gerard Ziemski
gziemski at openjdk.java.net
Wed Feb 17 19:35:42 UTC 2021
On Wed, 17 Feb 2021 19:06:45 GMT, Gerard Ziemski <gziemski at openjdk.org> wrote:
> On Mac ARM hardware running x86 JDK under Rosetta emulation, a div by 0 instruction causes the VM to crash.
>
> The proposed fix (a workaround) for hotspot is to add **FPE_FLTINV** to the signal handler.
>
> The actual fix needs to be done in macOS by Apple as the expected signal type here is **FPE_FLTDIV**
> This issue has been filed with Apple and they are tracking it.
Simple native test case for those curious to try it out for themselves:
/*
Natively on x86_64 we get:
sigHandler caught sig: 8, info->si_code: 7 [FPE_INTDIV]
Under Rossetta on M1 for x86_64 binary we get:
sigHandler caught sig: 8, info->si_code: 5 [FPE_FLTINV]
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static void sigHandler(int sig, siginfo_t* info, void* arg) {
printf("sigHandler caught sig: %d, info->si_code: %d [", sig, info->si_code);
switch (info->si_code) {
case FPE_FLTDIV: printf("FPE_FLTDIV");break;
case FPE_INTDIV: printf("FPE_INTDIV");break;
case FPE_FLTINV: printf("FPE_FLTINV");break;
default: printf("???");
}
printf("]\n");
exit(sig);
}
int main(int argc, const char * argv[]) {
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = sigHandler;
sa.sa_flags = SA_SIGINFO|SA_RESETHAND;
sigaction(SIGFPE, &sa, NULL);
volatile int i = 0;
volatile int j = 47 / i;
return j;
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/2615
More information about the hotspot-runtime-dev
mailing list