Re: Help me!! Why java is so popular
- From: "raddog58c" <raddog@xxxxxxxxx>
- Date: 7 Feb 2007 11:19:48 -0800
On Feb 7, 11:14 am, "Chris Uppal" <chris.up...@xxxxxxxxxxxxxxxxxxx
THIS.org> wrote:
raddog58c wrote:
Sometimes the penalty can be zero or even negative, particularly for
applications which run long enough to eliminate the startup effects of
JIT compiling.
How can it negative? I'm not saying you're wrong, but how can any
byte-coded language outperform a binary language if they are doing the
same thing? It can't, because you have to convert the byte code to
the native binary stream before you can execute it.
At least in theory, the JVM's JITer has more information available to it than a
compiler producing a statically pre-compiled binary would have. Some
theoretical examples:
Is the machine /actually/ a multiprocessor ? If not then some synchronisation
primitives can be replaced by no-ops.
Is a (virtual) method /actually/ overridden by any class loaded at runtime ?
If not then optimisations like static linking or even inlining become possible.
Does the processor have an extended instruction set ? If so then the JITer can
generate code which uses those instructions. (A statically precompiled binary
could include both sets of code, of course, with dynamic switching between
them, but that is not often deemed worth the extra bother).
As far as I know, all of those possibilities are implemented (if only in
limited ways) in current Sun JVMs.
These are good... thanks. It would depend on the nature of the
application, as some of the optimizations, unless significant,
wouldn't make up the difference in the time it took to compile the
byte code into machine code.
How does one get Java to run faster than a compiled language?
Simple: compare it with a compiled language with a bad optimiser ;-)
That'd be one of several ways... touche!
FWIW, I think it is /highly/ application dependent, and there is no simple set
of rules you can follow to make Java run as fast as possible. My impression is
that the optimiser in the server JVM, from 1.5 (and presumably later) generates
code which is comparable with GCC -o3 or MS's C++ compiler with all obvious
optimisations turned on -- however that is a useless observation unless the
code in the two languages is trying to do the same thing (e.g. 2-D arrays have
different layouts in C and Java, or a calculation might create many
intermediate objects in carefully-written Java whereas the "same" code in
well-crafted C++ might not).
This does presume that we're comparing the post-compiled byte code
against the precompiled code in the runtime binary (.EXE, .COM, etc).
The fact the conversion is done at run time and would have to be done
every time the code is run (unless it's cached) puts it at a
disadvantage out of the gate. The late binding to environment could
help close the gap, but that's not guaranteed because the .EXE can be
precompiled for the target deployment environment and if so the race
is over.
I'm nonetheless impressed with the computer scientists building
optimizations into the JVM -- they've a lot of clever techniques up
their respective sleeves.
-- chris
.
- Follow-Ups:
- Re: Help me!! Why java is so popular
- From: Arne Vajhøj
- Re: Help me!! Why java is so popular
- From: Mark Thornton
- Re: Help me!! Why java is so popular
- References:
- Help me!! Why java is so popular
- From: amalikarunanayake
- Re: Help me!! Why java is so popular
- From: Jack Kielsmeier
- Re: Help me!! Why java is so popular
- From: raddog58c
- Re: Help me!! Why java is so popular
- From: Mark Thornton
- Re: Help me!! Why java is so popular
- From: raddog58c
- Re: Help me!! Why java is so popular
- From: Chris Uppal
- Help me!! Why java is so popular
- Prev by Date: Re: ORA-01017: invalid username/password; logon denied
- Next by Date: Re: Java Certification Exam
- Previous by thread: Re: Help me!! Why java is so popular
- Next by thread: Re: Help me!! Why java is so popular
- Index(es):
Relevant Pages
|