Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running/Interpreting C on top of the JVM?

Is there a way to run plain c code on top of the JVM?
Not connect via JNI, running, like you can run ruby code via JRuby, or javascript via Rhino.

If there is no current solution, what would you recommend I should do?
Obviously I want to use as many partials solutions as I can to make it happen.

ANTLR seems like a good place to start, having a full "ANSI C" grammar implementation...
should I build a "toy" VM over the JVM using ANTLR generated code?

like image 437
amitkaz Avatar asked Jan 07 '09 20:01

amitkaz


People also ask

Can C run on JVM?

Yes. Here's a commercial C compiler that produces JVM bytecode.

How does a JVM interpreter work?

The JVM converts that code into machine code using the Java interpreter. The JVM uses the interpreter at runtime, after that it execute the code on the host machine. As the Java compiler compiles the source code into the Java bytecode.

What is use of interpreter in Java?

Interpreter in Java is a computer program that converts high-level program statement into Assembly Level Language. It is designed to read the input source program and then translate the source program instruction by instruction.

Does interpreter produce machine code?

An interpreter translates code into machine code, instruction by instruction - the CPU executes each instruction before the interpreter moves on to translate the next instruction.


2 Answers

Updated 2012-01-26: According to this page on the company's site the product has been bought out and is no longer available.

Yes.

Here's a commercial C compiler that produces JVM bytecode.

like image 63
joel.neely Avatar answered Sep 25 '22 18:09

joel.neely


There are two other possibilities, both open-source:

JPC emulates an entire x86 pc within the JVM, and is capable of running both DOS and Linux.

NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file. Hence any application written in C, C++, Fortran, or any other language supported by GCC can be run in 100% pure Java with no source changes.

like image 43
rasjidw Avatar answered Sep 22 '22 18:09

rasjidw