Subj : Re: JS_THREADSAFE / assertion failed on rt->gcRunning To : netscape.public.mozilla.jseng From : smaraux Date : Fri Mar 04 2005 01:58 am Brendan Eich wrote in message news:<4227931D.8050804@meer.net>... > sebastien maraux wrote: > > > When I run my program, it crashes after a few seconds, on an assertion > > failed to know if gc is running: > > JS_ASSERT(!rt->gcRunning); > > > You have written a finalizer that attempts to allocate a new GC-thing. > Don't do that. > I don't think so, I have 2 custom finalizers (one for arrays and one for single elements) and none call any JS_New... or JS_ConstructObject. It basically only call JSGetPrivate and delete its private. That's why I was thinking of a JS_THREADSAFE issue, or something related to code build. > > > I have read following post, where you can read that building js with > > JS_THREADSAFE and NSPR or a small replacement for it could fix my > > problem : > > > > http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=7be32359.0403171719.2ef8666%40posting.google.com > > > > However, I don't understand why js is built as multithreaded but > > without this tag in its default configuration, if it's unsafe. > > > I don't know what you mean. SpiderMonkey can be built without > JS_THREADSAFE for use in single-threaded embeddings, and with > JS_THREADSAFE for multi-threaded embeddings -- in the latter case you > want NSPR or a workalike (I am not sure that the post you link to above > supplies a complete workalike). I am under VC6, which as a default project with build setting to "multithreaded dll", but without JS_THREADSAFE definition. I may try to build a "single threaded DLL" project to see if it makes things better. > > > Moreover latest NSPR static binaries are not valid on the ftp (I can > > link js to dll ones, but not static ones), and I don't want additional > > dlls in my project. > > > Pull the source from cvs.mozilla.org and build it yourself. I am behind a very strict firewall which does not authorized cvs port and I don't have any "socks" utilities (I know, that s*cks, it is a common issue here : we have to stick to tarballs in most opensource projects) > > > > I also mention that however my environement is multithreaded, I am > > using js only in a single thread of my program but it still crashes. > > > Then why are you defining JS_THREADSAFE? Oh, you're saying that the > builds we put up define it? Those must be the library builds used with > the Mozilla suite, e.g. libmozjs.so on Linux. Again you should built it > yourself to suit your own requirements. We provide builds as a > convenience for developers, but we can't manage a bunch of different > configurations that meet all needs. > I am using independent js-rc1.5a build (VC6 project comes without this option, but with multithreaded settings) > > Also, is there some detailed doc on how to use JS_BeginRequest / > > JS_EndRequest other than js-c api reference ? I understand that it > > should be placed to bracket maximum non blocking chunk of code, but > > for example if I set members of an object from another , without > > knowing their number in advance, can it be considered as non blocking > > (or short enough) calls ? Or should I test for array size before > > calling JS_BeginRequest. If their is too many elements, must I break > > it in several smaller calls (this could be an issue as I have to > > handle a lot of different arrays types). > > > It depends on how long the loop you've written could run. If you're > worried, maybe using an unsigned index and testing (i % 1024) == 0 or > similar to call JS_YieldRequest(cx) would be good (I made up 1024, you > should pick a better number). Thank you, it makes it clear for me. > > > > I'll now try older versions of NSPR, but I am afraid that it will > > greatly increase my code footprint to link with NSP lib. > > > Use a static libnspr4.a library you build yourself, and ld shouldn't > link more than you need. OK, I don't know if vc6 knows how to link only used and not unused functions in a single c file. But in a first time, if I could just get rid of the assertion, this would be a good first step. > > /be Here is my call stack when the assertion fails : I call a function which should update data of my script : JS_CallFunctionValue(m_JSContext, m_GlobalObject, fval, 2, argv, &rval); -> js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags, uintN argc, jsval *argv, jsval *rval) -> js_Invoke(JSContext *cx, uintN argc, uintN flags) //call a function to move an object left -> js_Interpret(cx, &v); -> JSBool js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp) -> js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, NULL, &v)) -> js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags, uintN argc, jsval *argv, jsval *rval) -> js_Invoke() // call a function to draw moved object -> (my function) fieldToString() // try to print its new position : build a string from its vector position -> JS_NewUCStringCopyZ -> JS_NewString -> js_AllocGCThing -> assertion failed on JS_ASSERT(!rt->gcRunning); If this can help verify that I am not in a finalize function. .