C# GetCallingAssembly()和GetExecutionGassembly()是否同样倾向于JIT内联?
有和。请注意,C# GetCallingAssembly()和GetExecutionGassembly()是否同样倾向于JIT内联?,c#,.net,reflection,jit,C#,.net,Reflection,Jit,有和。请注意,GetCallingAssembly()有一个备注提到,根据JIT内联行为的不同,可能一个方法内联(或未内联)到另一个方法,因此GetCallingAssembly()返回不同的结果 现在getExecutionGassembly()有什么不同?JIT内联技术上可以内联调用getExecutionGassembly()的代码,因此代码现在属于不同的程序集,这取决于是否发生了getExecutionGassembly()同样可以产生不同的结果 为什么getExecutionGasse
GetCallingAssembly()
有一个备注
提到,根据JIT内联行为的不同,可能一个方法内联(或未内联)到另一个方法,因此GetCallingAssembly()
返回不同的结果
现在getExecutionGassembly()
有什么不同?JIT内联技术上可以内联调用getExecutionGassembly()
的代码,因此代码现在属于不同的程序集,这取决于是否发生了getExecutionGassembly()
同样可以产生不同的结果
为什么
getExecutionGassembly()
description没有类似于GetCallingAssembly()的提到JIT初始化的注释
description有?由于相同的原因,getExecutionGassembly
方法不受JIT内联的影响。GetCurrentMethod也不受影响,因为它们是以类似的方式实现的
这两种方法都声明特殊枚举的局部变量StackCrawlMark
,并将其初始化为StackCrawlMark.LookForMyCaller
。此局部变量的副作用是防止调用getExecutionGassembly
或GetCurrentMethod
的方法内联,从而保证正确的结果
实验以及SSCLI20中与此枚举相关的注释支持了这一点:
// declaring a local var of this enum type and passing it by ref
// into a function that needs to do a stack crawl will both prevent inlining of
// the calle and pass an ESP point to stack crawl to
//
// Declaring these in EH clauses is illegal;
// they must declared in the main method body
GetCallingAssembly
易受影响的原因是,您正在查找调用方的调用方,而局部变量仅保证调用方未内联,这意味着祖父母方法可以内联,从而导致意外的结果。当然,两者都易受影响是一种可能性,评论应该同样适用于两者。这将是一个突破性的改变,所以我不得不说不。我仔细阅读了技术实现细节,只是为了支持这样一个事实,即调用getExecutionGassembly
的方法保证不会内联,这就是为什么警告没有出现在其文档中。