Closed Bug 375808 Opened 19 years ago Closed 19 years ago

Replacing GCX_PRIVATE by GCX_FUNCTION

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla1.9beta2

People

(Reporter: igor, Assigned: peterv)

References

Details

Attachments

(1 file, 7 obsolete files)

Since the resolution of bug 331966 the only purpose of GCX_PRIVATE is to allocate JSFunction instances. Thus I suggest to replace GCX_PRIVATE by GCX_FUNCTION and replace the current function finalization that depends on js_IsAboutToBeFinalized hack with more straightforward code.
Attached patch Implementation v1 (obsolete) — — Splinter Review
For JSFunction the patch uses the same mark/finalize approach as JSXML* do.
Attachment #259994 - Flags: review?(brendan)
Comment on attachment 259994 [details] [diff] [review] Implementation v1 >@@ -1918,14 +1910,25 @@ gc_dump_thing(JSContext *cx, JSGCThing * > void *privateThing = JSVAL_IS_VOID(privateValue) > ? NULL > : JSVAL_TO_PRIVATE(privateValue); > const char *className = gc_object_class_name(thing); > fprintf(fp, "object %8p %s", privateThing, className); > break; > } >+ case GCX_FUNCTION: >+ { >+ JSFunction *fun = (JSFunction *)thing; >+ >+ fprintf(fp, "function"); >+ if (fun->name && ATOM_IS_STRING(fun->name)) { >+ fputc(' ', fp); >+ js_FileEscapedString(fp, ATOM_TO_STRING(fun->name), 0); >+ } >+ break; >+ } s/fun->name/fun->atom/g Nice cleanup. r=me with that fix. /be
Attachment #259994 - Flags: review?(brendan) → review+
(In reply to comment #2) > >+ if (fun->name && ATOM_IS_STRING(fun->name)) { > > s/fun->name/fun->atom/g Yep, patches for bug 375270 made me to forget that one needs to compile with GC_MARK_DEBUG to verify the dumping code.
Attached patch Implementation v2 (obsolete) — — Splinter Review
Besides addressing GC_MARK_DEBUG issue the patch also fixes embarrassing JSClass declaration where I used null instead of JS_FinalizeStub.
Attachment #259994 - Attachment is obsolete: true
Attachment #260041 - Flags: review?(brendan)
Comment on attachment 260041 [details] [diff] [review] Implementation v2 Whoops, should have caught that. r=me (again) /be
Attachment #260041 - Flags: review?(brendan) → review+
I committed the patch from comment 4 to the trunk: Checking in jsfun.c; /cvsroot/mozilla/js/src/jsfun.c,v <-- jsfun.c new revision: 3.179; previous revision: 3.178 done Checking in jsfun.h; /cvsroot/mozilla/js/src/jsfun.h,v <-- jsfun.h new revision: 3.31; previous revision: 3.30 done Checking in jsgc.c; /cvsroot/mozilla/js/src/jsgc.c,v <-- jsgc.c new revision: 3.208; previous revision: 3.207 done Checking in jsgc.h; /cvsroot/mozilla/js/src/jsgc.h,v <-- jsgc.h new revision: 3.62; previous revision: 3.61 done
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
This patch missed a reference to GCX_PRIVATE at nsXPConnect.cpp:481, turning the tree red.
I removed the patch for now to prepare the proper version.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attached patch Implementation v3 (obsolete) — — Splinter Review
Patch with the xpconnect fix. Sorry about that.
Attachment #260041 - Attachment is obsolete: true
Attachment #260083 - Flags: review?(brendan)
Comment on attachment 260083 [details] [diff] [review] Implementation v3 I forget why we need to allow function and xml gc-things to be ref-counted along with objects, but not qname and namespace (which may entrain objects of their own, which link via parent and proto to wrapped xpcom objects). /be
Attachment #260083 - Flags: review?(brendan) → review+
Peter, see comment 10. /be
I committed the patch from comment 9 to the trunk: Checking in jsfun.c; /cvsroot/mozilla/js/src/jsfun.c,v <-- jsfun.c new revision: 3.181; previous revision: 3.180 done Checking in jsfun.h; /cvsroot/mozilla/js/src/jsfun.h,v <-- jsfun.h new revision: 3.33; previous revision: 3.32 done Checking in jsgc.c; /cvsroot/mozilla/js/src/jsgc.c,v <-- jsgc.c new revision: 3.210; previous revision: 3.209 done Checking in jsgc.h; /cvsroot/mozilla/js/src/jsgc.h,v <-- jsgc.h new revision: 3.64; previous revision: 3.63 done Checking in xpconnect/src/nsXPConnect.cpp; /cvsroot/mozilla/js/src/xpconnect/src/nsXPConnect.cpp,v <-- nsXPConnect.cpp new revision: 1.99; previous revision: 1.98 done
Status: REOPENED → RESOLVED
Closed: 19 years ago → 19 years ago
Resolution: --- → FIXED
(In reply to comment #10) > I forget why we need to allow function and xml gc-things to be ref-counted > along with objects, but not qname and namespace (which may entrain objects of > their own, which link via parent and proto to wrapped xpcom objects). You'd have to ask graydon. With the current code, we actually only care about JSObject, and so should remove the other two. However, when bug 375270 lands we should probably instead add qname and namespace too. Note that this patch made Rlk on fxdbug-linux-tbox jump from 4.70KB to 720KB, undoing all the advances we recently made. Probably because the cycle collector doesn't know anything about the edge that was added from the JSFunction to the JSObject. I'm fine with leaving this patch in if we think bug 375270 will land soon, otherwise we should update the traversal code in XPConnect.
(In reply to comment #13) > You'd have to ask graydon. With the current code, we actually only care about > JSObject, and so should remove the other two. But this is wrong since, as Brendan pointed out, XML-QName-Namespace can point to JS object that refer to XPCOM entities. > However, when bug 375270 lands we > should probably instead add qname and namespace too. That is my current plan.
Flags: in-testsuite-
I like the trace patch, but we should be practicing zero regression tolerance, and using small patches to prove that we understand what caused a regression. Is it a small patch to spot-fix the current trunk to trace the missing edge, and restore the Rlk number? I'm in favor if so. /be
Depends on: 375999
(In reply to comment #14) > But this is wrong since, as Brendan pointed out, XML-QName-Namespace can point > to JS object that refer to XPCOM entities. I know it is wrong, but until we start traversing those objects there's not really a point in refcounting them. (In reply to comment #15) > I like the trace patch, but we should be practicing zero regression tolerance, > and using small patches to prove that we understand what caused a regression. Yeah, I don't completely understand the regression yet, so my proposal for a fix might be wrong. My theory is that we added a cycle between JSFunction and its object (js_MarkFunction now marks fun->object, I don't think we did that before). Since nsXPConnect::Traverse doesn't deal with JSFunction we could simulate the cycle by adding an edge from the JSObject to itself.
If you're not expecting to fix the regression in the next day, I think you should back out, since it will make further leak regressions harder to detect (as well as making the nightly builds a good bit less usable).
(In reply to comment #16) > Yeah, I don't completely understand the regression yet, so my proposal for a > fix might be wrong. My theory is that we added a cycle between JSFunction and > its object (js_MarkFunction now marks fun->object, I don't think we did that > before). Since nsXPConnect::Traverse doesn't deal with JSFunction we could > simulate the cycle by adding an edge from the JSObject to itself. > See my comments in bug 375999.
(In reply to comment #17) > If you're not expecting to fix the regression in the next day, I think you > should back out, since it will make further leak regressions harder to detect > (as well as making the nightly builds a good bit less usable). Ok, if the proposed fix in bug 375999 would not address the issue, I remove this patch.
Reopening as that regression fix did not help at all.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
I took out the patch: Checking in jsfun.c; /cvsroot/mozilla/js/src/jsfun.c,v <-- jsfun.c new revision: 3.183; previous revision: 3.182 done Checking in jsfun.h; /cvsroot/mozilla/js/src/jsfun.h,v <-- jsfun.h new revision: 3.34; previous revision: 3.33 done Checking in jsgc.c; /cvsroot/mozilla/js/src/jsgc.c,v <-- jsgc.c new revision: 3.211; previous revision: 3.210 done Checking in jsgc.h; /cvsroot/mozilla/js/src/jsgc.h,v <-- jsgc.h new revision: 3.65; previous revision: 3.64 done Checking in xpconnect/src/nsXPConnect.cpp; /cvsroot/mozilla/js/src/xpconnect/src/nsXPConnect.cpp,v <-- nsXPConnect.cpp new revision: 1.100; previous revision: 1.99 done
Am I unlucky today on 2007-04-01? Taking out the paches made Linux qm-rhel02 and MacOSX qm-xserve01 red yet the rest of the tboxes compiles. It seems that the red boxes did not picked the js/src/jsgc.h commit, only js/src/xpconnect/src was updated there.
This is a nice patch. Maybe the leakage could be fixed by implementing the JSTRACE_FUNCTION case in JS_TraceChildren and adding JSTRACE_FUNCTION at one or two places in nsXPConnect.cpp. (At the time of this patch, JS_TraceChildren didn't exist.)
Attached patch update v3 w/ bug 375270 (obsolete) — — Splinter Review
>- * Here we need to ensure that JSObject instances are finalized before GC- >- * allocated JSFunction instances so fun_finalize from jsfun.c can get the >- * proper result from the call to js_IsAboutToBeFinalized. For that we >- * simply finalize the list containing JSObject first since the static >- * assert at the beginning of the file guarantees that JSFunction instances >- * are allocated from a different list. >+ * Here we finalize the list containing JSObject first to ensure that >+ * JSObject finalizers can access JSString * and other GC things safely. > */ > for (i = 0; i < GC_NUM_FREELISTS; i++) { > arenaList = &rt->gcArenaList[i == 0 > ? GC_FREELIST_INDEX(sizeof(JSObject)) > : i == GC_FREELIST_INDEX(sizeof(JSObject)) > ? 0 > : i]; >+ arenaList = &rt->gcArenaList[i]; Igor: Do you remember what's going on here exactly? The new comments say that it'll finalize JSObjects first -- that already happens with the ?:?:, but then it gets overwritten with the added line. Patch is basically the attached v3, but updated with the separation of traversal and marking in bug 375270. Have nsXPConnect and JS_TraceChildren trace functions.
(In reply to comment #24) > Igor: Do you remember what's going on here exactly? The new comments say that > it'll finalize JSObjects first -- that already happens with the ?:?:, but then > it gets overwritten with the added line. The current code uses js_IsAboutToBeFinalized(fun) in fun_finalize to check if there is no other live references to fun. That works only if fun is always finalized after the corresponding object. Note that bug 389757 has a patch that also renames GCX_PRIVATE by GCX_FUNCTION and does proper finalization of fun. After that is landed the only thing that would be left for this bug is to add tracing for JSFunction.
Depends on: 389757
Does this bug block bug 379973? /be
(In reply to comment #26) > Does this bug block bug 379973? No, as JSTRACE_FUNCTION is not traced by the cycle collector in any case.
(In reply to comment #27) > (In reply to comment #26) > > Does this bug block bug 379973? > > No, as JSTRACE_FUNCTION is not traced by the cycle collector in any case. With Mardak's patch, it is. Comment #16 suggests something slightly different: tell the cycle collector that the JSObject contains a pointer to itself. (The difference is visible to JS_TraceChildren, so I think we should do whatever makes sense as an API.)
Igor, do we still want this? If so, I think we can reland this (and close bug 375999) now that we've stopped refcounting JS objects in the cycle collector.
Here's what I actually wanted to attach.
Attachment #288712 - Attachment is obsolete: true
Attached patch Implementation v3.1 (obsolete) — — Splinter Review
Igor points out that it might make sense to add JSTRACE_FUNCTION objects to the cycle collector to reduce the number of edges to the objects held through the JSScript. This patch does that and stops adding JSTRACE_QNAME and JSTRACE_NAMESPACE. No new leaks with this patch.
Attachment #260083 - Attachment is obsolete: true
Attachment #275187 - Attachment is obsolete: true
Attachment #288714 - Attachment is obsolete: true
Attachment #288722 - Flags: review?(igor)
Attachment #288722 - Flags: review?(igor) → review+
Fixes non-DEBUG_CC builds by moving the definition of the macro outside of the DEBUG_CC-only block. Also adds some brackets around the macro so negating works. Asking jst for sr on XPConnect part.
Assignee: igor → peterv
Attachment #288722 - Attachment is obsolete: true
Status: REOPENED → ASSIGNED
Attachment #289030 - Flags: superreview?(jst)
Attachment #289030 - Flags: review+
Attachment #289030 - Flags: superreview?(jst) → superreview+
Comment on attachment 289030 [details] [diff] [review] Implementation v3.2 This stops adding JS QName and namespace objects to the cycle collector (they should be held by only one object), reducing the number of nodes in the cycle collector. It also starts adding JSFunction objects to the cycle collector instead of silently traversing them, reducing the number of edges in the cycle collector (because those objects are held by and hold a lot of objects).
Attachment #289030 - Flags: approval1.9?
Comment on attachment 289030 [details] [diff] [review] Implementation v3.2 is there a why to construct automated tests to ensure that specific objects are/are not handled by CC?
Attachment #289030 - Flags: approval1.9? → approval1.9+
I guess we could write a custom nsCycleCollectionTraversalCallback and try traversing various objects. Though there are no general (automatically verifiable) rules about what types of objects should be traversed and which shouldn't, so it'd be hard to make it exhaustive.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago → 19 years ago
Resolution: --- → FIXED
Priority: -- → P3
Target Milestone: --- → mozilla1.9 M10
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: