Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8227019

CompletableFuture.waitingGet shouldn't call Runtime.availableProcessors in a tight loop

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8
    • core-libs

      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

            Unassigned Unassigned
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: