New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8278309: [windows] use of uninitialized OSThread::_state #6734
Conversation
|
b7058ef
to
e85638e
Compare
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. :)
Thanks,
David
@tstuefe This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 39 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
Thank you David! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine as the limited fix.
But I do wonder if the initial state ALLOCATED
should be stamped right in the OSThread::OSThread
constructor. Also, I see other platforms, for example, Linux does:
// set the correct thread state
osthread->set_thread_type(thr_type);
// Initial state is ALLOCATED but not INITIALIZED
osthread->set_state(ALLOCATED);
Not sure how safe it is to add set_thread_type
, but matching the comment for set_state
is probably in order.
Oh totally. This makes me itch. But I wanted a minimal patch to downport, and knowing me once I start touching OSThread I can't stop pulling threads. Ideally, I would like to get rid of OSThread altogether and merge it into Thread; there is no reason to have two physically separate structures like this.
Windows does not have a thread type. About the comment, sure, I can do that. Will do it before pushing. Thanks, Thomas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment at line 783 could be tweaked to no longer say "Initially".
I think a simple follow up RFE could move ALLOCATED into the constructor as Aleksey suggested, without opening up the whole cleanup can of worms.
Thanks,
David
Okay, fixed the comment as David suggested. If no objections come forward, I'll push after breakfast. |
/integrate |
Going to push as commit 54993b1.
Your commit was automatically rebased without conflicts. |
May I have reviews for this trivial fix.
On Windows, we use
OSThread::_state
inos::create_thread
before it has been initialized. This causes an assert to fire inThread::is_JavaThread_protected
(assert(target->is_handshake_safe_for(current_thread)
)This only happens if the following is true:
Thread::name()
usesThread::is_JavaThread_protected
, but on Windows, the thread state has not been set yet.Thread::is_JavaThread_protected
compares the thread state like this:and the compiler interprets the "F1F1F1F1" as 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.
Musings:
I wondered whether we should change the thread state comparison to unsigned like this:
which would have shown the error right away after JDK-8268773. This is matter of taste though since one could say that at this point we expect the enum to be filled correctly with one of its values, and guarding against uninitialized memory should belong somewhere else, maybe in a debug-only verify function.
--
Just my personal opinion, but
OSThread
could do with a bit of cleanup. E.g. using an initializer list to init its values, and possibly doing the per-platform-factoring out in a different way. That include-file-in-the-middle-of-class composition technique is terrible. It confuses IDEs and makes analyzing the code difficult, and the code is not really difficult in what it does.Tests: GHAs (twice, once with experimentally set init word to 1 to see that the patch works)
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6734/head:pull/6734
$ git checkout pull/6734
Update a local copy of the PR:
$ git checkout pull/6734
$ git pull https://git.openjdk.java.net/jdk pull/6734/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6734
View PR using the GUI difftool:
$ git pr show -t 6734
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6734.diff