JDK-8263997 : Remove old workaround for SIGFPE & FPE_INTDIV
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: os_x
  • Submitted: 2021-03-22
  • Updated: 2024-07-12
  • Resolved: 2024-07-12
Related Reports
Relates :  
Relates :  
Description
While investigating JDK-8263603 I noticed this code:

      if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
        // HACK: si_code does not work on bsd 2.2.12-20!!!
        int op = pc[0];
        if (op == 0xDB) {
          // FIST
          // TODO: The encoding of D2I in x86_32.ad can cause an exception
          // prior to the fist instruction if there was an invalid operation
          // pending. We want to dismiss that exception. From the win_32
          // side it also seems that if it really was the fist causing
          // the exception that we do the d2i by hand with different
          // rounding. Seems kind of weird.
          // NOTE: that we take the exception at the NEXT floating point instruction.
          assert(pc[0] == 0xDB, "not a FIST opcode");
          assert(pc[1] == 0x14, "not a FIST opcode");
          assert(pc[2] == 0x24, "not a FIST opcode");
          return true;
        } else if (op == 0xF7) {
          // IDIV
          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
        } else {
          // TODO: handle more cases if we are using other x86 instructions
          //   that can generate SIGFPE signal on bsd.
          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
          fatal("please update this code.");
        }
The Linux version has this comment:

// HACK: si_code does not work on linux 2.2.12-20!!!

Linux 2.2.12-20 according to https://en.wikipedia.org/wiki/Linux_kernel_version_history is from 20 years ago.

Dan thinks this code was just an unneeded code introduced from Linux-->BSD port task, so we should remove it.

Even on Linux, however, we surely don't need a workaround for a 20 year old Linux kernel - si_code does work correctly nowadays.

We should remove this dead code, that only adds complexity to the already complex POSIX signal handling.
Comments
Originally I meant mostly the code in os_bsd_x86.cpp, though the same workaround is in the linux version. In both cases we are dealing with x86, i.e. 32bit code, if I read the code correctly. Especially on BSD (i.e. mostly macOS?) x86 code is deprecated and runs via emulation layer (Rosetta). IMHO it's not a worthwhile effort anymore. Just to test the change here I would have to revive an old mac machine (x86,32bit).
12-07-2024

According to git (thanks Dan) this also comes from the Linux --> BSD port: oracle@dhcp-10-154-113-175 jdk % git blame src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp | grep "SIGFPE && info->si_code == FPE_NOOP" 95c56a472b9d hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp (Kurt Miller 2011-09-25 16:03:29 -0700 468) } else if (sig == SIGFPE && info->si_code == FPE_NOOP) { oracle@dhcp-10-154-113-175 jdk % git log 95c56a472b9d^! commit 95c56a472b9d4bcec5969f2463f550c18325d604 Author: Kurt Miller <kurt@intricatesoftware.com> Date: Sun Sep 25 16:03:29 2011 -0700 7089790: integrate bsd-port changes Co-authored-by: Greg Lewis <glewis@eyesbeyond.com> Co-authored-by: Jung-uk Kim <jkim@freebsd.org> Co-authored-by: Christos Zoulas <christos@zoulas.com> Co-authored-by: Landon Fuller <landonf@plausible.coop> Co-authored-by: The FreeBSD Foundation <board@freebsdfoundation.org> Co-authored-by: Michael Franz <mvfranz@gmail.com> Co-authored-by: Roger Hoover <rhoover@apple.com> Co-authored-by: Alexander Strange <astrange@apple.com> Reviewed-by: kvn, twisti, jrose
22-03-2021

There is also related code: } else if (sig == SIGFPE && info->si_code == FPE_NOOP) { int op = pc[0]; // Skip REX if ((pc[0] & 0xf0) == 0x40) { op = pc[1]; } else { op = pc[0]; } // Check for IDIV if (op == 0xF7) { stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO); } else { // TODO: handle more cases if we are using other x86 instructions // that can generate SIGFPE signal. tty->print_cr("unknown opcode 0x%X with SIGFPE.", op); fatal("please update this code."); }
22-03-2021