Use ObjPtr for reflection.cc/h/inl
Changed Pretty helpers to use this to reduce usage of Decode. The
eventual goal is not have almost any calls to ObjPtr::Decode.
Moved ObjPtr out of mirror namespace for convenience. Added more
PoisonObjectPointers calls in class linker, thread suspension.
Bug: 31113334
Test: test-art-host
Change-Id: I44d08db5143d95ed1b65e2f00f9749ef5cf379f7
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index af9b68f..b6260e9 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -33,6 +33,7 @@
#include "mirror/object-inl.h"
#include "mirror/object_array-inl.h"
#include "mirror/string-inl.h"
+#include "obj_ptr-inl.h"
#include "reflection.h"
#include "scoped_thread_state_change.h"
#include "scoped_fast_native_object_access.h"
@@ -669,7 +670,10 @@
caller.Assign(GetCallingClass(soa.Self(), 1));
}
if (UNLIKELY(caller.Get() != nullptr && !VerifyAccess(
- receiver.Get(), declaring_class, constructor->GetAccessFlags(), caller.Get()))) {
+ MakeObjPtr(receiver.Get()),
+ MakeObjPtr(declaring_class),
+ constructor->GetAccessFlags(),
+ MakeObjPtr(caller.Get())))) {
soa.Self()->ThrowNewExceptionF(
"Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
PrettyMethod(constructor).c_str(), PrettyClass(caller.Get()).c_str());
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index d001d0c..47c49d5 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -73,7 +73,7 @@
if (!m->IsAccessible() && !c->IsPublic()) {
// Go 2 frames back, this method is always called from newInstance0, which is called from
// Constructor.newInstance(Object... args).
- auto* caller = GetCallingClass(soa.Self(), 2);
+ ObjPtr<mirror::Class> caller = GetCallingClass(soa.Self(), 2);
// If caller is null, then we called from JNI, just avoid the check since JNI avoids most
// access checks anyways. TODO: Investigate if this the correct behavior.
if (caller != nullptr && !caller->CanAccess(c.Get())) {
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index 412445f..dab510d 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -43,9 +43,13 @@
PrettyClass(field->GetDeclaringClass()).c_str()).c_str());
return false;
}
- mirror::Class* calling_class = nullptr;
- if (!VerifyAccess(self, obj, field->GetDeclaringClass(), field->GetAccessFlags(),
- &calling_class, 1)) {
+ ObjPtr<mirror::Class> calling_class;
+ if (!VerifyAccess(self,
+ MakeObjPtr(obj),
+ MakeObjPtr(field->GetDeclaringClass()),
+ field->GetAccessFlags(),
+ &calling_class,
+ 1)) {
ThrowIllegalAccessException(
StringPrintf("Class %s cannot access %s field %s of class %s",
calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(),
@@ -124,7 +128,7 @@
return true;
}
*class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
- if (!VerifyObjectIsClass(*class_or_rcvr, declaringClass)) {
+ if (!VerifyObjectIsClass(MakeObjPtr(*class_or_rcvr), MakeObjPtr(declaringClass))) {
DCHECK(soa.Self()->IsExceptionPending());
return false;
}
@@ -152,7 +156,7 @@
DCHECK(soa.Self()->IsExceptionPending());
return nullptr;
}
- return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value));
+ return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value).Decode());
}
template<Primitive::Type kPrimitiveType>
@@ -323,7 +327,10 @@
// Unbox the value, if necessary.
mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
JValue unboxed_value;
- if (!UnboxPrimitiveForField(boxed_value, field_type, f->GetArtField(), &unboxed_value)) {
+ if (!UnboxPrimitiveForField(MakeObjPtr(boxed_value),
+ MakeObjPtr(field_type),
+ f->GetArtField(),
+ &unboxed_value)) {
DCHECK(soa.Self()->IsExceptionPending());
return;
}