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

RISC-V: Returns mispredicted

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 24
    • hotspot
    • b21
    • riscv

      Risc-v don't have dedicated call/ret instructions.
      Instead CPU assumes based on what registers are used.
      The cpu have a return-address stack where it stores return addresses for prediction.
      This stack is updated, accordingly (from unpriv manual):

      rd is x1/x5 | rs1 is x1/x5 | rd=rs1 | RAS action
      No | No | — | None
      No | Yes | — | Pop
      Yes | No | — | Push
      Yes | Yes | No | Pop, then push
      Yes | Yes | Yes | Push

      Additional:
      "A JAL instruction should push the return address onto a return-address stack (RAS) only when rd is 'x1' or x5."

      Hotspot only uses x1/ra for calls and return, and do not pop then push (coroutine call):
      - calls should plain push, this rd = x1/ra and rs1 != x5/t0
      - returns should plain pop, this rd != x5/t0 and rs1 != x1/ra
      - jumps rd and rs1 != x1/x5

      As today we use x5/t0 as main scratch this gets all wrong, all jumps, calls and return to use x5.

            rehn Robbin Ehn
            rehn Robbin Ehn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: