Java Reference
In-Depth Information
pass through the memory or start over from the beginning if they are interrupted,
an incremental GC works in short steps and thus allows for interruptions in
between the steps. The JVMs from NewMonics and Aicas, for example, use
incremental GC.
The JVM specifications do not preclude enhancements needed to make a real-
time implementation, and in 1998 work began on the
Real-Time Specification for
Java
(RTSJ) by a group in the Java Community Process [11,12]. Their job was to
detail a set of standard extensions for a real-time JVM. The RTSJ was released in
2003 and the company TimeSys provides the reference implementation [13]. The
extension classes come via the
javax.realtime
API. Standard Java programs
can run without modification in a real-time JVM.
The RTSJ does not specify a particular GC algorithm such as incremental
collection. It does define new types of memory areas that allow for avoiding the
GC altogether. There is
immortal memory
in which objects are never destroyed
except when the program ends.
Scoped memory
is used only while a process works
within a particular section, or scope, of the program such as a method. Objects
there are automatically destroyed when the process leaves the scope. Neither
immortal nor scoped memories are garbage collected, so using them avoids the
problems of GC interference. Note, however, that the programmer must watch
out for overflow of the immortal memory.
Another important aspect of the RTSJ was the addition of
real-time threads
,
which provide for more precise scheduling than with standard threads. They have
28 levels of priority and their priority is strictly enforced. They are not subject to
so-called
priority inversion
situations where a lower priority thread has a block
on a resource needed by the higher priority thread and thus prevents the higher
priority thread from running. In addition, the RTSJ includes “non-heap real-
time threads” that cannot be interrupted by the GC.
The RTSJ also provides for
asynchronous event handlers
that deal with exter-
nal events (or
happenings
,asthey are called, to distinguish them from the events
in the AWT).
Asynchronous transfer of control
allows one thread to interrupt
another thread in a safe manner, unlike the deprecated
suspend()
and
stop()
methods for standard threads.
Timing is obviously important for real-time programming so the
javax.
realtime
API includes the abstract class
HighResolutionTime
and its sub-
class
AbsoluteTime
,which represents a point in time, and
RelativeTime
,
which represents a duration. The base class uses a
long
value for milliseconds
and an
int
value for nanoseconds. Unlike standard Java, RTSJ requires that an
implementation provide sub-millisecond precision. (Of course, the
accuracy
will
vary according to the capability of the clock on a particular system.)
While still maintaining security protections, the RTSJ allows direct access
to physical memory. This means that device drivers can be created with Java.
Previously, Java had to link to native code to communicate directly with
hardware.
Search WWH ::
Custom Search