HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 
A Look At Java Tools For Embedded Systems, by Sherry Shavor

Given the popularity of the Java software application development platform and the market potential for embedded devices, there's a need to understand how programs can take advantage of the use of Java for embedded application development. This article investigates three Java tools that are available for the embedded engineer and analyzes how well they map to the needs of the embedded community.

This article draws on the results from a study of the emerging embedded Java marketplace. The material was gathered by a team whose skills included a solid knowledge of object-oriented programming, the Java programming language, and embedded and real- time programming. It focuses on the following three products:

  • IBM VisualAge MicroEdition
  • Microware PersonalJava for OS-9
  • Sun KVM

The functions and features of these products as well as the overall lessons learned about the embedded Java environment are also described.

Why Is Java Technology Interesting to the Embedded Market?
The embedded market's interest in Java technology is similar to the interest in Java technology on the desktop. Engineers and device manufacturers want to be able to develop quality code quickly and run the software predictably on different hardware without rewriting code. The "write once, run anywhere" promise of Java programming is very attractive in this marketplace because of the various RTOS (Real-Time Operating System) and hardware combinations. The ability to easily take existing code from one RTOS and run it on another is very appealing to vendors who must continually port their C/C++ and assembler code to each new device. However, as discussed later, using Java requires porting the VM (virtual machine) to the RTOS and the processor the engineer wants to use. Given the large diversity of processors in use in the embedded marketplace, this is a daunting prerequisite. However, once the investment is made, reuse of application code becomes easier.

The amount of function being implemented in software instead of hardware is increasing due to market pressures. Engineers need to adopt new programming technologies such as Java. They're excited about the Java language because it's a well-designed, object-oriented programming language. The concepts built into the language and the way it avoids many of the complexities and error-prone areas in C++ are attractive.

Marketplace Survey Experience
Our group started with a survey of the marketplace to see which VMs existed for which RTOSs. This proved a much harder task than anticipated. The information was gathered by attending conferences such as the Embedded Systems Conference and by searching the Web; we then proceeded to compile a matrix of available tools, VMs, RTOSs, and processors. We learned the following:

Claims Exceed Reality
The marketing brochures can be misleading. When we started this work in March 1999, the marketing brochures led us to believe that a VM is already ported to an RTOS. Further inspection reveals that it may not be available for another six or nine months. Though the marketing brochures are still not very informative, the embedded virtual machines are now becoming available.

Lack of Information
The information on many Web sites is incomplete. In many cases, the information on the Web is insufficient to determine what hardware is supported. For example, a Web site may state that it supports processors from Motorola but not have any more details. In all cases, the companies needed to be called directly to acquire enough information to be able to make a purchase decision.

Desktop Java developers are familiar with looking for a VM that supports the operating systems they choose for development. In the embedded environment this process is more complex.

Multitude of Processors
An embedded VM is written to a particular RTOS but compiled for a specific processor instruction set. Because the VM is actually an executable typically written in C, it must be compiled to a particular instruction set. For instance, the HP Chai VM supports the LynxOS operating system for the Motorola PowerPC processor, specifically the MPC821 processor. It's not sufficient to ask which processor manufacturer (e.g., Motorola) the VM supports - you must be specific about which processor will support the instruction set the VM is compiled to.

Boards and RTOSs
An RTOS supports a specific board, not just the processor. The RTOS must be able to communicate with all the devices connected to the board. For example, the OS-9 operating system from Microware supports specific boards such as the Motorola MBX board. Running an RTOS on a particular board is achieved through a board-support package that's usually provided by the RTOS vendor. When you order the operating system and board, order the board-support package as well.

For an embedded developer these issues may not seem noteworthy. An embedded engineer typically starts with hardware specifications, such as the processor, and then seeks out the software. The typical Java developer usually decides on the software first, then seeks out the appropriate hardware. This was the approach we followed and learned that we needed to be very specific when gathering information.

Many Java Platforms
It's important to understand the profile or type of Java supported by the VM. There are different Java configurations available, such as PersonalJava and EmbeddedJava. When comparing VMs it's important that you understand what Java functionality is available in the VM.

  • PersonalJava: Designed for network-connectable applications for devices, it can also run applets unlike EmbeddedJava. There are numerous implementations from RTOS vendors.
  • EmbeddedJava Application Environment: For embedded devices with dedicated functionality and severely limited memory, it doesn't have a requirement for Web browsing or file systems. EmbeddedJava is intended to run on top of an RTOS. It's an application-driven subset because only the APIs required by the application are included.
  • JavaCard: This API is used in embedded programmable chips that can be embedded in credit cards or other devices. Usage of smart cards is growing in Europe but hasn't penetrated the U.S. market yet. The JavaRing, showcased at JavaOne '98, is an example of support for the JavaCard.
  • Java2 Platform, MicroEdition (J2ME): It was introduced at JavaOne '99 as a framework for Java for a variety of devices. A transition from PersonalJava and EmbeddedJava to the J2ME framework is planned. In J2ME there are two types of configurations: one for connected devices and the other for limited connected devices. A configuration consists of a VM and core libraries. One configuration is known as the CVM where the C stands for compact, connected, and consumer. This configuration is being developed as part of the Java Community Process, Java Specification Request - 0036. The other configuration is the K Virtual Machine (KVM), described below. Built on top of the configurations are profiles (classes) that are customized for the specific targeted market segment. The Personal Profile will be the next generation PersonalJava with profiles for TV, screen phone, auto, and handheld.
  • K Virtual Machine (KVM): The KVM is the VM for the limited connected device configurations. It'll have profiles built to support wireless and handheld devices, and is available for the Palm. The KVM is targeted for a very small footprint and consumes little power. Additional development work on the KVM is in conjunction with the Java Community Process, Java Specification Request - 0030.

Many Proposed Solutions
There are a variety of solutions available to provide Java support in the embedded space. These solutions can be categorized by their approach to solving the challenges of running Java in an embedded environment or by the Java platform that's supported. In this article, tools from three different Java platforms are investigated.

  • IBM VisualAge MicroEdition on QNX Neutrino: A subset of PersonalJava
  • Microware PersonalJava on OS-9: A PersonalJava implementation
  • Sun KVM on PalmOS: Part of the Java 2 MicroEdition platform

VisualAge MicroEdition
VisualAge MicroEdition includes a virtual machine and a fully integrated development environment to edit, compile, link, profile, and control the versions of your Java code. In addition to the embedded Java support, there's also a set of classes for serial I/O, voice, and user interfaces.

Virtual Machine Description
The VM, called J9, is based on the Sun JDK1.2 class libraries. You can use the J9 VM from the command line or make use of the integrated development environment that's included with VisualAge MicroEdition.

Tools
The integrated development environment has some similarities to IBM's VisualAge Java product. When using VisualAge MicroEdition, you can work in a stand-alone environment or in a team where each developer is connected to a server. The server contains a repository that allows developers to share code. Within the IDE you can group your code into projects, edit, compile, and debug on the host, or debug remotely.

The Remote Debugger provides the capability to debug embedded programs on the target virtual machine, either directly on the embedded target or simulated in the J9 Windows runtime environment. A productive feature is the ability to change the source code while debugging, then continue with the debugging session using the changes without restarting the debugger or program.

The Profiler allows you to profile your code that's executing on the target machine. In addition to the standard performance tuning, it can help solve threading problems and understand where garbage collection is occurring.

The Version Control doesn't follow the traditional check-in/checkout model in which code is locked while an engineer is working on it. In this product the engineers work in parallel. In the event that multiple engineers are working on the same class, the merge function enables them to merge the changes into the final version.

MicroView is the GUI framework that's about one-third the size of the AWT. It follows the model-view-controller architecture. The controller handles input events for the views and the model holds the state information. The model is observed by listeners who are notified of changes. As you'd expect, views can be nested.

The serial I/O classes are useful to communicate to other devices over RS232 serial ports. Use the SerialPortConfiguration class to set the configuration settings. There's a SerialPort class that's used with SerialInputStream and SerialOutputStream classes to read and write data.

The Voice classes consist of the VoiceDispatcher and the Listener interfaces that receive a voice event and handle it.

Building for the Target
When building your code, you can compile it into a .class file or .jar file. The J9 virtual machine allows you to store preprocessed classes in ROM. These classes are created by running the SmartLinker. To set the appropriate link options there's a GUI front-end to the SmartLinker tool. The output is a .jxe file and can be run on the target or Windows for simulation purposes. The J9 virtual machine still keeps a small portion of information in RAM for each class. Of the total runtime structures for a typical class, however, 75% can be stored in ROM with only 25% in RAM.

VisualAge class libraries are a subset of JDK1.2 for embedded applications. You have a choice of linking with one of three class libraries. The smallest library is jclXtra and is only 100K. It's a subset of the jclCore library and has no debug support. The jclCore library, which is about 300K, is used most often. The jclCore library has no security but does contain basic file I/O and networking support. The largest library is jclMax, which is about 2Mg. It includes most of the Java 2 APIs from the following packages: java.io, java.lang, java.math, java.net, java.text and java.util. It also includes Java 2 security.

Microware Personal Java for OS-9
PersonalJava for OS-9 includes the OS-9 operating system, the virtual machine, and a set of tools to help build the target.

Virtual Machine Description
PersonalJava for OS-9 is a Sun-licensed PersonalJava port that's been tuned for OS-9. The JDK version 1.1.6 is installed on the host for development. This PersonalJava implementation supports many optional features such as scrollbars and overlapping windows.

OS-9 has a modular architecture that enables dynamic loading of any OS-9 system or application module. This feature can be exercised to dynamically load Java programs.

In the architecture of OS-9 each process is protected from the other, so a bug in one process won't affect another. The Java thread scheduler and the OS-9 process scheduler are also independent. Therefore Java threads can be run independently from other processes executing real-time activities. PersonalJava for OS-9 contains a nonintrusive garbage collector that doesn't stop the entire system when it runs.

Tools
Along with the JVM are Java tools such as JavaCodeCompact, which allows a set of Java classes to be preloaded into RAM or converted into a ROMable shared library module.

A configuration wizard called mwWizard is available to help build system boot images. This is a GUI tool that allows you to select what should be included in the boot image and then creates the boot file. It can be very useful if you're iteratively rebuilding your boot image to make it smaller.

When writing Java programs, a developer is free to use any integrated development environment. Hawk, which is shipped with the product, is a C/C++ integrated development environment. It contains a syntax-sensitive editor, debugger, compiler, linker, profiler, project manager, and version control. From a Java perspective, Hawk is useful to dynamically load Java modules. The product contains two types of debuggers: Microware Hawk and ROMBug. The Microware Hawk debugger is a typical C source code debugger that also allows you to see the native assembler code. The ROMBug tool is used to debug system and user state programs. It runs in a supervisor state and takes control of the CPU when invoked.

The mwSoftStax component provides a C application programming interface to a variety of networking protocols. The LAN communications package contains the set of protocols.

Providing graphics capabilities are a graphics library with C APIs called mwMAUI (multimedia application user interface), a window manager called WinMgr, and a set of application framework classes.

An extensive set of online reference manuals in PDF format and Adobe Acrobat Reader with Search V3.0 are included.

Building for the Target
There are three ways to run PersonalJava in OS-9 when there's no hard drive on your target board. The first method prelinks the Java class files into an OS-9 module, which is then loaded into ROM or RAM. The second method involves including the classes.zip and the Java application code into a ModMan archive. The ModMan archive utility (mar) creates a single loadable file from a series of modules. The third method uses remote class loading.

The first method can be used to load the classes directly into ROM. To create the ROMized classes, the JavaCodeCompact tool is used. JavaCodeCompact creates the internal virtual machine data structures that represent the class in ROM. Since the JavaCodeCompact tool preloads the classes, information about the classes can be shared between them, resulting in a further savings in ROM. All symbolic references are resolved and the bytecode instructions referring to these symbols are rewritten to not perform symbolic lookups. PersonalJava for OS-9 ships JavaCodeCompact in the file called jcc.zip and a set of makefiles that invoke the JavaCodeCompact tool.

PersonalJava for OS-9 offers two versions of the Window Manager so if an application uses only basic window management functions, it can use a smaller library. One difference between the window managers is support for overlapping windows.

Sun KVM
The KVM is a new Java implementation developed at Sun Microsystems Laboratories, originally called the Spotless System. The KVM is targeted at providing a minimal set of functions for running on limited connected devices.

Virtual Machine Description
The KVM is currently available for download to run only on the Palm. It was also demonstrated on a Motorola pager at JavaOne '99. The system requirements for the KVM are 128K for the VM, libraries, and heap on the PalmOS.

The major design criteria was small size and portability. To achieve this goal, the garbage collector was redesigned to work with smaller heap sizes and the class library was reduced. AWT is replaced with a smaller GUI library. For example, instead of the Applet class, there's a Spotlet class. In some cases an entire class from the JDK is missing. Classes were removed if they were rarely used or created many short term objects. For example, there's no Float class. In other cases, though the class exists, some of the methods aren't supported. For example, some of the Math and String methods were removed. There's also a reduction in the number of distinct exceptions.

Tools
The only tool support is an emulator (POSE) that can be installed on the host machine. Once the emulator is installed, you can drop applications on it and see how they run before deploying them on a Palm.

Table 1

Building for the Target
To develop a Palm application in Java, there are four steps:

  1. Set your path and classpath.
    set path=c:\jdk1.2.1\bin;
    set classpath=

  2. Compile your Java code using the KVM class library. It's recommended that your classpath point to the KVM classes.zip file instead of the desktop JDK as coded below using the bootclasspath option on the javac command. With this approach, if your code attempts to reference a class that's not in the KVM, a compiler error is generated instead of a runtime exception. The following statement assumes that the KVM was installed in the c:\kvm directory.
    javac -O -bootclasspath c:\kvm\KVMDR4.1_bin\api\classes.zip HelloWorld.java

  3. Make a Palm PRC file that contains your code. The MakePalmApp utility is located in the classes.zip file that's located in the tools directory. It takes a .class file(s) and converts it into a single .prc file that can be transferred to the Palm.
    java -classpath c:\kvm|kvmDR4.1_bin\tools\classes.zip
    palm.database.MakePalmApp HelloWorld

  4. Transfer the PRC and KVM (if not already done) to the Palm. Start the HotSyncManager. Using the Palm Install tool add the application PRC file created in the previous step to the list of files to HotSync. If the KVM hasn't been transferred yet, add the KVM.prc and KVMClassDB.pdb to the list. Perform the HotSync.

Another way to load Java code on the Palm is to merge the application .class files into the Palm database for the JDK classes using the MakePalmDB utility. This is convenient if you have classes that will be shared across applications. The first step is to download the kjxfer utility and install it on the Palm. Then use the MakePalmDB as follows assuming that the HelloWorld.class file is in the current directory:

java -classpath c:\kvm\kvmDR4.1_bin\tools\classes.zip palm.database.MakePalmDB HelloWorld

This creates a .pdb file that when downloaded to the Palm, adds your classes to the KVM. You then run your classes using the class manager. To do this select the KVM icon. From the list of classes in the KVM, select the one you want to run and press the Run button. The class needs to have a main function to run. You can see the results of stdout and stderr on the Palm. There's no way to delete a class once you have added it to the .pdb file.

As mentioned earlier, the KVM supports a more limited class library than PersonalJava. The GUI framework contains the basic classes such as Bitmap, Button, CheckBox, Dialog, RadioButton, Slider, and TextField. These are used within a Spotlet (instead of an Applet). The Spotlet class is used to interact with the user and it provides callbacks for pen and key events. It also provides methods for beaming data. There's no PrintStream class. To do simple output, use the printString method in the Graphics class.

Conclusion
As we surveyed the marketplace, we found that this is a very exciting and dynamic time to be doing Java development as the Java embedded market is just starting to emerge. Many RTOS companies are providing a Java Virtual Machine for their operating system, such as Microware PersonalJava for OS-9. The application development tools that are geared for Java development, not just C/C++, are typically following the release of the virtual machine and are starting to appear in the market. IBM VisualAge MicroEdition is an example of a development environment for the embedded programmer. As shown in the Tool Summary table (see Table 1), the tools on the market support different levels of the Java platform. Most tools allow the engineer to package the code to be loaded into RAM or ROM on the target.

The Sun Java Community Process and the recent J2ME announcements point to future changes in the embedded Java community. The changes to various JVM configurations with a set of profiles for their particular targeted use will have an effect on the solutions vendors provide. In fact, additional development for the KVM is available via the specification for the Connected Limited Device Configuration (JSR #30), which is accessible for public review on the JavaSoft Web site. There's also ongoing work to add real-time extensions into the Java Language Specification that will standardize solutions to some of the challenges faced in the embedded environment.

References

  1. Barr, M. (2000). "Developing Embedded Software in Java." Embedded Systems Conference.
  2. Brenner, A. (1999). "K Virtual Machine Overview." Sun Microsystems, Inc.
  3. Dibble, P. (1997). "Synergy: OS-9 and Java." Microware Systems Corporation. www.microware.com.
  4. Grehan, R., Moote R., and Cyliax I. (1998). Real-Time Programming: A Guide to 32-Bit Embedded Development. Addison-Wesley.
  5. Real-Time Java: www.rtj.org.
  6. Reveaux, T. (1999)."Embedded Platforms for the Free Flow of Information." Strategic Platforms. The Journal of Advanced Software Engineering, Spring.
  7. Sun Microsystems. (2000). "EmbeddedJava Technical Overview." www.javasoft.com/products/embeddedjava/overview.html.
  8. Taivalsaari A., Bush B., and Simon D. (1999). "The Spotless System: Implementing a Java System for the Palm Connected Organizer." Sun Microsystems, Inc.
  9. Vokach-Brodsky B. (1999). "Java2 Platform, MicroEdition CDC Overview." Sun Microsystems, Inc.
  10. Waters J. K. (1999). "Java Driving a Revolution in Embedded Systems." Strategic Platforms. The Journal of Advanced Software Engineering, Spring.

Author Bio
Sherry Shavor is an advisory software engineer with IBM in Research Triangle Park, North Carolina. She received a BS in computer science from the State University of New York at Stony Brook.[email protected]

Peter Haggar is a senior software engineer with IBM in Research Triangle Park, North Carolina and the author of the book, Practical Java, published by Addison-Wesley. He received a BS in computer science from Clarkson University. [email protected]

Greg Bollella, a senior architect at the IBM Corporation, is lead engineer of The Real-Time for Java Expert Group. He holds a PhD in computer science from the University of North Carolina at Chapel Hill. [email protected]

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.