RFR: 8280320: C2: Loop opts are missing during OSR compilation
Tobias Hartmann
thartmann at openjdk.org
Mon Jun 20 08:04:58 UTC 2022
On Fri, 17 Jun 2022 21:29:41 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
> After [JDK-8272330](https://bugs.openjdk.org/browse/JDK-8272330), OSR compilations may completely miss loop optimizations pass due to misleading profiling data. The cleanup changed how profile counts are scaled and it had surprising effect on OSR compilations.
>
> For a long-running loop it's common to have an MDO allocated during the first invocation while running in the loop. Also, OSR compilation may be scheduled while running the very first method invocation. In such case, `MethodData::invocation_counter() == 0` while `MethodData::backedge_counter() > 0`. Before JDK-8272330 went in, `ciMethod::scale_count()` took into account both `invocation_counter()` and `backedge_counter()`. Now `MethodData::invocation_counter()` is taken by `ciMethod::scale_count()` as is and it forces all counts to be unconditionally scaled to `1`.
>
> It misleads `IdealLoopTree::beautify_loops()` to believe there are no hot
> backedges in the loop being compiled and `IdealLoopTree::split_outer_loop()`
> doesn't kick in thus effectively blocking any further loop optimizations.
>
> Proposed fix bumps `MethodData::invocation_counter()` from `0` to `1` and
> enables `ciMethod::scale_count()` to report sane numbers.
>
> Testing:
> - hs-tier1 - hs-tier4
Looks reasonable. Maybe change the comment to something like:
`// invocation counter may be slightly off because MDO is only allocated after first invocation`
src/hotspot/share/ci/ciMethodData.cpp line 255:
> 253: }
> 254:
> 255: _state = (mdo->is_mature() ? mature_state : immature_state);
I think the surrounding brackets should/could be removed.
-------------
Marked as reviewed by thartmann (Reviewer).
PR: https://git.openjdk.org/jdk19/pull/38
More information about the hotspot-compiler-dev
mailing list