Move monitor related object routines to object-inl.h

Also pass through readily available self Thread. Remove unused wait method.
Rename ObjectLock.Wait to document it doesn't honor interrupts.

Change-Id: I991e5036997b3f60ee4fdf1a420beabab9a70c85
diff --git a/src/class_linker.cc b/src/class_linker.cc
index ad51b5e..0e26791 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -1250,7 +1250,7 @@
     }
     // Wait for the pending initialization to complete.
     while (!klass->IsResolved() && !klass->IsErroneous()) {
-      lock.Wait();
+      lock.WaitIgnoringInterrupts();
     }
   }
   if (klass->IsErroneous()) {
@@ -2740,7 +2740,7 @@
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   while (true) {
     self->AssertNoPendingException();
-    lock.Wait();
+    lock.WaitIgnoringInterrupts();
 
     // When we wake up, repeat the test for init-in-progress.  If
     // there's an exception pending (only possible if
@@ -2873,7 +2873,8 @@
     if (!super_class->IsInitialized()) {
       CHECK(!super_class->IsInterface());
       // Must hold lock on object when initializing and setting status.
-      ObjectLock lock(Thread::Current(), klass);
+      Thread* self = Thread::Current();
+      ObjectLock lock(self, klass);
       bool super_initialized = InitializeClass(super_class, can_run_clinit, can_init_fields);
       // TODO: check for a pending exception
       if (!super_initialized) {
@@ -2884,7 +2885,7 @@
           return false;
         }
         klass->SetStatus(mirror::Class::kStatusError);
-        klass->NotifyAll();
+        klass->NotifyAll(self);
         return false;
       }
     }
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index bd63c30..195549a 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -163,7 +163,7 @@
   } else if (name == "java.lang.Object java.lang.Object.internalClone()") {
     result->SetL(receiver->Clone(self));
   } else if (name == "void java.lang.Object.notifyAll()") {
-    receiver->NotifyAll();
+    receiver->NotifyAll(self);
   } else if (name == "int java.lang.String.compareTo(java.lang.String)") {
     String* rhs = args[0].GetL()->AsString();
     CHECK(rhs != NULL);
diff --git a/src/mirror/object-inl.h b/src/mirror/object-inl.h
index 723192d..b6c8008 100644
--- a/src/mirror/object-inl.h
+++ b/src/mirror/object-inl.h
@@ -24,7 +24,9 @@
 #include "array.h"
 #include "field.h"
 #include "class.h"
+#include "monitor.h"
 #include "runtime.h"
+#include "throwable.h"
 
 namespace art {
 namespace mirror {
@@ -41,6 +43,34 @@
   SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(Object, klass_), new_klass, false, false);
 }
 
+inline uint32_t Object::GetThinLockId() {
+  return Monitor::GetThinLockId(monitor_);
+}
+
+inline void Object::MonitorEnter(Thread* self) {
+  Monitor::MonitorEnter(self, this);
+}
+
+inline bool Object::MonitorExit(Thread* self) {
+  return Monitor::MonitorExit(self, this);
+}
+
+inline void Object::Notify(Thread* self) {
+  Monitor::Notify(self, this);
+}
+
+inline void Object::NotifyAll(Thread* self) {
+  Monitor::NotifyAll(self, this);
+}
+
+inline void Object::Wait(Thread* self) {
+  Monitor::Wait(self, this, 0, 0, true, kWaiting);
+}
+
+inline void Object::Wait(Thread* self, int64_t ms, int32_t ns) {
+  Monitor::Wait(self, this, ms, ns, true, kTimedWaiting);
+}
+
 inline bool Object::InstanceOf(const Class* klass) const {
   DCHECK(klass != NULL);
   DCHECK(GetClass() != NULL);
@@ -114,6 +144,64 @@
   return GetClass()->IsReferenceClass();
 }
 
+inline Array* Object::AsArray() {
+  DCHECK(IsArrayInstance());
+  return down_cast<Array*>(this);
+}
+
+inline const Array* Object::AsArray() const {
+  DCHECK(IsArrayInstance());
+  return down_cast<const Array*>(this);
+}
+
+inline BooleanArray* Object::AsBooleanArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveBoolean());
+  return down_cast<BooleanArray*>(this);
+}
+
+inline ByteArray* Object::AsByteArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveByte());
+  return down_cast<ByteArray*>(this);
+}
+
+inline CharArray* Object::AsCharArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveChar());
+  return down_cast<CharArray*>(this);
+}
+
+inline ShortArray* Object::AsShortArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveShort());
+  return down_cast<ShortArray*>(this);
+}
+
+inline IntArray* Object::AsIntArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveInt() ||
+         GetClass()->GetComponentType()->IsPrimitiveFloat());
+  return down_cast<IntArray*>(this);
+}
+
+inline LongArray* Object::AsLongArray() {
+  DCHECK(GetClass()->IsArrayClass());
+  DCHECK(GetClass()->GetComponentType()->IsPrimitiveLong() ||
+         GetClass()->GetComponentType()->IsPrimitiveDouble());
+  return down_cast<LongArray*>(this);
+}
+
+inline String* Object::AsString() {
+  DCHECK(GetClass()->IsStringClass());
+  return down_cast<String*>(this);
+}
+
+inline Throwable* Object::AsThrowable() {
+  DCHECK(GetClass()->IsThrowableClass());
+  return down_cast<Throwable*>(this);
+}
+
 inline bool Object::IsWeakReferenceInstance() const {
   return GetClass()->IsWeakReferenceClass();
 }
diff --git a/src/mirror/object.cc b/src/mirror/object.cc
index 27a42d3..5c65b83 100644
--- a/src/mirror/object.cc
+++ b/src/mirror/object.cc
@@ -35,64 +35,6 @@
 namespace art {
 namespace mirror {
 
-Array* Object::AsArray() {
-  DCHECK(IsArrayInstance());
-  return down_cast<Array*>(this);
-}
-
-const Array* Object::AsArray() const {
-  DCHECK(IsArrayInstance());
-  return down_cast<const Array*>(this);
-}
-
-BooleanArray* Object::AsBooleanArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveBoolean());
-  return down_cast<BooleanArray*>(this);
-}
-
-ByteArray* Object::AsByteArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveByte());
-  return down_cast<ByteArray*>(this);
-}
-
-CharArray* Object::AsCharArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveChar());
-  return down_cast<CharArray*>(this);
-}
-
-ShortArray* Object::AsShortArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveShort());
-  return down_cast<ShortArray*>(this);
-}
-
-IntArray* Object::AsIntArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveInt() ||
-         GetClass()->GetComponentType()->IsPrimitiveFloat());
-  return down_cast<IntArray*>(this);
-}
-
-LongArray* Object::AsLongArray() {
-  DCHECK(GetClass()->IsArrayClass());
-  DCHECK(GetClass()->GetComponentType()->IsPrimitiveLong() ||
-         GetClass()->GetComponentType()->IsPrimitiveDouble());
-  return down_cast<LongArray*>(this);
-}
-
-String* Object::AsString() {
-  DCHECK(GetClass()->IsStringClass());
-  return down_cast<String*>(this);
-}
-
-Throwable* Object::AsThrowable() {
-  DCHECK(GetClass()->IsThrowableClass());
-  return down_cast<Throwable*>(this);
-}
-
 Object* Object::Clone(Thread* self) {
   Class* c = GetClass();
   DCHECK(!c->IsClassClass());
@@ -138,34 +80,6 @@
   return copy.get();
 }
 
-uint32_t Object::GetThinLockId() {
-  return Monitor::GetThinLockId(monitor_);
-}
-
-void Object::MonitorEnter(Thread* thread) {
-  Monitor::MonitorEnter(thread, this);
-}
-
-bool Object::MonitorExit(Thread* thread) {
-  return Monitor::MonitorExit(thread, this);
-}
-
-void Object::Notify() {
-  Monitor::Notify(Thread::Current(), this);
-}
-
-void Object::NotifyAll() {
-  Monitor::NotifyAll(Thread::Current(), this);
-}
-
-void Object::Wait() {
-  Monitor::Wait(Thread::Current(), this, 0, 0, true, kWaiting);
-}
-
-void Object::Wait(int64_t ms, int32_t ns) {
-  Monitor::Wait(Thread::Current(), this, ms, ns, true, kTimedWaiting);
-}
-
 #if VERIFY_OBJECT_ENABLED
 void Object::CheckFieldAssignment(MemberOffset field_offset, const Object* new_value) {
   const Class* c = GetClass();
diff --git a/src/mirror/object.h b/src/mirror/object.h
index e2cedd8..c404b61 100644
--- a/src/mirror/object.h
+++ b/src/mirror/object.h
@@ -97,21 +97,19 @@
 
   uint32_t GetThinLockId();
 
-  void MonitorEnter(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
+  void MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
       EXCLUSIVE_LOCK_FUNCTION(monitor_lock_);
 
-  bool MonitorExit(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
+  bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
       UNLOCK_FUNCTION(monitor_lock_);
 
-  void Notify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  void NotifyAll() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  void Wait() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  void Wait(int64_t timeout) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
-  void Wait(int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   bool IsClass() const;
 
diff --git a/src/monitor.cc b/src/monitor.cc
index aa4e5ac..b4c3964 100644
--- a/src/monitor.cc
+++ b/src/monitor.cc
@@ -23,7 +23,7 @@
 #include "class_linker.h"
 #include "dex_instruction.h"
 #include "mirror/abstract_method-inl.h"
-#include "mirror/object.h"
+#include "mirror/object-inl.h"
 #include "mirror/object_array-inl.h"
 #include "object_utils.h"
 #include "scoped_thread_state_change.h"
diff --git a/src/native/dalvik_system_DexFile.cc b/src/native/dalvik_system_DexFile.cc
index e549a8b..0390703 100644
--- a/src/native/dalvik_system_DexFile.cc
+++ b/src/native/dalvik_system_DexFile.cc
@@ -23,6 +23,7 @@
 #include "image.h"
 #include "jni_internal.h"
 #include "mirror/class_loader.h"
+#include "mirror/object-inl.h"
 #include "mirror/string.h"
 #include "oat.h"
 #include "os.h"
diff --git a/src/native/java_lang_Object.cc b/src/native/java_lang_Object.cc
index 75d5f70..5db7a33 100644
--- a/src/native/java_lang_Object.cc
+++ b/src/native/java_lang_Object.cc
@@ -15,7 +15,7 @@
  */
 
 #include "jni_internal.h"
-#include "mirror/object.h"
+#include "mirror/object-inl.h"
 #include "scoped_thread_state_change.h"
 
 // TODO: better support for overloading.
@@ -34,25 +34,25 @@
 static void Object_notify(JNIEnv* env, jobject java_this) {
   ScopedObjectAccess soa(env);
   mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
-  o->Notify();
+  o->Notify(soa.Self());
 }
 
 static void Object_notifyAll(JNIEnv* env, jobject java_this) {
   ScopedObjectAccess soa(env);
   mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
-  o->NotifyAll();
+  o->NotifyAll(soa.Self());
 }
 
 static void Object_wait(JNIEnv* env, jobject java_this) {
   ScopedObjectAccess soa(env);
   mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
-  o->Wait();
+  o->Wait(soa.Self());
 }
 
 static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
   ScopedObjectAccess soa(env);
   mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
-  o->Wait(ms, ns);
+  o->Wait(soa.Self(), ms, ns);
 }
 
 static JNINativeMethod gMethods[] = {
diff --git a/src/oat/runtime/support_locks.cc b/src/oat/runtime/support_locks.cc
index 38fc48c..79bb7a6 100644
--- a/src/oat/runtime/support_locks.cc
+++ b/src/oat/runtime/support_locks.cc
@@ -15,7 +15,7 @@
  */
 
 #include "callee_save_frame.h"
-#include "mirror/object.h"
+#include "mirror/object-inl.h"
 
 namespace art {
 
diff --git a/src/object_utils.h b/src/object_utils.h
index ea4de90..18ad312 100644
--- a/src/object_utils.h
+++ b/src/object_utils.h
@@ -46,16 +46,16 @@
     obj_->MonitorExit(self_);
   }
 
-  void Wait() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    return Monitor::Wait(self_, obj_, 0, 0, false, kWaiting);
+  void WaitIgnoringInterrupts() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+    Monitor::Wait(self_, obj_, 0, 0, false, kWaiting);
   }
 
   void Notify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    obj_->Notify();
+    obj_->Notify(self_);
   }
 
   void NotifyAll() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    obj_->NotifyAll();
+    obj_->NotifyAll(self_);
   }
 
  private:
diff --git a/src/thread.cc b/src/thread.cc
index 37c6783..d0401b6 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -987,9 +987,8 @@
         soa.DecodeField(WellKnownClasses::java_lang_Thread_lock)->GetObject(opeer_);
     // (This conditional is only needed for tests, where Thread.lock won't have been set.)
     if (lock != NULL) {
-      lock->MonitorEnter(self);
-      lock->Notify();
-      lock->MonitorExit(self);
+      ObjectLock locker(self, lock);
+      locker.Notify();
     }
   }