每次 .NET 应用程序运行时都会发生抖动吗? [英] Does jitting happen every time a .NET application runs?

查看:36
本文介绍了每次 .NET 应用程序运行时都会发生抖动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我安装 .NET 应用程序时,我知道它会被抖动.我的问题是每次我运行这个应用程序时都会发生这种抖动还是只在第一次发生?如果只是第一次发生,我在哪里可以找到这个应用程序的 jitted 版本?

When I install a .NET application, I understand that it will get jitted. My question is does this jitting happen everytime I will run this application or does it happen only the first time? If it happen only first time, where can I find jitted version of this application?

推荐答案

根据需要,程序集是零碎的.您的问题似乎暗示整个应用程序是立即编译的.这不是发生的事情.在任何特定时刻被抖动的部分都在内存中.

The assemblies are jitted piecemeal, as needed. Your question seems to imply that the whole application is jit compiled at once. That's not what happens. The parts that have been jitted at any particular moment in time are in memory.

JIT 编译考虑到某些代码可能永远不会在执行过程中被调用.而不是使用时间和记忆来将可移植可执行 (PE) 文件中的所有 MSIL 转换为本机代码,它在执行期间根据需要转换 MSIL 并存储生成的本机代码在内存中,以便它可以访问该过程上下文中的后续调用.加载器创建并在加载类型时将存根附加到类型中的每个方法并初始化.当一个方法第一次被调用时,存根将控制权传递给 JIT 编译器,后者会为此转换 MSIL方法转换为本机代码并修改存根以直接指向生成的本机代码.对 JIT 编译方法的后续调用因此直接进入本机代码.

JIT compilation takes into account the fact that some code might never get called during execution. Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as needed during execution and stores the resulting native code in memory so that it is accessible for subsequent calls in the context of that process. The loader creates and attaches a stub to each method in a type when the type is loaded and initialized. When a method is called for the first time, the stub passes control to the JIT compiler, which converts the MSIL for that method into native code and modifies the stub to point directly to the generated native code. Subsequent calls to the JIT-compiled method therefore proceed directly to the native code.

将 MSIL 编译为本机代码

它不会改变您问题的答案,但是存在一些差异在 .NET 4.5 中 JIT 编译是如何发生的.在多核处理器上,一个线程将负责在实际调用方法之前编译它们.

It doesn't change the answer to your question, but there are some differences in how the JIT compilation happens with .NET 4.5. On multi-core processors, a thread will be tasked to compile methods before they are actually called.

这篇关于每次 .NET 应用程序运行时都会发生抖动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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