Game Development Reference
In-Depth Information
The Kernel
Starting at the bottom of the stack, you can see that the Linux kernel provides the basic drivers
for the hardware components. Additionally, the kernel is responsible for such mundane things as
memory and process management, networking, and so on.
The Runtime and Dalvik
The Android runtime is built on top of the kernel, and it is responsible for spawning and running
Android applications. Each Android application is run in its own process with its own Dalvik VM.
Dalvik runs programs in the Dalvik Executable (DEX) bytecode format. Usually, you transform
common Java .class files into DEX format using a special tool called dx , which is provided by
the software development kit (SDK). The DEX format is designed to have a smaller memory
footprint compared to classic Java .class files. This is achieved through heavy compression,
tables, and merging of multiple .class iles.
The Dalvik VM interfaces with the core libraries, which provide the basic functionality that
is exposed to Java programs. The core libraries provide some, but not all, of the classes
available in Java Standard Edition (SE) through the use of a subset of the Apache Harmony
Java implementation. This also means that there's no Swing or Abstract Window Toolkit (AWT)
available, nor any classes that can be found in Java Micro Edition (ME). However, with some
care, you can still use many of the third-party libraries available for Java SE on Dalvik.
Before Android 2.2 (Froyo), all bytecode was interpreted. Froyo introduced a tracing JIT
compiler, which compiles parts of the bytecode to machine code on the fly. This considerably
increases the performance of computationally intensive applications. The JIT compiler can use
CPU features specifically tailored for special computations, such as a dedicated Floating Point
Unit (FPU). Nearly every new version of Android improves upon the JIT compiler and enhances
performance, usually at the cost of memory consumption. This is a scalable solution, though, as
new devices contain more and more RAM as standard fare.
Dalvik also has an integrated garbage collector (GC), which, in earlier versions, has had the
tendency to drive developers a little crazy at times. With some attention to detail, though, you
can peacefully coexist with the GC in your day-to-day game development. Starting from
Android 2.3, Dalvik employs an improved concurrent GC, which relieves some of the pain.
You'll get to investigate GC issues in more detail later in the topic.
Each application running in an instance of the Dalvik VM has a total of at least 16 MB of heap
memory available. Newer devices, specifically tablets, have much higher heap limits to facilitate
higher-resolution graphics. Still, with games it is easy to use up all of that memory, so you have
to keep that in mind as you juggle your image and audio resources.
System Libraries
Besides the core libraries, which provide some Java SE functionality, there's also a set of native
C/C++ libraries (second layer in Figure 1-1 ), which build the basis for the application framework
(third layer in Figure 1-1 ). These system libraries are mostly responsible for the computationally
 
Search WWH ::




Custom Search