From: Jan Kotas Date: Tue, 3 Jan 2017 14:13:46 +0000 (-0800) Subject: ArrayPool fixes (dotnet/coreclr#8774) X-Git-Tag: submit/tizen/20210909.063632~11030^2~8539 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31eded7d938a8bd433c9870be97c8af88ca3bf29;p=platform%2Fupstream%2Fdotnet%2Fruntime.git ArrayPool fixes (dotnet/coreclr#8774) * Use Array.Empty() to make the code identical to CoreRT copy The internal EmptyArray does not exist in CoreRT. * Remove unnecessary helper type for lazy initialization All generic types are beforefieldinit by design. * Use | for clarity Commit migrated from https://github.com/dotnet/coreclr/commit/65b50f1143cc0b0f1523f62f9c048cb3c89d4afb --- diff --git a/src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPool.cs b/src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPool.cs index 441e48d..77a07f7 100644 --- a/src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPool.cs +++ b/src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPool.cs @@ -29,26 +29,13 @@ namespace System.Buffers /// array than was requested. Renting a buffer from it with will result in an /// existing buffer being taken from the pool if an appropriate buffer is available or in a new /// buffer being allocated if one is not available. + /// byte[] and char[] are the most commonly pooled array types. For these we use a special pool type + /// optimized for very fast access speeds, at the expense of more memory consumption. + /// The shared pool instance is created lazily on first access. /// - public static ArrayPool Shared => SharedPool.Value; - - /// Stores a cached pool instance for T[]. - /// - /// Separated out into a nested class to enable lazy-initialization of the pool provided by - /// the runtime, only forced when Shared is used (and not when Create is called or when - /// other non-Shared accesses happen). - /// - private static class SharedPool - { - /// Per-type cached pool. - /// - /// byte[] and char[] are the most commonly pooled array types. For these we use a special pool type - /// optimized for very fast access speeds, at the expense of more memory consumption. - /// - internal readonly static ArrayPool Value = - typeof(T) == typeof(byte) || typeof(T) == typeof(char) ? new TlsOverPerCoreLockedStacksArrayPool() : - Create(); - } + public static ArrayPool Shared { get; } = + typeof(T) == typeof(byte) || typeof(T) == typeof(char) ? new TlsOverPerCoreLockedStacksArrayPool() : + Create(); /// /// Creates a new instance using default configuration options. diff --git a/src/coreclr/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs b/src/coreclr/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs index 1e0e769..f7b6034 100644 --- a/src/coreclr/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs +++ b/src/coreclr/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs @@ -70,7 +70,7 @@ namespace System.Buffers { // No need for events with the empty array. Our pool is effectively infinite // and we'll never allocate for rents and never store for returns. - return EmptyArray.Value; + return Array.Empty(); } var log = ArrayPoolEventSource.Log; diff --git a/src/coreclr/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs b/src/coreclr/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs index 9cf8bad..64c5ceb 100644 --- a/src/coreclr/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs +++ b/src/coreclr/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs @@ -80,7 +80,7 @@ namespace System.Buffers { // No need to log the empty array. Our pool is effectively infinite // and we'll never allocate for rents and never store for returns. - return EmptyArray.Value; + return Array.Empty(); } ArrayPoolEventSource log = ArrayPoolEventSource.Log; diff --git a/src/coreclr/src/mscorlib/src/System/Environment.cs b/src/coreclr/src/mscorlib/src/System/Environment.cs index 81c1f09..0e2e7bd 100644 --- a/src/coreclr/src/mscorlib/src/System/Environment.cs +++ b/src/coreclr/src/mscorlib/src/System/Environment.cs @@ -1168,7 +1168,7 @@ namespace System { Debug.Assert(ExecutionIdRefreshRate <= ExecutionIdCacheCountDownMask); // Mask with Int32.MaxValue to ensure the execution Id is not negative - t_executionIdCache = ((executionId << ExecutionIdCacheShift) & Int32.MaxValue) + ExecutionIdRefreshRate; + t_executionIdCache = ((executionId << ExecutionIdCacheShift) & Int32.MaxValue) | ExecutionIdRefreshRate; return executionId; }