Compiling Java to Native Code: Answer to Zyphrus
I was really wrong when I took Jeffrey's thread to talk about this subject...
Well, I'm not saying that Java programmers should deal with low level stuff when I said that Java is slow and that a cross-compiler, at least, is needed. And I don't want "1000" classes for one. That's not the issue here.
I just wanted to say that Java, for it is a high level language, probably carries useless procedures when it's compiled. This may be one of the reason why Java programs are slow.
I will be more specific. If a developer instantiates the Graphics2D class, for instance, it may happen that the resulting code he gets after compilation contains procedures and calls that never will be used in runtime.
This may be the reason, or not. The problem might also be that the JVM sometimes "monitors" too much the running Java program. Anyways, I know that something is slowing Java.
Why do I say that? Do you really think that the JVM optimizes the code to the point that a program written in Java compiled with the JVM (JIT) will result in the same amount and quality of a machine code obtained from C or C++?
I have downloaded many applications from Sun, and it's easy to see that those applications are a bit slow...You cannot say Sun's engineers are bad coders. Probably I am, but they certainly have the skills...
You can see that it happens even with applets. Compare a Java Applet with some Javascript that does the same thing.
Java is great because it's simple to make programs with. Why can't we add speed to this simplicity? If we had at least cross-compilers to lower level languages, like C++ or C, we could optimize the code to our needs and ENHANCE Java's popularity...And it would not represent the elimination of Java as an Object Oriented language. We would continue to use the classes getting smaller and better machine code...
I like Java. That's why I'm spending my time trying to convince people to improve it.
Perhaps you are trying to improve the wrong thing.
Why does Java even exist? Is it faster, cleaner Object Oriented, easier to develop in? Almost. There are other languages that are potentially faster (assembler, C, C++), more cleanly OO (Smalltalk, Eiffel), and potentially easier to develop in (dare I say Visual Basic?). So what is it about Java that makes it special? Two things IMO:
Write Once, Run Anywhere
The Java platform is what makes Java really unique among the mainstream programming languages. By having a well-defined JVM that is guaranteed to support a well-defined set of APIs, you take a lot of the guesswork out of programming.
A "pretty good" or "pretty **** good" score on the aspects I mentioned above
Of course, WORA doesn't mean a thing if the platform/language-combo just doesn't perform, doesn't support OO programming, or is too difficult to use. True, earlier versions (1.0.2, 1.1) of Java had performance issues (some quite serious), and there are still areas that can (and will) be improved, but performance is really up there and getting better with every release. Because of the extra Virtual Machine layer, extensively optimized native code will potentially be faster, but differences are getting so small as to become unnoticable, certainly not enough to throw away the benefits of WORA. For the applications we develop (ranging from desktop applications to purely server-side software and web-services), Java is certainly plenty good enough in all of these aspects. I'm sure there are areas where it is lacking, but overall performance isn't one of them, IMO.
So asking for a native compiler from Sun isn't very realistic IMO, as this is contrary to the WORA vision. Of course, a quick search on Google shows that there are quite a few java-native compilers available from other sources.
hhora at 2007-7-9 17:29:50 >

First... This tool converts java classes directly
to Windows .exe or dll files.
http://www.excelsior-usa.com/jetdl.html
Second Java execution is NOT slow when done properly.
In that I mean implemented in a manner that doesn't
degrade performance by such practices as this..
for(;;)
Image tempImage = createImage(100,100);
One must learn to use a balance between a modular
and a Monolithic approach.There are a few big companies ie: 1000+ java programmers releasing
most of the applications and in such a case
efficiency is not the prime consideration.
Thus we end up with an mpeg decoder in java that
can only do 1 frame a second on a p400.
I think the fault is not in the language
but in the implementation.
One of the major culprits is Threads.
people who have a less than adequate understanding
of the issues created by various operating systems,
preemption models, and shedule issues make
many programs either less than optimal or fatal
to run.
Another is code parroting BAD examples.
For example. almost every example I have seen
in the many books I have read, use Thread.sleep()
when they want to wait.Well this is not as
efficient as Object.wait() "Depending on the
preemption time" Yet look on the web most
people in lemming mode use sleep() which
doesnt release the Object's monitor and leaves
the Thread on the Shedule list thus gobbling
cycles for nothing.
Yet another is class instantiation.
Here is "Tony's #1 rule to speed up java"
DONT instatniate unless you have to and TRY to
instantiate at startup.
Within reason. I think implementation is the prime
issue regarding java and code execution time.
Sincerely:
--
Tony Swain
Senior V.P. of Software Development Hyperbyte inc. http://www.hyperbyte.ab.ca
Netscape DevEdge Champion Devs-Java Newsgroup
snews://secnews.netscape.com/netscape.devs-java