| 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. |
| 4 | // =========================================================================== |
| 5 | // File: ILInstrumentation.h |
| 6 | // |
| 7 | // =========================================================================== |
| 8 | |
| 9 | |
| 10 | |
| 11 | #ifndef IL_INSTRUMENTATION_H |
| 12 | #define IL_INSTRUMENTATION_H |
| 13 | |
| 14 | // declare an array type of COR_IL_MAP entries |
| 15 | typedef ArrayDPTR(COR_IL_MAP) ARRAY_PTR_COR_IL_MAP; |
| 16 | |
| 17 | //--------------------------------------------------------------------------------------- |
| 18 | // |
| 19 | // A profiler may instrument a method by changing the IL. This is typically done when the profiler receives |
| 20 | // a JITCompilationStarted notification. The profiler also has the option to provide the runtime with |
| 21 | // a mapping between original IL offsets and instrumented IL offsets. This struct is a simple container |
| 22 | // for storing the mapping information. We store the mapping information on the Module class, where it can |
| 23 | // be accessed by the debugger from out-of-process. |
| 24 | // |
| 25 | |
| 26 | class InstrumentedILOffsetMapping |
| 27 | { |
| 28 | public: |
| 29 | InstrumentedILOffsetMapping(); |
| 30 | |
| 31 | // Check whether there is any mapping information stored in this object. |
| 32 | BOOL IsNull() const; |
| 33 | |
| 34 | #if !defined(DACCESS_COMPILE) |
| 35 | // Release the memory used by the array of COR_IL_MAPs. |
| 36 | void Clear(); |
| 37 | |
| 38 | void SetMappingInfo(SIZE_T cMap, COR_IL_MAP * rgMap); |
| 39 | #endif // !DACCESS_COMPILE |
| 40 | |
| 41 | SIZE_T GetCount() const; |
| 42 | ARRAY_PTR_COR_IL_MAP GetOffsets() const; |
| 43 | |
| 44 | private: |
| 45 | SIZE_T m_cMap; // the number of elements in m_rgMap |
| 46 | ARRAY_PTR_COR_IL_MAP m_rgMap; // an array of COR_IL_MAPs |
| 47 | }; |
| 48 | |
| 49 | //--------------------------------------------------------------------------------------- |
| 50 | // |
| 51 | // Hash table entry for storing InstrumentedILOffsetMapping. This is keyed by the MethodDef token. |
| 52 | // |
| 53 | |
| 54 | struct ILOffsetMappingEntry |
| 55 | { |
| 56 | ILOffsetMappingEntry() |
| 57 | { |
| 58 | LIMITED_METHOD_DAC_CONTRACT; |
| 59 | |
| 60 | m_methodToken = mdMethodDefNil; |
| 61 | // No need to initialize m_mapping. The default ctor of InstrumentedILOffsetMapping does the job. |
| 62 | } |
| 63 | |
| 64 | ILOffsetMappingEntry(mdMethodDef token, InstrumentedILOffsetMapping mapping) |
| 65 | { |
| 66 | LIMITED_METHOD_DAC_CONTRACT; |
| 67 | |
| 68 | m_methodToken = token; |
| 69 | m_mapping = mapping; |
| 70 | } |
| 71 | |
| 72 | mdMethodDef m_methodToken; |
| 73 | InstrumentedILOffsetMapping m_mapping; |
| 74 | }; |
| 75 | |
| 76 | //--------------------------------------------------------------------------------------- |
| 77 | // |
| 78 | // This class is used to create the hash table for the instrumented IL offset mapping. |
| 79 | // It encapsulates the desired behaviour of the templated hash table and implements |
| 80 | // the various functions needed by the hash table. |
| 81 | // |
| 82 | |
| 83 | class ILOffsetMappingTraits : public NoRemoveSHashTraits<DefaultSHashTraits<ILOffsetMappingEntry> > |
| 84 | { |
| 85 | public: |
| 86 | typedef mdMethodDef key_t; |
| 87 | |
| 88 | static key_t GetKey(element_t e) |
| 89 | { |
| 90 | LIMITED_METHOD_DAC_CONTRACT; |
| 91 | return e.m_methodToken; |
| 92 | } |
| 93 | static BOOL Equals(key_t k1, key_t k2) |
| 94 | { |
| 95 | LIMITED_METHOD_DAC_CONTRACT; |
| 96 | return (k1 == k2); |
| 97 | } |
| 98 | static count_t Hash(key_t k) |
| 99 | { |
| 100 | LIMITED_METHOD_DAC_CONTRACT; |
| 101 | return (count_t)(size_t)k; |
| 102 | } |
| 103 | static const element_t Null() |
| 104 | { |
| 105 | LIMITED_METHOD_DAC_CONTRACT; |
| 106 | ILOffsetMappingEntry e; |
| 107 | return e; |
| 108 | } |
| 109 | static bool IsNull(const element_t &e) { LIMITED_METHOD_DAC_CONTRACT; return e.m_methodToken == mdMethodDefNil; } |
| 110 | }; |
| 111 | |
| 112 | // Hash table of profiler-provided instrumented IL offset mapping, keyed by the MethodDef token |
| 113 | typedef SHash<ILOffsetMappingTraits> ILOffsetMappingTable; |
| 114 | typedef DPTR(ILOffsetMappingTable) PTR_ILOffsetMappingTable; |
| 115 | |
| 116 | #endif // IL_INSTRUMENTATION_H |
| 117 | |