In java, “5/0” statement doesn't fire SIGFPE signal on my Linux machine, why?

后端 未结 6 1684
庸人自扰
庸人自扰 2021-01-18 17:04

I wrote a very simple c program:

#include

int main(){
    int a=2;
    int b=0;
    printf(\"%d\\n\", a/b);
}

and run it wi

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 17:31

    It might be that VM tests the divisor for 0 manually in emulated bytecode (for simplicity of implementation), but for performance will still switch to detecting the SIGFPE signal in JIT'd code. Try putting the division code in its own subroutine and call it in a loop thousands of times to ensure it gets compiled.

提交回复
热议问题