Skip to content

Commit

Permalink
8319927: Log that IEEE rounding mode was corrupted by loading a library
Browse files Browse the repository at this point in the history
Reviewed-by: goetz, lucy
  • Loading branch information
MBaesken authored and pull[bot] committed Jan 30, 2024
1 parent 30dc6a0 commit 8342579
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
18 changes: 17 additions & 1 deletion src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ bool os::dll_address_to_library_name(address addr, char* buf,

void *os::Bsd::dlopen_helper(const char *filename, int mode) {
#ifndef IA32
bool ieee_handling = IEEE_subnormal_handling_OK();
if (!ieee_handling) {
Events::log_dll_message(nullptr, "IEEE subnormal handling check failed before loading %s", filename);
log_info(os)("IEEE subnormal handling check failed before loading %s", filename);
}

// Save and restore the floating-point environment around dlopen().
// There are known cases where global library initialization sets
// FPU flags that affect computation accuracy, for example, enabling
Expand All @@ -1004,7 +1010,17 @@ void *os::Bsd::dlopen_helper(const char *filename, int mode) {
// flags. Silently fix things now.
int rtn = fesetenv(&default_fenv);
assert(rtn == 0, "fesetenv must succeed");
assert(IEEE_subnormal_handling_OK(), "fsetenv didn't work");
bool ieee_handling_after_issue = IEEE_subnormal_handling_OK();

if (ieee_handling_after_issue) {
Events::log_dll_message(nullptr, "IEEE subnormal handling had to be corrected after loading %s", filename);
log_info(os)("IEEE subnormal handling had to be corrected after loading %s", filename);
} else {
Events::log_dll_message(nullptr, "IEEE subnormal handling could not be corrected after loading %s", filename);
log_info(os)("IEEE subnormal handling could not be corrected after loading %s", filename);
}

assert(ieee_handling_after_issue, "fesetenv didn't work");
}
#endif // IA32

Expand Down
21 changes: 18 additions & 3 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,12 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {

void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
#ifndef IA32
bool ieee_handling = IEEE_subnormal_handling_OK();
if (!ieee_handling) {
Events::log_dll_message(nullptr, "IEEE subnormal handling check failed before loading %s", filename);
log_info(os)("IEEE subnormal handling check failed before loading %s", filename);
}

// Save and restore the floating-point environment around dlopen().
// There are known cases where global library initialization sets
// FPU flags that affect computation accuracy, for example, enabling
Expand Down Expand Up @@ -1843,11 +1849,20 @@ void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
#ifndef IA32
// Quickly test to make sure subnormals are correctly handled.
if (! IEEE_subnormal_handling_OK()) {
// We just dlopen()ed a library that mangled the floating-point
// flags. Silently fix things now.
// We just dlopen()ed a library that mangled the floating-point flags.
// Attempt to fix things now.
int rtn = fesetenv(&default_fenv);
assert(rtn == 0, "fesetenv must succeed");
assert(IEEE_subnormal_handling_OK(), "fsetenv didn't work");
bool ieee_handling_after_issue = IEEE_subnormal_handling_OK();

if (ieee_handling_after_issue) {
Events::log_dll_message(nullptr, "IEEE subnormal handling had to be corrected after loading %s", filename);
log_info(os)("IEEE subnormal handling had to be corrected after loading %s", filename);
} else {
Events::log_dll_message(nullptr, "IEEE subnormal handling could not be corrected after loading %s", filename);
log_info(os)("IEEE subnormal handling could not be corrected after loading %s", filename);
}
assert(ieee_handling_after_issue, "fesetenv didn't work");
}
#endif // IA32
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @test
* @bug 8295159
* @summary DSO created with -ffast-math breaks Java floating-point arithmetic
* @run main/othervm/native compiler.floatingpoint.TestSubnormalDouble
* @run main/othervm/native -Xlog:os=info compiler.floatingpoint.TestSubnormalDouble
*/

package compiler.floatingpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @test
* @bug 8295159
* @summary DSO created with -ffast-math breaks Java floating-point arithmetic
* @run main/othervm/native compiler.floatingpoint.TestSubnormalFloat
* @run main/othervm/native -Xlog:os=info compiler.floatingpoint.TestSubnormalFloat
*/

package compiler.floatingpoint;
Expand Down

0 comments on commit 8342579

Please sign in to comment.