DCSIMG
.NETInternals - All Your Base Are Belong To Us

All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

Browse by Tags

All Tags » .NETInternals (RSS)
Traversing the GC Heap with ClrMd
ClrMd is a newly released diagnostic library that wraps the CLR’s undocumented data access interfaces (a.k.a. “DAC”) in a friendly managed API. The underlying interfaces are what debugger extensions like SOS and SOSEX use to implement various diagnostic features, including enumerating the managed heap, detecting deadlocks, inspecting object contents, and dumping type/method information. Given my personal and professional interest in debugging tools and techniques, ClrMd is an incredible tool – I...
Two More Ways for Diagnosing For Which Synchronization Object Your Thread Is Waiting
It is as though there is an infinite variety of heuristics that you can use to determine which synchronization object your thread is waiting for. In fact, these are heuristics for retrieving fastcall parameters passed in registers that have been clobbered by subsequent method calls. Method 1: Inspect the handle passed to WaitForMultipleObjectsEx The CLR uses an auto-reset event to implement sync block synchronization, which means that every attempt to acquire an owned sync block will result in a...
Revisiting Value Types vs. Reference Types
Why do C#, the .NET Framework, and the CLR need value types and reference types? Why two categories of types? Why the added complexity in training developers to understand why and when to use each type of type? There are many answers, but very few get to the crux of the matter. You could try to justify the need for two types of types by looking at the semantic differences C# affords each. For example, you know that by default, instances of value types are copied when passed to a function, but instances...
Wishes for the CLR JIT in the 2020s
There have been some very interesting discussions at the MVP Summit concerning the CLR JIT, what we expect of it, and how to evolve it forward. I obviously can't disclose any NDA materials, but what I can do is share my hopes and dreams for the JIT, going forward. This is not a terribly popular subject, but there are some UserVoice suggestions around the JIT, such as adding SIMD support to C# . The state of the JIT today is that it's a fairly quick compiler that does a fairly bad job at optimization...
DevReach 2012: Garbage Collection Performance Tips
Thanks for attending my DevReach session on garbage collection performance tips ! This is one of my favorite subjects, and I found it very hard to cover it well in just under one hour. Still, we discussed the general inner workings of the garbage collector and highlighted several best practices for improving your application performance. Among the topics we covered: Switching GC flavors and understanding server, concurrent, and background GC Finding long-lived objects and allocation sources with...
Runtime Representation of Generics—Part 2
This is an excerpt from Chapter 5 (Collections and Generics) of Pro .NET Performance , scheduled to appear in less than a month. I might be publishing a few more of these before and after the book is out. After giving ample consideration to the design of Java generics and C++ templates, we can understand better the implementation choice for CLR generics. CLR generics are implemented as follows. Generic types — even open ones, like List<> — are first-class runtime citizens. There is a method...
Finalization Queue or F-Reachable Queue? SOSEX (Not So) New Commands
As Steve Johnson , the author of the awesome SOSEX debugging extension, pointed out in a comment on my last finalization post , as of SOSEX 4.0 you can use the !finq and !frq commands to inspect separately the finalization queue and the f-reachable queue. As a reminder, objects on the finalization queue are objects that are eligible for finalization but are still referenced by the application. These are objects for which finalizers will run at some point, but the GC has not passed them over to the...
Slides from the Third Jerusalem .NET/C++ User Group Meeting
On Sunday we hosted the third meeting of the Jerusalem .NET/C++ User Group . My presentation on generics in Java, .NET and C++ is below, and Noam’s presentation on the Windows Azure new features can be found in the Windows Azure Training Kit (June 2012 refresh), which I strongly recommend. Thanks for coming, and see you at the next meeting! Generics in .NET, C++ and Java
Micro-Benchmarking Done Wrong, And For The Wrong Reasons
This is a short excerpt from Chapter 2 (Performance Measurement) of Pro .NET Performance , scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. The purpose is to determine “which is faster”—using the is keyword and then casting to the desired type, or using the as keyword and relying on the result. Here’s a test class for this comparison I’ve seen lately: //Test class class Employee {   public void Work() {} } //Fragment 1 – casting...
What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11
The 32-bit and 64-bit development story on Windows seemingly never stops causing problems for developers. It’s been a decade since 64-bit processors have started popping up in the Windows consumer environment, but we just can’t get it right . If you forget some of the gory details, here are a couple of reminders: On a 64-bit Windows system, both the 32-bit and 64-bit versions of system DLLs are stored. The 64-bit DLLs are in C:\Windows\System32, and the 32-bit DLLs are in C:\Windows\SysWOW64. When...
Virtual Method Dispatch and Object Layout Changes in CLR 4.0
As part of the upcoming Pro .NET Performance book, there’s quite a bit of research we need to do on various facets of CLR internals. During my research for the Type Internals chapter I discovered a change in CLR object layout and virtual method dispatch as of CLR 4.0 – possibly not the most exciting of changes but one that invalidates most of the existing material on this subject, such as the popular JIT and Run article or the Advanced .NET Debugging book . First, a quick overview of how reference...
Pro .NET Performance
It is customary to apologize for a prolonged blog silence, so here goes: I’ve been very busy with three extremely interesting projects, one of which is the SELA Developer Practice that is very near. Here’s another: It’s been more than five years since I wrote a SELA course called Effective C#, which quickly turned to another course called .NET Performance . Since then, I trained this course dozens of times, spoke about performance optimization at conferences, delivered a one-day summary at several...
Finalization Queue or F-Reachable Queue? Find Out with SOS
It’s 2012, so time for another post related to finalization. This so-often-abused CLR feature has popped up here in the past. A quick recap: You can’t trust the finalizer to ever execute Finalization order is not guaranteed You can create subtle race conditions by using objects that are simultaneously finalized You can end up with a memory leak if objects are created faster than the finalizer thread can run their finalizers This time, we’ll see how to determine whether a particular object is in the...
How Understanding Assembly Language Helps Debug .NET Applications [CodeProject]
A quick plug to let you know that I published today an article called How Understanding Assembly Language Helps Debug .NET Applications on CodeProject. It contains some scenarios previously covered on this blog and others that I worked on specifically for the article, and strives to explain why assembly language skills are beneficial even if you’re only working on .NET applications. Here’s the TOC: Analyzing a corrupted or incomplete call stack Correlate crash location to source code line Determine...
Pinpointing a Static GC Root with SOS
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...
More Posts Next page »