What is a free object

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

What is a free object

Mathieu SUEN
 
Hi,

I was reading the code of the nextInstance primitive and  to  
undertand I need to know what is a FreeObject:

firstAccessibleObject
        "Return the first accessible object in the heap."
        | obj |
        obj := self firstObject.
        [obj < endOfMemory]
                whileTrue: [(self isFreeObject: obj) ifFalse: [^ obj].
                        obj := self objectAfter: obj].
        self error: 'heap is empty'

isFreeObject: oop

        ^ (self headerType: oop) = HeaderTypeFree



Why are they inside the image? When are they created?
Thanks

        Mth



Reply | Threaded
Open this post in threaded view
|

Re: What is a free object

Michael Haupt-3
 
Hi Mathieu,

On 7/26/07, Mathieu Suen <[hidden email]> wrote:
> I was reading the code of the nextInstance primitive and  to
> undertand I need to know what is a FreeObject:

since Squeak (fortunately) has a garbage collector, the heap does not
just consist of actual objects, but also of chunks of unused memory.
However, these also have an object header to be more easily handled:
during allocation, the memory manager must be able to find a free
piece of heap memory to assign it to the newly allocated object. These
chunks of free memory are what the VM code calls "free objects".

> Why are they inside the image? When are they created?

They are inside the image because the image is a snapshot of a running
system, possibly including pieces of free memory. They are created as
the garbage collector frees memory when objects are deallocated.

I hope this makes some sense.

Best,

Michael
Reply | Threaded
Open this post in threaded view
|

Re: What is a free object

Bert Freudenberg
 

On Jul 26, 2007, at 15:20 , Michael Haupt wrote:

> Hi Mathieu,
>
> On 7/26/07, Mathieu Suen <[hidden email]> wrote:
>> I was reading the code of the nextInstance primitive and  to
>> undertand I need to know what is a FreeObject:
>
> since Squeak (fortunately) has a garbage collector, the heap does not
> just consist of actual objects, but also of chunks of unused memory.
> However, these also have an object header to be more easily handled:
> during allocation, the memory manager must be able to find a free
> piece of heap memory to assign it to the newly allocated object. These
> chunks of free memory are what the VM code calls "free objects".
>
>> Why are they inside the image? When are they created?
>
> They are inside the image because the image is a snapshot of a running
> system, possibly including pieces of free memory. They are created as
> the garbage collector frees memory when objects are deallocated.

Actually they are not in the snapshot - a full garbage collect is  
performed just before snapshotting. This compacts the object memory  
so no free chunks will remain.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: What is a free object

johnmci
 

On Jul 26, 2007, at 10:43 AM, Bert Freudenberg wrote:
>> since Squeak (fortunately) has a garbage collector, the heap does not
>> just consist of actual objects, but also of chunks of unused memory.
>> However, these also have an object header to be more easily handled:
>> during allocation, the memory manager must be able to find a free
>> piece of heap memory to assign it to the newly allocated object.  
>> These
>> chunks of free memory are what the VM code calls "free objects".


To clarify this, the memory allocation logic does not scan for these  
free spaces when allocating new objects.
Rather it allocates memory from the end of the image which is the  
free space after the last GC, by using a simple math on the freeblock  
pointer.

A simplistic view:

After N allocations or if we can't allocate the memory a incremental  
GC is done which garbage collects  young space
and makes the free blocks as it find objects that are garbage. After  
the mark sweep phase of the GC, it runs compact phase
which then moves objects down to perculate all that free space up,  
then resets the freeblock pointer. At this point young space is
fully compacted.   If a full GC runs, then all of object memory is  
GCed and compacted leaving no free blocks in memory.



--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===


Reply | Threaded
Open this post in threaded view
|

Re: What is a free object

Michael Haupt-3
 
Hi,

thanks for sorting this out. I was a little too much on the
Smalltalk-80 trail there. Of course Squeak is much less "standard
conformant". ;-)

Best,

Michael