是否应该始终使用最新的javac编译器来编译Java代码? [英] Should I always compile Java code with latest javac compiler?

查看:78
本文介绍了是否应该始终使用最新的javac编译器来编译Java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算将tomcat安装从6.0版升级到8.5版,并将JVM从6版升级到8版。我们的Java代码目前已使用Java 6进行编译。

I'm about to upgrade a tomcat installation from version 6.0 to version 8.5, and also upgrading the JVM from 6 to 8. Our java code is compiled with java 6 as for now.

我知道在最新的JVM上运行Java代码始终是性能方面的好主意(更不用说安全方面的方面)。这样,与JVM 6相比,使用Java 1.6编译的某些代码在JVM 8上的运行速度可能更快。

I know that running java code on the latest JVM is always a good idea performance-wise (not to mention security-wise). In this way some code compiled with java 1.6 might run faster on JVM 8 compared to JVM 6.

但是编译又如何呢?通过使用Java 8编译器编译用Java 6编写的代码是否可以获得任何收益(即仅使用Java 6功能)?即使用Java 8(目标8)而不是Java 6进行编译时,以Java 1.6进行编译的代码在JVM 8上的运行速度更快吗?与Java 6相比,来自Java 8的字节码是否进行了优化?

But how about compilation? Does one gain anything by compiling code written in java 6 with a java 8 compiler (i.e. only java 6 features are used)? I.e. does code written with the intent of compiling with java 1.6 run faster on JVM 8 when the code is compiled with java 8 (targeted 8) and not java 6? Is the bytecode from java 8 optimized compared to java 6?

关于目标标志。与使用Java 6编译器进行编译的代码相比,使用针对Java 6的Java 8编译器来编译Java 6代码有什么好处(当代码仍要在JVM 6上运行时)?

And regarding the target flag. Is anything gained by compiling java 6 code with a java 8 compiler targeted to java 6 (when the code is still to be run on JVM 6), compared to if the code was compiled with a java 6 compiler?

推荐答案


与以编译Java代码为目标的Java 8编译器相比,编译Java 6代码获得的任何东西

Is anything gained by compiling java 6 code with a java 8 compiler targeted to java 6 compared to if the code was compiled with a java 6 compiler?

否。

绝对没有性能提高,因为Java编译器不执行任何类型的优化,甚至没有明显的优化。

There is absolutely no performance gain, since the java compiler don't perform any kind of optimization, not even obvious ones.

可以在 javac 产生的字节码是在应用程序运行后由JIT引擎完成的。

Any optimization that could be performed on the bytecode produced by javac is done by the JIT engine once your application is running.

编辑:看pveentjer注释,javac执行了一些简单的优化(例如,恒定分辨率)。但是我仍然有信心关于6和8之间的差异的答案仍然是否。

Look at pveentjer comment, a few simple optimizations (e.g. constant resolution) are performed by javac. But i'm still confident that the answer regarding the differences between 6 and 8 is still "no".

这篇关于是否应该始终使用最新的javac编译器来编译Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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