Scala on LLVM
For this semesters ‘Program Analysis and Transformation’ seminar I took a look on how you could potentially run Scala on the LLVM. I created an overview the motivation, implementation possibilities and challenges. The full paper is here. This blog post is an short overview that paper.
Scala on LLVM
There are three implementation strategies. The first one it to compile Scala with the LLVM tool chain and use it directly. That’s the approach of this project here. Another approach is to implement a JVM on top of LLVM, like in the VMKit project. The third possibility is combine different approaches. For example compile parts of a Scala application with the LLVM tool chain while other parts are compiled to Java byte code. This is mixed approach is interesting to run Scala on specialized Hardware.
Challenges
Scala usually runs on the JVM, which provides much higher level services than LLVM. Therefore when you want to create a 100% Scala implementation you have a lot of stuff to consider. Like garbage collection, threading, the Java memory model, reflection, debugging, dynamic class loading and support for existing Java libraries. Of course you can omit some features if they are not needed for a certain environment.
Interesting Subsets
Finally the interesting subsets can be the motivation for porting Scala to LLVM.
Embedded Systems
One possibility would be to bring Scala to embedded, small systems. Instead of requiring a JVM we could compile Scala down to native code. Of course for such a system it makes sense to remove certain features to keep the implementation small. Stuff like dynamic class loading it probably not needed.
Scala in Flavors
One motivation to port Scala could be to create Scala in ‘flavors’. For example that we can parts of a Scala program on specialized hardware, like a GPU. The idea is to isolate certain parts of program, then compile it with the LLVM tool chain for the specialized hardware. The rest is executed normally on a JVM. While the basic idea is simple, in practice it is hard. Nevertheless its a very interesting idea.
Compiled Scala
The last thing is to create a full blown, compiled Scala version. However I doubt that it is worth the effort. And you basically can by this already here =).
More Stuff
Again, here’s the full paper with a lot more details. Here are the slides of the presentation. And there is more stuff from the seminar from other people: LLVM Based Bug Detection, Architecture of Clang, Template Instantiation and Concepts in CLANG, LLVM to PTX Backend.
- Secret Agent Miss Oh
- Mixtape Locations
Very nice Roman, cool work. I wish I would be more familiar with Scala, I might try Android with it.
Best!
German
Hi Roman,
And thanks for linking to us. Have you actually tried compiling Scala apps with Excelsior JET? If so, I’d be most interested to learn about your experience.
Dmitry Leskov
Excelsior LLC
No, I didn’t. But I’m pretty sure that it works.
OK, if you want to give it a shot, drop me a line.