JDK-8252505 : C1/C2 compiler support for blackholes
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-08-28
  • Updated: 2021-01-06
  • Resolved: 2020-12-06
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 16
16 b28Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
JMH uses the Blackhole::consume() methods to avoid dead-code elimination of the code that produces benchmark values. It now relies on producing opaque side-effects and breaking inlining:
  https://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-core/src/main/java/org/openjdk/jmh/infra/Blackhole.java#l153

While it was proved useful for many years, it unfortunately comes with several major drawbacks:
 
 1. Call costs dominate nanobenchmarks. On TR 3970X, the call cost is several nanoseconds.
 2. The work spent in Blackhole.consume dominates nanobenchmarks too. It takes about a nanosecond on TR 3970X.
 3. Argument preparation for call makes different argument types behave differently. This is prominent on architectures where calling conventions for passing e.g. floating-point arguments require elaborate dance.

Supporting this directly in compilers would improve nanobenchmark fidelity. 

Instead of introducing public APIs, we can hook a new command to compiler control, and let JMH sign up its Blackhole methods for it with -XX:CompileCommand=blackhole,org.openjdk.jmh.infra.Blackhole::consume. This is being prototyped as CODETOOLS-7902762.

Dirty C1/C2 prototype that handles all arguments to "blackholed" method:
 https://github.com/openjdk/jdk/compare/master...shipilev:JDK-8252505-blackholes

It makes Blackholes behave substantially better:
 http://cr.openjdk.java.net/~shade/8252505/bh-old-vs-new.png
Comments
Redoing for JDK 17 in JDK-8259316.
06-01-2021

This change is reverted with JDK-8258558.
06-01-2021

Changeset: e5906189 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2020-12-06 17:43:34 +0000 URL: https://git.openjdk.java.net/jdk/commit/e5906189
06-12-2020

I added similar minimal changes for aarch64. Appended patch as a webrev: http://cr.openjdk.java.net/~dchuyko/8252505/webrev.01/ The test should be slightly corrected (UnlockDiagnosticVMOptions), it then passes. The plot looks similar: http://cr.openjdk.java.net/~dchuyko/8252505/aarch64.png
31-08-2020