Java Reference
In-Depth Information
Bar..Dispatch:
.word 6#thenumberofentriesinourtable
.word Object.clone
.word Object.equals
.word Object.toString
.word Bar.f
.word Foo.foo
.word Bar.bar
Arrays are a special kind of object; they are dynamically allocated on the heap but lie
outside the Object hierarchy. A possible layout for an array is illustrated in Figure 6.17.
FIGURE 6.17 Layout for an array.
Arrays have a type tag of 1. The size in bytes is the size of the array object in bytes,
that is, 12 + n bytes, where n is the number of elements in the array and bytes is the
number of bytes in each element. The array length is the number of elements in the array;
any implementation of the JVM arraylength instruction must compute this value. The
array elements follow. The size of the array object should be rounded up to a multiple of
4 to make sure the next object is word aligned. Notice that an array indexing expression
a[i] would translate to the heap address a + 12 + ibytes, where a is the address of the
array object on the heap and bytes is the number of bytes in a single element.
Strings are also special objects; while they are part of the Object hierarchy, they are
final and so they may not be sub-classed. This means we can do without a dispatch table
pointer in string objects; we can maintain one dispatch table for all string operations:
String..Dispatch:
.wordm#misthenumberofentriesinthetable
.wordString.clone
.wordString.equals
.wordString.toString
...addressesofmethodsforStrings...
Which String methods we implement is arbitrary and is left as an exercise.
A possible layout for a string is illustrated in Figure 6.18.
FIGURE 6.18 Layout for a string.
The type tag for a string is 2. Its size in bytes is the number of bytes that must be
allocated to represent the string object; it is 12 + size + 1 rounded up to a multiple of 4,
where size is the number of characters in the string. String size is the number of characters
in the string. The sequence of characters is terminated with an extra null character, with
Unicode representation 0; the null character is necessary so that our strings are compatible
with SPIM strings.
 
Search WWH ::




Custom Search