-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8189685: need PerfMemory class update and a volatile_static_field support in VMStructs #15373
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
Conversation
…port for volatile static.
👋 Welcome back cjplummer! A progress list of the required criteria for merging this PR into |
@plummercj The following label 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 list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
/label remove hotspot |
@plummercj |
@plummercj |
@plummercj
|
/label add hotspot-runtime |
@plummercj |
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.
LGTM.
Thank you for heading up for this issue!
@plummercj 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 61 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 |
@@ -197,7 +197,7 @@ void PerfMemory::destroy() { | |||
delete_memory_region(); | |||
} | |||
|
|||
_destroyed = true; | |||
Atomic::release_store(&_destroyed, 1); |
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 discussed in the final review thread for JDK-8151815 a release_store is not actually needed here as there is no data that we access based on _destroyed
being set to 1. Hence also no need for load_acquire
in is_destroyed()
.
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. I've updated it.
@@ -134,7 +134,7 @@ class PerfMemory : AllStatic { | |||
static size_t used() { return (size_t) (_top - _start); } | |||
static size_t capacity() { return _capacity; } | |||
static bool is_initialized(); | |||
static bool is_destroyed() { return _destroyed; } | |||
static bool is_destroyed(); |
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.
So don't we need to make changes here? I think we can keep current implementation ( is_destroyed()
)
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.
Agreed - I assume the change to int was for the release_store etc but that is not needed so we can keep the bool type and existing code.
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 was also partly going for consistency with _initialized and _destroyed w.r.t. int vs bool and 0/1 vs false/true. I can go back to making _destroyed all bool.
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.
Update done. I should also point out that _destroyed is not exported from VMStructs, so could have been made volatile long ago without needing to add any VMStructs support. SA only looks at _initialized, but I suppose you could argue that it also should be checking _destroyed before accessing PerfMemory.
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.
SA only looks at _initialized, but I suppose you could argue that it also should be checking _destroyed before accessing PerfMemory.
In JDK-8151815, we do not clear fields in PerfMemory
because they are used in SA even if they are freed, so we can ignore _destroyed
in SA. We've discussed about this in review thread of JDK-8151815.
PerfDataPrologue* PerfMemory::_prologue = nullptr; | ||
bool PerfMemory::_destroyed = false; | ||
volatile int PerfMemory::_destroyed = 0; |
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 was this changed to int?
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.
In my original patch (pasted into JBS), I changed it to int
because atomic operation only supports integer type only (maybe). So we can keep bool
if we don't need atomic operations here.
@@ -207,7 +207,7 @@ class VMStructs { | |||
|
|||
// This macro checks the type of a static pointer volatile VMStructEntry by comparing pointer types, | |||
// e.g.: "static ObjectMonitor * volatile g_block_list;" | |||
#define CHECK_STATIC_PTR_VOLATILE_VM_STRUCT_ENTRY(typeName, fieldName, type) \ | |||
#define CHECK_VOLATILE_STATIC_VM_STRUCT_ENTRY(typeName, fieldName, type) \ | |||
{type volatile * dummy = &typeName::fieldName; } |
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.
It is not clear why the PTR_
suffix is removed from the name.
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 intent was to generalize it but the comments also need changing, and now I'm not clear what this is actually doing.
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 change wasn't in the original patch, but the GENERATE_STATIC_PTR_VOLATILE_VM_STRUCT_ENTRY
change above it was. I found it when I noticed the use of GENERATE_STATIC_PTR_VOLATILE_VM_STRUCT_ENTRY
and thought it should be renamed too. I was also doing "static volatile" -> "volatile stack" at the time so that is also part of this macros rename.
As David points out, the purpose is to make it more general purpose, although for this macro only the name change is needed (`GENERATE_STATIC_PTR_VOLATILE_VM_STRUCT_ENTRY also has a minor implementation change that was needed).
The comments for both of these macros references "static pointer volatile" entries. That should changed to "volatile static". The type no longer needs to be a pointer type.
I'm not certain what this CHECK macro does, but it was pre-existing, and there is also the CHECK_STATIC_VM_STRUCT_ENTRY
macro above it which is identical except of the absence of "volatile" in the name and implementation. I think it verifies that the type specified in the vmstructs definition of the field is actually the same as the field itself. The macro will generate a compiler error if a cast was needed. I think this type of check can only be done with static fields. You would need an instance of the class/struct to do a similar check on an instance field. Thus CHECK_NONSTATIC_VM_STRUCT_ENTRY is much more complex and seems to be a runtime check that will assert if it fails.
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 can't convince myself that volatile
is in the right place in type volatile * dummy
. But volatile * dummy
means that the pointer is volatile as opposed to the type being pointed to, which would match with the original macro name's use of PTR_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.
But in that case the use of the macro doesn't make much sense. Regardless of the field type, vmstructs doesn't deal with volatile pointers to fields. It deals with volatile fields (that can be pointers or scalar). I think if anything the macro has always been wrong and should contain volatile type * dummy
. It probably never fails because it is taking a non-volatile type and assigning it to a volatile type, which always works if the types are otherwise the same.
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.
Well of course that change blows up
invalid conversion from 'ClassLoaderData* volatile*' to 'volatile ClassLoaderData**'
There's something I'm not understanding here. I use to understand the volatile ordering syntax and how to read it properly, but that was long long ago.
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 take back the following statement:
It probably never fails because it is taking a non-volatile type and assigning it to a volatile type, which always works if the types are otherwise the same.
Since the field type is volatile, the current approach must be correct. Otherwise there would be cast errors if the LHS did not have volatile in the right place.
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.
@dholmes-ora I'm not sure what is needed to move forward with this. Are you OK with the change?
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 quite certain about the intent with the old naming for the macros, but the new names certainly don't hurt anything. So this seems okay.
Thanks.
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,
Serguei
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 agree with this change.
Thanks for the reviews Yasumasa, David, and Serguei! /integrate |
Going to push as commit b2728cb.
Your commit was automatically rebased without conflicts. |
@plummercj Pushed as commit b2728cb. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
During JDK-8151815 it was noted that the PerfMemory _initialized and _destroyed fields should be volatile, but VMStructs didn't have the needed support for doing that, so it was left as a future task. @YaSuenag provided a patch at the time to take care of the VMStructs support. I've integrated it, although it was far from clean due to some changes in VMStructs, and also moving OrderAccess::release_store to Atomic::release_store.
One other change I made to the patch had to do with consistency with using "volatile static" vs "static volatile". We already have volatile_nonstatic_field. The patch renamed static_ptr_volatile_field to static_volatile_field to make it more general purpose, but this was inconsistent with the name of volatile_nonstatic_field, so I chose the name volatile_static_field instead. This carried over into some other areas like the names of the GENERATE_VOLATILE_STATIC_VM_STRUCT_ENTRY and CHECK_VOLATILE_STATIC_VM_STRUCT_ENTRY macros.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15373/head:pull/15373
$ git checkout pull/15373
Update a local copy of the PR:
$ git checkout pull/15373
$ git pull https://git.openjdk.org/jdk.git pull/15373/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15373
View PR using the GUI difftool:
$ git pr show -t 15373
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15373.diff
Webrev
Link to Webrev Comment