GNU Compiler for Java

This is an old revision of this page, as edited by Prosfilaes (talk | contribs) at 05:58, 12 November 2013 (mark link as dead; it's a problematic cite given that the claim depends on the details of the test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The GNU Compiler for Java (GCJ) is a free compiler software for the Java programming language and a part of the GNU Compiler Collection.

GNU Compiler for Java
Developer(s)The GNU Project
Operating systemUnix-like
TypeCompiler
LicenseGNU GPL
Websitehttp://gcc.gnu.org/java

GCJ can compile Java source code to Java Virtual Machine bytecode or to a machine code for a number of CPU architectures. It can also compile class files and whole JARs that contain bytecode.

History

The GCJ runtime-libraries original source is from GNU Classpath project, but there is a code difference between the libgcj libraries. GCJ 4.3 integrates with ecj[clarify], the Eclipse Compiler for Java.[1]

In 2007 a lot of work was done to implement support for Java's two graphical APIs in GNU Classpath: AWT and Swing .

As of 2013 there have been no new developments announced from GCJ[2] and the product is currently in maintenance mode.

Software support for AWT is still in development. The next planned support feature after AWT support is a software support for Swing.[3]

Performance

The compilation function in GCJ should have a faster start-up time than the equivalent bytecode launched in a JVM when compiling Java code into machine code.[4] GCJ does not execute[clarification needed] faster than bytecode executed by a modern JIT-enabled JVM.[5]

CNI (Compiled Native Interface)

The CNI (Compiled Native Interface, previously named 'Cygnus Native Interface') is a software framework for the GCJ that 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 JNI (Java Native Interface) framework which comes as a standard with various Java virtual machines.

Comparison of language use

the authors of CNI claim for various advantages over JNI:[6]

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,[7] 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, int k)
{
  if (k == 0)
    return Int::zero;  // Static member access.
  return new Int(p->i * k);
}

See also

References

  1. ^ "gcj to use Eclipse compiler as a front end". 2007-01-08. Retrieved 2007-05-20.
  2. ^ GCJ: News
  3. ^ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
  4. ^ GCJ: The GNU Static Java Compiler
  5. ^ GCJ vs Java JIT Performance Comparison[dead link]
  6. ^ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
  7. ^ The example comes from: http://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes