13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

186Chapter 7The GNU Compiler for Java (gcj)7.6REASONS TO USE GCJYou might think that speed would be the primary reas<strong>on</strong> to use gcj, but this isnot necessarily the case. Yes, gcj is usually used as a native code compiler(it can compile to Java bytecode as well, and thus can be used as a replacementfor javac), but there is a lot more to Java performance than that. First off, bothSun’s and IBM’s JVMs have JIT (“Just-In-Time”) compilers in them, whichc<strong>on</strong>vert some or all of a class’s bytecode to native code <strong>on</strong> the fly. In some cases,these compilers may do a better job than the gcj compiler, so as a result, initialruns under a JVM are slower than gcj but later loops or iterati<strong>on</strong>s are comparableor faster. Also performance of both gcj and JVM code is highly affected bymemory, stack, and garbage-collecti<strong>on</strong> parameters which may be modified withcommand-line opti<strong>on</strong>s or properties files. So speed is not the determining factor.We have not d<strong>on</strong>e sufficient testing or measurement to tell you which envir<strong>on</strong>mentproduces “the fastest code” from a given source file. (We’re not evensure exactly what such “sufficient testing” might c<strong>on</strong>sist of. All we can suggestis that your try your code in all three envir<strong>on</strong>ments and then make yourown choice.)It is, perhaps, ir<strong>on</strong>ic that <strong>on</strong>e of the main reas<strong>on</strong>s why you might wish touse gcj is portability. You see, you can <strong>on</strong>ly run Sun’s and IBM’s JVMs <strong>on</strong>platforms for which they provide a compiled versi<strong>on</strong>. <strong>Linux</strong> runs <strong>on</strong> severalhardware platforms (such as Str<strong>on</strong>gARM) for which Sun and/or IBM do notprovide JVMs. Also, if you are running <strong>Linux</strong> <strong>on</strong> some architectures, there maybe VMs for the “official” OS, but n<strong>on</strong>e for <strong>Linux</strong> <strong>on</strong> that architecture. This isthe case, for example, for SPARC and Alpha. The cross-compilati<strong>on</strong> that gcjinherits from the GNU Compiler Collecti<strong>on</strong> allows you to compile Java t<strong>on</strong>ative code for <strong>Linux</strong> <strong>on</strong> those platforms.Another reas<strong>on</strong> to use gcj might be a desire for better integrati<strong>on</strong> withcode compiled from other languages. gcj has JNI support, but also provides itsown inter-language integrati<strong>on</strong> system called CNI, for Compiled Native Interface.We d<strong>on</strong>’t have space to cover CNI (and, frankly, we haven’t used itenough to be good judges), but its prop<strong>on</strong>ents claim that it is both easier to useand more efficient than JNI. You can read up, use it, and judge that foryourself.Still another reas<strong>on</strong> might be <strong>on</strong>e that we d<strong>on</strong>’t like very much. Again, itis ir<strong>on</strong>ic that the <strong>on</strong>ly Free Software Java compiler is the <strong>on</strong>e best able to produceproprietary binary code. Code compiled with gcj is as difficult to reverseengineer as compiled C or C++ code. It is subject to the same sort of binary

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!