Java Reference
In-Depth Information
The layout and dispatch table for class
Bar
, which extends class
Foo
, is illustrated in Figure
6.16.
FIGURE 6.16 Layout and dispatch table for
Bar
.
Assuming the type tag for
Bar
is 5,
Bar..Tag: .word 5
The SPIM code for a template for
Bar
might look like
Bar..Template:
.word Bar..Tag
.word 28
.word Bar..Dispatch
.word 0
.word 0
.word 0
.word 0
Again, the fields have initial values of zero. It is the responsibility of the
<init>
routine for
Foo
and
Bar
to initialize them to 1,2, 3, and 4, respectively.
The construction of the dispatch table for
Bar
follows these steps:
1. First the methods for
Bar
's superclass (
Foo
) are copied into the table.
2. Then we add the methods defined in
Bar
to the dispatch table. The method
Bar.f()
overrides, and so replaces
Foo.f()
in the table; the new
Bar.bar()
is simply added
to the table.
The SPIM code for this dispatch table might look something like the following:
Search WWH ::
Custom Search