Note: There are a few cases of duplicates in user autocompletion which are being worked on.

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

RESOLVED FIXED in mozilla7

Status

()

Core
XPConnect
--
enhancement
RESOLVED FIXED
6 years ago
2 years ago

People

(Reporter: Jesse Ruderman, Assigned: jdm)

Tracking

(Depends on: 1 bug, Blocks: 1 bug, {dev-doc-complete})

Trunk
mozilla7
dev-doc-complete
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [sg:want])

Attachments

(1 attachment, 4 obsolete attachments)

(Reporter)

Description

6 years ago
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.
(Reporter)

Updated

6 years ago
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?
(Assignee)

Comment 2

6 years ago
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.
(Reporter)

Comment 4

6 years ago
Comment 2 sounds right, given the possibility of nested event loops.

No synchronously "blowing away the stack", please :)
(Assignee)

Comment 5

6 years ago
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.
(Reporter)

Comment 8

6 years ago
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.
(Assignee)

Comment 9

6 years ago
Created attachment 541852 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.
Attachment #541852 - Flags: review?(mrbkap)
(Assignee)

Updated

6 years ago
Attachment #541852 - Attachment is obsolete: true
Attachment #541852 - Flags: review?(mrbkap)
(Assignee)

Comment 10

6 years ago
Created attachment 541856 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.
Attachment #541856 - Flags: review?(mrbkap)
How does the patch guarantee that there is no JS running?
(Assignee)

Comment 12

6 years ago
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?
(Assignee)

Comment 14

6 years ago
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)
(Assignee)

Comment 17

6 years ago
> 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?
(Assignee)

Comment 18

6 years ago
Created attachment 542941 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.
Attachment #542941 - Flags: review?(mrbkap)
(Assignee)

Updated

6 years ago
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+
(Assignee)

Comment 20

6 years ago
http://hg.mozilla.org/integration/mozilla-inbound/rev/8dccc136f585
Whiteboard: [sg:want] → [sg:want] [inbound]
(Assignee)

Comment 21

6 years ago
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]
(Assignee)

Comment 22

6 years ago
Created attachment 543136 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.

Third time's the charm.
Attachment #543136 - Flags: review?(mrbkap)
(Assignee)

Updated

6 years ago
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+
(Assignee)

Comment 24

6 years ago
Created attachment 543358 [details] [diff] [review]
Add Cu.schedulePreciseGC to allow for a GC to run with no JS code running.

Patch for landing.
(Assignee)

Updated

6 years ago
Attachment #543136 - Attachment is obsolete: true
(Assignee)

Updated

6 years ago
Keywords: checkin-needed
http://hg.mozilla.org/mozilla-central/rev/7898841a922a
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Keywords: checkin-needed → dev-doc-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla7

Updated

6 years ago
Component: DOM → XPConnect
QA Contact: general → xpconnect
(Reporter)

Updated

6 years ago
Blocks: 633670

Updated

6 years ago
Depends on: 669617
Documentation added:

https://developer.mozilla.org/en/Components.utils.schedulePreciseGC

Documentation updated:

https://developer.mozilla.org/en/Components.utils.forceGC
https://developer.mozilla.org/en/Components.utils
https://developer.mozilla.org/en/Components_object

Firefox 7 for developers has also been updated.
Keywords: dev-doc-needed → dev-doc-complete
Depends on: 698151
(Reporter)

Updated

6 years ago
Depends on: 722771

Updated

2 years ago
Depends on: 1161491
You need to log in before you can comment on or make changes to this bug.