JDK-8227019 : CompletableFuture.waitingGet shouldn't call Runtime.availableProcessors in a tight loop
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2019-07-01
  • Updated: 2019-07-01
  • Resolved: 2019-07-01
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
As described in JDK-8227006 the addition of container support has slowed down the execution of Runtime.availableProcessors. By calling this function in its spin-loop waitingGet() can also suffer from a severe slowdown in performance.

                spins = (Runtime.getRuntime().availableProcessors() > 1) ?
                    1 << 8 : 0; // Use brief spin-wait on multiprocessors

As we only care about >1 processors we can cache this value in a field. The only problem case would be a >1 to 1 transition which is an unlikely change. If it did occur it would only result in a small performance hit anyway.

This fix is only needed for 8u as 9 and later have different code due to JDK-8157522