JDK-8314157 : G1: "yielded" is not initialized on some paths after JDK-8140326
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-08-11
  • Updated: 2023-08-28
  • Resolved: 2023-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b12Fixed
Related Reports
Relates :  
Description
SonarCloud has a new warning after JDK-8140326:

```
        bool yielded;
        bool mark_aborted = yield_if_necessary(yielded);
        if (mark_aborted) {
...
        } else if (yielded && !should_rebuild_or_scrub(hr)) { // <--- Branch condition evaluates to a garbage value
...
        }
```

This warning is about `yielded` being not initialized on some paths, reading the garbage value from it on branch checks.

There are other uses of `yield_if_necessary`, and at some uses we initialize `yielded = true`. This seems a bit awkward in itself: we are assuming the yield happened even without checking it in yield_if_necessary. It is therefore unclear what should be the default value in other cases.
Comments
Changeset: 742e319a Author: Thomas Schatzl <tschatzl@openjdk.org> Date: 2023-08-23 09:45:25 +0000 URL: https://git.openjdk.org/jdk/commit/742e319a21c767d8a93e13048add961f5ca8c5d7
23-08-2023

> However some additional analysis showed that there is another bug in the code, the code that actually clears the TARS, that has been erroneously deleted from older versions of JDK-8140326. Reinstated the original title/description of the CR because this is wrong; there is code clearing TARSes in G1ClearBitmapClosure that applies to all regions in the collection set.
21-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15359 Date: 2023-08-21 08:53:34 +0000
21-08-2023

The "yielded" flag is an optimization to not execute the remainder of the condition if we did not yield (there could not have been a change to the condition). I.e. only during gc (if we yielded) the result of the other part of the && condition will change. So it should be "false" in any case. Maybe it should be removed. However some additional analysis showed that there is another bug in the code, the code that actually clears the TARS, that has been erroneously deleted from older versions of JDK-8140326. So basically the whole check would never be executed... :(
11-08-2023

Hey Thomas, a Friday bug for you :)
11-08-2023