Welcome to mirror list, hosted at ThFree Co, Russian Federation.

onstackreplacement.cpp « vm « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10668188a4e600d4bb417681e65d469b9a654f64 (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ===========================================================================
// File: onstackreplacement.cpp
//
// ===========================================================================

#include "common.h"
#include "onstackreplacement.h"

#ifdef FEATURE_ON_STACK_REPLACEMENT


CrstStatic OnStackReplacementManager::s_lock;

#if _DEBUG
int OnStackReplacementManager::s_patchpointId = 0;
#endif

#ifndef DACCESS_COMPILE

void OnStackReplacementManager::StaticInitialize()
{
    WRAPPER_NO_CONTRACT;
    s_lock.Init(CrstJitPatchpoint, CrstFlags(CRST_UNSAFE_COOPGC));
}

OnStackReplacementManager::OnStackReplacementManager(LoaderAllocator * loaderAllocator) : m_allocator(loaderAllocator), m_jitPatchpointTable()
{
    CONTRACTL
    {
        GC_NOTRIGGER;
        CAN_TAKE_LOCK;
        MODE_ANY;
    }
    CONTRACTL_END;

    LockOwner lock = {&s_lock, IsOwnerOfCrst};
    m_jitPatchpointTable.Init(INITIAL_TABLE_SIZE, &lock, m_allocator->GetLowFrequencyHeap());
}

// Fetch or create patchpoint info for this patchpoint.
PerPatchpointInfo* OnStackReplacementManager::GetPerPatchpointInfo(PCODE ip)
{
    CONTRACTL
    {
        GC_NOTRIGGER;
        CAN_TAKE_LOCK;
        MODE_COOPERATIVE;
    }
    CONTRACTL_END;

    PTR_PCODE ppId = dac_cast<PTR_PCODE>(ip);
    PTR_PerPatchpointInfo ppInfo = NULL;

    BOOL hasData = m_jitPatchpointTable.GetValueSpeculative(ppId, (HashDatum*)&ppInfo);

    if (!hasData)
    {
        CrstHolder lock(&s_lock);
        hasData = m_jitPatchpointTable.GetValue(ppId, (HashDatum*)&ppInfo);

        if (!hasData)
        {
            void * pMem = m_allocator->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(PerPatchpointInfo)));
            ppInfo = dac_cast<PTR_PerPatchpointInfo>(new (pMem) PerPatchpointInfo());
            m_jitPatchpointTable.InsertValue(ppId, (HashDatum)ppInfo);

#if _DEBUG
            ppInfo->m_patchpointId = ++s_patchpointId;
#endif

        }
    }

    return ppInfo;
}

#endif // !DACCESS_COMPILE

#endif // FEATURE_ON_STACK_REPLACEMENT