交叉编译器与JVM [英] Cross-compiler vs JVM

查看:167
本文介绍了交叉编译器与JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道JVM的目的。如果创建JVM以允许独立于平台的可执行代码,那么能够生成独立于平台的可执行代码的交叉编译器不能取代JVM吗?



从以下网址检索有关交叉编译器的信息: http://en.wikipedia.org/wiki/Cross_compiler

解决方案

字节码格式的优点和JVM是基于在实际运行期间获取的分析数据在运行时优化代码的能力。换句话说,没有静态编译的本机代码是 win



运行时编译的优点的一个特别有趣的例子是单态调用站点:对于调用实例方法的代码中的每个位置,运行时会精确跟踪调用该方法的对象类型。在很多情况下,事实证明只涉及一种对象类型,然后JVM将编译该调用,如果它是静态方法(不涉及 vtables )。这将进一步允许它内联调用,然后进行更多优化,例如转义分析,寄存器分配,常量折叠等等。



<事实上,你的批评可能(有人说,应该)被颠倒过来:为什么Java根本定义字节码,修复许多可能留给实现的设计决策?现代趋势是分发源代码并让JIT编译器在其上工作。


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 platform independent executable code replace a JVM?

the information about cross-compiler was retrieved from: http://en.wikipedia.org/wiki/Cross_compiler

解决方案

The advantage of the bytecode format and the JVM is the ability to optimize code at runtime, based on profiling data acquired during the actual run. In other words, not having statically compiled native code is a win.

A specifically interesting example of the advantages of runtime compilation are monomorphic call sites: for each place in code where an instance method is being called, the runtime keeps track exactly what object types the method is called on. In very many cases it will turn out that there is only one object type involved and the JVM will then compile that call is if it was a static method (no vtables involved). This will further allow it to inline the call and then do even more optimizations such as escape analysis, register allocation, constant folding, and much more.

In fact, your criticism could (some say, should) be turned upside-down: why does Java define bytecode at all, fixing many design decisions which could have been left up to the implementation? The modern trend is to distribute source code and have the JIT compiler work on that.

这篇关于交叉编译器与JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆