TOBA

The Toba Implementation


Toba includes a class file translator written in Java and interface routines written in C. These are used with the Java Developers Kit, a C compiler, a garbage collector, and a thread library. A shell script named toba pulls these together and serves as the command-line interface.

JDK use

Toba functions in concert with the Java Developers Kit (JDK) from Sun. Currently, Toba requires use of JDK version 1.1. Several components are used:

Certain aspects of the Sun API implementation are reflected in the generated C code and the support library, including:

Overall Structure of toba.*

The toba.* hierarchy consists of four components, of which two are used only on platforms that support just-in-time compilation. The components are:

Class File Translation

The class file translator is a 2500-line program written in Java, which relies on the 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.

Data Structures

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.

The Toba Packages

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.

Portability

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:

Toba's dependency on the Java Developers Kit limits it to systems for which that kit is available.


index | usage | differences | native code | implementation | porting | releases | installation || home
http://www.cs.arizona.edu/sumatra/toba/doc/impl.html (July, 1998)