C#编译JIT和.NET [英] C# JIT compiling and .NET

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

问题描述

我已经成为一个有点困惑的JIT编译器是如何工作的细节。我知道C#编译为IL。它时,它会在第一时间为JIT'd。这是否涉及到它得到翻译成母语code?是.NET运行时(如虚拟机?)与JIT'd code互动?我知道这是天真的,但我真的很困惑自己。我的IM pression一直是该组件是由.NET运行库PTED不跨$ P $,但我不明白的交互的细节。

I've become a bit confused about the details of how the JIT compiler works. I know that C# compiles down to IL. The first time it is run it is JIT'd. Does this involve it getting translated into native code? Is the .NET runtime (as a Virtual Machine?) interact with the JIT'd code? I know this is naive, but I've really confused myself. My impression has always been that the assemblies are not interpreted by the .NET Runtime but I don't understand the details of the interaction.

推荐答案

是的,JIT'ing IL code涉及翻译成IL为本机指令。

Yes, JIT'ing IL code involves translating the IL into native machine instructions.

是,.NET运行时与JIT'ed本机code相互作用,在运行时拥有了本机code占用的内存块的意义上说,运行时调用到本机code等。

Yes, the .NET runtime interacts with the JIT'ed native machine code, in the sense that the runtime owns the memory blocks occupied by the native machine code, the runtime calls into the native machine code, etc.

您是正确的,.NET运行时不跨preT的IL code在你的程序集。

You are correct that the .NET runtime does not interpret the IL code in your assemblies.

会发生什么事,当执行到函数或code块(例如,如果一个块的else子句),目前尚未被JIT编译成本机code时,JIT'r被调用来编译IL的该块到本机code。如果这样做了,程序执行进入新鲜发出机器code来执行它的程序逻辑。如果在执行了本机code执行到达一个函数调用到尚未被编译成机器code函数,因此JIT'r调用编译的的功能只是及时。等等。

What happens is when execution reaches a function or code block (like, an else clause of an if block) that has not yet been JIT compiled into native machine code, the JIT'r is invoked to compile that block of IL into native machine code. When that's done, program execution enters the freshly emitted machine code to execute it's program logic. If while executing that native machine code execution reaches a function call to a function that has not yet been compiled to machine code, the JIT'r is invoked to compile that function "just in time". And so on.

该JIT'r不一定编译函数体的所有逻辑成机器code一次。如果函数有if语句,对语句块的if或else子句不得JIT编译执行之前,实际上通过该块。那些没有执行code路径保持在IL形态直到他们做执行。

The JIT'r doesn't necessarily compile all the logic of a function body into machine code at once. If the function has if statements, the statement blocks of the if or else clauses may not be JIT compiled until execution actually passes through that block. Code paths that have not executed remain in IL form until they do execute.

的编译的本机机器code为保存在内存中,以便它可以被再次使用,下一次code的那部分执行。你调用一个函数的第二次会跑的比你第一次调用它,因为没有JIT步骤是必须的第二次,速度更快。

The compiled native machine code is kept in memory so that it can be used again the next time that section of code executes. The second time you call a function it will run faster than the first time you call it because no JIT step is necessary the second time around.

在桌面.NET中,本机code保存在内存在AppDomain的生命周期。在.NET CF中,本机code可如果应用程序在内存不足的运行扔掉。它将再次JIT从原来的IL code,下一次执行通过了code编译。

In desktop .NET, the native machine code is kept in memory for the lifetime of the appdomain. In .NET CF, the native machine code may be thrown away if the application is running low on memory. It will be JIT compiled again from the original IL code the next time execution passes through that code.

这篇关于C#编译JIT和.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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