Skip to content
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

Closed

Conversation

iklam
Copy link
Member

@iklam iklam commented Feb 18, 2021

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 calling ClassListParser::current(). After the fix, I can no longer reproduce the crash.

I also did some renaming and comment cleaning.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8261921: ClassListParser::current should be used only by main thread

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2619/head:pull/2619
$ git checkout pull/2619

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 18, 2021

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 18, 2021

@iklam The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Feb 18, 2021
@iklam iklam marked this pull request as ready for review February 18, 2021 02:27
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 18, 2021
@mlbridge
Copy link

mlbridge bot commented Feb 18, 2021

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a 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());
Copy link
Member

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.

Copy link
Member Author

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;
}
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@openjdk
Copy link

openjdk bot commented Feb 18, 2021

@iklam This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261921: ClassListParser::current should be used only by main thread

Reviewed-by: dholmes, ccheung, coleenp

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 master branch:

  • 991f7c1: 8210373: Deadlock in libj2gss.so when loading "j2gss" and "net" libraries in parallel.
  • 0217d69: 8261975: Missing "classpath exception" in VectorSupport.java

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 18, 2021
InstanceKlass* k = SystemDictionaryShared::lookup_super_for_unregistered_class(class_name,
super_name, is_superclass);
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@calvinccheung calvinccheung left a 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

Copy link
Contributor

@coleenp coleenp left a 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
Copy link
Contributor

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.

Copy link
Member

@dholmes-ora dholmes-ora left a 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());
Copy link
Member

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

@iklam
Copy link
Member Author

iklam commented Feb 23, 2021

Thanks @calvinccheung @coleenp @dholmes-ora for the review!
/integrate

@openjdk openjdk bot closed this Feb 23, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 23, 2021
@openjdk
Copy link

openjdk bot commented Feb 23, 2021

@iklam Since your change was applied there have been 2 commits pushed to the master branch:

  • 991f7c1: 8210373: Deadlock in libj2gss.so when loading "j2gss" and "net" libraries in parallel.
  • 0217d69: 8261975: Missing "classpath exception" in VectorSupport.java

Your commit was automatically rebased without conflicts.

Pushed as commit 8cfea7c.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
5 participants