| 1 | // |
|---|---|
| 2 | // Copyright (c) Microsoft. All rights reserved. |
| 3 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 4 | // |
| 5 | |
| 6 | #include "standardpch.h" |
| 7 | #include "runtimedetails.h" |
| 8 | #include "spmiutil.h" |
| 9 | #include "jithost.h" |
| 10 | |
| 11 | JitHost* g_ourJitHost; |
| 12 | |
| 13 | JitHost::JitHost(ICorJitHost* wrappedHost, MethodContext* methodContext) : wrappedHost(wrappedHost), mc(methodContext) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | void JitHost::setMethodContext(MethodContext* methodContext) |
| 18 | { |
| 19 | this->mc = methodContext; |
| 20 | } |
| 21 | |
| 22 | void* JitHost::allocateMemory(size_t size) |
| 23 | { |
| 24 | return wrappedHost->allocateMemory(size); |
| 25 | } |
| 26 | |
| 27 | void JitHost::freeMemory(void* block) |
| 28 | { |
| 29 | return wrappedHost->freeMemory(block); |
| 30 | } |
| 31 | |
| 32 | int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue) |
| 33 | { |
| 34 | mc->cr->AddCall("getIntConfigValue"); |
| 35 | int result = wrappedHost->getIntConfigValue(key, defaultValue); |
| 36 | |
| 37 | // The JIT eagerly asks about every config value. If we store all these |
| 38 | // queries, it takes almost half the MC file space. So only store the |
| 39 | // non-default answers. |
| 40 | if (result != defaultValue) |
| 41 | { |
| 42 | mc->recGetIntConfigValue(key, defaultValue, result); |
| 43 | } |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | const wchar_t* JitHost::getStringConfigValue(const wchar_t* key) |
| 48 | { |
| 49 | mc->cr->AddCall("getStringConfigValue"); |
| 50 | const wchar_t* result = wrappedHost->getStringConfigValue(key); |
| 51 | |
| 52 | // Don't store null returns, which is the default |
| 53 | if (result != nullptr) |
| 54 | { |
| 55 | mc->recGetStringConfigValue(key, result); |
| 56 | } |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | void JitHost::freeStringConfigValue(const wchar_t* value) |
| 61 | { |
| 62 | mc->cr->AddCall("freeStringConfigValue"); |
| 63 | wrappedHost->freeStringConfigValue(value); |
| 64 | } |
| 65 |