JDK-8296545 : C2 Blackholes should allow load optimizations
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17,19,20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-11-08
  • Updated: 2022-12-05
  • Resolved: 2022-12-05
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 20
20 masterFixed
Related Reports
Relates :  
Description
If you look at generated code for the JMH benchmark like:

```
    @Param({"1", "100", "10000", "1000000"})
    int size;

    int[] is;

    @Setup
    public void setup() {
        is = new int[size];
        for (int c = 0; c < size; c++) {
            is[c] = c;
        }
    }

    @Benchmark
    public void test(Blackhole bh) {
        for (int i = 0; i < is.length; i++) {
            bh.consume(is[i]);
        }
    }
```

...then you would notice that the loop always re-reads `is`, `is.length`, does the range check, etc. -- all the things we would otherwise expect to be hoisted out of the loop.

This is because C2 blackholes are modeled as membars that pinch both control and memory slices (like you would expect from the opaque non-inlined call), therefore every iteration has to re-read the referenced memory contents and recompute everything dependent on those loads. This behavior is not new -- the old, non-compiler blackholes were doing the same thing, accidentally -- but it was drowned in blackhole overheads. Now, these effects are clearly visible.

We can try to do this a bit better: allow load optimizations to work across the blackholes, leaving only "prevent dead code elimination" part, as minimally required by blackhole semantics.
Comments
Changeset: eab0ada3 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2022-12-05 12:00:30 +0000 URL: https://git.openjdk.org/jdk/commit/eab0ada3a16a432fdfd1f0b8fceca149c725451b
05-12-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11041 Date: 2022-11-08 15:48:01 +0000
08-11-2022