RFR(s): 8212173: Thread._stack_base/_stack_size initialized too late for new threads (original) (raw)

Thomas Stüfe thomas.stuefe at gmail.com
Mon Oct 22 16:56:15 UTC 2018


Dear all,

may I have please reviews for the following fix:

Bug: https://bugs.openjdk.java.net/browse/JDK-8212173 cr: http://cr.openjdk.java.net/~stuefe/webrevs/8212173-thread-stack-and-base-initialized-too-late/webrev.02/webrev/

See also prior mail discussions: [1]

Wwhen iterating the thread list, threads may be visible which have stack base/size not yet set. Calling stack_base() will yield NULL, stack_size() 0 or it will assert. The reason for this is that there exist a race: Thread::_stack_base and ::_stack_size are initialized too late, when the Thread has already been added to the threads list.

My solution to this problem is basically to move the initialization of Thread::_stack_base and ::_stack_size to an earlier point at which the thread has not yet been added to the threads list.

Unfortunately, this is more difficult that it sounds. Retrieving thread stack base and size needs to be done from within the thread in question, and only on Linux and BSD we have the opportunity to execute code in the new child thread before its Thread object is added to the thread list. So, my patch solves the problem completely only on Linux and BSD. On Windows, Aix and Solaris it only minimizes the chance for it to happen.

For more details, please see bug description and the discussion in [1].


My changes in detail:

public virtual Thread::run()

to

public (nonvirtual) Thread::call_run(); protected virtual Thread::run() = 0;

Thread::call_run() now is the place to put common, platform-independent and -independent initializations. There I put the NMT stuff and logging. After ::run() returns, I put common cleanup checks.

Other changes:


That's about it.

The change ran through jdk-submit tests without errors.

Thank you for reviewing.

..Thomas

[1] http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2018-October/030516.html



More information about the hotspot-runtime-dev mailing list