Object Format
Ian Piumarta
ian.piumarta at inria.fr
Tue Oct 29 18:35:49 UTC 2002
Hi PhiHo,
On Tue, 29 Oct 2002, PhiHo Hoang wrote:
>
> > 8-11 10xx indexable byte fields only (no pointers)
> > 12-15 11xx compiled methods: # of literal oops specified in method header
>
> What are these 2 bits 'xx' ? In your slides, you said they are 'low 2
> "excess" size bits'.
It's for byte objects only and is needed because every object's size
is rounded up to an integral number of words (multiple of 4 bytes).
Say you have a byte object containing 6 bytes, it looks like this:
+-------------------------------+
| base header (4 bytes) |
+-------+-------+-------+-------+
| byte1 | byte2 | byte2 | byte4 |
+-------+-------+-------+-------+
| byte5 | byte6 | xxx xxx | xxx = unused byte
+-------+-------+---------------+
| ... next object ... |
The size stored in the base header (or in an extra size word before
the base header) gives the object's size as a number of _words_.
Because the object occupies three words in memory this size will be
three words, which implies a length of 12 bytes. However, your byte
object is really two bytes short of the size implied by the value in
the header: it's only 10 bytes long, not 12. This missing information
(by how many bytes the object is short of the size implied by its word
size) is stored in the `xx' bits of the format field.
For example, given a byte object with format F >= 8 of word size W,
the actual indexable size (number of bytes you're allowed to access
from within Smalltalk) is
(W * 4) - 4 - (F & 3)
i.e., convert words to bytes, then subtract the size of the base
header, then subtract the low two bits of the format (which are the
`excess size').
> Where are the compact class located in the Object Memory ?
They're in an Array, which is itself stored in the specialObjectsArray
(from where the VM can get to it). Look at:
Smalltalk compactClassesArray
which answers the array itself, and in the methods:
SystemDictionary>>compactClassesArray
SystemDictionary>>recreateSpecialObjectsArray
which deal with its presence in the special objects array, and in
methods like:
Behavior>>becomeCompact
Behavior>>becomeUncompact
which show how it is manipulated within the image.
> Having a 5-bit compact class index, how do you get at that class ?
In Smalltalk you use:
Smalltalk compactClassesArray at: index.
(index 0 means non-compact, so it is always at least 1). In the VM
(i.e., methods in class Interpreter) you would use something like:
self fetchPointer: index - 1
ofObject: (self splObj: CompactClasses)
where CompactClasses is 28 (i.e., the 29th element of the special
objects array).
> Thanks,
You're welcome.
Ian
More information about the Squeak-dev
mailing list
|