Subj : Re: AddRoot on the table of pointers To : Aleksander Wysocki From : Brendan Eich Date : Tue Jan 27 2004 11:37 am Aleksander Wysocki wrote: > Brendan Eich wrote: > >> There's no such "JS_AddRootArray" API. There could be, but it adds >> code bloat for something no one has requested until now (in > 6 years). > > > hmm... > anyway solution would slow down the gc - as i understand > every object in mark phase (if not marked and not in pending list) > has to be checked if belongs to roots. > as for now it is checked via hashing, so O(1), > and if there were set of tables with roots, they should have been > traversed in linear time... > is my reasoning correct? > No, the GC has to enumerate all roots, so whether you hash each, or hash a table of roots (possibly of size 1), the total number of roots enumerated is the same. Hashing (O(1) as you note) wins when adding and removing roots. > >> Is this table of roots part of the private data of a native object? >> If so, you can implement JSClass.mark and avoid adding roots altogether. > > > do you mean, that if i put my roots in native part of my complex object > and if js-component is marked by gc it can pass control to native > component, which would use JS_MarkGSThing(...) on every element of > the table? > > i have found: > > JS_MarkGSThing(JSContext *cx, void *thing, const char *name, void *arg) > in jsapi.c (but not in jsapi.h) > prefix JS_ suggest it could be used externally...? It's in jsapi.h too: http://lxr.mozilla.org/mozilla/source/js/src/jsapi.h#629. You misspelled it above (GC, not GS), but I'm sure that wasn't the problem. Are you looking at an ancient version of the source? > what do arguments "name" and mystical "arg" mean ? > is it to be passed arg from > (* JS_DLL_CALLBACK JSMarkOp)(JSContext *cx, JSObject *obj, void *arg); ? > > maybe some hints? The comment in jsapi.h explains all this, there's no mystery: http://lxr.mozilla.org/mozilla/source/js/src/jsapi.h#616. /be .