• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ever Need Hand Optimized Byte Code?  RSS feed

 
Sajid Raza
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some high-performance oriented libraries/systems inline-assembly is used to optimize function calls. Is there ever any equivalent in a Java method? I understand its possible to call a native method. However, would it be possible to insert inline byte-code in the middle of a methods statements? Would such a practice be of any use?
 
nauman ahmad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plz post this topc 2 me
 
Scott Palmer
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only time that you get a reasonable benefit from coming to assembly language is when you have a specific algorithm that can be efficiently coded with processor specifc instructions like MMX & SSE.. otherwise it is very rarely worth it.
For that reason I doubt that it would be worthwhile doing this with java bytecode. I would be interested to hear from someone that has actually attempted this though... Are java compiler's not efficient enough? How much more performance is available if you get closer to the "virtual" metal?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to be aware of is that compilers can often inline method calls for you if they can determine that the method will not be overridden. So for performance, it's worthwhile to declare methods as static, final, or private if one of those can possibly be appropriate. Otherwise the method lookup will have to be done at run-time, based on the class of the invoking object. Even here though, it's still possible for a JIT to identify that section of code as suitable for inlining, if it run often enough to catch the attention of the JIT.
 
Mo Ibrahim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think many Java compilers just in-line the private and static methods and do not bother to optimize much of the code leaving the burden to the JITs.
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mo Ibrahim:
I think many Java compilers just in-line the private and static methods and do not bother to optimize much of the code leaving the burden to the JITs.

Actually, most Java compilers don't inline anything. All the inlining, and almost all other optimizations, are done at runtime.
Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!