| 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 | #ifndef __JITHOST_H__ |
| 6 | #define __JITHOST_H__ |
| 7 | |
| 8 | // Common implementation of ICorJitHost that respects CLR host policies. |
| 9 | class JitHost : public ICorJitHost |
| 10 | { |
| 11 | private: |
| 12 | static JitHost s_theJitHost; |
| 13 | |
| 14 | struct Slab |
| 15 | { |
| 16 | Slab * pNext; |
| 17 | size_t size; |
| 18 | Thread* affinity; |
| 19 | }; |
| 20 | |
| 21 | CrstStatic m_jitSlabAllocatorCrst; |
| 22 | Slab* m_pCurrentCachedList; |
| 23 | Slab* m_pPreviousCachedList; |
| 24 | size_t m_totalCached; |
| 25 | DWORD m_lastFlush; |
| 26 | |
| 27 | JitHost() {} |
| 28 | JitHost(const JitHost& other) = delete; |
| 29 | JitHost& operator=(const JitHost& other) = delete; |
| 30 | |
| 31 | void init(); |
| 32 | void reclaim(); |
| 33 | |
| 34 | public: |
| 35 | virtual void* allocateMemory(size_t size); |
| 36 | virtual void freeMemory(void* block); |
| 37 | virtual int getIntConfigValue(const wchar_t* name, int defaultValue); |
| 38 | virtual const wchar_t* getStringConfigValue(const wchar_t* name); |
| 39 | virtual void freeStringConfigValue(const wchar_t* value); |
| 40 | virtual void* allocateSlab(size_t size, size_t* pActualSize); |
| 41 | virtual void freeSlab(void* slab, size_t actualSize); |
| 42 | |
| 43 | static void Init() { s_theJitHost.init(); } |
| 44 | static void Reclaim() { s_theJitHost.reclaim(); } |
| 45 | |
| 46 | static ICorJitHost* getJitHost() { return &s_theJitHost; } |
| 47 | }; |
| 48 | |
| 49 | #endif // __JITHOST_H__ |
| 50 | |