JIT具体过程

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,一部分正常解释

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值