diff options
author | Hans Boehm <hboehm@google.com> | 2018-08-07 05:35:12 +0000 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2018-08-07 05:35:12 +0000 |
commit | b9d0753d2ba88cc60947823e68bb3bed60268361 (patch) | |
tree | a12bb42c3c2783fbdddd12aefae11b608dcbd5aa /libutils/RefBase.cpp | |
parent | 9d3146af22588e0c23e110be13a515f5347bf687 (diff) |
Revert "Prepare to fail in RefBase destructor if count is untouched"
This reverts commit 9d3146af22588e0c23e110be13a515f5347bf687.
Reason for revert: It appears that weak symbols don't work as expected on MacOS, breaking the MacOS aapt build.
Change-Id: Ica0955106485a7bf2e2c3f09ff7910e230eb4139
Diffstat (limited to 'libutils/RefBase.cpp')
-rw-r--r-- | libutils/RefBase.cpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index 3f1e79a04..90748501d 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -17,41 +17,30 @@ #define LOG_TAG "RefBase" // #define LOG_NDEBUG 0 -#include <memory> - #include <utils/RefBase.h> #include <utils/CallStack.h> -#include <utils/Mutex.h> - #ifndef __unused #define __unused __attribute__((__unused__)) #endif -// Compile with refcounting debugging enabled. -#define DEBUG_REFS 0 - -// The following three are ignored unless DEBUG_REFS is set. +// compile with refcounting debugging enabled +#define DEBUG_REFS 0 // whether ref-tracking is enabled by default, if not, trackMe(true, false) // needs to be called explicitly -#define DEBUG_REFS_ENABLED_BY_DEFAULT 0 +#define DEBUG_REFS_ENABLED_BY_DEFAULT 0 // whether callstack are collected (significantly slows things down) -#define DEBUG_REFS_CALLSTACK_ENABLED 1 +#define DEBUG_REFS_CALLSTACK_ENABLED 1 // folder where stack traces are saved when DEBUG_REFS is enabled // this folder needs to exist and be writable -#define DEBUG_REFS_CALLSTACK_PATH "/data/debug" +#define DEBUG_REFS_CALLSTACK_PATH "/data/debug" // log all reference counting operations -#define PRINT_REFS 0 - -// Continue after logging a stack trace if ~RefBase discovers that reference -// count has never been incremented. Normally we conspicuously crash in that -// case. -#define DEBUG_REFBASE_DESTRUCTION 1 +#define PRINT_REFS 0 // --------------------------------------------------------------------------- @@ -195,7 +184,7 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - CallStack::logStack(LOG_TAG, refs->stack.get()); + refs->stack.log(LOG_TAG); #endif refs = refs->next; } @@ -209,14 +198,14 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - CallStack::logStack(LOG_TAG, refs->stack.get()); + refs->stack.log(LOG_TAG); #endif refs = refs->next; } } if (dumpStack) { ALOGE("above errors at:"); - CallStack::logStack(LOG_TAG); + CallStack stack(LOG_TAG); } } @@ -290,7 +279,7 @@ public: this); int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644); if (rc >= 0) { - (void)write(rc, text.string(), text.length()); + write(rc, text.string(), text.length()); close(rc); ALOGD("STACK TRACE for %p saved in %s", this, name); } @@ -305,7 +294,7 @@ private: ref_entry* next; const void* id; #if DEBUG_REFS_CALLSTACK_ENABLED - CallStack::CallStackUPtr stack; + CallStack stack; #endif int32_t ref; }; @@ -322,7 +311,7 @@ private: ref->ref = mRef; ref->id = id; #if DEBUG_REFS_CALLSTACK_ENABLED - ref->stack = CallStack::getCurrent(2); + ref->stack.update(2); #endif ref->next = *refs; *refs = ref; @@ -357,7 +346,7 @@ private: ref = ref->next; } - CallStack::logStack(LOG_TAG); + CallStack stack(LOG_TAG); } } @@ -384,7 +373,7 @@ private: inc, refs->id, refs->ref); out->append(buf); #if DEBUG_REFS_CALLSTACK_ENABLED - out->append(CallStack::stackToString("\t\t", refs->stack.get())); + out->append(refs->stack.toString("\t\t")); #else out->append("\t\t(call stacks disabled)"); #endif @@ -711,16 +700,16 @@ RefBase::~RefBase() if (mRefs->mWeak.load(std::memory_order_relaxed) == 0) { delete mRefs; } - } else if (mRefs->mStrong.load(std::memory_order_relaxed) == INITIAL_STRONG_VALUE) { + } else if (mRefs->mStrong.load(std::memory_order_relaxed) + == INITIAL_STRONG_VALUE) { // We never acquired a strong reference on this object. -#if DEBUG_REFBASE_DESTRUCTION - // Treating this as fatal is prone to causing boot loops. For debugging, it's - // better to treat as non-fatal. - ALOGD("RefBase: Explicit destruction, weak count = %d (in %p)", mRefs->mWeak.load(), this); - CallStack::logStack(LOG_TAG); -#else - LOG_ALWAYS_FATAL("RefBase: Explicit destruction, weak count = %d", mRefs->mWeak.load()); -#endif + LOG_ALWAYS_FATAL_IF(mRefs->mWeak.load() != 0, + "RefBase: Explicit destruction with non-zero weak " + "reference count"); + // TODO: Always report if we get here. Currently MediaMetadataRetriever + // C++ objects are inconsistently managed and sometimes get here. + // There may be other cases, but we believe they should all be fixed. + delete mRefs; } // For debugging purposes, clear mRefs. Ineffective against outstanding wp's. const_cast<weakref_impl*&>(mRefs) = nullptr; |