bhlangonijr wrote:The JVM itself is written in C++ how could it be faster?
The JVM is a compiler, it could even be written in BASIC and the compiled Java code might be faster than anything.
Of course, we all know that in general Java is definitely not faster than C or C++.
Where did you get that the JVM is a compiler? The JVM is the Java Virtual Machine and is responsible for running the Java bytecode (the compiled artifact). The compiler is present in the JDK which is not required for executing the Java binaries.
Regards,
I believe that most important JVM's compile the compiled bytecode into actual machine code for the architecture being used.
Some JVMs may not do this, but the ones for the most popular architectures / OSs certainly do. If bytecode emulation was always used, Java programs would run MUCH slower on those computationally intensive benchmarks instead of two times slower and similar.
The HotSpot VM does that. IMO it is more like a "feature" present in most VM's to improve performance. Although it doesn't make the JVM a "compiler" itself.
The point I was trying to make is that there is a middleman between the Java code and the machine code and it was actually written in the language C++. So how could we expect Java to be faster than C++?
some time ago Spike had a source code that could be compiled by a Java compiler and a C++ compiler. We had a little search & replace program for some code pieces as not all could be handled by macros.
Java took about 1.6 the time as C++, using a just in time compiler used for server applications.
The factor 1.6 is mainly coming from array access range checks. Spike use a lot of array access. Java tests if the index is inside the range (two tests) before reading from the array. IMHO the main difference in speed is there.