Concepts with Symbian OS (779878), страница 63
Текст из файла (страница 63)
This is generally software compiled for the hardware machinebeing emulated. Sometimes, depending on the way the virtual machine isimplemented, the software needs to be compiled in a special manner. If itdoes, it generally cannot take advantage of all features of hardware – realexecution and testing needs to be done on real hardware.Symbian OS provides a good example of this. In the emulated, virtualmachine environment, it provides for software development: the systemlibraries are delivered as Windows DLL-format files and the softwareunder development must be compiled specifically for the emulator environment. This is because the emulator does not execute a specifichardware’s instructions.
Since the hardware cannot be emulated exactly,304VIRTUAL MACHINESto test various parts of it (e.g., timers and real-time components) softwaremust be run on the actual smartphone target.Sometimes there is no clear difference between the operating system layer and the hardware layer. For example, on the Java virtualmachine, there is no operating system – just emulated hardware.
Sometimes, because certain operating systems are designed for many differenthardware platforms, only the operating system layer is present in thevirtual machine, assuming that it will run on the native host architecture.A virtual machine must emulate both user and privileged mode, butruns on the host machine in user mode. This means that system calls onthe virtual machine must be translated into appropriate system calls onthe host machine.
User mode operation on a virtual machine can executeon the virtual machine. Any access to privileged hardware – almost anysystem resource – must go through the host system.The Challenges of Virtual MachinesVirtual machines are interesting and effective in concept, but are difficultto implement in reality. The biggest challenge to implementation is theexact duplication required for emulation. The goal for implementationis to use exactly the same code for the operating system layer as in thetarget platform, but this is not always possible. If the hardware layer isneeded, exact duplication is again required, but very difficult to render.A good example is the Symbian OS emulator.
Symbian OS is designedto run on multiple platforms. However, the Windows emulator for Symbian OS required a special implementation with special restrictions(Chapter 7 discussed the special memory model developed for SymbianOS when it ran on the emulator). For many programs, the emulatedvirtual machine looks identical to the target hardware. However, certainprograms can only be tested on the target. Programs that work specifically with hardware, for instance, cannot be tested on the emulator. Also,programs that rely on processes cannot run on the emulator becausethe operating environment is one large process.
Since Symbian OS v9.1,these restrictions have mostly been eased; the design of Symbian OS hassince incorporated Windows as a target platform and the design of theemulator more closely resembles hardware.Virtual machines also suffer in terms of performance. Virtual machinesthat are not optimized are basically interpreters: they translate actions byprograms they are executing into actions that can be executed by the hostmachine. In a virtual-machine implementation with multiple layers, eachTHE JAVA VIRTUAL MACHINE AND SYMBIAN OS305layer is an interpreter. The Java Virtual Machine (JVM) is an example ofthis: Java is based on bytecode execution, but there is no computer systemthe JVM runs on that executes JVM instructions (‘bytecode’) directly.So each bytecode instruction must go through an interpretation, whereactual hardware instructions that implement each bytecode instruction areeventually executed on that bytecode instruction’s behalf. Each passagethrough an implementation layer represents a performance degradation.One of the most complex challenges to virtual-machine implementation is the access to the host machine’s system resources.
A major issuethat virtual-machine implementations must deal with is access to disk-filesystems. Consider a situation where the host system is running MicrosoftWindows with an NTFS file system but the virtual machine runs a Unixoperating system with a UFS file system. Clearly, these are incompatible.Consider again a situation where the virtual machine requires access toa peripheral, say a printer, that is being coordinated by the host operating system.
These situations all require special handling. Usually, virtualdevices are connected with physical devices through special interfacesthat merge the virtual machine with the host machine’s device mechanisms. Disks, however, are a special case. These are usually handled bycreating virtual disks that operate inside file space on physical disks. ALinux virtual machine might have a 10 GB virtual disk that is connectedto a 10 GB file on a physical disk. The Symbian OS emulator can provide drives that are actually files on the host’s system, as well as MMCemulation and an emulation of ROM.15.2The Java Virtual Machine and Symbian OSThe implementation of the JVM on Symbian OS provides an interestingcase study in the implementation of virtual machines.Before looking at implementation issues, we must clarify which JVMis implemented for the Symbian OS platform.
Symbian OS has supportedJava for quite a long time – since the days when Symbian OS was actually EPOC, implemented on handheld devices, not smartphones. EarlySymbian OS versions supported two types of JVM: PersonalJava and JavaPlatform, Micro Edition (Java ME). PersonalJava was an early attemptto pare down the Standard Edition of Java to fit into smaller platforms.It has largely been abandoned in favor of Java ME implementations.Java ME is a general specification of how Java fits on small platforms.Java ME is subdivided into configurations, profiles and optional packages.
For their implementations, Symbian OS designers implemented306VIRTUAL MACHINESthe Mobile Information Device Profile (MIDP) with the Connected Limited Device Configuration (CLDC). The CLDC defines the base set ofapplication-programming interfaces and the Java Virtual Machine forresource-constrained devices such as mobile phones, pagers, and mainstream personal digital assistants. When put together with MIDP, itprovides a Java platform for developing applications to run on deviceswith limited memory, processing power and graphical capabilities.As we stated, the JVM is an interesting virtual machine in that it hasno operating system.
Its sole existence is to implement an operatingenvironment for program execution. Java applications are implementedas a set of classes that are dynamically loaded as needed by the virtualmachine. Java classes, in turn, are compiled to a sequence of bytecode’,which is Java’s terminology for assembly language. Java bytecode isdesigned to have short instructions that could be loaded from anywhere:from a disk drive or over a network.The Java Virtual Machine is an abstract computer that provides aninsulation layer between the Java program and the underlying hardwareplatform and operating system.The JVM can be divided into several basic parts that are implementedin software to emulate a virtual underlying hardware layer: bytecodeexecution stack, a small number of registers, the object heap and themethod area which stores streams of bytecode.
The JVM also provides amechanism of native access to the host operating system.The JVM reads sequences of bytecode, which is a sequence of assemblyinstructions for the JVM. Each instruction consists of an opcode thatinstructs the JVM on what needs to be done and the following instructionoperands provide the required information for the completion of thecommand. As well as having in-built support for several primitive types,the JVM bytecode set includes instructions that operate on operands asobjects in order to invoke instance and static-class methods.The JVM has its own architecture. While this architecture is a virtual architecture implemented in software, it nonetheless influences theinstruction set design of JVM bytecode.
The JVM is based on a stackdesign, which means that all data for computation must be pushed ontothe stack, so it can be used in calculation, and that the JVM needs noregisters for storing data. The combination of the emulated hardwarearchitecture, bytecode design and class-file format make a unique designthat is at a much higher level compared to real hardware. It has featuresthat enable fast interpretation of instructions: class-file-constant pools thatEXERCISES307allow loading and storing of constants by using short assembly instructions, a typed data stack and registers that hold the program counter andmanage the stack.In addition to emulating virtual hardware, the JVM provides a mechanism of native access to the host operating system.
This means that implementation areas and various capabilities that are out of the scope of thevirtual machine role as a bytecode execution engine can be implementedusing the operating system native APIs. Symbian OS takes advantageof this mechanism by providing its Java ME implementation access toits rich native APIs. For example, the javax.microedition.lcdui.TextField class is implemented as a native Symbian OS widget and soa Java program benefits from the underlying usage of the native AVKONwidget implementation on a Nokia phone or the UIQ widget implementation on a Sony Ericsson phone. The two run the same Java program, basedon the same interfaces and JVM, but with a different look derived fromthe manufacturer-dependent native implementation of the user interface.Access to system resources is granted through standard Java APIs such asthe Bluetooth API and the Messaging API.15.3SummaryThis chapter has given a broad overview of the concept of virtualmachines and how virtual machines can be used by operating systems.We began by defining virtual machines and outlining their advantagesand challenges.
We concluded the chapter by giving an example of howthe Java virtual machine is implemented on Symbian OS.Exercises1.Describe the sequence of actions or calls that must take place fora program in a virtual machine on virtual hardware to write to thevirtual machine’s disk drive.2.Consider memory management on a virtual machine. Would thehost or the virtual machine map the virtual machine’s logical addressrequests to physical addresses? Would the host or the virtual machinedo paging if an application on the virtual machine referenced a pagethat was not in memory?308VIRTUAL MACHINES3.What are the consequences of a poor emulation? Is it sufficientto simply state that a virtual machine ‘approximates’ an operatingenvironment?4.The JVM has an architecture that allows for very short bytecodeinstructions.
Why is this advantageous for Java?5.Does the design of Java have any implications for its performance onSymbian OS?Appendix AWeb Resourceshttp://developer.symbian.com/mainhttp://en.wikipedia.org/wiki/List of operating systemswww.imc.orgwww.kernelthread.com/mac/oshistorywww.knoppix.orgwww.levenez.com/unixwww.microsoft.com/windows/WinHistoryIntro.mspxwww.opengroup.orgwww.pushl.com/taskspywww.renegade-uiq.comwww.ubuntu.orgReferencesCampbell, J.