JDK-8259316 : [REDO] C1/C2 compiler support for blackholes
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-01-06
  • Updated: 2022-11-08
  • Resolved: 2021-05-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 17
17 b21Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8273117 :  
Description
This is redo of JDK-8252505.

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/pull/2024

It makes Blackholes behave substantially better:
 http://cr.openjdk.java.net/~shade/8252505/bh-old-vs-new.png
Comments
Changeset: 6018336f Author: Aleksey Shipilev <shade@openjdk.org> Date: 2021-05-05 14:27:21 +0000 URL: https://git.openjdk.java.net/jdk/commit/6018336fc5e93675482b92df76594712c238adda
05-05-2021