From aa385a1317ac4d5a63a76542c7829c303652e095 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 20 Jul 2016 22:28:47 +0100 Subject: [PATCH] Use Environment.NewLine and Environment.StackTrace --- .../Internal/Infrastructure/MemoryPool.cs | 19 +++++++------------ .../Infrastructure/MemoryPoolBlock.cs | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs index 589efeba3f..b361be5477 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs @@ -61,6 +61,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// private bool _disposedValue = false; // To detect redundant calls + /// + /// Called to take a block from the pool. + /// + /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. #if DEBUG public MemoryPoolBlock Lease([CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", @@ -68,11 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { Debug.Assert(!_disposedValue, "Block being leased from disposed pool!"); #else - - /// - /// Called to take a block from the pool. - /// - /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. public MemoryPoolBlock Lease() { #endif @@ -83,9 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; -#if !NETSTANDARD1_3 - block.StackTrace = new StackTrace(true).ToString(); -#endif + block.StackTrace = Environment.StackTrace; #endif return block; } @@ -94,9 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; -#if !NETSTANDARD1_3 - block.StackTrace = new StackTrace(true).ToString(); -#endif + block.StackTrace = Environment.StackTrace; #endif return block; } @@ -153,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { #if DEBUG Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); - Debug.Assert(block.IsLeased, "Block being returned to pool twice: " + block.Leaser + "\n" + block.StackTrace); + Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}{block.StackTrace}"); block.IsLeased = false; #endif diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index 8b03dee1da..5ce1ce4122 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure ~MemoryPoolBlock() { #if DEBUG - Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool: " + Leaser + "\n" + StackTrace); + Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}Allocation StackTrace:{Environment.NewLine}{StackTrace}"); #endif if (Slab != null && Slab.IsActive) {