[Vm-dev] Compact class question
Gabriel Hernán Barbuto
gbarbuto at gmail.com
Mon Dec 6 15:10:22 UTC 2010
Thanks for your response. I am using John's code and I think I am
seeing the same bug. But I think the problem is when the object is 63
Ben found a method that produced a fail in an assertion. It's a
CompiledMethod instance that occupies 63 words. When the code makes
the calculation to see how many words it needs. It calculates that it
needs 1 word for the header and a total of 64 words for the object in
total. Because it needs to also take into account the word for the
I don't understand how you can encoded this object with a one word
header. I don't know about your fix. But I think the problem is that
this object cannot have a one word header. Because the size field only
allows for values up to 63 words and this value has to take the base
header word into account.
The problem is that John's code calculate the total words that an
object requires in two different places, and does it slightly
different in each one.
In MicroSqueakImageBuilder>>#headerAndTotalWords he calculates the
size of the object like this(CompiledMethod is variable and is bytes):
contents = instSize + (basicSize + 3 // 4) + extraWords
basicSize + 3 // 4 is called indexableWords in the other method.
I think the problem is in the following expression:
contentsWords > 63
ifFalse: [(cl indexIfCompact > 0) ifTrue:  ifFalse: ].
It should check against 62, because if the object has 63 words of
content, it cannot have a one word header.
totalWords := instSize + indexableWords + extraWords + 1.
The extra +1 in the last part of the expression make this particular
object to have a totalWords of 64, and so I think it cannot have a one
totalWords > 63
ifTrue: [ "3-word header"
cl indexIfCompact = 0
ifTrue: [ "2-word header"
ifFalse: [ "1-word header"]]
I think the object should have a 3 word header. Can you explain me how
to encode the size of this object in a one word header. Because I
don't understand how to do this. Thanks in advance.
On Mon, Dec 6, 2010 at 3:31 PM, Bert Freudenberg <bert at freudenbergs.de> wrote:
> On 06.12.2010, at 14:19, Gabriel Hernán Barbuto wrote:
>> I am working on writing an image to disk. If I understand correctly,
>> the size in words field in the one word header must take into account
>> the word for the header. I have a CompiledMethod instance that has 63
>> words of content plus at least one header word for a total of 64
>> I think that I should write a three word header for this instance even
>> though its class is compact. Is this correct? Is it fine to have an
>> instance of compact class that doesn't have a one word header?
> I think it must have a one-word header.
> Are you using MicroSqueak for writing the image? It works fine, including writing compact classes. But be aware John's code had a bug when writing methods that were exactly 63 bytes long. I sent him a fix in the mean time.
> - Bert -
More information about the Vm-dev