-
Notifications
You must be signed in to change notification settings - Fork 4.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
GC-report all associated LoaderAllocators #110856
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @mangod9 |
27573ee is being scheduled for building and testingGIT: |
27573ee is being scheduled for building and testingGIT: |
1 similar comment
27573ee is being scheduled for building and testingGIT: |
27573ee is being scheduled for building and testingGIT: |
I believe the bug is actually in reusing the image for a different loader allocator. We will need to fix that instead of the symptoms. |
I can have a look. To be exact, the fix would be suppressing image reuse for a different allocator or keeping the same allocator for reused images? In general, is multiple loader allocators per memory range valid? It's worth asserting if not. |
We do maintain one mapping per file path. It is how we end up reusing same image for different loader allocators. If we change to multiple mappings per file path, we will end up with different set of issues - for example, we won't be able to use LoadLibrary to map images on Windows anymore. |
I got mislead, I have forgotten that we don't allow loading R2R stuff into ALCs, so I have thought that the issue is about sharing the actual machine code, which we should not share. We share the IL stuff though, as @jkotas mentioned. |
Looking into it more - I have not remembered that we have added handling of RVA fields in collectible assemblies couple of years ago. That's why we record the ranges of collectible assemblies images to associate them with loader allocator and we can have multiple loader allocators associated with the range of the same image for this purpose. |
The fix looks correct then. I am sorry for the confusion. |
Infrastructure failure, I'll undraft when tests pass locally. |
Looks ok, PR ready for review. |
Fixes intermittent (about 1 fail in 100 runs) assert failure (refCollectionObject != NULL) in Interop/ICustomMarshaler/ConflictingNames/MultipleALCs with GCStress=0x3 on RISC-V. Symptom same as #47696 (abandoned because the issue relented spontaneously, the root cause was not found).
I did some more digging and it always failed when walking the following stack trace:
The problem was after ConflictingCustomMarshalerNamesInCollectibleLoadContexts_Succeeds() the LoaderAllocator's weak ref to its object was severed but LoaderAllocator was still associated with the loaded image memory range. Then in ConflictingCustomMarshalerNamesInNoncollectibleLoadContexts_Succeeds() the same file is loaded and another LoaderAllocator got associated with the reused image. The refs passed to SequenceEqual pointed to a method name whose bytes were in the loaded image. During GC in PromoteCarefully LoaderAllocator::GetAssociatedLoaderAllocator_Unsafe returned the first associated LoaderAllocator with the severed weak ref, which tripped the assertion.
I didn't find anything to prevent many LoaderAllocators being associated with the same memory range so I'm assuming it's valid state. The fix is to report all associated LoaderAllocators and assert if at least one of them has a valid ref to the exposed object.
Part of #84834, cc @dotnet/samsung @mangod9 @janvorli