Clean up explicit conversions to ObjPtr<>.

Add an ObjPtr<>::DownCast() overload that takes a plain
pointer and remove unnecessary calls to MakeObjPtr(),
usually preceding DownCast(). Move the MakeObjPtr() to
common_art_test.h .

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I2a243b6d8f3b2e773396dfc53b659c5f7d9ea44a
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 80e0f46..b74e81f 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -463,8 +463,8 @@
   auto class_class_size = mirror::Class::ClassClassSize(image_pointer_size_);
   // Allocate the object as non-movable so that there are no cases where Object::IsClass returns
   // the incorrect result when comparing to-space vs from-space.
-  Handle<mirror::Class> java_lang_Class(hs.NewHandle(ObjPtr<mirror::Class>::DownCast(MakeObjPtr(
-      heap->AllocNonMovableObject<true>(self, nullptr, class_class_size, VoidFunctor())))));
+  Handle<mirror::Class> java_lang_Class(hs.NewHandle(ObjPtr<mirror::Class>::DownCast(
+      heap->AllocNonMovableObject<true>(self, nullptr, class_class_size, VoidFunctor()))));
   CHECK(java_lang_Class != nullptr);
   java_lang_Class->SetClassFlags(mirror::kClassFlagClass);
   java_lang_Class->SetClass(java_lang_Class.Get());
@@ -1053,8 +1053,8 @@
   }
 
   class_roots_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
-      ObjPtr<mirror::ObjectArray<mirror::Class>>::DownCast(MakeObjPtr(
-          spaces[0]->GetImageHeader().GetImageRoot(ImageHeader::kClassRoots))));
+      ObjPtr<mirror::ObjectArray<mirror::Class>>::DownCast(
+          spaces[0]->GetImageHeader().GetImageRoot(ImageHeader::kClassRoots)));
   DCHECK_EQ(GetClassRoot<mirror::Class>(this)->GetClassFlags(), mirror::kClassFlagClass);
 
   ObjPtr<mirror::Class> java_lang_Object = GetClassRoot<mirror::Object>(this);
@@ -6621,8 +6621,8 @@
         DCHECK(if_table != nullptr);
         DCHECK(if_table->GetMethodArray(i) != nullptr);
         // If we are working on a super interface, try extending the existing method array.
-        method_array = ObjPtr<mirror::PointerArray>::DownCast(MakeObjPtr(
-            if_table->GetMethodArray(i)->Clone(self)));
+        method_array = ObjPtr<mirror::PointerArray>::DownCast(
+            if_table->GetMethodArray(i)->Clone(self));
       } else {
         method_array = AllocPointerArray(self, num_methods);
       }
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index c969051..a9343e9 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -995,7 +995,7 @@
   // Get the AllFields class for the dex cache and dex file.
   ObjPtr<mirror::Class> all_fields_klass
       = class_linker_->FindClass(soa.Self(), "LAllFields;", class_loader);
-  ASSERT_OBJ_PTR_NE(all_fields_klass, ObjPtr<mirror::Class>(nullptr));
+  ASSERT_TRUE(all_fields_klass != nullptr);
   Handle<mirror::DexCache> dex_cache = hs.NewHandle(all_fields_klass->GetDexCache());
   const DexFile& dex_file = *dex_cache->GetDexFile();
   // Get the index of the array class we want to test.
@@ -1003,13 +1003,12 @@
   ASSERT_TRUE(array_id != nullptr);
   dex::TypeIndex array_idx = dex_file.GetIndexForTypeId(*array_id);
   // Check that the array class wasn't resolved yet.
-  EXPECT_OBJ_PTR_EQ(
-      class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()),
-      ObjPtr<mirror::Class>(nullptr));
+  EXPECT_TRUE(
+      class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()) == nullptr);
   // Resolve the array class we want to test.
   ObjPtr<mirror::Class> array_klass
       = class_linker_->FindClass(soa.Self(), "[Ljava/lang/Object;", class_loader);
-  ASSERT_OBJ_PTR_NE(array_klass, ObjPtr<mirror::Class>(nullptr));
+  ASSERT_TRUE(array_klass != nullptr);
   // Test that LookupResolvedType() finds the array class.
   EXPECT_OBJ_PTR_EQ(
       class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()),
@@ -1030,7 +1029,7 @@
   AssertNonExistentClass("LErroneousInit;");
   Handle<mirror::Class> klass =
       hs.NewHandle(class_linker_->FindClass(soa.Self(), "LErroneousInit;", class_loader));
-  ASSERT_OBJ_PTR_NE(klass.Get(), ObjPtr<mirror::Class>(nullptr));
+  ASSERT_TRUE(klass != nullptr);
   dex::TypeIndex type_idx = klass->GetClassDef()->class_idx_;
   Handle<mirror::DexCache> dex_cache = hs.NewHandle(klass->GetDexCache());
   EXPECT_OBJ_PTR_EQ(
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 00c0a52..2758a8d 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2814,7 +2814,7 @@
   bool success = false;
   if (resolved_method->GetDeclaringClass() == GetClassRoot<mirror::MethodHandle>(linker)) {
     Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
-        ObjPtr<mirror::MethodHandle>::DownCast(MakeObjPtr(receiver_handle.Get()))));
+        ObjPtr<mirror::MethodHandle>::DownCast(receiver_handle.Get())));
     if (intrinsic == Intrinsics::kMethodHandleInvokeExact) {
       success = MethodHandleInvokeExact(self,
                                         *shadow_frame,
@@ -2835,7 +2835,7 @@
   } else {
     DCHECK_EQ(GetClassRoot<mirror::VarHandle>(linker), resolved_method->GetDeclaringClass());
     Handle<mirror::VarHandle> var_handle(hs.NewHandle(
-        ObjPtr<mirror::VarHandle>::DownCast(MakeObjPtr(receiver_handle.Get()))));
+        ObjPtr<mirror::VarHandle>::DownCast(receiver_handle.Get())));
     mirror::VarHandle::AccessMode access_mode =
         mirror::VarHandle::GetAccessModeByIntrinsic(intrinsic);
     success = VarHandleInvokeAccessor(self,
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 9b67030..cd10e12 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -1865,7 +1865,7 @@
                   ObjPtr<mirror::Reference> ref) const
       REQUIRES_SHARED(Locks::mutator_lock_) ALWAYS_INLINE {
     CHECK(klass->IsTypeOfReferenceClass());
-    this->operator()(ObjPtr<mirror::Object>(ref), mirror::Reference::ReferentOffset(), false);
+    this->operator()(ref, mirror::Reference::ReferentOffset(), false);
   }
 
   void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 657736c..4550dd7 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -1653,8 +1653,8 @@
       patch_object_visitor.VisitObject(image_roots.Ptr());
 
       ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots =
-          ObjPtr<mirror::ObjectArray<mirror::Class>>::DownCast(MakeObjPtr(
-              image_header.GetImageRoot<kWithoutReadBarrier>(ImageHeader::kClassRoots)));
+          ObjPtr<mirror::ObjectArray<mirror::Class>>::DownCast(
+              image_header.GetImageRoot<kWithoutReadBarrier>(ImageHeader::kClassRoots));
       patched_objects->Set(class_roots.Ptr());
       patch_object_visitor.VisitObject(class_roots.Ptr());
 
@@ -1682,7 +1682,7 @@
           } else if (klass == method_class || klass == constructor_class) {
             // Patch the ArtMethod* in the mirror::Executable subobject.
             ObjPtr<mirror::Executable> as_executable =
-                ObjPtr<mirror::Executable>::DownCast(MakeObjPtr(object));
+                ObjPtr<mirror::Executable>::DownCast(object);
             ArtMethod* unpatched_method = as_executable->GetArtMethod<kVerifyNone>();
             ArtMethod* patched_method = relocate_visitor(unpatched_method);
             as_executable->SetArtMethod</*kTransactionActive=*/ false,
diff --git a/runtime/handle_wrapper.h b/runtime/handle_wrapper.h
index 01252c7..a0bb772 100644
--- a/runtime/handle_wrapper.h
+++ b/runtime/handle_wrapper.h
@@ -53,7 +53,7 @@
   HandleWrapperObjPtr(const HandleWrapperObjPtr&) = default;
 
   ~HandleWrapperObjPtr() {
-    *obj_ = ObjPtr<T>(MutableHandle<T>::Get());
+    *obj_ = MutableHandle<T>::Get();
   }
 
  private:
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index 25d48c2..db116f5 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -42,7 +42,7 @@
 
 ALWAYS_INLINE static ObjPtr<mirror::Object> ObjArg(uint32_t arg)
     REQUIRES_SHARED(Locks::mutator_lock_) {
-  return ObjPtr<mirror::Object>(reinterpret_cast<mirror::Object*>(arg));
+  return reinterpret_cast<mirror::Object*>(arg);
 }
 
 static void InterpreterJni(Thread* self,
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 42609fb..a106305 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -671,8 +671,7 @@
   // and not the method that we'll dispatch to in the end.
   StackHandleScope<2> hs(self);
   Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
-      ObjPtr<mirror::MethodHandle>::DownCast(
-          MakeObjPtr(shadow_frame.GetVRegReference(vRegC)))));
+      ObjPtr<mirror::MethodHandle>::DownCast(shadow_frame.GetVRegReference(vRegC))));
   if (UNLIKELY(method_handle == nullptr)) {
     // Note that the invoke type is kVirtual here because a call to a signature
     // polymorphic method is shaped like a virtual call at the bytecode level.
@@ -1411,8 +1410,7 @@
   }
 
   // Check the call site target is not null as we're going to invoke it.
-  ObjPtr<mirror::CallSite> call_site =
-      ObjPtr<mirror::CallSite>::DownCast(ObjPtr<mirror::Object>(result.GetL()));
+  ObjPtr<mirror::CallSite> call_site = ObjPtr<mirror::CallSite>::DownCast(result.GetL());
   ObjPtr<mirror::MethodHandle> target = call_site->GetTarget();
   if (UNLIKELY(target == nullptr)) {
     ThrowClassCastException("Bootstrap method returned a CallSite with a null target");
diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc
index 8c372d4..6a8f864 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -773,7 +773,7 @@
     }
     ObjPtr<mirror::Object> obj = kIsStatic
         ? reinterpret_cast<ArtField*>(tls_value)->GetDeclaringClass()
-        : MakeObjPtr(shadow_frame->GetVRegReference(inst->VRegB_22c(inst_data)));
+        : ObjPtr<mirror::Object>(shadow_frame->GetVRegReference(inst->VRegB_22c(inst_data)));
     if (LIKELY(obj != nullptr)) {
       MterpFieldAccess<PrimType, kAccessType>(
           inst, inst_data, shadow_frame, obj, MemberOffset(offset), /* is_volatile= */ false);
diff --git a/runtime/method_handles.cc b/runtime/method_handles.cc
index dac68fa..5471d38 100644
--- a/runtime/method_handles.cc
+++ b/runtime/method_handles.cc
@@ -478,8 +478,8 @@
         // through from a transformer.
         size_t first_arg_register = operands->GetOperand(0);
         ObjPtr<mirror::EmulatedStackFrame> emulated_stack_frame(
-            ObjPtr<mirror::EmulatedStackFrame>::DownCast(MakeObjPtr(
-                shadow_frame.GetVRegReference(first_arg_register))));
+            ObjPtr<mirror::EmulatedStackFrame>::DownCast(
+                shadow_frame.GetVRegReference(first_arg_register)));
         if (!emulated_stack_frame->WriteToShadowFrame(self,
                                                       target_type,
                                                       first_dest_reg,
@@ -527,8 +527,8 @@
     StackHandleScope<2> hs(self);
     size_t first_callee_register = operands->GetOperand(0);
     Handle<mirror::EmulatedStackFrame> emulated_stack_frame(
-        hs.NewHandle(ObjPtr<mirror::EmulatedStackFrame>::DownCast(MakeObjPtr(
-            shadow_frame.GetVRegReference(first_callee_register)))));
+        hs.NewHandle(ObjPtr<mirror::EmulatedStackFrame>::DownCast(
+            shadow_frame.GetVRegReference(first_callee_register))));
     Handle<mirror::MethodType> emulated_stack_type(hs.NewHandle(emulated_stack_frame->GetType()));
     JValue local_result;
     local_result.SetJ(result->GetJ());
@@ -580,8 +580,8 @@
     // through the handle directly to the callee, instead of having to
     // instantiate a new stack frame based on the shadow frame.
     size_t first_callee_register = operands->GetOperand(0);
-    sf.Assign(ObjPtr<mirror::EmulatedStackFrame>::DownCast(MakeObjPtr(
-        shadow_frame.GetVRegReference(first_callee_register))));
+    sf.Assign(ObjPtr<mirror::EmulatedStackFrame>::DownCast(
+        shadow_frame.GetVRegReference(first_callee_register)));
   } else {
     sf.Assign(mirror::EmulatedStackFrame::CreateFromShadowFrameAndArgs(self,
                                                                        callsite_type,
diff --git a/runtime/mirror/array-alloc-inl.h b/runtime/mirror/array-alloc-inl.h
index 4250ff8..2ae4cab 100644
--- a/runtime/mirror/array-alloc-inl.h
+++ b/runtime/mirror/array-alloc-inl.h
@@ -142,16 +142,16 @@
   ObjPtr<Array> result;
   if (!kFillUsable) {
     SetLengthVisitor visitor(component_count);
-    result = ObjPtr<Array>::DownCast(MakeObjPtr(
-        heap->AllocObjectWithAllocator<kIsInstrumented, true>(self, array_class, size,
-                                                              allocator_type, visitor)));
+    result = ObjPtr<Array>::DownCast(
+        heap->AllocObjectWithAllocator<kIsInstrumented, true>(
+            self, array_class, size, allocator_type, visitor));
   } else {
     SetLengthToUsableSizeVisitor visitor(component_count,
                                          DataOffset(1U << component_size_shift).SizeValue(),
                                          component_size_shift);
-    result = ObjPtr<Array>::DownCast(MakeObjPtr(
-        heap->AllocObjectWithAllocator<kIsInstrumented, true>(self, array_class, size,
-                                                              allocator_type, visitor)));
+    result = ObjPtr<Array>::DownCast(
+        heap->AllocObjectWithAllocator<kIsInstrumented, true>(
+            self, array_class, size, allocator_type, visitor));
   }
   if (kIsDebugBuild && result != nullptr && Runtime::Current()->IsStarted()) {
     array_class = result->GetClass();  // In case the array class moved.
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index cf0fd9a..2e8ced5 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -65,8 +65,8 @@
   DCHECK(IsLoaded<kVerifyFlags>() ||
          IsErroneous<kVerifyFlags>() ||
          !Runtime::Current()->IsStarted()) << IsLoaded();
-  return ObjPtr<Class>(GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(
-      OFFSET_OF_OBJECT_MEMBER(Class, super_class_)));
+  return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(
+      OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
 }
 
 inline void Class::SetSuperClass(ObjPtr<Class> new_super_class) {
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index f916d5e..1c03fc3 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -1189,8 +1189,7 @@
     h_new_class_obj->SetClassSize(new_length_);
     // Visit all of the references to make sure there is no from space references in the native
     // roots.
-    ObjPtr<Object>(h_new_class_obj.Get())->VisitReferences(
-        ReadBarrierOnNativeRootsVisitor(), VoidFunctor());
+    h_new_class_obj->Object::VisitReferences(ReadBarrierOnNativeRootsVisitor(), VoidFunctor());
   }
 
  private:
diff --git a/runtime/mirror/emulated_stack_frame.cc b/runtime/mirror/emulated_stack_frame.cc
index f341788..cfdab8f 100644
--- a/runtime/mirror/emulated_stack_frame.cc
+++ b/runtime/mirror/emulated_stack_frame.cc
@@ -107,7 +107,7 @@
   }
 
   ALWAYS_INLINE ObjPtr<mirror::Object> GetReference() REQUIRES_SHARED(Locks::mutator_lock_) {
-    return ObjPtr<mirror::Object>(references_->Get(reference_idx_++));
+    return references_->Get(reference_idx_++);
   }
 
   ALWAYS_INLINE uint32_t Get() REQUIRES_SHARED(Locks::mutator_lock_) {
diff --git a/runtime/mirror/method.cc b/runtime/mirror/method.cc
index d7a1225..20a6979 100644
--- a/runtime/mirror/method.cc
+++ b/runtime/mirror/method.cc
@@ -30,8 +30,7 @@
   DCHECK(!method->IsConstructor()) << method->PrettyMethod();
   ObjPtr<Method> ret = ObjPtr<Method>::DownCast(GetClassRoot<Method>()->AllocObject(self));
   if (LIKELY(ret != nullptr)) {
-    ObjPtr<Executable>(ret)->
-        CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
+    ret->Executable::CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
   }
   return ret;
 }
@@ -51,8 +50,7 @@
   ObjPtr<Constructor> ret =
       ObjPtr<Constructor>::DownCast(GetClassRoot<Constructor>()->AllocObject(self));
   if (LIKELY(ret != nullptr)) {
-    ObjPtr<Executable>(ret)->
-        CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
+    ret->Executable::CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
   }
   return ret;
 }
diff --git a/runtime/mirror/method_handles_lookup.cc b/runtime/mirror/method_handles_lookup.cc
index c26948d..e0e7b06 100644
--- a/runtime/mirror/method_handles_lookup.cc
+++ b/runtime/mirror/method_handles_lookup.cc
@@ -45,7 +45,7 @@
   ArtMethod* lookup = jni::DecodeArtMethod(WellKnownClasses::java_lang_invoke_MethodHandles_lookup);
   JValue result;
   lookup->Invoke(self, nullptr, 0, &result, "L");
-  return ObjPtr<MethodHandlesLookup>::DownCast(MakeObjPtr(result.GetL()));
+  return ObjPtr<MethodHandlesLookup>::DownCast(result.GetL());
 }
 
 ObjPtr<MethodHandle> MethodHandlesLookup::FindConstructor(Thread* const self,
@@ -60,7 +60,7 @@
   };
   JValue result;
   findConstructor->Invoke(self, args, sizeof(args), &result, "LLL");
-  return ObjPtr<MethodHandle>::DownCast(MakeObjPtr(result.GetL()));
+  return ObjPtr<MethodHandle>::DownCast(result.GetL());
 }
 
 }  // namespace mirror
diff --git a/runtime/mirror/string-alloc-inl.h b/runtime/mirror/string-alloc-inl.h
index 4330235..7215c39 100644
--- a/runtime/mirror/string-alloc-inl.h
+++ b/runtime/mirror/string-alloc-inl.h
@@ -190,12 +190,12 @@
   }
 
   gc::Heap* heap = runtime->GetHeap();
-  return ObjPtr<String>::DownCast(MakeObjPtr(
+  return ObjPtr<String>::DownCast(
       heap->AllocObjectWithAllocator<kIsInstrumented, true>(self,
                                                             string_class,
                                                             alloc_size,
                                                             allocator_type,
-                                                            pre_fence_visitor)));
+                                                            pre_fence_visitor));
 }
 
 template <bool kIsInstrumented>
diff --git a/runtime/obj_ptr-inl.h b/runtime/obj_ptr-inl.h
index 6a68f14..ae13465 100644
--- a/runtime/obj_ptr-inl.h
+++ b/runtime/obj_ptr-inl.h
@@ -122,6 +122,14 @@
 }
 
 template<class MirrorType>
+template <typename SourceType>
+inline ObjPtr<MirrorType> ObjPtr<MirrorType>::DownCast(SourceType* ptr) {
+  static_assert(std::is_base_of_v<SourceType, MirrorType>,
+                "Target type must be a subtype of source type");
+  return static_cast<MirrorType*>(ptr);
+}
+
+template<class MirrorType>
 size_t HashObjPtr::operator()(const ObjPtr<MirrorType>& ptr) const {
   return std::hash<MirrorType*>()(ptr.Ptr());
 }
@@ -169,16 +177,6 @@
 }
 
 template<class MirrorType>
-static inline ObjPtr<MirrorType> MakeObjPtr(MirrorType* ptr) {
-  return ObjPtr<MirrorType>(ptr);
-}
-
-template<class MirrorType>
-static inline ObjPtr<MirrorType> MakeObjPtr(ObjPtr<MirrorType> ptr) {
-  return ObjPtr<MirrorType>(ptr);
-}
-
-template<class MirrorType>
 inline std::ostream& operator<<(std::ostream& os, ObjPtr<MirrorType> ptr) {
   // May be used for dumping bad pointers, do not use the checked version.
   return os << ptr.PtrUnchecked();
diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h
index 1f79d37..a03b67b 100644
--- a/runtime/obj_ptr.h
+++ b/runtime/obj_ptr.h
@@ -101,6 +101,10 @@
   template <typename SourceType>
   static ObjPtr<MirrorType> DownCast(ObjPtr<SourceType> ptr) REQUIRES_SHARED(Locks::mutator_lock_);
 
+  // Static function to be friendly with null pointers.
+  template <typename SourceType>
+  static ObjPtr<MirrorType> DownCast(SourceType* ptr) REQUIRES_SHARED(Locks::mutator_lock_);
+
  private:
   // Trim off high bits of thread local cookie.
   OBJPTR_INLINE static uintptr_t GetCurrentTrimedCookie();
@@ -183,12 +187,6 @@
 }
 
 template<class MirrorType>
-static OBJPTR_INLINE ObjPtr<MirrorType> MakeObjPtr(MirrorType* ptr);
-
-template<class MirrorType>
-static OBJPTR_INLINE ObjPtr<MirrorType> MakeObjPtr(ObjPtr<MirrorType> ptr);
-
-template<class MirrorType>
 OBJPTR_INLINE std::ostream& operator<<(std::ostream& os, ObjPtr<MirrorType> ptr);
 
 }  // namespace art
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index dbf40f6..0dbec85 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -767,7 +767,7 @@
 
 ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value) {
   if (src_class == Primitive::kPrimNot) {
-    return MakeObjPtr(value.GetL());
+    return value.GetL();
   }
   if (src_class == Primitive::kPrimVoid) {
     // There's no such thing as a void field, and void methods invoked via reflection return null.
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 77849a4..47c4604 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2766,7 +2766,7 @@
   }
 
   ObjPtr<mirror::PointerArray> GetTraceMethodsAndPCs() const REQUIRES_SHARED(Locks::mutator_lock_) {
-    return ObjPtr<mirror::PointerArray>::DownCast(MakeObjPtr(trace_->Get(0)));
+    return ObjPtr<mirror::PointerArray>::DownCast(trace_->Get(0));
   }
 
   mirror::ObjectArray<mirror::Object>* GetInternalStackTrace() const {
@@ -2939,7 +2939,7 @@
     // Methods and dex PC trace is element 0.
     DCHECK(decoded_traces->Get(0)->IsIntArray() || decoded_traces->Get(0)->IsLongArray());
     const ObjPtr<mirror::PointerArray> method_trace =
-        ObjPtr<mirror::PointerArray>::DownCast(MakeObjPtr(decoded_traces->Get(0)));
+        ObjPtr<mirror::PointerArray>::DownCast(decoded_traces->Get(0));
     // Prepare parameters for StackTraceElement(String cls, String method, String file, int line)
     ArtMethod* method = method_trace->GetElementPtrSize<ArtMethod*>(i, kRuntimePointerSize);
     uint32_t dex_pc = method_trace->GetElementPtrSize<uint32_t>(