Java 编译器优化 [英] Optimization by Java Compiler

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

问题描述

最近,我正在阅读这篇文章.

Recently, I was reading this article.

根据那篇文章,Java Compiler 即 javac 在生成字节码时不执行任何优化.真的吗?如果是这样,那么它是否可以实现为中间代码生成器以去除冗余并生成最优代码?

According to that article, Java Compiler i.e. javac does not perform any optimization while generating bytecode. Is it really true? If so, then can it be implemented as an intermediate code generator to remove redundancy and generate optimal code?

推荐答案

javac 只会做很少的优化,如果有的话.

javac will only do a very little optimization, if any.

关键是 JIT 编译器完成了大部分优化 - 如果它有很多信息,它的效果最好,如果 javac 也执行优化,其中一些信息可能会丢失.如果 javac 执行某种循环展开,JIT 将更难以一般方式自行执行此操作 - 并且它具有关于哪些优化实际起作用的更多信息,因为它知道目标平台.

The point is that the JIT compiler does most of the optimization - and it works best if it has a lot of information, some of which may be lost if javac performed optimization too. If javac performed some sort of loop unrolling, it would be harder for the JIT to do that itself in a general way - and it has more information about which optimizations will actually work, as it knows the target platform.

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

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