<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>All Your Base Are Belong To Us</title><link>http://blogs.microsoft.co.il/blogs/sasha/</link><description>Mostly .NET internals and other kinds of gory details</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/sashag" /><feedburner:info uri="sashag" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Performance Gains with Data Parallelism: Using SIMD Instructions from C#</title><link>http://feedproxy.google.com/~r/sashag/~3/LbiK-H6xi6U/performance-gains-with-data-parallelism-using-simd-instructions-from-c.aspx</link><pubDate>Thu, 24 May 2012 13:03:12 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1102208</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1102208</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/24/performance-gains-with-data-parallelism-using-simd-instructions-from-c.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This is a short excerpt (with slight modifications) from Chapter 10 of &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/13/pro-net-performance.aspx"&gt;Pro .NET Performance&lt;/a&gt;, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Theoretically, .NET developers should never be concerned with optimizations tailored to a specific processor or instruction set. After all, the purpose of IL and JIT compilation is to allow managed applications to run on any hardware that has the .NET Framework installed, and to remain indifferent to operating system bitness, processor features, and instruction sets. However, squeezing the last bits of performance from managed applications may require &lt;a href="http://www.codeproject.com/Articles/331050/Assembly-Helps-Debug-NET-Applications"&gt;reasoning at the assembly language level&lt;/a&gt;. At other times, understanding processor-specific features is a first step for even more significant performance gains.&lt;/p&gt;  &lt;p&gt;Data-level parallelism, also known as &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/SIMD"&gt;Single Instruction Multiple Data&lt;/a&gt;&lt;/i&gt; (SIMD), is a feature of modern processors that enables the execution of a single instruction on a large set of data (larger than the machine word). The de-facto standard for SIMD instruction sets is SSE (&lt;a href="http://en.wikipedia.org/wiki/Streaming_SIMD_Extensions"&gt;&lt;em&gt;Streaming SIMD Extensions&lt;/em&gt;&lt;/a&gt;), used by Intel processors since Pentium III. This instruction set adds new 128-bit registers (with the XMM prefix) as well as instructions that can operate on them. Recent Intel processors introduced &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Advanced_Vector_Extensions"&gt;Advanced Vector Extensions&lt;/a&gt;&lt;/i&gt; (AVX), which is an extension of SSE that offers 256-bit registers and even more SIMD instructions. Some examples of SSE instructions include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Integer and floating-point arithmetic&lt;/li&gt;    &lt;li&gt;Comparisons, shuffling, data type conversion (integer to floating-point)&lt;/li&gt;    &lt;li&gt;Bitwise operations&lt;/li&gt;    &lt;li&gt;Minimum, maximum, conditional copies, CRC32, population count (introduced in SSE4 and later)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You might be wondering whether instructions operating on these “new” registers are slower than their standard counterparts. If that were the case, any performance gains would be deceiving. Fortunately, that is not the case. On Intel i7 processors, a floating-point addition (FADD) instruction on 32-bit registers has throughput of one instruction per cycle and latency of 3 cycles. The equivalent ADDPS instruction on 128-bit registers also has throughput of one instruction per cycle and latency of 3 cycles.&lt;/p&gt;  &lt;p&gt;Using these instructions in high-performance loops can provide up to 8-fold performance gains compared to naïve sequential programs that operate on a single floating-point or integer value at a time. For example, consider the following (admittedly trivial) code:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;//Assume that A, B, C are equal-size float arrays     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;for (int i = 0; i &amp;lt; A.length; ++i) {     &lt;br /&gt;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;C[i] = A[i] + B[i];     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The standard code emitted by the JIT in this scenario is the following:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;; ESI has A, EDI has B, ECX has C, EDX has i     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;xor edx,edx     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;cmp dword ptr [esi+4],0     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;jle END_LOOP     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;NEXT_ITERATION:     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;fld dword ptr [esi+edx*4+8] ; load A[i], no range check     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;cmp edx,dword ptr [edi+4]&amp;#160;&amp;#160; ; range check accessing B[i]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;jae OUT_OF_RANGE     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;fadd dword ptr [edi+edx*4+8]; add B[i]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;cmp edx,dword ptr [ecx+4]&amp;#160;&amp;#160; ; range check accessing C[i]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;jae OUT_OF_RANGE     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;fstp dword ptr [ecx+edx*4+8]; store into C[i]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;inc edx     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;cmp dword ptr [esi+4],edx&amp;#160;&amp;#160; ; are we done yet?     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;jg NEXT_ITERATION     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;END_LOOP:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Each loop iteration performs a single FADD instruction that adds two 32-bit floating-point numbers. However, by using 128-bit SSE instructions, &lt;em&gt;four&lt;/em&gt; iterations of the loop can be issued at a time, as follows (the code below performs no range checks and assumes that the number of iterations is equally divisible by 4):&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;xor edx, edx     &lt;br /&gt;NEXT_ITERATION:      &lt;br /&gt;; copy 16 bytes from B to xmm1      &lt;br /&gt;movups xmm1, xmmword ptr [edi+edx*4+8]      &lt;br /&gt;; copy 16 bytes from A to xmm0&amp;#160; &lt;br /&gt;movups xmm0, xmmword ptr [esi+edx*4+8]      &lt;br /&gt;; add xmm0 to xmm1 and store the result in xmm1      &lt;br /&gt;addps xmm1, xmm0      &lt;br /&gt;; copy 16 bytes from xmm1 to C      &lt;br /&gt;movups xmmword ptr [ecx+edx*4+8], xmm1      &lt;br /&gt;add edx, 4 ; increase loop index by 4      &lt;br /&gt;cmp edx, dword ptr [esi+4]      &lt;br /&gt;jg NEXT_ITERATION&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;On an AVX processor, we could move even more data around in each iteration (with the 256-bit YMM* registers), for an even bigger performance improvement:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;xor edx, edx     &lt;br /&gt;NEXT_ITERATION:      &lt;br /&gt;; copy 32 bytes from B to ymm1      &lt;br /&gt;vmovups ymm1, ymmword ptr [edi+edx*4+8]       &lt;br /&gt;; copy 32 bytes from A to ymm0      &lt;br /&gt;vmovups ymm0, ymmword ptr [esi+edx*4+8]       &lt;br /&gt;; add ymm0 to ymm1 and store the result in ymm1      &lt;br /&gt;vaddps ymm1, ymm1, ymm0       &lt;br /&gt;; copy 32 bytes from ymm1 to C      &lt;br /&gt;vmovups ymmword ptr [ecx+edx*4+8], ymm1       &lt;br /&gt;add edx, 8 ; increase loop index by 8      &lt;br /&gt;cmp edx, dword ptr [esi+4]      &lt;br /&gt;jg NEXT_ITERATION&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The SIMD instructions used in these examples are only the tip of the iceberg. Modern applications and games use SIMD instructions to perform complex operations, including scalar product, shuffling data around in registers and memory, checksum calculation, and many others. &lt;/em&gt;&lt;a href="http://software.intel.com/en-us/avx/"&gt;&lt;em&gt;Intel’s AVX portal&lt;/em&gt;&lt;/a&gt;&lt;em&gt; is a good way to learn thoroughly what AVX can offer.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The JIT compiler uses only a small number of SSE instructions, even though they are available on practically every processor manufactured in the last 10 years. Specifically, the JIT compiler uses the SSE &lt;a href="http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc199.htm"&gt;MOVQ&lt;/a&gt; instruction to copy medium-sized structures through the XMM* registers (for large structures, &lt;a href="http://webster.cs.ucr.edu/AoA/Windows/HTML/StringInstructions.html"&gt;REP MOVS&lt;/a&gt; is used instead), uses SSE2 instructions for floating point to integer conversion, and other corner cases. The JIT compiler &lt;i&gt;does not&lt;/i&gt; auto-vectorize loops by unifying iterations, as we did manually in the preceding code.&lt;/p&gt;  &lt;p&gt;Unfortunately, C# doesn’t offer any keywords for embedding inline assembly code into your managed programs. Although you could factor out performance-sensitive parts to a C++ module and use .NET interoperability to access it, this is often clumsy and introduces a small performance penalty as the interoperability boundaries are crossed. There are two other approaches for embedding SIMD code without resorting to interoperability.&lt;/p&gt;  &lt;p&gt;A brute-force way to run arbitrary machine code from a managed application (albeit with a light interoperability layer) is to dynamically emit the machine code and then call it. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getdelegateforfunctionpointer.aspx"&gt;Marshal.GetDelegateForFunctionPointer&lt;/a&gt; method is key, as it returns a managed delegate pointing to an unmanaged memory location, which may contain arbitrary code. The following code allocates virtual memory with the EXECUTE_READWRITE page protection, which enables us to copy code bytes into memory and then execute them. The result, on my Intel i7-860 CPU, is a more than 2-fold improvement in execution time!&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;[UnmanagedFunctionPointer(CallingConvention.StdCall)]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;delegate void VectorAddDelegate(     &lt;br /&gt;&amp;#160; float[] C, float[] B, float[] A, int length);      &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;[DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;static extern IntPtr VirtualAlloc(     &lt;br /&gt;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;IntPtr lpAddress, UIntPtr dwSize,     &lt;br /&gt;&amp;#160; IntPtr flAllocationType, IntPtr flProtect);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;//This array of bytes has been produced from      &lt;br /&gt;//the SSE assembly version – it is a complete      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;//function that accepts four parameters (three     &lt;br /&gt;//vectors and length) and adds the vectors      &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;byte[] sseAssemblyBytes = {     &lt;br /&gt;&amp;#160; 0x8b, 0x5c, 0x24, 0x10, 0x8b, 0x74, 0x24, 0x0c, 0x8b,      &lt;br /&gt;&amp;#160; 0x7c, 0x24, &lt;/font&gt;&lt;font face="Consolas"&gt;0x08, 0x8b, 0x4c, 0x24, 0x04, 0x31, 0xd2,     &lt;br /&gt;&amp;#160; 0x0f, 0x10, 0x0c, 0x97, &lt;/font&gt;&lt;font face="Consolas"&gt;0x0f, 0x10, 0x04, 0x96, 0x0f,     &lt;br /&gt;&amp;#160; 0x58, 0xc8, 0x0f, 0x11, 0x0c, 0x91, &lt;/font&gt;&lt;font face="Consolas"&gt;0x83, 0xc2, 0x04,     &lt;br /&gt;&amp;#160; 0x39, 0xda, 0x7f, 0xea, 0xc2, 0x10, 0x00 };      &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;IntPtr codeBuffer = VirtualAlloc(     &lt;br /&gt;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;IntPtr.Zero, &lt;/font&gt;&lt;font face="Consolas"&gt;new UIntPtr((uint)sseAssemblyBytes.Length),     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160; 0x1000 | 0x2000, //MEM_COMMIT | MEM_RESERVE     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160; 0x40 //EXECUTE_READWRITE     &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;);     &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;Marshal.Copy(sseAssemblyBytes, 0,     &lt;br /&gt;&amp;#160; codeBuffer, sseAssemblyBytes.Length);      &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;VectorAddDelegate addVectors = (VectorAddDelegate)     &lt;br /&gt;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;Marshal.GetDelegateForFunctionPointer(     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; codeBuffer, typeof(VectorAddDelegate));      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;//We can now use ‘addVectors’ to add vectors!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;A completely different approach, which unfortunately isn’t available on the Microsoft CLR, is extending the JIT compiler to emit SIMD instructions. This is the approach taken by &lt;i&gt;&lt;a href="http://docs.go-mono.com/index.aspx?link=N:Mono.Simd"&gt;Mono.Simd&lt;/a&gt;&lt;/i&gt;. Managed code developers who use the Mono .NET runtime can reference the Mono.Simd assembly and use JIT compiler support that converts operations on types such as Vector16b or Vector4f to the appropriate SSE instructions.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;     &lt;hr /&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1102208" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/LbiK-H6xi6U" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/PerformanceBook/default.aspx">PerformanceBook</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/24/performance-gains-with-data-parallelism-using-simd-instructions-from-c.aspx</feedburner:origLink></item><item><title>Obtaining mscordacwks.dll for CLR Versions You Don’t Have</title><link>http://feedproxy.google.com/~r/sashag/~3/Mo5ut2Qw34E/obtaining-mscordacwks-dll-for-clr-versions-you-don-t-have.aspx</link><pubDate>Sat, 19 May 2012 14:46:55 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1096529</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1096529</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/19/obtaining-mscordacwks-dll-for-clr-versions-you-don-t-have.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Note: This blog post assumes that you can capture and analyze managed dumps in WinDbg using SOS, and have encountered a bizarre technical problem when using dumps from a production environment. If this assumption is incorrect, feel free to peruse my &lt;/em&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2010/08/10/net-debugging-and-c-debugging-resources.aspx"&gt;&lt;em&gt;.NET Debugging Resources link post&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;When debugging managed dumps in WinDbg, you will need to load the SOS version that is compatible with the CLR version in the dump. SOS, in turn, requires the CLR “data access DLL” (mscordacwks.dll), which is a debugging helper shipping with the .NET Framework. If SOS and/or mscordacwks.dll are missing or have the wrong version, you will receive an error similar to the following when trying to run most SOS commands:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Failed to load data access DLL, 0x80004005      &lt;br /&gt;Verify that 1) you have a recent build of the debugger (6.2.14 or newer)       &lt;br /&gt;2) the file mscordacwks.dll that matches your version of mscorwks.dll is in the version directory       &lt;br /&gt;3) or, if you are debugging a dump file, verify that the file mscordacwks_&amp;lt;arch&amp;gt;_&amp;lt;arch&amp;gt;_&amp;lt;version&amp;gt;.dll is on your symbol path.       &lt;br /&gt;4) you are debugging on the same architecture as the dump file. For example, an IA64 dump file must be debugged on an IA64 machine.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;You can also run the debugger command .cordll to control the debugger&amp;#39;s load of mscordacwks.dll. .cordll -ve -u -l will do a verbose reload. If that succeeds, the SOS command should work on retry.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;If you are debugging a minidump, you need to make sure that your executable path is pointing to mscorwks.dll as well.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Some CLR versions have been indexed by the Microsoft public symbol server, so you can instruct the debugger to download everything automatically by setting your symbol path and image path to the Microsoft symbol server.&lt;/p&gt;  &lt;p&gt;However, some CLR versions have not been indexed and cannot be retrieved automatically—and this is where you need to crawl the Web and find the binaries manually. Today I had the chance to encounter a CLR version, 2.0.50727.3607, which WinDbg couldn’t retrieve from the Microsoft symbol server:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;SYMSRV:&amp;#160; http://msdl.microsoft.com/download/symbols/      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mscordacwks_x86_x86_2.0.50727.3607.dll/4ADD5446590000/       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mscordacwks_x86_x86_2.0.50727.3607.dll not found&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Doug Stewart has been collecting &lt;a href="http://blogs.msdn.com/b/dougste/archive/2007/09/06/version-history-of-the-clr-2-0.aspx"&gt;updates to CLR 2.0&lt;/a&gt; for several years now, and has an entry on his post for the 3607 CLR build, associated with &lt;a href="http://support.microsoft.com/kb/976569"&gt;KB article 976569&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you go to the KB article, you’ll be able to download the update, an executable file. Instead of launching it, open it in an application that understands self-executing archives, such as &lt;a href="http://www.7-zip.org/"&gt;7-Zip&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_13F67A4D.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_3592A31E.png" width="560" height="408" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Locate the .msp file and open it again:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_395047EE.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_24EA8263.png" width="562" height="410" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One of the .cab files contains the files we are looking for. If you got the wrong .cab file, try the other one :-)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_739B9802.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_4A445004.png" width="568" height="402" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now all that’s left is to extract them to a temporary directory, rename them to mscorwdacwks.dll and mscorwks.dll, and issue a &lt;em&gt;.cordll -u -ve -lp &amp;lt;path&amp;gt;&lt;/em&gt; command in WinDbg:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:014&amp;gt; .cordll -u -ve -lp D:\temp\3607      &lt;br /&gt;CLRDLL: Loaded DLL D:\temp\3607\mscordacwks.dll       &lt;br /&gt;CLR DLL status: Loaded DLL D:\temp\3607\mscordacwks.dll&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Voila—you can run any SOS commands now.&lt;/p&gt;  &lt;hr /&gt;&lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1096529" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/Mo5ut2Qw34E" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Debugging/default.aspx">Debugging</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/19/obtaining-mscordacwks-dll-for-clr-versions-you-don-t-have.aspx</feedburner:origLink></item><item><title>“Fitting” Performance into the Software Development Lifecycle</title><link>http://feedproxy.google.com/~r/sashag/~3/z4iCkDYfBLI/fitting-performance-into-the-software-development-lifecycle.aspx</link><pubDate>Sun, 13 May 2012 09:22:47 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1090902</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1090902</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/13/fitting-performance-into-the-software-development-lifecycle.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This is a short excerpt from Chapter 1 of &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/13/pro-net-performance.aspx"&gt;Pro .NET Performance&lt;/a&gt;, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. We have an &lt;a href="http://www.amazon.com/Pro-NET-Performance-Optimize-Applications/dp/1430244585"&gt;Amazon page&lt;/a&gt; and a cover image now!&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Where do you fit performance in the software development lifecycle? This innocent question carries the mind baggage of having to &lt;i&gt;retrofit&lt;/i&gt; performance into an existing process. Although it is possible, a healthier approach is to consider every step of the development lifecycle an opportunity to understand the application’s performance better—first, the performance goals and important metrics; next, whether the application meets or exceeds its goals; and finally, whether maintenance, user loads, and requirement changes introduce any regressions.&lt;/p&gt;  &lt;p&gt;During the &lt;strong&gt;requirements gathering phase&lt;/strong&gt;, you should start thinking about the performance goals you would like to set.&lt;/p&gt;  &lt;p&gt;During the &lt;strong&gt;architecture phase&lt;/strong&gt;, you should refine the performance metrics important for your application and define concrete performance goals.&lt;/p&gt;  &lt;p&gt;During the &lt;strong&gt;development phase&lt;/strong&gt;, you should frequently perform exploratory performance testing on prototype code or partially complete features to verify that you are well within the system’s performance goals.&lt;/p&gt;  &lt;p&gt;During the &lt;strong&gt;testing phase&lt;/strong&gt;, you should perform significant load testing and performance testing to validate completely your system’s performance goals.&lt;/p&gt;  &lt;p&gt;During &lt;strong&gt;subsequent development and maintenance&lt;/strong&gt;, you should perform additional load testing and performance testing with every release (and preferably on a daily or weekly basis) to quickly identify any performance regressions introduced into the system.&lt;/p&gt;  &lt;p&gt;Taking the time to develop a suite of automatic load tests and performance tests, to set up an isolated lab environment in which to run them, and to analyze their results carefully to make sure no regressions are introduced is a very time-consuming process. Nevertheless, the performance benefits gained from systematically measuring and improving performance and making sure regressions don’t creep slowly into the system is worth the initial investment in having a robust performance development process.&lt;/p&gt;  &lt;p&gt;   &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1090902" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/z4iCkDYfBLI" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/PerformanceBook/default.aspx">PerformanceBook</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/13/fitting-performance-into-the-software-development-lifecycle.aspx</feedburner:origLink></item><item><title>Pinpointing Memory Leaks with CLR Profiler Heap Graphs</title><link>http://feedproxy.google.com/~r/sashag/~3/hYts-1XWpCk/pinpointing-memory-leaks-with-clr-profiler-heap-graphs.aspx</link><pubDate>Fri, 04 May 2012 08:43:52 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1082497</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1082497</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/04/pinpointing-memory-leaks-with-clr-profiler-heap-graphs.aspx#comments</comments><description>&lt;p&gt;CLR Profiler is a free Microsoft tool for diagnosing memory-related performance problems in managed applications. In this post, I’m using CLR Profiler v4.0, which you can &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=16273"&gt;download here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I talked about CLR Profiler here as a post-mortem diagnostic tool that can &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2011/07/22/mapping-the-memory-usage-of-net-applications-part-3-clr-profiler.aspx"&gt;open log files generated by SOS.dll’s &lt;em&gt;!TraverseHeap&lt;/em&gt; command and present a reference graph of all live objects&lt;/a&gt;. This in itself is a little-known feature of CLR Profiler; it is even less known that CLR Profiler can generate these reference graphs &lt;em&gt;live&lt;/em&gt;, and compare them automatically to show you where a memory leak is coming from.&lt;/p&gt;  &lt;p&gt;All you need to do is run your application under CLR Profiler, and click the “Show heap now” button periodically. This is similar to the “Take snapshot” functionality in ANTS Memory Profiler and other tools. When the application terminates, you click the “Heap Graph” button in the Summary view.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_0E4D33AD.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_093AD031.png" width="528" height="308" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This produces a reference graph in which you can see the differences between snapshots. This is the end of the graph, which makes it evident that almost all the retained objects are strings, held by string arrays and &lt;em&gt;FileInformation&lt;/em&gt; objects:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_0D64A7F6.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_3B224AEE.png" width="528" height="242" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And this is the beginning of the graph, which makes it clear (with &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2012/02/07/pinpointing-a-static-gc-root-with-sos.aspx"&gt;some experience deciphering root reference chains&lt;/a&gt;) that the majority of objects are retained by a static &lt;em&gt;EventHandler:&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_5194E975.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_2DAC121B.png" width="535" height="245" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you zoom into the snapshots, you’ll see three colors, indicating the amount of memory allocated and retained between the snapshots. For example, the darkest pink objects were created between the second and the third snapshots.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_720C035A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_3ECFC9F1.png" width="160" height="214" /&gt;&lt;/a&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_2FB8EB17.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_4050E605.png" width="363" height="162" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;There are several advanced options available for further exploration. For example, you can view only new objects and then see who allocated them (which call stack in your program is responsible for creating them). You could even look at a GC timeline and see which objects were alive at every point in time, as well as who allocated them:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_051D0A3A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_17C1DE24.png" width="530" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_4FB3AC3A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_4C521492.png" width="532" height="129" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To summarize, CLR Profiler still has plenty of hidden gems and you should consider using it—especially in simple scenarios. After all, it’s hard to beat its price :-)&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1082497" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/hYts-1XWpCk" height="1" width="1"/&gt;</description><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/04/pinpointing-memory-leaks-with-clr-profiler-heap-graphs.aspx</feedburner:origLink></item><item><title>Setting Up an Offline Production Debugging Environment</title><link>http://feedproxy.google.com/~r/sashag/~3/1xmXkpL_Zlg/setting-up-an-offline-production-debugging-environment.aspx</link><pubDate>Wed, 02 May 2012 07:22:05 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1080514</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1080514</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/02/setting-up-an-offline-production-debugging-environment.aspx#comments</comments><description>&lt;p&gt;If you’re doing production debugging in a closed environment—closed-down servers with no Internet access, or if you work at an institution that doesn’t have unrestricted Internet access from developer machines, this post will help you set up an offline production debugging environment. Incidentally, this post will also help if you’re going to host SELA’s &lt;a href="http://sela.co.il/syl/syllabus.aspx?CourseCode=DNDebug&amp;amp;CategoryID=165"&gt;.NET Debugging&lt;/a&gt; or &lt;a href="http://sela.co.il/syl/syllabus.aspx?coursecode=cppdbg&amp;amp;categoryid=165"&gt;C++ Debugging&lt;/a&gt; courses, and want to make sure your workstations are ready for the numerous hands-on labs.&lt;/p&gt;  &lt;p&gt;First and foremost, you are going to need all the tools you plan using for production debugging. At the very least, this includes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009"&gt;Debugging Tools for Windows&lt;/a&gt;        &lt;br /&gt;&lt;/strong&gt;Note there are 32-bit and 64-bit versions, you need whatever your application is using. For several releases now, the installation package is only available through the WDK or the Windows SDK, but you can follow the &lt;a href="http://msdn.microsoft.com/en-us/windows/hardware/hh852363"&gt;instructions here&lt;/a&gt; to configure the SDK web installer to download only the Debugging Tools for Windows installation package.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=16273"&gt;CLR Profiler&lt;/a&gt;&lt;/strong&gt;      &lt;br /&gt;The v4.0 version works for CLR 2.0 applications, so that’s the one you need.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb842062"&gt;Sysinternals Suite&lt;/a&gt;        &lt;br /&gt;&lt;/strong&gt;If you’re really low on disk space, the least you need are Process Explorer, Process Monitor, and VMMap.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;.NET disassembler&lt;/strong&gt; – any of the following will do:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://www.reflector.net/"&gt;RedGate .NET Reflector&lt;/a&gt; [paid]&lt;/li&gt;      &lt;li&gt;&lt;a href="http://wiki.sharpdevelop.net/ilspy.ashx"&gt;ILSpy&lt;/a&gt; [free, open source]&lt;/li&gt;      &lt;li&gt;&lt;a href="http://www.telerik.com/products/decompiler.aspx"&gt;JustDecompile&lt;/a&gt; [free]&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=20028"&gt;Application Verifier&lt;/a&gt;        &lt;br /&gt;&lt;/strong&gt;Note there are 32-bit and 64-bit versions.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Debugging extensions&lt;/strong&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://stevestechspot.com/"&gt;SOSEX&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://www.nynaeve.net/?p=94"&gt;SDbgExt&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;       &lt;div align="left"&gt;&lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=1073"&gt;PSScor2&lt;/a&gt; and &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=21255"&gt;PSScor4&lt;/a&gt;&lt;/div&gt;     &lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2009/10/24/wait-chain-traversal-debugging-extension-for-windbg.aspx"&gt;WCT&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;Next, you’re going to need debugging symbols for your environment. This includes debugging symbols for your own code, but more importantly, symbols for Windows, the CLR, and the .NET Framework versions your application is using.&lt;/p&gt;  &lt;p&gt;In an online environment, obtaining symbols is trivial through the &lt;a href="http://support.microsoft.com/kb/311503"&gt;Microsoft symbol server&lt;/a&gt;. In an offline environment, you need to jump through a few hoops to make sure you have all the symbols set up, so here goes.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Windows symbols&lt;/strong&gt; are available for download as &lt;a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463028.aspx"&gt;symbol packages&lt;/a&gt; for various OS versions. As always, you need to make sure you’re downloading symbols for the precise operating system version on which your application runs. If there are several platforms you’re using, you’ll need symbols for all of them.&lt;/p&gt;  &lt;p&gt;If you installed any &lt;strong&gt;hotfixes or updates&lt;/strong&gt; from Windows Update, you’ll need to download symbols for them manually. Use the symchk.exe utility that ships with the Debugging Tools for Windows to obtain manually symbols on an Internet-connected machine. Follow &lt;a href="http://msdn.microsoft.com/en-us/library/ff560061(VS.85).aspx"&gt;these instructions&lt;/a&gt; to generate a text file on the disconnected machine and use it on a connected machine to download symbols.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;.NET Framework symbols&lt;/strong&gt; are available &lt;a href="http://referencesource.microsoft.com/netframework.aspx"&gt;online on the Reference Source Code Center&lt;/a&gt;. These packages contain source code (!) and symbol files for the .NET Framework assemblies: mscorlib.dll, System.dll, and others.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;CLR symbols&lt;/strong&gt; are not available online as part of the .NET Framework symbol packages. You won’t usually need them unless you’re exploring CLR internals or dealing with very specific problems that require inspecting unmanaged call stacks of managed threads. To obtain CLR symbols, you’ll have to use the &lt;a href="http://msdn.microsoft.com/en-us/library/ff560061(VS.85).aspx"&gt;same technique&lt;/a&gt; mentioned above with symchk.exe.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Key CLR binaries and SOS.DLL&lt;/strong&gt; are required for properly debugging dump files on a different machine. If you have access to the original machine, you can simply copy mscorwks.dll/clr.dll, SOS.dll and mscordacwks.dll from the %windir%\Microsoft.NET\Framework* directory corresponding to your .NET version. If you don’t have access to the original machine, you’ll have to track down the installation package for the appropriate CLR version and retrieve these binaries from it—I’ll cover this in a future post.&lt;/p&gt;  &lt;p&gt;After following these instructions, you should have a fully functional offline production debugging environment. Additions and comments are welcome!&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1080514" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/1xmXkpL_Zlg" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Tools/default.aspx">Tools</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/05/02/setting-up-an-offline-production-debugging-environment.aspx</feedburner:origLink></item><item><title>Second Meeting of the Jerusalem .NET/C++ User Group</title><link>http://feedproxy.google.com/~r/sashag/~3/wGEZJuzoSvY/second-meeting-of-the-jerusalem-net-c-user-group.aspx</link><pubDate>Mon, 30 Apr 2012 07:22:38 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1078702</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1078702</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/30/second-meeting-of-the-jerusalem-net-c-user-group.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://jlm-cpp-may2012.eventbrite.com/"&gt;second meeting of the Jerusalem .NET C++ User Group&lt;/a&gt; will take place on May 29. This time we’ll be talking about advanced C++ topics. If you’re a developer in the Jerusalem area working with C++, this is the user group for you! &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/25/slides-from-the-first-jerusalem-net-c-meeting.aspx"&gt;Slides from the previous meeting’s talks are available online&lt;/a&gt; if you’d like to catch up on what you might have missed last time.&lt;/p&gt;  &lt;p&gt;The agenda for this meeting is as follows:&lt;/p&gt;  &lt;p&gt;18:00-18:15 – Networking and refreshments    &lt;br /&gt;18:15-19:00 – Portable lock-free use of STL containers (Adi Shavit)     &lt;br /&gt;19:00-19:15 – Networking and refreshments     &lt;br /&gt;19:15-20:00 – Undocumented native debugging tricks (&lt;a href="http://thetweaker.wordpress.com/"&gt;Ofek Shilon&lt;/a&gt;)&lt;/p&gt;  &lt;div style="text-align:center;margin:10px;width:195px;float:right;"&gt;&lt;iframe height="311" src="http://www.eventbrite.com/countdown-widget?eid=3457259757" frameborder="0" width="195" scrolling="no"&gt;&lt;/iframe&gt;&lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Undocumented native debugging tricks      &lt;br /&gt;&lt;/strong&gt;Visual Studio provides great debugging facilities as is – but, it also contains a tremendous wealth of useful debugging features, that just never matured enough to be documented and supported. Such hidden features range from enhanced interaction with the debugee, improved debugging productivity, better state diagnostics, better exploration of code flow, and more. The talk would survey as many of those goodies as time permits.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Portable lock-free use of standard STL containers      &lt;br /&gt;&lt;/strong&gt;Parallel and concurrent hardware is becoming more and more pervasive and, in turn, demand for high performance and fast response of these concurrent systems is growing. One modern go-to solution are lock-free data structures. A lot of research has recently produced many lock-free and wait-free data-structures. However, these are often data-structures for very specific use-cases. Portable, well-tested and suitably licensed implementations are still hard to come by. I&amp;#39;ll present a scheme for providing portable lock-free access to, and modification of, existing and standard STL containers. The scheme can also be adapted to most other non-STL container. With a compliant C++11 compiler, only the std library is required. On older compilers can use boost to provide the missing std components. This scheme leverages standard atomic reference-counting (via shared_ptr&amp;lt;&amp;gt;)to provide automatic garbage collection.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1078702" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/wGEZJuzoSvY" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/UserGroup/default.aspx">UserGroup</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/30/second-meeting-of-the-jerusalem-net-c-user-group.aspx</feedburner:origLink></item><item><title>The Case of The Unquoted Command Line: Process Monitor and MPGO.EXE</title><link>http://feedproxy.google.com/~r/sashag/~3/MYw__Vixf_8/the-case-of-the-unquoted-command-line-process-monitor-and-mpgo-exe.aspx</link><pubDate>Sat, 28 Apr 2012 11:49:16 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1077244</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1077244</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/28/the-case-of-the-unquoted-command-line-process-monitor-and-mpgo-exe.aspx#comments</comments><description>&lt;p&gt;A few months ago I wrote about &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/17/improvements-in-the-clr-core-in-net-framework-4-5.aspx"&gt;MPGO&lt;/a&gt;, a new Microsoft tool that ships with .NET 4.5 and enables profile-guided optimization of managed assemblies. Specifically, MPGO optimizes the layout of native images for managed assemblies, which reduces startup times, working set sizes, and page fault costs.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Shameless plug: &lt;/em&gt;&lt;a href="http://www.apress.com/9781430244585"&gt;&lt;em&gt;Pro .NET Performance&lt;/em&gt;&lt;/a&gt;&lt;em&gt; has a large section dedicated to improving startup performance, and I’ve written about this before: &lt;/em&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2009/07/22/improving-cold-startup-performance-prefetch.aspx"&gt;&lt;em&gt;Using Prefetch to improve startup performance&lt;/em&gt;&lt;/a&gt;, &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2009/07/24/improving-cold-startup-performance-rebasing-compression.aspx"&gt;&lt;em&gt;Rebasing and compression&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Anyway, I was experimenting with MPGO and encountered a strange error when working with some of my assemblies. Specifically:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;C:\Temp\mpgo test&amp;gt;mpgo -scenario App.exe -assemblylist App.exe -OutDir .      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;     &lt;br /&gt;Error:&amp;#160; Timeout or error when trying to instrument assembly C:\Temp\mpgo test\App.exe (FFFFFFFF)       &lt;br /&gt;Profile information will not be collected for this assembly.       &lt;br /&gt;This will not prevent information from being collected for other assemblies       &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;Error:&amp;#160; Timeout or Error when trying to remove instrumented assembly C:\Temp\mpgo test\App.exe (FFFFFFFF)      &lt;br /&gt;Failed to merge collected profile data into assembly C:\Temp\mpgo test\App.exe:       &lt;br /&gt;Unexpected Internal Exception The file &amp;quot;C:\Temp\mpgo test\App.ibc&amp;quot; does not exist&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This error struck me as odd, because the application in question was really simple, and I certainly didn’t know what error FFFFFFFF meant. I tried specifying the full path to the executable, and got a different error instead:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;C:\Temp\mpgo test&amp;gt;mpgo -scenario &amp;quot;C:\temp\mpgo test\App.exe&amp;quot; -assemblylist &amp;quot;C:\temp\mpgo test\App.exe&amp;quot; -OutDir .      &lt;br /&gt;      &lt;br /&gt;Session executable does not appear to exist.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This produced a somewhat simpler error, although still completely misleading because App.exe &lt;em&gt;exists&lt;/em&gt; in the specified directory. However, because the full path changed MPGO’s behavior, I suspected that something in its file access code or command-line parsing has gone awry.&lt;/p&gt;  &lt;p&gt;This is where I launched Process Monitor and configured it to watch all events generated by MPGO.EXE. When using the latter command line, I saw very quickly that MPGO was trying (and failing) to access “C:\Temp\mpgo”, which is a directory that doesn’t exist—I explicitly gave it “C:\Temp\mpgo test\App.exe” as a parameter!&lt;/p&gt;  &lt;p&gt;At this point I just had to look at the call stack to see what’s going on. MPGO.EXE is a managed application, but Process Monitor can’t give you managed call stacks (yet?), so I had to attach WinDbg and &lt;em&gt;!u&lt;/em&gt; the raw addresses to see where the file access was coming from.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_6C505B9A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_48D3B735.png" width="559" height="268" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_1955229C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_211D153E.png" width="556" height="607" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:000&amp;gt; !u &lt;strong&gt;0x600f8b&lt;/strong&gt;      &lt;br /&gt;Normal JIT generated code      &lt;br /&gt;MPGO.Harness.PreRunValidation()      &lt;br /&gt;Begin 00600e10, size 22d      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;00600e10 55&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; push&amp;#160;&amp;#160;&amp;#160; ebp     &lt;br /&gt;00600e11 8bec&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mov&amp;#160;&amp;#160;&amp;#160;&amp;#160; ebp,esp      &lt;br /&gt;…snipped…      &lt;br /&gt;00600f7e 8b4e04&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mov&amp;#160;&amp;#160;&amp;#160;&amp;#160; ecx,dword ptr [esi+4]      &lt;br /&gt;00600f81 ba01000000&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mov&amp;#160;&amp;#160;&amp;#160;&amp;#160; edx,1      &lt;br /&gt;00600f86 e8051e7f59&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; call&amp;#160;&amp;#160;&amp;#160; mscorlib_ni+0x2f2d90 (59df2d90) (System.IO.File.InternalExistsHelper(System.String, Boolean), mdToken: 06004402)      &lt;br /&gt;&lt;strong&gt;00600f8b&lt;/strong&gt; 85c0&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; test&amp;#160;&amp;#160;&amp;#160; eax,eax      &lt;br /&gt;00600f8d 7541&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; jne&amp;#160;&amp;#160;&amp;#160;&amp;#160; 00600fd0      &lt;br /&gt;00600f8f b9fc432a00&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mov&amp;#160;&amp;#160;&amp;#160;&amp;#160; ecx,2A43FCh (MT: MPGO.MpgoException)      &lt;br /&gt;00600f94 e88310c9ff&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; call&amp;#160;&amp;#160;&amp;#160; 0029201c (JitHelp: CORINFO_HELP_NEWSFAST)      &lt;br /&gt;…snipped…&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Next, I turned to the &lt;em&gt;PreRunValidation&lt;/em&gt; method in Reflector and discovered that the exception is thrown because MPGO thinks my executable file does not exist, from a line that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;if (!File.Exists(this.Exe))     &lt;br /&gt;{      &lt;br /&gt;&amp;#160; MpgoException.Throw(&amp;quot;Err_ExeMissing&amp;quot;);      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;By inspecting all assignments to &lt;em&gt;this.Exe&lt;/em&gt;, I found the following in the &lt;em&gt;Harness&lt;/em&gt; class constructor:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Match match = Regex.Match(args[i], &amp;quot;(?&amp;lt;exe&amp;gt;(?:\&amp;quot;[^\&amp;quot;]+\&amp;quot;)|[^ ]+)(?: (?&amp;lt;args&amp;gt;.*))?&amp;quot;);     &lt;br /&gt;if (!match.Success)      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Usage.Show(&amp;quot;Err_CantParseScenario_0&amp;quot;, args[i]);      &lt;br /&gt;}      &lt;br /&gt;this.Exe = match.Groups[&amp;quot;exe&amp;quot;].ToString();      &lt;br /&gt;if (this.Exe.StartsWith(&amp;quot;\&amp;quot;&amp;quot;))      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; this.Exe = this.Exe.Trim(new char[] { &amp;#39;&amp;quot;&amp;#39; });      &lt;br /&gt;}      &lt;br /&gt;this.Exe = Path.GetFullPath(this.Exe);      &lt;br /&gt;this.Args = match.Groups[&amp;quot;args&amp;quot;].ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;When applied to a quoted path, such as “C:\temp\mpgo test\App.exe”, this code produces an unquoted executable name and considers everything that follows the space to be the executable’s arguments…&lt;/p&gt;  &lt;p&gt;There is a different bug when using the former command line. In that case, I configured Process Monitor to log process (and thread) creation/deletion events, and noticed that MPGO.EXE launches NGEN.EXE with an invalid command line:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_74D0688C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_66B1798F.png" width="545" height="502" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The full command line is:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe&amp;quot; install C:\Temp\mpgo test\App.exe /tuning /ExeConfig:C:\Temp\mpgo test\App.exe&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;…which confuses NGEN, because it treats “C:\Temp\mpgo” as the application name and the rest is an invalid command line. This time, the problem is that when launching NGEN, MPGO does not bother to quote the application name.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;To summarize&lt;/strong&gt;: the purpose of this post is not to bash MPGO—the bug has been reported to the team responsible and will likely be fixed in the next Visual Studio 11 drop. What I wanted to show is that Process Monitor is quite useful in determining why applications you aren’t familiar with are behaving incorrectly. Also, figuring out proper quoting of command line parameters is really nasty (on Windows).&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1077244" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/MYw__Vixf_8" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Tools/default.aspx">Tools</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/VS2012/default.aspx">VS2012</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/28/the-case-of-the-unquoted-command-line-process-monitor-and-mpgo-exe.aspx</feedburner:origLink></item><item><title>Deep Dive into WinRT: MSDN Session</title><link>http://feedproxy.google.com/~r/sashag/~3/gPHeu1r7oUk/deep-dive-into-winrt-msdn-session.aspx</link><pubDate>Mon, 23 Apr 2012 11:33:20 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1072978</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1072978</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/23/deep-dive-into-winrt-msdn-session.aspx#comments</comments><description>&lt;p&gt;Thanks for coming to my session on WinRT internals today at Microsoft Raanana! Preparing for this session has been very interesting for me, especially as I was mucking around with vtable pointers for the &lt;a href="http://www.apress.com/9781430244585"&gt;Pro .NET Performance book&lt;/a&gt; anyway :-)&lt;/p&gt;  &lt;div style="width:425px;" id="__ss_12651249"&gt;&lt;strong style="margin:12px 0px 4px;display:block;"&gt;&lt;a title="Deep Dive into WinRT" href="http://www.slideshare.net/goldshtn/deep-dive-into-winrt" target="_blank"&gt;Deep Dive into WinRT&lt;/a&gt;&lt;/strong&gt; &lt;iframe height="355" src="http://www.slideshare.net/slideshow/embed_code/12651249" frameborder="0" width="425" scrolling="no"&gt;&lt;/iframe&gt;&lt;/div&gt;  &lt;p&gt;In this session we talked about the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Refreshment of how COM objects work &lt;/li&gt;    &lt;li&gt;WinRT object layout and relationship to COM &lt;/li&gt;    &lt;li&gt;The WinRT type system and threading model &lt;/li&gt;    &lt;li&gt;Asynchronous operations in WinRT &lt;/li&gt;    &lt;li&gt;Windows metadata files and projecting WinRT APIs to C#, C++/CX and JavaScript &lt;/li&gt;    &lt;li&gt;Designing and developing WinRT components &lt;/li&gt;    &lt;li&gt;Performance interoperability tips for WinRT &lt;/li&gt;    &lt;li&gt;Profiling WinRT applications with Visual Studio Profiler &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s my favorite slide—as close to assembly language as they let me:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_04E0D081.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_308D867E.png" width="534" height="399" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can &lt;a href="http://dl.dropbox.com/u/11349479/DeepDiveIntoWinRT_MSDN.zip"&gt;download the slides (PDF) and demos&lt;/a&gt; right now; the session’s video recording (Hebrew) will be available later on Channel 9.&lt;/p&gt;  &lt;hr /&gt;&lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1072978" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/gPHeu1r7oUk" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Windows8/default.aspx">Windows8</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/23/deep-dive-into-winrt-msdn-session.aspx</feedburner:origLink></item><item><title>Restoring a Computer From Windows Home Server Backup</title><link>http://feedproxy.google.com/~r/sashag/~3/oww6b9N0wQE/restoring-a-computer-from-windows-home-server-backup.aspx</link><pubDate>Sat, 14 Apr 2012 09:44:42 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1064299</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1064299</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/14/restoring-a-computer-from-windows-home-server-backup.aspx#comments</comments><description>&lt;p&gt;The other day I had the immensely fun experience of restoring my &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2010/07/31/my-new-laptop.aspx"&gt;Alienware m15x laptop&lt;/a&gt; from backup. It’s the second time I’ve restored a computer from backup since I have my trusty &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2010/02/04/another-happy-user-of-windows-home-server.aspx"&gt;Acer easyStore Windows Home Server system&lt;/a&gt;. It just sits quietly in the corner, gathering dust and backing up my documents, work, and memories, claiming no reward but an additional 2TB hard drive every six months.&lt;/p&gt;  &lt;p&gt;The general restore process is very simple:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Burn a copy of the &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=5587"&gt;Windows Home Server Computer Restore CD&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Boot the faulty machine from the CD&lt;/li&gt;    &lt;li&gt;Let it find your home server over the network&lt;/li&gt;    &lt;li&gt;Choose which machine to restore and which backup to use&lt;/li&gt;    &lt;li&gt;Wait a few hours and you have a restored machine&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The only potential pitfall in this process is that you need the restore CD environment to recognize your hardware. At the very least, it must be able to recognize the hard drive and the Ethernet network card, or it won’t be able to download the backup from your Home Server and restore the system from it.&lt;/p&gt;  &lt;p&gt;With every backup, Windows Home Server captures the set of critical drivers required for the restore. Before restoring the system, you can get these drivers from the Home Server backup—they will be in a folder called &lt;em&gt;Windows Home Server Drivers for Restore&lt;/em&gt; on your system drive when you view the Home Server backup from the Windows Home Server console. These drivers will work great in the recovery environment if you are restoring a 32-bit system—the recovery environment is 32-bit.&lt;/p&gt;  &lt;p&gt;Unfortunately, if you are restoring a 64-bit system, you will need to find 32-bit drivers for the hard drive and network card &lt;em&gt;manually&lt;/em&gt;. This can be a rather tedious process. You can usually find drivers on the hardware manufacturer’s website.&lt;/p&gt;  &lt;p&gt;When restoring my Alienware m15x, the only hardware device with a missing driver was the Intel Ethernet NIC. You’ll need the Windows Vista 32-bit drivers, as that’s what the recovery environment is based on. Download them from &lt;a href="http://downloadcenter.intel.com/SearchResult.aspx?lang=eng&amp;amp;ProductFamily=Ethernet+Components&amp;amp;ProductLine=Ethernet+Controllers&amp;amp;ProductProduct=Intel%C2%AE+82577+Gigabit+Ethernet+PHY"&gt;here&lt;/a&gt; and you’ll be good to go!&lt;/p&gt;  &lt;p&gt;Oh, and by the way—backups are important, but they are worthless if you never try restoring from backup. You’d think it should only take an hour and then spend a whole weekend sorting out driver problems, like I did :-)&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1064299" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/oww6b9N0wQE" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/HomeServer/default.aspx">HomeServer</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/14/restoring-a-computer-from-windows-home-server-backup.aspx</feedburner:origLink></item><item><title>Honored to be Renominated as Microsoft MVP for 2012</title><link>http://feedproxy.google.com/~r/sashag/~3/_CGtN8VYYFI/honored-to-be-renominated-as-microsoft-mvp-for-2012.aspx</link><pubDate>Wed, 04 Apr 2012 07:34:30 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1053970</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1053970</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/04/honored-to-be-renominated-as-microsoft-mvp-for-2012.aspx#comments</comments><description>&lt;p&gt;On April 1 (yes, it has the potential of being an April Fool’s every time!) I received the renomination letter—I am honored to receive the &lt;a href="http://www.microsoft.com/communities/mvp/mvp.mspx"&gt;Microsoft MVP Award&lt;/a&gt; in Visual C# for 2012.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_466B9FE4.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px 10px 10px 0px;padding-left:0px;padding-right:0px;display:inline;float:left;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" align="left" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_0E8935F4.png" width="110" height="173" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As I wrote a year ago, 2011 was an exciting year for C#—I had several opportunities to talk about async methods and the parallelism revolution last year, and 2012—the year of Windows 8—promises to be even more interesting for C# as we tackle the development of Metro-style apps.&lt;/p&gt;  &lt;p&gt;I wouldn’t be writing this post if it weren’t for the help and support of my colleagues, friends, and managers at SELA and our business partners and friends at Microsoft Israel. Specifically, David Bassa and Ishai Ram are still the best managers and friends a tech professional can have, and Guy Burstein of Microsoft DPE continuously amazes me by shaping the Israeli developer community with MSDN events and user group meetings.&lt;/p&gt;  &lt;p&gt;Thanks for reading—I am looking forward for the rest of 2012 and hope to continue providing you with interesting information on gory CLR internals and debugging problems :-)&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1053970" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/_CGtN8VYYFI" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/RandomThoughts/default.aspx">RandomThoughts</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/04/honored-to-be-renominated-as-microsoft-mvp-for-2012.aspx</feedburner:origLink></item><item><title>What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11</title><link>http://feedproxy.google.com/~r/sashag/~3/NeruNs_w6LY/what-anycpu-really-means-as-of-net-4-5-and-visual-studio-11.aspx</link><pubDate>Wed, 04 Apr 2012 06:59:15 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1053952</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1053952</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/04/what-anycpu-really-means-as-of-net-4-5-and-visual-studio-11.aspx#comments</comments><description>&lt;p&gt;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 &lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/06/28/the-case-of-regsvr32-and-the-haunted-dll.aspx"&gt;we just can’t get it right&lt;/a&gt;. If you forget some of the gory details, here are a couple of reminders:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;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.&lt;/li&gt;    &lt;li&gt;When a 32-bit process opens a file in C:\Program Files, it actually reads/writes to C:\Program Files (x86).&lt;/li&gt;    &lt;li&gt;There are separate views of (most of) the registry for 32-bit and 64-bit applications. You can change the 64-bit registry location and it wouldn’t be visible to 32-bit applications.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;These differences are hardly elegant as they are, but they allow 32-bit applications to run successfully on a 64-bit Windows system. While unmanaged applications always had to choose the native target—x86, x64, or ia64 in the Visual Studio case—managed code has the additional choice of &lt;a href="http://msdn.microsoft.com/en-us/library/zekwfyz4(v=vs.110).aspx"&gt;AnyCPU&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;What AnyCPU used to mean up to .NET 4.0 (and Visual Studio 2010) is the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.&lt;/li&gt;    &lt;li&gt;If the process runs on a 64-bit Windows system, it runs as a 64-bit process. IL is compiled to x64 machine code.&lt;/li&gt;    &lt;li&gt;If the process runs on an Itanium Windows system (has anyone got one? ;-)), it runs as a 64-bit process. IL is compiled to Itanium machine code.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Prior to Visual Studio 2010, AnyCPU was the default for most .NET projects, which was confusing to some developers: when they ran the application on a 64-bit Windows system, the process was a 64-bit process, which may cause unexpected results. For example, if the application relies on an unmanaged DLL of which only a 32-bit version is available, its 64-bit version won’t be able to load that component.&lt;/p&gt;  &lt;p&gt;In Visual Studio 2010, x86 (and not AnyCPU) became the default for most .NET projects—but otherwise the semantics haven’t changed.&lt;/p&gt;  &lt;p&gt;In .NET 4.5 and Visual Studio 11 the cheese has been moved. The default for most .NET projects is again AnyCPU, but there is more than one meaning to AnyCPU now. &lt;strong&gt;There is an additional sub-type of AnyCPU, “Any CPU 32-bit preferred”, which is the new default&lt;/strong&gt; (overall, there are now five options for the &lt;a href="http://msdn.microsoft.com/en-us/library/zekwfyz4(v=vs.110).aspx"&gt;/platform C# compiler switch&lt;/a&gt;: x86, Itanium, x64, anycpu, and anycpu32bitpreferred). When using that flavor of AnyCPU, the semantics are the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.&lt;/li&gt;    &lt;li&gt;If the process runs on a 64-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.&lt;/li&gt;    &lt;li&gt;If the process runs on an ARM Windows system, it runs as a 32-bit process. IL is compiled to ARM machine code.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The difference, then, between “Any CPU 32-bit preferred” and “x86” is only this: a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully.&lt;/p&gt;  &lt;p&gt;To inspect these changes, I created a new C# console application in Visual Studio 11 that prints the values of &lt;em&gt;Environment.Is64BitOperatingSystem&lt;/em&gt; and &lt;em&gt;Environment.Is64BitProcess&lt;/em&gt;. When I ran it on my 64-bit Windows system, the result was as follows:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Is64BitOperatingSystem = True     &lt;br /&gt;Is64BitProcess&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = False&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Inspecting the project’s properties shows the following (in the current Visual Studio UI “Prefer 32-bit” is grayed out and unchecked, where in actuality it is enabled…):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/image_58A19091.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/sasha/image_thumb_21978C8B.png" width="510" height="296" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Inspecting the executable with &lt;a href="http://msdn.microsoft.com/en-us/library/ms164699(v=vs.110).aspx"&gt;CorFlags.exe&lt;/a&gt; shows the following:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Version&amp;#160;&amp;#160; : v4.0.30319     &lt;br /&gt;CLR Header: 2.5      &lt;br /&gt;PE&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : PE32      &lt;br /&gt;CorFlags&amp;#160; : 131075      &lt;br /&gt;ILONLY&amp;#160;&amp;#160;&amp;#160; : 1      &lt;br /&gt;32BITREQ&amp;#160; : 0      &lt;br /&gt;&lt;strong&gt;32BITPREF : 1&lt;/strong&gt;      &lt;br /&gt;Signed&amp;#160;&amp;#160;&amp;#160; : 0&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;After changing the 32BITPREF setting with CorFlags.exe (using the /32bitpref- option), the output was as follows:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Is64BitOperatingSystem = True     &lt;br /&gt;Is64BitProcess&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = True&lt;/font&gt;&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me:&lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1053952" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/NeruNs_w6LY" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/.NETInternals/default.aspx">.NETInternals</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/64-bit/default.aspx">64-bit</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/VS11/default.aspx">VS11</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/04/04/what-anycpu-really-means-as-of-net-4-5-and-visual-studio-11.aspx</feedburner:origLink></item><item><title>Slides from the First Jerusalem .NET/C++ Meeting</title><link>http://feedproxy.google.com/~r/sashag/~3/TLD5JvEl6yA/slides-from-the-first-jerusalem-net-c-meeting.aspx</link><pubDate>Sun, 25 Mar 2012 10:13:03 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1042384</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1042384</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/25/slides-from-the-first-jerusalem-net-c-meeting.aspx#comments</comments><description>&lt;p&gt;Last Tuesday we hosted the &lt;a href="http://jlm-cpp-march2012.eventbrite.com/"&gt;first meeting of the Jerusalem .NET/C++ User Group&lt;/a&gt;. I forgot to take pictures, but we were a nice group of hardcore C++ developers eager to learn about the new C++ 11 features, debugging C++ code in production, and some memory management tricks relevant for C++ real-time applications.&lt;/p&gt;  &lt;p&gt;As promised, below are the presentations from the event. My presentation on C++11 covers lambdas, auto variables, rvalue references and even touches briefly on the subject of variadic templates:&lt;/p&gt;  &lt;div style="width:425px;" id="__ss_12147261"&gt;&lt;strong style="margin:12px 0px 4px;display:block;"&gt;&lt;a title="C++11" href="http://www.slideshare.net/goldshtn/c11-12147261"&gt;C++11&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse12147261" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c11-120325050750-phpapp01&amp;amp;stripped_title=c11-12147261&amp;amp;userName=goldshtn" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed name="__sse12147261" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c11-120325050750-phpapp01&amp;amp;stripped_title=c11-12147261&amp;amp;userName=goldshtn" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;    &lt;div style="padding-bottom:12px;padding-left:0px;padding-right:0px;padding-top:5px;"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/goldshtn"&gt;goldshtn&lt;/a&gt;.&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;a href="http://blog.microsoft.co.il/blogs/noams/"&gt;Noam Sheffer&lt;/a&gt;’s presentation covers the fundamentals of debugging C++ applications in production—generating crash dumps and hang dumps, performing basic analysis in WinDbg, and inspecting memory dumps to solve more complex problems:&lt;/p&gt;  &lt;div style="width:425px;" id="__ss_12147270"&gt;&lt;strong style="margin:12px 0px 4px;display:block;"&gt;&lt;a title="C++ Production Debugging" href="http://www.slideshare.net/goldshtn/c-production-debugging"&gt;C++ Production Debugging&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse12147270" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=productiondebugging-120325051023-phpapp02&amp;amp;stripped_title=c-production-debugging&amp;amp;userName=goldshtn" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed name="__sse12147270" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=productiondebugging-120325051023-phpapp02&amp;amp;stripped_title=c-production-debugging&amp;amp;userName=goldshtn" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;    &lt;div style="padding-bottom:12px;padding-left:0px;padding-right:0px;padding-top:5px;"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/goldshtn"&gt;goldshtn&lt;/a&gt;.&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Finally, Vladimir Oster talked about memory management in C++ real-time applications—overloading operators new and delete, allocating from a static memory pool, using placement new correctly, and other topics. Unfortunately, I can’t share his slides online, but ping me directly if you attended the session and would like to receive a soft copy.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1042384" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/TLD5JvEl6yA" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/JerusalemUG/default.aspx">JerusalemUG</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/25/slides-from-the-first-jerusalem-net-c-meeting.aspx</feedburner:origLink></item><item><title>Virtual Method Dispatch and Object Layout Changes in CLR 4.0</title><link>http://feedproxy.google.com/~r/sashag/~3/6T32oXyZbiU/virtual-method-dispatch-and-object-layout-changes-in-clr-4-0.aspx</link><pubDate>Thu, 15 Mar 2012 10:37:28 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1033905</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1033905</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/15/virtual-method-dispatch-and-object-layout-changes-in-clr-4-0.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;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 &lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx"&gt;&lt;em&gt;JIT and Run article&lt;/em&gt;&lt;/a&gt;&lt;em&gt; or the &lt;/em&gt;&lt;a href="http://advanceddotnetdebugging.com/"&gt;&lt;em&gt;Advanced .NET Debugging book&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;First, a quick overview of how reference type instances are laid out on the heap. Suppose that we have an &lt;em&gt;Employee &lt;/em&gt;class with two instance fields, &lt;em&gt;_name&lt;/em&gt; and &lt;em&gt;_id&lt;/em&gt;, as well as a virtual method called &lt;em&gt;Work&lt;/em&gt;. On a 32-bit managed heap, an &lt;em&gt;Employee &lt;/em&gt;instance occupies 16 bytes, and has the following layout (each cell = 4 bytes):&lt;/p&gt;  &lt;table cellspacing="5" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;Object Header Word (Sync Block Index)&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;Method Table Pointer&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;The _name field&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;The _id field&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;The method table pointer points to &lt;em&gt;Employee&lt;/em&gt;’s method table, which contains, among other things, code addresses for &lt;em&gt;Employee&lt;/em&gt;’s methods. On CLR 2.0, the method table has roughly the following layout:&lt;/p&gt;  &lt;table cellspacing="5" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Flags, Size, EEClass, Module Ptr, etc.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interface Map Pointer&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x28 Object.ToString&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x2c Object.Equals&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x30 Object.GetHashCode&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x34 Object.Finalize&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x38 Employee.Work&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Employee..ctor&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interface MTs implemented by Employee&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;The code addresses for &lt;em&gt;Employee&lt;/em&gt;’s virtual methods (including those inherited and possibly overridden from any base classes) allow virtual method dispatch to proceed as follows (assuming that the object reference is in ECX):&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;mov eax, dword ptr [ecx]      &lt;br /&gt;call dword ptr [eax+38]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The key here is that the order of methods in the method table and the offset of overridden methods from the beginning of the method table remains constant in all derived classes. For example, suppose that &lt;em&gt;Manager&lt;/em&gt; derives from &lt;em&gt;Employee &lt;/em&gt;and overrides the &lt;em&gt;Work &lt;/em&gt;method. The method table for &lt;em&gt;Manager &lt;/em&gt;would have the following layout:&lt;/p&gt;  &lt;table cellspacing="5" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Flags, Size, EEClass, Module Ptr, etc.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interface Map Pointer&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x28 Object.ToString&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x2c Object.Equals&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x30 Object.GetHashCode&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x34 Object.Finalize&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x38 &lt;strong&gt;Manager.Work&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Manager..ctor&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interfaces implemented by Manager&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;If you inspect carefully the invocation sequence for &lt;em&gt;Employee.Work&lt;/em&gt;, it turns out that the same instructions can be used to invoke &lt;em&gt;Manager.Work&lt;/em&gt; – indeed, the caller’s instruction sequence should not depend on whether &lt;em&gt;Manager &lt;/em&gt;overrides the &lt;em&gt;Work &lt;/em&gt;method, and whether the referenced instance is of type &lt;em&gt;Employee &lt;/em&gt;or of type &lt;em&gt;Manager&lt;/em&gt;. This is the key to polymorphism.&lt;/p&gt;  &lt;p&gt;However, as of CLR 4.0, the method table layout has changed. Several fields have been moved around or removed completely. Specifically, the invariant offset where virtual methods are laid out is no longer constant, because the list of interfaces implemented by the type precedes them (and can vary in derived classes). For example, this is a possible layout for &lt;em&gt;Employee&lt;/em&gt;’s method table on CLR 4.0 – assuming that it implements three interfaces:&lt;/p&gt;  &lt;table cellspacing="5" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Flags, Size, EEClass, Module Ptr, etc.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x24 Pointer to Interface List&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x28 Pointer to Methods&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; More Miscellanea&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interfaces implemented by Employee&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x40 Object.ToString&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x44 Object.Equals&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x48 Object.GetHashCode&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x4c Object.Finalize&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x50 Employee.Work&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;Fortunately, the “Pointer to Methods” field is at a constant offset from the beginning of the method table, and always points to the first entry in the code address list, which is the code address for &lt;em&gt;Object.ToString&lt;/em&gt;. The offset of any virtual methods from &lt;em&gt;that&lt;/em&gt; address is constant in all derived classes. In other words, the JIT can use a slightly longer method invocation sequence to call virtual methods in CLR 4.0:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;mov eax, dword ptr [ecx]      &lt;br /&gt;mov eax, dword ptr [eax+28]       &lt;br /&gt;call dword ptr [eax+10]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In &lt;em&gt;Manager&lt;/em&gt;’s method table, the &lt;em&gt;Work &lt;/em&gt;method may have a different offset from the beginning of the method table because &lt;em&gt;Manager &lt;/em&gt;is free to implement additional interfaces, but the “Pointer to Methods” field is at the same offset and accommodates for this difference:&lt;/p&gt;  &lt;table cellspacing="5" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Flags, Size, EEClass, Module Ptr, etc.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x24 Pointer to Interface List&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x28 Pointer to Methods&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; More Miscellanea&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Interfaces implemented by Manager&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x44 Object.ToString&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x48 Object.Equals&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x4c Object.GetHashCode&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;+0x50 Object.Finalize&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;+0x54 Manager.Work&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;This allows the same form of dispatch to work for Manager objects as well.&lt;/p&gt;  &lt;p&gt;Needless to say, relying on the details shown in this blog post would be as futile as relying on any prior material on this subject. Internal details such as object layout and code generated by the JIT are subject to change at any time between CLR releases.&lt;/p&gt;  &lt;hr /&gt;&lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;   &lt;br /&gt;&lt;em&gt;This blog post was also cross-posted to &lt;/em&gt;&lt;a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=4533592"&gt;&lt;em&gt;CodeProject&lt;/em&gt;&lt;/a&gt;.    &lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1033905" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/6T32oXyZbiU" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/.NETInternals/default.aspx">.NETInternals</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/15/virtual-method-dispatch-and-object-layout-changes-in-clr-4-0.aspx</feedburner:origLink></item><item><title>Pro .NET Performance</title><link>http://feedproxy.google.com/~r/sashag/~3/eMEPgTzJO7U/pro-net-performance.aspx</link><pubDate>Tue, 13 Mar 2012 05:34:17 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1032416</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>8</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1032416</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/13/pro-net-performance.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;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 &lt;a href="http://www.sela.co.il/s/SDP2012/index.html"&gt;SELA Developer Practice&lt;/a&gt; that is very near. Here’s another:&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;It’s been more than five years since I wrote a SELA course called Effective C#, which quickly turned to another course called &lt;a href="http://sela.co.il/syl/syllabus.aspx?CourseCode=50153&amp;amp;CategoryID=165"&gt;.NET Performance&lt;/a&gt;. Since then, I trained this course dozens of times, spoke about performance optimization at conferences, delivered a one-day summary at several tutorials and workshops. All along I was thinking that there is no single decent textbook that combines the deep dive into CLR internals I am teaching in the course with real tips for performance measurement and optimization. The time was ripe to write one.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;I am very happy to announce that I am writing a book on .NET Performance! Together with Dima Zurbalev, my esteemed colleague and coauthor, we are trying to produce a relevant guide for seasoned .NET developers looking to improve the performance of their applications and understand much better how and why the CLR does things.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The chapter list is not set in stone, and we don’t have yet a cover to show off, but we’re looking at around 350 pages across the following chapters:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Performance Metrics&lt;/li&gt;    &lt;li&gt;Performance Measurement Tools&lt;/li&gt;    &lt;li&gt;Type Internals&lt;/li&gt;    &lt;li&gt;Garbage Collection&lt;/li&gt;    &lt;li&gt;Collections and Generics&lt;/li&gt;    &lt;li&gt;Concurrency and Parallelism&lt;/li&gt;    &lt;li&gt;Networking, I/O, and Serialization&lt;/li&gt;    &lt;li&gt;Unsafe Code and Interoperability&lt;/li&gt;    &lt;li&gt;Algorithm Optimization&lt;/li&gt;    &lt;li&gt;Performance Patterns&lt;/li&gt;    &lt;li&gt;Web Application Performance – guest chapter by &lt;a href="http://blogs.microsoft.co.il/blogs/idof/"&gt;Ido Flatow&lt;/a&gt;, an outstanding Web application expert and renowned international speaker&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The book will be published by &lt;a href="http://www.apress.com/"&gt;Apress&lt;/a&gt; around August (2012), somewhere before or near the release of Visual Studio 11 and .NET 4.5, which should be a very exciting time.&lt;/p&gt;  &lt;hr /&gt; &lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1032416" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/eMEPgTzJO7U" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/.NETInternals/default.aspx">.NETInternals</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/PerformanceBook/default.aspx">PerformanceBook</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/03/13/pro-net-performance.aspx</feedburner:origLink></item><item><title>Finalization Queue or F-Reachable Queue? Find Out with SOS</title><link>http://feedproxy.google.com/~r/sashag/~3/HHjSECwkzA8/finalization-queue-or-f-reachable-queue-find-out-with-sos.aspx</link><pubDate>Sat, 25 Feb 2012 15:45:59 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1020008</guid><dc:creator>Sasha Goldshtein</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/sasha/rsscomments.aspx?PostID=1020008</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/02/25/finalization-queue-or-f-reachable-queue-find-out-with-sos.aspx#comments</comments><description>&lt;p&gt;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:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/04/26/don-t-blindly-count-on-a-finalizer.aspx"&gt;You can’t trust the finalizer to ever execute&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/28/guaranteed-finalization-order-is-not.aspx"&gt;Finalization order is not guaranteed&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/28/finalizer-vs-application-a-race-condition-from-hell.aspx"&gt;You can create subtle race conditions by using objects that are simultaneously finalized&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/04/08/next-generation-production-debugging-demo-2-and-demo-3.aspx"&gt;You can end up with a memory leak if objects are created faster than the finalizer thread can run their finalizers&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This time, we’ll see how to &lt;strong&gt;determine whether a particular object is in the finalization queue&lt;/strong&gt; (which means it hasn’t been scheduled for finalization yet) &lt;strong&gt;or in the f-reachable queue&lt;/strong&gt; (which means it’s waiting for the finalizer thread to run its finalizer).&lt;/p&gt;  &lt;p&gt;Let’s fire up our trusty WinDbg and SOS and look at some heap objects:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:003&amp;gt; !dumpheap -stat      &lt;br /&gt;...snipped…       &lt;br /&gt;000007ff00023b78&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1340&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 32160 MemoryLeak.Schedule       &lt;br /&gt;000007ff00023aa0&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1340&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 32160 MemoryLeak.Employee       &lt;br /&gt;000007fef5ff7b08&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 435&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 44400 System.String       &lt;br /&gt;000007fef5fe58f8&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 310&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 67120 System.Object[]       &lt;br /&gt;00000000005387f0&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 577&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2680608&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Free       &lt;br /&gt;000007fef5fffb48&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1345&amp;#160;&amp;#160;&amp;#160;&amp;#160; 13432600 System.Byte[]       &lt;br /&gt;Total 6231 objects&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Okay, what are these schedules, employees, and byte arrays running around?&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:003&amp;gt; .foreach (obj {!dumpheap -mt 000007fef5fffb48 -short}) {!gcroot obj; .echo -----}      &lt;br /&gt;…edited for clarity…       &lt;br /&gt;Finalizer queue:Root:000000002a021a8(MemoryLeak.Employee)-&amp;gt;       &lt;br /&gt;0000000002a021c0(MemoryLeak.Schedule)-&amp;gt;       &lt;br /&gt;0000000002a021d8(System.Byte[])       &lt;br /&gt;-----       &lt;br /&gt;Finalizer queue:Root:000000002a07058(MemoryLeak.Employee)-&amp;gt;       &lt;br /&gt;0000000002a07070(MemoryLeak.Schedule)-&amp;gt;       &lt;br /&gt;0000000002a07088(System.Byte[])       &lt;br /&gt;-----       &lt;br /&gt;Finalizer queue:Root:000000002a0bf08(MemoryLeak.Employee)-&amp;gt;       &lt;br /&gt;0000000002a0bf20(MemoryLeak.Schedule)-&amp;gt;       &lt;br /&gt;0000000002a0bf38(System.Byte[])       &lt;br /&gt;…many more of these snipped…&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now, are these Employee objects rooted at the finalization queue or the f-reachable queue? Unfortunately, &lt;em&gt;!gcroot&lt;/em&gt; does not tell. However, &lt;em&gt;!FinalizeQueue&lt;/em&gt; shows the queue statistics:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:003&amp;gt; !FinalizeQueue      &lt;br /&gt;SyncBlocks to be cleaned up: 0       &lt;br /&gt;MTA Interfaces to be released: 0       &lt;br /&gt;STA Interfaces to be released: 0       &lt;br /&gt;----------------------------------       &lt;br /&gt;generation 0 has 370 finalizable objects       &lt;br /&gt;&amp;#160; (0000000000d29030-&amp;gt;&lt;font color="#0000ff"&gt;&lt;strong&gt;0000000000d29bc0&lt;/strong&gt;&lt;/font&gt;)       &lt;br /&gt;generation 1 has 4 finalizable objects       &lt;br /&gt;&amp;#160; (0000000000d29010-&amp;gt;0000000000d29030)       &lt;br /&gt;generation 2 has 8 finalizable objects       &lt;br /&gt;&amp;#160; (&lt;font color="#ff0000"&gt;&lt;strong&gt;0000000000d28fd0&lt;/strong&gt;&lt;/font&gt;-&amp;gt;0000000000d29010)       &lt;br /&gt;Ready for finalization 571 objects       &lt;br /&gt;&amp;#160; (&lt;font style="background-color:#ffff00;"&gt;0000000000d29bc0&lt;/font&gt;-&amp;gt;&lt;font style="background-color:#ffff00;"&gt;0000000000d2ad98&lt;/font&gt;)       &lt;br /&gt;Statistics:       &lt;br /&gt;…snipped…&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Note the information on finalizable objects vs. objects that are ready for finalization. The former are in the finalization queue, the latter are in the f-reachable queue.&lt;/p&gt;  &lt;p&gt;But now suppose that you have an individual object and you want to determine whether it’s in the finalization queue or the f-reachable queue. All you need to do is check in which array it is contained by searching memory with the &lt;em&gt;s&lt;/em&gt; command:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;0:003&amp;gt; s -q &lt;font style="background-color:#ffff00;"&gt;0000000000d29bc0&lt;/font&gt; &lt;font style="background-color:#ffff00;"&gt;0000000000d2ad98&lt;/font&gt; 0000000002a0bf08       &lt;br /&gt;00000000`00d29da8&amp;#160; 00000000`02a0bf08 00000000`02a10db8       &lt;br /&gt;0:003&amp;gt; s -q &lt;font color="#ff0000"&gt;&lt;strong&gt;0000000000d28fd0&lt;/strong&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;strong&gt;0000000000d29bc0&lt;/strong&gt;&lt;/font&gt; 0000000002a0bf08&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Okay, so 0000000002a0bf08 is in the f-reachable queue, waiting for the finalizer thread.&lt;/p&gt;  &lt;hr /&gt;&lt;em&gt;I am posting short updates and links on Twitter as well as on this blog. You can follow me: &lt;/em&gt;&lt;a href="http://twitter.com/goldshtn"&gt;&lt;em&gt;@goldshtn&lt;/em&gt;&lt;/a&gt;   &lt;br /&gt;&lt;em&gt;This blog post was also cross-posted to &lt;/em&gt;&lt;a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=4533592"&gt;&lt;em&gt;CodeProject&lt;/em&gt;&lt;/a&gt;.   &lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1020008" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/sashag/~4/HHjSECwkzA8" height="1" width="1"/&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.microsoft.co.il/blogs/sasha/archive/tags/.NETInternals/default.aspx">.NETInternals</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/sasha/archive/2012/02/25/finalization-queue-or-f-reachable-queue-find-out-with-sos.aspx</feedburner:origLink></item></channel></rss>

