Closed Bug 1445619 Opened 6 years ago Closed 6 years ago

Convert JS_ShutDown world-leaking warning to an error.

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla61
Tracking Status
firefox-esr52 --- wontfix
firefox59 --- wontfix
firefox60 --- wontfix
firefox61 --- fixed

People

(Reporter: nbp, Assigned: nbp)

References

Details

(Keywords: memory-leak, meta)

Attachments

(1 file, 1 obsolete file)

Attachment #8958797 - Flags: review?(jwalden+bmo)
Please don't do this for Firefox builds. This means that all sorts of leaks in Firefox will cause a fatal assert, rather than give a list of leaked objects that might help somebody actually investigate and fix the leak.
If you want tests to fail because of leaked runtimes, the proper way to do that would be to use MOZ_COUNT_CTOR and MOZ_COUNT_DTOR in the JS runtime class.
Comment on attachment 8958797 [details] [diff] [review]
It is not longer acceptable to leak the world.

Debug builds do not even build [1], and this is apparently the wrong approach (comment 3).

[1] https://treeherder.mozilla.org/#/jobs?repo=try&revision=7e2ebacf476a6b048405f5bc6bc89ffbf5bf3d3e
Attachment #8958797 - Flags: review?(jwalden+bmo)
This is following the recommendation from comment 3, except that we cannot use
the MOZ_COUNT_CTOR as they depend on NS_LogCtor. Thus, I added the JS_COUNT_CTOR
macro, and forwarded the NS_LogCtor function to the JS engine at the
initialization of the process.

So far the leakcheck tests[1] seems to be failing for every parent process. I
will investigate if there is something obvious to fix in this patch or
else-where.

In the mean time I am asking for review on this patch (even if it cannot land as
long as Try is orange), but it seems to me that this patch looks correct.

[1] https://treeherder.mozilla.org/#/jobs?repo=try&revision=d2e4c3f2fc33c07c62ab60059942329a9dc33df6
Attachment #8959100 - Flags: review?(jwalden+bmo)
Attachment #8959100 - Flags: review?(continuation)
(In reply to Nicolas B. Pierron [:nbp] {backlog: ~36} from comment #5)
> So far the leakcheck tests[1] seems to be failing for every parent process. I
> will investigate if there is something obvious to fix in this patch or
> else-where.
> 
> [1]
> https://treeherder.mozilla.org/#/
> jobs?repo=try&revision=d2e4c3f2fc33c07c62ab60059942329a9dc33df6

This seems to be an optimized build issue, which apparently do not call the JSRuntime destructor.
Attachment #8958797 - Attachment is obsolete: true
Comment on attachment 8959100 [details] [diff] [review]
It is not longer acceptable to leak the world.

Review of attachment 8959100 [details] [diff] [review]:
-----------------------------------------------------------------

Mm.  Kinda fugly, but eh, it works enough.

::: js/src/jsfriendapi.cpp
@@ +1548,5 @@
>      return owner.context() == nullptr;
>  }
> +
> +static mozilla::Atomic<LogCtorDtor> sLogCtor(nullptr);
> +static mozilla::Atomic<LogCtorDtor> sLogDtor(nullptr);

Kinda dubious of these being atomics, certainly doesn't seem necessary unless I'm missing something -- but eh, JSRuntime creation/destruction is not a perf-sensitive thing.  :-)

@@ +1553,5 @@
> +
> +JS_FRIEND_API(void)
> +js::SetLogCtorDtorFunctions(LogCtorDtor ctor, LogCtorDtor dtor)
> +{
> +    sLogCtor = ctor;

MOZ_ASSERT(ctor && dtor);

@@ +1561,5 @@
> +JS_FRIEND_API(void)
> +js::LogCtor(void* self, const char* type, uint32_t sz)
> +{
> +    LogCtorDtor fun = sLogCtor;
> +    if (fun)

if (LogCtorDtor fun = sLogCtor)

@@ +1569,5 @@
> +JS_FRIEND_API(void)
> +js::LogDtor(void* self, const char* type, uint32_t sz)
> +{
> +    LogCtorDtor fun = sLogDtor;
> +    if (fun)

Ditto.

::: js/xpconnect/src/nsXPConnect.cpp
@@ +120,5 @@
>  void
>  nsXPConnect::InitStatics()
>  {
> +    // These functions are used for reporting leaks, we register them as early
> +    // as possible to avoid missing any classes creations.

...leaks, so we register...
...any classes' creations.
Attachment #8959100 - Flags: review?(jwalden+bmo) → review+
(In reply to Jeff Walden [:Waldo] from comment #7)
> > +
> > +static mozilla::Atomic<LogCtorDtor> sLogCtor(nullptr);
> > +static mozilla::Atomic<LogCtorDtor> sLogDtor(nullptr);
> 
> Kinda dubious of these being atomics, certainly doesn't seem necessary
> unless I'm missing something -- but eh, JSRuntime creation/destruction is
> not a perf-sensitive thing.  :-)

I guess I've done too much Rust in my life to not consider static without some an Atomic wrapper.
Comment on attachment 8959100 [details] [diff] [review]
It is not longer acceptable to leak the world.

Review of attachment 8959100 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks for fixing it to work with our existing leak checking. It'll be interesting to see what it turns up that leak checking on the nsXPConnect object doesn't turn up.

::: js/src/jsfriendapi.cpp
@@ +1551,5 @@
> +static mozilla::Atomic<LogCtorDtor> sLogCtor(nullptr);
> +static mozilla::Atomic<LogCtorDtor> sLogDtor(nullptr);
> +
> +JS_FRIEND_API(void)
> +js::SetLogCtorDtorFunctions(LogCtorDtor ctor, LogCtorDtor dtor)

Like Jeff said, you shouldn't need atomics here, because this method should only be called once. You could assert that the two static variables are null at the start of the function, as a loose check that there's no race. If we're creating more than one XPConnect in a process there's going to be lots more that goes wrong besides this.

::: js/xpconnect/src/nsXPConnect.cpp
@@ +121,5 @@
>  nsXPConnect::InitStatics()
>  {
> +    // These functions are used for reporting leaks, we register them as early
> +    // as possible to avoid missing any classes creations.
> +    js::SetLogCtorDtorFunctions(NS_LogCtor, NS_LogDtor);

That leak you are seeing is funny! I didn't realize we'd even have enough set up to do leak checking in opt builds. Anyways, you just need to guard this with #ifdef NS_BUILD_REFCNT_LOGGING.
Attachment #8959100 - Flags: review?(continuation) → review+
https://treeherder.mozilla.org/#/jobs?repo=try&revision=175f4290cb6ea43559e1173aff438727ed766f77

No leak check failures yet, I will cross fingers and push it.
Pushed by npierron@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/55b8fe1015cb
It is not longer acceptable to leak the world. r=Waldo,mccr8
https://hg.mozilla.org/mozilla-central/rev/55b8fe1015cb
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
Assignee: nobody → nicolas.b.pierron
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: