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

Add diagnostic VM options to control Thread.onSpinWait intrinsic code for AArch64

XMLWordPrintable

    • behavioral
    • minimal
    • A pure addition, and can be ignored by the JVM, so no compatibility risk. `Thread.onSpinWait` is a hint to the JVM without any guarantee that the JVM will use it.
    • add/remove/modify command line option
    • Implementation

      Summary

      Add new diagnostic VM options OnSpinWaitInst and OnSpinWaitInstCount to control the code generated for JVM's Thread.onSpinWait intrinsic on AArch64.

      Problem

      AArch64 ISA provides the YIELD instruction. According to the specification the instruction can be used to implement spin pauses including Thread.onSpinWait intrinsic. However most known hardware implementations of AArch64 ISA treat the instruction as NOP. As a result no pauses happen.

      Experiments with sequences of the NOP instructions or the ISB instructions have shown they can be used to implement spin pauses:

      The problem is that for some AArch64 microarchitectures NOPs should be used, for other AArch64 microarchitectures - ISBs. Also a number of instructions can depend on a microarchitecture. Future microarchitectures may have the proper implementation of the YIELD instruction.

      Solution

      Add diagnostic VM options to control which instruction and how many to use for Thread.onSpinWait intrinsic code on AArch64. Performance engineers can use the options to find the best instruction and its count for a AArch64 microarchitecture which can be set as default for that microarchitecture. In rare cases the default can be changed with options but this would be either to disable the functionality or to change instruction count.

      Specification

      VM option to specify an instruction: OnSpinWaitInst=inst, where inst can be, for AArch64,

      • none: no implementation for spin pauses. This is the default value.
      • nop: use nop instruction for spin pauses.
      • isb: use isb instruction for spin pauses.
      • yield: use yield instruction for spin pauses.

      VM option to specify a number of instructions: OnSpinWaitInstCount=count, where count specifies a number of OnSpinWaitInst and can be in 1..99 range.

      It is an error to use OnSpinWaitInstCount when OnSpinWaitInst is none.

        product(ccstr, OnSpinWaitInst, "none", DIAGNOSTIC,
                "The instruction to use to implement java.lang.Thread.onSpinWait()."
                "Options: none, nop, isb, yield.")
        product(uint, OnSpinWaitInstCount, 1, DIAGNOSTIC,
                "The number of OnSpinWaitInst instructions to generate."
                "It cannot be used with OnSpinWaitInst=none.")
                range(1, 99)

      See: https://github.com/openjdk/jdk/pull/5562/

            eastigeevich Evgeny Astigeevich
            dchuyko Dmitry Chuyko
            Paul Hohensee, Volker Simonis
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: