GNU Compiler for Java
File:Gcj2.png | |
---|---|
Developer(s) | The GNU Project |
Stable release | 4.4.2 / October 15, 2009 |
Operating system | Unix-like |
Type | Compiler |
License | GNU GPL |
Website | http://gcc.gnu.org/java |
The GNU Compiler for Java (GCJ or gcj) is a free software compiler for the Java programming language and a part of the GNU Compiler Collection.
GCJ 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[update] a lot of work has gone in to getting GNU Classpath to support Java's two graphical APIs: AWT and Swing. Work on supporting AWT is ongoing, after which support for Swing will follow.[2]
As of 2009[update] new developments in gcj have nearly stopped.[3] The product is currently in maintenance mode.
Performance
Java code compiled by GCJ should have faster start-up time than the equivalent bytecode launched in a JVM[4].
However, after start-up, Java code compiled by GCJ does not necessarily execute any faster than bytecode executed by a modern JIT-enabled JVM. This is true even when GCJ is invoked with advanced optimization options such as -fno-bounds-check -O3 -mfpmath=sse -msse2 -ffast-math -march=native -- in this case, the compiled program may or may not surpass JVM performance, depending on the operations performed by the code in question[5].
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:[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, jint k)
{
if (k == 0)
return Int::zero; // Static member access.
return new Int(p->i * k);
}
See also
- GNU Interpreter for Java (GIJ)
- IcedTea
- Kaffe
- SableVM
- JamVM
- Apache Harmony
- Jikes
- C to Java Virtual Machine compilers
- Free Java implementations
References
- ↑ "gcj to use Eclipse compiler as a front end". 2007-01-08. http://gcc.gnu.org/java/. Retrieved 2007-05-20.
- ↑ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
- ↑ GCJ: News
- ↑ GCJ: The GNU Static Java Compiler
- ↑ GCJ vs Java JIT Performance Comparison
- ↑ The GCJ FAQ - GNU Project - Free Software Foundation (FSF)
- ↑ The example comes from: http://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes
External links
- GCJ Homepage
- GCJ Manual
- About CNI section of GCJ Manual
- GCJ Frequently Asked Questions
- LWN: GCJ - past, present, and future - the article discuss some history of GCJ.
Template:Java Virtual Machine Template:Java (Sun)
de:GNU Compiler for Java es:GNU Compiler for Java fr:GCJ ja:GNU Compiler for Java pl:GNU Compiler for Java pt:GCJ uk:GCJ
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...
- Pages where expansion depth is exceeded
- Pages using deprecated source tags
- Pages with syntax highlighting errors
- Pages with broken file links
- Articles containing potentially dated statements from 2007
- Articles with invalid date parameter in template
- All articles containing potentially dated statements
- Articles containing potentially dated statements from 2009
- GNU project software
- Java development tools
- Free compilers and interpreters
- Java platform