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
6
7#ifndef _FPTRSTUBS_H
8#define _FPTRSTUBS_H
9
10#include "common.h"
11
12// FuncPtrStubs contains stubs that is used by GetMultiCallableAddrOfCode() if
13// the function has not been jitted. Using a stub decouples ldftn from
14// the prestub, so prestub does not need to be backpatched.
15//
16// This stub is also used in other places which need a function pointer
17
18class FuncPtrStubs
19{
20public :
21 FuncPtrStubs();
22
23 Precode* Lookup(MethodDesc * pMD, PrecodeType type);
24 PCODE GetFuncPtrStub(MethodDesc * pMD, PrecodeType type);
25
26 Precode* Lookup(MethodDesc * pMD)
27 {
28 return Lookup(pMD, GetDefaultType(pMD));
29 }
30
31 PCODE GetFuncPtrStub(MethodDesc * pMD)
32 {
33 return GetFuncPtrStub(pMD, GetDefaultType(pMD));
34 }
35
36 static PrecodeType GetDefaultType(MethodDesc* pMD);
37
38private:
39 Crst m_hashTableCrst;
40
41 struct PrecodeKey
42 {
43 PrecodeKey(MethodDesc* pMD, PrecodeType type)
44 : m_pMD(pMD), m_type(type)
45 {
46 }
47
48 MethodDesc* m_pMD;
49 PrecodeType m_type;
50 };
51
52 class PrecodeTraits : public NoRemoveSHashTraits< DefaultSHashTraits<Precode*> >
53 {
54 public:
55 typedef PrecodeKey key_t;
56
57 static key_t GetKey(element_t e)
58 {
59 CONTRACTL
60 {
61 NOTHROW;
62 GC_NOTRIGGER;
63 MODE_ANY;
64 }
65 CONTRACTL_END;
66 return PrecodeKey(e->GetMethodDesc(), e->GetType());
67 }
68 static BOOL Equals(key_t k1, key_t k2)
69 {
70 LIMITED_METHOD_CONTRACT;
71 return (k1.m_pMD == k2.m_pMD) && (k1.m_type == k2.m_type);
72 }
73 static count_t Hash(key_t k)
74 {
75 LIMITED_METHOD_CONTRACT;
76 return (count_t)(size_t)k.m_pMD ^ k.m_type;
77 }
78 };
79
80 SHash<PrecodeTraits> m_hashTable; // To find a existing stub for a method
81};
82
83#endif // _FPTRSTUBS_H
84