GNU Compiler for Java
| Company type | Free software project |
|---|---|
| Industry | Software development, Compiler |
| Defunct | 2016-09-30 |
| Fate | Removed from GCC mainline repository |
| Products | Java compiler |
| Parent | GNU Compiler Collection (GCC) |
The GNU Compiler for Java (GCJ) was a Free software compiler dedicated to the Java language and was once included in the GNU Compiler Collection.
GCJ had the capability to translate Java source code into either Java virtual machine (JVM) bytecode or directly into machine code compatible with multiple CPU architectures. Additionally, it could convert class files and entire JARs containing bytecode into native executable code.
History
The runtime libraries used by GCJ originated from the GNU Classpath initiative but later evolved separately within the libgcj module. Starting with version 4.3, GCJ integrated the Eclipse Compiler for Java as its front-end parser.
In 2007, development efforts concentrated on enabling support for Java’s graphical APIs within GNU Classpath, particularly focusing on the AWT and Swing. While AWT support was still under active development, this limited the extent of Swing functionality available. The GNU Classpath project itself ceased progressing before achieving full compliance with Java 1.2 specifications and appears to have been abandoned.
By 2015, GCJ was maintained only in a limited capacity without major enhancements, as open-source Java development predominantly transitioned to OpenJDK. GCJ was officially removed from the GCC mainline repository on September 30, 2016, and excluded starting with GCC version 7.1, though it remained included in GCC 6.
Performance
GCJ’s compilation approach offers improved application start-up speed compared to running equivalent Java bytecode within a JVM, since it compiles Java programs directly into native machine instructions.
Compiled Native Interface (CNI)
The Compiled Native Interface (CNI), originally known as "Cygnus Native Interface," is a framework designed for GCJ that facilitates interaction between Java code and native programs or libraries written in C++.
While similar in purpose to the standard JNI, CNI is optimized to better integrate Java with native code by utilizing GCC’s compilation infrastructure.
Comparison of language use
Developers of CNI emphasize its benefits over JNI by treating Java as effectively a subset of C++, enabling binary compatibility between Java and C++ objects along with their calling conventions. This approach streamlines cross-language interoperability and enhances execution efficiency.
In CNI, Java classes are represented as C++ classes. For instance, consider the following Java class:
<syntaxhighlight lang="java"> public class MyInteger {
private int i;
public Int(int i) {
this.i = i;
}
public int get() {
return i;
}
public void set(int j) {
i = j;
}
public static final Int ZERO = new Int(0);
} </syntaxhighlight>
This class can be utilized within C++ code as shown:
<syntaxhighlight lang="cpp">
- include <gcj/cni.h>
- include <MyInteger>
MyInteger* mult(MyInteger& p, int k) {
if (k == 0) {
return MyInteger::ZERO; // Accessing static member.
}
return new MyInteger(p.get() * k);
} </syntaxhighlight>
See also
- Excelsior JET (Java native compiler)
- IcedTea
- Kaffe
- SableVM
- JamVM
- Apache Harmony
- Jikes
- GraalVM – GraalVM's Native Image feature enables ahead-of-time compilation, generating executable binaries directly from class files.
- Java virtual machine
- Free Java implementations
- Kotlin – Kotlin/Native converts Kotlin code into native executables without relying on the JVM, utilizing an LLVM-based backend alongside a native runtime environment.
External links
- GNU GCC official site
- GCJ Documentation
- Overview of CNI (GCJ Documentation)
- GCJ: history and outlook (LWN, April 6, 2005)