Question about thread initialization

Thomas Stüfe thomas.stuefe at gmail.com
Fri Oct 12 08:18:20 UTC 2018


Hi all,

a small question.

JVM_StartThread calls new JavaThread()
  JavaThread::JavaThread() calls os::create_thread()
    os::create_thread() starts the new thread and waits for the
handshake, then returns

Back in JVM_StartThread, we call JavaThread::prepare(), which adds the
new thread to the Threads list. By that time, the new thread is
already running, but how far it has gotten is unknown.

The new thread's stack dimensions are set from within Thread::run()
(for some reason, every child class does this on its own?) by calling
Thread::record_stack_base_and_size(). So, after the handshake with its
parent thread. Why?

This means we have a little race: in the Threads list there may be
threads which have been just created and Thread::run() did not yet get
around to set the stack size. In tests I stumbled over this, very
rarely, when iterating Threads to check the stack sizes.

Is there any reason why we could not just call
record_stack_base_and_size() before calling Thread::run(), right at
the start of the native entry function (thread_native_entry in the
case of Linux)?

Am I missing something here?

Thanks,

Thomas


More information about the hotspot-runtime-dev mailing list