- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
[clr-interp] Fix conservative reporting data in gc enumeration #119867
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
Conversation
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.
Pull Request Overview
This PR fixes a bug in the garbage collection (GC) enumeration for the CLR interpreter by preventing inappropriate promotion of conservative roots during the relocate phase.
- Adds conditional logic to skip promotion for pinned objects during relocate phase
 - Restructures the existing interior pointer handling into clearer conditional blocks
 - Prevents conservative reporting from incorrectly reporting roots during GC relocate phase
 
| 
           /azp run runtime-interpreter  | 
    
| 
          
Azure Pipelines successfully started running 1 pipeline(s). | 
    
| 
           Tagging subscribers to this area: @BrzVlad, @janvorli, @kg  | 
    
| 
           LGTM  | 
    
| 
           @jkotas could you provide an opinion here? I think that this is correct, but I'd be interested to see if you think we shouldn't have such a change outside of the FEATURE_INTERPRETER path. Notably, this is NOT localized to the interpreter codebase. It will change all pinned pointers to not be reported during the relocate phase of gc scanning.  | 
    
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 looks correct to me.
Alternatively, it can be checked on the GC side as the first thing in Relocate callback. It would save us from checking the bit during promotion. The stackroot reporting is relatively expensive - it is unlikely to make a material difference.
If we keep it here, we may want to make the same change in NAOT clone of this method for consistency:
runtime/src/coreclr/nativeaot/Runtime/GcEnum.cpp
Lines 68 to 82 in 6246c4d
| static void GcEnumObject(PTR_PTR_Object ppObj, uint32_t flags, ScanFunc* fnGcEnumRef, ScanContext* pSc) | |
| { | |
| // | |
| // Sanity check that the flags contain only these values | |
| // | |
| assert((flags & ~(GC_CALL_INTERIOR | GC_CALL_PINNED)) == 0); | |
| // for interior pointers, we optimize the case in which | |
| // it points into the current threads stack area | |
| // | |
| if (flags & GC_CALL_INTERIOR) | |
| PromoteCarefully(ppObj, flags, fnGcEnumRef, pSc); | |
| else | |
| fnGcEnumRef(ppObj, pSc, flags); | |
| } | 
| 
           @jkotas, I decided against moving the check to GCHeap::Relocate, since that function is potentially called on somewhat more expensive constructs like promoting the background roots and such. Again, not something that is likely a problem, but stack root marking is definitely expensive enough that a single check isn't going to break the world.  | 
    
…t#119867) Co-authored-by: Jan Kotas <jkotas@microsoft.com>
I found that if the conservative reference pointed into the GC it caused problems in the relocation logic in the GC. For all forms of pinned references, the relocation phase isn't necessary, so add a check for it and avoid the problem.