Real-Time Java HelloWorld

Are you starting with Real-time Java and don't know where to look first? Here is a step-by-step tutorial showing you how to install and run simple RT Java programs.

1. Install Real-time Java VM
There is a bunch of RT VMs that you can donwload and use but perhaps the one that is the easiest to install and to play with is Oracle's Java RTS. The current version is Java RTS 2.2. After filling the download form, you should be able to download it to your desktop. The name of the donwloaded file will be something like :  java_rts-2_2-fcs-bin-b19-linux-i586-eval_academic.zip

1.0 Requirements
  • RT Linux - if you want to really run with real-time priorities. However, for starting and learning how to work with RT VMs, a regular linux should do - try eg. Ubuntu or Fedora OS.
1.1  Install the RTJ VM
untar downloaded distributable into /opt/jrts2.2 directory. Let's call it RTJAVA_HOME.
$ export RTJAVA_HOME=/opt/jrts2.2/

For more details, see SUN Java RTS Technical Documentation. Java RTS is distributed under restricted academic license that expires after 365 days but don't worry, you can just dowload a new distribution and re-install it.

1.2. Verify the Installation
$ $RTJAVA_HOME/bin/java -version
You should see:
java version "1.5.0_20"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20_Java-RTS-2.2_fcs-b19_RTSJ-1.0.2)
Java Real-Time System HotSpot(TM) 64-Bit Client VM (build 1.5.0_20-b19, mixed mode)

In case you are not running in a real-time environment or your linux does not have the rt-kernel extensions, you will also see the following warning:
Java Real-Time System HotSpot(TM) 64-Bit Client VM warning: Unable to lock pages into memory: insufficient privileges
Java Real-Time System HotSpot(TM) 64-Bit Client VM warning: Cannot use the real-time scheduling class.
You can safely ignore this one for testing RTSJ.

1.3. A missing libcap.so problem
However, a problem can occur when running the "./bin/java" on some systems:
$RTJAVA_HOME/bin/java -version
dl failure on line 824Error: failed /opt/sunrts-2.2/jre/lib/i386/server/libjvm.so,
because libcap.so.1: cannot open shared object file: No such file or directory
This happened to me both on Ubuntu and Fedora OS. There is a detailed description of this problem here (as it appears, I was the first person to identify this issue).

Solution to the missing libcap.so.1 lib is to locate a libcap.so.2 and rename it as libcap.so.1
$ locate libcap.so.2
$ sudo cp /lib/libcap.so.2 /lib/libcap.so.1 

2. Runnig a Real-time HelloWorld program
Now we can finally run some real-time Java code. A classical real-time Java hello world example is below:
import javax.realtime.RealtimeThread;

public class HelloRealtimeWorld extends RealtimeThread {

    String message;

    public void run(){
      message = "Hello Realtime World";
    public static void main(String args[]){
      HelloRealtimeWorld thread = new HelloRealtimeWorld();
      } catch(InterruptedException ie){
        System.err.println("got interrupted");

To compile the Real-Time HelloWorld class:
$ $RTJAVA_HOME/bin/javac -classpath $RTJAVA_HOME/jre/lib/rt2.jar 
-d build/  HelloRealtimeWorld.java 

And, to run:
$ $RTJAVA_HOME/bin/java -cp build/ HelloRealtimeWorld
Hello Realtime World! 

And we are done!

Further resources on RT Java:
Further blog-post on the same topic:
  • http://viswanathj.wordpress.com/2011/04/09/installing-java-rts-on-ubuntu-2/


October Reading List

The list of papers, books, and other articles that caught my attention during the last month.



oSCJ News

Recently, there has been a lot of activity around the oSCJ project, here is a short summary.

We currently develop several new features in parallel:
  • SCJ benchmarks - we have added a set of new SCJ programs to compare performance and memory usage of the SCJ memory management againts real-time garbage collection algorithms
  • SCJ Annotations - soon, our annotation checker will be extended to cover a full-scale of different allocation scenarios to guarantee memory safety of the applications running on oSCJ. Furthermore, this feature will allow us to disable the runtime scope checks in the underlying VM, achieving 5-10% speed-up!
  • SCJ library extensions - as JSR-302 is nearing to its completion, we extend the set of supported features.
Also, the installation and running of oSCJ is now super-easy! First, you can get an academic version of FijiVM - our major platform for running oSCJ. Just contact us so we can send you the Fiji VM distribution!

Installation procedure:
$ wget fivm.tar.gz
$ untar fivm.tar.gz 
cd fivm 
$ hg clone https://scj-jsr302.googlecode.com/hg/ scj

and then compile FijiVM, which will also compile the oSCJ as well:
$ autoreconf -i 
$ ./configure
$ make 

To update oSCJ:
$ cd fivm/scj
$ hg pull
$ hg update 

For your better orientation in the distribution directory, here is a structure of the distribution directory
fivm/                 fivm/scj
  lib/                this is where "scj.jar" is 
    oSCJ/             oSCJ root dir
      doc/              Documenation 
      examples/         oSCJ examples and benchmarks dir
        minicdx/          our CDx benchmark implemented in SCJ
        hello/            SCJ helloworld example
      scj/              oSCJ library implementation
        ri/               SCJ library source codes
      tools/            our SCJ tools
        checker/          Static Checker for SCJ
        tck/              TCK for SCJ

See our oSCJ Code base for the most recent updates.


Azul@Purdue Project

Recently, our team acquired a revolutionary Azul appliance platform. I had a great opportunity to play with this exciting hardware a little when installing and running the first helloworld programs both in Java and C. This was the first time ever that this machine was used in an academic institution. Here is some more info:

Azul appliance is built around the Vega 3 chip and is a unique virtualization platform that features 54 cores pre processor giving users the power to run up to 800 Java threads in parallel.  Futhermore, the appliance offers ~700GB of memory while running a concurrent GC that achieves garbage collection without any pauses in the host application.

Find more at our webpage: http://sss.cs.purdue.edu/projects/azul/


Garbage Collection and Real-time Garbage Collection Introduction

Here are some documents and slides you may find useful when studying Garbage Collection and Real-time Garbage Collection:

First, look at SUN's
Memory Management in the Java HotSpotTM Virtual Machine. Its from 2006 but contains a very nice introduction to GC, even parallel and small-pause collection algorithms are mentioned.

An another introduction slides are:
GC Introduction Presentation

When looking at performance of GCs, look at a nice study
Myths & Realities The Performance Impact of Garbage Collection from Steve Blackburn, Perry Cheng and Kathryn McKinley.

For interesting implementation details, I recommend:


Static Checker for SCJ: Paper and its Presentation

Presentation of our Static SCJ Checker is now available online:

The paper itself can be downloaded from JTRES2010 webpage.


Developing Safety-Critical Java Applications with oSCJ

Read our oSCJ paper:
Developing Safety-Critical Java Applications with oSCJ

We present oSCJ, an implementation of the draft of Safety Critical Java (SCJ) specification. SCJ is designed to make Java amenable to writing mission- and safety-critical software. It does this by defining a subset of the Real-time Specification for Java that trades expressiveness for verifiability. 

This paper gives a high-level description of our implementation of the first compliance level of the SCJ speci- fication, a library called oSCJ, and reports on performance evaluation on the Ovm real-time Java virtual machine. We compare SCJ to C on both a real-time operating system on the RTEMS/LEON3 platform and Linux on a x86. Our results suggest that a high-degree of predictability and competitive performance can indeed be achieved.

The paper will be presented at JTRES'10 in Prague.

Download the paper in [PDF].


JTRES'10: Advance Program

The advance program of the JTRES conference, held next week in Prague, is already availabe at JTRES Webpage. Here are some highlights. 

The keynotes:
  • Greg Bollella (ORACLE) : Some Recent Developments Around The RTSJ and Oracle.
  • Marc Pantel (University of Toulouse) : Certification and qualification concerns in the development of safety critical systems.
  • Rainer Trummer (University of Salzburg) : The JAviator Project
  • Marek Prochazka (European Space Agency) : Java in Space?
Also, do not miss the presentations of our two papers, I will be presenting:
  • Developing Safety-Critical Java Applications with oSCJ/L0 by Ales Plsek, Lei Zhao, Veysel H. Sahin, Daniel Tang, Tomas Kalibera, and Jan Vitek
  • Static Checking of Safety-Critical Java Annotations by Daniel Tang, Ales Plsek, and Jan Vitek
See you at JTRES.


Certification challenges for Real-Time Java

A very interesting article about recent development in the area of certification for Real-time Java: 
Its exciting to see that Safety-Critical Java (JSR-302) is in the middle of these efforts!

See our implementation of safety-critical Java here: oSCJ


RTEMS HelloWorld Tutorial

Let's go embedded.

RTEMS is a real-time executive which provides a high performance environment for embedded applications on a range processors and embedded hardware. In this tutorial you will learn howto:
  • install RTEMS and build RTEMS tools
  • run RTESM applications on TSIM simulator 
We leave the topic of compiling RTEMS applications for a separe howto article.  Check the blog for updates.
    Note: This tutorial is focused on the following platforms : SPARC LEON3 and ERC32/SIS.

    1) Prerequisities
    First, you will need a linux distribution supporting RTEMS. Try Fedora 11 or higher or SUSE 11 or higher.
    This tutorial is using the RTEMS version 4.9. RTEMS 4.10 is not officially distributed, but the instructions here in general should be valid once this new distribution is released.
    2) RTEMS OS installation
    As part of the installation, we need to install the RTEMS prebuilt tools first.
    Install (SUSE):
    $ rpm -Uvh <package name>.rpm

    Install (Fedora):
    $ yum install "installation_package_name"

    • All the packages will be installed in /opt/rtems-4.9/ by default.
    • During installation you can get some warnings about keys. Don't worry about them.
    • During installation you can get some dependency errors. Find the required packages from suse repositories and install them.
    3. Build RTEMS  
    In this step we will build RTEMS for two different configurations - LEON3 and ERC32/SIS.

    3.1 Build RTEMS with LEON3 support 
    1. Become root
    2. Browse http://www.rtems.org/ftp/pub/rtems/4.9.3/
    3. Download rtems-4.9.3.tar.bz2. Extract archive in the /opt/ directory. This will create /opt/rtems-4.9.3/
    4. Execute the following:
    $ cd /opt/rtems-4.9/
    $ export PATH=/opt/rtems-4.9/bin:$PATH
    $ ./bootstrap
    $ mkdir leon3
    $ cd leon3
    $ ../../rtems-4.9.3/configure --target=sparc-rtems4.9 
             --enable-rtemsbsp=leon3 --enable-posix
    $ make
    $ make install        
    3.2 Build RTEMS with ERC32/SIS support (optional)
    The same approach as above, only the configuration during the building is different:
    $ cd /opt/rtems-4.9/
    $ export PATH=/opt/rtems-4.9/bin:$PATH
    $ ./bootstrap
    $ mkdir bsis
    $ cd bsis
    $ ../../rtems-4.9.3/configure --target=sparc-rtems4.9 
    --enable-rtemsbsp=sis --enable-posix
    $ make
    $ make install    
    3.3 TSIM simulator
    Go to TSIM distribution at Gaisler Inc.
     - install the TSIM simulator, eg. in /opt/tsim 
    - the simulator will allow you to execute RTEMS binnaries on your x86

    4. RTEMS Helloworld with TSIM:
    First, you need to compile RTEMS C application. We will however not address this step here, we will dedicate a separate tutorial for this step. But, in order to verify that your installation is correct, RTEMS distribution contains many pre-compiled examples that you can use to run out of the box.
    You can also download it here: RTEMS HelloWorld binnary (compiled for SPARC LEON3).

    And then load the binnary file into the TSIM simulator and run it:
    $ /opt/tsim/linux/tsim-eval
    tsim> load hello
    tsim> go
    resuming at 0x40000000
    Hello World!
    Program exited normally.
    tsim> quit

    5. RTEMS installation - Building a toolchain and target C library  (optional)
    First, fetch gcc-core and gcc-c++ 4.3.2, binutils 2.19, newlib 1.16.0, and related patches from http://www.rtems.org/ftp/pub/rtems/SOURCES/4.9/. You need only the newest patch (the filenames include the date) for each component. Extract and patch each component from the same directory (we'll call it $TOP), so that you have $TOP/gcc-4.3.2/, $TOP/binutils-2.19/, and $TOP/newlib-1.16.0/.

    Link $TOP/newlib-1.16.0/newlib to $TOP/gcc-4.3.2/newlib:
    ln -s $TOP/newlib-1.16.0/newlib $TOP/gcc-4.3.2
    Create a build directory for each of binutils and gcc, indicating the architecture; something like binutils-2.19-$ARCH, where $ARCH is i386, sparc, etc.

    Pick an install directory; we will call it $PREFIX -- I use /opt/rtems-4.9.
    Configure and build binutils:
    cd $TOP/binutils-2.19-$ARCH
    ../binutils-2.19/configure --target=$ARCH-rtems4.9 
    --prefix=$PREFIX --disable-werror
    make install

    Configure and build gcc; this may require some platform-specific arguments:
    cd $TOP/gcc-4

    6. Other Tips (optional)

    RTEMS on x86:
    If you wish to boot RTEMS using grub (as for qemu), provide --enable-rtems-grub. This forces the binary to load up above the 1MB mark.

    FPU support:
    In case your RTEMS configuration is not FPU-friendly, when building your tools, provide --with-float=soft to the gcc configuration.

    1) Another RTEMS installation tutorial
    2) RTEMS: http://www.rtems.com/

    Acknowledgment: Thanks to Petr Maj and Ethan Blanton for help with this tutorial! 


    Static Checker for SCJ released!

    We have released a new version of our Static Checker for SCJ. The checker is based on the Checker framework that will be shipped with Java 7 and is able to statically verify various SCJ properties.

     Here you can see an example SCJ code and possible errors that the checker will identify:

                                                                      (click to enlarge)

    We now support all the SCJ annotations:
    • @SCJAllowed
    • @SCJRestricted
    • @DefineScope
    • @Scope
    • @RunsIn
    A typical example of a checker output can be seen here:
                          (click to enlarge)

    You can find more information about the Checker at oSCJ Home Page.

    The checker is open-source and can be downloaded from here.


    Comparator: An AST Parser for SCJ

    Keeping specification and its corresponding implementation in sync is often a huge hasle.

    In our case, the situation is even more complex since we have several different implementations of the same Specification. Moreover, the Spec. itself is being constantly updated.

    Therefore, we introduce Comparator -- our new tool that is able to automatically determine all the differences between a specification class and its corresponding implementation.

    Comparator creates AST trees both from the spec and from the implementation and compares them, simple yet powerful.

    You can see a typical report log produced by the Comparator :

    Comparator will be shipped with the updated version of SCJ TCK soon, stay tuned.

    JTRES Workshop

    As every year, JTRES'10 : International Workshop on Java Technologies for Real-time and Embedded Systems is coming.

    This year in Prague, Czech Republic, August 19-21.
    Research Paper Deadline : June 7th (firm).

    For more info, see:


    CDx Benchmark : Update

    We have released a new version of the CDx benchmark: Version 1.2!

    Version 1.2 unifies the CDx implementation across all the platforms and implementations languages.

    We now provide the same CDx algorithm implemented in:
    • CDj-Java - CDx in regular Java,
    • CDj-RTSJ - CDx in RTSJ,
    • CDj-SCJ - CDx in SCJ,
    • CDj-Fiji - a specific-FijiVM-implementation,
    • CDc - language C implementation. 

    We specifically paid attention to implementation of each version so that all the provided CDx applications and computationally identical, the only difference is the programming language used for their implementation.

    Download the CDx benchmark.


    oSCJ on GoogleCode!

    We have set up a GoogleCode project for oSCJ. 

    See the project here: http://code.google.com/p/scj-jsr302/
    This move allows you to closely follow updates on oSCJ. We now introduce new features almost every day!

    You can now easily check-out oSCJ from our Mercurial repository:
    hg clone https://scj-jsr302.googlecode.com/hg/ scj-jsr302


    oSCJ Released!

    We are happy to announce
    oSCJ : open Safety-Critical Java implementation 
    has been released.

    The oSCJ distribution contains:
    • Library
      • SCJ Level 0 library implementation
      • an RTSJ-compatible implementation for evaluating SCJ on top of RTSJ VMs
    • SCJ-compliant VM
      • our VM is based on OVM
      • we provide support also for FijiVM
    • Tools 
      • Checker - a static checker for proving memory safety of SCJ programs and other properties
      • TCK - Technology Compatibility Kit for SCJ
    • Benchmark Suite 
      • HelloWorld example for experimenting with SCJ
      • miniCDj - SCJ implementation of our CDx benchmark
    Download the distribution from oSCJ webpage.
      Enjoy and we are looking forward to your feedback!


      Collision Detector Benchmark : A New Version Released

      We have just released a new version of CDx : Open-source Realtime Collision Detector benchmark.
      Download our CDx benchmark version 1.1 here.

      This new version is largely simplified, specially the simulation of the input Frames is changed, now each frame is computed on-the-fly. The version 1.1 of the benchmark is used in two research papers recently published at EuroSys'10 and PLDI'10, see our list of publications.

      The CDx benchmark is now distributed under the New BSD License.


      ROOTs'10 Workshop Announcement

      ROOTs 2010 stands for 1st International Workshop on Real-time Object-Oriented Technologies. Workshop will be collocated with ECOOP 2010 in Slovenia in June. 

      Briefly, the workshop will be concentrated around object-oriented desing and development of real-time, embedded and safety-critical applications
      The Program Committee comprises 16 independent specialists both from academia and industry.
      See more at our webpage:
      Feel free to propose participation. We are looking for your papers, demos submissions, etc.

      See you at ECOOP 2010!


      oSCJ White Paper

      oSCJ : Open Safety-Critical Java white paper will be part of annual report of Computer Science department at Purdue University. See the paper here: