Furthermore, because safe languages
have a fully defined semantics, unlike
languages like C, with one semantics if a program obeys the language
rules and no guarantees if they don’t,
program-analysis tools are not put in
the untenable position of assuming a
buggy program plays strictly according
to the language definition.
Safe languages are far more popular
since the introduction of Java but are
generally considered inappropriate for
systems code, which is usually written
in a low-level, glorified assembly language like C or its more sophisticated
cousin C++. The common belief is that
safe languages are inefficient, due in
part to the size and complexity of their
runtime systems and reliance on garbage collection.
Singularity’s Bartok compiler provides language safety without the typical performance penalty by compiling
C#’s Microsoft Intermediate Language
representation to native (x86, x64, or
ARM) code at installation time rather
than at runtime. Bartok also links compiled code to a small runtime consisting of only a class library and a garbage
collector, not a large runtime environment like the Common Language Runtime (the virtual machine component
of Microsoft .NET) and the Java Virtual
Machine. The Shared Source Common
Language Infrastructure runtime and
class library are more than five times
larger than the Bartok runtime ( 64
thousand lines of code, or KLOC, vs.
350KLOC), roughly the same as the C
runtime in the latest version of Windows (72KLOC). Moreover, Bartok is a
highly optimizing compiler that generates high-quality code and reduces
memory use through extensive tree
shaking to discard unneeded class variables and method definitions.
Table 1 emphasizes this point by
outlining the memory footprint for a
small program written in C, C++, and
C# running on several different oper-
ating systems. The program outputs
“Hello World” using the standard I/O
libraries and APIs for each system—
printf for C and C++ and Console.
WriteLine for C#. The C# code on
Singularity is smaller than for all but
one other system—the statistically
linked code on Free BSD—in some
cases half to one-third the size of C++
code. Table 2 outlines the reduction
in memory footprint Bartok achieves
for a variety of programs. Much of the
code and data “shaken” out of these
programs comes from the unused por-
tions of general-purpose libraries.
Table 1. memory footprint for “hello World” process (in kilobytes).
c - static lib
c++ - static lib
c# - w/ Gc
freeBSD 5. 3 Linux 2. 6. 11 (Red hat fc4) Windows XP (SP2)
232Kb 664Kb 544Kb
704Kb 1,216Kb 572Kb
— — 3,750Kb
Table 2. memory-footprint reduction due to tree shaking.
iDe Disk Driver
code (Tree Shake)
figure 2. Singularity process objects reside on a dedicated collection of pages.