Using VMKit to convert Java Bytecode to LLVM IR

Hi,

I wanted to use VMKit project to convert Java Bytecode to LLVM IR bitcode. But I do not know how to start, since I came to know that VMkit is written for llvm -3.3 version, but I want it for latest LLVM version 6.0.1.

So, could you please suggest me, whether I have to write it whole project from scratch to meet my requirement of latest llvm version, or can use existing project by building it. Since, I think existing VMKit project which is unmaintained might have a lot of bug to meet latest llvm version.

Also tell me if I have to write it from scratch to convert from Java Bytecode to LLVM IR, what is the basic code flow approach ,how to start and related guidance. Please help me by suggesting above queries.

Thanks & Regards
Ratnesh Tiwari

There’s been a lot of code changes from LLVM 3.3 to LLVM 6.0, so expecting to just compile vmkit with a newer version of LLVM is not going to work.

Translation of pure JVM bytecode to LLVM itself is not particularly challenging. You do need a garbage collector, which LLVM does not provide, but that does not make the conversion that much harder. The difficult part is that any effective project requires an implementation of several Java classes that are very closely tied to implementation details (particularly things like java.lang.Class or java.lang.String). The most obvious source of the Java library (OpenJDK) essentially requires you to implement the full and complex dynamic class loading interfaces before you can even get a simple hello world application running.

VMKit did spend a lot of effort in being able to use the OpenJDK’s implementation of the Java library, so while it may be a substantial amount of effort to get VMKit to a newer version of LLVM (or OpenJDK, for that matter), it is probably easier to do that instead of writing your own JVM-to-LLVM converter.

Hi all,

Thanks for discussing JVM topic!

There’s been a lot of code changes from LLVM 3.3 to LLVM 6.0, so expecting to just compile vmkit with a newer version of LLVM is not going to work.

Translation of pure JVM bytecode to LLVM itself is not particularly challenging. You do need a garbage collector, which LLVM does not provide, but that does not make the conversion that much harder. The difficult part is that any effective project requires an implementation of several Java classes that are very closely tied to implementation details (particularly things like java.lang.Class or java.lang.String). The most obvious source of the Java library (OpenJDK) essentially requires you to implement the full and complex dynamic class loading interfaces before you can even get a simple hello world application running.

VMKit did spend a lot of effort in being able to use the OpenJDK’s implementation of the Java library, so while it may be a substantial amount of effort to get VMKit to a newer version of LLVM (or OpenJDK, for that matter), it is probably easier to do that instead of writing your own JVM-to-LLVM converter.

What about Falcon[1] It is an optimizing Java JIT base on modern LLVM, perhaps it is able to learn from it. And I also have the same question: how to support JDK[2] library?

*From:*llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] *On Behalf Of *Ratnesh Tiwari via llvm-dev
*Sent:* Monday, August 20, 2018 7:20
*To:* llvm-dev <llvm-dev@lists.llvm.org>
*Subject:* [llvm-dev] Using VMKit to convert Java Bytecode to LLVM IR

Hi,

I wanted to use VMKit project to convert Java Bytecode to LLVM IR bitcode. But I do not know how to start, since I came to know that VMkit is written for llvm -3.3 version, but I want it for latest LLVM version 6.0.1.

I love Compiler Principle[3] so I migrated DragonEgg[4] from GCC-4.8 + LLVM-3.3 to GCC-8 + LLVM-6, you can also migrate VMkit from LLVM-3.3 to LLVM-8.

So, could you please suggest me, whether I have to write it whole project from scratch to meet my requirement of latest llvm version, or can use existing project by building it. Since, I think existing VMKit project which is unmaintained might have a lot of bug to meet latest llvm version.

Also tell me if I have to write it from scratch to convert from Java Bytecode to LLVM IR, what is the basic code flow approach ,how to start and related guidance. Please help me by suggesting above queries.

Java Bytecode to LLVM IR is not difficult, but there is graalvm/sulong[5] for transforming LLVM IR to Java Bytecode already :slight_smile:

Thanks & Regards

Ratnesh Tiwari

_______________________________________________
LLVM Developers mailing list
llvm-dev@lists.llvm.org
llvm-dev Info Page

1. http://llvm.org/devmtg/2017-10/#talk12
2. jdk8u/jdk8u-dev/jdk: log
3. https://www.leetcode.cn/2017/12/ilove-compiler-principle.html
4. http://lists.llvm.org/pipermail/llvm-dev/2017-August/116705.html
5. GitHub - graalvm/sulong: Obsolete repository. Moved to oracle/graal.