Slashdot Mirror


Java Native Compilation Examined

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."

130 of 455 comments (clear)

  1. Well gee *that* makes sense.... by Anonymous Coward · · Score: 2, Insightful

    What's the point of taking a language that jumps through hoops to be "cross-platform" and cutting it's legs off?

    1. Re:Well gee *that* makes sense.... by Andrewkov · · Score: 2, Informative
      What's the point of taking a language that jumps through hoops to be "cross-platform" and cutting it's legs off?


      Huh? You still have the Java source .. You can compile it to a native executable for whatever platform you need, or compile it to Java bytecode. Obviously, compiling to a native executable is not applicable for applets served from websites, sending objects over the network, or Remote Method Invocation (RMI). The point of the article is that if you have a large, slow Java application, you can compile to run natively on a given platform to increase it's speed and reduce the disk and memory requirements.

    2. Re:Well gee *that* makes sense.... by MisterBlister · · Score: 5, Informative
      Not everyone cares too much about binary cross-platform. Many people would be happy just with 100% source cross-platform porting, which doesn't exist with C/C++, etc.

      Further, not everyone even cares about the cross-platform nature of Java to begin with. I've worked on a few projects where the OS requirements were completely fixed but Java was chosen anyway -- for its rapid-design features (built-in garbage collector, nice network access classes, etc) rather than its cross-platform nature.

      All in all, its good to have a choice..Just because you can native-compile Java doesn't mean you have to do it.. And in situations where cross-platform is not needed, why not compile to native and get the extra efficiency? Choice is good.

      Its a shame Sun spreads so much FUD about native-compiled Java.

    3. Re:Well gee *that* makes sense.... by shrdlu · · Score: 3, Interesting
      What's the point of taking a language that jumps through hoops to be "cross-platform" and cutting it's legs off?

      It seems like you might not have read the article all the way through. It doesn't recommend only native compilation, but it does make a nice comparison between the two solutions. It points out when you might want to take advantage of native compilation, and when it doesn't help. You are always free to generate byte code in addition.

      Much of the work I do would be nicer and easier in Java than in other languages, but Java is just too slow and large for my purposes. This gives me the chance to use a language that has a little elegance, without giving up the speed of execution that I require. C++ just doesn't cut it, and it's tough trying to write this kind of code in C (but not impossible, it just takes a little discipline).

      Java isn't really cross platform anyway. Where's the JVM for MVS?

      --
      The difference between a Miracle and a Fact is exactly the difference between a mermaid and a seal. (Mark Twain)
    4. Re:Well gee *that* makes sense.... by thomas.galvin · · Score: 4, Insightful

      The point of the article is that if you have a large, slow Java application, you can compile to run natively on a given platform to increase it's speed and reduce the disk and memory requirements

      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.

    5. Re:Well gee *that* makes sense.... by NickDoulas · · Score: 3, Insightful

      I agree. I think there are still a ton of benefits to Java without it being interpreted.

      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.

    6. Re:Well gee *that* makes sense.... by egomaniac · · Score: 4, Informative

      What VM are you using? I haven't seen a significant problem with moving apps between machine architectures since Java 1.3 came out.

      I do most of my development on a Windows box, and deploy to Solaris and Linux. It's been years since I've seen a bug only manifest on one of the three systems.

      --
      ZFS: because love is never having to say fsck
    7. Re:Well gee *that* makes sense.... by MisterBlister · · Score: 3, Insightful
      Try rereading my message.

      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)?

    8. Re:Well gee *that* makes sense.... by clare-ents · · Score: 3, Informative

      Exactly my experience, I've written a set of Oracle database administration tools with image display & mp3 playing capabilities, they were developed under Linux and run out of the box under Solaris, NT & OSX with a 1.3 runtime.

      I haven't had a single cross platform problem, the one component written in Perl/Tk has caused no end of grief though.

      --
      Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Einstein)
    9. Re:Well gee *that* makes sense.... by gorilla · · Score: 2

      There is nothing in theory stopping RMI from working even if the two ends are running two different languages. As long as there is a well defined API, where each end can understand the paramaters sent & received, then it makes no difference what the languages are. A good example of this sort of thing working would be COBRA, which allows basically any language to call methods in remote subsystems.

    10. Re:Well gee *that* makes sense.... by big_hairy_mama · · Score: 2

      This has to be a troll or flaimbait, because that is just plain not true. The only problems Java has running cross-platform are certainly not related to binary or bytecode, they are if you use native libraries or don't do your file-system access correctly.

    11. Re:Well gee *that* makes sense.... by ttfkam · · Score: 2
      C++ just doesn't cut it, and it's tough trying to write this kind of code in C (but not impossible, it just takes a little discipline).

      What exactly can C do that C++ can't? C++'s std:string ends up comparable to C and char* in speed. C++'s standard quicksort algorithm is faster than C's (not as fast -- faster).

      Instead of taking "a little discipline" with C, why not spend some effort with a more advanced language?

      --

      - I don't need to go outside, my CRT tan'll do me just fine.
  2. What about Java's safety advantages? by Ryu2 · · Score: 3, Interesting

    Runtime bounds checking, typecast checking, etc... do those get included in the native executable as well (and if so, then wouldn't the performance hit negate the advantages gained thru native compilation?), and if not, then it could be dangerous.

    --
    There's 10 types of people in this world, those who understand binary and those who don't.
    1. Re:What about Java's safety advantages? by andres32a · · Score: 2

      Actually i believe tha implementing Runtime bounds checking, typecast checking and so on wouldnt be easy to include un the native executable... as said in the article :
      Diagnostic tools can be somewhat thin on the ground, which makes it potentially more difficult to diagnose problems that occur in natively compiled Java apps (particularly if the error doesn't occur in the Java bytecode version!)

    2. Re:What about Java's safety advantages? by tommck · · Score: 2
      C++ has typecast checking (if you use dynamic_cast()) it does not have runtime bounds checking on basic arrays, but it does if you use STL containers.


      I don't see where there's a problem. It's all just code. It gets compiled. End of story.

      T

      --
      ---- It puts the lotion on its skin or else it gets the hose again. It does this whenever it's told.
  3. Re:Oh, it's there, alright by number+one+duck · · Score: 2

    I've seen a few php 'compilers' that do the same thing. They basically jam the executable and the script together in a self extractor, and let them sort themselves out... slowly.

  4. Finally! by tulare · · Score: 2

    This would solve my greatest beef with Java - that messy JVM which piles into the processor when it compiles bytecode. Of course, the idea of running Java natively seems to defeat the purpose of Java entirely: runs the same on any computer. Interesting idea, though...

    --
    political_news.c: warning: comparison is always true due to limited range of data type
    1. Re:Finally! by PD · · Score: 2

      Garbage collection in an interpreter or virtual machine might be a big factor, I don't know. But I do know that garbage collection in compiled code does not need to be slower. Either you've got to free the pointers manually, and do the bookkeeping yourself, or the collector has to do it. The workload is the same either way.

      Check out the Boehm conservative collector and read what Hans Boehm has to say on the subject. I think he qualifies as an expert, since he is a mind behind both the Boehm collector (free beer and speech) and the Great Circle collector (proprietary).

  5. Not new ... ho hum by Evil+Pete · · Score: 5, Insightful

    Lets see TowerJ has been out since when ? 1999. Having tried my hand at this I have some reservations. The project I was on ... a large dinosaur of a thing which will remain nameless had 12,000 classes which TowerJ turned into C files which were then compiled by GCC. Resulted in 50 megabyte executables on a Sun. Didn't really solve the problem which wasn't really about speed but throughput. The solution was a better design using servlets and Java Webserver ... result DRAMATICALLY faster without any need for native compilation.

    Mind you I noticed in the IBM article that the memory footprint was much smaller. That might be nice.

    --
    Bitter and proud of it.
    1. Re:Not new ... ho hum by tommck · · Score: 2
      Come on! Generating C++ classes is NOT a decent way to compile.

      I vehemently agree that design is often (not always) the solution for speed issues. PHBs, though, see the possibility of buying a tool for $X that will immediately give the app a Y% increase in speed and they'll jump on it every time

      T

      --
      ---- It puts the lotion on its skin or else it gets the hose again. It does this whenever it's told.
  6. AWT support a must by Coulson · · Score: 5, Insightful

    Most notably, there is very little support for AWT, making GCJ unsuitable for GUI applications.

    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!

    1. Re:AWT support a must by addaon · · Score: 4, Informative

      Having used JET somewhat extensively, I can say that Swing works beautifully in it... exactly as you'd expect, and at a reasonable speed, to boot. It doesn't make small applications, but it optimizes relatively heavily. There's more than hope: it's already there!

      --

      I've had this sig for three days.
    2. Re:AWT support a must by Augusto · · Score: 2

      Interesting, they have a free eval version, I'm going to try that.

      Do you know if they plan to provide 1.4 support anytime soon ?

      --

      - sigs are for wimps.
    3. Re:AWT support a must by be-fan · · Score: 2

      You know the sad thing? These days GNOME and KDE have become so bloated that Limewire's Java GUI runs almost as fast as most KDE or GNOME apps on my PII 300.

      --
      A deep unwavering belief is a sure sign you're missing something...
  7. Benchmarks by Andrewkov · · Score: 3, Interesting

    The program used in the benchmarks was very simplistic .. I would rather have seen a program creating and destroying many objects of various sizes. In the nativly compiled version, how does garbage collection work? Is it possible to write AWT apps? Swing?

    1. Re:Benchmarks by jsse · · Score: 2

      The program used in the benchmarks was very simplistic .. I would rather have seen a program creating and destroying many objects of various sizes. In the nativly compiled version, how does garbage collection work? Is it possible to write AWT apps? Swing?

      and string processing too! It's a well-known performance handicap for java. SUN is heading the right direction to improve the performance of it in each version, I wonder how well IBM would perform in this battle? :)

    2. Re:Benchmarks by snowman153 · · Score: 2, Informative
      Some links to more extensive native compiler benchmarks:

      Osvaldo Pinali Doederlein.
      The Java Performance Report - Part IV: Static Compilers, and More. August, 2001

      The Java Performance Report is an independent study of Java performance, where both virtual machines and static compilers are evaluated. Part IV compares Excelsior JET and two other static compilers with Sun's HotSpot Server VM.

      Volano, LLC.
      The Volano Report. Dec 26, 2001

      The Volano Report covers VolanoMark(tm) - a widely recognized pure Java server benchmark characterized by long-lasting network connections and high thread counts. This report includes Excelsior JET a native compiler.

      Excelsior JET Benchmarks

      From Caffeine and SPECJVM through XML Transformations to Java2Demo and VolanoMark.

  8. Speed isn't the advantage of GCJ by Ondo · · Score: 2, Insightful

    The big advantage of GCJ isn't speed, it's the vastly better interface to C++ code (CNI vs. JNI). Of course, using that really does make your code non-portable.

  9. Speed improvements very noticeable in PDAs by Bigger+R · · Score: 5, Informative

    Good progress is being made in native compiler for Palm OS. See http://sourceforge.net/projects/jump/

    and also http://www.superwaba.org for info on the related JVM for PDAs that it replaces.

    Good stuff.

    --
    Beta only seems to work for Google. Such a shame.
  10. Garbage Collection Question by adamy · · Score: 3, Interesting

    Seems to me the problem with Java is that it waits until memory is full to garbage collect. In C++ Code, if you allocate and free a lot of memory, eventually you are going to fragment your memory to the point where you may not be able to allocate large enough memory blocks for your purpose. GC is supposed to get around that. But if C++ doesn't GC, how can a C++ app run indefinitely. I would really appreciate someone who understands the subtle nuances to explain. If there are better memory allocation schemes, couldn't you use them until you were forced to use GC?

    --
    Open Source Identity Management: FreeIPA.org
    1. Re:Garbage Collection Question by dstone · · Score: 3, Informative

      I would really appreciate someone who understands the subtle nuances to explain.

      Bruce Eckel explains some different approaches to GC, pros and cons, etc., especially as it relates to Java. Check out Thinking In Java 2nd Edition, pp. 207-219. You can download it here.

    2. Re:Garbage Collection Question by FastT · · Score: 2
      Seems to me the problem with Java is that it waits until memory is full to garbage collect.
      Your information is out of date. See the information on the HotSpot VM and its use of generational GC. Essentially, short-lived objects are GC'd frequently.
      --

      The only certainty is entropy.
    3. Re:Garbage Collection Question by hding · · Score: 3, Informative

      A good source for starting to address all of your garbage collection questions is Jones & Lins' book, Garbage Collection : Algorithms for Automatic Dynamic Memory Management. Another good source is The Memory Management Reference

  11. AmigaDE, Savaje, Symbian and Jeode by Quizme2000 · · Score: 3, Interesting

    I was a little disappointed in the selection of the the JVM's they selected for their example. Especially now that PDAs/CellPhones are now powerful enough to run real applications on the client. I have yet to see a StrongArm device ship with the Sun, IBM, or KaffeJVM, why, because they are slow. The JVMs listed in the subject line run 10-200x faster on devices. Soon we will see EJB and other J2EE compents on PDAs. As a developer of client java applications/applets I would never distribute a device specific application, it would be a nightmare to have 160 diiferent compiled versions of the same application. The good JVMs already have done that, and my code I compiled years ago works on the newest PDAs...So there

    --
    "Get them before they get....
  12. Re:What happened to Sun's Java chips? by dstone · · Score: 3, Interesting

    Dallas Semi makes the TINI, a Java implementation in hardware packaged as a 72-pin SIMM stick. I have one and it's cheap and fun to program. Built-in ethernet, general purpose IO pins, etc.

    Go here for more info.

  13. Re:It's about time! by angel'o'sphere · · Score: 3, Informative

    I was waiting for this to happen.

    Man, JAVA to native compilers exist since 1996 or even earlyer.

    Symantec Visual CAFE did it from the first release.

    If you enter "+java +native +code +compiler" into altavista.com, yahoo.com etc., you find at least 20 solutions providing that.

    The problem is: a java application on linux is no longer able to communicate via RMI or object serialization etc. with an other java application on Solaris or any other OS. You loose reflection support and similar low level access to the runtime environment.

    Its a common myth that java is (to)slow ... the way to compile it to native code exists since 3 month later since java was widely adopted.

    There is even a GNU implementation of a java to native code compiler, since ... 3? years?
    ---> gjc

    Regards,
    angel'o'sphre

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  14. Re:It's about time! by bugg · · Score: 3, Insightful

    Operator overloads make it *way* too easy to write code that is difficult to follow. The ability to add, subtract, etc. objects *rarely* makes perfect sense when you consider everything that the object represents. Really, the lack of operator overloads is not a big deal, perhaps even an advantage, if you ask me. (IMHO)

    --
    -bugg
  15. Another weak study... by Alea · · Score: 5, Insightful

    I'm not going to try to champion Java, JITs, or native compilation, I'm just going to point out what's wrong with this "study".

    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

    1. Re:Another weak study... by dvdeug · · Score: 4, Informative

      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.

      It goes straight from source to native; for one thing, the source format exposes stuff that allows it to be more heavily optimized by GCC's optimizer than the bytecode format does.

    2. Re:Another weak study... by dvdeug · · Score: 2

      Context: GCJ compiles Java source better than bytecode.

      All you say is true, however it is merely a flaw in the current GCJ implementation.

      A completely optimizating compiler solves the halting problem as a side effect. Hence, any real compiler has places where it can optimize better.

      There are only so many compiler writers working on GCJ and many improvements that can made. IMO, the normal mode of GCJ is feeding your own source to it, so their time could be better spent improving the libraries and overall optimization rather then something that's more flashy than useful.

    3. Re:Another weak study... by dvdeug · · Score: 2

      I dont know about where you live, but in the unvierse in which I reside, the halting problem has no solution.

      Right. Read what I said again.

      A completely optimizating compiler solves the halting problem as a side effect. Hence, any real compiler has places where it can optimize better.

      Or, more formally, a completely optimizing compiler implies a solution to the halting problem. Since there does not exist a solution to the halting problem, there does not exist a completely optimizing compiler.

  16. beos developers.. by Suppafly · · Score: 2

    With the renewed interest in beos thanks to the leaked 5.1/dano release, developers for beos should seriously consider trying for a native compiler since the various jvm projects arent going anywhere fast. If beos could run java apps, I could see this renewed interest continue to grow at amazing rates..

  17. New name... by SlashChick · · Score: 2, Funny

    "...compiling Java apps to run as native appplications on the target machine without the need for a JVM."

    In other news, they have also decided on a name for this wonderful new technology: C.

    1. Re:New name... by FastT · · Score: 2
      they have also decided on a name for this wonderful new technology: C.
      In other news, computer scientists have developed a way to preserve all the flaws of assembly language without having to remember those pesky 3-letter pneumonics. They have also decided on a name for this wonderful new technology: C.
      --

      The only certainty is entropy.
    2. Re:New name... by FastT · · Score: 2

      At last we agree. I'd no more use Java to write an OS than I'd use C to write a real-world application.

      --

      The only certainty is entropy.
  18. VM: a definition by fm6 · · Score: 5, Informative
    In a previous life, I sat in a corner taking notes while around me, engineers designed Java VMs. The experience didn't make me into a real expert, but it did make one thing clear: there's no such thing as running Java without a VM.

    People think of the VM as an interpreter that executes the bytecodes. That's a particular implementation of a VM. And not a very good one -- which is why no production VM works that way.

    The simplest optimization is to use a JIT. This gives you native execution speed once the class files are loaded -- but loading is slower, because it includes compiling the byte codes. You can end up wasting a lot of time compiling code you'll only execute once -- most programs spend 90% of their time in 10% of their code. Depending on the application, you can end up wasting more time on unnecessary compilation than you save by running native code.

    Intuition suggests that the most efficient thing to do is to "get rid" of the VM by compiling everything to native code before you distribute your app. But that doesn't get rid of the VM -- it just converts it to a different form. There are some VM features you can't compile away, such as garbage collection. Some experts claim (not me, I get dizzy when I even read benchmarks) that "pure" nativeness is illusory and not that efficient. Plus you lose a lot of the features of the Java platform when you run the program that way. Might as well stick with C++.

    Some VM implementations use a sophisticated comprimize between interpreters and JIT compilers. If you can identify the small part of the program that does most of the actual work, you know what parts of the program really need to be compiled. How do you do this? You wait until the program actually starts running!

    Advocates of this approach claim that it has the potential to be faster than C++ and other native-code languages. A traditional optimizing compiler can only make decisions based on general predictions as to how the program will behave at run time. But if you watch the program's behavior, you have specific knowledge of what needs to be optimized.

    Computer science breakthrough, or illogical fantasy? Don't ask me, I'm just a spectator.

    The engineers I picked this stuff up were very contemptuous of "microbenchmarks" like those described in the developerWorks article. Nothing to do with the real world.

    1. Re:VM: a definition by fm6 · · Score: 2

      Not the most imaginative troll.

    2. Re:VM: a definition by spiral · · Score: 2

      > ...there is nothing to stop a profiler from being built into a C/C++ compiler.

      While profile-driven optimizing compiler are interesting, I think you're missing the point here. With a profiling JIT, the information is gathered and used at runtime, not compile time. That means that you're optimizing for THIS run, not some run that you hoped was representative at development time.

      For a bogus benchmark, the two approaches are effectively identical -- each benchmark run presumably runs exactly the same code as the last. The compile-time profiler would win simply because it doesn't add any runtime overhead. In an interactive application, say GUI or a game, you can't really predict what functionality any particular user will stress.

      Of course, for added fun, the two approaches don't have to be mutually exclusive. There's no reason you can't find and improve many of your code's hot spots at development time, and then let the JIT do its thing at runtime.

      --
      Drinking will help us plan!
    3. Re:VM: a definition by scrytch · · Score: 2

      Intuition suggests that the most efficient thing to do is to "get rid" of the VM by compiling everything to native code before you distribute your app. But that doesn't get rid of the VM -- it just converts it to a different form. There are some VM features you can't compile away, such as garbage collection.

      Where did you pull this assertion out? It's rubbish. Eiffel and Ada are garbage collected out of the box. C and C++ can be by just linking code to a different library. The 'V' in VM stands for Virtual. There is no virtual machine being used, it is using the real machine. Real registers, real opcodes. In fact, gcj compiles down to what amounts to C++ (the object layout is the same)

      Some experts claim (not me, I get dizzy when I even read benchmarks) that "pure" nativeness is illusory and not that efficient. Plus you lose a lot of the features of the Java platform when you run the program that way.

      Partly true on both counts. A VM has some known constraints that lends utsekf to optimization. Pointers in C and C++ for example create potential aliasing problems that just don't exist in Java. However, a good native compiler (not a merely adequate one like gcc) can do instruction ordering that a VM cannot. Bytecode has advantages like portability, and with clever classloaders, you can do all kinds of wizardry to objects by rewriting the bytecode. Not every app needs these features however, and so native compilation is also a compelling option. Native compilation also gains you the capability of using more native features efficiently. Case in point, JNI is slow -- Macromedia Generator is largely a Java scaffold around C++ components, so it uses JNI extensively. Turns out to be slower than an alternative written in pure java.

      --
      I've finally had it: until slashdot gets article moderation, I am not coming back.
    4. Re:VM: a definition by AtrN · · Score: 2

      While I agree with "Where did you pull this assertion out?" the follow up doesn't go far enough. People are forgetting that languages have models of data and regardless of translator and execution style you need to implement the language's data model. For Java this means objects with GC. VM or real-M.

    5. Re:VM: a definition by fm6 · · Score: 2

      You read it. Your jealousy is almost tangible!

    6. Re:VM: a definition by fm6 · · Score: 2

      Hey, don't be so sensitive. It's not your fault I'm slow.

  19. The article misses some key points by kaladorn · · Score: 5, Informative

    First, I have to identify that we (my company) do use the JET byte->native compiler by Excelsior. Good product, I've recommended it to others and they've had success with it too. In our case, it produced a 10-15% speed increase, some in-memory size savings, and it had one huge advantage missing from the byte code: SECURITY!

    After experimentation, I'm pretty convinced that the decompilers on the market that work on obfuscated byte code KICK THE CRAP OUT OF THE OBFUSCATORS. The long and the short of it is the decompiled code is pretty decipherable.

    If you want to protect your IP (Intellectual Property), that's not a good thing. In fact, that might be (if you are in a competitive arena) a VeryBadThing(TM). The native code (especially optimized native code) is far harder to effectively decompile into something usefully readable which crackers and script kiddies can abuse or which competitors can peruse. This benefit alone makes it worth going this route if you can.

    One of the other things the article missed:
    It didn't devote much thought to the settings and optimizations these compilers provide. The Excelsior compiler (by example, I looked at Bullet Train and some others before we picked Excelsior) provides ways to disable certain safety checks (like array bounds checks) for extra speed. If you're in a fairly aggressive environment with some pretty significant timing issues (I won't say hard realtime, because anyone doing hard realtime should be using something like QNX), you will find that even these small gains may be useful (and the risks they introduce acceptible). But the article didn't even hint at these possibilities.

    So, if you want to build something that is less likely to be cracked or examined, this type of tool is the way to go. Excelsior, for example, is fairly easy to setup. I did get some help from their guys, but only because our product includes OpenGL, QuickTime, a bunch of XML parser stuff, DirectX, sound support, UI, etc. - a whole pile of external dependencies. The buddy I recommended it to had his project up in going in half an hour or so, with a more modest project (but still a useful, full fledged app with GUI).

    Undoubtedly, these won't solve all your ills and they may introduce some new difficulties in bug hunting (though some of the new debuggers coming out with these products are very neat also). So you will want to look at what you need, what your concerns are (security, speed, cross platform deployment, etc) and decide accordingly.

    --
    -- Mal: "Well they tell you: never hit a man with a closed fist. But it is, on occasion, hilarious."
    1. Re:The article misses some key points by _xeno_ · · Score: 3, Interesting
      After experimentation, I'm pretty convinced that the decompilers on the market that work on obfuscated byte code KICK THE CRAP OUT OF THE OBFUSCATORS. The long and the short of it is the decompiled code is pretty decipherable.

      That's probably because there's really no way to obfuscate Java byte code, since it's all java.lang.reflectable anyway - you can use Java code to dynamically load a class name at run time and then discover methods it contains and public variables it has.

      As far as I know the .class format in essense requires methods and class variables to be determinable makes it fairly hard for Java to be "secure" when it comes to making code hard to disassemble. Especially because all your classes wind up being one-class-to-file and by default end up with the names of the classes and the package structure laid out in the directories created...

      Sun may want to consider creating a secure JAR file which is loaded by a "secure" class loader that prevents reflecting, but a lot of cool stuff can be done with the reflect interface (like loading plugin classes at runtime).

      Bottom line is that every .class file contains a list of all methods and public variables as well as being one instance of an original class definition - not useful for making your program structure hard to dissassemble. However, the ability to determine methods and load classes at runtime can be useful to. (As well as required for Java's RMI, I think - I might be wrong, though.)

      --
      You are in a maze of twisty little relative jumps, all alike.
    2. Re:The article misses some key points by LadyLucky · · Score: 2, Interesting
      KICK THE CRAP OUT OF THE OBFUSCATORS.

      This is not the case anymore. An example is Zelix Klassmaster. We use it for our java web application. No decompiler can cope with it. The decompiled code is littered with byte code that it couldnt work out what to do with. I wrote the code, and I cannot for the life of me work out which methods are which in the decompiled after obfuscated classes. They also do things like String encryption so even string constants are unrecognisable.

      Java is certainly not perfect in this respect, but my experience with obfuscation (this is very recent) has been very good.

      --
      dominionrd.blogspot.com - Restaurants on
    3. Re:The article misses some key points by (H)elix1 · · Score: 2


      After experimentation, I'm pretty convinced that the decompilers on the market that work on obfuscated byte code KICK THE CRAP OUT OF THE OBFUSCATORS. The long and the short of it is the decompiled code is pretty decipherable.


      Oh man, you are not kidding. One department at the shop I work at holds their source code very close to their chest. It is easier to JAD the class files into java code than it is to go through channels to get a copy of the source. Try it - even on big commercial code like an app server. You will be shocked.

    4. Re:The article misses some key points by kaladorn · · Score: 2

      Huge .dlls? I didn't find the JET embedded JVM to be terribly huge. Of course, our app runs at somewhere between 30 and 60 Mb of memory usage and disk space waaaay beyond that. So I wasn't looking at it for size as a primary concern. The in-memory footprint was smaller than when running the HotSpot VM. The disk space hit just doesn't seem like an issue anymore. But, YMMV. :)

      --
      -- Mal: "Well they tell you: never hit a man with a closed fist. But it is, on occasion, hilarious."
    5. Re:The article misses some key points by kaladorn · · Score: 2

      Yes, I did. You'll note my principal security focus was on the INTELLECTUAL PROPERTY issue, not run-time security. They are very different considerations. Codebase security and system integrity are both valid concerns, but different.

      You'll also note I did not _recommend_ disabling run-time bounds checking, I just pointed out that it is an option if you absolutely NEED THE SPEED. Obviously, you'd have to decide if you were willing to undertake the inherent risks in disabling this kind of check. In some cases, this may be necessary. (Though again, why you'd be using Java in these circumstances is a question - writing MMORPG technology isn't hard real-time though there are serious performance benchmarks).

      BTW, disabling run-time bounds checking on all-arrays does not mean you don't have any security. It just removes the "father knows best" work in the JVM and the compiler into the hands of the programmer. One can still be careful with how one accesses strings (for example using some secure string classes). One does not NEED to have the system do the work for him or her. And there may be times you need every processor cycle. If having the system run-time check array bounds is expensive enough to cause a critical failure in my system, and I can't sell it, then it really doesn't matter how secure it is.

      Also, I'd like to point out that using strncpy() in C and a number of other sensible precautions have existed for years, and C/C++ programmers still _routinely_ don't bother.

      There are two ways to have security: Have the OS do it for you (Do you enjoy the sandbox? Works well, can't do much in it!) or having conscientious and well-trained programmers. Since there hasn't been much emphasis on security in programming courses at Colleges, Universities and trade schools, this lack of attention is scarcely surprising. But is the solution better educated programmers or paternalistic tools? I know which I'd choose, just in case the tool isn't designed to handle something a well educated programmer might catch.

      And BTW, I made an exception this once to talk to an AC. You were motivated enough to comment, so I assume laziness isn't the shortcoming. So I'll have to assume you don't like to stand up for things you say....

      --
      -- Mal: "Well they tell you: never hit a man with a closed fist. But it is, on occasion, hilarious."
  20. Fat-binary? by John+Harrison · · Score: 2
    Back when I first learned Java (1996?) I thought that native compilation would solve some of the speed problems that came with Java. This article makes it look like the speed-up might not even exist. But let me get to my idea.

    I also realized that native compilation would destroy the cross-platform capabilities of Java. So I always thought it would be cool to distribute Java apps with both native compiled code for a specific platform and Java bytecode too. That way if you happened to be running the target platform you could get the speedup. If not you could still run the app, and maybe even compile the bytecode to a native app for your platform. This is similar to the fat-binary idea that Macs used when they switched from 68k chips to PPC, allowing a binary to run on either platform.

  21. My Cynical Take on This: by DaveWood · · Score: 5, Insightful

    I found it interesting that this author, an IBM researcher, chose to only test a single java-to-native compiler, the GCJ (GNU product). This is an immature open-source package that I would not expect much performance from. His paper rehashes a lot of really basic info, then gives some performance results which show IBM's JVM spanking Sun, Kaffe, and GCJ. This is no great surprise; IBM is tooting it's own horn - fine, they deserve to IMHO. But as an exercise in "the state of native compilation" it's useless. What would actually be really useful is a comparison that also included at least a half-dozen other major players in the java native compiler market. I suspect you'd see some different results.

    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...

    1. Re:My Cynical Take on This: by kzeddy · · Score: 2, Interesting

      >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...

      I have yet to be proven wrong that developing using C++ is any harder or time consuming than writing in Java. Arguments for usually revolve around Java's libraries and its garbage collection.
      To that i say Java's libraries are outclassed and outnumbered by the amount of source for C++ and the number of libraries like Boost ,Dinkum, etc for instance. As for garbage collection, I myself have 7 different conceptual collection systems implemented that can be easily integerated into any code you want.
      I can even make the case that developing for C++ is easier given the use of templates. Those who say that Java is easier to program in really don't want to learn the advantages of programming in C++.

    2. Re:My Cynical Take on This: by FastT · · Score: 5, Informative
      I have yet to be proven wrong that developing using C++ is any harder or time consuming than writing in Java.
      From this I deduce that you are either a student or someone in academia, or someone working at a small shop somewhere writing non-commercial or only minorly-commercial software. There is just no comparison when writing large, real world commercial (or even non-commercial IMHO) software. You wouldn't need it proved to you if you saw the misery C++ causes in these situations.
      I myself have 7 different conceptual collection systems implemented that can be easily integerated into any code you want.
      You know, this is exactly what I would expect guys like you to say. You have 7 different ways, the guy in the next cube has 3, my last company had N. This is the problem. Java has this capability built into the system, it works one way, and everyone understands it, both its strengths and its flaws. Same goes for all the other class libraries you mention in you argument.

      The point is, I can come in and maintain someone else's code with far less trouble if it's written in Java than I can if it's written in C++. Same goes for the support engineers. Same goes for customers. If it's written in C++, the application can essentially be a language unto itself. You have different mechanisms for just about any major feature between development teams; none of them are standard, and none of them are even remotely as easy to learn and use as the equivalent Java API. Maintaining these applications costs a huge amount, and is fraught with support issues exactly because there are so many incompatible ways of doing the same thing.

      Your argument is so tired because it doesn't take into account the actual cost of developing real applications--maintenance and support.

      Those who say that Java is easier to program in really don't want to learn the advantages of programming in C++.
      Wrong: Those who say that Java is easier to program in (and who don't know C++) really don't want to learn the disadvantages of programming in C++.
      --

      The only certainty is entropy.
    3. Re:My Cynical Take on This: by FastT · · Score: 2
      I am [sic] yet to see serious desktop application written in Java
      Even if this were true (and it's not), what does a desktop application have to do with Java's viability? I've yet to see a serious desktop application written in COBOL, FORTRAN, or Perl. Furthermore, I have yet to see a serious desktop application written in any language for Linux. What does that say?

      Anyway, with .net and C#, Java is already history
      That's funny, since .net and C# aren't even the present yet.
      --

      The only certainty is entropy.
    4. Re:My Cynical Take on This: by FastT · · Score: 2
      I hate to break it to you, but the COBOL rates are well over $200 an hour. I guess we can both see what that says about the correlation of language obsolesence to billing rates.

      Oh, and by the way, when I used to bill (I left the loser consulting lifestyle behind long ago), I billed $10,000/week for enterprise Java expertise. You do the long division.

      --

      The only certainty is entropy.
    5. Re:My Cynical Take on This: by cheezehead · · Score: 2, Informative

      I have yet to be proven wrong that developing using C++ is any harder or time consuming than writing in Java.

      Hmm. Do you include debugging and maintenance as part of development? I'm sure you can type C++ about as fast as you can Java, but the work doesn't end there. One of Java's advantages is the vast reduction of memory leaks (not elimination, some guys can leak resources in any language...). In my opinion memory mismanagement is largely responsible for the typical C/C++ bug.

      --

      MSN 8: Now Microsoft even has bugs in their ad campaigns.

    6. Re:My Cynical Take on This: by myelin42 · · Score: 2, Insightful

      I know I'll get flamed for this, but ...

      If you want to use templates as well as garbage collection, you might like Managed C++, the .NET version of C++.

      It'll let you code in C++ (with templates etc) but also use garbage collected arrays etc, and the .NET class library.

    7. Re:My Cynical Take on This: by FastT · · Score: 2, Insightful
      The difference is that FORTRAN and COBOL are not even in this race while Java is right there trying to compete with C++.
      That's an interesing point. It's certainly the perception, anyway. You can't write an OS or device driver in Java, but you can in C/C++. You can write an application in C++, but should you? It used to be that C++ was the only game in town for application development. It's what programmers knew, and the APIs they needed from the OS were written in the same language. It's great for writing low-level things, or things that need absolute speed, but it certainly doesn't excel over other languages for building apps, especially networked apps. Delphi/Pascal, VB, and Java are all better choices there. Why that's a problem for some people, I don't know.

      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.

      --

      The only certainty is entropy.
    8. Re:My Cynical Take on This: by Wraithlyn · · Score: 2

      Well actually, with inner classes, there's no limit to what you can do with a single file.

      (Mind you, these all compile to separate class files)

      --
      "Mind, as manifested by the capacity to make choices, is to some extent present in every electron." -Freeman Dyson
    9. Re:My Cynical Take on This: by Pfhreakaz0id · · Score: 3, Informative

      That's funny, since .net and C# aren't even the present yet.

      Ummm, you might want to check your facts on that one. .NET has shipped. (at least, visual studio.net and the .net framework). You can download the release of the compiler and the SDK on MSDN.

      Of course, you didn't hear about it here, since slashdot refused my story. I guess the release of a brand new API the largest software company in the world has been working on for years isn't "news for nerds". Download the runtime/compiler here or the full sdk here

    10. Re:My Cynical Take on This: by Bodrius · · Score: 2

      The problem with C++ is not that it is harder to write good code, but that it's easier to write bad code, apparently because of its C-ness.

      Note that this does not have to do with the difficulty of writing up an object or method. C++ is more time-consuming because it's harder to read (and clean up) other people's code.

      Sure, templates are (were? 1.4?) sorely missing in Java, and that definitely makes the implementation of a lot of algorithms easier in C++. But other language idioms encourage "bad programming practices". Java, as a language, encourages good programming practices and makes some bad practices actually impossible. This price in flexibility pays off in maintainability and other fuzzy buzz-wordy qualities which are the whole point of not writing assembly.

      Even if there's only one person in the team that abuses some of C++ facilities everyone's time is wasted. Since "abuse" is a term relative to the code-reader and not the coder, this would happen very often.

      Then there's the issue of becoming familiar with the pletorah of libraries that exist for C++. The good thing about the Java libraries is not their amount, but the fact they're part of a standard (licensed) distribution of the language. Therefore, everyone uses them unless they have a very good reason not to, which makes it easier to read other people's code without familiarizing yourself with every library in the market. This is the advantage of the STLs for a much greater problem domain.

      Once more, it's about restricting choice to provide maintainability. It helps if the libraries don't suck (java.lang, java.util), it hurts if they do (java.awt, javax.swing).

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
  22. What does native compilation gain me... by stph · · Score: 4, Interesting

    These kinds of articles raise more questions than they answer. I have to ask what does Java native compilation gain me? Martyn writes in the article that performance and memory consumption were basically a wash on the more complex app, so what are the other considerations that might drive me to use a native compiler?

    • Does it make programming in Java easier? Not really. Most of my development environments for Java would take serious tweaking to get something like gcj to work. And somethings, like WebObjects where much of my stuff has to run might never be made to work with native code.
    • Does it make debugging easier? Now this might be a useful avenue to explore. Debugging an app that works in one JVM but not the other(s) can be a serious pain. I do a fair bit of developing on a PC and deploying on a Linux server, where the former has Sun's JVM and latter uses IBM's JVM. Maybe native compilation would help solve that, especially if you could hook back to the source code. Without source support, though, it would be troublesome.
    • Can I support my customers more efficiently with native compilation? I don't see how native compilation would make this easier. Instead of JVM differences, now I have hardware differences.
    • Does it reduce the load on my servers when I fire up these applications? We get a lot of individual JVMs running on our application servers when they are loaded up with lots of multithreaded apps and other such things. It is possible that the total footprint across a bunch of threaded apps would make this a compeling reason to explore, but Martyn's article doesn't really address that issue. Of course, our JVM proliferation could be the result of the various frameworks we're plugged into: WebObjects talking to DB2 and SQL Server databases.

    Native compilers have been here for a long time and they haven't really taken off. They either need to offer something absolutely necessary that I can't get via regular Java compilation and runtime, or they need to offer performance improvements that are orders of magnitude better than what we already have. If the vendors can do that, then I want to talk to them. Otherwise it's just another experiment in an already too busy world. Stph

  23. Re:Java's Cover by borzwazie · · Score: 2
    Having worked for the Gov't I think I can tell you why the DoD loves it's plans and protocols so much, as you put it:


    If your programming mucks up, the wrong people DIE. If you don't have standards that are _rigorously_ abided by, our soldiers DIE. The US military and the rest of the gov't prides itself on it's technological edge. It relies on on structures that are there NOT to screw up (ask a space shuttle computer programmer about standards sometime).


    At the risk of responding to a troll, I'd like to point out to the parent's moderators that there's a reason for "bureaucratic" programming.


    Probably the reason the DoD likes Java (if they do, I don't know for sure) is that it's well documented, has a wealth of libraries, and reasonably safe (secure) out of the box, even in the hands of someone relatively inexperienced with secure coding standards.


    To get back on topic, I've tried native compilation of Java code...I'm not really sold on it. On higher-end machines, or machines with goodly amounts of ram, Java's no stinker. The upcoming 1.4 from Sun promises neat stuff like 2D acceleration. No 2D accel is one of the reasons why redraws feel relatively slow now. Plus, speeds of JIT's are increasing to the point at which I'm not sure I'd want to give up platform independence. If anything, this is probably useful to the handheld crowd, more than any other platform.

    --

    "We apologize for the inconvenience."

  24. Re:Java's Cover by _xeno_ · · Score: 2, Flamebait
    It's still a useless bit of fluff - based on observations about the language and not projects that are actually using it.

    Small list of open-source Java projects:

    • Jakarta - the Apache Software Foundation's primary Java development site. Most notable are their Tomcat and Ant projects.
    • Xerces - a pure-Java XML parser (there's a C++ version too) - also by the Apache Software Foundation.
    • jEdit - pure Java text editor. Very powerful and easily extensible with Java plugins.
    • Over 4000 projects at SourceForge.
    • Freenet - the idea behind the network has gotten a lot of publicity, it's client is written in Java.

    There's quite a community based around Java - I would suggest people start looking at those aspects of its cover.

    --
    You are in a maze of twisty little relative jumps, all alike.
  25. I'm the biggest expert here, listen to me! by trance9 · · Score: 5, Insightful

    Lots of experts here.

    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!

    1. Re:I'm the biggest expert here, listen to me! by trance9 · · Score: 2

      Whatever.

      I've been writing Java code for five years. I've put some of my code into high performance situations. I've put some of it into high availability situations. I've written stuff quickly under pressure, and also other things that I took time to develop. I've worked on opensource projects (webmacro, now running AltaVista, is java) and after all that time, and all that experience, I just don't think I know enough about it to say "JAVA SUCKS! IT MUST DIE!" or to say "JAVA IS GREAT! GIVE UP ON C/PERL/XXX RIGHT NOW!"

      Sometimes it's been difficult to get what I need to do done, or to make it fast, or reliable enough. But I've always managed to do it, and I haven't found my life any more or less difficult than when I wrote C++ or PERL. I tend to find that Java fits the work that I have to do, but I can see quite clearly that it doesn't fit other work.

      I wish that on slashdot the size and strength of peoples opinion was somehow proportional to their expertise or experience--but unfortunately it's not.

      I came here expecting something interesting and instead found a bunch of technically inaccurate crap coupled with some ridiculous opinions (I really liked the "I learned all I need to know about Java from a bookstore--it sucks!" obviously the voice of experience there).

      It seems the more experience people have the more likely they are to judge that a tool does fit some things and fails to fit others.

      It seems the less experience people have the more likely they are to thump on their favorite bible and insist that the whole programming would should switch to use their favorite tool, and everything else "must die!".

      I'll let you judge whether you think that sounds like the voice of expertise.

  26. Re:It's about time! by gUmbi · · Score: 2, Insightful

    But that same person can just call their Java file deletion function .equals().


    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 .close()

    Jason.

  27. Hold on. by Anonymous Coward · · Score: 3, Informative

    There's a thread about this article over at the gcj's mailing list: here.

    The author chimes in, BTW.

    1. Re:Hold on. by crisco · · Score: 2
      That thread also references this page that has a bit more comprehensive bit of performance testing.

      A quick scan seemed to indicate that Sun's HotSpot, IBM's JVM and GCJ all do very well.

      --

      Bleh!

  28. Bad review by Animats · · Score: 5, Insightful
    The simple case, the prime number finding loops, should have been followed by an analysis of the object code to find out why the native compilation is so slow. Look at the inner loop:
    • for (long test=2; test < i; test++)
      { if (i%test == 0) { return false; }
      }
    If the compiler generates slow code for that, something is very wrong in the compiler.

    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.

    1. Re:Bad review by Stormie · · Score: 2

      for (long test=2; test < i; test++)
      { if (i%test == 0) { return false; }
      }
      If the compiler generates slow code for that, something is very wrong in the compiler.

      According to this message to the GCJ mailing list, it's because GCJ doesn't produce particularly good 64-bit integer math code..

    2. Re:Bad review by Jordy · · Score: 2

      Just as a quick test I decided to build his Java program with my version of Javac and also write a C version that is basically identical with the exception of the time/print calls and variable ordering and compiled it with both GCC and G++ under MacOS X (PPC.)

      Java version: 51250 ms
      C version: 6392 ms
      C version compiled with G++: 6412 ms

      If GCJ can approach even half the performance of G++ in the future it looks like it'll be a complete win over Javac. As I understand it, Apple's version of Java is quite good, but the two just don't compare.

      --
      The world is neither black nor white nor good nor evil, only many shades of CowboyNeal.
    3. Re:Bad review by Florian+Weimer · · Score: 2

      AFAIK, the GNU Ada compiler is not too bad on eliminating unnecessary bounds checking (array bounds checking usually only adds a penalty of a few percent), so something can be done even in the GCC context.

      BTW, I would expect that gcj-compiled Java applications start much more quickly than entire VMs. The comparison doesn't seem to take this into account.

    4. Re:Bad review by kenthorvath · · Score: 2

      Actually, that is a pretty bad algorithm for factoring primes. You can get at least a 50% performance increase by testing 2, starting at 3 and then incrementing by 2. You can gain another 50% by stopping at test=floor(sqrt(i)).

    5. Re:Bad review by Animats · · Score: 2
      it's because GCJ doesn't produce particularly good 64-bit integer math code..

      Ah. That's surprising, though, because GCC was one of the first compilers to do 64-bit integer operations in the x86 FPU, which has good 64-bit integer capability. Why didn't that get used for Java?

    6. Re:Bad review by Karellen · · Score: 2

      Duh!

      1) Factoring primes is easy. I can factor any prime you care to name in my head in no seconds flat.

      2) The algorithm is a test of how quick the code is to run, not how quickly you can produce primes. If they made a better (say 2 times as quick) algorithm, but wanted to eliminate startup and shutdown costs as much as possible, they'd make the loop longer (say twice as long) to get the same amount of runtime.

      --
      Why doesn't the gene pool have a life guard?
  29. Re:Some thoughts... by the+eric+conspiracy · · Score: 2

    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++.

    Hmmm.. It would seem to me that some run-time dynamic binding features present in a JVM would be lost in a native code compilation.

  30. Java for servers by Nick+Mitchell · · Score: 2, Insightful

    Java, in the form of EJBs and servlets, is becoming fairly common on "big iron". One reason is indeed the cross-platformability of it. But, frankly, most often a change in platform accompanies a change in framework. For example, a switch from UNIX servers to a mainframe may accompany a switch from CGIs to an application server (such as Websphere). The dramatic switch here is probably not from UNIX to OS/390 (after all, OS/390 has a POSIX layer), but from CGIs to Websphere. So, as you said, it's not really cross-platformability which is driving Java in the server realm. I think the principal reason is that Java provides (at least some semblance of :) a language-level security model. By security, I don't mean crypto and virii and external attacks. I mean an application is secure from itself, and its (all too human) programmers.

    1. Re:Java for servers by CrazyLegs · · Score: 4, Interesting

      I agree with your points, mostly. The company I work for has a TON of function implemented on Websphere running on AIX. We really haven't cared too much about cross-platform features (do a bit of sharing between NT PC apps and Websphere AIX). We were an early adopter of Java because it seemed to address a lot of issues we had in developing C++ and Smalltalk apps (e.g. packaging, garbage collection, change mgmt, etc.).

      However, we are planning to move our Websphere AIX implementation (for EJBs anyways) to an IBM390 box (or Z Series these days I guess) and we've found the proof-of-concept effort easier than we anticipated - simply because we can pickup our code (in JARs) and run it on big iron. Very nice! It also gives us some encouragement that we can really start to share more Java classes/components between browser-delivery and fat-client environments if we're smart about it.

      Anyways, just one experience that's worked out...

      --

      CrazyLegs

      "Pork!!" said the Fish, and we all laughed.

  31. IBM JRE is surely the winner....but wait.. by jsse · · Score: 3, Interesting

    It's being done by IBM, anyone would think it's biased? :)

    Don't get me wrong, I'm a big fan of IBM, and IBM has really, really made a JDK multi-times out-performing SUN's JDK.

    However, I'd believe the selection of 'opponents' are simily..unfair. :)

    Kaffe is surely an easy-pick. Yes it's the only GPL JDK out there but many people(at least Java developers here) would avoid kaffe as it has a fatal security flaws that kaffe team doesn't seem to want to solve it. :/ (We call Kaffe 'MS' JDK'2, not just for humor, but it's really the case. ^_^)

    Even the GNU people know gcj is slow, even GNU guys know it; but speed is not a real issue for gcj, it's basically a starting point for all implementation - or reference implementation as we like to call it. We would pick a commercial java compiler if we need it.

    SUN's JDK, well...you know what I think it just what you think - IT'S SLOW! Yes, we all know that. :D

    Nevertheless I think developer's work is doing a great job here, it confirms something everybody know - that IBM's JDK is fast, and that's it. I don't see it could conclude the performance of native compiled java programs. Unless they include all other commercial java compilers into testing, I wouldn't think we have reached a conclusion yet. :)

  32. Re:It's about time! by borgboy · · Score: 2, Insightful

    A common complaint of people writing in a language that lacks feature x is to declare feature x useless or dangerous. Operator overloading makes sense in certain situations, especially where math semantics are being modeled.
    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.

    --
    meh.
  33. Java Native Compilation by PRR · · Score: 4, Interesting

    One of the best articles on native compilation is this performance report

    Also see on Javalobby the The "native compilation" myth and RFEs for JDK1.5 threads which discuss native compilation.

    Yes, there are some companies like Jet and Jove (and GCJ) making native compilers, but I'd like to see a company of the clout of Sun (or IBM) make native Java compiling more accessable by having a "javac -native" option with their JDK and a smaller standardized runtime (instead of the full JRE) specifically for native compiled apps. The most likely target for native compiled apps running w/o a JVM would probably for the client/desktop side which don't have the resources of server boxes. Remember... it would be an OPTION in the JDK... the old bytecode compiling for VM/JIT would still be there.

    It's arguable whether the runtime performance of a native compiled app would be substantially better than JIT compiled (if some of the Hotspot tricks were moved upstream into the JDK compiler?), but there are also other advantages, such as a faster startup time (no need to startup a VM processes and JIT compile) better memory usage (no need for VM process as well as the meta data and bytecode which must be held in memeory). There would also be some drivespace savings as the full JRE wouldn't be needed (though at this time, a developer can't include a partial runtime, Sun wants the full thing if they include one... Sun needs a change of heart and make a standardized smaller runtime for native apps). Also, with native binaries an obfuscator (used for btyecode classes) isn't needed for commercial apps for those who want to keep their code proprietary.

    There are lots of suggestions going around for the VM/JIT issues such as loading the VM at bootime, a singular shared VM, and JIT caching. These workarounds aren't neccesary with JVM-less native compiled apps.

    Of course, there are WORA extremists who don't like this idea of native compilation because it goes against the dogma of only needing to compile ONCE and run on any OS with a JVM. IMO, as long as the source stays the same, compiling natively for different OS's is still pretty near to the WORA ideals. The Java language is VERY tweaked for portability as-is. It's the OPTION of native compiling that should be available in the Sun or IBM JDK.

  34. either embed the jvm or the compiler - you choose by S.+Allen · · Score: 2

    You simply can't run most Java programs without either a JVM or a bundled compiler. The reason for this is dynamic class loading. You can load classes by arbitrary name, from urls, from byte codes you've created on the fly in memory, etc, etc. These classes cannot be precompiled. So you either need a JVM to interpret them, a compiler to compile them, or both in the form of a jitted JVM.

    Why do people complain about the size of the JVM? Every scripting language has to have the equivalent in the form of an interpreter. The *base* perl installation on Linux is 21MB. That's without docs and a UI toolkit (Java includes both). I don't hear complaints about the size of Perl's interpreter or the heft of the Tk or Gtk toolkit libraries.

    Would people like Java more if it didn't have byte codes? If we had a Java shell like Perl, Tcl and Python? Skip the byte codes and let it be tokenized each and every time? Or is it just the cross-platform talk that rankles everyone? Maybe it's Sun's stupid open/not-open antics. Or perhaps it's just language l33t1sm.

  35. Re:It's about time! by n1k0 · · Score: 2, Informative

    > (no operator overloads, etc).

    Here you go. ;-D

    What's etc?

    niko

  36. Free Java Performance Book by WilsonSD · · Score: 2, Informative
    For anyone that wants to learn more about Java performance tuning you might want to check out my book. You can read it online here:

    http://java.sun.com/docs/books/performance/

    -Steve

  37. Re:what about compile time speed. by dead_penguin · · Score: 2

    When I discovered jikes, I nearly cried. It's that much faster. I've easily seen improvements in compile time of well over 10x what javac does.

    For me the most painful part of java development had always been the compiles. Sitting there, waiting minutes for larger projects until everything was done. With jikes that now takes seconds. I really don't even want to think about the hours of my life that are missing from just waiting for javac...

    --

    It's only software!
  38. Excelsior JET by LadyLucky · · Score: 2, Insightful
    For my own curiosity, I compiled an interpreter I had written in java using this, just to compare the performance.

    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.

    --
    dominionrd.blogspot.com - Restaurants on
  39. Re:Java's Cover by Waffle+Iron · · Score: 3, Insightful
    I've never found a language that allowed me to be as productive as Java for the type of applications that I build. The language supports all the things I need such as threads, network communication (RMI) and web development (JSP) and the API allows me to develop apps quickly and with the freedom of interchanging parts (Web servers, databases, etc.) from different vendors whenever I want.

    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.

  40. Some gcj facts by tromey · · Score: 3, Informative
    Some facts about gcj and the IBM article.
    • They tested an old version of gcj. gcj 3.1 beats the Sun and IBM JDKs on SciMark. It also wins on the "primes" test once you change it to use int and not long; this is a known gcc weakness.
    • In general we haven't done a lot of performance tuning. There is still a lot of room for us to improve.
    • You can see a much better (IMHO) comparison of gcj with other VMs here.
    • Contrary to what one poster said, my understanding is that gcj has better I/O performance than the Sun JDK.
    • It is true that gcj is missing AWT (though much progress has been made on that front recent, we still aren't there) and some other things. However, it is still useful for many things.
  41. One more rant :) by _avs_007 · · Score: 2, Informative

    Why is everything inconsistent?

    With Sun's latest JDK, behavior is different between Linux and Windows, despite it being the same version and from the same vendor.

    Example:

    Under windows: Component gets both Key and Mouse events, as well as repaints.

    Under linux: Component gets key event, but frame traps mouse event. And frame traps repaint as well.

    You would think they would have the same behavior... This really makes for write once, debug everywhere.

  42. Third that! by jonabbey · · Score: 2

    The biggest speed issues in Java are not from the JVM being an interpreter or JIT, they are from the API and the very high level of safety guarantees provided by Java.

    Java code can be very fast, but you have to take the API and the nature of Java into account in your design. If you want to do nothing but sling strings around, you're going to pay a massive penalty for doing it in Java, because all of the Java API's (at least in 1.3 and prior) require String objects for any string activity, and String objects are non-mutable due to a concern for thread safe API calls. If you want to change the third character in a String, you get to either create a new String with that change in place, or you get to create a StringBuffer class that will spew non-mutable String copies for each time you want to use the characters in your StringBuffer.

    A C program would never ever do things this way, and so you get insanely better performance. But if you write a C++ program that does do things this way, you'll actually get performance that is very close to Java's, except you have no guarantees as to the integrity of any of your objects because some random piece of code can scribble all over anything it wants to. Plus no universal set of exception classes that everything knows about, no portable thread synchronization primitives, etc., etc., etc.

  43. Different tools for different tasks by Roy+Ward · · Score: 4, Insightful

    I've used both C++ and Java extensively (although I haven't used garbage collected C++).

    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.

    1. Re:Different tools for different tasks by Malc · · Score: 2

      "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)."

      Threading issues are no different in C++. In fact, they're probably worse in C++ because it could cause memory corruption and continue running only to crash much later.

    2. Re:Different tools for different tasks by Roy+Ward · · Score: 2

      > awful templates mean you used them for something that they shouldn't have been use for

      No, I mean that C++ has got the worst template system that I've seen anywhere - they look like they have been hacked on top of the C++ spec.

      I prefer to code (where possible) in really high level languages like Mercury ( http://www.cs.mu.oz.au/research/mercury/index.html ) where the equivalent of templates (although they don't call them that) is handled beautifully and fit with the rest of the language.

      It is possible to use the C++ templates nicely (and sometimes I do), but it doesn't stop them being ugly.

    3. Re:Different tools for different tasks by Roy+Ward · · Score: 2

      > enforce a style and it won't happen

      I've never seen a style that completely eliminates this without also destroying the power of the language, although I do use a style that prevents many of the problems.

      One thing that C++ has that Java doesn't (yet) is the 'assert' function. This on many occasions can make C++ easier to debug than the equivalent Java.

      > same code written in Java would also somehow be flawed.

      Yes, the same code written in Java would also be flawed, but the flaw is usually much easier to find, and sometimes even turns up at 'compile' time.

      Better (IMO) than either C++ or Java are some higher level languages that are likely not to even compile if there are flaws.

    4. Re:Different tools for different tasks by DaveWood · · Score: 2

      "One thing that C++ has that Java doesn't (yet) is the 'assert' function. This on many occasions can make C++ easier to debug than the equivalent Java."

      1.4 baby!

  44. Re:Some thoughts... by FastT · · Score: 2

    Just brainstorming here, but what about making every Java class (or related group of classes) a shared library that can be dynamically loaded? Seems like you could fake class inheritance by using inter-library references and some infrastructure to fix-up the references dynamically. Polymorphism would be achieved by translating calls to "super" as calls to the "parent" library.

    --

    The only certainty is entropy.
  45. Toshiba going mobile with ARM chip by ackthpt · · Score: 2, Informative

    No JVM for this baby.

    --

    A feeling of having made the same mistake before: Deja Foobar
  46. Re:Java Question. - Some Answers by FastT · · Score: 4, Interesting
    The answers I typically get are not related to the programming *language* at all, but the organization and "java culture":
    But why does this invalidate the answers you get? Any language is equally as much a union of the language syntax itself and its built-in capabilities, i.e. its libraries. Your question is analogous to asking what is the advantage of English syntax over French syntax. In the broad scope of things, nothing really makes one better than the other--except perhaps their vocabularies.

    The richness of a language's vocabulary is what lets its speakers express themselves in powerful ways distinct from what other language speakers can do. French has a number of terms and concepts that don't have direct translations in English, and in fact, a huge amount of common English vocabulary comes from French.

    A programming language's libraries are equivalent to a natural language's vocabulary. And this is exactly where Java shines the most from an application development point of view. (It shines for other reasons on other fronts, like for embedded programming.)

    If you REALLY hated pointers that much you could write C++ code without pointers and write your own garbage collector (not to mention that LISP does garbage collection too -- nothing new).
    Sure, you can go out and develop a C++ app without using pointers, but that's just one app. The next one probably will use pointers. Even if I become a C++ programmer and refuse to use pointers in all my applications, I will have to work with someone who does, or use a library that requires them (is there one that doesn't?). And, eventually, I'll have to maintain someone's code that uses pointers. In the end, there's no getting away from it. Java eliminates the vulnerability pointers represent unilaterally, for better or worse.

    And similarly, you can go grab a library for doing garbage collection, but which one? You have nearly infinite choices, and every app will make a different choice. It's exactly the consistency of features that make Java superior in this regard. And when I say superior, I mean cheaper, and not just in terms of money, but in terms of resources. The support engineer trying to fix a bug in a Java program won't have any questions about the subtleties of a garbage collection API he's never seen, nor wonder what's in this odd little pointer that seems to keep causing a production crash. These are real advantages, even if they are hard to quantify.

    I haven't seen too many implementations when cross-platform is needed at run-time
    That's just the limit of your experience then. My experience is exactly the opposite. The advantage here is the fact that you maintain a single codebase--the same source files--for all platforms, and they do work as advertised minus any VM bugs (which are fairly rare compared to application bugs).

    Let me tell you a story. I used to work for one of the real success stories of the dot-com era. My company implemented different pieces of its product using Java and C++, and these pieces used CORBA to interoperate. As far as any one distributed object was concerned, the object on the other end could be any language; it was only a difference of implementation.

    Anyway, the support and maintenance costs for the Java portion of the product were dramatically lower than for the C++ portions. They both used the same infrastructure, but one was cheaper and faster to develop in, easier to fix and enhance for the next version, easier to debug both in-house and in the field, and more stable to boot. Add to this the fact that you only had one copy of the source files for the Java portions, versus the several versions for all the different platforms we supported in C++. In the end, if you work on large, complex software systems, Java is vastly easier to maintain, and vastly cheaper to support. Ask any of the product engineers and they would say the same thing: Java is just more pleasant and productive to work in, and they prefer Java over C++. They all hated the C++ portions of the product, and regretted ever putting them in.

    And, sadly, most programmers out there aren't that good. With C++, you give them a loaded weapon and tell them to be careful. As often as not, they inadvertantly shoot you or themselves. At least with Java, poor programmers have to load the gun before they can shoot anyone. Sorry for the extended analogy.

    You know the platform of your server (it won't randomly change without you knowing) so why not write in a higher-level language such as C++ and skip all the platform-dependant code (or do ifdefs) and have it run natively faster? If your platform changes you just re-compile
    Ugh, so much to say here. The problem is that what you are suggesting is a myth; it does not represent the real world of enterprise application development. You don't know your platform, it is not a constant in the equation. You want to provide for all platforms if you're a software vendor. Once you can sell to one, using Java, you can sell to all others without any significant extra effort. Furthermore, bugs fixed in one version of your code are fixed in all versions--support costs go down dramatically.

    If you're a client, you may find that you are grossly unsatisified with vendor X's hardware/support/performance and want to switch to using a solution by vendor Y (and this happens all the time in the corporate environment). What do you do now? Just because you know things are changing doesn't make the cost of changing any less. However, the fact that you wrote your application in Java does make the cost less--it makes it nil, because the same code runs on HP, Solaris, Intel, Windows, Linux, MacOS, AS/400, etc. The ability to move code effortlessly between platforms allows you as a company to save costs if it makes sense to switch hardware platforms, or mix and match platforms.

    "Java has a cross-platform GUI". So is GTK and QT.
    Yes, but the application code your GUI fronts is also cross-platform. Not so with the others. And again, there's the benefit of the single binary versus a binary per platform.
    "Java is easy to learn". I'll skip that.
    That's fine, but it really is. Try it. The limited complexity of the language lets programmers focus on the task at hand far more easily in my experience, and it's much easier to do OO in Java than in C++. This means all the benefits of OO are more easily achievable (and if you don't think OO is a good thing, don't bother talking to me.)
    Why program in Java when you can achieve the same result faster in another language?
    If you can, great, but I haven't found that language yet. It might be Smalltalk, or Perl, or COBOL, but nothing so far has taken all the great ideas from all of these languages and made them so eminently useful and practical. For example, Smalltalk is probably the most elegant, most forward-thinking languages around (even today), with tons of powerful features. However, it doesn't have the network orientation that Java does, or the C/C++ like syntax that makes it easy for developers to learn. It doesn't have the ability to be pared down and run inside a DIMM-sized computer, or be as dynamic as Java.

    I'm not advocating Java over other languages if those languages are more suited to the job. I'm not going to write a device driver in Java. I'm suggesting that a task that can be equally accomplished in Java and some other language will be more maintainable, cost less to support, and completed more quickly, when written in Java. The real-world merits of Java are that it reduces resource costs for anyone using it, end of story.

    --

    The only certainty is entropy.
  47. Re:Java's Cover by FastT · · Score: 3, Insightful
    I think a lot of people hate java because it makes the feel obsolete
    I agree. If twisting your brain to think like a silicon chip that is less intelligent than your average paramecium is your yardstick of personal greatness, so be it. It's not mine. I'd rather spend my time defining the architecture to solve the problem at hand than spend a few months writing the infrastructure to support that architecture. I'd rather let an expert on linked lists write the most efficient linked list possible, and just let me inherit from it.

    Why does business like it?
    For what you said, and so much more. In the end, Java reduces resource costs. It lets them choose their platform, and not be hamstrung because of that decision down the road. It lets them escape vendor lockin. It lets them vastly reduce their support costs. And many other reasons that I'm just too tired to list.
    So the last refuge of the C, C++ programmer is speed. They can say there app is slightly faster then Java apps. With computers getting faster every day, this becomes less and less of an argument.
    And besides, hardware is cheap, at least to a company. It's cheaper to buy many times more hardware to support a more maintainable application than it is to try to cut hardware costs by spending an arm and a leg developing the fastest, most efficient software. Not only do they risk not doing that (it's like a 10% shot that they can even do it), but the lifetime of hardware is much shorter than that of software, and it tends to be a fixed cost, unlike problems with software.
    --

    The only certainty is entropy.
  48. 100% right! by GCP · · Score: 4, Insightful

    Sun pushed *binary* compatibility so hard because Java's claim to fame was taking what loaded into your browser from static content to full executable apps -- making the underlying OS irrelevant in the process. "Death to Windows!"

    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.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  49. Re:prime example rewriten in C++ results by __Reason__ · · Score: 2, Informative

    Your C++ version is not comparable. A "long" in Java is 64 bits. A "long" in C++ is 32 bits. The Java code is doing far more work.

    Change the Java code to use "int" or the C++ to use "long long" for a fairer comparison.

  50. Re:Some thoughts... by doug363 · · Score: 2

    There's a Java class called ClassLoader that allows Java programs to dynamically load classes at runtime. The classes can be stored somehow on the computer, downloaded over the network, or generated dynamically by the program if it knows the Java class format. You can make portable self-modifying code with Java ;). Basically, you can make your precompiled class files into shared libraries or whatever, but you still need to be able to handle bytecode class files received over the network, compiled with a source-to-bytecode compiler, etc.

  51. Welcome to FDPR by tjwhaynes · · Score: 2

    Some VM implementations use a sophisticated comprimize between interpreters and JIT compilers [sun.com]. If you can identify the small part of the program that does most of the actual work, you know what parts of the program really need to be compiled. How do you do this? You wait until the program actually starts running!

    Advocates of this approach claim that it has the potential to be faster than C++ and other native-code languages. A traditional optimizing compiler can only make decisions based on general predictions as to how the program will behave at run time. But if you watch the program's behavior, you have specific knowledge of what needs to be optimized.

    Err - but you can do that with C++. Ever heard of Feedback Directed Program Restructuring (FDPR)? You run your code under whatever load you feel like optimizing and use the FDPR tools to rebuild the code, changing the ordering and ensuring that cache misses are minimized as much as possible. Try taking a look here for some more details.

    Cheers,

    Toby Haynes

    --
    Anything I post is strictly my own thoughts and doesn't necessarily have anything to do with the opinions of IBM.
    1. Re:Welcome to FDPR by egeorge · · Score: 2, Interesting
      Err - but you can do that with C++. Ever heard of Feedback Directed Program Restructuring (FDPR)? You run your code under whatever load you feel like optimizing and use the FDPR tools to rebuild the code, changing the ordering and ensuring that cache misses are minimized as much as possible.

      There is one thing wrong with this process; rebuild. The latest generation of Java dynamic compilation/optimization does its work behind the scenes and happens automatically which I think is a huge advantage over FDPR. It allows the optimizer to adapt to unforseen changes in the production environment.

      I think that Hotspot-style dynamic optimization is the future of Java and will eventually overtake statically compiled (or repeatedly compiled) options.

      However, Hotspot has a lot to learn from FDPR, like how to keep track of performance metrics across VM sessions. The biggest drawback of current Java dynamic optimizers is that you only get their full potential for long-running processes. Once they get optimization profile management down, the dynamic optimizers like Hotspot are going to look much more appealing on the types of benchmarks like this article uses.

  52. Re:Java's Cover by iapetus · · Score: 2
    So far, Java seems like a stinker to me. I've never written a Java program, never more than glanced over reference books about it, but I have a hunch that it won't be a very successful language.

    I didn't bother reading your discussion of why you don't think Java will be a very successful language (too late, by the way - it already is), but I have a hunch that all of your points were invalid.

    --
    ++ Say to Elrond "Hello.".
    Elrond says "No.". Elrond gives you some lunch.
  53. Cobol rates are even higher by Ars-Fartsica · · Score: 2

    So why aren't you switching? Rates go up as the number of practitioners in the field drops - usually as a result of reduced demand. The last man standing in the C++ practioner market will be a happy camper, but this doesn't indicate a success for the language.

  54. Re:Microsoft .NET already does it! by Lussarn · · Score: 2


    This is built into the .NET Framework. Run ngen.exe on any .NET .exe or .dll and the MSIL is precompiled into an optimized native binary. In fact, setups for .NET apps can do this on the assemblies they install. Indeed, the .NET Framework actually precompiles its managed shared .dlls on install time.


    And with .NET you wouldn't miss anything since it only works on windows. Until there is a framework for Unix, Mac and Amiga it shouldn't be compared to Java.

  55. Re:either embed the jvm or the compiler - you choo by tulare · · Score: 2

    Bah. My beef with java is and always has been that it is slow, buggy, and produces a reliably ugly GUI when you need to create one. It really doesn't matter which platform, either. Apple used to do this advertising (you will laugh) which said "See java run - quickly!" Guess which OS? If you guessed X, you're right. The fact is that for whatever reason (I admit ignorance - I don't know!), Java is slower than other languages. I have been watching this thread, and it is interesting to see the arguments re: automatic garbage collection versus manual cleanup.
    My >guess is that the reason most Java apps run so slowly is because the language is structured in such a way that it is easy to write sloppy code. For example, why bother figuring out which specific library to call up when you can just call java.lang.* in your file. In that sense, I guess I am guilty as charged. The second biggest reason most people poo poo Visual Basic is that it lets people get awaw with writing shitty code. Same with Java.

    --
    political_news.c: warning: comparison is always true due to limited range of data type
  56. Java is not God by fm6 · · Score: 2
    Hey, I was just parroting the VM engineers. I'm not qualified to compare their approach with alternatives.

    Obviously Java has not turned out to be the universal solution that it was supposed to be. Of course there are non-Java solutions for some problems that are objectively better, or at least preferrable to the developers that employ them.

    The purpose of my rant was not to advocate Java in general, or any particular approach to it. (In point of fact, I haven't worked with Java for over 3 years. As I said, I'm no expert, and it doesn't suprise me that people find flaws in my summary of the VM issue.) I was merely pointing out that the naiveness of the VM-versus-Native dichotomy.

  57. Well, then... by devphil · · Score: 2
    I find that Java simply outshines C++ because it doesn't leave me dealing with low level stuff, like pointers.

    Then perhaps you should learn how to use C++.

    Not to flame you -- I'm usually the first person to use the right-tools-right-job argument -- but one of the best books to teach C++ doesn't even mention pointers or builtin arrays until chapter 10. They teach C++, not C features that happen to show up in C++.

    After having used C++ quite heavily for a decade, even I found parts of this book refreshing. I highly recommend it, both to beginning programmers, and crusty veterans like us.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
  58. Re:either embed the jvm or the compiler - you choo by tulare · · Score: 2

    "when it's compiled"
    And I suppose the compiler doesn't need any resources to run? So who's the dumbass? BTW, post with your logon if you want to namecall.

    --
    political_news.c: warning: comparison is always true due to limited range of data type
  59. Write Once, Run Anywhere by ansible · · Score: 2

    I tend to sympathize with the write-once-run-anywhere (WORA) advocates.

    I haven't seen single cross-platform programming language that didn't have some platform-specific idiosyncrasies. You either have to avoid those areas completely, or try to code around them.

    If you need those features, then you have to fix things for the specific platform at either compile-time or run-time. Compile-time means some kind of hack like the C pre-processor. Run-time means dynamically loading the correct version of some class. Either way, I say: "Ugh." That's not to say that either approach won't work, but it isn't as pleasant.

    It keeps things simplier and saner when you're just targeting the same VM and standard libraries. You still have to have a bunch of conformance tests to make sure the particular JVM is compliant, but that's easier to maintain than platform-specific code in every application you write.

    I've been doing mostly Java programming for the last couple months, and while there are a number of features in the language that annoy me, the overall development process is more pleasant than in other environments.

  60. That's the worst argument I've ever heard by MemeRot · · Score: 2

    You can do the same thing with C or C++. Or ANY language that you can compile. If Java compiled separately for each different platform is 'cross-platform' then so is C++. This DOES eliminate cross-platform as a benefit. And confirms the point that if you have a large, slow Java application where the speed is a serious problem, you should have written it in C++ in the first place.

  61. Re:Java's Cover by Bodrius · · Score: 2

    I disagree with your conclusion, but I find your comments most insightful. Particularly because you admit to be judging Java by its cover, and the reality is that the worst part of Java, IMHO, is its cover. It has little to do with the language strengths, and promotes a lot of its weaknesses (applets, anyone?).

    Let me try to address each argument. Note that these rebuttals are based on my limited experience and the impression I get from the language, and I'm no expert:

    1. It has been so energetically hyped. Real standards don't have to be promoted... . On the hacker radar screen, Perl is as big as Java, or bigger, just on the strength of its own merits.

    Java is not a "hacker"'s programming language, it's a software designer's programming language. A lot of what makes Perl so cool to code with is considered the very nature of evil by the people who liked (designed?) Java, so the techie radar screens tend to be pretty much apart.

    However, Java has been hyped before it was ready to be hyped, and for the wrong reasons. Sun's vision of browsers running applets everywhere and for everything never made it, in part because Microsoft destroyed the dream of a standard JVM for applets, but mostly because Java's GUI libraries and the ISP's bandwith were not ready for primetime.

    You will notice, however, that Java sneaked into the server market before anyone noticed, and has become the standard there. Suddenly Java was all about server-side applications, and servlets have replaced the old Sun vision after (and because) Java was already a success in that field.

    2. It's aimed low. In the original Java white paper, Gosling explicitly says Java was designed not to be too difficult for programmers used to C. It was designed to be another C++: C plus a few ideas taken from more advanced languages.

    That was a sintax constraint. It has little to do with the design of the language. I think you could make Java easy for Pascal programmers with some trivial changes to the parser and 1-based indexes.

    Java has definitely different aims, and philosophies, than C++, and it doesn't aim low: binary cross-platform compatibility, transparent networking and serialization, fully object-oriented, language-level security and threading, good exception handling, etc.

    Java was not meant to run in big hardware, it was meant to run in very small hardware in a network environment without compromising security. That's no C.

    3. It has ulterior motives. ... Likewise, the reason we hear about Java all the time is not because it has something to say about programming languages. We hear about Java as part of a plan by Sun to undermine Microsoft.

    Most successful languages had nothing new to say about programming languages. They just partially implemented ideas from theoretically better programming languages, and owe their success to their sponsors' ulterior motives.

    C is just an Algol-like language. So is Pascal (which you seem to think is "bad"; have you tried Delphi?), which was very successful. So is almost every language commonly used. C++ just patched up C with some objects and generics, no new concepts there. About the only real innovation Perl seems to have is the subtext of its design and semantics, not the language itself.

    Lisp, however, owed it's failures to its innovative qualities, and it's successes to IBM and its ulterior motives. The only times I can come up with where innovation met with success is Smalltalk.

    We are doomed to reap the fruits of innovation in the second generation.

    4. No one loves it. C, Perl, Python, Smalltalk, and Lisp programmers love their languages. I've never heard anyone say that they loved Java.

    You're probably talking to the wrong crowd. Talk to a programmer/software designer.

    5. People are forced to use it. A lot of the people I know using Java are using it because they feel they have to.... These are smart people; if the technology was good, they'd have used it voluntarily.

    People were forced to use C for decades. Then they were forced to use C++ for years.

    Management rarely understand that such decisions should be left to techies, not to other management. When they don't understand the tools, they stick to (an arbitrary) one, and that's what everyone uses.

    Smart people would use LISP/ML for a lot of things. Smart people would use Delphi for database applications. Smart people would use Smalltalk for desktop applications. Smart people would use C for OS development or device drivers only.

    If you think C/C++ became the de facto standards they are because the technology is good, you are sorely mistaken. People learned C++ because they were forced to. People learned to develop GUIs in C because they had to. And people will always be forced to use a tool that is perfectly good for one thing, for something it's no good for.

    6. It has too many cooks. The best programming languages have been developed by small groups. Java seems to be run by a committee. If it turns out to be a good language, it will be the first time in history that a committee has designed a good language.

    I'm not sure, but I think the commitee was not there at the level of language design (unless you consider 5-people a commitee, in which case lots of languages, from Prolog to probably LISP, also were created by commitees).

    Whatever the case may be, Java already IS. You can judge whether it's good or bad, no need to wait. Don't confuse the language with the standard libraries (which are part of the language distribution and the Java(TM) thingie, but don't define the language).

    The commitee process in Java exists right now to standarize the libraries. For something like that you NEED a commitee.

    7. It's bureaucratic. From what little I know about Java, there seem to be a lot of protocols for doing things. Really good languages aren't like that. They let you do what you want and get out of the way.

    Java is not a hacking language. To "do what you want and get out of the way" is to do a hack, a quick one-time solution for a particular problem.

    If that's what you need, great, but Java is not the tool for that. Some (perhaps most) programming problems require more thought on the security, stability and maintainability of the solution. Java, and many other languages, are tools for that.

    Java is an object-oriented language, and by definition any OO language is bureaucratic. That's the whole point of object-orientedness: to provide extra layers of abstraction that will later allow flexibility. Messaging and more messaging. Smalltalk is bureaucratic too (it invented the bureaucracy), and yet almost all its coders consider it a great language.

    8. It's pseudo-hip.

    That, it is. But then again, if you don't take it seriously, Sun's PR is always entertaining.

    9. It's designed for large organizations. Large organizations have different aims from hackers. ... Historically, languages designed for large organizations (PL/I, Ada) have lost, while hacker languages (C, Perl) have won. The reason: today's teenage hacker is tomorrow's CTO.

    Java's libraries are designed for large organizations, but I think the language itself is not. Its only real constraint in that sense is that it is designed to exist in an insecure environment. The semantics are relatively simple and concise.

    The reason Ada and PL/I failed was because they were semantic monsters, with conflicting features, and most of the semantics they had were not understood and used anyway. C++ is closer to that situation than Java.

    10. The wrong people like it. The programmers I admire most are not, on the whole, captivated by Java. Who does like Java? Suits...

    This all depends on who do you admire, and why. If they're kernel hackers they're not going to be captivated by Java: jet pilots are not captivated by 747s, farmers are not captivated by the concept of the supermarket.

    Suits like Java. Now they like C#. Before, they liked C++, and at some point they liked an inferior OS system so much they put it everywhere and on everything (Windows? Yes, but Unix too, before). Suits like everything for about 5 seconds, good or bad, particularly if they read it can do something-ML, something-Net.

    11. Its daddy is in a pinch.

    Good point if it's true, but it would be hard for Sun to drag Java along with it at this point. The worst that could happen is that the standard stays at a stable 1.x version.

    Or actually, the worst that could happen is that Sun is incredibly successful and manages to destroy Java by being careless with the standards, but I doubt that will happen.

    12. The DoD likes it. The Defense Department is encouraging developers to use Java...

    I think the DoD likes it because it's the only other language that offers security at the language level. It's either that, or creating their own language, or keeping Ada, which is pretty much the same thing.

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  62. No, wrong architecture by GCP · · Score: 2

    If your fridge asks the printer to print something, then status messages for that print job will be returned to the requester automatically. If the fridge has any message display mechanism, it can decide to display the messages. Or it can ignore them. What the fridge does with its messages isn't the printer's concern.

    The printer and the fridge have no need to reprogram each other. They just need to send messages in standard formats appropriate for the class of device: a printer or a fridge.

    Java was designed to run on general-purpose clients, and it's only there that the idea of sending executable code makes more sense than sending remote API calls. I think that will mostly mean clients with browsers, and I expect .Net to become more successful at this than Java due to MS's dominance of this type of client.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  63. Re:Java's Cover by Malc · · Score: 2

    You put great store in hacking. Large scale development doesn't involve hacking. Leave that at home with ones other hobbies: writing reliable software involves discipline, whichever language one uses. As a C++ programmer, I found Java allowed me to very rapidly write reliable programmes with minimal fuss. It is very elegant compared with C++, and anything that helps lesser programmes produce code with fewer wierd bugs makes my job easier and costs the business less.

  64. Re:prime example rewriten in C++ results by Karellen · · Score: 2

    No, a 'long' in C++ is _at_least_ 32 bits. It may be more. Especially on 64-bit systems.

    C++ doesn't have a 'long long' type. You're thinking of C99. Or a compiler-specific extension. (And, IMO, 'long long' is really fscking ugly. 'longlong' (one keyword) would have been better if it was _really_ needed, which it wasn't. Stupid decision by the C9X committee if you ask me.... :-)

    --
    Why doesn't the gene pool have a life guard?
  65. what's left by poemofatic · · Score: 2

    is still a language that's much easier/quicker to code in than C++,

    and that has all the portability of the old Java, in addition to this (still vaporware) extra feature.

    --

    When in doubt, have a man come through a door with a gun in his hand.

  66. 64-bit integer math in FPU registers by Animats · · Score: 2
    x86 FPUs, all the way back to the 8087, have internally a 64-bit mantissa and a 16-bit exponent. IEEE floating point is integer-preserving if the numbers will fit. And the x86 FPU has instructions like FILD and FISTP, which load and store 64-bit integers to and from the FPU, converting them to 16/64 extended format.

    64-bit add, subtract, and multiply work fine if the numbers fit in integers. Overflows on conversion back to integer cause an invalid-arithmetic-operand FPU exception, which Java can use but C has no idea what to do with. So that's fine.

    Divide and mod are tougher to do as integer operations in the FPU, because fractional results appear in the FPU registers, but it's possible if the rounding modes are set to "round down". Note that the benchmark used "%", and it's possible that GCC doesn't try to do 64-bit "%" (which, after all, isn't used much) in the FPU.

  67. Thank You. by cgleba · · Score: 2

    Thank you all for the informed replies and the anecdotes. I have a better outlook on Java now and understand better where it is best suited.

    I think most of my 'questioning' Java has come from people who try to 'sell' Java as a panacea -- aka 'putting Java in light bulbs', "re-writing OS kernels in Java', etc.

    What you mantioned is the clearest and best answer that I've hear for the reasons to use Java thus far -- aka you *can* do it in another language, but the support costs and development time for Java is a lot smaller. That makes sense and in that case the main costs to weigh when choosing Java over another language is what it will cost in developer/support time versus the performance losses.

    Thank you for your answers, even though my question did get modded into oblivion :).