Hi All,First .NET code compiles to MSIL and then JIT convert it to machine dependent code. Can any one tell me what all benifits get because of the 2 step compilation.Thanks
There are a few reasons. First and foremost is probably to make it cross platform. If C# or other .NET languages compiled directly to native code, they would have to be recompiled for each platform they run on. With a VM, all code can be kept in an intermediate format, and you only need write a VM implementation for each platform.
Also, by having a language-agnostic intermediary language, you can have many high level languages (C#, VB.NET, Python etc) all referencing assemblies written in other languages. Since they all compile into the same thing, they can work seamlessly with each other.
There are also performance benefits. The JIT compiler can do aggressive optimizations specifically for the machine the code is running on at that time. I do not know how much optimization the .NET JIT compiler does in this sense, but there are very large theoretical benefits that could be had.
An executable is not bound to the platform. For instance XNA targets both PPC (Xbox360) and x86 processors. Some programs will run on Mono on linux or OSX.
It allows you to better optimize for the target machine or replace missing functions:
- For instance OSX >= 10.5 compiles in missing GPU instructions at runtime with OpenCL.
- Lets say you are working on a CPU without floating point support, then you could emulate it with the JIT without needing a complete code rewrite.
- At some point in the future it could be possible to offload processing into the GPU or other targets dynamically (I suspect functional languages are somewhat better suited for this).
First Conversion from High Level Language and then to Machine Level, this is how .Net platform is designed. The first layer take care of High Level language to MSIL and second level can concentrate on hitch & glitch of platform to convert from MSIL to machine level code. It mainly supports Language interoperability and may be in near future it will also provide Cross Platform support when Project like Mono will gain more ground.