Hi Niko,
the header size calculation is also wrong. If the byte size if the object body is > 255 bytes there needs to be an additional header size word. So something like
byteSizeOfBody := anObject class isBytes ifTrue: [....] ifFalse: [.....]. headerSize := byteSizeOfBody > 255 ifTrue: [12] ifFalse: [anObject class indexIfCompact > 0 ifTrue: [4] ifFalse: [8]].
On Wed, Mar 14, 2012 at 1:05 PM, niko.schwarz@googlemail.com wrote:
Hi guys,
I haven't checked if this bug exists already, so please ignore this if it's been reported before.
Bug in WAMemoryItem:
sizeOfObject: anObject | headerSize instanceSize variableSize | headerSize := anObject class indexIfCompact > 0 ifTrue: [ 4 ] ifFalse: [ 8 ]. instanceSize := anObject class instSize. variableSize := anObject class isBytes ifTrue: [ anObject basicSize ] ifFalse: [ anObject class isWords ifTrue: [ Smalltalk wordSize * anObject basicSize ] ifFalse: [ Smalltalk wordSize * anObject basicSize // 2 ] ]. ^ headerSize + instanceSize + variableSize
In this snippet, the units that are added together in the last line are of different units.
instanceSize is in unit "number of machine words", whereas variableSize and headerSize are in unit "bytes".
The method is fixed here:
sizeOfObject: anObject | headerSize instanceSize variableSize | headerSize := anObject class indexIfCompact > 0 ifTrue: [ 4 ] ifFalse: [ 8 ]. instanceSize := anObject class instSize * Smalltalk wordSize. variableSize := anObject class isBytes ifTrue: [ anObject basicSize ] ifFalse: [ anObject class isWords ifTrue: [ Smalltalk wordSize * anObject basicSize ] ifFalse: [ Smalltalk wordSize * anObject basicSize // 2 ] ]. ^ headerSize + instanceSize + variableSize
Example:
|m| dict := Dictionary new. m := WAMemory new. dict traverseWithMemory: m seen: IdentitySet new. m totalSize
This will incorrectly spit out 10, but should return 16, on a 32 bit VM.
Niko
-- http://scg.unibe.ch/staff/Schwarz twitter.com/nes1983 Tel: +41786126354