forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathilstubcache.h
130 lines (106 loc) · 3.68 KB
/
ilstubcache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// File: ILStubCache.h
//
//
#ifdef _MSC_VER
#pragma once
#endif // _MSC_VER
#ifndef _ILSTUBCACHE_H
#define _ILSTUBCACHE_H
#include "vars.hpp"
#include "util.hpp"
#include "crst.h"
#include "stubgen.h"
class ILStubHashBlobBase
{
public:
size_t m_cbSizeOfBlob; // this is size of entire object!!
};
class ILStubHashBlob : public ILStubHashBlobBase
{
public:
BYTE m_rgbBlobData[1];
};
class LoaderAllocator;
//
// This class caches MethodDesc's for dynamically generated IL stubs, it is not
// persisted in NGEN images.
//
class ILStubCache final
{
public:
//---------------------------------------------------------
// Constructor
//---------------------------------------------------------
ILStubCache(LoaderAllocator* pAllocator = NULL);
void Init(LoaderAllocator* pAllocator);
MethodDesc* GetStubMethodDesc(
MethodDesc *pTargetMD,
ILStubHashBlob* pHashBlob,
DWORD dwStubFlags, // bitmask of NDirectStubFlags
Module* pSigModule,
Module* pSigLoaderModule,
PCCOR_SIGNATURE pSig,
DWORD cbSig,
SigTypeContext* pTypeContext,
AllocMemTracker* pamTracker,
bool& bILStubCreator,
MethodDesc* pLastMD);
void DeleteEntry(ILStubHashBlob* pHashBlob);
void AddMethodDescChunkWithLockTaken(MethodDesc *pMD);
static MethodDesc* CreateAndLinkNewILStubMethodDesc(
LoaderAllocator* pAllocator,
MethodTable* pMT,
DWORD dwStubFlags, // bitmask of NDirectStubFlags
Module* pSigModule,
PCCOR_SIGNATURE pSig,
DWORD cbSig,
SigTypeContext *pTypeContext,
ILStubLinker* pStubLinker);
MethodTable * GetStubMethodTable()
{
LIMITED_METHOD_CONTRACT;
return m_pStubMT;
}
MethodTable* GetOrCreateStubMethodTable(Module* pLoaderModule);
MethodDesc* LookupStubMethodDesc(ILStubHashBlob* pHashBlob);
// Insert a stub MethodDesc into the cache
// If one is already present at a matching hash blob, return the already present one, otherwise, return pMD
MethodDesc* InsertStubMethodDesc(MethodDesc* pMD, ILStubHashBlob* pHashBlob);
private: // static
static MethodDesc* CreateNewMethodDesc(
LoaderHeap* pCreationHeap,
MethodTable* pMT,
DWORD dwStubFlags, // bitmask of NDirectStubFlags
Module* pSigModule,
PCCOR_SIGNATURE pSig,
DWORD cbSig,
SigTypeContext *pTypeContext,
AllocMemTracker* pamTracker);
private: // Inner classes
struct ILStubCacheEntry
{
MethodDesc *m_pMethodDesc;
ILStubHashBlob *m_pBlob;
};
class ILStubCacheTraits : public DefaultSHashTraits<ILStubCacheEntry>
{
public:
using key_t = const ILStubHashBlob *;
static const key_t GetKey(_In_ const element_t& e) { LIMITED_METHOD_CONTRACT; return e.m_pBlob; }
static count_t Hash(_In_ key_t key);
static bool Equals(_In_ key_t lhs, _In_ key_t rhs);
static bool IsNull(_In_ const element_t& e) { LIMITED_METHOD_CONTRACT; return e.m_pMethodDesc == NULL; }
static const element_t Null() { LIMITED_METHOD_CONTRACT; return ILStubCacheEntry(); }
static bool IsDeleted(const element_t &e) { LIMITED_METHOD_CONTRACT; return e.m_pMethodDesc == (MethodDesc *)-1; }
static const element_t Deleted() { LIMITED_METHOD_CONTRACT; return ILStubCacheEntry{(MethodDesc *)-1, NULL}; }
};
private:
Crst m_crst;
LoaderAllocator*m_pAllocator;
MethodTable* m_pStubMT;
SHash<ILStubCacheTraits> m_hashMap;
};
#endif //_ILSTUBCACHE_H