Like the Java Virtual Machine (JVM),. Net CLR is a virtual machine that interprets byte code.
The JVM interprets programs that contain java byte codes, and the .net CLR interprets programs that contain what Microsoft calls Intermediate Language (IL) instructions. There are differences between these byte codes, but virtual machines are similar and strive to provide similar functions.
Both of these versions of the virtual machine have the ability to compile their input bytecode into the machine language of the computer on which they are running. This is called "Just In Time Compilation (JIT)," and the resulting output code is called the "JIT Code." Because the JIT code contains sequences of instructions in machine language of the computer CPU, this code is sometimes called the "native" code.
However, the JIT code is qualitatively and quantitatively different from the code based, as explained below. For this reason, in this article, JIT code is nothing more than a built-in implementation of a virtual machine when a specific bytecode program is run.
One of the possibilities that both of these virtual machines (VMs) are striving to provide is security in the form of preventing some dangerous programming errors. For example, the title of this web forum, stackoverflow, is inspired by one of these dangerous bugs that is possible in native code.
To ensure security and runtime security, virtual machines implement type safety at the Virtual Machine level. VM memory assignments are needed to store the type of data that is stored in this memory location. For example, if an integer is pushed onto the stack, it is not possible to pop a double from the stack. C-style "unions" are prohibited. Pointers and direct memory access are prohibited.
We could not get the same benefits using an object-oriented language environment for developers, if the result is a native binary, such as an EXE file. In this case, we will not be able to distinguish between source binaries generated using the framework and EXE created by an attacker using sources other than the structure.
In the case of virtual machines, type security is applied at the "lowest level" to which the programmer is allowed access. (Neglecting for a moment that you can write managed native code, that is.) Therefore, no user will encounter an application that performs one of the dangerous operations that require direct access to memory cells and pointers.
In practice, CLR.NET implements a way to write its own code, which can be invoked by "managed" .net code. In this case, the burden lies with the author of his own code so as not to make pointer and memory errors.
Since both the JVM and the .net CLR perform JIT compilation, either the virtual machine actually creates binary code with source code from the supplied bytecode. This "JIT code" runs faster than the execution of the virtual machine interpreter, because even the machine language code generated by the JIT contains all the necessary VM security checks that the VM will execute. As a result, JIT output code is not as fast as native code, which usually does not contain numerous runtime checks. However, this lack of speed performance is being replaced by improved reliability, including safety; in particular, the use of uninitialized storage is prevented, destination type security is maintained, the range is checked (thus preventing buffer and heap overflows), the lifetime of objects is controlled by garbage collection, and dynamic allocation is safe by type. The environment that performs such runtime checks implements the specification of the virtual machine and is slightly larger than the implementation of the machine language of the virtual machine.