Cross-compiler vs JVM

后端 未结 3 1249
终归单人心
终归单人心 2021-01-20 16:32

I am wondering about the purpose of JVM. If JVM was created to allow platform independent executable code, then can\'t a cross-compiler which is capable of producing platfor

3条回答
  •  清酒与你
    2021-01-20 16:49

    JVM is doing much more than compiling. JVM is an interpreter for byte code, which also contain JIT (just in time) compiler that compiles byte code - but depending on the context of the application the same byte code can be compiled differently based on the runtime context (it decides in the runtime how your byte code is compiled). JIT is doing lof of optimization - it is trying to compile your code in most efficient way. Cross compiler can't do (all of) this because it doesn't know how your code will be used in the runtime. This is the big advantage of JVM over cross compiler.

    I haven't been using cross compiler before but I guess that the advantage of crosscompiler is that you have better control on how your code is compiled.

提交回复
热议问题