In today's digital world, programming languages such as C#, VB employ a user-friendly syntax which is not interpreted by computers. Before a computer can execute the source code(i.e. user friendly syntax), special tools like compiler must rewrite it into machine language known as object or binary code. This compilation process can be compiled implicitly or explicitly.
Explicit Compilation:
Explicit compilation converts the higher level language to lower level language(binary code or object code) ahead of program execution.Every line of code is interpreted and executed such that machine hardware understands easily.
Implicit Compilation:
Implicit compilation follows a 2-step process. The first step is converting the source code(C#) to intermediate language(IL) by language specific compiler(C# Compiler). The second step is converting the IL to machine instructions. The main difference between explicit compilation is that only executed fragment of IL code are compiled into machine code, at runtime.For Example, .NET framework, which follows similar compilation process with the help of Just-In-Time(JIT) Compilation.
Just-In-Time Compilation:
The JIT compiler is part of Common Language Runtime. The CLR manages the execution of .NET applications. As depicted in below diagram, the source code is compiled to .exe or .dll by the language specific compiler. The JIT compiler processes the IL code to machine specific code for an environment. JIT compiler calls only those methods called at runtime. It also keeps track of any variable or parameter passed through methods which enforces type-safety in runtime environment.
There are 3 different types of JIT Compilation:
- Normal JIT Compilation: With Normal JIT compiler, methods are compiled when called at runtime, where as after execution these methods are stored in memory and no compilation is required next time for these methods. The next time the method is called at runtime, it is accessed directly from memory cache.
- Econo-JIT Compilation: With Econo-JIT Compiler, it compiles methods when called at runtime and removes them from memory after execution.
- Pre-JIT Compilation: With Pre-JIT Compiler, it compiles the entire assembly instead of used methods. For example, Ngen.exe (Native Image Generator).
The .NET JIT Compiler optimizes the most used IL code for faster performance and I/O Operations.
No comments:
Post a Comment