java front-end

Hi,

I’m trying to use the Java front-end (which, based on svn commits, appears to be three-years-dead), and I’m running into some build errors. In that time did llvm change from building with exception handling and rtti to building without?

I remember reading somewhere that llvm code should use dyn_cast instead of dynamic_cast. Do these need to be changed here?

A little background:
I’m trying to use llvm as a replacement aot compiler for the Avian JVM (see oss.readytalk.com). I figured I may be able to complete the java front end, and sufficiently parameterize it to be used with Avian (which will essentially just provide runtime services like GC and exception handling).

Sincerely,
Joshua

Here is the output of the build (after ./configure):

make[1]: Entering directory /home/jowarner/code/llvm/projects/java/lib' make[2]: Entering directory /home/jowarner/code/llvm/projects/java/lib/ClassFile’
llvm[2]: Compiling ClassFile.cpp for Release build
In file included from ClassFile.cpp:17:
/home/jowarner/code/llvm/projects/java/include/llvm/Java/ClassFile.h:24:36: warning: llvm/Support/DataTypes.h: No such file or directory
ClassFile.cpp:21:32: warning: llvm/Config/alloca.h: No such file or directory
In file included from ClassFile.cpp:17:
/home/jowarner/code/llvm/projects/java/include/llvm/Java/ClassFile.h:58: warning: comma at end of enumerator list
ClassFile.cpp: In function ‘uint8_t::readU1(std::istream&)’:
ClassFile.cpp:56: error: exception handling disabled, use -fexceptions to enable
ClassFile.cpp: In static member function ‘static std::vector<llvm::sys::Path, std::allocatorllvm::sys::Path > llvm::Java::ClassFile::getClassPath()’:
ClassFile.cpp:143: error: ‘class llvm::sys::Path’ has no member named ‘toString’
ClassFile.cpp:146: warning: comparison is always true due to limited range of data type
ClassFile.cpp: In static member function ‘static llvm::sys::Path llvm::Java::ClassFile::getFileForClass(const std::string&)’:
ClassFile.cpp:167: error: ‘class llvm::sys::Path’ has no member named ‘toString’
ClassFile.cpp: In member function ‘llvm::Java::ConstantClass* llvm::Java::ClassFile::getConstantClass(unsigned int) const’:
ClassFile.cpp:218: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantMemberRef* llvm::Java::ClassFile::getConstantMemberRef(unsigned int) const’:
ClassFile.cpp:225: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantFieldRef* llvm::Java::ClassFile::getConstantFieldRef(unsigned int) const’:
ClassFile.cpp:232: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantMethodRef* llvm::Java::ClassFile::getConstantMethodRef(unsigned int) const’:
ClassFile.cpp:239: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantInterfaceMethodRef* llvm::Java::ClassFile::getConstantInterfaceMethodRef(unsigned int) const’:
ClassFile.cpp:247: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantNameAndType* llvm::Java::ClassFile::getConstantNameAndType(unsigned int) const’:
ClassFile.cpp:254: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In member function ‘llvm::Java::ConstantUtf8* llvm::Java::ClassFile::getConstantUtf8(unsigned int) const’:
ClassFile.cpp:261: error: ‘dynamic_cast’ not permitted with -fno-rtti
ClassFile.cpp: In constructor ‘llvm::Java::CodeAttribute::CodeAttribute(const llvm::Java::ClassFile*, uint16_t, std::istream&)’:
ClassFile.cpp:688: warning: unused variable ‘length’
ClassFile.cpp: In constructor ‘llvm::Java::ExceptionsAttribute::ExceptionsAttribute(const llvm::Java::ClassFile*, uint16_t, std::istream&)’:
ClassFile.cpp:754: warning: unused variable ‘length’
make[2]: *** [/home/jowarner/code/llvm/projects/java/lib/ClassFile/Release/ClassFile.o] Error 1
make[2]: Leaving directory /home/jowarner/code/llvm/projects/java/lib/ClassFile' make[1]: *** [ClassFile/.makeall] Error 2 make[1]: Leaving directory /home/jowarner/code/llvm/projects/java/lib’
make: *** [all] Error 1
jowarner@jowarner-pc:~/code/llvm/projects/java$ find …/…/include/ -name DataTypes.h
…/…/include/llvm/System/DataTypes.h
jowarner@jowarner-pc:~/code/llvm/projects/java$ find …/…/include/ -name alloca.h

I believe so. LLVM now builds with EH and RTTI disabled by default. To build with them on, you need to define these environment variables:

REQUIRES_EH=1
REQUIRES_RTTI=1

Trevor

Hi Joshua,

I'm trying to use the Java front-end (which, based on svn commits, appears
to be three-years-dead),
I'm trying to use llvm as a replacement aot compiler

I'm not acquainted with the Avian JVM, but
haven't you considered using VMkit llvm project, it contains
.class/.jar to llvm compiler, also JIT compiler(native code compiler)
and aot compiler.
And it's not three years-old

Regards,
Minas

Hi Minas,

Thanks! I wasn’t aware that VMKit had the ability to generate llvm code from .class / .jar files - I thought all of its code-generation capabilities were very closely tied to the VM itself. I’ll look into this.

The motivation behind this project is to be able to get both the small size and fast startup times of Avian, along with the speed of llvm-generated code.

Currently, to do aot compilation, Avian runs its (completely non-optimizing, but blazingly fast) JIT over all the methods in the selected classpath, and stores these methods in a bootimage, which it links statically with the main Avian executable. All I want to do is use the llvm code generation in place of the Avian JIT when making this aot-compiled boot image.

Regards,
Joshua

Hi Joshua,

VMKit should be a perfect fit for your purposes. VMKit can take Java classes and generate a dynamic library or an executable with it. Currently, it only works on Linux/x86.

You will probably need to change the VMKit specific runtime functions (eg for things like synchronization, exception throwing, object allocations, etc) with Avian runtime functions.

Nicolas