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 Korn 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. Several components are used:

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

Class File Translation

The class file translator is a 4000-line program written in Java. 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 Library

Toba links each program with a library of object code. The library is composed of API classes, as noted above, and C functions.

The Boehm-Demers-Weiser conservative garbage collector is used for memory management.

Thread support is built on the Solaris threads implementation and is not currently available under Linux.

Some low-level API methods are implemented as native code. New implementations of these methods are provided with Toba.

A small number of helper functions implement support functions such as initialization and termination, exception handling, and array construction.

Portability

Toba was designed with portability in mind. The current release supports Solaris and Linux, although the Linux implementation lacks thread support. Further ports are contemplated, and some porting hints are available.

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 (December, 1996)