Does JIT convert the binary code of IL into binary

2019-08-07 05:17发布

This is regarding .NET.

  1. Code (high-level: c#,vb.net - human understandable) is compiled in VS and dll/exe is generated This is called IL (this is also more or less human understandable).

  2. When we run this dll/exe for the first time on the machine, the CLR/JIT converts the IL to machine code (binary format: 0's and 1's - this is not human understandable). This machine code is saved in memory so next time the conversion is not required unless the system is restarted.

  3. ILASM.exe can be used to convert the dll/exe (IL code) into machine code and ILDASM.exe is other opposite.

If the compiler generates exe/dll (IL) which is in binary format, then, what is purpose of the JIT? Since code is already in binary format... Does it mean that the binary code of IL is converted into binary machine code by JIT?

Please correct me on above statements.

标签: .net clr
1条回答
混吃等死
2楼-- · 2019-08-07 06:07

Code (high-level: c#,vb.net - human understandable) is compiled in VS and dll/exe is generated This is called IL (this is also more or less human understandable).

You need to differentiate between the binary form of IL, and the textual form of IL - if you open up a compiled EXE or DLL file, you won't see text, so that isn't human readable... but the textual representation is a sort of "object oriented assembly language". The binary representation is "machine code for a CLI" - but that's not the native machine code of the computer you're running on.

This machine code is saved in memory so next time the conversion is not required.

No, not as far as I'm aware - it's only retained in the process, in most cases. So if you start another process, it will JIT the code again.

ILASM.exe can be used to convert the dll/exe (IL code) into machine code and ILDASM.exe is other opposite. Is this saved in memory also? What is file format?

No, that's not true. ILASM takes source IL (text) and assembles it into binary IL... it doesn't convert it into machine code. ILDASM does the reverse - it will convert a DLL or EXE into textual IL, that can be read.

When would one make use of tool like ILASM?

I sometimes use ILDASM to look at the IL for a particular compiled binary (although I usually use Reflector). I use ILASM more rarely - usually after using ILDASM to get the text IL, then I've tweaked it in some interesting way. You could look at my Unconstrained Melody project for an example of this, where I tweak the IL to represent generic constraints which can't be represented in C#.

查看更多
登录 后发表回答