GNU Compiler for Java

From Wikipedia, the free encyclopedia

GNU Compiler for Java
Developed by The GNU Project
Latest release 4.3.0 / March 5, 2008 (2008-03-05); 96 days ago
OS Unix-like
Genre Compiler
License GPL
Website http://gcc.gnu.org/java

The GNU Compiler for Java (GCJ or gcj), a free-software compiler for the Java programming language, forms part of the GNU Compiler Collection. It can compile Java source code to either Java Virtual Machine bytecode, or directly to machine code for any of a number of CPU architectures. It can also compile class files containing bytecode or entire JARs containing such files into machine code. Almost all of the runtime-libraries used by gcj come from the GNU Classpath project (but compare the libgcj library). As of gcj 4.3, gcj integrates with ecj, the Eclipse Compiler for Java.[1]

As of 2007 a lot of work has gone in to getting GNU Classpath to support Java's two graphical APIs: AWT and Swing. The programmers have almost achieved full support for both AWT and Swing[original research?], and it seems that soon users will no longer have to use the runtime provided by Sun Microsystems in order to run AWT/Swing applications.[citation needed]

Contents

[edit] CNI (Compiled Native Interface)

The CNI (Compiled Native Interface, previously Cygnus Native Interface), a software framework for the gcj, allows Java code to call and be called by native applications (programs specific to a hardware and operating-system platform) and libraries written in C++.

CNI closely resembles the Java Native Interface (JNI) framework which comes as standard with various Java virtual machines. However the CNI authors claim various advantages over JNI:[2]

We use CNI because we think it is a better solution, especially for a Java implementation that is based on the idea that Java is just another programming language that can be implemented using standard compilation techniques. Given that, and the idea that languages implemented using Gcc should be compatible where it makes sense, it follows that the Java calling convention should be as similar as practical to that used for other languages, especially C++, since we can think of Java as a subset of C++. CNI is just a set of helper functions and conventions built on the idea that C++ and Java have the *same* calling convention and object layout; they are binary compatible. (This is a simplification, but close enough.)

CNI depends on Java classes appearing as C++ classes. For example,[3] given a Java class,

public class Int {
   public int i;
   public Int (int i) { this.i = i; }
   public static Int zero = new Int(0);
}

one can use the class thus:

#include <gcj/cni.h>
#include <Int>
 
Int* mult(Int* p, jint k)
{
  if (k == 0)
    return Int::zero;  // Static member access.
  return new Int(p->i * k);
}

[edit] References

[edit] See also

[edit] External links