Browse by Tags
All Tags »
.NETInternals (
RSS)
NOTE : if you’re not familiar with SOS (a WinDbg extension for managed code) and leak detection with !gcroot , start by reading an introductory post on the subject. A typical root reference chain for a managed object that is retained by a static GC root would have a pinned object array appear as the rooted object. Here is a typical reference chain: 0:010> !gcroot 0000000002bcaf58 …snipped… DOMAIN(0000000000C1C5F0):HANDLE(Pinned):5017f8:Root: 0000000012761018 (System.Object[])-> 00000000039b3c30...
Inlining is an important optimization that allows compilers to eliminate the cost of method calls in situations where the method call overhead is more significant than the method body itself. The CLR JIT uses inlining conservatively, but features some nice tricks such as interface method call inlining – this was one of the first things I covered on this blog, almost five years ago. The limitations on JIT inlining are not known precisely, but some criteria have been announced previously (in 2004!...
More than a year after writing my first post touching on the subject of Managed Debugging Assistants (MDA) through the “Callback on Garbage Collected Delegate” case study , it’s time for a brief mention of another useful MDA – “P/Invoke Stack Imbalance” . This MDA fires whenever a P/Invoke call causes an imbalance on the stack. What does a stack imbalance mean? The top of the thread’s stack is pointed to by the ESP register (RSP on x64), and a stack imbalance occurs if the ESP value before making...
This is a bug Dima encountered several months ago, and I’ve been looking for an opportunity to document ever since. tl;dr – when unmanaged C++ code throws an exception which propagates through an interop boundary to managed code, C++ destructors are not called. To fix, don’t allow C++ exception propagation outside module boundaries, or compile with /EHa. It was recorded before on this StackOverflow thread , where the conclusion is that “ the CLR hooks into SEH handling to catch native exceptions...
Noam and I delivered a joint keynote at the first day of the SDP , covering the new APIs and internal features of .NET 4.5. With my love for internals, I took the easy route of talking about CLR internals and C# 5 async methods , and Noam talked about WCF, Entity Framework, WPF, ASP.NET MVC, and plenty of other frameworks which have been updated in .NET 4.5. As you probably know, .NET 4.5 is an in-place update for .NET 4.0, which means—as far as Microsoft is concerned—that it should work seamlessly...
I apologize for the silence during the last two weeks—organizing the SDP and preparing three full-day sessions and two keynotes left no time to breathe :-) On Monday I delivered a session called Improving the Performance of .NET Applications at the SELA Developer Practice . Here are some of the practical scenarios we covered: Measuring application memory usage and allocation sources Diagnosing memory leak sources with memory profilers Using sampling and instrumentation profilers to find CPU bottlenecks...
.NET 4.5 has a little hidden gem up its sleeve – the ExceptionDispatchInfo class . It’s used by the Task Parallel Library to capture and rethrow exceptions when they are not aggregated – specifically, to support the await keyword. Luckily, the class is public and can be used by anyone to capture an exception that occurred in one context – say, a thread – and then rethrow it (selectively) in another context – say, on another thread, while maintaining the full fidelity of the original stack trace and...
Alongside all the exciting advents in Windows 8 and Metro apps, the .NET CLR is marching on. The next version of the CLR will feature several “internals” improvements, mostly in the performance area. Read on to learn about changes to the garbage collector, the JIT, and the native image generator engine in the next CLR. Background mode for Server GC Background GC is a neat feature introduced in CLR 4.0 to the Workstation GC flavor. It’s a little hard to explain without any background (pun intended...
The amount of confusion generated by the first two keynotes at BUILD was immense. The blogosphere and Twitter were brimming with bold rumors of the “.NET is dead” kin. I even heard someone discuss seriously the possibility that C# Metro apps will be compiled directly to native WinRT bindings, bypassing IL and JIT altogether, so that clr.dll won’t even be loaded. Even though I disproved these rumors two days ago, it was still great to hear Krzysztof Cwalina explain in detail how .NET remains a fully...
Suppose you want a more detailed drill-down into your application's GC heap usage. For example, you want to see if there's fragmentation going on, or if there are lots of large objects, or if the XMLDocument objects you allocated a while ago are finally gone. This is something you can do with the CLR Profiler , another free Microsoft tool that supports memory allocation profiling as well as visualizing the managed heap at the individual object level. Unfortunately, running the application...
Synopsis: CLR Stack Explorer obtains reliable call stacks of managed processes, supports any combination of 32-bit/64-bit and CLR2/CLR4. UPDATE [2011/7/20]: If you downloaded CLR Stack Explorer from the above link and are using a recent Windows version, you need to Unblock all the .exe files (right-click, Properties, Unblock) for the tool to run correctly. I have just updated the download location with a self-extracting executable which should solve this problem. I’m happy to announce that CLR Stack...
How can you map the memory usage of your .NET application? We'll start with VMMap , a free Sysinternals tool that visualizes your process' virtual address space. Below is VMMap's output for an example process: The type statistics give you a detailed overview of how memory usage is distributed – there are 240MB of DLLs, 50MB of managed heaps (of which only 10MB are committed), etc. In the bottom details view you can see each individual address range on the heap, including its type, size...
To evaluate whether your application can scale with larger data sets and more concurrent users, you have to understand how it uses the memory available to it. Modern .NET applications (and especially mixed managed and native applications) have thousands of memory chunks across their address space—keeping track of these chunks manually in your head is an impossible endeavor. First, a quick reminder about how virtual memory, managed heap allocations, and native heap allocations relate to each other...
There’s just one day left for the SELA Developer Days , and today I delivered my session titled Improving the Performance of .NET Applications . In this brief one-day session I wanted to distill the best practices and tools for measuring various performance metrics, but also provide some insight into OS and CLR internals relevant to high-performance development. Other sessions today included Parallel Programming: One Step Beyond , Windows Phone Mango , Introduction to Scrum , and Visual Studio 2010...
During the last week of June Sela is going to host 25 one-day sessions in 5 days packed with the latest and greatest Microsoft technologies, agile and ALM tips, debugging and troubleshooting, cloud and web. This mini-conference, dubbed Sela Developer Days , is going to open for registration on Sunday and I encourage you to take a look at the conference website to see what sessions are going to be available. Yours truly is scheduled for four sessions. Instead of rehashing the abstracts from the conference...
More Posts
Next page »