Closed Bug 1226376 Opened 10 years ago Closed 9 years ago

Mark mozilla::StaticMutex as MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect
Not set
normal

Tracking

(firefox46 fixed)

RESOLVED FIXED
mozilla46
Tracking Status
firefox46 --- fixed

People

(Reporter: nika, Assigned: nika)

References

Details

Attachments

(2 files, 1 obsolete file)

This will prohibit it from being allocated outside of a static context, which the documentation comment seems to suggest is mandatory.
Summary: Mark mozilla::StaticMutex as MOZ_GLOBAL_CLASS → Mark mozilla::StaticMutex as MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS
Attachment #8689743 - Flags: review?(nfroyd)
Attachment #8689743 - Flags: review?(nfroyd) → review+
So, the problem here is that Atomic<T> doesn't have a non-trivial constructor, instead, it has a constexpr constructor which dispatches to AtomicBase, which also has a constexpr constructor. I'm not sure about what the exact semantics of constexpr are, and whether that is acceptable. For example, on MSVC right now it seems like StaticMutex has a "non-trivial" constructor, (though it will probably? be optimized away?), and on clang/gcc it's a constexpr constructor, and shouldn't therefore have any runtime cost at startup (I think?).
We should = delete some of the things on StaticMutex (and probably StaticAutoPtr, if we don't already). I'm not sure what to do about the DEBUG-only StaticMutex constructor; I think now that we have the static analysis that ensures StaticMutex only occurs at toplevel, we could get rid of the assert.
(In reply to Nathan Froyd [:froydnj] from comment #5) > We should = delete some of the things on StaticMutex (and probably > StaticAutoPtr, if we don't already). I'm not sure what to do about the > DEBUG-only StaticMutex constructor; I think now that we have the static > analysis that ensures StaticMutex only occurs at toplevel, we could get rid > of the assert. So, the analysis to ensure that things only appear at the top level is currently (MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS), which also asserts that all constructors are trivial (in release mode), which is not the case for StaticMutex, as Atomic has a constructor. Do you think that I should also expose MOZ_GLOBAL_CLASS directly for types which must be global, but which may have a non-trivial constructor? I agree that removing the assert is probably OK, but I don't really see any reason to. The thing I'm more worried about is that StaticMutex has a non-trivial destructor in release mode, which AFAICR is a slight problem.
Flags: needinfo?(nfroyd)
Where do you see the release-mode destructor for StaticMutex? That would certainly be a bad thing. I'm a bit surprised that MSVC would have a non-trivial constructor; constexpr isn't supported by 2013, but I think MSVC would optimize the initialization away...unless there's something else I'm missing. I am not super-thrilled about adding another annotation, as I think the current set of annotations is complicated enough. It seems like we ought to permit constexpr constructors in the analysis.
Flags: needinfo?(nfroyd)
(In reply to Nathan Froyd [:froydnj] from comment #7) > Where do you see the release-mode destructor for StaticMutex? That would > certainly be a bad thing. I'm a bit surprised that MSVC would have a > non-trivial constructor; constexpr isn't supported by 2013, but I think MSVC > would optimize the initialization away...unless there's something else I'm > missing. > > I am not super-thrilled about adding another annotation, as I think the > current set of annotations is complicated enough. It seems like we ought to > permit constexpr constructors in the analysis. That's what I was thinking too, I think that it would be optimized away, so it _probably_ isn't a problem (I don't really want to read the output from the compiler to find out ^.^). It's only constructor, sorry, I typoed and typed destructor instead of constructor. I can probably whitelist constexpr constructors in the analysis, I'll take a look at how annoying that will be to do.
I believe that this should be OK for the purpose of MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS, as constexpr functions should be run at compile time, and thus there shouldn't be any of the static constructor overhead. We may want to re-name the internal annotation name to MOZ_CONSTEXPR_CTOR_DTOR if we choose to use this.
Attachment #8697302 - Flags: review?(ehsan)
Attachment #8697302 - Flags: review?(ehsan) → review+
Sorry for asking for review again. I was going to push, but noticed some weird edge cases. I just want to make sure that the edge cases are OK before actually making this change, as they may make this entire thing too complicated and annoying (meaning that we should scrap this entire patch).
Attachment #8697415 - Flags: review?(ehsan)
Attachment #8697302 - Attachment is obsolete: true
Attachment #8697415 - Flags: review?(ehsan) → review+
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
See Also: → 1800294
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: