C To Bytecode Compilers
From the viewpoint of a compiler, the Java virtual machine is just another processor with an instruction set, Java bytecode, for which code can be generated. The JVM was originally designed to execute programs written in the Java language. However, the JVM provides an execution environment in the form of a bytecode instruction set and a runtime system that is general enough that it can be used as the target for compilers of other languages.
Because of its close association with the Java language, the JVM performs the strict runtime checks mandated by the Java specification. That requires C to bytecode compilers to provide their own lax machine abstraction, for instance producing compiled code that uses a Java array to represent main memory (so pointers can be compiled to integers), and linking the C library to a centralized Java class that emulates system calls. Most or all of the compilers listed below use a similar approach.
Several C to bytecode compilers exist:
- NestedVM translates C to MIPS machine language first before converting to Java bytecode.
- Cibyl works similarly to NestedVM but targets J2ME devices.
- LLJVM compiles C to LLVM IR, which is then translated to JVM bytecode.
- C2J is also GCC-based, but it produces intermediary Java source code before generating bytecode. Supports the full ANSI C runtime. Win32 only.
- Axiomatic Multi-Platform C supports full ANSI C 1989, SWT, and J2ME CDC 1.1 for mobile devices.
- Java Backend for GCC, possibly the oldest project of its kind, was developed at The University of Queensland in 1999.
- Javum is an attempt to port the full GNU environment to the JVM, and includes one of the above compilers packaged with additional utilities.
Compilers targeting Java bytecode have been written for other programming languages, including Ada and COBOL.
Read more about this topic: Java Virtual Machine