|
A Closer Look at the Squawk VM
(Cont'd from Java Coming to FIRST Robotics Competition)
April 16, 2009 - So what exactly is the Squawk VM? Let's start our look under the hood with a quick review of the role of the virtual machine. A VM takes the place of the operating system or hardware for which the program would ordinarily be tailored. Java is ported to each platform creating a layer isolating an application from the specifics of the hardware and operating system, so there's no need to produce and maintain separate versions of the application. Most commercial virtual machines today are complex, hard to understand, hard to modify, hard to maintain, and hard to port. For many developers, these complexities are dauntingand the result has been constrained development of VMs for small devices, which in turn slows the pace of innovation and growth in the embedded device market. The Squawk VM brings the inherent advantages of Java to embedded development. The portability of Java makes it simpler to migrate applications among platforms; Java eliminates or streamlines many of the low-level tasks of traditional development languages such as C/C++; and for the millions of developers who already write code in Java there is little additional learning curve for building programs for small devices. Originally inspired by the "Squeak" project, a highly portable VM written in Smalltalk, the Squawk VM is written almost entirely in Java to allow developers to use standard IDEs that are more developer-friendly. "Squawk started out as the Java version of Squeak," said Mr. Arseneau. "It's a VM written in a language that implements itself. It gives you Java compliance with a small footprint and CLDC 1.1 compatibility, and it allows you to bootstrap a running system." While most VMs assume there is an operating system, Squawk allows applications to run on the bare metaldirectly on the CPU without any underlying OSso there's less overhead and better control of the device. That means with Squawk, resource-constrained devices don't need additional resources to support a general-purpose OS (in fact, Squawk is turning into an OS, providing the interface to the device it is running on). Developers are free to experiment with different implementations of low-level services, such as device drivers, which are typically buried inside an OS. Squawk also facilitates embedded development by making the effort of porting Java to a new platform much easier. Most vendors of Java focus on the high-volume platforms in order to offset their cost in doing a port and maintaining it. By making the port of Java simpler, the Squawk VM enables smaller organizations to consider using Java on platforms that are not mainstream but are perfectly suited for their application needs. Another huge advantage of the Squawk VM is that it allows developers to run multiple applications on one virtual machineand even migrate a running application to another device. The application can continue running on the new device right where it left off. This capability is done through a Java extension similar to JSR 121. By running multiple applications on one virtual machine, and by using a more compact representation of class files, the Squawk VM makes better use of the constrained resources of small devices. This capability makes it possible, for example, to move software off a device with low battery power onto another device with more battery life, avoiding loss of state information. It also enables developers to write programs that run through the network; the application can move from one device to the next collecting state information and other data. "The ability to migrate applications on the fly could also be extremely useful for load balancing, ensuring fault tolerance, and local debugging of remote applications," said Mr. Arseneau. Squawk is currently the only research VM that is certified under the Java Micro Edition (JME) Java Verified Program. "We put the time and effort into the certification process up front so developers could develop, deliver, and monetize their implementations with confidence," said Mr. Arseneau.
The way the Squawk VM is implemented differs from a traditional virtual machine in several ways. One of the most important is that Squawk can be used to compile and optimize the core VM itself along with user's application, to create a self-contained, optimized application. This is done by using various levels of ahead-of-time compilation levels. Squawk implements a "Split VM" architecture. This is a way of harnessing the power of a workstation/server to reduce the amount of work needed to be done by the smaller target devices. All of the heavy work needed to perform class loading and optimizing is done on the desktop and execution of the result is done on-device. A file format known as "suites" is used to transfer/deploy applications from the desktop to the device. Each suite is a collection of objects, including classes and methods, that are ready to be used by the VM as is, no further transformation needed. Once a suite is closed (i.e. cannot have any more classes loaded into it), it is immutable. An immutable suite can be saved to and loaded from a file. This execute-in-place format results in a significantly reduced start up time when running an application from a suite (as opposed to a dynamically loaded set of classes). The diagram below shows the different steps involved in running Java compile code (.class/.jar files).
| ||||||||||||||||||||||||