Code execution process in .Net
Today i am going to cover a very basic topic/concept that is core concept of .Net.
How code execution process has taken place in Asp.net framework? Basically in .Net framework
code execution process is divided into two steps/categories -
Above image show the code execution process into two phase.
Now we look further to understand the key points of compiler time and run time execution.
How code execution process has taken place in Asp.net framework? Basically in .Net framework
code execution process is divided into two steps/categories -
1. Compiler time process.
2. Runtime process.
Above image show the code execution process into two phase.
Now we look further to understand the key points of compiler time and run time execution.
1. Compiler time process
- .Net framework has one or more language compliers, such as Visual Basic, C#, Visual C++, JScript, or one of many third-party compilers such as an Eiffel, Perl, or COBOL compiler.
- Any one of the compilers translates your source code into Microsoft Intermediate Language (MSIL) code.
- For example, if you are using the C# programming language to develop an application, when you compile the application, the C# language compiler will convert your source code into Microsoft Intermediate Language (MSIL) code.
- In short, VB.NET, C# and other language compilers generate MSIL code. (In other words, compiling translates your source code into MSIL and generates the required metadata.)
- Currently "Microsoft Intermediate Language" (MSIL) code is also known as "Intermediate Language"(IL) Code or "Common Intermediate Language"(CIL) Code.
SOURCE CODE -----[.NET COMLIPER]------> BYTE CODE (MSIL + META DATA)
2. Runtime process.
- The Common Language Runtime (CLR) includes a JIT compiler for converting MSIL to native code.
- The JIT Compiler in CLR converts the MSIL code into native machine code that is then executed by the OS.
- During the runtime of a program the "Just in Time" (JIT) compiler of the Common Language Runtime (CLR) uses the Metadata and converts Microsoft Intermediate Language (MSIL) into native code.
BYTE CODE(MSIL + META DATA) -----> Just-In-Time (JIT) compiler------> NATIVE CODE
Key Notes to remember:
Whenever you compile a C# application or any application written in a CLS-compliant language, the application is compiled into MSIL. This MSIL is then further compiled into native CPU instructions when the application is executed for the first time by the CLR. (Actually, only the called functions are compiled the first time they are invoked.)
Whenever you compile a C# application or any application written in a CLS-compliant language, the application is compiled into MSIL. This MSIL is then further compiled into native CPU instructions when the application is executed for the first time by the CLR. (Actually, only the called functions are compiled the first time they are invoked.)
- We write a source code in C#.
- Then we compile it using the C# compiler (csc.exe) into an EXE.
- The C# compiler outputs the MSIL code and a manifest into a read-only part of the EXE that has a standard PE (Win32-portable executable) header.
- When the compiler creates the output, it also imports a function named "_CorExeMain" from the .NET runtime.
- When the application is executed, the operating system loads the PE, as well as any dependent dynamic-link libraries (DLLs), such as the one that exports the "_CorExeMain" function (mscoree.dll), just as it does with any valid PE.
- However, since the operating system obviously can't execute the MSIL code, the entry point is just a small stub that jumps to the "_CorExeMain" function in mscoree.dll.
- The "_CorExeMain" function starts the execution of the MSIL code that was placed in the PE.
- Since MSIL code cannot be executed directly, because it's not in a machine-executable format, the CLR compiles the MSIL using the Just-In-Time (JIT) compiler (or JITter) into native CPU instructions as it processes the MSIL. The JIT compiling occurs only as methods in the program are called. The compiled executable code is cached on the machine and is recompiled only if there's some change to the source code.
Code execution process in .Net
Reviewed by CodiBucket
on
10:15
Rating:
No comments: