summaryrefslogtreecommitdiff
path: root/src/vm/jithost.h
blob: b2ec67b3dee32b7600ce748afc0db09e7f1ba4aa (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#ifndef __JITHOST_H__
#define __JITHOST_H__

// Common implementation of ICorJitHost that respects CLR host policies.
class JitHost : public ICorJitHost
{
private:
    static JitHost s_theJitHost;

    struct Slab
    {
        Slab * pNext;
        size_t size;
        Thread* affinity;
    };

    CrstStatic m_jitSlabAllocatorCrst;
    Slab* m_pCurrentCachedList;
    Slab* m_pPreviousCachedList;
    size_t m_totalCached;
    DWORD m_lastFlush;

    JitHost() {}
    JitHost(const JitHost& other) = delete;
    JitHost& operator=(const JitHost& other) = delete;

    void init();
    void reclaim();

public:
    virtual void* allocateMemory(size_t size);
    virtual void freeMemory(void* block);
    virtual int getIntConfigValue(const wchar_t* name, int defaultValue);
    virtual const wchar_t* getStringConfigValue(const wchar_t* name);
    virtual void freeStringConfigValue(const wchar_t* value);
    virtual void* allocateSlab(size_t size, size_t* pActualSize);
    virtual void freeSlab(void* slab, size_t actualSize);

    static void Init() { s_theJitHost.init(); }
    static void Reclaim() { s_theJitHost.reclaim(); }

    static ICorJitHost* getJitHost() { return &s_theJitHost; }
};

#endif // __JITHOST_H__