Closed Bug 661927 Opened 13 years ago Closed 13 years ago

API to force a precise GC (return to event loop, GC with no JS stack, then call a callback)

Categories

(Core :: XPConnect, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla7

People

(Reporter: jruderman, Assigned: jdm)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, Whiteboard: [sg:want])

Attachments

(1 file, 4 obsolete files)

For quitWithLeakCheck (and perhaps other automated tests), I'd like to have a way to cause a GC to happen with no JS on the stack, so I don't have to worry about conservative GC false positives.
Whiteboard: [sg:want]
Do we want to run other things on the event loop here, or do we want to just remove what's entrained on the stack from consideration?
Hmm, is the idea that you would just dispatch a runnable that would check if there's JS on the stack and redispatch itself if it couldn't gc yet?
I'd think that the function would take a JS function as an argument.  When run, it would blow away the JS stack, and invoke the function argument, which is being used as a continuation.  A JS-exec, if you prefer.
Comment 2 sounds right, given the possibility of nested event loops.

No synchronously "blowing away the stack", please :)
Sounds like fun.
Assignee: nobody → josh
I would think for fuzzing that you'd want to be able to make GC happen "right now", or as close to right now as is possible.  That would mean that you wouldn't want to run extra things off the event loop, which comment 2 would do ...
Clearly Javascript needs a general call-cc mechanism.
I can already make GC happen "right now", and I use that for fuzzing. What I'm asking for here would be used for precise leak checks at the end of fuzzing, so it's ok if it's stuck on the end of the event queue.
Attachment #541852 - Attachment is obsolete: true
Attachment #541852 - Flags: review?(mrbkap)
How does the patch guarantee that there is no JS running?
I assumed that simply checking JS_IsRunning on the desired context would be enough. Should I instead acquire the xpconnect JS runtime, then iterate over all its contexts and do the same check?
My mistake. I missed the JS_IsRunning in the ::Run().
(I don't know what JS_IsRunning does)

Another question, couldn't you have some idl interface to implement the callback?
I could. I don't really see why that's desirable, however.
That way the callback would automatically support both function() {} and
{ foo: function() {} }. And using JS API is quite error prone.
Comment on attachment 541856 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.

I think I agree with smaug here. If you take an XPCOM interface, you won't have to deal with rooting or context pushing or anything else like that. I'm not sure if the JS_IsRunning check is sufficient. It's possible that other JS code could be running on a different context. On the other hand, I'm not sure if we have an easy way of finding that out...
Attachment #541856 - Flags: review?(mrbkap)
> I'm not sure if the JS_IsRunning check is sufficient. It's possible that other
> JS code could be running on a different context. On the other hand, I'm not
> sure if we have an easy way of finding that out...

It's possible to grab the runtime service, get the JSRuntime and then use a context iterator to check every context therein. Would that be more suitable?
Attachment #541856 - Attachment is obsolete: true
Comment on attachment 542941 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.

Yeah, this is much cleaner.

One nit: your test addition to the makefile should use tabs instead of spaces for spacing. r=mrbkap with that.
Attachment #542941 - Flags: review?(mrbkap) → review+
http://hg.mozilla.org/integration/mozilla-inbound/rev/8dccc136f585
Whiteboard: [sg:want] → [sg:want] [inbound]
Backed out in http://hg.mozilla.org/integration/mozilla-inbound/rev/5773d613df94 due to persistent windows build failures.

xpccomponents.obj : error LNK2019: unresolved external symbol "struct JSContext * __cdecl js_ContextIterator(struct JSRuntime *,int,struct JSContext * *)" (?js_ContextIterator@@YAPAUJSContext@@PAUJSRuntime@@HPAPAU1@@Z) referenced in function "public: virtual unsigned int __stdcall PreciseGCRunnable::Run(void)" (?Run@PreciseGCRunnable@@UAGIXZ)
NEXT ERROR xul.dll : fatal error LNK1120: 1 unresolved externals
Whiteboard: [sg:want] [inbound] → [sg:want]
Third time's the charm.
Attachment #543136 - Flags: review?(mrbkap)
Attachment #542941 - Attachment is obsolete: true
Comment on attachment 543136 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.

You don't want the request around the JS_GC call. Otherwise, we'll still scan the stack. Other than that, this looks good.
Attachment #543136 - Flags: review?(mrbkap) → review+
Attachment #543136 - Attachment is obsolete: true
Keywords: checkin-needed
http://hg.mozilla.org/mozilla-central/rev/7898841a922a
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla7
Component: DOM → XPConnect
QA Contact: general → xpconnect
Depends on: 669617
Depends on: 698151
Depends on: 722771
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: