Mobile Device Reference Software
Also for different platform software we may use a reference software model. The reference
software is shown below.
Reference software
Process Process Process
Heap Heap Heap
Thread Thread Thread
Thread Thread Thread
Stack Stack Stack
Stack Stack Stack
Kernel
Mobile System Programming
tommi.mikkonen@tut.fi, Institute of SW systems, TUT
We shortly describe the architecture components.
Kernel
Today’s operating systems are built in layers. The base layer, or the core of the operating system, is
called the kernel. The kernel manages the machine’s hardware resources (including the processor
and the memory), and provides and controls the way any other software component can access these
resources. Because the kernel stays in memory, it is important for the kernel to be as small as
possible.
Process
A process is created by the operating system. Processes contain information about program
resources and program execution state, including: Process ID, process group ID, user ID, and group
ID, environment, working directory, program instructions, registers, stack, heap, file descriptors,
signal actions, shared libraries and inter-process communication tools (such as message queues,
pipes, semaphores, or shared memory).
Thread
The concept of a "procedure that runs independently from its main program” may best describe a
thread. Threads use and exist within processes, yet they are able to be scheduled by the operating
system and run as independent entities within a process. A process can have multiple threads, all of
which share the resources within a process and all of which execute within the same address space.
Within a multi-threaded program, there are at any time multiple points of execution. Because
threads within the same process share resources:
Changes made by one thread to shared system resources (such as closing a file) will
be seen by all other threads.
Two pointers having the same value point to the same data.
Reading and writing to the same memory locations is possible, and therefore requires
explicit synchronization by the programmer.
Stack
A stack is a last-in-first-out storage (mechanism) situated in RAM memory. This memory is needed
for execution. So called activation records are stored in the stack. The activation record is
automatically created when a subprogram starts. Generally the record contains the return address,
return value, subprogram parameters and local subprogram variables. The main program continues
to run from the return address when the subprogram has finished. The current stack address is
monitored by the stack pointer (SP).
Stack content
Previous activation record
Return address
Return value
Activation
Parameters record
Local variables
Other information
Next activation record
Mobile System Programming
tommi.mikkonen@tut.fi, Institute of SW systems, TUT
Heap
Heap is a memory under programmer’s responsibility. At runtime, all the objects that the
applications create and manipulate live on the heap. Local variables and member variables are both
allocated from the heap.
J2SE runtime environments offer megabytes of heap space, MIDP environments much less. An
extreme case is the MIDP for Palm OS environment. On Palm OS devices with little main memory,
the heap can be as small as 20 kB.
Your MIDlet (application) can find out the total size of the heap, and the amount currently
available, by calling methods of the java.lang.Runtime class, totalMemory() and freeMemory().
Note that the runtime system may make use of the heap, which means that your application may not
be able to use all of the memory reported by freeMemory().
A few simple guidelines will help the application perform well with a small heap:
Use as few objects as possible.
Dereference objects when they're no longer useful. That is, set references to them to null as
soon as you can, so they will be garbage-collected.
Catch OutOfMemoryErrors on all allocations, or at least the large ones. Don't let an
OutOfMemroyError take your application by surprise. A polite message from your MIDlet
will look a lot better than the device's default mechanism for displaying a memory error.
The selection and execution of a thread is depending of the environment. This is called scheduling.
Scheduling is pre-emptive if the initiative is taken by the kernel and non-pre-emptive if a thread
takes the initiative.
Infrastructure
Pre-installed Other
application application
processes processes
Operating system processes
Libraries
Middleware (protocols, resource access etc)
Kernel
Mobile System Programming
tommi.mikkonen@tut.fi, Institute of SW systems, TUT
The reference architecture can shortly be described by three levels (starting from the bottom):
Resource platform – This platform is closest to the hardware. Also the operating system is
on this platform.
Architecture platform – Design patterns are defined here. Many library elements and also
middleware belong to this platform. Middleware is between low-level software and the
application process
Application platform – Here we have the applications
The infrastructure is illustrated in a little different way above.
The programmer has to make decisions where some of the features will not be fulfilled.
Architecture design includes a group of compatible solutions that take into account different
demands of different mobile systems. This put design challenges on the programmer
(Mobiiliohjelmointi, 2004):
Flexibility
… with regard to the essential parts of the system
Optimized use of memory
… keep implementation simple, modifiable and robust, but do not use memory in an
uncontrolled way
… especially flash memory can be difficult to master
Performance
… vs. modular and flexible introduction of functions without risking memory consumption
Security
… vs. small memory and minimal performance