I'm using C#.NET for a web application. I've read that JIT compilation happens at run-time, which means(correct me if I'm wrong) that the compilation will happen when the request hits IIS.
Another compilation happens using csc.exe
during the build phase of the solution using MSBuild
to convert high-level code to CIL.
If there was no JIT and we wanted to use AOT, where would AOT fit in all this?
My question is at what point in the entire phase from building code to the first request, AOT compilation happens? (The platform/framework does not matter)
After a lot of Googling and research, I found out that my basic understanding of the compilers was wrong.
A compiler is a program that converts a program in language X to a program in language Y. The language Y can be anything(native machine code, intermediate code/bytecode, some other language Z, or the same language itself).
A compiler is not necessarily a program that converts a program in language X to m-code.
For example, a compilation happens from high-level C# code to CIL using a compiler csc.exe. (how could I miss that? duh!)
Also, the time in Ahead-Of-Time and Just-In-Time compilers refers to the runtime. So, in Ahead-Of-Time compiler, the compilation happens before the program is run, usually added as a build step. While in Just-In-Time compiler, the compilation keeps happening while the program is being run.
To put it in C#.NET perspective and to answer my question, the CIL is generated by MSBuild using csc.exe without any consideration whether the CLR uses JIT or AOT compiler. It is at the time of running the program that JIT or AOT compiler comes into action. AOT compiler compiles entire assemblies(in CIL, or language X) into native machine code(language Y) before the program is run. JIT compiler compiles individual methods and classes(in CIL, or language X) into native machine code(language Y) when the methods are called.
CLR provides JIT compiler by default but it also supports AOT compilation using Native Image Generator(Ngen.exe).