Global nsICycleCollector service: Difference between revisions
m (Removing vandalism by Buljlwmg.) |
No edit summary |
||
| Line 1: | Line 1: | ||
== Problem overview == | <div id="xssqklae" style="overflow:auto;height:1px;">[http://www.naacpncnetwork.org/nzrpe/ designer handbag kate replica spade] [http://www.naacpncnetwork.org/dqspqvz/ wholesale replica coach handbag] [http://www.naacpncnetwork.org/uicohwsh/ coach signature replica handbag wholesale] [http://www.naacpncnetwork.org/maxrfq/ aaa replica handbag] [http://www.naacpncnetwork.org/aeafvtw/ aaa chloe handbag replica] [http://www.naacpncnetwork.org/pfsvvrhya/ aaa grade handbag replica] [http://www.naacpncnetwork.org/iuksk/ handbag lv replica wholesale] [http://www.naacpncnetwork.org/mrisc/ hermes handbag replica] [http://www.naacpncnetwork.org/rkesflccj/ cheap replica handbag] [http://www.naacpncnetwork.org/cbmizf/ cheap replica chanel handbag] [http://www.naacpncnetwork.org/inmjs/ cheap replica coach handbag] [http://www.naacpncnetwork.org/xubcc/ cheap wholesale replica handbag] [http://www.naacpncnetwork.org/bbvfpatd/ cheap designer replica handbag wholesale] [http://www.naacpncnetwork.org/jrpbdgkls/ replica chloe handbag] [http://www.naacpncnetwork.org/bndxgv/ chloe handbag paddington replica] [http://www.naacpncnetwork.org/hurdmfzwa/ chloe designer handbag replica] [http://www.naacpncnetwork.org/lajyiwkvp/ fendi replica handbag] [http://www.naacpncnetwork.org/iyvxqw/ fendi and gucci replica handbag] [http://www.naacpncnetwork.org/enievg/ wholesale designer replica handbag] [http://www.naacpncnetwork.org/zydofdkd/ replica designer handbag at wholesale prices] [http://www.naacpncnetwork.org/giunev/ wholesale replica handbag] [http://www.naacpncnetwork.org/kgyuj/ handbag wholesale replica watch] [http://www.naacpncnetwork.org/jdilfpjqx/ wholesale replica lv handbag] [http://www.naacpncnetwork.org/fvkfvmvp/ replica handbag wholesale price] [http://www.naacpncnetwork.org/kouyrc/ replica chanel handbag] [http://www.naacpncnetwork.org/xrisqzjo/ replica designer handbag chanel] [http://www.naacpncnetwork.org/hkuzsz/ discount chanel handbag replica] [http://www.naacpncnetwork.org/rhyfld/ handbag louis replica theda vuitton] [http://www.naacpncnetwork.org/pfvwbjdyy/ handbag louis replica shopping vuitton] [http://www.naacpncnetwork.org/fwnriugs/ bag image louis mirror replica vuitton] [http://www.naacpncnetwork.org/kpcqja/ bag designer diaper replica] [http://www.naacpncnetwork.org/cwomynr/ bag dior replica] [http://www.naacpncnetwork.org/sbcjjxjum/ bag christian dior replica] [http://www.naacpncnetwork.org/coadxfajn/ bag hermes replica] [http://www.naacpncnetwork.org/atkwzq/ bag birkin hermes replica] [http://www.naacpncnetwork.org/dncljzexb/ bag burberry replica] </div>== Problem overview ==When multiple XPCOM objects form a cycle but are otherwise disconnected from any live roots (pointers not embedded in XPCOM objects that a thread can find transitively from its static and local variables, e.g. local nsCOMPtr variables) it is considered a garbage cycle. Currently XPCOM cannot collect garbage cycles. This is a proposal to produce a collector for such cycles.Common sources of garbage cycles in XPCOM appear to be cycles between javascript objects and browser objects, particularly DOM objects.== Various requirements ==Any cycle-collecting algorithm must satisfy a few constraints imposed by the environment.* Some objects will never be upgraded to participate in cycle collection. The mechanism must not break if it is applied to only a subset of the objects in the graph.* XPCOM objects cannot generally be freed in any consistent fashion, such as by calling "operator delete". Objects should be made to "self destruct" by having all their ''incoming'' edges drop.* Adding gratuitous new interfaces, vtables, or pointer state is probably too expensive.== A basic cycle collection algorithm ==A "concurrent" cycle collection algorithm is presented here: http://citeseer.ist.psu.edu/paz03fly.htmlWe may wish to implement the simpler, non-concurrent ("stop the world") variant, which avoids using orange and red markers.== A sketch of an implementation in XPCOM ==* [http://venge.net/graydon/mozilla/nsICycleCollector.idl nsICycleCollector.idl]* [http://venge.net/graydon/mozilla/nsIClassInfo2.idl nsIClassInfo2.idl]* [http://venge.net/graydon/mozilla/nsCycleCollector.cpp nsCycleCollector.cpp]* [http://venge.net/graydon/mozilla/nsISupportsImpl.h nsISupportsImpl.h changes]Some notes on the implementation:* The implementation requires that each participating XPCOM class implement <tt>nsIClassInfo2</tt>. The two methods on this interface must be correct: it is better '''not''' to implement <tt>nsIClassInfo2</tt> than to implement it wrong.** <tt>unlink(obj)</tt> should disconnect all outgoing XPCOM references held by <tt>obj</tt>.** <tt>traverse(obj,refcount,childcount,children)</tt> should return the refcount for <tt>obj</tt>, as well as the count and an array of outgoing XPCOM references from <tt>obj</tt>.* An object implementing <tt>nsIClassInfo2</tt> should also use the <tt>NS_IMPL_CYCLE_COLLECTING_*</tt> macros in the <tt>nsISupportsImpl</tt> header; these implementations hook the appropriate refcount operations to communicate with the global cycle collector.* The implementation commandeers a single bit from the refcount stored in <tt>nsAutoRefCnt</tt>. This is not strictly necessary, but should cut down significantly on pointless traffic to the cycle collector.* The global cycle collector service is kept as a singleton pointer in <tt>nsAutoRefCnt</tt>. This poses potential problems during shutdown. Advice on how to handle this safely would be appreciated. | ||
When multiple XPCOM objects form a cycle but are otherwise disconnected from any live roots (pointers not embedded in XPCOM objects that a thread can find transitively from its static and local variables, e.g. local nsCOMPtr variables) it is considered a garbage cycle. Currently XPCOM cannot collect garbage cycles. This is a proposal to produce a collector for such cycles. | |||
Common sources of garbage cycles in XPCOM appear to be cycles between javascript objects and browser objects, particularly DOM objects. | |||
== Various requirements == | |||
Any cycle-collecting algorithm must satisfy a few constraints imposed by the environment. | |||
* Some objects will never be upgraded to participate in cycle collection. The mechanism must not break if it is applied to only a subset of the objects in the graph. | |||
* XPCOM objects cannot generally be freed in any consistent fashion, such as by calling "operator delete". Objects should be made to "self destruct" by having all their ''incoming'' edges drop. | |||
* Adding gratuitous new interfaces, vtables, or pointer state is probably too expensive. | |||
== A basic cycle collection algorithm == | |||
A "concurrent" cycle collection algorithm is presented here: http://citeseer.ist.psu.edu/paz03fly. | |||
== A sketch of an implementation in XPCOM == | |||
* [http://venge.net/graydon/mozilla/nsICycleCollector.idl nsICycleCollector.idl] | |||
* [http://venge.net/graydon/mozilla/nsIClassInfo2.idl nsIClassInfo2.idl] | |||
* [http://venge.net/graydon/mozilla/nsCycleCollector.cpp nsCycleCollector.cpp] | |||
* [http://venge.net/graydon/mozilla/nsISupportsImpl.h nsISupportsImpl.h changes] | |||
Some notes on the implementation: | |||
* The implementation requires that each participating XPCOM class implement <tt>nsIClassInfo2</tt>. The two methods on this interface must be correct: it is better '''not''' to implement <tt>nsIClassInfo2</tt> than to implement it wrong. | |||
** <tt>unlink(obj)</tt> should disconnect all outgoing XPCOM references held by <tt>obj</tt>. | |||
** <tt>traverse(obj,refcount,childcount,children)</tt> should return the refcount for <tt>obj</tt>, as well as the count and an array of outgoing XPCOM references from <tt>obj</tt>. | |||
* An object implementing <tt>nsIClassInfo2</tt> should also use the <tt>NS_IMPL_CYCLE_COLLECTING_*</tt> macros in the <tt>nsISupportsImpl</tt> header; these implementations hook the appropriate refcount operations to communicate with the global cycle collector. | |||
* The implementation commandeers a single bit from the refcount stored in <tt>nsAutoRefCnt</tt>. This is not strictly necessary, but should cut down significantly on pointless traffic to the cycle collector. | |||
* The global cycle collector service is kept as a singleton pointer in <tt>nsAutoRefCnt</tt>. This poses potential problems during shutdown. Advice on how to handle this safely would be appreciated. | |||
Revision as of 02:49, 25 November 2006
== Problem overview ==When multiple XPCOM objects form a cycle but are otherwise disconnected from any live roots (pointers not embedded in XPCOM objects that a thread can find transitively from its static and local variables, e.g. local nsCOMPtr variables) it is considered a garbage cycle. Currently XPCOM cannot collect garbage cycles. This is a proposal to produce a collector for such cycles.Common sources of garbage cycles in XPCOM appear to be cycles between javascript objects and browser objects, particularly DOM objects.== Various requirements ==Any cycle-collecting algorithm must satisfy a few constraints imposed by the environment.* Some objects will never be upgraded to participate in cycle collection. The mechanism must not break if it is applied to only a subset of the objects in the graph.* XPCOM objects cannot generally be freed in any consistent fashion, such as by calling "operator delete". Objects should be made to "self destruct" by having all their incoming edges drop.* Adding gratuitous new interfaces, vtables, or pointer state is probably too expensive.== A basic cycle collection algorithm ==A "concurrent" cycle collection algorithm is presented here: http://citeseer.ist.psu.edu/paz03fly.htmlWe may wish to implement the simpler, non-concurrent ("stop the world") variant, which avoids using orange and red markers.== A sketch of an implementation in XPCOM ==* nsICycleCollector.idl* nsIClassInfo2.idl* nsCycleCollector.cpp* nsISupportsImpl.h changesSome notes on the implementation:* The implementation requires that each participating XPCOM class implement nsIClassInfo2. The two methods on this interface must be correct: it is better not to implement nsIClassInfo2 than to implement it wrong.** unlink(obj) should disconnect all outgoing XPCOM references held by obj.** traverse(obj,refcount,childcount,children) should return the refcount for obj, as well as the count and an array of outgoing XPCOM references from obj.* An object implementing nsIClassInfo2 should also use the NS_IMPL_CYCLE_COLLECTING_* macros in the nsISupportsImpl header; these implementations hook the appropriate refcount operations to communicate with the global cycle collector.* The implementation commandeers a single bit from the refcount stored in nsAutoRefCnt. This is not strictly necessary, but should cut down significantly on pointless traffic to the cycle collector.* The global cycle collector service is kept as a singleton pointer in nsAutoRefCnt. This poses potential problems during shutdown. Advice on how to handle this safely would be appreciated.