Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From C Source to Java Bytecode? [closed]

I'm looking for a way to compile C source code into high-performance Java bytecode. I've successfully used NestedVM, but the performance hit is not acceptable for a project I'm working on. I've also seen various open source projects aimed at this problem and a couple of commercial products. This SO question deals with general problem of converting non-Java into Java source, but I only want to go from C to Java bytecode.

What's the best way to compile C source code into high-performance, pure Java bytecode?

like image 276
Rich Apodaca Avatar asked Jan 20 '09 01:01

Rich Apodaca


People also ask

Does JVM convert source code to byte code?

Compiler converts the source code or the Java program into the Byte Code(or machine code), and secondly, the Interpreter executes the byte code on the system. The Interpreter can also be called JVM(Java Virtual Machine).

Which converts source code to byte code in Java?

The Java compiler (javac) converts the source code into bytecode. Bytecode is a kind of average machine language. This bytecode file (. class file) can be run on any operating system by using the Java interpreter (java) for that platform.

How is source code converted to bytecode?

A compiler converts the source code to bytecode, an intermediary code that bridges the gap between the high-level source code and low-level machine code. The compiler is a special type of program that translates statements in the source code to bytecode, machine code or another programming language.

Do C programs compile to bytecode?

C typically is compiled into “object code” (no relation to OOP) files that contain machine code. Java is compiled into “bytecodes” than can theoretically run on any system by the use of a bytecode interpreter.


2 Answers

Being the author of Cibyl, I might be biased here. Anyway, I've looked at the java bytecode generated by the axiomatic C compiler, and it is not efficient. NestedVM and Cibyl both works by compiling MIPS binaries and then translating the binary into Java bytecode. It's surprisingly efficient, with the main problem being memory access of 8- and 16-byte values (which needs to be done in multiple steps).

NestedVM and Cibyl have slightly different performance characteristics, with Cibyl typically being faster for integer-heavy workloads whereas NestedVM handles floats and doubles better. This is because Cibyl uses GCC soft-float support (though using "real" Java bytecode floating point instructions) while NestedVM translates MIPS FPU instructions.

Cibyl is also more targeted to J2ME environments, although it's definately useable on other platforms as well. My guess is that you would have more luck with either of them than with the Axiomatic C compiler.

like image 161
Simon Kågström Avatar answered Sep 22 '22 10:09

Simon Kågström


It's not exactly what you asked for, but Cibyl converts compiled C programs into JVM bytecode. It's the same idea as NestedVM (which you mentioned) but might be faster for your task being as how it's an independent implementation.

like image 32
geocar Avatar answered Sep 21 '22 10:09

geocar