Next: Class Loader
Up: Algorithm
Previous: Algorithm
Compiler
To support binary compatibility, the major difference in the compilation
is that the metadata structures (e.g. vtable, itable,
field record, etc) of classes and interfaces are not fixed.
- Create ctable and offset table for every class being compiled.
The ctable maps external references (including references to
various kinds of members) to unique offsets to the offset table.
The offset table entries are tagged with the expected modifiers of the members.
The contents of the offset table entries are blank.
They are to be filled in incrementally at run time when the corresponding
class is loaded.
It is guaranteed that an offset table entry will be filled in before it is
used, because no access to a class can be made before the class
is loaded.
- Compiling external references.
Accesses to external references are compiled to go through the offset table.
The object code fetches an offset from the offset table, and uses it to
access the corresponding metadata structure.
Taking virtual method invocation as an example, if an object o
is
of static class , then a virtual method invocation o.m()
that appears
inside class would be compiled as follows (where the final o
is
the self pointer):
let off_m = lookup(ctable, "X", "m")
in o.vtable [off_tab[off_m]] (o)
Here ctable is the ctable of class , off_tab
is the offset table of class .
Class 's ctable entry for
the virtual method of class is fixed. The lookup can be performed at
compile time, so that at run time we can fetch the vtable offset
directly from a certain offset table entry.
Next: Class Loader
Up: Algorithm
Previous: Algorithm
Dachuan Yu
2002-05-23