-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Refactor FrozenObjectHeapManager for dynamic segment size #121526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,72 @@ | |
| private FrozenObjectSegment m_CurrentSegment; | ||
|
|
||
| // Default size to reserve for a frozen segment | ||
| private const nuint FOH_SEGMENT_DEFAULT_SIZE = 4 * 1024 * 1024; | ||
| private static readonly nuint FOH_SEGMENT_DEFAULT_SIZE = GetDefaultSegmentSize(); | ||
| // Size to commit on demand in that reserved space | ||
| private const nuint FOH_COMMIT_SIZE = 64 * 1024; | ||
|
|
||
| private static bool TryParsePositiveULong(string s, out ulong value) | ||
| { | ||
| value = 0; | ||
| if (string.IsNullOrEmpty(s)) | ||
| return false; | ||
|
|
||
| int i = 0; | ||
|
|
||
|
Check failure on line 34 in src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/FrozenObjectHeapManager.cs
|
||
| while (i < s.Length && char.IsWhiteSpace(s[i])) | ||
| i++; | ||
|
|
||
|
|
||
|
Check failure on line 38 in src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/FrozenObjectHeapManager.cs
|
||
| if (i < s.Length && s[i] == '+') | ||
| i++; | ||
|
|
||
| if (i >= s.Length) | ||
| return false; | ||
|
|
||
| ulong result = 0; | ||
| for (; i < s.Length; i++) | ||
| { | ||
| char c = s[i]; | ||
| if (c < '0' || c > '9') | ||
| return false; | ||
| ulong digit = (ulong)(c - '0'); | ||
|
|
||
|
Check failure on line 52 in src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/FrozenObjectHeapManager.cs
|
||
| if (result > (ulong.MaxValue - digit) / 10) | ||
| return false; | ||
| result = result * 10 + digit; | ||
| } | ||
|
|
||
| value = result; | ||
| return true; | ||
| } | ||
|
|
||
| private static nuint GetDefaultSegmentSize() | ||
| { | ||
| const nuint defaultSize = 4 * 1024 * 1024; | ||
| nuint finalSize = defaultSize; | ||
|
|
||
| try | ||
| { | ||
| string? env = Environment.GetEnvironmentVariable("DOTNET_FOH_SEGMENT_DEFAULT_SIZE"); | ||
| if (!string.IsNullOrEmpty(env)) | ||
| { | ||
| if (TryParsePositiveULong(env, out ulong parsed) && parsed > 0) | ||
| { | ||
| finalSize = (nuint)parsed; | ||
| if (finalSize < FOH_COMMIT_SIZE) | ||
| { | ||
| finalSize = FOH_COMMIT_SIZE; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // ignore and use default | ||
| } | ||
| return finalSize; | ||
| } | ||
|
|
||
| public T? TryAllocateObject<T>() where T : class | ||
| { | ||
| MethodTable* pMT = MethodTable.Of<T>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not an acceptable pattern to parse an environment variable like this. Use
AppContextswitch instead, which is integrated with more toolchain. CheckGC.NativeAot:runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs
Lines 883 to 890 in 118ff8e