summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2019-03-28 13:18:57 +0000
committer Vladimir Marko <vmarko@google.com> 2019-03-29 09:50:00 +0000
commitd7e9bbf092b5a61048358fd54183526ef12284af (patch)
tree620cee17c499bdb23217224b0b1332408d725a6e
parentbb206de72135271e66e58576b1196f3e08d5b6fd (diff)
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
-rw-r--r--libartbase/base/common_art_test.h11
-rw-r--r--runtime/class_linker.cc12
-rw-r--r--runtime/class_linker_test.cc11
-rw-r--r--runtime/entrypoints/quick/quick_trampoline_entrypoints.cc4
-rw-r--r--runtime/gc/collector/concurrent_copying.cc2
-rw-r--r--runtime/gc/space/image_space.cc6
-rw-r--r--runtime/handle_wrapper.h2
-rw-r--r--runtime/interpreter/interpreter.cc2
-rw-r--r--runtime/interpreter/interpreter_common.cc6
-rw-r--r--runtime/interpreter/mterp/mterp.cc2
-rw-r--r--runtime/method_handles.cc12
-rw-r--r--runtime/mirror/array-alloc-inl.h12
-rw-r--r--runtime/mirror/class-inl.h4
-rw-r--r--runtime/mirror/class.cc3
-rw-r--r--runtime/mirror/emulated_stack_frame.cc2
-rw-r--r--runtime/mirror/method.cc6
-rw-r--r--runtime/mirror/method_handles_lookup.cc4
-rw-r--r--runtime/mirror/string-alloc-inl.h4
-rw-r--r--runtime/obj_ptr-inl.h18
-rw-r--r--runtime/obj_ptr.h10
-rw-r--r--runtime/reflection.cc2
-rw-r--r--runtime/thread.cc4
22 files changed, 70 insertions, 69 deletions
diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h
index bfb03c8ee6..9b23d15513 100644
--- a/libartbase/base/common_art_test.h
+++ b/libartbase/base/common_art_test.h
@@ -32,12 +32,23 @@
#include "base/unix_file/fd_file.h"
#include "dex/art_dex_file_loader.h"
#include "dex/compact_dex_level.h"
+#include "obj_ptr-inl.h"
namespace art {
using LogSeverity = android::base::LogSeverity;
using ScopedLogSeverity = android::base::ScopedLogSeverity;
+template<class MirrorType>
+static inline ObjPtr<MirrorType> MakeObjPtr(MirrorType* ptr) {
+ return ptr;
+}
+
+template<class MirrorType>
+static inline ObjPtr<MirrorType> MakeObjPtr(ObjPtr<MirrorType> ptr) {
+ return ptr;
+}
+
// OBJ pointer helpers to avoid needing .Decode everywhere.
#define EXPECT_OBJ_PTR_EQ(a, b) EXPECT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr())
#define ASSERT_OBJ_PTR_EQ(a, b) ASSERT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr())
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 80e0f462bc..b74e81f14e 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -463,8 +463,8 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b
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 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) {
}
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 @@ bool ClassLinker::AllocateIfTableMethodArrays(Thread* self,
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 c969051459..a9343e9aec 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -995,7 +995,7 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeArray) {
// 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 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeArray) {
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 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeErroneousInit) {
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 00c0a52588..2758a8d142 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2814,7 +2814,7 @@ extern "C" uint64_t artInvokePolymorphic(mirror::Object* raw_receiver, Thread* s
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 @@ extern "C" uint64_t artInvokePolymorphic(mirror::Object* raw_receiver, Thread* s
} 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 9b67030d7e..cd10e12206 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -1865,7 +1865,7 @@ class ConcurrentCopying::VerifyNoFromSpaceRefsFieldVisitor {
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 657736c28a..4550dd7e3b 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -1653,8 +1653,8 @@ class ImageSpace::BootImageLoader {
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 @@ class ImageSpace::BootImageLoader {
} 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 01252c724d..a0bb772765 100644
--- a/runtime/handle_wrapper.h
+++ b/runtime/handle_wrapper.h
@@ -53,7 +53,7 @@ class HandleWrapperObjPtr : public MutableHandle<T> {
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 25d48c2e06..db116f5a63 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -42,7 +42,7 @@ namespace interpreter {
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 42609fb0a7..a106305031 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -671,8 +671,7 @@ static bool DoMethodHandleInvokeCommon(Thread* self,
// 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 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self,
}
// 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 8c372d483e..6a8f864901 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -773,7 +773,7 @@ ALWAYS_INLINE bool MterpFieldAccessFast(Instruction* inst,
}
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 dac68fa584..5471d38751 100644
--- a/runtime/method_handles.cc
+++ b/runtime/method_handles.cc
@@ -478,8 +478,8 @@ static inline bool MethodHandleInvokeMethod(ArtMethod* called_method,
// 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 @@ static inline bool MethodHandleInvokeMethod(ArtMethod* called_method,
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 @@ static inline bool MethodHandleInvokeTransform(ArtMethod* called_method,
// 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 4250ff8c70..2ae4cab59c 100644
--- a/runtime/mirror/array-alloc-inl.h
+++ b/runtime/mirror/array-alloc-inl.h
@@ -142,16 +142,16 @@ inline ObjPtr<Array> Array::Alloc(Thread* self,
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 cf0fd9ae2a..2e8ced5e2f 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -65,8 +65,8 @@ inline ObjPtr<Class> Class::GetSuperClass() {
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 f916d5e28f..1c03fc3396 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -1189,8 +1189,7 @@ class CopyClassVisitor {
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 f341788985..cfdab8fee7 100644
--- a/runtime/mirror/emulated_stack_frame.cc
+++ b/runtime/mirror/emulated_stack_frame.cc
@@ -107,7 +107,7 @@ class EmulatedStackFrameAccessor {
}
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 d7a1225d3c..20a697977b 100644
--- a/runtime/mirror/method.cc
+++ b/runtime/mirror/method.cc
@@ -30,8 +30,7 @@ ObjPtr<Method> Method::CreateFromArtMethod(Thread* self, ArtMethod* method) {
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> Constructor::CreateFromArtMethod(Thread* self, ArtMethod* me
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 c26948d934..e0e7b06134 100644
--- a/runtime/mirror/method_handles_lookup.cc
+++ b/runtime/mirror/method_handles_lookup.cc
@@ -45,7 +45,7 @@ ObjPtr<MethodHandlesLookup> MethodHandlesLookup::GetDefault(Thread* const self)
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 @@ ObjPtr<MethodHandle> MethodHandlesLookup::FindConstructor(Thread* const self,
};
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 4330235dd9..7215c39927 100644
--- a/runtime/mirror/string-alloc-inl.h
+++ b/runtime/mirror/string-alloc-inl.h
@@ -190,12 +190,12 @@ inline ObjPtr<String> String::Alloc(Thread* self,
}
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 6a68f147de..ae13465e59 100644
--- a/runtime/obj_ptr-inl.h
+++ b/runtime/obj_ptr-inl.h
@@ -122,6 +122,14 @@ inline ObjPtr<MirrorType> ObjPtr<MirrorType>::DownCast(ObjPtr<SourceType> ptr) {
}
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 @@ operator!=(ObjPtr<MirrorType1> lhs, const MirrorType2* rhs) {
}
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 1f79d37516..a03b67bed7 100644
--- a/runtime/obj_ptr.h
+++ b/runtime/obj_ptr.h
@@ -101,6 +101,10 @@ class ObjPtr {
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 @@ OBJPTR_INLINE bool operator!=(std::nullptr_t, ObjPtr<MirrorType> ptr) {
}
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 dbf40f6a8a..0dbec85c02 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -767,7 +767,7 @@ void InvokeConstructor(const ScopedObjectAccessAlreadyRunnable& soa,
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 77849a4c24..47c46044d0 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2766,7 +2766,7 @@ class BuildInternalStackTraceVisitor : public StackVisitor {
}
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 @@ jobjectArray Thread::InternalStackTraceToStackTraceElementArray(
// 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>(