-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[cDAC] Implement EnumerateMonitorEventWaitList for cDAC #129054
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
Open
barosiak
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
barosiak:barosiak/EnumerateMonitorEventWaitList
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+308
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -3180,7 +3180,90 @@ public int GetThreadOwningMonitorLock(ulong vmObject, DacDbiMonitorLockInfo* pRe | |
| } | ||
|
|
||
| public int EnumerateMonitorEventWaitList(ulong vmObject, nint fpCallback, nint pUserData) | ||
| => LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.EnumerateMonitorEventWaitList(vmObject, fpCallback, pUserData) : HResults.E_NOTIMPL; | ||
| { | ||
| int hr = HResults.S_OK; | ||
| #if DEBUG | ||
| List<ulong>? cdacThreads = _legacy is not null ? new() : null; | ||
| #endif | ||
| try | ||
| { | ||
| var callback = (delegate* unmanaged<ulong, nint, void>)fpCallback; | ||
| if (callback == null) | ||
| throw new ArgumentNullException(nameof(fpCallback)); | ||
|
|
||
| TargetPointer syncBlock = _target.Contracts.Object.GetSyncBlockAddress(vmObject); | ||
|
|
||
| // no sync block means no wait list | ||
| if (syncBlock != TargetPointer.Null | ||
| && _target.Contracts.ManagedTypeSource.TryGetStaticFieldAddress( | ||
| "System.Threading.Monitor", "s_conditionTable", out TargetPointer conditionTableSlot)) | ||
| { | ||
| TargetPointer conditionTable = _target.ReadPointer(conditionTableSlot); | ||
|
|
||
| if (conditionTable != TargetPointer.Null | ||
| && _target.Contracts.ConditionalWeakTable.TryGetValue(conditionTable, new TargetPointer(vmObject), out TargetPointer condition)) | ||
| { | ||
| // Build a map of Waiter objects to their owning Threads. | ||
| var waiterToThreadMap = new Dictionary<ulong, TargetPointer>(); | ||
| Contracts.IThread threadContract = _target.Contracts.Thread; | ||
| Contracts.ThreadStoreData threadStore = threadContract.GetThreadStoreData(); | ||
| TargetPointer currentThread = threadStore.FirstThread; | ||
| while (currentThread != TargetPointer.Null) | ||
| { | ||
| Contracts.ThreadData threadData = threadContract.GetThreadData(currentThread); | ||
|
|
||
| if (_target.Contracts.ManagedTypeSource.TryGetThreadStaticFieldAddress( | ||
| "System.Threading.Condition", "t_waiterForCurrentThread", currentThread, out TargetPointer waiterSlot)) | ||
| { | ||
| TargetPointer waiterObj = _target.ReadPointer(waiterSlot); | ||
| if (waiterObj != TargetPointer.Null) | ||
|
Comment on lines
+3206
to
+3219
|
||
| waiterToThreadMap[waiterObj.Value] = currentThread; | ||
| } | ||
|
|
||
| currentThread = threadData.NextThread; | ||
| } | ||
|
|
||
| // Walk the waiters linked list and invoke callback for each matching thread | ||
| Target.TypeInfo conditionType = _target.Contracts.ManagedTypeSource.GetTypeInfo("System.Threading.Condition"); | ||
| TargetPointer waiter = _target.ReadPointer(condition + (ulong)conditionType.Fields["_waitersHead"].Offset); | ||
|
|
||
| Target.TypeInfo waiterType = _target.Contracts.ManagedTypeSource.GetTypeInfo("System.Threading.Condition+Waiter"); | ||
| while (waiter != TargetPointer.Null) | ||
| { | ||
| if (waiterToThreadMap.TryGetValue(waiter.Value, out TargetPointer thread)) | ||
| { | ||
| callback(thread.Value, pUserData); | ||
| #if DEBUG | ||
| cdacThreads?.Add(thread.Value); | ||
| #endif | ||
| } | ||
|
|
||
| waiter = _target.ReadPointer(waiter + (ulong)waiterType.Fields["next"].Offset); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch (System.Exception ex) | ||
| { | ||
| hr = ex.HResult; | ||
| } | ||
| #if DEBUG | ||
| if (_legacy is not null && fpCallback != 0) | ||
| List<ulong> dacThreads = new(); | ||
|
Comment on lines
+3251
to
+3252
Member
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. missing opening brace? |
||
| GCHandle dacHandle = GCHandle.Alloc(dacThreads); | ||
| int hrLocal = _legacy.EnumerateMonitorEventWaitList(vmObject, (nint)(delegate* unmanaged<ulong, nint, void>)&CollectEnumerationCallback, GCHandle.ToIntPtr(dacHandle)); | ||
| dacHandle.Free(); | ||
| Debug.ValidateHResult(hr, hrLocal); | ||
| if (hr == HResults.S_OK) | ||
| { | ||
| Debug.Assert( | ||
| cdacThreads!.SequenceEqual(dacThreads), | ||
| $"MonitorEventWaitList mismatch - cDAC: [{string.Join(",", cdacThreads!.Select(t => $"0x{t:x}"))}], DAC: [{string.Join(",", dacThreads.Select(t => $"0x{t:x}"))}]"); | ||
| } | ||
| } | ||
| #endif | ||
| return hr; | ||
| } | ||
|
|
||
| public int GetAttachStateFlags(int* pRetVal) | ||
| { | ||
|
|
||
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.
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.
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.
Wondering if we should put this in a contract to allow it to be versioned.