ObjPtr<>-ify StackTraceElement and ClassLoader.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I457eeda55bbfb905dd2de0abd68451ab42ef9c1f
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index d5ceafe..633e124 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -33,7 +33,7 @@
 #include "mirror/class-inl.h"
 #include "mirror/object-inl.h"
 #include "mirror/object_array-inl.h"
-#include "mirror/stack_trace_element.h"
+#include "mirror/stack_trace_element-inl.h"
 #include "oat_quick_method_header.h"
 #include "obj_ptr-inl.h"
 #include "optimizing/stack_map_stream.h"
diff --git a/compiler/jni/jni_compiler_test.cc b/compiler/jni/jni_compiler_test.cc
index cbd2031..0d0f8a0 100644
--- a/compiler/jni/jni_compiler_test.cc
+++ b/compiler/jni/jni_compiler_test.cc
@@ -34,7 +34,7 @@
 #include "mirror/class_loader.h"
 #include "mirror/object-inl.h"
 #include "mirror/object_array-inl.h"
-#include "mirror/stack_trace_element.h"
+#include "mirror/stack_trace_element-inl.h"
 #include "nativehelper/ScopedLocalRef.h"
 #include "nativeloader/native_loader.h"
 #include "runtime.h"
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 66d134e..428bf30 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -31,6 +31,7 @@
 #include "dex/dex_file_loader.h"
 #include "handle_scope-inl.h"
 #include "jni/jni_internal.h"
+#include "mirror/class_loader-inl.h"
 #include "mirror/object_array-alloc-inl.h"
 #include "nativehelper/scoped_local_ref.h"
 #include "oat_file_assistant.h"
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index 8452675..6d44b71 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -29,7 +29,7 @@
 #include "handle_scope-inl.h"
 #include "jni/jni_internal.h"
 #include "mirror/class.h"
-#include "mirror/class_loader.h"
+#include "mirror/class_loader-inl.h"
 #include "mirror/object-inl.h"
 #include "mirror/object_array-alloc-inl.h"
 #include "oat_file_assistant.h"
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 87c7ba6..f4cc161 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -52,7 +52,7 @@
 #include "jni/jni_internal.h"
 #include "mirror/class-alloc-inl.h"
 #include "mirror/class-inl.h"
-#include "mirror/class_loader.h"
+#include "mirror/class_loader-inl.h"
 #include "mirror/object_array-alloc-inl.h"
 #include "native/dalvik_system_DexFile.h"
 #include "noop_compiler_callbacks.h"
diff --git a/runtime/debug_print.cc b/runtime/debug_print.cc
index 2939b00..cde4d86 100644
--- a/runtime/debug_print.cc
+++ b/runtime/debug_print.cc
@@ -25,7 +25,7 @@
 #include "gc/heap.h"
 #include "gc/space/space-inl.h"
 #include "mirror/class.h"
-#include "mirror/class_loader.h"
+#include "mirror/class_loader-inl.h"
 #include "runtime.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread-current-inl.h"
diff --git a/runtime/mirror/class_loader-inl.h b/runtime/mirror/class_loader-inl.h
index 64b4e74..1c98e0a 100644
--- a/runtime/mirror/class_loader-inl.h
+++ b/runtime/mirror/class_loader-inl.h
@@ -20,10 +20,15 @@
 #include "class_loader.h"
 
 #include "class_table-inl.h"
+#include "object-inl.h"
 
 namespace art {
 namespace mirror {
 
+inline ObjPtr<ClassLoader> ClassLoader::GetParent() {
+  return GetFieldObject<ClassLoader>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, parent_));
+}
+
 template <bool kVisitClasses,
           VerifyObjectFlags kVerifyFlags,
           ReadBarrierOption kReadBarrierOption,
diff --git a/runtime/mirror/class_loader.h b/runtime/mirror/class_loader.h
index 783ba6a..c90a3da 100644
--- a/runtime/mirror/class_loader.h
+++ b/runtime/mirror/class_loader.h
@@ -40,9 +40,7 @@
     return sizeof(ClassLoader);
   }
 
-  ClassLoader* GetParent() REQUIRES_SHARED(Locks::mutator_lock_) {
-    return GetFieldObject<ClassLoader>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, parent_));
-  }
+  ObjPtr<ClassLoader> GetParent() REQUIRES_SHARED(Locks::mutator_lock_);
 
   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
   ClassTable* GetClassTable() REQUIRES_SHARED(Locks::mutator_lock_) {
diff --git a/runtime/mirror/stack_trace_element-inl.h b/runtime/mirror/stack_trace_element-inl.h
new file mode 100644
index 0000000..0ce6866
--- /dev/null
+++ b/runtime/mirror/stack_trace_element-inl.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_INL_H_
+#define ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_INL_H_
+
+#include "stack_trace_element.h"
+
+#include "object-inl.h"
+
+namespace art {
+namespace mirror {
+
+inline ObjPtr<String> StackTraceElement::GetDeclaringClass() {
+  return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_));
+}
+
+inline ObjPtr<String> StackTraceElement::GetMethodName() {
+  return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_));
+}
+
+inline ObjPtr<String> StackTraceElement::GetFileName() {
+  return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_));
+}
+
+}  // namespace mirror
+}  // namespace art
+
+#endif  // ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_INL_H_
diff --git a/runtime/mirror/stack_trace_element.cc b/runtime/mirror/stack_trace_element.cc
index 01f2d76..2a272d3 100644
--- a/runtime/mirror/stack_trace_element.cc
+++ b/runtime/mirror/stack_trace_element.cc
@@ -27,11 +27,11 @@
 namespace art {
 namespace mirror {
 
-StackTraceElement* StackTraceElement::Alloc(Thread* self,
-                                            Handle<String> declaring_class,
-                                            Handle<String> method_name,
-                                            Handle<String> file_name,
-                                            int32_t line_number) {
+ObjPtr<StackTraceElement> StackTraceElement::Alloc(Thread* self,
+                                                   Handle<String> declaring_class,
+                                                   Handle<String> method_name,
+                                                   Handle<String> file_name,
+                                                   int32_t line_number) {
   ObjPtr<StackTraceElement> trace =
       ObjPtr<StackTraceElement>::DownCast(GetClassRoot<StackTraceElement>()->AllocObject(self));
   if (LIKELY(trace != nullptr)) {
@@ -41,7 +41,7 @@
       trace->Init<false>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
     }
   }
-  return trace.Ptr();
+  return trace;
 }
 
 template<bool kTransactionActive>
diff --git a/runtime/mirror/stack_trace_element.h b/runtime/mirror/stack_trace_element.h
index 37ac575..67eedbc 100644
--- a/runtime/mirror/stack_trace_element.h
+++ b/runtime/mirror/stack_trace_element.h
@@ -29,27 +29,21 @@
 // C++ mirror of java.lang.StackTraceElement
 class MANAGED StackTraceElement final : public Object {
  public:
-  String* GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
-    return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_));
-  }
+  ObjPtr<String> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
 
-  String* GetMethodName() REQUIRES_SHARED(Locks::mutator_lock_) {
-    return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_));
-  }
+  ObjPtr<String> GetMethodName() REQUIRES_SHARED(Locks::mutator_lock_);
 
-  String* GetFileName() REQUIRES_SHARED(Locks::mutator_lock_) {
-    return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_));
-  }
+  ObjPtr<String> GetFileName() REQUIRES_SHARED(Locks::mutator_lock_);
 
   int32_t GetLineNumber() REQUIRES_SHARED(Locks::mutator_lock_) {
     return GetField32(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_));
   }
 
-  static StackTraceElement* Alloc(Thread* self,
-                                  Handle<String> declaring_class,
-                                  Handle<String> method_name,
-                                  Handle<String> file_name,
-                                  int32_t line_number)
+  static ObjPtr<StackTraceElement> Alloc(Thread* self,
+                                         Handle<String> declaring_class,
+                                         Handle<String> method_name,
+                                         Handle<String> file_name,
+                                         int32_t line_number)
       REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
 
  private:
diff --git a/runtime/mirror/throwable.cc b/runtime/mirror/throwable.cc
index c6afca0..faa605c 100644
--- a/runtime/mirror/throwable.cc
+++ b/runtime/mirror/throwable.cc
@@ -29,7 +29,7 @@
 #include "object-inl.h"
 #include "object_array-inl.h"
 #include "object_array.h"
-#include "stack_trace_element.h"
+#include "stack_trace_element-inl.h"
 #include "string.h"
 #include "well_known_classes.h"
 
@@ -50,7 +50,8 @@
 void Throwable::SetCause(ObjPtr<Throwable> cause) {
   CHECK(cause != nullptr);
   CHECK(cause != this);
-  Throwable* current_cause = GetFieldObject<Throwable>(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_));
+  ObjPtr<Throwable> current_cause =
+      GetFieldObject<Throwable>(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_));
   CHECK(current_cause == nullptr || current_cause == this);
   if (Runtime::Current()->IsActiveTransaction()) {
     SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_), cause);
@@ -137,8 +138,8 @@
         for (int32_t i = 0; i < ste_array->GetLength(); ++i) {
           ObjPtr<StackTraceElement> ste = ste_array->Get(i);
           DCHECK(ste != nullptr);
-          auto* method_name = ste->GetMethodName();
-          auto* file_name = ste->GetFileName();
+          ObjPtr<String> method_name = ste->GetMethodName();
+          ObjPtr<String> file_name = ste->GetFileName();
           result += StringPrintf(
               "  at %s (%s:%d)\n",
               method_name != nullptr ? method_name->ToModifiedUtf8().c_str() : "<unknown method>",
diff --git a/runtime/module_exclusion_test.cc b/runtime/module_exclusion_test.cc
index 14942ed..67b79d4 100644
--- a/runtime/module_exclusion_test.cc
+++ b/runtime/module_exclusion_test.cc
@@ -19,7 +19,7 @@
 #include "class_linker-inl.h"
 #include "handle.h"
 #include "handle_scope-inl.h"
-#include "mirror/class_loader.h"
+#include "mirror/class_loader-inl.h"
 #include "mirror/dex_cache.h"
 #include "mirror/object-inl.h"
 #include "runtime.h"