Method Invocation and Type

Based on the discussion of JIT compilation and invocation, it is apparent that type is involved in method invocation. Specifically, the CLR uses the method table for a type to locate the address of the target method. Consider the following simple type definition:

public class Bob {
  public void f() { }
  static public void UseBob(int n, Bob b) {
    b.f();
  }
}

Ignoring method prolog and epilog, the JIT compiler would generate the following IA-32 native code for the UseBob method:

mov ecx, esi
call dword ptr ds:[352108h]

The first instruction moves the target object reference into the ecx register. This is because the JIT compiler typically uses the __fastcall stack discipline, and that causes the first two parameters to ...

Get Essential .NET, Volume 1: The Common Language Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.