Skip to content
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

Fix statics issue with barriers #108311

Conversation

davidwrighton
Copy link
Member

@davidwrighton davidwrighton commented Sep 27, 2024

A barrier based approach for fixing issue #105441

This adds barriers after all the places outside of jitted code where we check to see if the class constructor is initialized. These barriers are somewhat non-optimal on ARM64, as they use ldar instead of ldapr, but should fix the problems we've been encountering with regards to memory model behavior around statics.

@@ -653,7 +653,8 @@ DynamicHelper DynamicHelperFrameFlags_ObjectArg | DynamicHelperFrameFlags_Object

LEAF_ENTRY JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT
// If class is not initialized, bail to C++ helper
ldr x1, [x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics]
add x1, x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics
ldar x1, [x1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the barriers in arm32 version of these helpers as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And also riscv and loongarch.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do, this was more intended to get a quick bit written up so that we could run some tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: can be ldapur x1, [x1, #OFFSETOF__DynamicStaticsInfo__m_pGCStatics] for macos-arm64 since that has rcpc2 in the baseline, but not sure it worth the complexity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's a detail that we will be able to do a better job of implementing these helpers when we move them to managed. (Since the jit will take advantage of the ldapr or ldapur instructions instead of just using ldar which is a stronger barrier than we need.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, there is no need to fix arm, as we don't have handwritten assembly helpers for this set of helpers.

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@davidwrighton davidwrighton marked this pull request as ready for review September 27, 2024 16:18
@davidwrighton davidwrighton merged commit 2fcc09b into dotnet:main Sep 27, 2024
88 of 90 checks passed
@davidwrighton
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/11076638514

Copy link
Contributor

@davidwrighton backporting to release/9.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix statics issue with barriers
Applying: Add barriers for RiscV and Loongson
Using index info to reconstruct a base tree...
M	src/coreclr/vm/loongarch64/asmhelpers.S
M	src/coreclr/vm/riscv64/asmhelpers.S
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/vm/riscv64/asmhelpers.S
CONFLICT (content): Merge conflict in src/coreclr/vm/riscv64/asmhelpers.S
Auto-merging src/coreclr/vm/loongarch64/asmhelpers.S
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0002 Add barriers for RiscV and Loongson
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@davidwrighton an error occurred while backporting to release/9.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

davidwrighton added a commit to davidwrighton/runtime that referenced this pull request Sep 27, 2024
* Fix statics issue with barriers

* Add barriers for RiscV and Loongson
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
* Fix statics issue with barriers

* Add barriers for RiscV and Loongson
jeffschwMSFT added a commit that referenced this pull request Oct 3, 2024
* Fix statics issue with barriers

* Add barriers for RiscV and Loongson

Co-authored-by: Jeff Schwartz <jeffschw@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants