8261397: Try Catch Method Failing to Work When Dividing An Integer By 0

Reviewed-by: stuefe, prr, dcubed, dholmes
This commit is contained in:
Gerard Ziemski 2021-02-23 16:38:53 +00:00
parent 8a2f58907c
commit 0257caad38
3 changed files with 30 additions and 1 deletions

View File

@ -1063,6 +1063,11 @@ public:
static bool supports_clflushopt() { return ((_features & CPU_FLUSHOPT) != 0); }
static bool supports_clwb() { return ((_features & CPU_CLWB) != 0); }
#ifdef __APPLE__
// Is the CPU running emulated (for example macOS Rosetta running x86_64 code on M1 ARM (aarch64)
static bool is_cpu_emulated();
#endif
// support functions for virtualization detection
private:
static void check_virtualizations();

View File

@ -454,7 +454,10 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
#ifdef AMD64
if (sig == SIGFPE &&
(info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
(info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV
// Workaround for macOS ARM incorrectly reporting FPE_FLTINV for "div by 0"
// instead of the expected FPE_FLTDIV when running x86_64 binary under Rosetta emulation
MACOS_ONLY(|| (VM_Version::is_cpu_emulated() && info->si_code == FPE_FLTINV)))) {
stub =
SharedRuntime::
continuation_for_implicit_exception(thread,

View File

@ -25,3 +25,24 @@
#include "precompiled.hpp"
#include "runtime/os.hpp"
#include "runtime/vm_version.hpp"
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
bool VM_Version::is_cpu_emulated() {
int ret = 0;
size_t size = sizeof(ret);
// Is this process being ran in Rosetta (i.e. emulation) mode on macOS?
if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) {
// errno == ENOENT is a valid response, but anything else is a real error
if (errno != ENOENT) {
warning("unable to lookup sysctl.proc_translated");
}
}
return (ret==1);
}
#endif