Java Native Compilation Examined 486
An Anonymous Coward writes: "DeveloperWorks has an interesting article about compiling Java apps to run as native appplications on the target machine without the need for a JVM."
On the eighth day, God created FORTRAN.
Well gee *that* makes sense.... (Score:2, Insightful)
Not new ... ho hum (Score:5, Insightful)
Mind you I noticed in the IBM article that the memory footprint was much smaller. That might be nice.
AWT support a must (Score:5, Insightful)
That's the real shame of the matter. Java shines most in its ease-of-use for creating complex GUIs -- unfortunately that's also where the worst memory/performance problems appear. For instance, Swing is good for client apps if you can ship with minimum RAM requirements of 64+ mb (and even that's cutting it close). Performance is most important in the UI, where the user notices any lack of responsiveness. Hopefully some Java native compilers will help out here.
Different compilers support differing levels of class library; Excelsior JET is one compiler that claims to completely support AWT and Swing.
Maybe there's hope yet!
Speed isn't the advantage of GCJ (Score:2, Insightful)
Some thoughts... (Score:1, Insightful)
I always thought Java was very interesting with it's cross-platform compatibility and whatnot. But as everyone has noted, it's painfully slow. I always wondered why people hadn't implemented a native-code compiler for it. Sure, with bounds-checking and garbage collection, natively compiled Java will still be slower than natively compiled C++.
The point is, Java is really just another programming language. What's wrong with allowing developers the opportunity to write their natively compiled software in a solid, object-oriented language that doesn't have all the backwards-compatability issues that C/C++ has?
Whether this will be useful, I dunno. But it opens up options, and that's always a good thing.
Re:It's about time! (Score:3, Insightful)
Another weak study... (Score:5, Insightful)
This has to be the third or fourth weak study of Java performance I've seen over several years. Issues such as whether or not all Java features are in place in the native compilations (e.g. array bound checking, but note that GCJ turns this on by default) or what sort of optimizations are performed by the native compiler and JVMs are completely ignored. The author also suggests that compiling from bytecode to native code is the natural route when it's quite possible that gains could be made by compiling directly from source to native. While GCJ accepts either Java source or bytecode, it's not clear from the documentation I've read whether or not it first translates source to bytecode or goes straight from source to native.
When comparing disk space, the author comments that an installed JVM can be up to 50 MB vs. 3 MB or so for libgcj. This is a ridiculous comparison since those directories probably include all of the tools, examples and libraries, and as far as I know, libgcj doesn't include the whole J2SE API set, so it's nowhere near a fair comparison. It's a pretty limited set of benchmarks for making these judgements too.
I played around with native compilation of Java a few years ago. At one point (probably around 1996/7?) native compilers could offer noticable gains over Sun's JVM on a numerically intensive application (neural network stuff). However, after the initial versions of HotSpot and IBM's JIT, I couldn't find a native compiler that gave competitive performance on similar apps. I think this is largely due to underdeveloped native compilers with poor optimization (HotSpot is quite insane in its runtime optimizations).
Anyway, I sure hope IBM doesn't pay too generously for studies this poor. Its final message is essentially "who knows?" - not terribly useful.
Alea
My Cynical Take on This: (Score:5, Insightful)
As an aside; I see people call Java "painfully slow," but in my experience it's not that painful post 1.3. I'm not giving you benchmarks, and anti-Java people will just "no" me, but these are my experiences after a few hundred thousand lines of Java code over the past few years. Anyway, it's a good exercise to ask naysayers what _their_ basis is; they often have none.
Also, as other posters have pointed out, the speed loss must be seen in the runtime safety context, as bounds checking and garbage collection yield stability and security dividends and, at the end of the day, we almost always want those things and are willing to wait the extra few ms for the guarantees.
All these complaints about speed are especially ironic given how many massive wasters there are in the modern computer, _especially_ in Windows NT/2k/XP.
But the biggest flaw in this Java vs. C debate is that often you don't get a choice between writing code in Java vs. C/C++, since you don't have the extra 50% in your time budget to do C/C++, and your real choice is between Java and VBScript...
All the people shouting "I can write C++ 10 times as fast as you can write Java, loser" please form a line in an orderly fashion, you will be spanked in the order you arrive...
Re:Well gee *that* makes sense.... (Score:4, Insightful)
Well, yes and no. There are some very slick Vms out there, and some very lazy compilers, though in most cases, you are correct, native code will execute faster than interpreted code.
The disk requierments, though, can in the long run be larger for native code apps. The VMs have a lot of common tools (i.e. all of the java.* classes) available for any app that needs them. If you plan to compile to native code, you hav to link these in. You can save space by only linking in the libraries you need, but will still end up loosing space when you start installing mulitple applications that all include the SWING packages.
I have been a bog fan of Java for some time, but the need for a VM held me back from a full-out endorsement for some time...it seemed like I was writing toy code because I needed another program to do anything with it, and I didn't like leaving all of those class files laying around. I have gotten over a lot of this, especially once I learned how to make an executable JAR file, and considering the widespread use of DLLs. Plus, I realy like being able to work on my text editor on my home WinXP box, and take it in and use it on our Sun achines.
Still, I'm downloading one of those compilers right now. Why? Because native Java would just be neat. I probably won't even use it that much, but it will be nice to see that it can be done.
Re:It's about time! (Score:1, Insightful)
But that same person can just call their Java file deletion function
So the so called 'advantage' is just more marketing bullshit.
And how about the case of a Matrix class? Which is more readable:
Matrix b = a.plus(b.multiply(c));
vs.
Matrix b = a + b * c;
Using template trickery (see Blitz++ for examples) you can even optimize away all the implicit temporaries in the C++ example. With Java, you're stuck both with the less readable code, _AND_ unneeded temporary objects.
I'm the biggest expert here, listen to me! (Score:5, Insightful)
Some experts who have never used Java want to tell me that it's no good, and will never be any good--why? They don't know, but they know!
And some experts who want to tell me all about why Java's compilation, why it is hard or easy even though they really don't know anything about a compiler.
And some experts on Java's market share who really don't know anything about who uses Java.
And some experts who sat in a room where Java was... gosh gee... being implemented, telling me... well I don't quite know what, but gosh!
So many experts here--I must be reading slashdot!
Re:It's about time! (Score:2, Insightful)
Of course they can..and that person would be a goddamn fool.
The point is that an operator overload might make complete sense to the person that programmed it. The next person who looked at it may have used a different convention and interprets it differently.
As an example, I overload (file--) to delete the file. But the convention you read in the latest issue of 'L33T Developer' indicates that (file--) should mean close the file handle. You look at the code, make somes changes and your clients file was just deleted.
And BTW, I would never have called a function that deleted a file
Jason.
Bad review (Score:5, Insightful)
{ if (i%test == 0) { return false; }
}
On the safety front, subscript checking is almost free if done right. Subscript checking can usually be hoisted out of loops. Old studies on Pascal optimization showed that 95% of subscript checks can be optimized out at compile time without loss of safety. GCC, though, being a C compiler at heart, isn't likely to know how to do that. Merely putting a Java front end on it doesn't make it a Java compiler deep inside.
Re:Well gee *that* makes sense.... (Score:3, Insightful)
It seems to me that most discussions of Java lose track of that fact that the key to the "write once run anywhere" idea is that the Java source code is translated to bytecodes and then executed in a non-ambiguous way. In other words, the language definition doesn't have all the "implementation defined" behavior that C/C++ language definitions have.
It takes a lot of discipline to write truly portable C/C++ source code. It seems a lot easier to achieve this source code portability with Java. I think having bytecode portability is a big plus in some cases but not very important in others.
So there's many ways to execute a given set of byte codes - strict interpretation, JIT compilation, native compilation, etc. This flexibility seems pretty good to me.
Java for servers (Score:2, Insightful)
Re:It's about time! (Score:2, Insightful)
Are operator overloads misused? Sure. So are knives, but that doesn't mean that cooks shouldn't use knives.
But you wanna talk about language features that Java lacks? How about enums? Why leave those out? And whats with this whole "bean" concept? Why can't that be a first class concept with real syntactical support instead of this asinine get___ set___ crap?
I could be biased, though.
Excelsior JET (Score:2, Insightful)
It took forever to compile, but once it was done, I had a (large) executable for my native platform, windows.
It ran about 30% slower than the JDK. There are a number of things that are still pretty slow in java, but in general, it's a pretty fast language these days. JIT compilers and hotspot to a good job. It can never be as fast as C++ due to things such as GC, but the performance tends to be close for most applications.
This is indeed interesting, but I think it is entirely irrelevant. Speed of execution is usually about 7th on the list of important-stuff-im-thinking-about when choosing a language and starting a project. There are so many more important things, such as maintainability, scalability, code reusability, code robustness (the number of stuff you get so easy compared to C++ just leaves you wondering how you could ever program in C++ again), you know the stuff. These things are often far more of an issue than raw performance. Look at Slashdot, it's written in perl, presumably because they thought it was easier to write the website in, not because it was the fastest thing around.
Re:Java's Cover (Score:3, Insightful)
I agree with you relative to C/C++, and I was using Java heavily a couple of years ago. But now I've moved on to higher-level languages such as Perl, Python and Ruby. They each have APIs that provide functionality similar to Java, but usually simpler and more intuitive. They also don't have licensing policies or agendas driven by one particular corporation..
I usually get the same job done with 1/2 or 1/3 the lines of code as with Java. I've also found that once you free your mind from the strong-typing yoke, you can transform your concepts into reality much more efficiently.
It's funny that a few years ago I had to argue to the PHBs that Java was a valid solution. Now, they are set on Java, and I have to argue that a better solution has emerged as support for other languages has matured.
Different tools for different tasks (Score:4, Insightful)
For ease of coding, I find that Java simply outshines C++ because it doesn't leave me dealing with low level stuff, like pointers.
An occasional big time-killer with C++ is trying to debug something that corrupts memory.This doesn't happen with Java (although you can muck up the synchronization with threading and get unpredictable results which is just about as bad).
On the other hand, if I want performance (such as writing image processing software), I'll go with C++ (or assembler), as there is no way that Java can compete on speed for low level stuff.
And even the awful C++ templates are better than no templates at all.
Re:Java's Cover (Score:3, Insightful)
Re:Well gee *that* makes sense.... (Score:3, Insightful)
What you do in that case is pull the source code out of source control and recompile for the new platform.
100% source code compatibility between platforms is insanely useful. 100% binary code compatibility between platforms, while nice, is not nearly as big of a deal for most systems... As long as you can easily recompile the original source and it runs the same, why not go for the extra efficienty of native if you dont need things like extensive runtime typing (reflection, etc)?
Re:My Cynical Take on This: (Score:2, Insightful)
If you want to use templates as well as garbage collection, you might like Managed C++ [gotdotnet.com], the
It'll let you code in C++ (with templates etc) but also use garbage collected arrays etc, and the
100% right! (Score:4, Insightful)
It didn't work out. Client side Java is essentially dead. "Death to Java applets!" C#/.Net will become what Java only dreamed it could be -- but, sadly, only on Windows.
In the meantime, Java hit pay dirt on the server, because the language is so easy and productive to work in and the result is so portable.
Source portability would have been sufficient on the server, though. I can't prove it, but I strongly suspect they could have created a better server-side programming language if they had designed for 100% *source* portability, then instead of constraining themselves to binary portability and security sufficient for running *anybody's* binaries on *anybody's* client, had instead optimized for high performance plus ease of rapid, bug-free development -- more like Eiffel.
Re:My Cynical Take on This: (Score:2, Insightful)
Actually I do know. Whatever tool someone last used is what they consider the best tool for the job, especially when they don't have experience with lots of different tools. It takes intellectual honesty to admit that your favorite tool isn't always the best tool for the job, and it takes a fair amount of experience and detachment to reach that point.
Reflection (Score:1, Insightful)
lies, damn lies, and benchmarks (Score:2, Insightful)
I expected a little better from their 'developerworks' people---this is just marketing drivel.
Re:Well gee *that* makes sense.... (Score:1, Insightful)
A native-code compiler doesn't make Java any less portable. In a broad sense, it just lets the JVM do its work once, instead of repeating the same work every time a program is run.
I read a similar article in Byte magazine 5 years ago (give or take). It was a good idea then, its a good idea now.
JVM bloat (Score:2, Insightful)
I use the applet because I have a unique, interactive GUI page that needs to address the screen pixel-by-pixel, and Java applets are the only game in town if you want the maximum number of different browsers to be able to run it.
The applet is written for Java 1.1, which is the level of built-in Java support for all Explorer browsers (80 percent of the market) and all Netscape through 4.X (another 10 percent).
My applet works smoothly with these browsers, mainly because the JVM is built into the browser, and the 1.1 level of support makes the JVM package much, much smaller.
What concerns me is that with Opera (starting with ver. 6.0), and Explorer 6.0 (if you download Sun's JVM plug-in instead of the MS download), and other browsers that refer you to Sun for Java plug-in support, I have a problem. The integration is poor between the browser and the JVM, when Sun's bloated 1.3 is used instead of a stripped-down, built-in 1.1 of yesteryear.
There are two different areas that are problematic, and they make my application unsatisfactory. One is that the JVM 1.3 is so utterly bloated that the load time for the plug-in is objectionable. The other is that on several different browsers I've tried using the 1.3 plug-in, the browser and the applet don't always know which one is supposed to be in control. The communication between them, or the integration of one with the other, is so poor that the browser is likely to hang. For example, clicking on a link from inside the applet, when that link points to a page with another applet, will often spell trouble.
I think that Java has become so bloated that Sun is inadvertently forgetting about the use of applets on the Web.
Too bad, because you know who will step into the vacuum.