tags:

views:

220

answers:

2

Does anyone know of a good Java to C cross compiler?

Do they work well?

+2  A: 

Can you explain why you want to port your Java code to c?

If it's for performance you likely won't see much of an improvement. Java is a garbage collected language and currently there isn't an algorithm that can insert memory allocation and deallocation calls efficiently. There have been many researchers trying to solve this problem and they have some interesting solutions but I have not seen a good commercial product that can scale to large programs yet. You can look at the conference proceeding for previous ISMM conferences for more information.

If you want to speed your code up I suggest that you use a profiler and find the hot methods. Try and optimize the hot methods and if that is still not enough try and use JNI.

scurial
1st we like to go from Java to C, then from C to VHDL (for implementation into either FPGA or ASIC).
Martin Damrau
@Martin: So you want to go from Java to VHDL, and the best path looks like it uses C? You might want to edit your question, or attract a new one, to see if anybody has a better way to start with Java and get VHDL. I am reminded of the mid-90s, when I used f2c to change a Fortran linear programming code to C so I could interface it with Macintosh Common Lisp.
David Thornley
A: 

This is very similar to this question, and answers may be helpful to you: Compiler to translate Java to C.

Summary: There are tools for this (Toba, GCJ, etc), but you may run into problems with not all of the Java libraries being ported. In the end, tools will probably only do PART of the work, and you'll have to hand-code some of the rest.

A good first step is to convert your Java code to only use standard libraries available in Java 1.4. In fact, you'll probably want to wean as much as possible off of anything not in java.lang.* or java.util.* packages in order to simplify the porting procedure.

Depending on the size of your codebase, it may actually be easier to rewrite the bulk directly rather than relying on tools. Java and C have a lot of syntax similarity, but the mismatch between C's straight procedural code, and Java's object oriented features could cause problems. Automated tools may generate virtually unmaintainable C code when trying to work around this, and there's always the possibility for subtle bugs.

BobMcGee