Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Java 7 faster than ancient versions?

 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to know if Java 7 is faster than ancient versions.

Thank you
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 7 is a language. It makes no sense to say it's faster or slower than other versions.

Oracle's new JVM might be faster than older versions, but I could write a JVM for Java 7 that runs old code slower than Sun's 1.1 version.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're asking about the Sun / Oracle Java implementations, then yes, Oracle's Java 7 JVM is certainly faster than older versions. In each new Java version from Oracle there are new optimizations and other performance improvements.
 
Jennifer Reese
author
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true there are improvements in the performance of the JVM with each release. However, the new features of Java 7 are intended to help you improve the maintainability and efficiency of your applications. This could in turn result in more reliable and possibly faster execution. For example, in our book we discuss the ThreadLocalRandom class. This class, when used in place of the older Random class, will improve the performance of your threads.

Also, don't forget the javac compiler has a -O option that will result in the compiler optimizing the compiled code.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jennifer Reese wrote:Also, don't forget the javac compiler has a -O option that will result in the compiler optimizing the compiled code.

No, it doesn't. And if it does, then it's not in the documentation.

The Java compiler (javac) doesn't do a lot of optimization. The JIT compiler that's part of the JVM on the other hand, does a lot of very sophisticated optimizations when it compiles the Java byte code to native machine code.

There's a reason why javac doesn't optimize. By not doing a lot of optimization, javac makes it easier for the JIT to generate optimized native machine code.
 
Jennifer Reese
author
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, you're right! As of 1.3, the -O has been deprecated and should not be used. In earlier releases, it would inline static, final and private methods to attempt to speed up your code.

For many applications, fine tuning JVM options is not really necessary, but if you are curious, here is an interesting article about some current options for improving JVM performance.
http://randomlyrr.blogspot.com/2012/03/java-tuning-in-nutshell-part-1.html

Also, just some general techniques to use to help the JVM handle your code in the optimal manner:
https://wikis.oracle.com/display/HotSpotInternals/PerformanceTechniques
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jennifer Reese wrote:Oops, you're right! As of 1.3, the -O has been deprecated and should not be used. In earlier releases, it would inline static, final and private methods to attempt to speed up your code. . . .
Presumably using JIT techniques works a lot better than trying inlining.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inlining is one of the optimizations that the JIT compiler does. Probably it works a lot better if javac leaves it to the JIT, so that's why they took it out of javac since version 1.3.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic