An Example Project Show Convert Java Byte Code to LLVM IR assembler , then compile to standalone executable file
This project is referenced on class2ir, that based on an old llvm version.
So I've changed instruction syntax, reimplemention to stack mode to fix branch problem, and repaired some bugs.
There is a similar project that tinyj2c, it convert java bytecode to c source , it impmentated more function for java
Generated CentOS_x64 and MacOS executable file, and say "Hello world".
There are 2 implemention in the project, branch "emu stack ver" and "register ver", "register_ver" is fastest, but maybe problem that branch static analysis, the "emu_stack_ver" is more slow, no branch problem.
- Enter directory java2llvm/
- Run mac_build.sh or centos_build.sh , then you will get a.out here.
java 1.8
- Centos:
CentOS 7.0 x86_64
llvm-as / llc / clang 5.0
make - MacOS
MacOS 10.15
XCode with cli tools 11.0
- No GC.
- Maybe some of java instruction can't work
- some of java instruction behavior simplify , eg. invokevirtual
- Object memory allocation , like NO inheirt parent class field.
- Add base class java.lang.*, java.io.PrintStream
- Add String to handle text output, StringBuilder to handle string concat
- Trace instruction flow , to fix register var scope bug.
==============
This project is the compiler from class files (Java byte code) to LL files (LLVM IR assembler). Result files can be compiled by llvm-as to standalone binary ELF files.
Features:
- No JDK, no JVM
- Linux x86_64 target arch
- Extreme small size (~10-20 kB ordinary program)
- Use glibc
- Use clang for system object
At this moment project in active development, many things does not work.