Issue 4543 in pharo: Wrong calculated size of objects in memory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 4543 in pharo: Wrong calculated size of objects in memory

pharo
Status: New
Owner: ----

New issue 4543 by [hidden email]: Wrong calculated size of objects  
in memory
http://code.google.com/p/pharo/issues/detail?id=4543

Pharo image: Pharo
Pharo core version: Pharo1.3a Latest update: #13204
Virtual machine used: custom


Steps to reproduce:
1. print this: (ByteArray new: 252) sizeInMemory
2. it says 260, but the real size is 264 (252 for bytes, 4 for base header,  
8 for extra header).


The problem is really really subtle. The object carries a 2 words extra  
header if its size is bigger than 255 (because otherwise size won't fit in  
the 8 bit size field). But which size? The response is that the size is the  
amount of bytes including the base header but not the extra header. Because  
of that, the code should add the size of the base header before checking if  
size > 255. This bug only affects objects whose base size is less than 256,  
but that after adding the base header go over 255.

Here is a proposed implementation that fixes the problem:

sizeInMemory
     "Answer the number of bytes consumed by this instance including object  
header."
     | contentBytes |

        contentBytes := Smalltalk wordSize. "base header"
        contentBytes := contentBytes + (self class instSize * Smalltalk  
wordSize). "instance vars"

        self class isVariable ifTrue:[ | bytesPerElement | "indexed elements"
                bytesPerElement := self class isBytes ifTrue: [1] ifFalse: [4].
                contentBytes := contentBytes + (self basicSize * bytesPerElement)
        ].

        contentBytes > 255 ifTrue: [ contentBytes := contentBytes +  (2 *  
Smalltalk wordSize) ]
                                                ifFalse: [ self class indexIfCompact > 0
                                                                        ifFalse: [ contentBytes := contentBytes + Smalltalk wordSize]
                                                                ].
        ^contentBytes


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4543 in pharo: Wrong calculated size of objects in memory

pharo
Updates:
        Status: ReviewNeeded
        Labels: Milestone-1.4

Comment #1 on issue 4543 by [hidden email]: Wrong calculated size of  
objects in memory
http://code.google.com/p/pharo/issues/detail?id=4543

do you have a bunch of tests?


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4543 in pharo: Wrong calculated size of objects in memory

pharo
Updates:
        Status: Closed

Comment #2 on issue 4543 by [hidden email]: Wrong calculated size of  
objects in memory
http://code.google.com/p/pharo/issues/detail?id=4543

in 14059


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4543 in pharo: Wrong calculated size of objects in memory

pharo

Comment #3 on issue 4543 by [hidden email]: Wrong calculated size of  
objects in memory
http://code.google.com/p/pharo/issues/detail?id=4543

Did you sign the license agreement?


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker