I finished my master’s thesis. Grab it (oneside/twoside) while it’s hot. It isn’t Simon-quality, but it’s something :-) MateVM is the prototype; unfortunately it’s restricted to 32bit x86 at the moment. If you have such a machine available, give it a try!

Some highlights regarding Haskell:

  • GADTs in the intermediate representation (since this is a requirement of Hoopl)
  • Finally I’ve found an usage for RankNTypes (apart from the ST monad): Since Harpy uses an interesting way to define its instructions via type classes in order to tackle different addressing modes for x86, we need RankNTypes for defining a generic way to emit code for binary operators.
  • Fun with FFI: (1) how to call native machine code from Haskell (2) mechanism to interrupt execution and do things in the run-time system (e.g. code patching)

In general, every part of the current implementation is described, therefore also interesting for people who always wanted to know how to implement a Java virtual machine. A college also started to implement an exact garbage collector, of course in Haskell. Fun stuff.

Performance is not so bad as one would probably expect and with enough manpower it would have similar performance someday. Due to Hoopl, it is an interesting playground for different optimizations. The real issue is to implement a Java VM according to the specification. Sometimes this kills all the fun and makes things inelegant. In particular lazy class loading sucks… Welcome to the real world.

In the past month I’ve learned a lot about Haskell—so, thanks to the Haskell community! I also want to thank the guys behind hs-java, Harpy and Hoopl for their awesome work. Although they are not very widely used, we had surprisingly few issues. I don’t know what is the reason for this; awesome hackers or great language? Probably both :-)


Just-in-time compilation became popular lately, among others, due to the success of the Java programming language. In this thesis we successfully demonstrate a modern prototype of the Java virtual machine implemented as method-based just-in-time compiler in the purely functional programming language Haskell. Motivated by the powerful abstraction mechanism provided by the language, we were able to build a sophisticated compiler. Since a high-level language is used, we had to solve problems regarding the interface between Haskell and native code.

Existing libraries from the Haskell community are used. hs-java for processing Java class files. Hoopl to implement a sophisticated compiler, that supports data-flow analysis on an intermediate representation by making extensive use of the type system. Harpy is used to generate machine code for the target architecture x86 in the manner of a domain specific language. We tried to keep as much as possible in pure code to gain the elegance of Haskell. The compilation pipeline, e.g. JVM stack elimination or linear scan register allocation, is presented in detail in this thesis.

Basic features of a run-time system in order to complete a JVM, such as method invocation, lazy class loading, dynamic type checking or exception handling, are presented.

Although implemented in Haskell and therefore at a high abstraction level, our prototype performs well. The performance is compared to mainstream JVMs.

blog comments powered by Disqus




06 February 2013