Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 812
bungrudi Avatar asked Apr 26 '12 10:04

bungrudi


2 Answers

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.

like image 51
Tomasz Nurkiewicz Avatar answered Sep 20 '22 04:09

Tomasz Nurkiewicz


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.

like image 22
shams Avatar answered Sep 23 '22 04:09

shams