diff --git a/DotnetCLIVersion.txt b/DotnetCLIVersion.txt index d04fdeffa7e..c3dd321d427 100644 --- a/DotnetCLIVersion.txt +++ b/DotnetCLIVersion.txt @@ -1 +1 @@ -2.1.300-preview2-008019 +2.1.300-preview2-008022 diff --git a/SharedRuntimeVersion.txt b/SharedRuntimeVersion.txt index 4e86791333d..e11d1d3eabc 100644 --- a/SharedRuntimeVersion.txt +++ b/SharedRuntimeVersion.txt @@ -1 +1 @@ -2.1.0-preview2-26124-07 \ No newline at end of file +2.1.0-preview2-26129-05 \ No newline at end of file diff --git a/scripts/update-dependencies/Program.cs b/scripts/update-dependencies/Program.cs index 4f34a1e93e8..0a3e1a7aa25 100644 --- a/scripts/update-dependencies/Program.cs +++ b/scripts/update-dependencies/Program.cs @@ -100,6 +100,7 @@ private static IEnumerable GetUpdaters() yield return CreateRegexPropertyUpdater(config.DependencyFilePath, "SystemCompilerServicesUnsafeVersion", "System.Runtime.CompilerServices.Unsafe"); yield return CreateRegexPropertyUpdater(config.DependencyFilePath, "SystemMemoryVersion", "System.Memory"); yield return CreateRegexPropertyUpdater(config.DependencyFilePath, "SystemNumericsVectorsVersion", "System.Numerics.Vectors"); + yield return CreateRegexPropertyUpdater(config.DependencyFilePath, "SystemBuffersVersion", "System.Buffers"); yield return CreateFileUpdater(config.CLIVersionFilePath, "Microsoft.DotNet.Cli.Utils"); // Temporary workaround until CLI, Core-Setup, CoreFx are all in sync with the shared runtime. diff --git a/src/System.Buffers.Experimental/System/Buffers/Native/NativeMemoryPool.cs b/src/System.Buffers.Experimental/System/Buffers/Native/NativeMemoryPool.cs index befa96efa40..f5a7d2c43fe 100644 --- a/src/System.Buffers.Experimental/System/Buffers/Native/NativeMemoryPool.cs +++ b/src/System.Buffers.Experimental/System/Buffers/Native/NativeMemoryPool.cs @@ -45,7 +45,7 @@ protected override void Dispose(bool disposing) public override OwnedMemory Rent(int numberOfBytes = DefaultSize) { - if (numberOfBytes == AnySize) numberOfBytes = DefaultSize; + if (numberOfBytes == -1) numberOfBytes = DefaultSize; if (numberOfBytes < 1 || numberOfBytes > MaxBufferSize) throw new ArgumentOutOfRangeException(nameof(numberOfBytes)); if (numberOfBytes > _bufferSize) new NotSupportedException(); diff --git a/src/System.Buffers.Primitives/System.Buffers.Primitives.csproj b/src/System.Buffers.Primitives/System.Buffers.Primitives.csproj index 9bdef720ed3..0a0b9731dcb 100644 --- a/src/System.Buffers.Primitives/System.Buffers.Primitives.csproj +++ b/src/System.Buffers.Primitives/System.Buffers.Primitives.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/System.Buffers.Primitives/System/Buffers/Pooling/ArrayMemoryPool.cs b/src/System.Buffers.Primitives/System/Buffers/Pooling/ArrayMemoryPool.cs deleted file mode 100644 index 3ef7dd82db5..00000000000 --- a/src/System.Buffers.Primitives/System/Buffers/Pooling/ArrayMemoryPool.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Threading; - -namespace System.Buffers.Internal -{ - internal sealed class ArrayMemoryPool : MemoryPool - { - const int DefaultSize = 4096; - - readonly static ArrayMemoryPool s_shared = new ArrayMemoryPool(); - - public static ArrayMemoryPool Shared => s_shared; - - public override int MaxBufferSize => 1024 * 1024 * 1024; - - public override OwnedMemory Rent(int minimumBufferSize = AnySize) - { - if (minimumBufferSize == AnySize) minimumBufferSize = DefaultSize; - else if (minimumBufferSize > MaxBufferSize || minimumBufferSize < 1) throw new ArgumentOutOfRangeException(nameof(minimumBufferSize)); - return new ArrayPoolMemory(minimumBufferSize); - } - - protected override void Dispose(bool disposing) - { - } - - private sealed class ArrayPoolMemory : OwnedMemory - { - T[] _array; - bool _disposed; - int _referenceCount; - - public ArrayPoolMemory(int size) - { - _array = ArrayPool.Shared.Rent(size); - } - - public override int Length => _array.Length; - - public override bool IsDisposed => _disposed; - - protected override bool IsRetained => _referenceCount > 0; - - public override Span Span - { - get - { - if (IsDisposed) ThrowObjectDisposedException(nameof(ArrayPoolMemory)); - return _array; - } - } - - protected override void Dispose(bool disposing) - { - var array = Interlocked.Exchange(ref _array, null); - if (array != null) - { - _disposed = true; - ArrayPool.Shared.Return(array); - } - } - - protected override bool TryGetArray(out ArraySegment arraySegment) - { - if (IsDisposed) ThrowObjectDisposedException(nameof(ArrayMemoryPool)); - arraySegment = new ArraySegment(_array); - return true; - } - - public override MemoryHandle Pin(int byteOffset = 0) - { - unsafe - { - Retain(); // this checks IsDisposed - if (byteOffset != 0 && (((uint)byteOffset) - 1) / Unsafe.SizeOf() >= _array.Length) throw new ArgumentOutOfRangeException(nameof(byteOffset)); - var handle = GCHandle.Alloc(_array, GCHandleType.Pinned); - void* pointer = Unsafe.Add((void*)handle.AddrOfPinnedObject(), byteOffset); - return new MemoryHandle(this, pointer, handle); - } - } - - public override void Retain() - { - if (IsDisposed) ThrowObjectDisposedException(nameof(ArrayPoolMemory)); - Interlocked.Increment(ref _referenceCount); - } - - public override bool Release() - { - int newRefCount = Interlocked.Decrement(ref _referenceCount); - if (newRefCount < 0) throw new InvalidOperationException(); - if (newRefCount == 0) - { - Dispose(); - return false; - } - return true; - } - - [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowObjectDisposedException(string objectName) - => throw new ObjectDisposedException(objectName); - } - } -} diff --git a/src/System.Buffers.Primitives/System/Buffers/Pooling/MemoryPool.cs b/src/System.Buffers.Primitives/System/Buffers/Pooling/MemoryPool.cs deleted file mode 100644 index 5cb668439ec..00000000000 --- a/src/System.Buffers.Primitives/System/Buffers/Pooling/MemoryPool.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace System.Buffers -{ - public abstract class MemoryPool : IDisposable - { - public const int AnySize = int.MinValue; - - public static MemoryPool Default => Internal.ArrayMemoryPool.Shared; - - public abstract OwnedMemory Rent(int minimumBufferSize = AnySize); - - public abstract int MaxBufferSize { get; } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - ~MemoryPool() - { - Dispose(false); - } - - protected abstract void Dispose(bool disposing); - } -} diff --git a/src/System.IO.Pipelines.Networking.Windows.RIO/Internal/Pool/MemoryPool.cs b/src/System.IO.Pipelines.Networking.Windows.RIO/Internal/Pool/MemoryPool.cs index dc9b252ec8d..91eab71ad15 100644 --- a/src/System.IO.Pipelines.Networking.Windows.RIO/Internal/Pool/MemoryPool.cs +++ b/src/System.IO.Pipelines.Networking.Windows.RIO/Internal/Pool/MemoryPool.cs @@ -73,9 +73,9 @@ public RioMemoryPool(Action allocationCallback = null, Action _slabDeallocationCallback = deallocationCallback; } - public override OwnedMemory Rent(int size = AnySize) + public override OwnedMemory Rent(int size = -1) { - if (size == AnySize) size = _blockLength; + if (size == -1) size = _blockLength; else if (size > _blockLength) { RioPipelinesThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockLength); diff --git a/src/System.IO.Pipelines/System/Buffers/MemoryPool.cs b/src/System.IO.Pipelines/System/Buffers/MemoryPool.cs index 498f4d7bada..0c0a70ad04c 100644 --- a/src/System.IO.Pipelines/System/Buffers/MemoryPool.cs +++ b/src/System.IO.Pipelines/System/Buffers/MemoryPool.cs @@ -63,9 +63,9 @@ public class MemoryPool : MemoryPool /// private bool _disposedValue = false; // To detect redundant calls - public override OwnedMemory Rent(int size = AnySize) + public override OwnedMemory Rent(int size = -1) { - if (size == AnySize) size = _blockLength; + if (size == -1) size = _blockLength; else if (size > _blockLength) { PipelinesThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockLength); diff --git a/src/System.IO.Pipelines/System/IO/Pipelines/PipeOptions.cs b/src/System.IO.Pipelines/System/IO/Pipelines/PipeOptions.cs index 8280743310a..1c8dd738eae 100644 --- a/src/System.IO.Pipelines/System/IO/Pipelines/PipeOptions.cs +++ b/src/System.IO.Pipelines/System/IO/Pipelines/PipeOptions.cs @@ -19,7 +19,7 @@ public PipeOptions( long resumeWriterThreshold = 0, int minimumSegmentSize = 2048) { - Pool = pool ?? MemoryPool.Default; + Pool = pool ?? MemoryPool.Shared; ReaderScheduler = readerScheduler; WriterScheduler = writerScheduler; PauseWriterThreshold = pauseWriterThreshold; diff --git a/src/System.Text.Json/System/Text/Json/JsonParser.cs b/src/System.Text.Json/System/Text/Json/JsonParser.cs index 4423e07d510..debfaca3a55 100644 --- a/src/System.Text.Json/System/Text/Json/JsonParser.cs +++ b/src/System.Text.Json/System/Text/Json/JsonParser.cs @@ -146,7 +146,7 @@ private enum JsonTokenType public JsonObject Parse(ReadOnlySpan utf8Json, MemoryPool pool = null) { _pool = pool; - if (_pool == null) _pool = MemoryPool.Default; + if (_pool == null) _pool = MemoryPool.Shared; _scratchManager = _pool.Rent(utf8Json.Length * 4); _scratchMemory = _scratchManager.Memory; diff --git a/tests/System.Buffers.Primitives.Tests/BufferReferenceTests.cs b/tests/System.Buffers.Primitives.Tests/BufferReferenceTests.cs index 61e25b2e999..99528e525c4 100644 --- a/tests/System.Buffers.Primitives.Tests/BufferReferenceTests.cs +++ b/tests/System.Buffers.Primitives.Tests/BufferReferenceTests.cs @@ -18,7 +18,7 @@ public void OwnedArrayReferenceTests() public void PooledBufferReferenceTests() { BufferReferenceTests.TestOwnedBuffer(() => { - return MemoryPool.Default.Rent(1000); + return MemoryPool.Shared.Rent(1000); }); } diff --git a/tools/dependencies.props b/tools/dependencies.props index e2cbd0b26b4..9789eb75337 100644 --- a/tools/dependencies.props +++ b/tools/dependencies.props @@ -1,11 +1,12 @@ - 2.1.0-preview2-26124-07 + 2.1.0-preview2-26129-05 4.3.0 2.6.0-beta3-62316-02 - 4.5.0-preview2-26125-06 - 4.5.0-preview2-26125-06 - 4.5.0-preview2-26125-06 + 4.5.0-preview2-26127-04 + 4.5.0-preview2-26127-04 + 4.5.0-preview2-26127-04 + 4.5.0-preview2-26127-04 1.9.1 15.0.0 2.2.0