Calling a method for the first time:
- Your program code calls a method Foo()
- The CLR looks at the type that implements Foo() and gets the metadata associated with it
- From the metadata, the CLR knows what memory address the IL (Intermediate byte code) is stored in.
- The CLR allocates a block of memory, and calls the JIT.
- The JIT compiles the IL into native code, places it into the allocated memory, and then changes the function pointer in Foo()'s type metadata to point to this native code.
- The native code is ran.
Calling a method for the second time:
- Your program code calls a method Foo()
- The CLR looks at the type that implements Foo() and finds the function pointer in the metadata.
- The native code at this memory location is ran.
第二次调用跟C/C++本地码差不多了
正常解释:一条字节码(语义信息不足)翻译成若干机器码
JIT:一坨字节码(根据整体语义进行优化)编译成机器码,缓存起来,方便下次使用
如果在浏览器这种只运行一次脚本的的环境,则只需部分JIT;而在服务器端要多次运行的环境,则把所有的代码JIT,方便多次使用
Hotspot:一部分JIT,一部分正常解释