From: Mathieu Chartier Date: Wed, 5 Oct 2016 20:48:41 +0000 (-0700) Subject: Change java_lang_reflect_Field.cc to use ObjPtr X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=299958fc681f591fee7ff9ae0d81bd3adfebdd2b;p=android-x86%2Fart.git Change java_lang_reflect_Field.cc to use ObjPtr Also deleted some calls to ObjPtr::Ptr and fixed formatting. Bug: 31113334 Test: test-art-host Change-Id: I951b80886b723e1beff4783f28ee7c928cb10650 --- diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc index 07b59dd90..86b42d005 100644 --- a/runtime/native/java_lang_reflect_Field.cc +++ b/runtime/native/java_lang_reflect_Field.cc @@ -31,8 +31,9 @@ namespace art { template -ALWAYS_INLINE inline static bool VerifyFieldAccess(Thread* self, mirror::Field* field, - mirror::Object* obj) +ALWAYS_INLINE inline static bool VerifyFieldAccess(Thread* self, + ObjPtr field, + ObjPtr obj) REQUIRES_SHARED(Locks::mutator_lock_) { if (kIsSet && field->IsFinal()) { ThrowIllegalAccessException( @@ -63,8 +64,10 @@ ALWAYS_INLINE inline static bool VerifyFieldAccess(Thread* self, mirror::Field* } template -ALWAYS_INLINE inline static bool GetFieldValue(mirror::Object* o, mirror::Field* f, - Primitive::Type field_type, JValue* value) +ALWAYS_INLINE inline static bool GetFieldValue(ObjPtr o, + ObjPtr f, + Primitive::Type field_type, + JValue* value) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK_EQ(value->GetJ(), INT64_C(0)); MemberOffset offset(f->GetOffset()); @@ -108,27 +111,28 @@ ALWAYS_INLINE inline static bool GetFieldValue(mirror::Object* o, mirror::Field* } ALWAYS_INLINE inline static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa, - jobject j_rcvr, mirror::Field** f, - mirror::Object** class_or_rcvr) + jobject j_rcvr, + ObjPtr* f, + ObjPtr* class_or_rcvr) REQUIRES_SHARED(Locks::mutator_lock_) { soa.Self()->AssertThreadSuspensionIsAllowable(); - mirror::Class* declaringClass = (*f)->GetDeclaringClass(); + ObjPtr declaring_class = (*f)->GetDeclaringClass(); if ((*f)->IsStatic()) { - if (UNLIKELY(!declaringClass->IsInitialized())) { + if (UNLIKELY(!declaring_class->IsInitialized())) { StackHandleScope<2> hs(soa.Self()); - HandleWrapper h_f(hs.NewHandleWrapper(f)); - HandleWrapper h_klass(hs.NewHandleWrapper(&declaringClass)); + HandleWrapperObjPtr h_f(hs.NewHandleWrapper(f)); + HandleWrapperObjPtr h_klass(hs.NewHandleWrapper(&declaring_class)); ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); if (UNLIKELY(!class_linker->EnsureInitialized(soa.Self(), h_klass, true, true))) { DCHECK(soa.Self()->IsExceptionPending()); return false; } } - *class_or_rcvr = declaringClass; + *class_or_rcvr = declaring_class; return true; } - *class_or_rcvr = soa.Decode(j_rcvr).Ptr(); - if (!VerifyObjectIsClass(MakeObjPtr(*class_or_rcvr), MakeObjPtr(declaringClass))) { + *class_or_rcvr = soa.Decode(j_rcvr); + if (!VerifyObjectIsClass(*class_or_rcvr, declaring_class)) { DCHECK(soa.Self()->IsExceptionPending()); return false; } @@ -137,8 +141,8 @@ ALWAYS_INLINE inline static bool CheckReceiver(const ScopedFastNativeObjectAcces static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) { ScopedFastNativeObjectAccess soa(env); - mirror::Field* f = soa.Decode(javaField).Ptr(); - mirror::Object* o = nullptr; + ObjPtr f = soa.Decode(javaField); + ObjPtr o; if (!CheckReceiver(soa, javaObj, &f, &o)) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; @@ -156,15 +160,16 @@ static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; } - return soa.AddLocalReference(BoxPrimitive(field_type, value).Ptr()); + return soa.AddLocalReference(BoxPrimitive(field_type, value)); } template -ALWAYS_INLINE inline static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, +ALWAYS_INLINE inline static JValue GetPrimitiveField(JNIEnv* env, + jobject javaField, jobject javaObj) { ScopedFastNativeObjectAccess soa(env); - mirror::Field* f = soa.Decode(javaField).Ptr(); - mirror::Object* o = nullptr; + ObjPtr f = soa.Decode(javaField); + ObjPtr o; if (!CheckReceiver(soa, javaObj, &f, &o)) { DCHECK(soa.Self()->IsExceptionPending()); return JValue(); @@ -234,8 +239,10 @@ static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) { return GetPrimitiveField(env, javaField, javaObj).GetS(); } -ALWAYS_INLINE inline static void SetFieldValue(mirror::Object* o, mirror::Field* f, - Primitive::Type field_type, bool allow_references, +ALWAYS_INLINE inline static void SetFieldValue(ObjPtr o, + ObjPtr f, + Primitive::Type field_type, + bool allow_references, const JValue& new_value) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(f->GetDeclaringClass()->IsInitialized()); @@ -307,14 +314,14 @@ ALWAYS_INLINE inline static void SetFieldValue(mirror::Object* o, mirror::Field* static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) { ScopedFastNativeObjectAccess soa(env); - mirror::Field* f = soa.Decode(javaField).Ptr(); + ObjPtr f = soa.Decode(javaField); // Check that the receiver is non-null and an instance of the field's declaring class. - mirror::Object* o = nullptr; + ObjPtr o; if (!CheckReceiver(soa, javaObj, &f, &o)) { DCHECK(soa.Self()->IsExceptionPending()); return; } - mirror::Class* field_type; + ObjPtr field_type; const char* field_type_desciptor = f->GetArtField()->GetTypeDescriptor(); Primitive::Type field_prim_type = Primitive::GetType(field_type_desciptor[0]); if (field_prim_type == Primitive::kPrimNot) { @@ -343,11 +350,13 @@ static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject j } template -static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, +static void SetPrimitiveField(JNIEnv* env, + jobject javaField, + jobject javaObj, const JValue& new_value) { ScopedFastNativeObjectAccess soa(env); - mirror::Field* f = soa.Decode(javaField).Ptr(); - mirror::Object* o = nullptr; + ObjPtr f = soa.Decode(javaField); + ObjPtr o; if (!CheckReceiver(soa, javaObj, &f, &o)) { return; } @@ -439,11 +448,10 @@ static jobjectArray Field_getDeclaredAnnotations(JNIEnv* env, jobject javaField) ArtField* field = soa.Decode(javaField)->GetArtField(); if (field->GetDeclaringClass()->IsProxyClass()) { // Return an empty array instead of a null pointer. - mirror::Class* annotation_array_class = - soa.Decode( - WellKnownClasses::java_lang_annotation_Annotation__array).Ptr(); - mirror::ObjectArray* empty_array = - mirror::ObjectArray::Alloc(soa.Self(), annotation_array_class, 0); + ObjPtr annotation_array_class = + soa.Decode(WellKnownClasses::java_lang_annotation_Annotation__array); + ObjPtr> empty_array = + mirror::ObjectArray::Alloc(soa.Self(), annotation_array_class.Ptr(), 0); return soa.AddLocalReference(empty_array); } return soa.AddLocalReference(annotations::GetAnnotationsForField(field)); @@ -458,7 +466,8 @@ static jobjectArray Field_getSignatureAnnotation(JNIEnv* env, jobject javaField) return soa.AddLocalReference(annotations::GetSignatureAnnotationForField(field)); } -static jboolean Field_isAnnotationPresentNative(JNIEnv* env, jobject javaField, +static jboolean Field_isAnnotationPresentNative(JNIEnv* env, + jobject javaField, jclass annotationType) { ScopedFastNativeObjectAccess soa(env); StackHandleScope<1> hs(soa.Self());