-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8316961: Fallback implementations for 64-bit Atomic::{add,xchg} on 32-bit platforms #16252
Conversation
👋 Welcome back shade! A progress list of the required criteria for merging this PR into |
Webrevs
|
This is actually pretty generic area. /label remove hotspot-runtime |
@shipilev |
@shipilev |
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.
Having monotonic counters tends to require 64 bits. I have pulled my hair out so many times that we can't have atomic monotonic counters because of the lack of 32 bit platform support for it. The fix looks great, thanks for fixing!
@shipilev 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 43 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 |
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 for fixing. I'm a bit surprised this wasn't done from the start ... makes me wonder how we missed it.
ARM32 comes back with a massive wrinkle: even though EDIT: Wait, something is off here. I am running on RPi 4 that is definitely ARM v7+, which should support this. I think the gtest does not initialize |
Oh, I see, that's the test bug: #16269 The contract for
ARM32 does not implement this for all types of machines, as per comment here:
I guess we still have a problem for ARM < v7 without kernel support, which would either assert in Given how even current direct uses of Agree, @dholmes-ora? |
I guess on arm32 without 64-bit atomic support, the gtest operations on int64 would crash, because the _LP64 guard was removed. |
I'm afraid I've lost track of the history here. We had supports_cx8 to deal with exactly this problem. If a platform could not support 64-bit cmpxchg (and thus implicitly any 64-bit r-m-w operation) then it has to fall back to locking. |
All right, hear me out. I am trying to briefly recap where we are and where we are going from here. From the perspective of caller, the
...and on the other hand, it requires platforms to implement 8-byte CAS:
This PR implicitly relies on second assumption. I think the only platform left that needs the Before this PR:
After this PR:
So, I don't think this qualifies as regression for ARM <= 6: we are trading the link-time failure for all ARM platforms for clean runtime failure on ARM <= 6 platform, if we violate the I dabbled a little in trying to implement 8-byte CAS (locked) implementation for ARM <= 6, and I think it would require some rewrites. There are cases, for example, when we are doing creepy non-atomic stuff when Once/if we fix ARM <= 6, that would eliminate the need for Does all this make sense? Am I missing something? Should we proceed with this change? |
Surely the I can accept the current proposal doesn't make the mess worse, it just shone a light on the fact there is a mess. If ARMv6 is broken then maybe it needs to be dropped? (Not in this PR of course.) |
From a related discussion in JDK-8246770 I was under the impression that the kernel helper would be used to provide this support on ARMv6 - see code in ./cpu/arm/vm_version_arm_32.cpp. |
Okay part of the (my) confusion here is that |
Yes, it is confusing. jdk/src/hotspot/share/runtime/atomic.hpp Lines 58 to 62 in 729f4c5
So I would like to go forward with this PR. The only question that remains for me is whether to protect the gtest cases with |
It would be nice if Atomic used a PlatformMutex or something internally, for platforms that don't have supports_cx8, so we could just assume that this stuff works across all platforms, just maybe "a bit" slower on some platforms. If we wanted to be really fancy, we could have an array that is say 8 * number of CPUs large, where addresses are hashed to a PlatformMutex to reduce contention a bit. But perhaps that's more than you bargained for with this PR! |
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.
Throughout, Atomic::PlatformMumble is intended to be used in the implementation of
Atomic::Mumble, and isn't intended to be used elsewhere. I think intent is even adhered
to currently. This proposed change violates that in a bunch of places.
@kimbarrett, do you suggest to use |
Yes, and Atomic::load instead of PlatformLoad. So actually follow the model of the atomic bitset functions. |
Yes, providing the locked implementation was my initial intent as well, but now that I looked into it, it seems to be too much hassle for little, if any, gain. In other words, we can already assume 8-byte atomics work on all platforms we build for. Even Zero -- which runs on obscurest platforms imaginable -- goes into GCC built-ins for Note that I only found ARMv6 "issue" due to a test bug. |
Right. Done in new commit. The previous version was from the time I did these fallbacks straight in platform atomic files. But in the shared code, we should definitely go for the non-platform methods. I am re-running tests, but expect no trouble. |
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.
Thanks, looks good to me.
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.
Do I understand correctly that all platforms support cas64 other than arm32,
and even it does so if using a non-ancient hardware version or the kernel
helper? If so, I'd be inclined to just say it must always be supported and be
done with the supports_cx8 stuff around the Atomic class. So update the
comments for Atomic accordingly, and remove the supports_cx8 checks in the
tests. But I'm okay with the current version and leaving that for followup.
Regarding the comment "inconsistency" for Atomic, I read those as being a
general comment about 64bit operations not necessarily being supported, but
that cas64 is an exception and must be supported. I'm guessing we didn't do
what's in this PR and provide cas64-based implementations of other operations
due to also needing load64/store64, though I suppose one could even implement
those with cas64, horrid as that might be. The templatizing effort just
maintained the status quo in this regard.
That is my understanding after doing this work, yes. |
Note you cannot just provide a lock-based implementation of cmpxchg8 and think all is well with the world. All accesses to variables that could be updated by such a cmpxchg8 would have to be accessed in a way that is consistent/safe with the use of the lock (e.g. a raw read could see a partial update if done concurrently with a locked-cmpxchg8). Even on the Java side (via Unsafe) this is not fully in place but that issue is recognized and documented. |
I'm tempted to say the VM should simply fail to start if |
Same. That would also remove any need for lockers in Access API, AFAICS. Let's try that in a separate PR and see what happens? |
If there are no other comments/complaints, I am going to integrate this soon. Last call! |
Okay. I will file a RFE to make |
Thanks all! /integrate |
Going to push as commit ba7d08b.
Your commit was automatically rebased without conflicts. |
See the bug for rationale. Looks like there is enough infrastructure to achieve what we want without significant fan-out. I checked all
atomic_*.hpp
headers for unimplementedPlatformAdd<8>
andPlatformXchg<8>
, and only these seem to be affected.Unfortunately, we cannot test these apart from the existing gtest.
Additional testing:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16252/head:pull/16252
$ git checkout pull/16252
Update a local copy of the PR:
$ git checkout pull/16252
$ git pull https://git.openjdk.org/jdk.git pull/16252/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16252
View PR using the GUI difftool:
$ git pr show -t 16252
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16252.diff
Webrev
Link to Webrev Comment