summaryrefslogtreecommitdiff
path: root/src/vm/typeequivalencehash.hpp
diff options
context:
space:
mode:
authordotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
committerdotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
commitef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch)
treedee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/vm/typeequivalencehash.hpp
downloadcoreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/vm/typeequivalencehash.hpp')
-rw-r--r--src/vm/typeequivalencehash.hpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/vm/typeequivalencehash.hpp b/src/vm/typeequivalencehash.hpp
new file mode 100644
index 0000000000..73912ba114
--- /dev/null
+++ b/src/vm/typeequivalencehash.hpp
@@ -0,0 +1,117 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+//
+// Hash table associated with each module that records for all types defined in that module the mapping
+// between type name and token (or TypeHandle).
+//
+
+#ifndef __TYPEEQUIVALENCE_HASH_INCLUDED
+#define __TYPEEQUIVALENCE_HASH_INCLUDED
+
+#include "ngenhash.h"
+
+#ifdef FEATURE_TYPEEQUIVALENCE
+
+// The type of each entry in the hash.
+typedef DPTR(struct TypeEquivalenceEntry) PTR_TypeEquivalenceEntry;
+typedef struct TypeEquivalenceEntry
+{
+ static NgenHashValue HashTypeHandles(TypeHandle thA, TypeHandle thB)
+ {
+ LIMITED_METHOD_CONTRACT;
+
+ UINT_PTR aPtr = thA.AsTAddr();
+ UINT_PTR bPtr = thB.AsTAddr();
+ DWORD hash = (DWORD)((aPtr + bPtr) >> 3);
+
+ return hash;
+ }
+
+ bool Match(TypeHandle thA, TypeHandle thB)
+ {
+ LIMITED_METHOD_CONTRACT;
+
+ return (((thA == m_thA) && (thB == m_thB)) ||
+ ((thB == m_thA) && (thA == m_thB)));
+ }
+
+ void SetData(TypeHandle thA, TypeHandle thB, bool fEquivalent)
+ {
+ LIMITED_METHOD_CONTRACT;
+
+ m_thA = thA;
+ m_thB = thB;
+ m_fEquivalent = fEquivalent;
+ }
+
+ bool GetEquivalence()
+ {
+ LIMITED_METHOD_CONTRACT;
+ return m_fEquivalent;
+ }
+
+private:
+
+ TypeHandle m_thA;
+ TypeHandle m_thB;
+ bool m_fEquivalent;
+} TypeEquivalenceEntry_t;
+
+// The hash type itself. All common logic is provided by the NgenHashTable templated base class. See
+// NgenHash.h for details.
+typedef DPTR(class TypeEquivalenceHashTable) PTR_TypeEquivalenceHashTable;
+class TypeEquivalenceHashTable : public NgenHashTable<TypeEquivalenceHashTable, TypeEquivalenceEntry, 4>
+{
+ friend class NgenHashTable<TypeEquivalenceHashTable, TypeEquivalenceEntry, 4>;
+#ifdef DACCESS_COMPILE
+ friend class NativeImageDumper;
+#endif
+
+public:
+ typedef enum EquivalenceMatch
+ {
+ MatchUnknown,
+ Match,
+ NoMatch
+ };
+
+ // The LookupContext type we export to track GetValue/FindNextNestedClass enumerations is simply a rename
+ // of the base classes' hash value enumerator.
+ typedef NgenHashTable<TypeEquivalenceHashTable, TypeEquivalenceEntry, 4>::LookupContext LookupContext;
+
+#ifndef DACCESS_COMPILE
+ static TypeEquivalenceHashTable *Create(AppDomain *pDomain, DWORD dwNumBuckets, CrstExplicitInit *pCrst);
+ void RecordEquivalence(TypeHandle thA, TypeHandle thB, EquivalenceMatch match);
+#endif
+ EquivalenceMatch CheckEquivalence(TypeHandle thA, TypeHandle thB);
+
+#ifdef DACCESS_COMPILE
+ void EnumMemoryRegionsForEntry(TypeEquivalenceEntry_t *pEntry, CLRDataEnumMemoryFlags flags) { return; }
+#endif
+
+#if defined(FEATURE_PREJIT) && !defined(DACCESS_COMPILE)
+private:
+
+ bool ShouldSave(DataImage *pImage, TypeEquivalenceEntry_t *pEntry) { return false; }
+ bool IsHotEntry(TypeEquivalenceEntry_t *pEntry, CorProfileData *pProfileData) { return false; }
+ bool SaveEntry(DataImage *pImage, CorProfileData *pProfileData, TypeEquivalenceEntry_t *pOldEntry, TypeEquivalenceEntry_t *pNewEntry, EntryMappingTable *pMap) { return true; }
+ void FixupEntry(DataImage *pImage, TypeEquivalenceEntry_t *pEntry, void *pFixupBase, DWORD cbFixupOffset) { return; }
+#endif // FEATURE_PREJIT && !DACCESS_COMPILE
+
+private:
+#ifndef DACCESS_COMPILE
+ TypeEquivalenceHashTable(LoaderHeap *pHeap, DWORD cInitialBuckets, CrstExplicitInit *pCrst) :
+ NgenHashTable<TypeEquivalenceHashTable, TypeEquivalenceEntry, 4>(NULL, pHeap, cInitialBuckets),
+ m_pHashTableCrst(pCrst)
+ {
+ }
+#endif
+ CrstExplicitInit* m_pHashTableCrst;
+};
+
+#endif // FEATURE_TYPEEQUIVALENCE
+
+#endif // !__CLASS_HASH_INCLUDED