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

Redundant condition check in SafepointSynchronize::thread_not_running

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 17
    • Fix Version/s: 18
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b26

      Description

      `SafepointSynchronize::thread_not_running` starts by checking if the current state is `is_running`:

      ```
      bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) {
        if (!cur_state->is_running()) {
          return true;
        }
        ...
      }
      ```

      However, this has been asserted by the caller, `SafepointSynchronize::synchronize_threads`.

      ## call site 1

      ```
        for (; JavaThread *cur = jtiwh.next(); ) {
          assert(cur->safepoint_state()->is_running(), "Illegal initial state");
        }
        ...
        if (thread_not_running(cur_tss)) {
      ```

      ## call site 2

      ```
            assert(cur_tss->is_running(), "Illegal initial state");
            if (thread_not_running(cur_tss)) {
      ```

      Therefore, `!cur_state->is_running()` is always false, and the `if` is just skipped.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dholmes David Holmes
              Reporter:
              ayang Albert Yang
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: