/ Markus Amersdorfer:home / university / about:me /
\ Say NO to Software-Patents! \


Some Hints on the Real-Time Specifications for Java (RTSJ)

Table of Contents

Introduction

RTSJ is one of the basic elements I used for my diploma thesis.

The official homepage for RTSJ is rtj.org. Among other things, you will find a link to the specification there.

The reference implementation can be downloaded from timesys.com.
From it's README file: [...] The target platform for this RTSJ-compliant JVM is TimeSys Linux However, it will also run on RedHat Linux with some minor loss of functionality, e.g. Priority Inheritance. [...]

Here's the rtj-discuss mailing-list archive.
AFAIK you can subscribe by sending a mail to "listproc [at] email . nist . gov" with no subject and "subscribe <list> <your name>" in the body.

Peter C. Dibble (one of the creators of RTSJ) wrote the book "Real-Time Java Platform Programming" (ISBN 0130282618).
He put the website www.rtsj.org online where - among other things - the (error-corrected) sources from this book can be downloaded.

TimeSys-Powered Mars Exploration Rover Demonstrated at JavaOne(SM) Conference.
Slightly related: TimeSys Offers Free 2.6-based Linux Board Support Packages for PowerPC and x86 Architectures.
Here's a German article on Realtime-Java partially used for a military jet: Unbemannter Militärjet fliegt mit Echtzeit-Java".

According to this German article on heise.de, Sun announced the "Java Real-Time System (Java RTS)" on the JavaOne developer conference. Java RTS seems to be based on J2SE.
Here's the link to the official Sun project on real-time Java, Sun Java Real-Time System.

Here's a series of real-time Java related articles on IBM's developerWorks: Real-time Java, Part 1: Using the Java language for real-time systems, Real-time Java, Part 2: Comparing compilation techniques, Real-time Java, Part 3: Threading and synchronization, Real-time Java, Part 4: Real-time garbage collection.

The RTSJ Reference Implementation

Get it up and running ...

  1. Unpack the reference implementation to /opt/rtsj/.
  2. Install "libpthreadrt" (which is part of the reference implementation):
      cp -u libpthreadrt.so.2.0 /usr/local/lib
      chmod -x /usr/local/lib/libpthreadrt.so.2.0
      cd /usr/lib
      ln -s ../local/lib/libpthreadrt.so.2.0 libpthreadrt.so
     
  3. For convenience, I added the following aliases to ~/.bashrc:
      alias javacrt='javac -classpath /opt/rtsj/lib/foundation.jar'
      alias javart='/opt/rtsj/bin/tjvm -Djava.class.path=. -Xbootclasspath=/opt/rtsj/lib/foundation.jar'
     
  4. To create the API documentation using javadoc:
      jar xt /opt/rtsj/realtime.jar           [creates the directory javax/]
        [If this doesn't work, run "unzip realtime.jar".]
      javadoc -d rtsj_api-doc javax.realtime  [creates the API doc in rtsj_api-doc]
     

New version of the RI

As of March 2004, there is a new version of the reference implementation. While this is good news, it seems to have some problems with periodic threads when being executed on a default Linux kernel or TimeSys' GPL-version of Linux. AFAIK, fixes are on their way -- or might even already be available at the time you're reading this.
Furthermore, I couldn't find the necessary resources in the new package anymore in order to create the Javadoc-documentation locally -- but I may simply overlook it ...

HelloRTWorld.java

Here is our beloved "Hello World" using Realtime-Threads (with Sun's J2SDK-1.4.2 on Debian Sarge, Linux 2.4.21):

import javax.realtime.*;
public class HelloRTWorld {
  public static void main(String[] args) {
    RealtimeThread rt = new RealtimeThread() {
      public void run() {
        System.out.println("Hello Real-Time World!");
      }
    };
    rt.start();
  }
}

In order to run it (using our aliases set above):

Compile and Run:
  javacrt HelloRTWorld.java
  javart HelloRTWorld

Output:
  security properties not found. using defaults.
  Hello Real-Time World!

Memory Sizes

Immortal Memory

If your programs use immortal memory and abort with error messages such as "mem_registry.c::InvokeNewInstance() - Went out of memory", you have too little immortal memory.
Per default, its size is set to 2 MB. This can be changed by running something like export IMMORTAL_SIZE=10000000. Using this environment variable, you can set the immortal memory's size to the specified amount of bytes.

But be aware of memory leaks! While such errors won't occur in normal Java, they perfectly can with RTSJ: If you allocate something from immortal memory, it will consume this memory as long as your program runs, even if there aren't any references to it anymore.
And be aware of print statements! Even running System.out.println(); from within a loop will allocate new memory every time it is invoked. If you're using NoHeapRealtimeThreads, the only solution I know to prevent print statements being a memory leak is to enter scoped memory every time you want to print something and have println(/*...*/) be executed there.
(Nevertheless, to prevent mem-leaks there too, one must not create a runnable object over and over again but instead must create one only once and re-use this object when entering the scoped memory. While it is possible to set/change primitives stored in this object, AFAICT it is not possible to change the message of the print statement itself in any way, as this includes creating a String object everytime...)

Heap Memory

According to TimeSys' README, the default size of heap memory is 4 MB. Use tjvm's command line parameter -Xms20M or similar to change the heap size.

My general Java page.

Valid HTML 4.01! Valid CSS! Created with Vim [Blue Ribbon Campaign icon]
© Markus Amersdorfer (markus<dott>amersdorfer<att>subnet<dott>at)
last modified: 2010-02-23 15:52:05
10257 hits