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
Singularity
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.
Singularity kernel
Web Server
SPecweb99 Plug-in
iDe Disk Driver
code (Total)
2,371 Kb
2,731 Kb
2,144 Kb
1,846 Kb
code (Tree Shake)
1,291 Kb
765 Kb
502 Kb
455 Kb
Reduction
46%
72%
77%
75%
figure 2. Singularity process objects reside on a dedicated collection of pages.
Process 1
Process 2
Process 3
channel
2
3
1