-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[release/8.0] Use unordered_map in DacInstanceManager in lieu of hand-rolled hash table #125487
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
Closed
Closed
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -14,12 +14,10 @@ | |
| #define __DACIMPL_H__ | ||
|
|
||
| #include "gcinterface.dac.h" | ||
|
|
||
| //--------------------------------------------------------------------------------------- | ||
| // Setting DAC_HASHTABLE tells the DAC to use the hand rolled hashtable for | ||
| // storing code:DAC_INSTANCE . Otherwise, the DAC uses the STL unordered_map to. | ||
|
|
||
| #define DAC_HASHTABLE | ||
|
|
||
| #ifndef DAC_HASHTABLE | ||
| #pragma push_macro("return") | ||
| #undef return | ||
|
|
@@ -736,9 +734,8 @@ class DacInstanceManager | |
| // This has the benefit of scaling to different workloads appropriately (as opposed to having a | ||
| // fixed number of buckets). | ||
|
|
||
| class DacHashCompare : public std::hash_compare<TADDR> | ||
| struct DacInstanceHashFunc | ||
| { | ||
| public: | ||
| // Custom hash function | ||
| // The default hash function uses a pseudo-randomizing function to get a random | ||
| // distribution. In our case, we'd actually like a more even distribution to get | ||
|
|
@@ -755,29 +752,13 @@ class DacInstanceManager | |
| // The default pseudo-randomizing function also requires a call to ldiv which shows up as | ||
| // a 3%-5% perf hit in most perf-sensitive scenarios, so this should also always be | ||
| // faster. | ||
| inline size_t operator()(const TADDR& keyval) const | ||
| std::size_t operator()(const TADDR& keyval) const noexcept | ||
| { | ||
| return (unsigned)(keyval >>DAC_INSTANCE_HASH_SHIFT); | ||
| return (std::size_t)(keyval >>DAC_INSTANCE_HASH_SHIFT); | ||
| } | ||
|
|
||
| // Explicitly bring in the two-argument comparison function from the base class (just less-than) | ||
| // This is necessary because once we override one form of operator() above, we don't automatically | ||
| // get the others by C++ inheritance rules. | ||
| using std::hash_compare<TADDR>::operator(); | ||
|
|
||
| #ifdef NIDUMP_CUSTOMIZED_DAC_HASH // not set | ||
| //this particular number is supposed to be roughly the same amount of | ||
| //memory as the old code (buckets * number of entries in the old | ||
| //blocks.) | ||
| //disabled for now. May tweak implementation later. It turns out that | ||
| //having a large number of initial buckets is excellent for nidump, but it | ||
| // is terrible for most other scenarios due to the cost of clearing them at | ||
| // every Flush. Once there is a better perf suite, we can tweak these values more. | ||
| static const size_t min_buckets = DAC_INSTANCE_HASH_SIZE * 256; | ||
| #endif | ||
|
|
||
| }; | ||
| typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash; | ||
|
|
||
| typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacInstanceHashFunc> DacInstanceHash; | ||
|
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. We have been limiting use of standard C++ library in our shipping binaries: This is probably the first use of |
||
| typedef DacInstanceHash::value_type DacInstanceHashValue; | ||
| typedef DacInstanceHash::iterator DacInstanceHashIterator; | ||
| DacInstanceHash m_hash; | ||
|
|
||
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.
In this code path, the later "verify descending order" debug check is ineffective because
targetis overwritten withinstbefore the size comparison, so it will always compareinst->sizeto itself. If the goal is to validate ordering against the previous entry for this address, capture the old value (e.g., viainst->next) and compare against that before overwritingtarget.