Java 6 的性能改进是针对 JDK、JVM 还是两者?
我一直想知道 Java SE 6 中所吹捧的性能改进 - 是在编译器中还是在运行时中? 换句话说,由 JDK 6 编译的 Java 5 应用程序在 JSE 5 下运行时是否会看到改进(表明编译器优化得到改进)? 由 JDK 5 编译的 Java 5 应用程序在 JSE 6 下运行时是否会看到改进(表明改进的运行时优化)?
我注意到,对于完全相同的代码库,在 JDK 6 下编译所需的时间几乎是在 JDK 5 下编译的两倍; 我希望至少有一些额外的时间花在编译器优化上,希望能带来更高性能的 JAR 和 WAR。 Sun 的 JDK 信息并没有真正详细介绍他们所做的性能改进 - 我认为它有一点来自 A 列,还有一点来自 B 列,但我想知道哪一个影响更大。 有谁知道 JDK 6 与 JDK 5 的基准测试吗?
I've been wondering about the performance improvements touted in Java SE 6 - is it in the compiler or the runtime? Put another way, would a Java 5 application compiled by JDK 6 see an improvement run under JSE 5 (indicating improved compiler optimization)? Would a Java 5 application compiled by JDK 5 see an improvement run under JSE 6 (indicating improved runtime optimization)?
I've noticed that compiling under JDK 6 takes almost twice as long as it did under JDK 5 for the exact same codebase; I'm hoping that at least some of that extra time is being spent on compiler optimizations, hopefully leading to more performant JARs and WARs. Sun's JDK info doesn't really go into detail on the performance improvements they've made - I assume it's a little from column A, and a little from column B, but I wonder which is the greater influence. Does anyone know of any benchmarks done on JDK 6 vs. JDK 5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
javac 从 Java 源代码编译为字节码,几乎没有进行任何优化。 事实上,优化通常会使代码实际上运行得更慢,因为更难分析以便以后进行优化。
1.5 和 1.6 生成的代码之间唯一显着的区别是,使用 -target 1.6 添加了有关堆栈状态的额外信息,以使验证更容易、更快(Java ME 也这样做)。 这仅影响类加载速度。
真正优化的部分是把字节码编译为本机代码的热点编译器。 这甚至在某些更新版本上进行了更新。 在 Windows 上,默认情况下,JRE 中仅分发较慢的客户端 C1 版本的热点。 服务器C2热点运行速度较快(在java命令行上使用-server),但启动速度较慢并且占用更多内存。
此外,库和工具(包括 javac)有时也会完成优化工作。
我不知道为什么您发现 JDK 6 编译代码比 JDK 5 慢。设置方面是否存在一些细微的差异?
javac, which compiles from Java source to bytecodes, does almost no optimisation. Indeed optimisation would often make code actually run slower by being harder to analyse for later optimisation.
The only significant difference between generated code for 1.5 and 1.6 is that with -target 1.6 extra information is added about the state of the stack to make verification easier and faster (Java ME does this as well). This only affects class loading speeds.
The real optimising part is the hotspot compiler that compile bytecode to native code. This is even updated on some update releases. On Windows only the slower client C1 version of hotspot is distributed in the JRE by default. The server C2 hotspot runs faster (use -server on the java command line), but is slower to start up and uses more memory.
Also the libraries and tools (including javac) sometimes have optimisation work done.
I don't know why you are finding JDK 6 slower to compile code than JDK 5. Is there some subtle difference in set up?
我还没有听说过编译器的改进,但已经发布了有关运行时性能改进的大量信息。
迁移指南:
http://java. sun.com/javase/6/webnotes/adoption/adoptionguide.html
性能白皮书:
https://www.oracle.com/java/technologies/javase/6performance.html
I have not heard about improvements in the compiler, but extensive information has been published on the runtime performance improvements.
Migration guide:
http://java.sun.com/javase/6/webnotes/adoption/adoptionguide.html
Performance whitepaper:
https://www.oracle.com/java/technologies/javase/6performance.html
其运行时间几乎是 100%。 虽然一些基本的编译技巧可以融入 Java 编译器本身,但我不认为 Java 1.5 和 1.6 之间有任何重大改进。
Its almost 100% the runtime. While it is possible for some basic compilation tricks to make it into the Java compiler itself, I don't believe there are any significant improvements between Java 1.5 and 1.6.
新的java虚拟机有很多新的改进和优化。 因此,您将看到性能改进的主要部分是使用版本 6 jvm 运行 java 时。
使用 Java 6 JDK 编译旧的 java 代码可能会产生更高效的代码,但主要的改进在于虚拟机,至少我注意到这一点。
There's been a lot of new improvements and optimization in the new java virtual machine. So the main part you'll see improved performance is while running java with the version 6 jvm.
Compiling old java code using the Java 6 JDK will probably yield more efficient code, but the main improvements lie in the virtual machine, at least that's what I've noticed.