[Vm-dev] Compact class question

Bert Freudenberg bert at freudenbergs.de
Tue Dec 7 14:47:59 UTC 2010


Find my fix attached. And you are right, it was at 63 words not bytes.

The first pass used 3-word headers only if contentsSize > 63 words, but the base header's size (1 word) needs to be included in that calculation.

Here's my isolated test method:

foo
	"image build fails if size is 253 to 256 bytes"
	"remove return to change size by 1, add/remove zeroes to change by 2"
	^0+0+0+0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20
	+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39


- Bert -

On 06.12.2010, at 07:10, Gabriel Hernán Barbuto wrote:

> 
> Hi Bert
> 
> 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
> words long.
> 
> 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
> header.
> 
> 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:
> 
> headerWords :=
> 	contentsWords > 63
> 		ifTrue: [3]
> 		ifFalse: [(cl indexIfCompact > 0) ifTrue: [1] ifFalse: [2]].
> 
> It should check against 62, because if the object has 63 words of
> content, it cannot have a one word header.
> 
> 
> In MicroSqueakImageBuilder>>#writeObjHeaderFor:map:on:
> 
> 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
> word header.
> 
> totalWords > 63
> 	ifTrue: [  "3-word header"
> 	ifFalse: [
> 		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.
> 
> Bests
> Gabriel
> 
> 
> 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:
>> 
>>> 
>>> Hi
>>> 
>>> 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
>>> words.
>>> 
>>> 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 -
>> 
>> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: MicroSqueakImageBuilder-headerAndTotalWordsFor.st
Type: application/octet-stream
Size: 812 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20101207/b10b3afb/MicroSqueakImageBuilder-headerAndTotalWordsFor-0001.obj


More information about the Vm-dev mailing list