This procedure runs a standard Java™ application in a real-time environment
using the ahead-of-time (AOT) compiler, without the need to rewrite
code. Use this sample to compare running the same application using
the JIT compiler.
About this task
The ahead-of-time compiler compiles your Java application to native code before running
it. Therefore, you can predict how the application runs more precisely,
because there are no interruptions caused by just-in-time (JIT) compilation.
Procedure
- Convert the application bytecodes into native code.
- Identify which bytecodes to precompile
by running the sample with the normal JIT compiler:
java -Xrealtime -Xjit:verbose={precompile},vlog=./sim.aotOpts \
-classpath ./demo.jar -Xgc:scopedMemoryMaximumSize=11m demo.sim.SimLauncher <port>
And
in a new window, enter:java -Xrealtime -Xjit:verbose={precompile},vlog=./control.aotOpts \
-classpath ./demo.jar -Xmx300m demo.controller.JavaControlLauncher localhost <port>
where <port> is
an deallocated port for this workstation. You
will see messages similar to the following: Fire down transitions 141, fire horizontally transitions 141
and:Land!
- Combine the AOT options files. The names
used for the log files created in the previous step have
date and process ID information appended to the file name specified
by the vlog= option. For example, vlog=sim.aotOpts generates
a file name similar to sim.aotOpts.20081014.234958.13205:
cat sim.aotOpts.20081014.234958.13205 control.aotOpts.20081014.234958.13205 > sample.aotOpts
- Start the simulation: where <port> is
an unallocated port for this workstation.
- Start the controller: where <host> is
the hostname of the workstation running the simulation and <port> is
the port specified in the previous step. Running both JVMs on the
same workstation can lead to less deterministic behavior.
See Considerations for more
information.
Results
As with the non-real-time example, the application now
runs and generates data points and a graph.
In this run with
ahead-of-time compilation, the graph shows no spikes in the blue Radar
Height, and very accurate tracking of the red Real Height line, because
the Controller code is now running with only very
short garbage collection pauses and no just-in-time compilation interruptions.
Figure 1. Graph generated
by the sample application with ahead-of-time compilation