none
My custom class, Why method table only contain 4 methods? RRS feed

  • Question

  • using System;
    using System.Text;
    
    namespace C2
    { class TypeSample { TypeSample(int x, int y, int z) { coordinates.x = x; coordinates.y = y; coordinates.z = z; } private struct Coordinates { public int x; public int y; public int z; } private Coordinates coordinates; public void AddCoordinates() { int hashCode = GetHashCode(); lock (this) { Coordinates tempCoord; tempCoord.x = coordinates.x + 100; tempCoord.y = coordinates.y + 50; tempCoord.z = coordinates.z + 100; System.Console.WriteLine("x={0}, y={1}, z={2}", tempCoord.x, tempCoord.y, tempCoord.z); } } static void Main(string[] args) { TypeSample sample = new TypeSample(10,5,10); sample.AddCoordinates(); } } }

    I always get 4 methods information in method table.
    0:000> dd 009d308c
    009d308c  00000000 00000014 00040011 00000004
    NO main,  AddCoordinates and ctor
    Have no idea of it,  Any help will be appreciated greatly. Thank your help very much!

    See details below:

    1. Use windbg to open this PE
    2. .load sosex.dll
    3. !bpsc TypeSample.cs 41
    4. !bpsc TypeSample.cs 34
    5. g

    0:000> !loadby sos.dll mscorwks
    0:000> !clrstack -a
    OS Thread Id: 0x1594 (0)
    ESP       EIP    
    0012f454 00d200b2 C2.TypeSample.Main(System.String[])
        PARAMETERS:
            args = 0x013129c4
        LOCALS:
            0x0012f458 = 0x013129d4

    0012f688 79e71b4c [GCFrame: 0012f688]
    0:000> dd 0x013129d4
    013129d4  009d308c 0000000a 00000005 0000000a
    013129e4  00000000 00000000 00000000 00000000
    013129f4  00000000 00000000 00000000 00000000
    01312a04  00000000 00000000 00000000 00000000
    01312a14  00000000 00000000 00000000 00000000
    01312a24  00000000 00000000 00000000 00000000
    01312a34  00000000 00000000 00000000 00000000
    01312a44  00000000 00000000 00000000 00000000
    0:000> dd 009d308c
    009d308c  00000000 00000014 00040011 00000004
    009d309c  7933061c 009d2c5c 009d30c4 009d12a8
    009d30ac  00000000 00000000 79286aa0 79286ac0
    009d30bc  79286b30 792f7410 00000080 00000000
    009d30cc  00000000 00000000 00000000 00000000
    009d30dc  00000000 00000000 00000000 00000000
    009d30ec  00000000 00000000 00000000 00000000
    009d30fc  00000000 00000000 00000000 00000000

    Sunday, May 15, 2011 5:26 PM

Answers

  • The 0x0004 means virtual methods' count, not number of total methods, you can add a virtual method to your type and check the difference.

     

    Attached my test data:

     

    0:000> !dumpmt -md 002e3360

    EEClass: 002e1394

    Module: 002e2f2c

    Name: C2.TypeSample

    ...

    MethodDesc Table

       Entry MethodDesc      JIT Name

    047d6a90   0465493c   PreJIT System.Object.ToString()

    047d6ab0   04654944   PreJIT System.Object.Equals(System.Object)

    047d6b20   04654974   PreJIT System.Object.GetHashCode()

    048474c0   04654998   PreJIT System.Object.Finalize()

    005300e0   002e32d8      JIT C2.TypeSample..ctor(Int32, Int32, Int32)

    00530138   002e32e4      JIT C2.TypeSample.AddCoordinates()

    00530070   002e32f0      JIT C2.TypeSample.Main(System.String[])

     

    0:000> dt mscorwks!MethodTable 002e3360

       +0x000 m_wFlags         : 0

       +0x004 m_BaseSize       : 0x14

       +0x008 m_wFlags2        : 0x11

       +0x00a m_wNumVtableSlots : 4

       +0x00c m_wNumVirtuals   : 4

       +0x00e m_wNumInterfaces : 0

     

    0:000> dd 002e3360

    002e3360  00000000 00000014 00040011 00000004

    002e3370  04880704 002e2f2c 002e3398 002e1394

    002e3380  00000000 00000000 047d6a90 047d6ab0

    002e3390  047d6b20 048474c0 00000080 00000000

    002e33a0  00000000 00000000 00000000 00000000

    002e33b0  00000000 00000000 00000000 00000000

    002e33c0  00000000 00000000 00000000 00000000

    002e33d0  00000000 00000000 00000000 00000000

     


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by eryang Friday, May 27, 2011 6:37 AM
    Thursday, May 19, 2011 3:42 AM

All replies

  • The 0x0004 means virtual methods' count, not number of total methods, you can add a virtual method to your type and check the difference.

     

    Attached my test data:

     

    0:000> !dumpmt -md 002e3360

    EEClass: 002e1394

    Module: 002e2f2c

    Name: C2.TypeSample

    ...

    MethodDesc Table

       Entry MethodDesc      JIT Name

    047d6a90   0465493c   PreJIT System.Object.ToString()

    047d6ab0   04654944   PreJIT System.Object.Equals(System.Object)

    047d6b20   04654974   PreJIT System.Object.GetHashCode()

    048474c0   04654998   PreJIT System.Object.Finalize()

    005300e0   002e32d8      JIT C2.TypeSample..ctor(Int32, Int32, Int32)

    00530138   002e32e4      JIT C2.TypeSample.AddCoordinates()

    00530070   002e32f0      JIT C2.TypeSample.Main(System.String[])

     

    0:000> dt mscorwks!MethodTable 002e3360

       +0x000 m_wFlags         : 0

       +0x004 m_BaseSize       : 0x14

       +0x008 m_wFlags2        : 0x11

       +0x00a m_wNumVtableSlots : 4

       +0x00c m_wNumVirtuals   : 4

       +0x00e m_wNumInterfaces : 0

     

    0:000> dd 002e3360

    002e3360  00000000 00000014 00040011 00000004

    002e3370  04880704 002e2f2c 002e3398 002e1394

    002e3380  00000000 00000000 047d6a90 047d6ab0

    002e3390  047d6b20 048474c0 00000080 00000000

    002e33a0  00000000 00000000 00000000 00000000

    002e33b0  00000000 00000000 00000000 00000000

    002e33c0  00000000 00000000 00000000 00000000

    002e33d0  00000000 00000000 00000000 00000000

     


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by eryang Friday, May 27, 2011 6:37 AM
    Thursday, May 19, 2011 3:42 AM
  • We temporarily mark a reply since the thread idle for a long time, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 27, 2011 6:37 AM