8355627: Don't use ThreadCritical for EventLog list#24954
8355627: Don't use ThreadCritical for EventLog list#24954coleenp wants to merge 5 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back coleenp! A progress list of the required criteria for merging this PR into |
|
@coleenp 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: 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 168 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. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
There was a problem hiding this comment.
Not having extra locks during initialization is nice. But I am somewhat confused why we need LockFreeStack here. Looks like we "only" need to build the linked list of EventLog-s in thread-safe manner? So why don't just do our usual Atomic dance, e.g. (untested!):
EventLog::EventLog() {
EventLog* old_head;
do {
old_head = Atomic::load(&Events::_logs);
_next = old_head;
} while (Atomic::cmpxchg(&Events::_logs, old_head, this, memory_order_relaxed) != old_head);
}
|
So I was playing around with LockFreeStack because I thought it might be a good way to avoid writing yet another CAS loop in the code. But you're right, I don't really use LockFreeStack which isn't so lock free since it requires synchronization to pop. I couldn't decide whether I wanted to use it partially or write the CAS loop. I take it this is a vote for the CAS loop. |
| do { | ||
| old_head = Atomic::load(&Events::_logs); | ||
| _next = old_head; | ||
| } while (Atomic::cmpxchg(&Events::_logs, old_head, this, memory_order_relaxed) != old_head); |
There was a problem hiding this comment.
I don't think it is safe to use memory_order_relaxed order if events are added after JVM enters multi-thread mode.
There was a problem hiding this comment.
Thanks for this. I didn't know why Aleksey suggested it. I'll remove it.
There was a problem hiding this comment.
Maybe @shipilev meant memory_order_release? Anyway, I guess we don't need to optimize it.
There was a problem hiding this comment.
I saw no point in enforcing memory ordering mode here, as it looks like we only did ThreadCritical for mutual exclusion. Note that we do not have a matching acquire on list traversals, so seqcst/release on list additions would be incomplete. That only reinforces my original thinking: we are riding on memory ordering given by something else, I'd guess the initialization sequence itself.
But I won't quibble, it is a very minor optimization.
There was a problem hiding this comment.
I guess we rely on memory ordering by address dependency on the reader's side.
There was a problem hiding this comment.
First of all, nothing on the writer's side can fix the reader's side.
We're basically relying on volatile load + dependency chain on the reader's side. This is very likely to work, but C++ memory model specialists may find this questionable.
There was a problem hiding this comment.
Are we on the same page? which load you are talking about?
There was a problem hiding this comment.
I'm talking about Atomic::load() which is essentially a volatile load without ordering.
There was a problem hiding this comment.
I don't believe we need reader side barrier, given the conservative order on writer side. @shipilev any opinion?
There was a problem hiding this comment.
Well, if we are going fully pedantic here, we only need to make sure that the EventLog::_next is properly visible to the code that traverses the EventLog list. This realistically only matters if there are no synchronization points in between those, which I suspect are plenty. E.g. this is the same thing that make all other init code robust in practice: things that happen at init are good to go.
If you want to cover the path to be fully 100% bullet-proof and squeeze some performance at the same time, then I think cmpxchg to Events::_logs should be release and loads from there should be acquire-s.
|
Thank you for reviewing and commenting, Aleksey, Zhengyu, Leonid and Martin. |
|
Going to push as commit afb9134.
Your commit was automatically rebased without conflicts. |
Use LockFreeStack to link events on the eventLog queue. They are never popped so this requires no further synchronization.
Tested by tier1-4.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24954/head:pull/24954$ git checkout pull/24954Update a local copy of the PR:
$ git checkout pull/24954$ git pull https://git.openjdk.org/jdk.git pull/24954/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24954View PR using the GUI difftool:
$ git pr show -t 24954Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24954.diff
Using Webrev
Link to Webrev Comment