CLR VS JIT [英] CLR vs JIT

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

问题描述

什么是JIT编译器和CLR之间的区别?如果您编译code到IL和CLR将运行code,那么什么是JIT在做什么?是如何JIT编译通过增加仿制药的CLR改变?

What is the difference between the JIT compiler and CLR? If you compile your code to il and CLR runs that code then what is the JIT doing? How has JIT compilation changed with the addition of generics to the CLR?

推荐答案

的JIT是CLR的一个方面。

The JIT is one aspect of the CLR.

具体来说它负责改变由原始语言的编译器(CSC.EXE用于Microsoft C#例如)制作成机器code原产于当前处理器(和架构CIL / MSIL(以下称为IL)的一部分它暴露了当前进程,例如32位/ 64位)。如果有问题的程序集ngen'd那么JIT的过程是完全没有必要和CLR将执行此code就好离不开它了。

Specifically it is the part responsible for changing CIL/MSIL (hereafter called IL) produced by the original language's compiler (csc.exe for Microsoft c# for example) into machine code native to the current processor (and architecture that it exposes in the current process, for example 32/64bit). If the assembly in question was ngen'd then the the JIT process is completely unnecessary and the CLR will run this code just fine without it.

在使用方法,该方法还没有从中间再presentation转换它是JIT的责任转换。

确切的的JIT的会踢是具体执行,并随时可能更改。然而,CLR设计任务的JIT发生的的相关code执行,JVM的对比,而一个单独的线程创建可以自由地跨preT的code一会儿一台机器code再presentation。

在正常CLR使用<一个href=\"http://$c$cidol.com/csharp/net-framework/Inside-the-CLR/Just-In-Time-%28JIT%29-Compilation/\">$p$p-JIT存根方法凡方法只因为它们是使用JIT编译。这包括具有初始本机方法存根是指示JIT编译方法,然后修改原有的呼叫跳过最初的存根的间接。目前的精简版,而不是在编译时加载一个类型的所有方法。

Before a method is used which has not yet been converted from the intermediate representation it is the JIT's responsibility to convert it.
Exactly when the JIT will kick in is implementation specific, and subject to change. However the CLR design mandates that the JIT happens before the relevant code executes, JVM's in contrast would be free to interpret the code for a while while a separate thread creates a machine code representation.
The 'normal' CLR uses a pre-JIT stub approach where by methods are JIT compiled only as they are used. This involves having the initial native method stub be an indirection to instruct the JIT to compile the method then modify the original call to skip past the initial stub. The current compact edition instead compiles all methods on a type when it is loaded.

要解决另外泛型的。

这是在语义方面的IL规范和JIT的最后一个重大改变,而不是它的内部实现细节。

This was the last major change to the IL specification and JIT in terms of its semantics as opposed to its internal implementation details.

若干新的IL指令,并提供插装类型和成员更多的元数据的选项。
在IL级别添加约束也是如此。

Several new IL instructions were added, and more meta data options were provided for instrumenting types and members. Constraints were added at the IL level as well.

当JIT编译它(通过包含类或隐或显)具有通用参数可能设置为使用的每种类型不同的code路径(机code指令)的方法。在实践中,JIT用于所有引用类型共享的实现,因为变量这些都会表现出相同的语义,并占据相同的空间(IntPtr.Size)。

When the JIT compiles a method which has generic arguments (either explicitly or implicitly through the containing class) it may set up different code paths (machine code instructions) for each type used. In practice the JIT uses a shared implementation for all reference types since variables for these will exhibit the same semantics and occupy the same space (IntPtr.Size).

每个值类型将得到它产生的特定code,处理堆栈上的变量的减少/增加的大小/堆是其中的主要原因。还通过发射约束运code方法调用许多调用非引用类型之前,不需要框中的值来调用方法(这种优化在非一般的情况下使用为好)。这也使得默认的&LT; T&GT; 行为进行正确处理,并进行比较,以空被剥离出来,因为没有OPS(总是假)当一个非空值类型是用了。

Each value type will get specific code generated for it, dealing with the reduced / increased size of the variables on the stack/heap is a major reason for this. Also by emitting the constrained opcode before method calls many invocations on non reference types need not box the value to call the method (this optimization is used in non generic cases as well). This also allows the default<T> behaviour to be correctly handled and for comparisons to null to be stripped out as no ops (always false) when a non Nullable value type is used.

如果试图在运行时做出通过反射,那么该类型的参数将运行时进行验证,以创建一个通用类型的实例,以确保他们传递任何限制。这不会直接影响到JIT,除非这是该类型的系统中使用(虽然不太可能)。

If an attempt is made at runtime to create an instance of a generic type via reflection then the type parameters will be validated by the runtime to ensure they pass any constraints. This does not directly affect the JIT unless this is used within the type system (unlikely though possible).

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

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