GNU Compiler for Java
Developer(s) | The GNU Project |
---|---|
Stable release |
6.2[1]
/ August 22, 2016 |
Preview release |
7.0
/ May 22, 2016 |
Operating system | Unix-like |
Type | Compiler |
License | GNU GPL |
Website |
gcc |
The GNU Compiler for Java (GCJ) is a free compiler for the Java programming language and part of the GNU Compiler Collection.[2][3]
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.[4][5]
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.[6]
In 2007, a lot of work was done to implement support for Java's two graphical APIs in GNU Classpath: AWT and Swing. Software support for AWT is still in development. "Once AWT support is working then Swing support can be considered. There is at least one free-software partial implementations of Swing that may be usable.".[7] The GNU CLASSPATH was never completed to even Java 1.2 status and now appears to have been abandoned completely.
As of 2015, there were no new developments announced from GCJ[8] and the product was in deep maintenance mode.[9] In 2016, GCJ was in the process of being removed from GCC[10] and was deleted in October.[11]
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.[12]
Compiled Native Interface (CNI)
The Compiled Native Interface (CNI), 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:[13]
“ | 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,[14] 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
- GNU Interpreter for Java (GIJ)
- Excelsior JET (Excelsior Java native code compiler)
- IcedTea
- Kaffe
- SableVM
- JamVM
- Apache Harmony
- Jikes
- C to Java Virtual Machine compilers
- Free Java implementations
References
- ↑ "GCC Releases – GNU Project – Free Software Foundation (FSF)".
- ↑ https://gcc.gnu.org/java/
- ↑ 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.
- ↑ http://www.linuxjournal.com/article/4860
- ↑ http://freecode.com/projects/gcj
- ↑ "gcj to use Eclipse compiler as a front end". 2007-01-08. Retrieved 2007-05-20.
- ↑ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
- ↑ GCJ: News
- ↑ GCC Looks To Turn Off Java, Replace With Go Or ADA
- ↑ https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00602.html
- ↑ Tromey, Tom (October 2, 2016). "The Deletion of gcj". The Cliffs of Inanity. Retrieved October 3, 2016.
- ↑ GCJ: The GNU Static Java Compiler
- ↑ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
- ↑ The example comes from: https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes
External links
- GCJ Homepage
- GCJ Manual
- About CNI section of GCJ Manual
- LWN: GCJ - past, present, and future – the article discusses some history of GCJ