CLR Via C# Note--The CLR's execution mode

  • Managed module: Standard 32 or 64 bit Windows portable excutable  PE32 or PE32+ file. 

Compilers compile source code into managed module.

Content: 

PE32/PE32+ header: The Windows version; Type of files(GUI, DLL...); Timestamp of building

                

CLR Header: version of CLR; some flags; MethodDef metadata token(main method); location/size of metadata; resources; strong name; 

Metadata: table1: types and memebers in source code

table 2: types and memebers in references

IL code

metadata and IL code are in the same place. Metadata is created by IL code.

  • Assembly: a logical grouping of one or more modules or resource files; the smallest unit of reuse.

Compilers turn managed module into an assembly.

C# compiler emits a managed module that contains a manifest which indicates that the assembly consists of just the one file. So for projects that have only 


  • Difference:

CLR only runs assembly

Assembly could have more than one managed modules


Application Run:

1. Windows examine the PE32/PE32+ header

2. Create a 32 or 64 process

3. Load x86, x64 or ARM version of MSCorEE.dll into the process space

4. The main thread of the process called a method of MSCorEE.dll to initialize the CLR, load the application file and call its entry Main method.

Method executes

1. Before the Main method executes, CLR detects all the types that are referenced by Main

2. CLR allocates an internal data structure to maintain access to all the referenced types

   This data structure contains an entry to each methods that defined by the referenced type. 

   Each entry holds the address where the method's implementation can be found

   When initialize this structure, CLR sets each entry to an internal, undocumented function(JITCompiler) contained inside the CLR itself.

3. When Main makes its first call, JITCompiler function is called.

4. JITCompiler function verifies and compiles a method's IL code into native CPU instructions (JIT: Just In Time)

    JITCompiler function knows the called method and its type, and then JITCompiler searches the defining assembly's metadata for the IL code of the called method.

   The native CPU instructions are saved in a dynamically allocated block of memory.

5. JITCompiler function goes back to the entry for the called method and replaces the reference with the address of the dynamically allocated memory.

6. JITCompiler jumps to the code in the memory block.

7. When this code returns, it returns to the code in Main and continues.

8. When the same method is called the second time, the call goes directly to the memory block and skips the JITCompiler function.

performance hit only happens in the first call

JIT optimizes the code



IL is stack-based, typeless.

While compiling IL code into native CPU instructions, CLR performs a process named Verification which examines the IL code and makes sure everything is safe.

The managed module's metadata includes all of the methods and types information used by the verification process.

Multiple managed applications can be run in a single Windows virtual address space.


NGen.exe: compile IL code into native CPU structions

It can be used when an application is installed on a user's machine.


Managed Profile Guided Optimization tool (MPGO.exe): This tool analyzes the execution of your application to see what it needs at startup.

FCL: Framework Class Library

CTS: Common Type System

CLS: Common Language Specification--interlanguage operation


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值