1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
9 // ZapNode that wraps EE datastructure for zapping
11 // ======================================================================================
13 #ifndef __ZAPWRAPPER_H__
14 #define __ZAPWRAPPER_H__
17 // When generating compiled code for IL, the compiler will need to embed
18 // handles, which are pointers to various data structures. The data
19 // structures may either not exist, or we may not have some information
20 // we need for optimal code gen.
22 // In such cases, we use placeholders. Compiled code embed pointers
23 // to placeholders, which then have rich information about the
24 // referenced data structure.
26 // Once information is finally available for the exact code required,
27 // ZapWrapper::Resolve makes the place holder to point to the intended target.
30 class ZapWrapper : public ZapNode
35 ZapWrapper(PVOID handle)
44 void SetHandle(PVOID handle)
46 _ASSERTE(m_handle == NULL);
47 _ASSERTE(handle != NULL);
56 virtual ZapNode * GetBase()
61 virtual void Resolve(ZapImage * pImage)
68 class WrapperTraits : public NoRemoveSHashTraits< DefaultSHashTraits<ZapWrapper *> >
73 static key_t GetKey(element_t e)
75 LIMITED_METHOD_CONTRACT;
76 return e->GetHandle();
78 static BOOL Equals(key_t k1, key_t k2)
80 LIMITED_METHOD_CONTRACT;
83 static count_t Hash(key_t k)
85 LIMITED_METHOD_CONTRACT;
86 return (count_t)(size_t)k;
89 static element_t Null() { LIMITED_METHOD_CONTRACT; return NULL; }
90 static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e == NULL; }
93 typedef SHash< WrapperTraits > WrapperTable;
95 WrapperTable m_entries;
99 // Helper for inserting actual implementations of placeholders into hashtable
101 template < typename impl, ZapNodeType type >
102 ZapNode * GetPlaceHolder(PVOID handle)
104 ZapWrapper * pPlaceHolder = m_entries.Lookup(handle);
106 if (pPlaceHolder != NULL)
108 _ASSERTE(pPlaceHolder->GetType() == type);
112 pPlaceHolder = new (m_pImage->GetHeap()) impl();
113 _ASSERTE(pPlaceHolder->GetType() == type);
114 pPlaceHolder->SetHandle(handle);
115 m_entries.Add(pPlaceHolder);
120 ZapWrapperTable(ZapImage * pImage)
125 void Preallocate(COUNT_T cbILImage)
127 PREALLOCATE_HASHTABLE(ZapWrapperTable::m_entries, 0.0013, cbILImage);
130 ZapNode * GetMethodHandle(CORINFO_METHOD_HANDLE handle);
131 ZapNode * GetClassHandle(CORINFO_CLASS_HANDLE handle);
132 ZapNode * GetFieldHandle(CORINFO_FIELD_HANDLE handle);
133 ZapNode * GetAddrOfPInvokeFixup(CORINFO_METHOD_HANDLE handle);
134 ZapNode * GetGenericHandle(CORINFO_GENERIC_HANDLE handle);
135 ZapNode * GetModuleIDHandle(CORINFO_MODULE_HANDLE handle);
137 ZapNode * GetStub(void * pStub);
142 #endif // __ZAPWRAPPER_H__