究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类 [英] Where exactly is SomeDelegate.Invoke implemented and how is it "wired" to the delegate classes

查看:138
本文介绍了究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里完全相同(CLR源文件)可以找到实际执行 SomeDelegate.Invoke 方法?

Where exactly (CLR source file) can in find the actual implementation of the SomeDelegate.Invoke method?

如何.NET运行时知道调用 SomeDelegate.Invoke 应导致调用该实现?请记住,在 SomeDelegate.Invoke 方法可以有任意数量的参数。

How does the .Net runtime knows that calling SomeDelegate.Invoke should result in calling that implementation? Keep in mind that the SomeDelegate.Invoke method can have any number of arguments.

推荐答案

所以,这里是巫术是如何工作的(从我发现掠入在源一个小时):

So, here is how the voodoo magic works (from what I found by glancing over the sources for an hour):


  1. 在某些时候,对于 SomeDelegate 类中的方法表是填充的,对调用方法运行时失蹄。

  2. PreStubWorker vm\prestub.cpp )被调用,它调用 DoPrestub ,要求 MakeStubWorker

  3. MakeStubWorker 认为,该方法是运行时实现的;(?为什么要问的方法表)( pMD-> IsEEImpl ),声称该方法表如下如委托和电话 COMDelegate :: GetInvokeMethodStub vm\comdelegate.cp p)来创建存根。

  4. COMDelegate :: GetInvokeMethodStub 办法( vm\comdelegate.cpp )电话 COMDelegate :: TheDelegateInvokeStub 它调用 EmitDelegateInvoke EmitMulticastInvoke 方法。

  5. StubLinkerCPU :: EmitDelegateInvoke StubLinkerCPU :: EmitMulticastInvoke 方法在 vm\i386\stublinkerx86.cpp 文件中实现(86)和 vm\ppc\cgenppc.cpp (用于PowerPC)。这些方法是很短,放出的调用方法的具体装配/ CPU特定的实现。

  6. 来的方法实现的参考放置到 SomeDelegate 的方法表。

  1. At some time, the method table for the SomeDelegate class is populated and the runtime stumbles upon the Invoke method.
  2. The PreStubWorker (vm\prestub.cpp) is called, which calls DoPrestub, which calls MakeStubWorker
  3. The MakeStubWorker sees that the method is runtime-implemented (pMD->IsEEImpl), asserts that the method table (why ask the method table?) looks like a delegate and calls COMDelegate::GetInvokeMethodStub (vm\comdelegate.cpp) to create the stub.
  4. The COMDelegate::GetInvokeMethodStub method (vm\comdelegate.cpp) calls COMDelegate::TheDelegateInvokeStub which calls the EmitDelegateInvoke and EmitMulticastInvoke methods.
  5. The StubLinkerCPU::EmitDelegateInvoke and StubLinkerCPU::EmitMulticastInvoke methods are implemented in the vm\i386\stublinkerx86.cpp file (for x86) and vm\ppc\cgenppc.cpp (for PowerPC). These methods are quite short and emit the concrete assembly/CPU-specific implementations of the Invoke methods.
  6. The reference to the method implementation is put to the SomeDelegate's method table.

这篇关于究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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