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

riscv: should call Atomic::release_store in JavaThread::set_thread_state

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 19
    • 19
    • hotspot
    • None
    • b17
    • riscv
    • linux

        For RISCV, we use membars when accessing volatile _thread_state through Atomic::load_acquire in JavaThread::thread_state.
        Accordingly, we should use Atomic::release_store to access volatile _thread_state in JavaThread::set_thread_state for this architecture.
        This is correct for our JDK 11 version: both functions are guarded by a single-line macro check for architecures [1].

        The code is refactored in JDK mainline: each function has their own macro check for architectures.
        But looks like we only kept the macro check for RISCV64 in JavaThread::thread_state when porting from JDK 11.
        The same check is missing for JavaThread::set_thread_state. We should add it back.

        Simple fix:
        diff --git a/src/hotspot/share/runtime/thread.inline.hpp b/src/hotspot/share/runtime/thread.inline.hpp
        index 92dfdfa3dbe..ee7d48b8660 100644
        --- a/src/hotspot/share/runtime/thread.inline.hpp
        +++ b/src/hotspot/share/runtime/thread.inline.hpp
        @@ -162,7 +162,7 @@ inline JavaThreadState JavaThread::thread_state() const {
         inline void JavaThread::set_thread_state(JavaThreadState s) {
           assert(current_or_null() == NULL || current_or_null() == this,
                  "state change should only be called by the current thread");
        -#if defined(PPC64) || defined (AARCH64)
        +#if defined(PPC64) || defined (AARCH64) || defined(RISCV64)
           // Use membars when accessing volatile _thread_state. See
           // Threads::create_vm() for size checks.
           Atomic::release_store((volatile jint*)&_thread_state, (jint)s);

        [1] https://gitee.com/openeuler/bishengjdk-11/blob/risc-v/src/hotspot/share/runtime/thread.inline.hpp#L123

              fyang Fei Yang
              fyang Fei Yang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: