Cross-compiling Java-C

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

Do they work well?

+4
source share
2 answers

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

If this is for performance, most likely you will not see an improvement. Java is a garbage collection, and there is currently no algorithm that could efficiently use memory allocation and freeing calls. There have been many researchers trying to solve this problem, and they have interesting solutions, but I have not seen a good commercial product that can scale to large programs. You can watch the conference dedicated to previous ISMM conferences for more information.

If you want to adjust the code, I suggest you use a profiler and find hot methods. Try and optimize the hot methods, and if that is not enough, try using JNI.

+3
source

This is very similar to this question, and the answers may help you: Compiler for translating Java to C.

Summary. . There are tools for this (Toba, GCJ, etc.), but you may not encounter problems with all portable Java libraries. In the end, the tools are likely to do only the PART OF WORK, and you will have to manually compose some of the rest.

A good first step is to convert your Java code only to use the standard libraries available in Java 1.4. In fact, you probably want to wean as much as possible from everything that is not in java.lang packages. * Or java.util. * To simplify the porting procedure.

Depending on the size of your code base, it may actually be easier to rewrite the volume directly, rather than relying on tools. Java and C have a lot of syntax similarities, but the mismatch between C straight procedural code and object-oriented Java objects can cause problems. Automated tools can generate almost invisible C code when trying to get around this, and there is always the opportunity for subtle errors.

Update 2016: Do not do this, not now, and not ever. The parameters that were used for this were not supported (for example, GCJ), and it may be easier to find a developer who owns Java than C. In addition, Java performance continues to improve, and basic implementations tend to have the same performance. Optimized C is even faster, but the edge is getting smaller and smaller with each version of the JRE.

+3
source

Source: https://habr.com/ru/post/1300076/


All Articles