gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-dev] Garbage collector


From: strk
Subject: [Gnash-dev] Garbage collector
Date: Fri, 15 Jun 2007 17:14:51 +0200

You may have noticed a huge commit introducing the Garbage Collector.
Some info about it:

First of all, the current implementation allows a compile-time selection
between the old ref-counted model (RC) and the new garbage-collected model (GC).
The default is the RC one, as the GC one is still bogus.

If you want to try the GC model, for improving it, you just have to define
GNASH_USE_GC in libbase/smart_ptr.h

Doing so, every ref_counted class will become a GcResource class and the
boost::intrusive_ptr smart pointers will stop calling the ref-counting methods.

Currently, any constructed GcResource will be automatically registered with
the GC. In the future we might make this optional by using an explicit smart
pointer class like we do use the boost::intrusive_ptr one. An intermediate
step for this would be using a 'smart_ptr' that would map to intrusive_ptr
when using the RC model and to a yet to be defined 'gc_ptr' when using the GC
model. The idea of using a gc_ptr is to allow finer control about what gets
registered to the garbage collector and what doesn't.

Anyway, whatever is registered to the GC will be deleted by the next 
GC::collect()
call *unless* it is found to be reachable. GC::collect() is  currently called 
at the end of movie_root::advance(), so at FPS rate.

Now, the method needing more care is the one used during the mark scan of the 
GC.
Our GC is a mark&sweep one, which is it uses a first scan to find reachable 
objects
and a second scan to remove all those resulting still not reachable.

The way the GC finds reachable objects is by calling a 
GcRoot::markReachableResources()
method. So far, the GcRoot registered is in server/impl.cpp and invokes 
VM::mamarkReachableResources()
and MovieLibrary::markReachableResourceS() in turn.

These function will call ::setMarked() on every GcResource they know of.
GcResource::setMarked() is an inlined function, that sets the instance as
being reachable and (if wasn't already reachable) calls a 
::markReachableResources
virtual function, which is expected to be implemented by all derivate classes.

So far I implemented it in a few classes, providing a class-bound version to be
called by subclasses. For example, as_object will mark all its properties and 
it's
__proto__ member; gnash::character will mark it's parent (probably unneeded)
and the as_object implementation (markAsObjectReachable); gnash::as_function 
will
mark it's prototype and the as_object implementation; gnash::swf_function will
mark the scope chain and the as_function implementation 
(markAsFunctionReachable).

I implemented a few, but there are more to implement and to verify for 
correctness.

Next step would be allowing an *empty* movie to run w/out memory faults, which
is currently not working. You will see that the GC is verbose by deafult, so 
that
it shows which class (and which address) is being removed because not marked 
reachable.
This will hopefully help finding out who's failing to mark it reachable.

Comments and questions welcome.

--strk;




-- 

 ()   ASCII Ribbon Campaign
 /\   Keep it simple! 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]