Why is Java faster when using a JIT vs. compiling to machine code?

前端 未结 10 1682
轻奢々
轻奢々 2020-12-12 12:27

I have heard that Java must use a JIT to be fast. This makes perfect sense when comparing to interpretation, but why can\'t someone make an ahead-of-time compiler that gener

10条回答
  •  长情又很酷
    2020-12-12 13:28

    Java's JIT compiler is also lazy and adaptive.

    Lazy

    Being lazy it only compiles methods when it gets to them instead of compiling the whole program (very useful if you don't use part of a program). Class loading actually helps make the JIT faster by allowing it to ignore classes it hasn't come across yet.

    Adaptive

    Being adaptive it emits a quick and dirty version of the machine code first and then only goes back and does a through job if that method is used frequently.

提交回复
热议问题