0

We know java adopts stack-based instruction set in case of enhencing its compatibility,but stack operation is much slower than register operation,so is it a important factor degrades the performance of java?I learned that java some times also uses registers to accelerate its excution speed,but I don't know how and when does java utilizes registers. Thank you!

xinghui
  • 22
  • 3
  • This is depends from JVM implementation. – MariuszS Jan 10 '14 at 11:43
  • 1
    Java's performance is not degraded. On a modern JVM for most purposes it is as fast as compiled code. – Tim B Jan 10 '14 at 11:52
  • @TimB But when I utilize a complex algorithm,java code always run much slower than C/C++ code,how do you explain it? – xinghui Jan 10 '14 at 12:09
  • @xinghui: If the java code is always much slower, it could be the problem is with your implementation of the algorithm in Java... From my experience, Java is generally about as fast as C/C++ for most problems, faster for some, slower for others. Often, Java seems to be slower in mirco-benchmarks, because of longer startup-times. – Axel Jan 10 '14 at 15:35

1 Answers1

3

The Java bytecode model has very little to do with the actual code being executed in a running application. HotSpot, as well as all other major JVMs, compiles the bytecode into native code using all applicable optimizations.

There is no performance impact of the bytecode's stack-based model on the performance of modern JVMs.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • What you said may be right in a long time system.But anyway,java is a interpreted programming language,and HotSpot just compiles Hot code. – xinghui Jan 10 '14 at 12:15
  • So I think there are still a part of codes execute by jvm stack instruction. Is it right? – xinghui Jan 10 '14 at 12:25
  • You are right, those parts of code whose performance is irrelevant to the overall system performance (rarely executed code---e.g. the system spends 2% of its time interpreting bytecode). – Marko Topolnik Jan 11 '14 at 12:47
  • BTW Java is not an interpreted PL by any official definition or its consequence. There was actual hardware produced which executed bytecode natively. – Marko Topolnik Jan 11 '14 at 12:50
  • As for "right in a long time system", that is also false: HotSpot has *tiered compilation*--the C1 and the C2 compiler. In `client` mode, C1 is exclusively used, and in `server` you can have all your code immediately compiled into C1 (no interpretation at all) and then gradually recompiled into C2. – Marko Topolnik Jan 11 '14 at 12:53