Check out the new USENIX Web site. next up previous
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.

  1. 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.
  2. 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 $ X$, then a virtual method invocation o.m() that appears inside class $ C$ 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 $ C$, off_tab is the offset table of class $ C$. Class $ C$'s ctable entry for the virtual method $ m$ of class $ X$ 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 up previous
Next: Class Loader Up: Algorithm Previous: Algorithm
Dachuan Yu 2002-05-23