title: How to tell if a program uses dynamic dispatch by looking at the assembly
body: <p>I read a post on Reddit on <a href="http://www.reddit.com/r/programming/comments/rr2dj/herb_stutter_jit_will_never_be_as_fast_as_native/" rel="nofollow">Herb Stutter: JIT will never be as fast as native</a> and somebody made a comment that it was incredible somebody called Herb "misinformed" that C# uses virtual methods instead of non-virtual (you can read the article <a href="http://herbsutter.com/2012/04/02/reader-qa-when-will-better-jits-save-managed-code/" rel="nofollow">here</a>). It got me to thinking and I made a quick little program and noticed that C# does in fact generate virtual methods for CIL (callvirt vs call). But then I was told it wasn't that easy and that the JIT may inline the code instead of using vtables and dynamic dispatch. I fired up my debugger and tried to see. Here is my simple program:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Test t = new Test();
              t.TestIt();
              t.TestOut();
  
          }
      }
  
      class Test
      {
          public Test() { }
          public void TestIt()
          {
              Console.WriteLine("TESTIT");
          }
          public void TestOut()
          {
              Console.WriteLine("TESTOUT");
          }
      }
  }
  </code></pre>
  
  <p>And then here is the assembly:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Test t = new Test();
  00000000  push        ebp  
  00000001  mov         ebp,esp 
  00000003  push        esi  
  00000004  mov         ecx,439E68h 
  00000009  call        FFCE0AD4 
  0000000e  mov         esi,eax 
              t.TestIt();
  00000010  call        704BBEB8 // Call to Console.WriteLine()
  00000015  mov         ecx,eax 
  00000017  mov         edx,dword ptr ds:[02A02088h] 
  0000001d  mov         eax,dword ptr [ecx] 
  0000001f  call        dword ptr [eax+000000D8h] 
              t.TestOut();
  00000025  call        704BBEB8  // Call to Console.WriteLine()
  0000002a  mov         ecx,eax 
  0000002c  mov         edx,dword ptr ds:[02A0208Ch] 
  00000032  mov         eax,dword ptr [ecx] 
  00000034  call        dword ptr [eax+000000D8h] 
  0000003a  pop         esi  
  
      }
  0000003b  pop         ebp  
  0000003c  ret     
  </code></pre>
  
  <p>My question is this: by looking at the assembly how does one tell if it is using dynamic dispatch? My hunch is that it is because of these 4 instructions which resemble what I remember from my programming language class:</p>
  
  <pre><code>0000002a  mov         ecx,eax 
  0000002c  mov         edx,dword ptr ds:[02A0208Ch] 
  00000032  mov         eax,dword ptr [ecx] 
  00000034  call        dword ptr [eax+000000D8h]
  </code></pre>
  
  <p>Am I correct in assuming this is dynamic dispatch? If so, are there any other tell-tale signs? If I'm wrong, how would I be able to tell if it is dynamic dispatch or not?</p>