Horizon

What is horizon?

Horizon is a bytecode and a bytecode compiler, designed with systems programming in mind. The bytecode language itself is similar in structure to a typed high-level assembly language; it is intended to be a target language for a high-level language compiler (like the 'H' language packaged with horizon).

What's the point?

Modern operating systems are designed to make use of a hardware memory management unit (MMU) for process isolation - ensuring that one process cannot interfere with another. It also uses a feature of the processor to ensure that user code cannot run privileged instructions that could affect the integrity of the system. The address space and processor mode switches this entails reduces the efficiency of the system.

The alternate approach is that of using language features to facilitate process isolation (SIPs or Software Isolated Processes). This involves writing all programs (and most of the OS kernel) in a managed, typesafe language that does not allow unsafe pointer arithmetic. The correctness (to an extent) of the program can then be guaranteed by the compiler, and the resulting code run with supervisor privileges.

Inferno has been doing this for years; Microsoft Research's Singularity does the same using Sing#, and there are open source efforts to write SAS OSes in C# (Cosmos) or Java (JNode).

So what's different about Horizon?

C# and Java were not written with pure speed in mind, as C was. C# and Java both have strict exception handling requirements, which either produces slower code or rather slow unwinding. Catching NullPointerExceptions and the like and being able to recover program flow is costly. Most exception handlers (excepting safety critical systems here for obvious reasons!) merely throw() and then eventually abort() with a pretty message and stack trace.

Horizon's buzzphrase is "Just Enough Safety (tm)". C provides no safety at all - a C program can destroy its own state as well as anything else in its addressable space. C coupled with a UNIX-like kernel however, is safer. Yes, one can still shoot oneself in the foot, but one can no longer shoot others in the foot. That is the big difference between Horizon and Java.

Horizon is built for speed, and where there is a speed/safety tradeoff will always take the speed option as long as other processes or the system in general cannot be affected. Therefore, null pointers are allowed to be accessed - they just trap and the process is ended. The programmer is responsible for his/her own error detection and correction, C or C++ (with exceptions disabled) style.

In its rawest form, there is no reason why a horizon program should run any slower than the equivalent C program; there are very few bookkeeping overheads. In fact, in one test (drhystone; yes, I know, not the best benchmark in the world) Horizon outperformed C (the compiler was able to reason better about horizon's IL and found the main drhystone loop, finding it did no useful work).

How did Horizon come about?

Myself (JamesM), froggey and AlexExtreme were the initial project members, although the long term architecture of the project was not exactly how it has ended up today! Alex wrote the build system, froggey wrote the initial code generator and core datastructures. He left the project after 3 months, JamesM being the sole contributer from that point.

Horizon was my masters thesis project - in this paper can be found some more of the rationale behind Horizon, as well as an extensive literature review and background information on the subject, along with an introduction to the language.

What's the general architecture?

A high level language (like H, packaged with horizon) compiles down to horizon bytecode. This is then converted to LLVM bitcode and native machine code is generated, either ahead of time using LLVM's JIT, or a hybrid mixture of both.

Your wish is my command.

How can I contribute / get more information / get help?

The IRC channel #horizonos on freenode.net. Ask for JamesM, or send me an email at james AT jamesmolloy DOT co DOT uk.

Also available in: HTML TXT