java2llvm

Introduction: An Example shown convert java class bytecode to llvm ir , then compile llvm ir to standalong executable file .
More: Author   ReportBugs   
Tags:

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

Currently:

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.

Make:

  1. Enter directory java2llvm/
  2. Run mac_build.sh or centos_build.sh , then you will get a.out here.

Requirements:

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

Known issue:

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

change log:

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

==============

class2ir readme

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.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools