|
6 | 6 | //*****************************************************************************
|
7 | 7 | // unixinterface.cpp
|
8 | 8 | //
|
9 |
| -// Implementation for the interface exposed by the libcoreclr.so on Unix |
| 9 | +// Implementation for the interface exposed by libcoreclr.so |
10 | 10 | //
|
11 | 11 |
|
12 | 12 | //*****************************************************************************
|
13 | 13 |
|
14 | 14 | #include "stdafx.h"
|
15 | 15 | #include <utilcode.h>
|
16 | 16 | #include <corhost.h>
|
| 17 | +#include <configuration.h> |
17 | 18 |
|
18 | 19 | typedef int (STDMETHODCALLTYPE *HostMain)(
|
19 | 20 | const int argc,
|
@@ -86,76 +87,47 @@ static LPCWSTR* StringArrayToUnicode(int argc, LPCSTR* argv)
|
86 | 87 | return argvW;
|
87 | 88 | }
|
88 | 89 |
|
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( |
90 | 113 | const char** propertyKeys,
|
91 | 114 | const char** propertyValues,
|
92 |
| - int* propertyCountRef, |
93 |
| - STARTUP_FLAGS* startupFlagsRef, |
| 115 | + int propertyCount, |
94 | 116 | LPCWSTR** propertyKeysWRef,
|
95 | 117 | LPCWSTR** propertyValuesWRef)
|
96 | 118 | {
|
97 |
| - int propertyCount = *propertyCountRef; |
98 |
| - |
99 | 119 | LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
|
100 | 120 | ASSERTE_ALL_BUILDS(propertyKeysW != nullptr);
|
101 | 121 |
|
102 | 122 | LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[propertyCount];
|
103 | 123 | ASSERTE_ALL_BUILDS(propertyValuesW != nullptr);
|
104 | 124 |
|
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; |
112 | 125 | for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
|
113 | 126 | {
|
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]); |
155 | 129 | }
|
156 | 130 |
|
157 |
| - *propertyCountRef = propertyCountW; |
158 |
| - *startupFlagsRef = startupFlags; |
159 | 131 | *propertyKeysWRef = propertyKeysW;
|
160 | 132 | *propertyValuesWRef = propertyValuesW;
|
161 | 133 | }
|
@@ -205,22 +177,20 @@ int coreclr_initialize(
|
205 | 177 |
|
206 | 178 | ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
|
207 | 179 |
|
208 |
| - STARTUP_FLAGS startupFlags; |
209 |
| - LPCWSTR* propertyKeysWTemp; |
210 |
| - LPCWSTR* propertyValuesWTemp; |
211 |
| - ExtractStartupFlagsAndConvertToUnicode( |
| 180 | + LPCWSTR* propertyKeysW; |
| 181 | + LPCWSTR* propertyValuesW; |
| 182 | + ConvertConfigPropertiesToUnicode( |
212 | 183 | propertyKeys,
|
213 | 184 | 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); |
224 | 194 |
|
225 | 195 | hr = host->SetStartupFlags(startupFlags);
|
226 | 196 | IfFailRet(hr);
|
|
0 commit comments