-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8326936: RISC-V: Shenandoah GC crashes due to incorrect atomic memory operations #18039
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7ff141a
Fix a bug about GCC atomic built-in function.
MaxXSoft 4b894b0
Remove unnecessary sign-extension.
MaxXSoft 48e3895
Fix static assert.
MaxXSoft 94194f7
Add comments, change `flag` to `rc_temp`.
MaxXSoft e1a49d8
Fix value types, macro conditions and comments.
MaxXSoft dff9923
Add explicit type cast for `old_value`.
MaxXSoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,12 @@ | |
#define FULL_COMPILER_ATOMIC_SUPPORT | ||
#endif | ||
|
||
#if defined(__clang_major__) | ||
#define CORRECT_COMPILER_ATOMIC_SUPPORT | ||
#elif defined(__GNUC__) && (__riscv_xlen <= 32 || __GNUC__ > 13) | ||
#define CORRECT_COMPILER_ATOMIC_SUPPORT | ||
#endif | ||
|
||
template<size_t byte_size> | ||
struct Atomic::PlatformAdd { | ||
template<typename D, typename I> | ||
|
@@ -114,6 +120,44 @@ inline T Atomic::PlatformCmpxchg<1>::operator()(T volatile* dest __attribute__(( | |
} | ||
#endif | ||
|
||
#ifndef CORRECT_COMPILER_ATOMIC_SUPPORT | ||
// The implementation of `__atomic_compare_exchange` lacks sign extensions | ||
// in GCC 13 and lower when using with 32-bit unsigned integers on RV64, | ||
// so we should implement it manually. | ||
// GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114130. | ||
// See also JDK-8326936. | ||
template<> | ||
template<typename T> | ||
inline T Atomic::PlatformCmpxchg<4>::operator()(T volatile* dest __attribute__((unused)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a code comment about why we should have this defined? Better to add a link to the related GCC bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
T compare_value, | ||
T exchange_value, | ||
atomic_memory_order order) const { | ||
STATIC_ASSERT(4 == sizeof(T)); | ||
|
||
int32_t old_value; | ||
uint64_t rc_temp; | ||
|
||
if (order != memory_order_relaxed) { | ||
FULL_MEM_BARRIER; | ||
} | ||
|
||
__asm__ __volatile__ ( | ||
"1: lr.w %0, %2 \n\t" | ||
" bne %0, %3, 2f \n\t" | ||
" sc.w %1, %4, %2 \n\t" | ||
" bnez %1, 1b \n\t" | ||
"2: \n\t" | ||
: /*%0*/"=&r" (old_value), /*%1*/"=&r" (rc_temp), /*%2*/"+A" (*dest) | ||
: /*%3*/"r" ((int64_t)(int32_t)compare_value), /*%4*/"r" (exchange_value) | ||
: "memory" ); | ||
|
||
if (order != memory_order_relaxed) { | ||
FULL_MEM_BARRIER; | ||
} | ||
return (T)old_value; | ||
} | ||
#endif | ||
|
||
template<size_t byte_size> | ||
template<typename T> | ||
inline T Atomic::PlatformXchg<byte_size>::operator()(T volatile* dest, | ||
|
@@ -151,6 +195,10 @@ inline T Atomic::PlatformCmpxchg<byte_size>::operator()(T volatile* dest __attri | |
STATIC_ASSERT(byte_size >= 4); | ||
#endif | ||
|
||
#ifndef CORRECT_COMPILER_ATOMIC_SUPPORT | ||
STATIC_ASSERT(byte_size != 4); | ||
#endif | ||
|
||
STATIC_ASSERT(byte_size == sizeof(T)); | ||
if (order != memory_order_relaxed) { | ||
FULL_MEM_BARRIER; | ||
|
@@ -187,5 +235,6 @@ struct Atomic::PlatformOrderedStore<byte_size, RELEASE_X_FENCE> | |
}; | ||
|
||
#undef FULL_COMPILER_ATOMIC_SUPPORT | ||
#undef CORRECT_COMPILER_ATOMIC_SUPPORT | ||
|
||
#endif // OS_CPU_LINUX_RISCV_ATOMIC_LINUX_RISCV_HPP |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 doesn't make sense to me to have this
CORRECT_COMPILER_ATOMIC_SUPPORT
macro.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.
Reason for adding this macro:
__atomic_compare_exchange
is correct in Clang, we can directly use it withuint32_t
for potential optimization opportunities.