Closed Bug 326837 Opened 19 years ago Closed 18 years ago

invalid assertions on startup [XPCOM objects created/destroyed from static ctor/dtor] (gActivityTLS != BAD_TLS_INDEX && NS_PTR_TO_INT32(PR_Get ThreadPrivate(gActivityTLS)) == 0)

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: chpe, Assigned: jaas)

References

Details

Attachments

(3 files)

With the patch from bug 318622 (checked in as part of patch from bug 325229), gtkmozembed embedders get loads of assertions on startup:

###!!! ASSERTION: XPCOM objects created/destroyed from static ctor/dtor: 'gActivityTLS != BAD_TLS_INDEX && NS_PTR_TO_INT32(PR_GetThreadPrivate(gActivityTLS)) == 0', file /opt/source/mozilla/trunk/mozilla/xpcom/base/nsTraceRefcntImpl.cpp, line 969

Adding NS_InitLog before using gtk_moz_embed_set_profile_path (and NS_TermLog after the final gtk_moz_embed_pop_startup) makes them go away, but IMHO gtkmozembed embedders shouldn't have to fiddle with that in order not to get those incorrect assertions.

They happen:
- below gtk_moz_embed_set_profile_path
- when I instantiate my nsIDirectoryServiceProvider[2] implementation class, and then use
- gtk_moz_embed_set_directory_service_provider
- gtk_moz_embed_push_startup

For example, they happen below NS_NewNativeLocalFile which is explicitly marked as ok to call before XPCOM startup.

And on shutdown they happen too, I haven't gdb'd those though.

Traces from the assertions on startup (and one on shutdown, then I quit gdb) @ http://www.gnome.org/~chpe/gdblog .
I agree that gtk_moz_embed_set_profile_path and friends shouldn't assert, and I can write a patch to fix that.

I'm not so certain that instantiating your own nsIDirectoryServiceProvider shouldn't assert; I rather think it should, if you're using the NS_IMPL_ISUPPORTS* macros (which with DEBUG defined will call NS_LogAddRef/Release).
Depends on: 318622
This happens on starting a trunk seamonkey too. The assert is from GRE_Startup calling nsGREDirServiceProvider::AddRef.
(In reply to comment #1)
> I'm not so certain that instantiating your own nsIDirectoryServiceProvider
> shouldn't assert; I rather think it should, if you're using the
> NS_IMPL_ISUPPORTS* macros (which with DEBUG defined will call
> NS_LogAddRef/Release).

Well, I *need* to instantiate my directory service provider before XPCOM startup, and I don't see why I shouldn't use the provided convenience macros to simplify my code. Also in this instance the warning is *wrong* (or I'm completely misunderstanding it), since my object is in fact new'd, and has no static ctor.
To the XPCOM debugging code, any addref/release/ctor/dtor outside NS_LogInit/NS_LogTerm is treated as an expected event. It has to be this way, or how else could we know what a static ctor/dtor was? Events that take place outside the logging code will skew the results and report false-positive leaks.

If you want to use the NS_Log* functions (in this indirectly through a macro), you're going to need to initialize/term the logging code in a predictable manner.
I think it might be worth excluding some classes from this warning. It can be expected that a lot of users will want to create an nsIDirectoryServiceProvider before starting XPCOM since you need one to call NS_InitXPCOM. It's a pain for users to have to implement their AddRef and Release manually just to avoid the assertion, and we'd rather that people used the macros anyway.

What we could do is to check if the object being addrefed QIs to nsIDirectoryServiceProvider, and if it does not assert. 
(In reply to comment #5)
> What we could do is to check if the object being addrefed QIs to
> nsIDirectoryServiceProvider, and if it does not assert. 

QI addrefs though...

Hrm.. i spoke too soon. By the time we check ASSERT_ACTIVITY_IS_LEGAL we don't have any pointer we can call QI on (unless we assume that all classes inherit nsISupports as their first baseclass, which i doubt we can rely on).

So the other alternative is to provide macros that implements AddRef and Release that doesn't call NS_LOG_ADDREF. Sort of sucks to not log addref/release for the directory providers, but it doesn't look like there's anything else we can do.
Sure there is, it involves calling NS_LogInit/LogTerm in your main...
Assignee: dougt → benjamin
So we'd pretty much force everyone to call those manually then. Not sure if that is a big deal, but we should be aware of, and document that, that is the proper way to start up XPCOM.
This is a warning now... I'm pretty sure that I do want to introduce the new behavior here since it is binary-compatible with old release binaries. But we should make XRE_InitEmbedding and the gtkmozembed bits call this automatically.
Priority: -- → P3
Target Milestone: --- → mozilla1.9alpha
I'd say that NS_New(Native)LocalFile should call it too.
I get tons of these assertions during startup on Mac :(
This problem may have been made worse by the recent change to log string buffer AddRef and Release.  I think the assertions are somewhat silly.  Why can't we just initialize the TLS the first time we get a call and cleanup from the TLS destructor?  Any problem with that?
Hrm? The original intent of the assertions was to catch XPCOM object allocations that happen during static module loads, which is exactly what seems to be happening, unless I'm missing something.
> Hrm? The original intent of the assertions was to catch XPCOM object
> allocations that happen during static module loads...

OK, I see... so, then perhaps the warning should mention NS_LogInit explicitly to help guide embedders in the right direction.
Blocks: fx-noise
Do we understand what's going on on Mac?
OS: Linux → All
Hardware: PC → All
Summary: invalid assertions on startup [XPCOM objects created/destroyed from static ctor/dtor] → invalid assertions on startup [XPCOM objects created/destroyed from static ctor/dtor] (gActivityTLS != BAD_TLS_INDEX && NS_PTR_TO_INT32(PR_Get ThreadPrivate(gActivityTLS)) == 0)
*** Bug 349285 has been marked as a duplicate of this bug. ***
So, can we exempt the directory service provider from this warning in some (at worst hackish) way? 

This bug seems to be especially prevalent on mac, where you get millions of these warnings for every startup.
We shouldn't be exempting it, we should be adding NS_LogInit/Term pairs around known-good behavior. Do you have stacks for the bogus warnings?
Attached file startup-output.txt.gz
Here's the stacks + arguments of all such assertions (96 for this startup).
I don't run Firefox in a debugger on anything but Mac OS X, but I can confirm what hwaara says about this being especially bad on Mac OS X - I see an insane number of assertions every time. Since obviously this assertion is pointless when its set off like this, can we at least disable it if nobody is going to fix this any time soon?
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.9a1) Gecko/20061023 Minefield/3.0a1

Further to comment 18, comment 19 and comment 20: Are you asking to be told the caller responsible for each of these NS_WARNINGS on the Mac?
(In reply to comment #22)
> Further to comment 18, comment 19 and comment 20: Are you asking to be told the
> caller responsible for each of these NS_WARNINGS on the Mac?

That's what attachment 238412 [details] (comment 20) is.
Thank you. So to take the first one, do we modify the code at 
mozilla/xpcom/io/nsLocalFileOSX.cpp:340 ( I think that that is the macro 
NS_IMPL_THREADSAFE_ISUPPORTS4 ) or 
mozilla/xpcom/base/nsTraceRefcntImpl.cpp:1025 ( the macro ASSERT_ACTIVITY_IS_LEGAL ) or somewhere else entirely?
This might help. Josh, please test?
Attachment #245017 - Flags: review?(joshmoz)
Comment on attachment 245017 [details] [diff] [review]
Fix the errors in XRE_main, hopefully, rev. 1 (fixed on trunk)

unfortunately it looks like this doesn't really do anything
Attachment #245017 - Flags: review?(joshmoz) → review-
Assignee: benjamin → joshmoz
Attached patch fix v1.0Splinter Review
Thanks for the help bsmedberg! Since we do string operations inside of nsLocalFile::Load on the mac, we get these illegal operation warnings. Other platforms don't do string operations and thus don't have those problems. We really only need to declare certain operations to be illegal during actual library loading.
Attachment #245017 - Attachment is obsolete: true
Attachment #245515 - Flags: review?(hwaara)
One thing we might want to change is whether or not we want to put the nsTraceRefcntImpl calls inside or outside of the timeline calls. I put them on the inside in my patch, now I'm leaning towards the outside, and I'll fix that on checkin.

     NS_TIMELINE_START_TIMER("PR_LoadLibrary");
 
+#ifdef NS_BUILD_REFCNT_LOGGING
+    nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
+#endif
+
     *_retval = PR_LoadLibrary(mPath.get());
 
+#ifdef NS_BUILD_REFCNT_LOGGING
+    nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
+#endif
+
     NS_TIMELINE_STOP_TIMER("PR_LoadLibrary");
     NS_TIMELINE_MARK_TIMER1("PR_LoadLibrary", mPath.get());
Comment on attachment 245515 [details] [diff] [review]
fix v1.0

bsmedberg is probably a better reviewer for this patch
Attachment #245515 - Flags: review?(hwaara) → review?(benjamin)
Comment on attachment 245515 [details] [diff] [review]
fix v1.0

Yeah, but I wanted him as an sr. I just wanted a sanity check for a first review.
Attachment #245515 - Flags: review?(benjamin) → review?(mark)
Attachment #245515 - Flags: review?(mark) → review?(dbaron)
Comment on attachment 245515 [details] [diff] [review]
fix v1.0

>Index: io/nsLocalFileMac.cpp

Please remove this file, it is dead code.

r=me, no need for separate sr since XPCOM is strongly-owned
Attachment #245515 - Flags: review?(dbaron) → review+
landed on trunk
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Depends on: 362318
I'm still seeing this. Did it regress, or was the bug ever actually 100% fixed?

AFAICS, it is nsAppRunner code (XRE_main) that is using XPCOM that seems to be triggering all the assertions.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
For example, XRE_GetBinaryPath() asserts a bunch. This line is responsible for the first three assertions: http://tinyurl.com/ycxddh
> For example, XRE_GetBinaryPath() asserts a bunch. This line is responsible for
> the first three assertions: http://tinyurl.com/ycxddh

TinyURLs are pretty useless for archiving, especially if you're just linking into LXR anyway... -> <http://landfill.mozilla.org/mxr-test/mozilla/source/toolkit/xre/nsAppRunner.cpp#1076>
I don't think this needs to be reopened.  Bug 362318 covers the remaining reasons for this assertion to fire.
(In reply to comment #36)
> I don't think this needs to be reopened.  Bug 362318 covers the remaining
> reasons for this assertion to fire.

Ok, didn't know about that bug.
Status: REOPENED → RESOLVED
Closed: 18 years ago18 years ago
Resolution: --- → FIXED
Comment on attachment 245017 [details] [diff] [review]
Fix the errors in XRE_main, hopefully, rev. 1 (fixed on trunk)

Re-requesting review for a change which actually does help fix a class of errors, see bug 362318 for details.
Attachment #245017 - Flags: review- → review?(sspitzer)
Comment on attachment 245017 [details] [diff] [review]
Fix the errors in XRE_main, hopefully, rev. 1 (fixed on trunk)

benjamin, did you want me to review this obsolete patch, or the other one?
Seth, the obsolete one (it's not really).
Attachment #245017 - Attachment is obsolete: false
Comment on attachment 245017 [details] [diff] [review]
Fix the errors in XRE_main, hopefully, rev. 1 (fixed on trunk)

r=sspitzer, sorry for the delay benjamin!
Attachment #245017 - Flags: review?(sspitzer) → review+
Attachment #245017 - Attachment description: Fix the errors in XRE_main, hopefully, rev. 1 → Fix the errors in XRE_main, hopefully, rev. 1 (fixed on trunk)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: