[windows] use of uninitialized OSThread::_state

XMLWordPrintable

    • b27
    • windows

        On Windows, we use `OSThread::_state` in `os::create_thread` before it has been initialized. This causes asserts to fire in `Thread::is_JavaThread_protected` (`assert(target->is_handshake_safe_for(current_thread)`)

        Only happens if the following is true:
        - We log os=info level, thereby firing the "Thread started.." log output the parent thread of a newly started child thread writes. Since JDK-8268773, we also print the thread name. `Thread::name()` uses `Thread::is_JavaThread_protected`, but on Windows the thread state has not been set yet.
        - This is an assert, so only debug, but in debug newly malloced memory is poisened with "F1F1F1F1...", which hides the error since `Thread::is_JavaThread_protected` compares the thread state like this:
        ```
          if (target->osthread() == NULL || target->osthread()->get_state() <= INITIALIZED) {
            return true;
          }
        ```
        and the compiler interprets the "F1F1F1F1"-filled enum as a signed integer and hence a negative large value. Changing the init pattern to 0x01, or adding an explicit cast to unsigned, causes the assert to fire as soon as logging is switched on.

              Assignee:
              Thomas Stuefe
              Reporter:
              Thomas Stuefe
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: