From ef1e2ab328087c61a6878c1e84f4fc5d710aebce Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Fri, 30 Jan 2015 14:14:42 -0800 Subject: Initial commit to populate CoreCLR repo [tfs-changeset: 1407945] --- src/vm/typeequivalencehash.hpp | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/vm/typeequivalencehash.hpp (limited to 'src/vm/typeequivalencehash.hpp') 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 +{ + friend class NgenHashTable; +#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::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(NULL, pHeap, cInitialBuckets), + m_pHashTableCrst(pCrst) + { + } +#endif + CrstExplicitInit* m_pHashTableCrst; +}; + +#endif // FEATURE_TYPEEQUIVALENCE + +#endif // !__CLASS_HASH_INCLUDED -- cgit v1.2.3