воскресенье, 14 июня 2009 г.

C# 4.0 lock statement implementation

We all know what C# lock statement turns into.

Giving

static void Main(string[] args)
{
lock (s_lock)
{
}
}

We get

private static void Main(string[] args)
{
object CS$2$0000;
Monitor.Enter(CS$2$0000 = s_lock);
try
{
}
finally
{
Monitor.Exit(CS$2$0000);
}
}


But in C# 4 lock statement uses new overload of Monitor.Enter and enters guarded region inside try block.

private static void Main(string[] args)
{
object CS$2$0000;
bool <>s__LockTaken0 = false;
try
{
Monitor.Enter(CS$2$0000 = s_lock, ref <>s__LockTaken0);
}
finally
{
if (<>s__LockTaken0)
{
Monitor.Exit(CS$2$0000);
}
}
}

If you want to know what it was made for read this exhaustive Joe Duffy’s explanation.
If you have thought that the window between Monitor.Enter and try block is too short to be considered read this case.

пятница, 5 июня 2009 г.

New SOS commands in CLR 4.0 Beta1

I seems that SOS will have several new commands in CLR 4.0.

How did I find that out?  I just retrieved SOS help file (it’s just a binary resource in SOS.dll) from .NET 2.0 SOS   and .NET 4.0  SOS and fed the files to WinDiff.  And that is what we have.

New commands:
Examining code and stacks
ThreadState

Diagnostic Utilities
VerifyObj
FindRoots
HeapStat
GCWhere
ListNearObj
FinalizeQueue
AnalyzeOOM

Examining the GC history
HistInit
HistStats
HistRoot
HistObj
HistObjFind
HistClear

New arguments for two commands:
!ObjSize [<Object address>] | [-aggregate] [-stat]
!FinalizeQueue [-detail] | [-allReady] [-short]

Supporting DML:
>> Does SOS support DML?
Yes.  SOS respects the .prefer_dml option in the debugger.  If this setting is
turned on, then SOS will output DML by default.  Alternatively, you may leave
it off and add /D to the beginning of a command to get DML based output for it.
Not all SOS commands support DML output.


SOS_2_help.txt
SOS_4_help.txt

четверг, 4 июня 2009 г.

Introduction

Hi everybody. I created this blog to share my .NET findings and thoughts. It is also a way to learn English,  so if you find my English really weird remember what  the blog's name  is stand for :)