.NET CLR方法表结构 [英] .net clr method table structure

查看:344
本文介绍了.NET CLR方法表结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在读一本书名为Pro的.NET性能。它的一个章节包含引用类型内部结构的详细信息。方法表是引用类型的布局结构的内部的领域之一。它是在这本书的方法表包含有关类的所有方法的信息说。我试图检查这个理论有一个小程序

I'm currently reading book titled Pro .NET Performance. One of its chapters contains detailed information about reference types internal structure. Method table is one of the internal fields of reference type layout structure. It is said in this book that method table consists of information about ALL methods of a class. I'm trying to check this theory with a little program

class MyClass
{
    public void M()
    {
    }
}

static void Main(string[] args)
{
     MyClass m = new MyClass();
     m.M();
     Console.ReadLine();
}  

乙:我的WinDbg的会议看起来像我启动该程序使用WinDbg $ B $以下

I start this program with WinDbg My WinDbg session looks like the following

!clrstack -a
ConsoleApp.Program.Main(System.String[]) [c:\visual studio 2012\Projects\Algorithms\ConsoleApp\Program.cs @ 36]
    PARAMETERS:
        args (0x00bff274) = 0x02ba2fbc
    LOCALS:
        0x00bff270 = 0x02ba2fd8

0x02ba2fd8 - 是MyClass的实例,$ b $乙我接下来做的就是尽量转储MyClass的实例的地址

0x02ba2fd8 - is the address of MyClass instance What I do next is try to dump MyClass instance

!do 0x02ba2fd8

Name:        ConsoleApp.MyClass
MethodTable: 00f84d74
EEClass:     00f81840
Size:        12(0xc) bytes
File:        C:\visual studio 2012\Projects\Algorithms\ConsoleApp\bin\Debug\ConsoleApp.exe
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
601a4544  4000001        4         System.Int32  1 instance       10 Z

下一步是转储方法表(其地址为00f84d74)

Next step is to dump method table (its address is 00f84d74)

!dumpmt -md 00f84d74

EEClass:         00f81840
Module:          00f83fbc
Name:            ConsoleApp.MyClass
mdToken:         02000002
File:            C:\visual studio 2012\Projects\Algorithms\ConsoleApp\bin\Debug\ConsoleApp.exe
BaseSize:        0xc
ComponentSize:   0x0
Slots in VTable: 6
Number of IFaces in IFaceMap: 0
--------------------------------------
MethodDesc Table
   Entry MethodDe    JIT Name
6005a2c8 5fcf8354 PreJIT System.Object.ToString()
60065600 5fcf835c PreJIT System.Object.Equals(System.Object)
600319b0 5fcf837c PreJIT System.Object.GetHashCode()
600316e8 5fcf8390 PreJIT System.Object.Finalize()
012604c0 00f84d6c    JIT ConsoleApp.MyClass..ctor()
012604f8 00f84d60    JIT ConsoleApp.MyClass.M()

这!dumpmt命令的输出显示方法表包含M()方法条目。但是,当我试着在地址00f84d74

The output from !dumpmt command shows that method table contains entry for M() method. But when I try to dump memory at address 00f84d74

dd  00f84d74

00f84d74  00000200 0000000c 00024188 00000004
00f84d84  601a299c 00f83fbc 00f84db0 00f81840
00f84d94  012604c0 00000000 00f84da0 6005a2c8
00f84da4  60065600 600319b0 600316e8 00000080
00f84db4  00000000 03ba3500 00000000 03ba3504
00f84dc4  00000000 00000000 00000000 00000000
00f84dd4  00000000 00000000 00000000 00000000
00f84de4  00000000 00000000 00000000 00000000

我找不到地址的任何引用M()方法(012604f8)

I can't find any references to address of M() method (012604f8)

所以,问题是方法表是否包含对非虚方法的引用?他们在哪里存放?

So the question is whether method table contains references to non-virtual methods? Where are they stored?

推荐答案

感谢我的同事们谁提供一些线索,以我的问题之一。事实证明,方法指针位于相对于方法表的指针负偏移

Thanks to one of my colleagues who shed some light to my question. It turns out that method pointers are located at negative offsets relative to method table pointer

这篇关于.NET CLR方法表结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆