从C Source到Java Bytecode?

时间:2021-02-18 17:20:41

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.

我正在寻找一种将C源代码编译成高性能Java字节码的方法。我已成功使用NestedVM,但对于我正在处理的项目而言,性能损失是不可接受的。我还看到了针对这个问题的各种开源项目以及一些商业产品。这个SO问题涉及将非Java转换为Java源代码的一般问题,但我只想从C转换为Java字节码。

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

将C源代码编译成高性能,纯Java字节码的最佳方法是什么?

5 个解决方案

#1


6  

Um, that's called "a compiler". You're asking for a C compiler that targets the JVM.

嗯,那叫做“编译器”。您要求的是一个以JVM为目标的C编译器。

Google for that and you will find the Axiomatic Ansi C Compiler.

谷歌为此,你会发现Axiomatic Ansi C编译器。

#2


9  

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).

作为Cibyl的作者,我可能会有偏见。无论如何,我已经看过了公理化C编译器生成的java字节码,效率不高。 NestedVM和Cibyl都可以通过编译MIPS二进制文件然后将二进制文件转换为Java字节码来工作。它的效率令人惊讶,主要问题是8字节和16字节值的存储器访问(需要在多个步骤中完成)。

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.

NestedVM和Cibyl的性能特征略有不同,Cibyl通常对整数繁重的工作负载更快,而NestedVM处理浮动和双倍更好。这是因为Cibyl使用GCC软浮点支持(尽管使用“真正的”Java字节码浮点指令),而NestedVM则转换MIPS FPU指令。

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.

Cibyl也更适合J2ME环境,尽管它在其他平台上也可以使用。我的猜测是,你会比使用Axiomatic C编译器更幸运。

#3


4  

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.

这不完全是你要求的,但Cibyl将编译的C程序转换为JVM字节码。它与NestedVM(您提到过)的想法相同,但对于您的任务来说可能更快,因为它是一个独立的实现。

#4


3  

I believe some projects have attempted this, but there is just no way to deal with pointers without some pretty severe restrictions about what can access what (essentially they have to be converted into array indexes and arrays allocated instead of memory)

我相信有些项目已经尝试过这个,但是没有办法处理指针而没有对什么可以访问什么(基本上他们必须转换为数组索引和数组而不是内存)的严格限制

If you have C without too much reliance on pointers, and you want it into the JVM, you might just convert it to Java--should be pretty easy and the performance shouldn't be too bad. C still beats Java in most areas by about 2x with some areas much worse and in a few areas Java actually beats C (heap memory management, for one), but compared to most other languages (interpreted ones at least), java and c are 100x faster, so the difference between them is pretty meaningless from that point of view.

如果你有C而不太依赖指针,并且你想要它进入JVM,你可能只是将它转换为Java - 应该非常简单并且性能不应该太糟糕。在大多数领域,C仍然大约是2倍,有些领域更糟糕,在一些领域,Java实际上胜过C(堆内存管理,一个),但与大多数其他语言(至少是解释的)相比,java和c是快100倍,因此从这个角度来看,它们之间的区别是毫无意义的。

#5


1  

try C2J software................

尝试C2J软件................

type c to java translator in google .you will get the link to download

在google中输入c到java转换器。你将获得下载链接

#1


6  

Um, that's called "a compiler". You're asking for a C compiler that targets the JVM.

嗯,那叫做“编译器”。您要求的是一个以JVM为目标的C编译器。

Google for that and you will find the Axiomatic Ansi C Compiler.

谷歌为此,你会发现Axiomatic Ansi C编译器。

#2


9  

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).

作为Cibyl的作者,我可能会有偏见。无论如何,我已经看过了公理化C编译器生成的java字节码,效率不高。 NestedVM和Cibyl都可以通过编译MIPS二进制文件然后将二进制文件转换为Java字节码来工作。它的效率令人惊讶,主要问题是8字节和16字节值的存储器访问(需要在多个步骤中完成)。

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.

NestedVM和Cibyl的性能特征略有不同,Cibyl通常对整数繁重的工作负载更快,而NestedVM处理浮动和双倍更好。这是因为Cibyl使用GCC软浮点支持(尽管使用“真正的”Java字节码浮点指令),而NestedVM则转换MIPS FPU指令。

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.

Cibyl也更适合J2ME环境,尽管它在其他平台上也可以使用。我的猜测是,你会比使用Axiomatic C编译器更幸运。

#3


4  

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.

这不完全是你要求的,但Cibyl将编译的C程序转换为JVM字节码。它与NestedVM(您提到过)的想法相同,但对于您的任务来说可能更快,因为它是一个独立的实现。

#4


3  

I believe some projects have attempted this, but there is just no way to deal with pointers without some pretty severe restrictions about what can access what (essentially they have to be converted into array indexes and arrays allocated instead of memory)

我相信有些项目已经尝试过这个,但是没有办法处理指针而没有对什么可以访问什么(基本上他们必须转换为数组索引和数组而不是内存)的严格限制

If you have C without too much reliance on pointers, and you want it into the JVM, you might just convert it to Java--should be pretty easy and the performance shouldn't be too bad. C still beats Java in most areas by about 2x with some areas much worse and in a few areas Java actually beats C (heap memory management, for one), but compared to most other languages (interpreted ones at least), java and c are 100x faster, so the difference between them is pretty meaningless from that point of view.

如果你有C而不太依赖指针,并且你想要它进入JVM,你可能只是将它转换为Java - 应该非常简单并且性能不应该太糟糕。在大多数领域,C仍然大约是2倍,有些领域更糟糕,在一些领域,Java实际上胜过C(堆内存管理,一个),但与大多数其他语言(至少是解释的)相比,java和c是快100倍,因此从这个角度来看,它们之间的区别是毫无意义的。

#5


1  

try C2J software................

尝试C2J软件................

type c to java translator in google .you will get the link to download

在google中输入c到java转换器。你将获得下载链接