-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Wasm] Write barriers #128225
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
Merged
Merged
[Wasm] Write barriers #128225
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
be3c701
Checkpoint
kg c65cbe7
Cleanup
kg fadf0ca
Fix use of ref instead of dst
kg e7b7942
Cleanup
kg 003a92c
Address PR feedback
kg 5a233fa
Fix bad ifdef
kg 87c493e
Fix lack of card table indirection
kg 9d6aa88
Move wasm writebarriers.cpp from src/coreclr/vm/wasm to src/coreclr/r…
kg a8d9caf
Cleanup comments
kg e083d6e
Fix storeblk codegen to not use byref write barrier since we're not i…
kg 250e557
Fix include paths
kg dabdb06
Address PR feedback
kg 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
kg marked this conversation as resolved.
|
||
| // | ||
|
|
||
| #include <fcall.h> | ||
|
|
||
| #ifndef FEATURE_NATIVEAOT | ||
| #include "gchelpers.inl" | ||
| #include "gcheaputilities.h" | ||
|
kg marked this conversation as resolved.
|
||
| #endif | ||
|
|
||
|
kg marked this conversation as resolved.
|
||
| #ifdef FEATURE_MULTITHREADING | ||
| #error The current assembly implementation of write barriers assumes single-threaded Wasm | ||
| #endif | ||
|
|
||
| #ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES | ||
| #error The current assembly implementation of write barriers does not implement card bundles | ||
| #endif | ||
|
|
||
| // To simplify integration with the rest of the codebase and avoid complicating the build | ||
| // system, Wasm write barriers are implemented using inline assembly inside C functions, below. | ||
| // These write barriers use the Wasm-specific FCDECL2_RAW for a native calling convention instead | ||
| // of a managed calling convention (to omit the sp and pep parameters). This reduces code size | ||
| // considerably and simplifies the JIT. In order to make it safe to call these write barriers from | ||
| // inside of a managed function without manually updating the __stack_pointer global, the barriers | ||
| // *must* be implemented without use of the linear memory stack, and the best way to guarantee that | ||
| // is to implement the barriers by hand in assembly. | ||
|
|
||
| #define ASM_HELPER_2(rettype, funcname, a1, a2) \ | ||
|
kg marked this conversation as resolved.
|
||
| EXTERN_C rettype __attribute__((naked)) F_CALL_CONV funcname(a1, a2) | ||
|
|
||
| // Helper to make relevant GC globals and constants visible inside of inline assembly | ||
| #define GC_ASM(text) \ | ||
| asm(text \ | ||
| :: [g_lowest_address] "i" (&g_lowest_address), \ | ||
| [g_highest_address] "i" (&g_highest_address), \ | ||
| [g_ephemeral_low] "i" (&g_ephemeral_low), \ | ||
| [g_ephemeral_high] "i" (&g_ephemeral_high), \ | ||
| [g_card_table] "i" (&g_card_table), \ | ||
| [card_byte_shift] "i" (card_byte_shift) \ | ||
| ) | ||
|
|
||
| EXTERN_C FCDECL2_RAW(VOID, RhpAssignRef, Object **dst, Object *ref); | ||
| ASM_HELPER_2(VOID, RhpAssignRef, Object **dst, Object *ref) | ||
| { | ||
| GC_ASM( | ||
| /* *dst = ref */ | ||
| "local.get 0\n" | ||
| "local.get 1\n" | ||
| "i32.store 0\n" | ||
| /* if ((ref < ephemeral_low) || (ref >= ephemeral_high)) return */ | ||
| "local.get 1\n" | ||
| "i32.const 0\n i32.load %[g_ephemeral_low]\n" | ||
| "i32.lt_u\n" | ||
| "local.get 1\n" | ||
| "i32.const 0\n i32.load %[g_ephemeral_high]\n" | ||
| "i32.ge_u\n" | ||
| "i32.or\n" | ||
| "if\n return\n end_if\n" | ||
| /* dst = &g_card_table[(dst >> card_byte_shift)] */ | ||
|
kg marked this conversation as resolved.
|
||
| "local.get 0\n" | ||
| "i32.const %[card_byte_shift]\n" | ||
| "i32.shr_u\n" | ||
| "i32.const 0\n" | ||
| "i32.load %[g_card_table]\n" | ||
| "i32.add\n" | ||
| "local.tee 0\n" | ||
| /* if (*dst == 255) return */ | ||
| "i32.load8_u 0\n" | ||
| "i32.const 255\n" | ||
| "i32.eq\n" | ||
| "if\n return\n end_if\n" | ||
| /* *dst = 255 */ | ||
| "local.get 0\n" | ||
| "i32.const 255\n" | ||
| "i32.store8 0\n" | ||
| "return\n" | ||
| ); | ||
| } | ||
|
|
||
| EXTERN_C FCDECL2_RAW(VOID, RhpCheckedAssignRef, Object **dst, Object *ref); | ||
| ASM_HELPER_2(VOID, RhpCheckedAssignRef, Object **dst, Object *ref) | ||
| { | ||
| GC_ASM( | ||
| /* *dst = ref */ | ||
| "local.get 0\n" | ||
| "local.get 1\n" | ||
| "i32.store 0\n" | ||
| /* if ((dst < lowest) || (dst >= highest)) return */ | ||
| "local.get 0\n" | ||
| "i32.const 0\n i32.load %[g_lowest_address]\n" | ||
| "i32.lt_u\n" | ||
| "local.get 0\n" | ||
| "i32.const 0\n i32.load %[g_highest_address]\n" | ||
| "i32.ge_u\n" | ||
| "i32.or\n" | ||
| "if\n return\n end_if\n" | ||
| /* if ((ref < ephemeral_low) || (ref >= ephemeral_high)) return */ | ||
| "local.get 1\n" | ||
| "i32.const 0\n i32.load %[g_ephemeral_low]\n" | ||
| "i32.lt_u\n" | ||
| "local.get 1\n" | ||
| "i32.const 0\n i32.load %[g_ephemeral_high]\n" | ||
| "i32.ge_u\n" | ||
| "i32.or\n" | ||
| "if\n return\n end_if\n" | ||
| /* dst = &g_card_table[(dst >> card_byte_shift)] */ | ||
| "local.get 0\n" | ||
| "i32.const %[card_byte_shift]\n" | ||
| "i32.shr_u\n" | ||
| "i32.const 0\n" | ||
| "i32.load %[g_card_table]\n" | ||
| "i32.add\n" | ||
| "local.tee 0\n" | ||
| /* if (*dst == 255) return */ | ||
| "i32.load8_u 0\n" | ||
| "i32.const 255\n" | ||
| "i32.eq\n" | ||
| "if\n return\n end_if\n" | ||
| /* *dst = 255 */ | ||
| "local.get 0\n" | ||
| "i32.const 255\n" | ||
| "i32.store8 0\n" | ||
| "return\n" | ||
| ); | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.