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
8261921: ClassListParser::current should be used only by main thread #2619
8261921: ClassListParser::current should be used only by main thread #2619
Conversation
|
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.
Hi Ioi,
Thanks for the side-bar explanations on the background here.
Changes seem fine, but a couple of comments below.
Thanks,
David
// _instance should only be accessed by the thread that created _instance. | ||
assert(_instance == NULL, "must be singleton"); | ||
_instance = this; | ||
Atomic::store(&_parsing_thread, Thread::current()); |
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 use of atomics here seems overkill as we have no issues with atomicity, tearing or ordering, when checking if the field is the current thread. You can't get a false positive and the current thread must always see the value it set.
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.
As we discussed off-line, theoretically we could have tearing if _parsing_thread spanned across a cache line. We don't actually support such platforms today (as you pointed out, Atomic:load is just a naked load for now). However, it's better to use the proper atomic operations for future proofing.
ClassListParser::~ClassListParser() { | ||
if (_file) { | ||
fclose(_file); | ||
} | ||
Atomic::store(&_parsing_thread, (Thread*)NULL); | ||
_instance = NULL; | ||
} |
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 gives the impression that we can create a new ClassListParser later, potentially in a different thread - is that really the case?
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.
Currently we don't do that, but I want to make sure we have proper clean up. Since we are modifying _instance, we should clean up other statics as well.
@@ -81,6 +83,7 @@ class ClassListParser : public StackObj { | |||
_line_buf_size = _max_allowed_line_len + _line_buf_extra | |||
}; | |||
|
|||
static Thread* _parsing_thread; // the thread that created _instance |
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.
I forget whether we still want to use volatile
here or not.
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.
_parsing_thread and _instance are read by another thread so that's why they have Atomic::load and store. This should be volatile if they need that level of memory ordering.
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.
I've changed it to volatile.
bool is_superclass, | ||
TRAPS); | ||
static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name, | ||
Symbol* super_name, bool is_superclass); |
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.
Indentation is ad-hoc here, please align Symbol
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.
Fixed.
@iklam 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 2 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the
|
InstanceKlass* k = SystemDictionaryShared::lookup_super_for_unregistered_class(class_name, | ||
super_name, is_superclass); |
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.
Please align super_name
with class_name
in the previous line.
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.
Fixed.
@@ -81,6 +83,7 @@ class ClassListParser : public StackObj { | |||
_line_buf_size = _max_allowed_line_len + _line_buf_extra | |||
}; | |||
|
|||
static Thread* _parsing_thread; // the thread that created _instance |
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.
Should this be declared volatile
?
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.
Fixed.
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. Just couple of comments.
Thanks,
Calvin
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.
@@ -81,6 +83,7 @@ class ClassListParser : public StackObj { | |||
_line_buf_size = _max_allowed_line_len + _line_buf_extra | |||
}; | |||
|
|||
static Thread* _parsing_thread; // the thread that created _instance |
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.
_parsing_thread and _instance are read by another thread so that's why they have Atomic::load and store. This should be volatile if they need that level of memory ordering.
…classlistparser-only-main-thread
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.
Still good.
Thanks,
David
@@ -81,8 +81,7 @@ ClassListParser::ClassListParser(const char* file) { | |||
} | |||
|
|||
bool ClassListParser::is_parsing_thread() { | |||
Thread* t = Atomic::load(&_parsing_thread); | |||
return (t == Thread::current()); | |||
return (Atomic::load(&_parsing_thread) == Thread::current()); |
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.
Nit: superfluous brackets on a binary operator
Thanks @calvinccheung @coleenp @dholmes-ora for the review! |
@iklam Since your change was applied there have been 2 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 8cfea7c. |
During -Xshare:dump, ClassListParser::current() should be used only by the main thread, which has created the only ClassListParser instance. Accessing it from other threads could cause intermittent failures. We observed this only on certain hosts with -Xcomp.
The fix is to check for
ClassListParser::is_parsing_thread()
before callingClassListParser::current()
. After the fix, I can no longer reproduce the crash.I also did some renaming and comment cleaning.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2619/head:pull/2619
$ git checkout pull/2619