Real Java for Real Time - Gain and Pain Anders Nilsson Dept. of Computer Science Lund University Box 118 S-221 00 SWEDEN andersn@cs.lth.se Torbjörn Ekman Dept. of Computer Science Lund University Box 118 S-221 00 SWEDEN torbjorn@cs.lth.se Klas Nilsson Dept. of Computer Science Lund University Box 118 S-221 00 SWEDEN klas@cs.lth.se ABSTRACT The Java programming language, being a portable and safe object-oriented language, has gained much interest among embedded and real-time systems developers. However, stan- dard Java implementations exhibit problems with perfor- mance, memory footprint, and predictability. The question is then, are these limitations inherent in the technology? Reviewing run-time aspects and the possibility to com- pile Java to native code, reveals some real limitations as well as common misconceptions. Investigation of the real limitations shows that for implementing real-time Java on small embedded platforms, native compilation via C is an appropriate solution for many platforms and applications. A revised technique for Java-compatible memory manage- ment is proposed to reduce latencies, and linkage of exter- nally generated (C) code with natively compiled Java is con- sidered in a prototype that has been implemented. Based on application demands and experimental verification, we find that real-time Java can, and should, retain the standard simple Java memory model to the programmer. Categories and Subject Descriptors J.7 [Computer Applications]: Computers in Other Systems—Real-Time ; D.3.3 [Programming Languages]: Language Constructs and Features General Terms Languages, Performance, Experimentation Keywords real-time Java, embedded systems, rtj Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. CASES 2002, October 8–11, 2002, Grenoble, France. Copyright 2002 ACM 1-58113-575-0/02/0010 ...$5.00. 1. INTRODUCTION Properties such as portability and safety 1 motivate a great interest in using Java for implementation of embedded soft- ware. However, Java has not yet been widely used for pro- gramming embedded systems due to a number of reasons. Some of these we suspect are more or less misconceptions and easily solvable, whereas others may be real problems. When talking about Java, one could mean the language, the virtual machine running byte-codes, or the complete set of standard classes that comprise the Java platform. For small embedded systems there are reasons to believe that the Java language with (a subset of) the standard classes com- prises a sufficient basis for developing Java-based systems. In the sequel, we therefore make use of the Java language, possibly with enhanced but Java-compatible semantics. Real-Time Java Objectives Considering application and development needs, there exist a number of criteria that all need to be fulfilled for Java to be an appropriate programming language for real-time systems. Such systems range from small embedded devices (such as micro-controllers), and up to large scale systems including both enterprise computing and real-time machine control (such as automation systems). In order for Java to be a widely applicable language in the embedded world, all of the following objectives need to be considered: Memory footprint For most embedded devices, especially mass-produced devices, memory is an expensive re- source. A tradeoff has to be made between cost of physical memory and cost savings from application de- velopment in higher level languages. Performance CPU performance, and in some cases power consumption, is also an limited resource. The cheapest CPU that will do the job generates the most profit for the manufacturer. The same tradeoff as for memory footprint has to be made. Determinism Many embedded devices have real-time con- straints, and for some applications, such as controllers, there might be hard real-time constraints. Computing in Java needs to be as predictive as current industrial practice, that is, as predictive as when programming in C/C++. 1 By safe language we not only mean that it has strict typing, but also that all possible executions are expressed by the source code. This in contrast with for example C and C++, or C# when the keyword unsafe is used.