Sure, that’s one major strength of LLVM: we could decide on a runtime function (CallVirtualMethod) that will get lowered depending on the underlying VM. I don’t see any difficulties in accomplishing this.
Is it common practice to emit function calls that are expected to be lowered by a later pass? I know LLVM uses this kind of thing with intrinsics (llvm.gcroot, for instance), but a pass lowering calls to specific functions seems very… messy.
It is not lowering calls to specific functions but emitting a virtual call: we could decide to have a runtime call (ie that will get lowered) to get the virtual table of the object and put the indirect call instruction in place (ie it will not get lowered). Or a single runtime call that will get lowered to both getting the virtual table and do the indirect call.
What about something like a --emit-unlowered-llvm option on llcj that just spits out the LLVM IR before running this lowering pass?
Yes, that’s what I had in mind. llcj is just a driver here for VMKit, the real executable is vmjc, to which you can give a number of passes, including your pass that will lower your virtual call.
LLVM is capable of generating dwarf/unwind tables at compile-time (and also in a JIT environment), so you should get access to these tables in a standard fashion. The only caveat is that you need to change VMKit and they way it compiles exception handlers and exception checks.
Could this be another case for emitting calls in the IR that are lowered by a later pass?
This is much more difficult, but we could try to have something like that. On the list of difficulties: where is the exception handler IR located? who references it? how to prevent dead code elimination to remove it?
Avian only needs a 1-word header - it uses the lower bits of the vtable pointer for GC and hashing.
Cool. And on a synchronized, it pushes the header on the stack? Or Avian is not multi-threaded?
- Able to output object files (preferably) or assembly for the target platform, with appropriate global symbols for functions, etc. to be linked as a boot image.
VMKit already does that, thanks to LLVM code generators.
I was more concerned with whether this is what the llcj driver does.
Yes, llcj can generate assembly files, dynamic libraries, object files, executables, etc.
On the VMKit side, I’d be worried about the implications of adding extra steps in the compilation process, particularly if their only purpose is supporting another VM.
VMKit is framework-driven, so we won’t mind extra steps in the compilation process, especially if it ends up demonstrating the modularity of VMKit. And I would love to be able to specify on the command line what kind of object header I want, what kind of exceptions, how to implement virtual calls and optimize them, etc. All of these would be implemented as LLVM pass.
Personally, if I were a VMKit developer, such a feature would be high on my list of things to remove, unless such a feature turned out to be useful in other ways.
Bare in mind that VMKit is research- and framework-driven. For run-time execution of VMKit, performance is always important, so we have to be careful (but adding LLVM passes does not cost at all). For ahead of time compilation, we should aim at having something the more generic as possible.
Is this a feature that could genuinely improve VMKit, or do you see this as something that would only end up being used with Avian?
It will definitely improve VMKit. It may end up only being used with Avian, but at least it opens more opportunities.
It sounds as if the big sticking point is support for 64-bit linux. It wouldn’t be all that bad to require cross-compiling all AOT Avian builds from a linux machine (not worrying about building on windows), but I don’t think I could justify supporting only 32-bit linux as a build platform. 32 bit systems are on their way out.
64-bit linux is near to being fully supported. There is little code in VMKit (except the GC) that is arch-dependent.
Just to be clear, I do fully intend on using llvm - the only question is what I use to compile class files down to llvm IR (or directly to native object files).
Using the vmjc tool in VMKit and LLVM lowering passes seems like a nice option to me.