CROS Dispatching
Here is an outline of the mechanism used by CROS for dynamic
dispatching to keeping things robust, fast, and safe.
- Features of C++ classes are used to create reference and
implementation models and hide the technical details of this
dispatching mechanism, making it natural, efficient, and easy
to use.
- An object reference consists of the following private
data, which must not change for binary compatibility:
-
- Pointer to the start of the combined object (for easy
object identity, garbage collection, etc.). The
object pointer is null if this is a class reference, in
which case the identity of the reference is null.
- Pointer to the dispatch table of the reference, which
should never be null or dispatching will fail.
- The dispatch table maps an implementation class to a
reference class, with an entry for each dispatched
method. Each entry contains the following fields, which
must not change for binary compatibility:
-
- Pointer to the method. In addition to its
primary function, this method is responsible for setting
up its execution context. For a fixed cast, this
will be null.
- Pointer to the class context. This contains
including the nested dispatch table, the offset of the
data within the object, and any additional class
information required. For a fixed cast, this will
be the dispatch table of the resultant reference.
- The first entry in any dispatch table contains the class
implementation's _dispatch method, which accepts a
case-insensitive method name, a canonical signature, the
dispatch entry of the most derived class, and a consistency
pointer (to determine the scope of the compilation unit
within which no casting of reference arguments or returns is
required) and returns the entry of the desired method's
dispatch entry, rejecting the request if the signature is
incompatible. The class context of the _dispatch entry
is also used to uniquely identify the class.
- Fixed casts are precomputed by the reference, appearing
as entries with no method since all that is required is the
replacement dispatch table, which can be stored as the class
context of the cast.
- Dynamic casts are a function of the target reference that
looks up a new dispatch table in a local cache. If this
reference type has never been mapped to the specific
reference class, a dispatch table is created using the
_dispatch method of the class.
- The natural object scope for object methods is
constructed from a reference to the aggregate object type
being defined, which is fixed up via a fixed cast specified
in the dispatch table before invoking a given method. This
scope also makes the superclass methods and private data
available.
- An array with entries of a primative type such as long is
a simple class implementation. An array of CROS objects (not
references) is a generic array class implementation which
parameterizes the contained object type. Each of these
is available in the core CROS library.
- Object instance classes provide static _sizeof and
_alignment methods which are used to allocate the object and
set up object offsets in dispatch tables. If the object
implementation inherits from other object implementations,
these methods report the aggregate size and alignment.
An _aggregate method constructs a class definition where the
data is offset, for purposes of aggragation.
- Initialization, implementation inheritance, and other
standard class methods can be created as required without
breaking compatibility, since they are all robustly supplied
by the _dispatch method.
Go to the main CROS page for an
overview.
Created: January 8, 2000
Last updated: January 15, 2000