Skip to content

Commit

Permalink
Remove include/backtrace symlink.
Browse files Browse the repository at this point in the history
This requires a few other changes to support building libutils
properly. It does appear the windows versions of libutils is
referencing CallStack code, but it doesn't seem to cause any problems.
However, I removed those references completely for the windows build.

Also removed a few extra spaces that seem to have accumulated in the
RefBase.cpp.

Bug: 170465278

Test: Builds and libutils unit tests pass.
Change-Id: Ibeee7791b13636b34bdd592c5420fd91620f752a
  • Loading branch information
cferris1000 committed Oct 20, 2020
1 parent 862b017 commit 0e69160
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
1 change: 0 additions & 1 deletion include/backtrace

This file was deleted.

6 changes: 6 additions & 0 deletions libutils/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ cc_library_headers {
header_libs: ["libbacktrace_headers"],
export_header_lib_headers: ["libbacktrace_headers"],
},
linux_glibc: {
header_libs: ["libbacktrace_headers"],
export_header_lib_headers: ["libbacktrace_headers"],
},
linux_bionic: {
header_libs: ["libbacktrace_headers"],
export_header_lib_headers: ["libbacktrace_headers"],
enabled: true,
},
windows: {
Expand Down
49 changes: 33 additions & 16 deletions libutils/RefBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include <android-base/macros.h>

#include <utils/RefBase.h>
#include <log/log.h>

#include <utils/CallStack.h>
#include <utils/RefBase.h>

#include <utils/Mutex.h>

Expand Down Expand Up @@ -55,6 +55,17 @@
// case.
#define DEBUG_REFBASE_DESTRUCTION 1

#if !defined(_WIN32)
// CallStack is only supported on linux type platforms.
#define CALLSTACK_ENABLED 1
#else
#define CALLSTACK_ENABLED 0
#endif

#if CALLSTACK_ENABLED
#include <utils/CallStack.h>
#endif

// ---------------------------------------------------------------------------

namespace android {
Expand Down Expand Up @@ -185,7 +196,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
, mRetain(false)
{
}

~weakref_impl()
{
bool dumpStack = false;
Expand All @@ -196,7 +207,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
while (refs) {
char inc = refs->ref >= 0 ? '+' : '-';
ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref);
#if DEBUG_REFS_CALLSTACK_ENABLED
#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED
CallStack::logStack(LOG_TAG, refs->stack.get());
#endif
refs = refs->next;
Expand All @@ -210,15 +221,17 @@ class RefBase::weakref_impl : public RefBase::weakref_type
while (refs) {
char inc = refs->ref >= 0 ? '+' : '-';
ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref);
#if DEBUG_REFS_CALLSTACK_ENABLED
#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED
CallStack::logStack(LOG_TAG, refs->stack.get());
#endif
refs = refs->next;
}
}
if (dumpStack) {
ALOGE("above errors at:");
#if CALLSTACK_ENABLED
CallStack::logStack(LOG_TAG);
#endif
}
}

Expand Down Expand Up @@ -261,8 +274,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
renameRefsId(mWeakRefs, old_id, new_id);
}

void trackMe(bool track, bool retain)
{
void trackMe(bool track, bool retain) {
mTrackEnabled = track;
mRetain = retain;
}
Expand Down Expand Up @@ -306,7 +318,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
{
ref_entry* next;
const void* id;
#if DEBUG_REFS_CALLSTACK_ENABLED
#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED
CallStack::CallStackUPtr stack;
#endif
int32_t ref;
Expand All @@ -323,7 +335,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
// decrement the reference count.
ref->ref = mRef;
ref->id = id;
#if DEBUG_REFS_CALLSTACK_ENABLED
#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED
ref->stack = CallStack::getCurrent(2);
#endif
ref->next = *refs;
Expand All @@ -335,7 +347,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
{
if (mTrackEnabled) {
AutoMutex _l(mMutex);

ref_entry* const head = *refs;
ref_entry* ref = head;
while (ref != NULL) {
Expand All @@ -359,7 +371,9 @@ class RefBase::weakref_impl : public RefBase::weakref_type
ref = ref->next;
}

#if CALLSTACK_ENABLED
CallStack::logStack(LOG_TAG);
#endif
}
}

Expand All @@ -385,7 +399,7 @@ class RefBase::weakref_impl : public RefBase::weakref_type
snprintf(buf, sizeof(buf), "\t%c ID %p (ref %d):\n",
inc, refs->id, refs->ref);
out->append(buf);
#if DEBUG_REFS_CALLSTACK_ENABLED
#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED
out->append(CallStack::stackToString("\t\t", refs->stack.get()));
#else
out->append("\t\t(call stacks disabled)");
Expand All @@ -412,7 +426,7 @@ void RefBase::incStrong(const void* id) const
{
weakref_impl* const refs = mRefs;
refs->incWeak(id);

refs->addStrongRef(id);
const int32_t c = refs->mStrong.fetch_add(1, std::memory_order_relaxed);
ALOG_ASSERT(c > 0, "incStrong() called on %p after last strong ref", refs);
Expand Down Expand Up @@ -468,7 +482,7 @@ void RefBase::forceIncStrong(const void* id) const
// TODO: Better document assumptions.
weakref_impl* const refs = mRefs;
refs->incWeak(id);

refs->addStrongRef(id);
const int32_t c = refs->mStrong.fetch_add(1, std::memory_order_relaxed);
ALOG_ASSERT(c >= 0, "forceIncStrong called on %p after ref count underflow",
Expand Down Expand Up @@ -550,7 +564,7 @@ void RefBase::weakref_type::decWeak(const void* id)
bool RefBase::weakref_type::attemptIncStrong(const void* id)
{
incWeak(id);

weakref_impl* const impl = static_cast<weakref_impl*>(this);
int32_t curCount = impl->mStrong.load(std::memory_order_relaxed);

Expand All @@ -567,7 +581,7 @@ bool RefBase::weakref_type::attemptIncStrong(const void* id)
// the strong count has changed on us, we need to re-assert our
// situation. curCount was updated by compare_exchange_weak.
}

if (curCount <= 0 || curCount == INITIAL_STRONG_VALUE) {
// we're now in the harder case of either:
// - there never was a strong reference on us
Expand Down Expand Up @@ -624,7 +638,7 @@ bool RefBase::weakref_type::attemptIncStrong(const void* id)
}
}
}

impl->addStrongRef(id);

#if PRINT_REFS
Expand Down Expand Up @@ -719,7 +733,10 @@ RefBase::~RefBase()
// 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);

#if CALLSTACK_ENABLED
CallStack::logStack(LOG_TAG);
#endif
#else
LOG_ALWAYS_FATAL("RefBase: Explicit destruction, weak count = %d", mRefs->mWeak.load());
#endif
Expand Down

0 comments on commit 0e69160

Please sign in to comment.