From 46455c55fd7b31b0cbf87256527c9a1611b5b838 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Wed, 4 Jun 2014 14:37:49 -0400 Subject: [PATCH] Bug 1019182 - ProfileEntry flags should be zeroed when setting frame data, r=djvj --- js/public/ProfilingStack.h | 19 ++++++++++--------- js/src/vm/SPSProfiler.cpp | 9 +++++++-- tools/profiler/PseudoStack.h | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/js/public/ProfilingStack.h b/js/public/ProfilingStack.h index 39a5ae206a8..97abdde89b3 100644 --- a/js/public/ProfilingStack.h +++ b/js/public/ProfilingStack.h @@ -47,11 +47,9 @@ class ProfileEntry int32_t volatile lineOrPc; // General purpose storage describing this frame. - uint32_t volatile flags; + uint32_t volatile flags_; public: - ProfileEntry(void) : flags(0) {} - // These traits are bit masks. Make sure they're powers of 2. enum Flags { // Indicate whether a profile entry represents a CPP frame. If not set, @@ -93,26 +91,29 @@ class ProfileEntry const char *label() const volatile { return string; } void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { - flags &= ~IS_CPP_ENTRY; + flags_ = 0; spOrScript = aScript; setPC(aPc); } void setCppFrame(void *aSp, uint32_t aLine) volatile { - flags |= IS_CPP_ENTRY; + flags_ = IS_CPP_ENTRY; spOrScript = aSp; lineOrPc = static_cast(aLine); } void setFlag(uint32_t flag) volatile { MOZ_ASSERT(flag != IS_CPP_ENTRY); - flags |= flag; + flags_ |= flag; } void unsetFlag(uint32_t flag) volatile { MOZ_ASSERT(flag != IS_CPP_ENTRY); - flags &= ~flag; + flags_ &= ~flag; } bool hasFlag(uint32_t flag) const volatile { - return bool(flags & uint32_t(flag)); + return bool(flags_ & flag); + } + uint32_t flags() const volatile { + return flags_; } void *stackAddress() const volatile { @@ -140,7 +141,7 @@ class ProfileEntry static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } - static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) diff --git a/js/src/vm/SPSProfiler.cpp b/js/src/vm/SPSProfiler.cpp index f9e8a12da24..e8b40bd1da4 100644 --- a/js/src/vm/SPSProfiler.cpp +++ b/js/src/vm/SPSProfiler.cpp @@ -215,6 +215,7 @@ SPSProfiler::enterNative(const char *string, void *sp) if (current < max_) { stack[current].setLabel(string); stack[current].setCppFrame(sp, 0); + JS_ASSERT(stack[current].flags() == js::ProfileEntry::IS_CPP_ENTRY); } *size = current + 1; } @@ -235,10 +236,14 @@ SPSProfiler::push(const char *string, void *sp, JSScript *script, jsbytecode *pc volatile ProfileEntry &entry = stack[current]; entry.setLabel(string); - if (sp != nullptr) + if (sp != nullptr) { entry.setCppFrame(sp, 0); - else + JS_ASSERT(entry.flags() == js::ProfileEntry::IS_CPP_ENTRY); + } + else { entry.setJsFrame(script, pc); + JS_ASSERT(entry.flags() == 0); + } // Track if mLabel needs a copy. if (copy) diff --git a/tools/profiler/PseudoStack.h b/tools/profiler/PseudoStack.h index af186593d69..00e1eecd038 100644 --- a/tools/profiler/PseudoStack.h +++ b/tools/profiler/PseudoStack.h @@ -362,6 +362,7 @@ public: // been written such that mStack is always consistent. entry.setLabel(aName); entry.setCppFrame(aStackAddress, line); + MOZ_ASSERT(entry.flags() == js::ProfileEntry::IS_CPP_ENTRY); uint32_t uint_category = static_cast(aCategory); MOZ_ASSERT(