Urban, B. (2013). Implementation of a Java just-in-time compiler in Haskell [Diploma Thesis, Technische Universität Wien]. reposiTUm. https://resolver.obvsg.at/urn:nbn:at:at-ubtuw:1-56149
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.<br />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.<br />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.<br />Although implemented in Haskell and therefore at a high abstraction level, our prototype performs well. The performance is compared to mainstream JVMs.<br />