MethodDesc方法描叙符

在方法表中包含了虚方法表,里面包含了一些指向隐藏在类型方法背后的代码的指针。既然虚方法表中包含了指向代码的指针,那么这些方法本身如何自行描叙?这个问题的答案就在与方法描叙符。在方法描叙符中包含了关于方法的详细信息,例如方法的文本表示,他所在的模块,以及实现方法的代码的地址。

要找到指定方法的方法描叙符,可以使用扩展命令dumpmt,同时使用开关-md.例如,如果在调试器下运行ConsoleApplication1.exe,

并且将局部变量myObject的方法表转存出来(dump),那么可以看到以下内容:

!dumpmt -md 00a138cc
EEClass:      00a114bc
Module:       00a12e9c
Name:         ConsoleApplication1.MyObject
mdToken:      451c819402000003
File:         D:\xgc\0402\Solution1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
BaseSize:        0xc
ComponentSize:   0x0
Slots in VTable: 6
Number of IFaces in IFaceMap: 0
--------------------------------------
MethodDesc Table
   Entry MethodDesc      JIT Name
79aaa7e0   79884934   PreJIT System.Object.ToString()
79aae2e0   7988493c   PreJIT System.Object.Equals(System.Object)
79aae1f0   7988495c   PreJIT System.Object.GetHashCode()
79b31600   79884970   PreJIT System.Object.Finalize()
00a1c038   00a138a0      JIT ConsoleApplication1.MyObject..ctor(Int32)
00a1c040   00a138b0     NONE ConsoleApplication1.MyObject.ProcessingItem(Feedback)

在输出信息的“MethodDesc Table”部分中列出了MyObject类型的所有方法描述符。在Entity列中包含的是该方法的代码被加载到内存中的位置,而在MethodDesc列给出了方法描叙符的地址。在JIT 列给出的是代码地址的状态,可以是以下值:

PreJIT表示位于Entity地址的代码被JIT预编译了。

JIT表示这段代码已经被JIT编译过了。

NONE表示这段代码还没有被JIT编译过。

最后,在Name列给出了方法名的文本表示。要进一步获得指定方法的信息,我们可以将MethodDesc列中的地址传递给扩展命令dumpmd,如下所示:

!dumpmd 00a138b0
Method Name:  ConsoleApplication1.MyObject.ProcessingItem(Feedback)
Class:        00a114bc
MethodTable:  00a138cc
mdToken:      465a813c06000005
Module:       00a12e9c
IsJitted:     no
CodeAddr:     ffffffff
Transparency: Critical

在输出信息中,最需要注意的部分是IsJitted和m_CodeOrIL这两个域,他们同样告诉我们方法的状态(就JIT编译过程而言)。

如果IsJitted设置为“yes”,那么就意味着这个方法已经被JIT编译了,并且在地址m_CodeOrIL中包含了实际代码。如果IsJitted设置为“no”,那么m_CodeOrIL域就被设置为ffffffff

!dumpmd 00a138a0
Method Name:  ConsoleApplication1.MyObject..ctor(Int32)
Class:        00a114bc
MethodTable:  00a138cc
mdToken:      451c813c06000004
Module:       00a12e9c
IsJitted:     yes
CodeAddr:     031b0120
Transparency: Critical

 

 

!dumpvc 79b9a9ac 009920e4  //009920e4=009920D8+c(16进制相加)
Name:        System.IntPtr
MethodTable: 79b9a9ac
EEClass:     798d57e0
Size:        12(0xc) bytes
File:        C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
79b5a21c  40004a9        0                  PTR  0 instance 8b0c2444 m_value
79b9a9ac  40004aa      b4c        System.IntPtr  1   shared   static Zero
    >> Domain:Value  0015db70:NotInit  <<

posted @ 2012-04-02 18:11  szjdw  阅读(911)  评论(0编辑  收藏  举报