Will we still have the performance gain of Java 6 if the bytecode was compiled in 1.4
Asked Answered
O

4

6

I'm assuming there is vast performance difference between Java 1.4 and Java 6 after skimming this document.

My question, will Java 6 runtime still got its magic when the bytecode it has to run was compiled in 1.4?

Some background for "why the question?" is here.

Olodort answered 26/4, 2012 at 10:51 Comment(0)
Z
8

Yes, because most of the optimizations are done at runtime by the JVM, compiler is doing very little with regards to optimization. Thus code compiled with old Java compiler will still benefit from new JVM.

However there are some optimizations performed at compile time, like replacing consecutive String concatenations with StringBuilder.

Zinkenite answered 26/4, 2012 at 10:57 Comment(6)
Hi Tomasz, thanks for the answer. Do you have any pointer to reading materials stating the above? Something official from Sun or Oracle would be very great.Olodort
@bungrudi: unfortunately, it is just a common knowledge from SO. But maybe someone else will point out to hard resources?Zinkenite
+1 Not only does the javac compiler do very little optimisations, what is does hasn't changed much since Java 1.4. Using StringBuilder instead fo StringBuffer was added in Java 5.0 (2004) but the difference is usually very small.Diastole
@Olodort The paper titled "Design of the Java HotSpot Client Compiler for Java 6" summarizes the optimizations performed by the client JIT compiler. There is a corresponding version for the server compiler. Those should serve as excellent starting points.Clannish
Oh how I wish I can use "someone in SO with a reputation of 48k" as a line to back my arguments when convincing my bosses. :)Olodort
@Clannish thanks for the pointer to the doc. will have a look. +1.Olodort
D
1

Nearly all optimizations in java occur in the jit and so depend only the jvm version that is running the application. The javac bytecode compiler just emits the most straight-forward bytecodes possible. I don't think there are any optimizations at this stage, except perhaps for string concatenation using StringBuilder / StringBuffer.

Java 6 and above can use a faster and simpler bytecode verifier for classes compiled with target version 6. The javac compiler creates additional information about the data types in each stack slot, which the verifier has to validate. In previous versions the verifier had to deduce these types which is more complex. This change will only speed up the loading of classes and should have no impact when actually executing the bytecode.

I think another change to the bytecode in version 5 or 6 was that the constant pool in the class file can reference classes and interfaces. Again, this probably only affects class loading.

Diestock answered 26/4, 2012 at 13:32 Comment(0)
C
1

As Tomasz Nurkiewicz points out most of the optimization is done by the JIT compiler and you should see performance benefits by running on java 6 instead of java 1.4. However, this doesn't guarantee you will extract the best results. You can still miss out on benefits if you are using slower (older) variants of data structures. e.g. StringBuffer instead of StringBuilder, Vector instead of LinkedList, Hashtable instead of HashMap, and so on...

You can also consider compiling with the -deprecated flag for javac. You probably want to replace deprecated methods as they usually mean there is a better performing alternative available to achieve the same thing.

Clannish answered 27/4, 2012 at 4:19 Comment(0)
G
0

Not only will there be simply vast performance gains, but even between Java 6 versions there are big differences. I tracked minor releases of Java 6 over an 18-month period and saw 15-20% speedup just from that.

Java 7 is out, by the way, and is the preferred production version - is there a reason why you wouldn't want to go to that version?

Oh, and one last thing. If you need to prove the gains to management, then you should read up a lot on performance measuring of Java applications. I have an article in the upcoming May / June 2012 issue of Oracle's Java magazine which is a real 101 if you need it. It's a very slippery subject, so you should do plenty of reading or you may get very misleading numbers.

Griddlecake answered 27/4, 2012 at 3:1 Comment(1)
The app is a legacy WebSphere 6 (Java 1.4 based) application which we are now migrating to WebSphere 7. The 'bundled' JDK is a 1.6.0_xx and we don't have the luxury of spare time to try to change it to Java 7 (at least for now). I'm eagerly waiting for your article.Olodort

© 2022 - 2024 — McMap. All rights reserved.