未验证 提交 44ed52a8 编写于 作者: A Andrew Au 提交者: GitHub

Make GCToEEInterface::Get*ConfigValue check the runtimeconfig.json (#34797)

上级 cf66f084
......@@ -73,9 +73,9 @@ public:
static void HandleFatalError(unsigned int exitCode);
static bool EagerFinalized(Object* obj);
static MethodTable* GetFreeObjectMethodTable();
static bool GetBooleanConfigValue(const char* key, bool* value);
static bool GetIntConfigValue(const char* key, int64_t* value);
static bool GetStringConfigValue(const char* key, const char** value);
static bool GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value);
static bool GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value);
static bool GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value);
static void FreeStringConfigValue(const char* key);
static bool IsGCThread();
static bool WasCurrentThreadCreatedByGC();
......
......@@ -6,23 +6,23 @@
#include "gcenv.h"
#include "gc.h"
#define BOOL_CONFIG(name, key, default, unused_doc) \
bool GCConfig::Get##name() { return s_##name; } \
#define BOOL_CONFIG(name, unused_private_key, unused_public_key, default, unused_doc) \
bool GCConfig::Get##name() { return s_##name; } \
bool GCConfig::s_##name = default;
#define INT_CONFIG(name, key, default, unused_doc) \
int64_t GCConfig::Get##name() { return s_##name; } \
#define INT_CONFIG(name, unused_private_key, unused_public_key, default, unused_doc) \
int64_t GCConfig::Get##name() { return s_##name; } \
int64_t GCConfig::s_##name = default;
// String configs are not cached because 1) they are rare and
// not on hot paths and 2) they involve transfers of ownership
// of EE-allocated strings, which is potentially complicated.
#define STRING_CONFIG(name, key, unused_doc) \
GCConfigStringHolder GCConfig::Get##name() \
{ \
const char* resultStr = nullptr; \
GCToEEInterface::GetStringConfigValue(key, &resultStr); \
return GCConfigStringHolder(resultStr); \
#define STRING_CONFIG(name, private_key, public_key, unused_doc) \
GCConfigStringHolder GCConfig::Get##name() \
{ \
const char* resultStr = nullptr; \
GCToEEInterface::GetStringConfigValue(private_key, public_key, &resultStr); \
return GCConfigStringHolder(resultStr); \
}
GC_CONFIGURATION_KEYS
......@@ -33,18 +33,19 @@ GC_CONFIGURATION_KEYS
void GCConfig::Initialize()
{
#define BOOL_CONFIG(name, key, default, unused_doc) \
GCToEEInterface::GetBooleanConfigValue(key, &s_##name);
#define BOOL_CONFIG(name, private_key, public_key, default, unused_doc) \
GCToEEInterface::GetBooleanConfigValue(private_key, public_key, &s_##name);
#define INT_CONFIG(name, key, default, unused_doc) \
GCToEEInterface::GetIntConfigValue(key, &s_##name);
#define INT_CONFIG(name, private_key, public_key, default, unused_doc) \
GCToEEInterface::GetIntConfigValue(private_key, public_key, &s_##name);
#define STRING_CONFIG(unused_name, unused_key, unused_doc)
#define STRING_CONFIG(unused_name, unused_private_key, unused_public_key, unused_doc)
GC_CONFIGURATION_KEYS
#undef BOOL_CONFIG
#undef INT_CONFIG
#undef STRING_CONFIG
}
// Parse an integer index or range of two indices separated by '-'.
......
此差异已折叠。
......@@ -203,22 +203,22 @@ inline MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
return g_theGCToCLR->GetFreeObjectMethodTable();
}
inline bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
inline bool GCToEEInterface::GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetBooleanConfigValue(key, value);
return g_theGCToCLR->GetBooleanConfigValue(privateKey, publicKey, value);
}
inline bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
inline bool GCToEEInterface::GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetIntConfigValue(key, value);
return g_theGCToCLR->GetIntConfigValue(privateKey, publicKey, value);
}
inline bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
inline bool GCToEEInterface::GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetStringConfigValue(key, value);
return g_theGCToCLR->GetStringConfigValue(privateKey, publicKey, value);
}
inline void GCToEEInterface::FreeStringConfigValue(const char* value)
......
......@@ -348,13 +348,13 @@ public:
// pointer is undefined. Otherwise, true is returned and the config key's value is written to
// the passed-in pointer.
virtual
bool GetBooleanConfigValue(const char* key, bool* value) = 0;
bool GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value) = 0;
virtual
bool GetIntConfigValue(const char* key, int64_t* value) = 0;
bool GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value) = 0;
virtual
bool GetStringConfigValue(const char* key, const char** value) = 0;
bool GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value) = 0;
virtual
void FreeStringConfigValue(const char* value) = 0;
......
......@@ -275,17 +275,17 @@ bool GCToEEInterface::EagerFinalized(Object* obj)
return false;
}
bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
bool GCToEEInterface::GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value)
{
return false;
}
bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
bool GCToEEInterface::GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value)
{
return false;
}
bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
bool GCToEEInterface::GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value)
{
return false;
}
......
......@@ -35,7 +35,7 @@ public:
// in the traditional way separately if you need to.
//
// Returns value for name if found in config.
static ULONGLONG GetKnobULONGLONGValue(LPCWSTR name);
static ULONGLONG GetKnobULONGLONGValue(LPCWSTR name, ULONGLONG defaultValue);
// Returns (in priority order):
// - The value of the ConfigStringInfo if it's set
......
......@@ -79,7 +79,7 @@ DWORD Configuration::GetKnobDWORDValue(LPCWSTR name, DWORD defaultValue)
return defaultValue;
}
ULONGLONG Configuration::GetKnobULONGLONGValue(LPCWSTR name)
ULONGLONG Configuration::GetKnobULONGLONGValue(LPCWSTR name, ULONGLONG defaultValue)
{
LPCWSTR knobValue = GetConfigurationValue(name);
if (knobValue != nullptr)
......@@ -87,7 +87,7 @@ ULONGLONG Configuration::GetKnobULONGLONGValue(LPCWSTR name)
return _wcstoui64(knobValue, nullptr, 0);
}
return 0;
return defaultValue;
}
LPCWSTR Configuration::GetKnobStringValue(LPCWSTR name, const CLRConfig::ConfigStringInfo& stringInfo)
......
......@@ -114,8 +114,6 @@ HRESULT EEConfig::Init()
iGCHoardVM = 0;
iGCLOHCompactionMode = 0;
iGCLOHThreshold = 0;
iGCHeapCount = 0;
iGCNoAffinitize = 0;
iGCAffinityMask = 0;
#ifdef GCTRIMCOMMIT
......@@ -564,7 +562,7 @@ fTrackDynamicMethodDebugInfo = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_
#ifdef HOST_64BIT
iGCAffinityMask = GetConfigULONGLONG_DontUse_(CLRConfig::EXTERNAL_GCHeapAffinitizeMask, iGCAffinityMask);
if (!iGCAffinityMask) iGCAffinityMask = Configuration::GetKnobULONGLONGValue(W("System.GC.HeapAffinitizeMask"));
if (!iGCAffinityMask) iGCAffinityMask = Configuration::GetKnobULONGLONGValue(W("System.GC.HeapAffinitizeMask"), 0);
if (!iGCSegmentSize) iGCSegmentSize = GetConfigULONGLONG_DontUse_(CLRConfig::UNSUPPORTED_GCSegmentSize, iGCSegmentSize);
if (!iGCgen0size) iGCgen0size = GetConfigULONGLONG_DontUse_(CLRConfig::UNSUPPORTED_GCgen0size, iGCgen0size);
#else
......@@ -574,11 +572,10 @@ fTrackDynamicMethodDebugInfo = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_
if (!iGCgen0size) iGCgen0size = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCgen0size, iGCgen0size);
#endif //HOST_64BIT
const ULONGLONG ullHeapHardLimit = Configuration::GetKnobULONGLONGValue(W("System.GC.HeapHardLimit"));
const ULONGLONG ullHeapHardLimit = Configuration::GetKnobULONGLONGValue(W("System.GC.HeapHardLimit"), 0);
iGCHeapHardLimit = FitsIn<size_t, ULONGLONG>(ullHeapHardLimit)
? static_cast<size_t>(ullHeapHardLimit)
: ClrSafeInt<size_t>::MaxInt();
iGCHeapHardLimitPercent = Configuration::GetKnobDWORDValue(W("System.GC.HeapHardLimitPercent"), 0);
if (g_IGCHoardVM)
iGCHoardVM = g_IGCHoardVM;
......@@ -639,9 +636,6 @@ fTrackDynamicMethodDebugInfo = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_
#endif
iGCForceCompact = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_gcForceCompact, iGCForceCompact);
iGCNoAffinitize = Configuration::GetKnobBooleanValue(W("System.GC.NoAffinitize"),
CLRConfig::EXTERNAL_GCNoAffinitize);
iGCHeapCount = Configuration::GetKnobDWORDValue(W("System.GC.HeapCount"), CLRConfig::EXTERNAL_GCHeapCount);
fStressLog = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_StressLog, fStressLog) != 0;
fForceEnc = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_ForceEnc, fForceEnc) != 0;
......
......@@ -399,27 +399,24 @@ public:
GCStressFlags GetGCStressLevel() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GCStressFlags(iGCStress); }
#endif
bool IsGCBreakOnOOMEnabled() const {LIMITED_METHOD_CONTRACT; return fGCBreakOnOOM; }
bool IsGCBreakOnOOMEnabled() const {LIMITED_METHOD_CONTRACT; return fGCBreakOnOOM; }
size_t GetGCgen0size () const {LIMITED_METHOD_CONTRACT; return iGCgen0size; }
void SetGCgen0size (size_t iSize) {LIMITED_METHOD_CONTRACT; iGCgen0size = iSize; }
size_t GetSegmentSize () const {LIMITED_METHOD_CONTRACT; return iGCSegmentSize; }
void SetSegmentSize (size_t iSize) {LIMITED_METHOD_CONTRACT; iGCSegmentSize = iSize; }
size_t GetGCgen0size () const {LIMITED_METHOD_CONTRACT; return iGCgen0size; }
void SetGCgen0size (size_t iSize) {LIMITED_METHOD_CONTRACT; iGCgen0size = iSize; }
size_t GetSegmentSize () const {LIMITED_METHOD_CONTRACT; return iGCSegmentSize; }
void SetSegmentSize (size_t iSize) {LIMITED_METHOD_CONTRACT; iGCSegmentSize = iSize; }
int GetGCconcurrent() const {LIMITED_METHOD_CONTRACT; return iGCconcurrent; }
void SetGCconcurrent(int val) {LIMITED_METHOD_CONTRACT; iGCconcurrent = val; }
int GetGCconcurrent() const {LIMITED_METHOD_CONTRACT; return iGCconcurrent; }
void SetGCconcurrent(int val) {LIMITED_METHOD_CONTRACT; iGCconcurrent = val; }
#ifdef _DEBUG
int GetGCLatencyMode() const {LIMITED_METHOD_CONTRACT; return iGCLatencyMode; }
int GetGCLatencyMode() const {LIMITED_METHOD_CONTRACT; return iGCLatencyMode; }
#endif //_DEBUG
int GetGCForceCompact() const {LIMITED_METHOD_CONTRACT; return iGCForceCompact; }
int GetGCRetainVM () const {LIMITED_METHOD_CONTRACT; return iGCHoardVM;}
DWORD GetGCLOHThreshold() const {LIMITED_METHOD_CONTRACT; return iGCLOHThreshold;}
int GetGCLOHCompactionMode() const {LIMITED_METHOD_CONTRACT; return iGCLOHCompactionMode;}
int GetGCHeapCount() const {LIMITED_METHOD_CONTRACT; return iGCHeapCount;}
int GetGCNoAffinitize () const {LIMITED_METHOD_CONTRACT; return iGCNoAffinitize;}
size_t GetGCAffinityMask() const {LIMITED_METHOD_CONTRACT; return iGCAffinityMask;}
size_t GetGCHeapHardLimit() const {LIMITED_METHOD_CONTRACT; return iGCHeapHardLimit;}
int GetGCHeapHardLimitPercent() const {LIMITED_METHOD_CONTRACT; return iGCHeapHardLimitPercent;}
#ifdef GCTRIMCOMMIT
......@@ -698,11 +695,8 @@ private: //----------------------------------------------------------------
int iGCHoardVM;
int iGCLOHCompactionMode;
DWORD iGCLOHThreshold;
int iGCHeapCount;
int iGCNoAffinitize;
size_t iGCAffinityMask;
size_t iGCHeapHardLimit;
int iGCHeapHardLimitPercent;
#ifdef GCTRIMCOMMIT
......
......@@ -1023,7 +1023,7 @@ MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
// longer than these lengths.
const size_t MaxConfigKeyLength = 255;
bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
bool GCToEEInterface::GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value)
{
CONTRACTL {
NOTHROW;
......@@ -1031,32 +1031,26 @@ bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
} CONTRACTL_END;
// these configuration values are given to us via startup flags.
if (strcmp(key, "gcServer") == 0)
if (strcmp(privateKey, "gcServer") == 0)
{
*value = g_heap_type == GC_HEAP_SVR;
return true;
}
if (strcmp(key, "gcConcurrent") == 0)
if (strcmp(privateKey, "gcConcurrent") == 0)
{
*value = !!g_pConfig->GetGCconcurrent();
return true;
}
if (strcmp(key, "GCRetainVM") == 0)
if (strcmp(privateKey, "GCRetainVM") == 0)
{
*value = !!g_pConfig->GetGCRetainVM();
return true;
}
if (strcmp(key, "GCLargePages") == 0)
{
*value = Configuration::GetKnobBooleanValue(W("System.GC.LargePages"), CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_GCLargePages));
return true;
}
WCHAR configKey[MaxConfigKeyLength];
if (MultiByteToWideChar(CP_ACP, 0, key, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
if (MultiByteToWideChar(CP_ACP, 0, privateKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
......@@ -1069,49 +1063,56 @@ bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
*value = CLRConfig::GetConfigValue(info) != 0;
return true;
}
else if (publicKey != NULL)
{
if (MultiByteToWideChar(CP_ACP, 0, publicKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
}
if (Configuration::GetKnobStringValue(configKey) != NULL)
{
*value = Configuration::GetKnobBooleanValue(configKey, false);
return true;
}
}
return false;
}
bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
bool GCToEEInterface::GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
} CONTRACTL_END;
if (strcmp(key, "GCSegmentSize") == 0)
if (strcmp(privateKey, "GCSegmentSize") == 0)
{
*value = g_pConfig->GetSegmentSize();
return true;
}
if (strcmp(key, "GCgen0size") == 0)
if (strcmp(privateKey, "GCgen0size") == 0)
{
*value = g_pConfig->GetGCgen0size();
return true;
}
if (strcmp(key, "GCHeapHardLimit") == 0)
if (strcmp(privateKey, "GCHeapHardLimit") == 0)
{
*value = g_pConfig->GetGCHeapHardLimit();
return true;
}
if (strcmp(key, "GCHeapHardLimitPercent") == 0)
{
*value = g_pConfig->GetGCHeapHardLimitPercent();
return true;
}
if (strcmp(key, "GCLOHThreshold") == 0)
if (strcmp(privateKey, "GCLOHThreshold") == 0)
{
*value = g_pConfig->GetGCLOHThreshold();
return true;
}
WCHAR configKey[MaxConfigKeyLength];
if (MultiByteToWideChar(CP_ACP, 0, key, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
if (MultiByteToWideChar(CP_ACP, 0, privateKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
......@@ -1146,11 +1147,24 @@ bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
CLRConfig::FreeConfigString(out);
return true;
}
else if (publicKey != NULL)
{
if (MultiByteToWideChar(CP_ACP, 0, publicKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
}
if (Configuration::GetKnobStringValue(configKey) != NULL)
{
*value = Configuration::GetKnobULONGLONGValue(configKey, 0);
return true;
}
}
return false;
}
bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
bool GCToEEInterface::GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value)
{
CONTRACTL {
NOTHROW;
......@@ -1158,18 +1172,30 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
} CONTRACTL_END;
WCHAR configKey[MaxConfigKeyLength];
if (MultiByteToWideChar(CP_ACP, 0, key, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
if (MultiByteToWideChar(CP_ACP, 0, privateKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
}
CLRConfig::ConfigStringInfo info { configKey, CLRConfig::EEConfig_default };
LPWSTR out = CLRConfig::GetConfigValue(info);
if (!out)
LPWSTR fromClrConfig = CLRConfig::GetConfigValue(info);
LPCWSTR out = fromClrConfig;
if (out == NULL)
{
// config not found
return false;
if (publicKey != NULL)
{
if (MultiByteToWideChar(CP_ACP, 0, publicKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
}
out = Configuration::GetKnobStringValue(configKey);
if (out == NULL)
{
return false;
}
}
}
int charCount = WideCharToMultiByte(CP_ACP, 0, out, -1 /* out is null-terminated */, NULL, 0, nullptr, nullptr);
......@@ -1177,7 +1203,10 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
{
// this should only happen if the config subsystem gives us a string that's not valid
// unicode.
CLRConfig::FreeConfigString(out);
if (fromClrConfig)
{
CLRConfig::FreeConfigString(fromClrConfig);
}
return false;
}
......@@ -1185,7 +1214,10 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
AStringHolder configResult = new (nothrow) char[charCount];
if (!configResult)
{
CLRConfig::FreeConfigString(out);
if (fromClrConfig)
{
CLRConfig::FreeConfigString(fromClrConfig);
}
return false;
}
......@@ -1195,12 +1227,18 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
// this should never happen, the previous call to WideCharToMultiByte that computed the charCount should
// have caught all issues.
assert(false);
CLRConfig::FreeConfigString(out);
if (fromClrConfig)
{
CLRConfig::FreeConfigString(fromClrConfig);
}
return false;
}
*value = configResult.Extract();
CLRConfig::FreeConfigString(out);
if (fromClrConfig)
{
CLRConfig::FreeConfigString(fromClrConfig);
}
return true;
}
......
......@@ -64,9 +64,9 @@ public:
void HandleFatalError(unsigned int exitCode);
bool EagerFinalized(Object* obj);
MethodTable* GetFreeObjectMethodTable();
bool GetBooleanConfigValue(const char* key, bool* value);
bool GetIntConfigValue(const char* key, int64_t* value);
bool GetStringConfigValue(const char* key, const char** value);
bool GetBooleanConfigValue(const char* privateKey, const char* publicKey, bool* value);
bool GetIntConfigValue(const char* privateKey, const char* publicKey, int64_t* value);
bool GetStringConfigValue(const char* privateKey, const char* publicKey, const char** value);
void FreeStringConfigValue(const char* value);
bool IsGCThread();
bool WasCurrentThreadCreatedByGC();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册