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

[cdac] ExecutionManager contract and RangeSectionMap lookup unit tests #108685

Merged
merged 27 commits into from
Oct 17, 2024

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Oct 8, 2024

RangeSectionMap is a data structure for coarse-grained lookups to man native code pointers to managed method descriptors that cover the entire addressable memory.

This PR adds unit tests for the cdac reader RangeSectionMap lookup algorithm and some unit tests for the ExecutionManager contract APIs that use a RangeSectionMap and NibbleMap together to do a full TargetCodePointer->MethodDesc lookup

Contributes to #108553

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 8, 2024
@lambdageek lambdageek removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 8, 2024
Copy link
Contributor

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

*  add RangeSectionMap docs

*  exhaustively test RangeSectionMap.EffectiveBitsForLevel

*  fix lookup in RangeSection.Find

    RangeSectionLookupAlgorithm.FindFragment finds the slot containing the range section fragment pointer.
    Have to dereference it once to get the actual RangeSectionFragment pointer from the slot.

    This "worked" before because RangeSectionFragment.Next is at offset 0, so the first lookup would have a garbage range, so we would follow the "next" field and get to the correct fragment

*   make a testable RangeSectionMap.FindFragmentInternal

*   brief nibble map summary

*   [cdac] Implement NibbleMap lookup and tests

    The execution manager uses a nibble map to quickly map program counter
    pointers to the beginnings of the native code for the managed method.

    Implement the lookup algorithm for a nibble map.

    Start adding unit tests for the nibble map

    Also for testing in MockMemorySpace simplify ReaderContext, there's nothing special about the descriptor HeapFragments anymore.  We can use a uniform reader.

*   NibbleMap: fix bug and add test

    Previously we incorrectly computed the prior map index when doing the backward linear search

*   [testing] display Target values in hex in debugger views

*   MockMemorySpace: simplify ReaderContext

    there's nothing special about the descriptor HeapFragments anymore.  We can use a uniform reader

*   refactor ExecutionManager

*   ExecutionManager contract

    the presence of RangeSection.R2RModule is a discriminator for whether we're looking at EE code or R2R code

*   WIP NibbleMap

*   WIP JitCodeToMethodInfo

*   WIP RangeSectionMap
The EECodeInfo includes the relative offset (given ip - start of method) so it's not ok to share for different code pointers into the same method
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
docs/design/datacontracts/ExecutionManager.md Outdated Show resolved Hide resolved
return FindFragmentInternal(target, topRangeSectionMap.TopLevelData, jittedCodeAddress)?.LoadValue(target).Address ?? TargetPointer.Null;
}

internal Cursor? FindFragmentInternal(Target target, TargetPointer topMap, TargetCodePointer jittedCodeAddress)
Copy link
Member

Choose a reason for hiding this comment

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

Can this just be merged into FindFragment? What is the split into FindFragmentInternal getting us?

Copy link
Member Author

Choose a reason for hiding this comment

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

Easier testing. I don't need to mock up a Data.RangeSectionMap value

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it's a bit more than that. We also avoid making the Cursor type visible in callers.

@lambdageek
Copy link
Member Author

@elinor-fung applied all of your suggestions


[Theory]
[ClassData(typeof(MockTarget.StdArch))]
public void TestLookupOne(MockTarget.Architecture arch)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be useful to also cover:

  • failing when there are (one or more) ranges in the map
  • success with more than one range fragments in the map

@elinor-fung
Copy link
Member

Last comments were minor around tests and test coverage. Since we already know there will be MethodDesc-related follow-ups (and this already made it through PR builds), I'm entirely fine with this going as-is.

lambdageek and others added 2 commits October 16, 2024 18:45
Co-authored-by: Elinor Fung <elfung@microsoft.com>
@lambdageek lambdageek merged commit 1b8f744 into dotnet:main Oct 17, 2024
149 of 151 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants