summaryrefslogtreecommitdiff
path: root/src/vm/methodimpl.h
blob: 3cac85f08b6b25b3555af69412c8a3f56688d6e4 (plain)
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
131
132
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
//
// File: methodimpl.h
//


//

//
// ============================================================================

#ifndef _METHODIMPL_H 
#define _METHODIMPL_H

class MethodDesc;

// <TODO>@TODO: This is very bloated. We need to trim this down alot. However,
// we need to keep it on a 8 byte boundary.</TODO>
class MethodImpl
{
#ifdef DACCESS_COMPILE
    friend class NativeImageDumper;
#endif
#ifdef BINDER
    friend class MdilModule;    // this allows it to get the offset of pdwSlots and pImplementedMD
#endif

    PTR_DWORD            pdwSlots;       // Maintains the slots in sorted order, the first entry is the size
    DPTR(PTR_MethodDesc) pImplementedMD;

public:

#ifndef DACCESS_COMPILE 
    ///////////////////////////////////////////////////////////////////////////////////////
    class Iterator
    {
    private:
        MethodDesc *m_pMD;
        MethodImpl *m_pImpl;
        DWORD       m_iCur;

    public:
        Iterator(MethodDesc *pMD);
        inline BOOL IsValid()
            { WRAPPER_NO_CONTRACT; return ((m_pImpl != NULL)&& (m_iCur < m_pImpl->GetSize())); }
        inline void Next()
            { WRAPPER_NO_CONTRACT; if (IsValid()) m_iCur++; }
        inline WORD GetSlot()
            { WRAPPER_NO_CONTRACT; CONSISTENCY_CHECK(IsValid()); _ASSERTE(FitsIn<WORD>(m_pImpl->GetSlots()[m_iCur])); return static_cast<WORD>(m_pImpl->GetSlots()[m_iCur]); }
        inline MethodDesc *GetMethodDesc()
            { WRAPPER_NO_CONTRACT; return m_pImpl->FindMethodDesc(GetSlot(), (PTR_MethodDesc) m_pMD); }
    };

    ///////////////////////////////////////////////////////////////////////////////////////
    inline MethodDesc** GetImplementedMDs()
    {
        CONTRACTL {
            NOTHROW;
            GC_NOTRIGGER;
            PRECONDITION(CheckPointer(this));
        } CONTRACTL_END;
        return pImplementedMD;
    }
#endif // !DACCESS_COMPILE

    ///////////////////////////////////////////////////////////////////////////////////////
    inline DWORD GetSize()
    {
        CONTRACTL {
            NOTHROW;
            GC_NOTRIGGER;
            PRECONDITION(CheckPointer(this));
        } CONTRACTL_END;

        if(pdwSlots == NULL)
            return 0;
        else
            return *pdwSlots;
    }

    ///////////////////////////////////////////////////////////////////////////////////////
    inline PTR_DWORD GetSlots()
    {
        CONTRACTL {
            NOTHROW;
            GC_NOTRIGGER;
            PRECONDITION(CheckPointer(this));
            SUPPORTS_DAC;
        } CONTRACTL_END;

        if(pdwSlots == NULL)
            return NULL;
        else
            return pdwSlots + 1;
    }

#ifndef DACCESS_COMPILE 

    ///////////////////////////////////////////////////////////////////////////////////////
    void SetSize(LoaderHeap *pHeap, AllocMemTracker *pamTracker, DWORD size);

    ///////////////////////////////////////////////////////////////////////////////////////
    void SetData(DWORD* slots, MethodDesc** md);

#endif // !DACCESS_COMPILE

#ifdef DACCESS_COMPILE 
    void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif

#ifdef FEATURE_PREJIT 
    void Save(DataImage *image);
    void Fixup(DataImage *image, PVOID p, SSIZE_T offset);
#endif // FEATURE_PREJIT


    // Returns the method desc for the replaced slot;
    PTR_MethodDesc FindMethodDesc(DWORD slot, PTR_MethodDesc defaultReturn);

private:
    static const DWORD INVALID_INDEX = (DWORD)(-1);
    DWORD FindSlotIndex(DWORD slot);
#ifndef DACCESS_COMPILE 
    MethodDesc* RestoreSlot(DWORD slotIndex, MethodTable *pMT);
#endif

};

#endif // !_METHODIMPL_H