Improve Logging
A couple of changes here to improve logging. First, we eliminate some red herrings when a java app
is aborting by guarding some lock invariant checking when aborting. Second, we print the name of the
thread (if it exists) if we try to suspend a thread with no peer. A separate CL is coming that
eliminates most, if not all, of the occurences of this that we're seeing on device.
Change-Id: I9177e45462b1f0ff9b88be4d72c7d77edf6ac43c
diff --git a/src/base/mutex.h b/src/base/mutex.h
index e7d2e97..a393765 100644
--- a/src/base/mutex.h
+++ b/src/base/mutex.h
@@ -141,7 +141,7 @@
// Assert that the Mutex is exclusively held by the current thread.
void AssertExclusiveHeld(const Thread* self) {
- if (kDebugLocking && !gAborting) {
+ if (kDebugLocking && (gAborting == 0)) {
CHECK(IsExclusiveHeld(self)) << *this;
}
}
@@ -149,7 +149,7 @@
// Assert that the Mutex is not held by the current thread.
void AssertNotHeldExclusive(const Thread* self) {
- if (kDebugLocking) {
+ if (kDebugLocking && (gAborting == 0)) {
CHECK(!IsExclusiveHeld(self)) << *this;
}
}
@@ -238,7 +238,7 @@
// Assert the current thread has exclusive access to the ReaderWriterMutex.
void AssertExclusiveHeld(const Thread* self) {
- if (kDebugLocking) {
+ if (kDebugLocking & (gAborting == 0)) {
CHECK(IsExclusiveHeld(self)) << *this;
}
}
@@ -246,7 +246,7 @@
// Assert the current thread doesn't have exclusive access to the ReaderWriterMutex.
void AssertNotExclusiveHeld(const Thread* self) {
- if (kDebugLocking) {
+ if (kDebugLocking & (gAborting == 0)) {
CHECK(!IsExclusiveHeld(self)) << *this;
}
}
@@ -257,7 +257,7 @@
// Assert the current thread has shared access to the ReaderWriterMutex.
void AssertSharedHeld(const Thread* self) {
- if (kDebugLocking) {
+ if (kDebugLocking & (gAborting == 0)) {
// TODO: we can only assert this well when self != NULL.
CHECK(IsSharedHeld(self) || self == NULL) << *this;
}
@@ -267,7 +267,7 @@
// Assert the current thread doesn't hold this ReaderWriterMutex either in shared or exclusive
// mode.
void AssertNotHeld(const Thread* self) {
- if (kDebugLocking) {
+ if (kDebugLocking && (gAborting == 0)) {
CHECK(!IsSharedHeld(self)) << *this;
}
}
diff --git a/src/thread.cc b/src/thread.cc
index aa87888..3ed388b 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -53,6 +53,7 @@
#include "runtime_support.h"
#include "scoped_thread_state_change.h"
#include "ScopedLocalRef.h"
+#include "ScopedUtfChars.h"
#include "sirt_ref.h"
#include "gc/space.h"
#include "stack.h"
@@ -605,10 +606,22 @@
Thread* thread;
{
ScopedObjectAccess soa(Thread::Current());
- MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
+ Thread* self = soa.Self();
+ MutexLock mu(self, *Locks::thread_list_lock_);
thread = Thread::FromManagedThread(soa, peer);
if (thread == NULL) {
- LOG(WARNING) << "No such thread for suspend: " << peer;
+ JNIEnv* env = self->GetJniEnv();
+ ScopedLocalRef<jstring> scoped_name_string(env,
+ (jstring)env->GetObjectField(peer,
+ WellKnownClasses::java_lang_Thread_name));
+ ScopedUtfChars scoped_name_chars(env,scoped_name_string.get());
+ if (scoped_name_chars.c_str() == NULL) {
+ LOG(WARNING) << "No such thread for suspend: " << peer;
+ env->ExceptionClear();
+ } else {
+ LOG(WARNING) << "No such thread for suspend: " << peer << ":" << scoped_name_chars.c_str();
+ }
+
return NULL;
}
{