JDK-8284848 : C2: Compiler blackhole arguments should be treated as globally escaping
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17,18,19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-04-13
  • Updated: 2022-05-17
  • Resolved: 2022-04-28
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 17 JDK 18 JDK 19
17.0.4Fixed 18.0.2Fixed 19 b21Fixed
Related Reports
Relates :  
Description
Running a JMH test like this:

@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class Synchronization {
    @Benchmark
    public Object blackhole() {
        Object o = new Object();
        synchronized (o) {}
        return o;
    }
}

...with JMH that enables compiler blackholes, shows that the synchronization for the object is eliminated by EA, because the object is deemed non-escaping. Blackholes do prevent scalar replacement, but not other optimizations made available by EA.

While this is not exactly a bug in compiler blackhole implementation, this diverts from the status quo of plain Java JMH blackholes: they were fully opaque for EA, that is the arguments were globally escaping. We should probably match that behavior to avoid surprises for users. See the real world sighting of the related EA-enabled optimization -- eliding constructor storestore barriers -- here: https://mail.openjdk.java.net/pipermail/jmh-dev/2022-April/003428.html

One can still get current compiler blackhole behavior by doing the non-inlined empty method like:

    @Benchmark
    public void dontinline() {
        Object o = new Object();
        synchronized (o) {}
        sink(o);
    }

    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
    public void sink(Object o) {}
Comments
Fix Request (17u, 18u) Fixes the Blackhole - EA interactions. Patches does not apply cleanly due to minor test differences. RFRs acked by kvn.
03-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/379 Date: 2022-05-02 11:29:26 +0000
02-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk18u/pull/118 Date: 2022-05-02 11:11:14 +0000
02-05-2022

Changeset: 5629c755 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2022-04-28 08:32:44 +0000 URL: https://git.openjdk.java.net/jdk/commit/5629c7555f9bb779c57f45dfb071abbb1d87bb7d
28-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8228 Date: 2022-04-13 17:18:43 +0000
13-04-2022