RFR: 8366145: Help diagnose ubsan failure

Thomas Schatzl tschatzl at openjdk.org
Wed Aug 27 09:20:46 UTC 2025


On Tue, 26 Aug 2025 11:22:30 GMT, Leo Korinth <lkorinth at openjdk.org> wrote:

> This pull request is created to help diagnose the bug report https://bugs.openjdk.org/browse/JDK-8354430.
> 
> The problem is that we get a ubsan runtime error when dividing by zero. Ubsan is not normally running, so I will add an assert making it easier to catch the problem and printing the value of the two variables that when subtracted will create a zero; it will hopefully help with diagnosis.
> 
> Some comments: 
> 1) the result of `most_recent_gc_end_time_sec()` will not change within the function, thus I will not clutter the code with a new variable, is that okay?
> 2) I added two calls to `fabs` which are most probably not needed (ieee floating point rules seems to say that positive and negative zero equals). However I think my proposed code makes it clear that I have thought about it. 
> 
> I am now running tier1-3

The CR title should be more specific, possibly mentioning both the approximate issue and failure and/or the CR number.

E.g. `Help diagnose ubsan division by zero in computing pause time ratios` or something.

src/hotspot/share/gc/g1/g1Analytics.cpp line 167:

> 165: 
> 166:   double short_interval_ms = (end_time_sec - most_recent_gc_end_time_sec()) * 1000.0;
> 167:   assert(fabs(short_interval_ms) != fabs(0.0), "short_interval_ms should not be zero, calculated from %f and %f", end_time_sec,  most_recent_gc_end_time_sec());

Not sure why one would need the `fabs(0.0)`. It simply returns `0.0`.
Suggestion:

  assert(fabs(short_interval_ms) != 0.0, "short_interval_ms should not be zero, calculated from %f and %f", end_time_sec,  most_recent_gc_end_time_sec());

Maybe even compare against some very small epsilon, which would also be suspicious given that pauses smaller than a nanosecond or so seem suspicious in any case.

-------------

Changes requested by tschatzl (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/26939#pullrequestreview-3159020811
PR Review Comment: https://git.openjdk.org/jdk/pull/26939#discussion_r2303369293


More information about the hotspot-gc-dev mailing list