Showing posts with label RT VM. Show all posts
Showing posts with label RT VM. Show all posts

26/07/2011

Real-time Embedded Java HelloWorld with FijiVM

The previous post introduced FijiVM. In this follow up we show how to compile and run simple Java programs with FijiVM.

Consider a classical HelloWorld Java Program :
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World.");
  }
}

1. Compile .java files

Running a Java compiler on this program will produce HelloWorld.class – a Java byte code representation of this program. In most Java implementations HelloWorld.class would then be provided as input to a Java VM. The program’s main method would be interpreted or JIT-compiled and run.
$ javac -d build/ HelloWorld.java


2. Java2C generation

Instead, to run this program in the Fiji JVM, HelloWorld.class would be provided as input to Fiji’s AOT compiler fivmc. The Fiji compiler then creates a native executable for the target platform as well as a build directory containing the generated code and the resources required to build this executable.
$ $(FIJI_HOME)/bin/fivmc  -o HelloWorld ./build/*.class

This command will then execute the Fiji Java2C compiler that translates the bytecode from the .build/ dir to a C source code and then generates a binary executable file "HelloWorld".

Notable compiler options and runtime variables are:

  • --more-opt   - enable maximal possible performance optimizations
  • --max-threads 5     - max number of threads running in the application
  • --g-def-max-mem=1200k    - set up the heap size
  • --g-def-trigger=850k             -  set up the trigger for the GC
  • export FIVMR_LOG_FILE=log.txt            - log file to document fiji runtime
  • export FIVMR_LOG_LEVEL=3  - filter the log messages, the level 3 will give you the most information
  • export FIVMR_FAKE_RT_PRIORITIES=true         - make FijiVM run on an OS that does not provide real-time guarantees
  • FIVMR_GC_COMPILE_INFO=true
  • FIVMR_GC_MAX_MEM=1m
  • FIVMR_TRIGGER_LOG_GC=true
  • FIVMR_SHOW_COMPILE_INFO=true
  • --no-inline - disable inlining of the C methods, useful when hacking the Java2C compiler or debugging the generated code.
  • --c-debug yes  - enables C debug mode

3. Running HelloWorld

And, to run:
$ ./HelloWorld
Hello World! 


4. FijiVM generated content

Inspection of the build directory after successful compilation gives us some insight into how Fiji works. The build directory contains five types of files:

XML files — one which contains the mapping from Java method to generated C function and two containing configuration for the Java component of the compiler;
- text files containing analysis of the Java program including string literals, referenced methods, types and classes;
- the generated, OS-independent C code representation of the program; • a copy of the Fiji runtime for the target platform;
- a generated Makefile used to build the executable, as well as build scripts to rebuild without regenerating content.

There are in effect two “main” functions, the C main function in the Fiji runtime and the generated C representation of the Java program’s main method. The runtime main invokes the generated Java main after it has completed its initial setup.

5. Cross-compiling with FijiVM


You an also use FijiVM running on your x86 machine to generate executables for other platforms. For example RTEMS running on LEON3 processor or ARM processor running on BeagleBoard. Setting up the FijiVM to cross-compile to a desired platform is very straightforward:

Example #1: adding a Mac OS X PowerPC target on OS X:
$ bin/add-target --name ppc --cc "gcc -arch ppc"

This will create a target called 'ppc' that will build a Fiji VM compiler and runtime that will generate a OS X PowerPC executables.  You can run such executables on almost all Macs, since they have a built-in emulator.  This is great for validating our PowerPC support.  Note that the argument to '--name' can be anything you like.  In many cases, the name is automatically inferred; but specifying one explicitly is often a good idea.  You can then run fivmc as follows to create a binary for PowerPC:
$ bin/fivmc --target ppc 

Example #2: adding an RTEMS target:
$ bin/add-target --rtems-build /path/to/rtems/bsp/build/dir


This will automatically infer everything it needs to know about the BSP, architecture, RTEMS version, etc.  It will also automatically name the target something like RTEMS-sis-rtems4.9-sparc-32, with useful aliases such as sis, rtems4.9, sparc, and sparc-rtems4.9.  So you can then run fivmc using any of the following --target options; whatever you like best:
$ bin/add-target --target sis 
$ bin/add-target --target sparc-rtems4.9 
$ bin/add-target --target sparc 
$ bin/add-target --target RTEMS-sis-rtems4.9-sparc-32 


And that's it. You should be now able to play with the FijiVM, target various platforms and use specific compile options to tailor the generated executables to your specific needs.

11/12/2009

oSCJ Webpage Launched

Recently, we have launched our Open Safety-Critical Java (oSCJ) Project. This project is based on the JSR302 Safety-Critical Java Specification, 

As the first result, an oSCJ Home Page was launched:



More news to come soon, the first release is coming January 2010. Stay tuned.

30/06/2009

Real-time Java VMs

Although real-time Java is becoming well known, the specific Virtual Machines implementing its functionalities are still known only to the community. There is no list of VMs supporting real-time features, furthermore, every VM is implementing a different subset of RTSJ. 
Therefore, I am posting a list of RTSJ-compatible VMs that are available up to this date (sorted by first release date).
  • TimeSys RTSJ Reference Implementation Only licensed for non-commercial use. Runs on X86/Linux. Available at www.timesys.com.
  • Java RTS Sun - Java SE Real-time (Java RTS). Runs on Sparc/Solaris (Beta for SUSE Linux Enterprise Realtime 10, and Red Hat Enterprise MRG 1.0.). Available at http://java.sun.com/javase/technologies/realtime/rts/.
  • IBM WebSphere Real Time. IBM WebSphere Real Time V2 for Real Time Linux, running on main-line real-time Linux distributions (Red Hat MRG and Novell SLERT). However, there are limitations on the hardware supported. The main reason for the hardware limitation is that the supported models have modified firmware to allow better control over SMI event prioritization, in order to achieve determinism of the underlying hardware. Availale at www.ibm.com/software/webservers/realtime/.
Furthermore, other real-time, Java-like platforms have been developed, either commercial or academic projects. Usually, these VMs are not fully compliant with RTSJ.
  • OVM is an academia research project at Purdue University that implements RT VM. Available at http://www.ovmj.org
  • JamaicaVM implements RTSJ and a deterministic garbage collector. Runs on various platforms. Available at http://www.aicas.com/jamaica.html.
  • jRate (Java Real-Time Extension) is an extension of the GNU GCJ compiler front-end and runtime system which adds support for most of the features required by the RTSJ. Available at http://jrate.sourceforge.net/.
  • Aonix PERC is a commercial project targeting many hard real-time, safety critical and embedded systems. The PERC platform is introducing many trade-offs and therefore is not fully compliant with RTSJ, however, allows developers to target a broader scope of applications rather than having strict limitations as it is the case of RTSJ. Available at www.aonix.com/perc.
  • aJ100 is a hardware coded JVM. Available at www.ajile.com.
  • JRockit Real-Time JRockit Enterprise Java Runtime provided by ORACLE is a Java VM featuring real-time garbage collection suitable for soft real-time systems. Available at www.oracle.com/jrockit.
  • IBM/Apogee Aphelion is comprised of reliable and high performance JREs for deploying Java applications on devices based on embedded systems. Supports many OS platforms, further details at http://www.apogee.com/
  • [UPDATE: 07/2011] LJRT - Lund Java based Real-Time, http://www.robot.lth.se/java
  • [UPDATE: 07/2011] FijiVM - FijiVM, http://www.fiji-systems.com/, more also at this post.
Source: Real-time Java programming book, discussions in the Real-time Java Group.
Please, let me know if there is any VM missing in this list.