Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f34fbbd

Browse files
Add new configuration mechanism for CoreCLR.
1 parent 17c2640 commit f34fbbd

14 files changed

+365
-122
lines changed

src/dlls/mscoree/unixinterface.cpp

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
//*****************************************************************************
77
// unixinterface.cpp
88
//
9-
// Implementation for the interface exposed by the libcoreclr.so on Unix
9+
// Implementation for the interface exposed by libcoreclr.so
1010
//
1111

1212
//*****************************************************************************
1313

1414
#include "stdafx.h"
1515
#include <utilcode.h>
1616
#include <corhost.h>
17+
#include <configuration.h>
1718

1819
typedef int (STDMETHODCALLTYPE *HostMain)(
1920
const int argc,
@@ -86,76 +87,47 @@ static LPCWSTR* StringArrayToUnicode(int argc, LPCSTR* argv)
8687
return argvW;
8788
}
8889

89-
static void ExtractStartupFlagsAndConvertToUnicode(
90+
static void InitializeStartupFlags(STARTUP_FLAGS* startupFlagsRef)
91+
{
92+
STARTUP_FLAGS startupFlags = static_cast<STARTUP_FLAGS>(
93+
STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
94+
STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN);
95+
96+
if (Configuration::GetKnobBooleanValue(W("System.GC.Concurrent"), CLRConfig::UNSUPPORTED_gcConcurrent))
97+
{
98+
startupFlags = static_cast<STARTUP_FLAGS>(startupFlags | STARTUP_CONCURRENT_GC);
99+
}
100+
if (Configuration::GetKnobBooleanValue(W("System.GC.Server"), CLRConfig::UNSUPPORTED_gcServer))
101+
{
102+
startupFlags = static_cast<STARTUP_FLAGS>(startupFlags | STARTUP_SERVER_GC);
103+
}
104+
if (Configuration::GetKnobBooleanValue(W("System.GC.RetainVM"), CLRConfig::UNSUPPORTED_GCRetainVM))
105+
{
106+
startupFlags = static_cast<STARTUP_FLAGS>(startupFlags | STARTUP_HOARD_GC_VM);
107+
}
108+
109+
*startupFlagsRef = startupFlags;
110+
}
111+
112+
static void ConvertConfigPropertiesToUnicode(
90113
const char** propertyKeys,
91114
const char** propertyValues,
92-
int* propertyCountRef,
93-
STARTUP_FLAGS* startupFlagsRef,
115+
int propertyCount,
94116
LPCWSTR** propertyKeysWRef,
95117
LPCWSTR** propertyValuesWRef)
96118
{
97-
int propertyCount = *propertyCountRef;
98-
99119
LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
100120
ASSERTE_ALL_BUILDS(propertyKeysW != nullptr);
101121

102122
LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[propertyCount];
103123
ASSERTE_ALL_BUILDS(propertyValuesW != nullptr);
104124

105-
// Extract the startup flags from the properties, and convert the remaining properties into unicode
106-
STARTUP_FLAGS startupFlags =
107-
static_cast<STARTUP_FLAGS>(
108-
STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
109-
STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN |
110-
STARTUP_FLAGS::STARTUP_CONCURRENT_GC);
111-
int propertyCountW = 0;
112125
for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
113126
{
114-
auto SetFlagValue = [&](STARTUP_FLAGS flag)
115-
{
116-
if (strcmp(propertyValues[propertyIndex], "0") == 0)
117-
{
118-
startupFlags = static_cast<STARTUP_FLAGS>(startupFlags & ~flag);
119-
}
120-
else if (strcmp(propertyValues[propertyIndex], "1") == 0)
121-
{
122-
startupFlags = static_cast<STARTUP_FLAGS>(startupFlags | flag);
123-
}
124-
};
125-
126-
if (strcmp(propertyKeys[propertyIndex], "CONCURRENT_GC") == 0)
127-
{
128-
SetFlagValue(STARTUP_CONCURRENT_GC);
129-
}
130-
else if (strcmp(propertyKeys[propertyIndex], "SERVER_GC") == 0)
131-
{
132-
SetFlagValue(STARTUP_SERVER_GC);
133-
}
134-
else if (strcmp(propertyKeys[propertyIndex], "HOARD_GC_VM") == 0)
135-
{
136-
SetFlagValue(STARTUP_HOARD_GC_VM);
137-
}
138-
else if (strcmp(propertyKeys[propertyIndex], "TRIM_GC_COMMIT") == 0)
139-
{
140-
SetFlagValue(STARTUP_TRIM_GC_COMMIT);
141-
}
142-
else
143-
{
144-
// This is not a CoreCLR startup flag, convert it to unicode and preserve it for returning
145-
propertyKeysW[propertyCountW] = StringToUnicode(propertyKeys[propertyIndex]);
146-
propertyValuesW[propertyCountW] = StringToUnicode(propertyValues[propertyIndex]);
147-
++propertyCountW;
148-
}
149-
}
150-
151-
for (int propertyIndex = propertyCountW; propertyIndex < propertyCount; ++propertyIndex)
152-
{
153-
propertyKeysW[propertyIndex] = nullptr;
154-
propertyValuesW[propertyIndex] = nullptr;
127+
propertyKeysW[propertyIndex] = StringToUnicode(propertyKeys[propertyIndex]);
128+
propertyValuesW[propertyIndex] = StringToUnicode(propertyValues[propertyIndex]);
155129
}
156130

157-
*propertyCountRef = propertyCountW;
158-
*startupFlagsRef = startupFlags;
159131
*propertyKeysWRef = propertyKeysW;
160132
*propertyValuesWRef = propertyValuesW;
161133
}
@@ -205,22 +177,20 @@ int coreclr_initialize(
205177

206178
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
207179

208-
STARTUP_FLAGS startupFlags;
209-
LPCWSTR* propertyKeysWTemp;
210-
LPCWSTR* propertyValuesWTemp;
211-
ExtractStartupFlagsAndConvertToUnicode(
180+
LPCWSTR* propertyKeysW;
181+
LPCWSTR* propertyValuesW;
182+
ConvertConfigPropertiesToUnicode(
212183
propertyKeys,
213184
propertyValues,
214-
&propertyCount,
215-
&startupFlags,
216-
&propertyKeysWTemp,
217-
&propertyValuesWTemp);
218-
219-
ConstWStringArrayHolder propertyKeysW;
220-
propertyKeysW.Set(propertyKeysWTemp, propertyCount);
221-
222-
ConstWStringArrayHolder propertyValuesW;
223-
propertyValuesW.Set(propertyValuesWTemp, propertyCount);
185+
propertyCount,
186+
&propertyKeysW,
187+
&propertyValuesW);
188+
189+
// This will take ownership of propertyKeysWTemp and propertyValuesWTemp
190+
Configuration::InitializeConfigurationKnobs(propertyCount, propertyKeysW, propertyValuesW);
191+
192+
STARTUP_FLAGS startupFlags;
193+
InitializeStartupFlags(&startupFlags);
224194

225195
hr = host->SetStartupFlags(startupFlags);
226196
IfFailRet(hr);

src/inc/clrconfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ class CLRConfig
171171

172172
// Look up a DWORD config value.
173173
static DWORD GetConfigValue(const ConfigDWORDInfo & info);
174-
174+
175+
// Look up a DWORD config value.
176+
static DWORD GetConfigValue(const ConfigDWORDInfo & info, bool acceptExplicitDefaultFromRegutil, /* [Out] */ bool *isDefault);
177+
175178
// Look up a string config value.
176179
// You own the string that's returned.
177180
static LPWSTR GetConfigValue(const ConfigStringInfo & info);

src/inc/clrconfigvalues.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ CONFIG_DWORD_INFO(INTERNAL_FastGCCheckStack, W("FastGCCheckStack"), 0, "")
309309
CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_FastGCStress, W("FastGCStress"), "reduce the number of GCs done by enabling GCStress")
310310
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(UNSUPPORTED_GCBreakOnOOM, W("GCBreakOnOOM"), "Does a DebugBreak at the soonest time we detect an OOM")
311311
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_gcConcurrent, W("gcConcurrent"), (DWORD)-1, "Enables/Disables concurrent GC")
312+
312313
#ifdef FEATURE_CONSERVATIVE_GC
313314
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_gcConservative, W("gcConservative"), 0, "Enables/Disables conservative GC")
314315
#endif
@@ -335,7 +336,7 @@ RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_GCCompactRatio, W("GCCompactRatio"), 0, "Sp
335336
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(EXTERNAL_GCPollType, W("GCPollType"), "")
336337
RETAIL_CONFIG_STRING_INFO_EX(EXTERNAL_NewGCCalc, W("NewGCCalc"), "", CLRConfig::REGUTIL_default)
337338
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(UNSUPPORTED_GCprnLvl, W("GCprnLvl"), "Specifies the maximum level of GC logging")
338-
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(UNSUPPORTED_GCRetainVM, W("GCRetainVM"), "When set we put the segments that should be deleted on a standby list (instead of releasing them back to the OS) which will be considered to satisfy new segment requests (note that the same thing can be specified via API which is the supported way)")
339+
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_GCRetainVM, W("GCRetainVM"), 0, "When set we put the segments that should be deleted on a standby list (instead of releasing them back to the OS) which will be considered to satisfy new segment requests (note that the same thing can be specified via API which is the supported way)")
339340
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(UNSUPPORTED_GCSegmentSize, W("GCSegmentSize"), "Specifies the managed heap segment size")
340341
RETAIL_CONFIG_DWORD_INFO_DIRECT_ACCESS(UNSUPPORTED_GCLOHCompact, W("GCLOHCompact"), "Specifies the LOH compaction mode")
341342
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_gcAllowVeryLargeObjects, W("gcAllowVeryLargeObjects"), 0, "allow allocation of 2GB+ objects on GC heap")

src/inc/configuration.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
// --------------------------------------------------------------------------------------------------
6+
// configuration.h
7+
//
8+
//
9+
// Access and update configuration values, falling back on legacy CLRConfig methods where necessary.
10+
//
11+
// --------------------------------------------------------------------------------------------------
12+
13+
#include "clrconfig.h"
14+
15+
#ifndef __configuration_h__
16+
#define __configuration_h__
17+
18+
class Configuration
19+
{
20+
public:
21+
static void InitializeConfigurationKnobs(int numberOfConfigs, LPCWSTR *configNames, LPCWSTR *configValues);
22+
23+
// Returns (in priority order):
24+
// - The value of the ConfigDWORDInfo if it's set
25+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcstoul).
26+
// - The default set in the ConfigDWORDInfo
27+
static DWORD GetKnobDWORDValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo);
28+
29+
// Returns (in priority order):
30+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcstoul)
31+
// - The default value passed in
32+
static DWORD GetKnobDWORDValue(LPCWSTR name, DWORD defaultValue);
33+
34+
// Returns (in priority order):
35+
// - The value of the ConfigStringInfo if it's set
36+
// - The value of the ConfigurationKnob (searched by name) if it's set
37+
// - nullptr
38+
static LPCWSTR GetKnobStringValue(LPCWSTR name, const CLRConfig::ConfigStringInfo& stringInfo);
39+
40+
// Returns (in priority order):
41+
// - The value of the ConfigurationKnob (searched by name) if it's set
42+
// - nullptr
43+
static LPCWSTR GetKnobStringValue(LPCWSTR name);
44+
45+
// Returns (in priority order):
46+
// - The value of the ConfigDWORDInfo if it's set (1 is true, anything else is false)
47+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
48+
// - The default set in the ConfigDWORDInfo (1 is true, anything else is false)
49+
static bool GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo);
50+
51+
// Returns (in priority order):
52+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
53+
// - The default value passed in
54+
static bool GetKnobBooleanValue(LPCWSTR name, bool defaultValue);
55+
};
56+
57+
#endif // __configuration_h__

src/utilcode/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(UTILCODE_COMMON_SOURCES
1616
makepath.cpp
1717
splitpath.cpp
1818
clrconfig.cpp
19+
configuration.cpp
1920
collections.cpp
2021
posterror.cpp
2122
fstream.cpp

src/utilcode/UtilCode.vcproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@
375375
<File
376376
RelativePath=".\CLRConfig.cpp"
377377
>
378+
<File
379+
RelativePath=".\configuration.cpp"
380+
>
378381
</File>
379382
<File
380383
RelativePath=".\clrhost.cpp"

src/utilcode/UtilCode.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
<ClCompile Include="check.cpp" />
383383
<ClCompile Include="circularlog.cpp" />
384384
<ClCompile Include="CLRConfig.cpp" />
385+
<ClCompile Include="configuration.cpp" />
385386
<ClCompile Include="clrhost.cpp" />
386387
<ClCompile Include="COMEx.cpp" />
387388
<ClCompile Include="corimage.cpp" />

0 commit comments

Comments
 (0)