-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8355960: JvmtiAgentList::Iterator dtor double free with -fno-elide-constructors #26083
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back amenkov! A progress list of the required criteria for merging this PR into |
@alexmenkov 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 36 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 |
@alexmenkov The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
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.
I'm not very familiar with these aspects of C++ but this seems to be a very complex solution to what sounds in JBS to be a pretty straight-forward problem.
|
||
while (true) { | ||
// set _tail to address of agent->_next | ||
JvmtiAgent** tail = Atomic::load_acquire(&_tail); |
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.
You don't need acquire semantics here as you are not doing anything with the _tail
pointer value other than use it in relation to cmpxchg which provides fully memory barriers.
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.
ok, thanks
@@ -31,7 +31,8 @@ | |||
#include "runtime/atomic.hpp" | |||
#include "runtime/os.inline.hpp" | |||
|
|||
JvmtiAgent* JvmtiAgentList::_list = nullptr; | |||
JvmtiAgent* JvmtiAgentList::_head = nullptr; | |||
JvmtiAgent** JvmtiAgentList::_tail = nullptr; |
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.
Why is the tail a pointer to a pointer? Sorry I'm not understanding how your list is being managed here.
I'm trying to work out where you need acquire/release because I'm pretty sure it is missing where needed, but again I can't understand how you are actually constructing and using the list.
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.
pointer to pointer because it contains not the pointer to the last agent in the list, but address of the JvmtiAgent::_next
field.
_tail
is for faster adding at the end of the list. Performance is not important here and number of agents is always low, so I think _tail
can be removed to make the logic simpler. Will update the fix after testing completes
Straight-forward solution would be to add copy ctor for Iterator class which clones GrowableArray (allocates new instance and copies all elements). |
The updated version without |
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.
Okay - still took me a little while to understand the double-indirection of the "tail ptr" in add
, but I get it now. So looking at the acquire/release requirements:
- all additions are done with
cmpxchg
which is effectively a release-store - when you iterate the list all loads of the "next" agent must be a load-acquire, this means
- when you create the iterator you need a load-acquire (which you have when you pass
head()
) - In
Iterator::next()
you need a load-acquire on each read of the_next
field which is most simply done by definingJvmtiAgent::next()
as a load-acquire and using that in the iterator code instead of direct field access.
- when you create the iterator you need a load-acquire (which you have when you pass
JvmtiAgent::set_next
should be a release-store though as far as I can see it is not used.
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 good to me.
I hope, David will sort out where the Atomic::
operations are needed.
Thank you for the detailed analysis. |
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
Currently jvmtiAgentList keeps agents in reversed order (new agents are added to the head of the list).
To restore original order JvmtiAgentList::Iterator uses GrowableArray allocated in heap.
Iterators for different agent types are returned by value, and the iterator class nas no custom copy ctor, so if the constructor not elides, GrowableArray is deallocated twice.
The fix updates jvmtiAgentList to keep agents in the original order, agents are added to the tail.
Iterator now needs only single pointer to next agent.
Additionally removed
JvmtiAgentList::Iterator::next() const
method (it looks very strange asnext()
is expected to change state of the iterator).Testing: tier1..4,hs-tier5-svc
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26083/head:pull/26083
$ git checkout pull/26083
Update a local copy of the PR:
$ git checkout pull/26083
$ git pull https://git.openjdk.org/jdk.git pull/26083/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26083
View PR using the GUI difftool:
$ git pr show -t 26083
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26083.diff
Using Webrev
Link to Webrev Comment