Jump to content

GNU Compiler for Java

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 117.120.18.134 (talk) at 16:55, 3 August 2017 (History). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
GNU Compiler for Java
Developer(s)The GNU Project
Initial releaseSeptember 6, 1998; 26 years ago (1998-09-06)[1]
Final release
6.4[2] / July 4, 2017; 7 years ago (2017-07-04)
Operating systemUnix-like
TypeCompiler
LicenseGNU GPL
Websitegcc.gnu.org

The GNU Compiler for Java (GCJ) was a free compiler for the Java programming language and part of the GNU Compiler Collection.[3][4]

GCJ could compile Java source code to Java Virtual Machine bytecode or to machine code for a number of CPU architectures. It could also compile class files and whole JARs that contain bytecode into machine code.[5][6]

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 uses the Eclipse Compiler for Java as a front-end.[7]

In 2007, a lot of work was done to implement support for Java's two graphical APIs in GNU Classpath: AWT and Swing. AWT support is working, Swing is also working. The GNU CLASSPATH was merged with Oracle sources this might be a reason why it has been abandoned completely. You can use it with mingw/msys2 on windows or on every linux box.

]</ref>

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,[8] 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. ^ Anthony Green, Cygnus Solutions. "GCJ announcement".
  2. ^ "GCC Releases – GNU Project – Free Software Foundation (FSF)".
  3. ^ https://gcc.gnu.org/java/
  4. ^ Campbell, Bill (2013). Introduction to Compiler Construction in a Java World. CRC Press Taylor & Francis Group. ISBN 978-1-4398-6088-5. Retrieved 2014-02-06.
  5. ^ http://www.linuxjournal.com/article/4860
  6. ^ http://freecode.com/projects/gcj
  7. ^ "gcj to use Eclipse compiler as a front end". 2007-01-08. Retrieved 2007-05-20.
  8. ^ The example comes from: https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes