Certain aspects of the Sun API implementation are reflected in the generated C code and the support library, including:
java.lang.String
objects
java.lang.Class
objects
java.lang.Object
does nothing
toba.*
toba.*
hierarchy consists of four components, of which two
are used only on platforms that support just-in-time compilation. The
components are:
toba.classfile.*
: Classes that support reading JVM class
files and operating on the instructions and data structures therein.toba.translator.*
: The classes which translate from JVM
class files into C code. This is the main Toba program.toba.jit.*
: Classes that generate machine-specific code from
a JVM class file.toba.runtime.*
: Classes that support transfer of data
between the native C format used by Tobafied sources and the internal Java
classes used in toba.jit.*
.
toba.classfile.*
classes for reading JVM class
files.
Translation of a class file produces a .h file and a .c file.
The .h file contains function prototypes, structure definitions,
and a class initializer macro.
The .c file contains structure initializations and
executable method code.
Each Java method produces a C function with corresponding parameters. Instance methods also include a parameter corresponding to the instance object. Method names are modified if necessary (to produce names that are legal in the C world) and a hash code is appended to distinguish among overloaded methods and like-named methods of different classes.
Positions on the Java Virtual Machine (JVM) stack are mapped to sets of local variables: i1, i2, i3,... for integers, f1, f2, f3,... for floats, and so on. (Although there is a single JVM stack, the types never mix.) Stack operations of the JVM code become assignments in the generated C code.
Control flow is handled using conditional and unconditional goto statements. Generated labels correspond to each point of the JVM code that is a jump target. The C code looks much like assembly code in this respect.
Exceptions are handled using setjmp and longjmp. Caught exceptions are dispatched by a switch statement at the head of the method. Methods that do not catch exceptions incur no setjmp overhead. The JVM ret operation, really a computed goto, is also handled using the switch statement.
A class record holds the important data about each class. This includes a jump table of all local and inherited methods; any class variables; and general information such as the class name, superclass, instance size, and so on.
Java objects (class instances) are stored in records that are specific to a particular class. These records contain any instance variables and also a pointer to the class record. Pointers to instance records represent Java objects on the stack, in function calls, and as data values inside other objects.
A pair of structures is also generated for each string constant referenced by method code.
Toba links each program with a set of pre-compiled packages. These packages provide a standard API implementation and runtime support needed by Toba.
Class files from Sun's JDK are translated to form the
SUNAPI
package. This package provides the standard Java API to
Toba programs.
A small number of helper functions implement support functions such as initialization and termination, exception handling, and array construction.
Some low-level API methods are implemented as native code. New implementations of these methods are provided with Toba.
The Boehm-Demers-Weiser conservative garbage collector is used for memory management.
Thread support is platform-specific.
The BISS AWT implementation is used to provide AWT support.
Toba was designed with portability in mind. The current release supports Linux and Solaris, although only Linux has a just-in-time compiler. No further ports are currently planned, although some porting hints are available. If you succeed in getting Toba to run on another platform, please mail your patches and build notes, and we will incorporate them into future releases if possible.
Toba requires an ANSI C platform with the following features:
char
, short
, and int
datatypes
of 8, 16, and 32 bits, respectively
long
or long long
Toba's dependency on the Java Developers Kit limits it to systems for which that kit is available.