Java Reference
In-Depth Information
FIGURE 6.15 Layout and dispatch table for
Foo
.
Assuming the type tag for
Foo
is 4
6
,
Foo..Tag: .word 4
The SPIM code for a template for
Foo
might look like
Foo..Template:
.word Foo..Tag
.word 20
.word Foo..Dispatch
.word 0
.word 0
The fields have initial values of zero. It is the responsibility of the
<init>
routine for
Foo
to initialize them to 1 and 2, respectively.
The construction of the dispatch table for
Foo
follows these steps:
1. First the methods for
Foo
's superclass (
Object
) are copied into the table. (Here we as-
sume we have given
Object
just the three methods
clone()
,
equals()
and
toString
()
).
2. Then we add the methods defined in
Foo
to the dispatch table:
f()
and
foo()
.
The SPIM code for this dispatch table might look something like the following:
Foo..Dispatch:
.word 5#thenumberofentriesinourtable
.word Object.clone
.word Object.equals
.word Object.toString
.word Foo.f
.word Foo.foo
6
This assumes that, 1 represents a string, 2 represents an array, and 3 represents an
Object
.
Search WWH ::
Custom Search