1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "java_lang_reflect_Field.h"
18
19 #include "android-base/stringprintf.h"
20
21 #include "art_field-inl.h"
22 #include "class_linker.h"
23 #include "class_linker-inl.h"
24 #include "common_throws.h"
25 #include "dex_file-inl.h"
26 #include "dex_file_annotations.h"
27 #include "jni_internal.h"
28 #include "mirror/class-inl.h"
29 #include "mirror/field.h"
30 #include "reflection-inl.h"
31 #include "scoped_fast_native_object_access-inl.h"
32 #include "utils.h"
33 #include "well_known_classes.h"
34
35 namespace art {
36
37 using android::base::StringPrintf;
38
39 template<bool kIsSet>
VerifyFieldAccess(Thread * self,ObjPtr<mirror::Field> field,ObjPtr<mirror::Object> obj)40 ALWAYS_INLINE inline static bool VerifyFieldAccess(Thread* self,
41 ObjPtr<mirror::Field> field,
42 ObjPtr<mirror::Object> obj)
43 REQUIRES_SHARED(Locks::mutator_lock_) {
44 if (kIsSet && field->IsFinal()) {
45 ThrowIllegalAccessException(
46 StringPrintf("Cannot set %s field %s of class %s",
47 PrettyJavaAccessFlags(field->GetAccessFlags()).c_str(),
48 ArtField::PrettyField(field->GetArtField()).c_str(),
49 field->GetDeclaringClass() == nullptr ? "null" :
50 field->GetDeclaringClass()->PrettyClass().c_str()).c_str());
51 return false;
52 }
53 ObjPtr<mirror::Class> calling_class;
54 if (!VerifyAccess(self,
55 obj,
56 field->GetDeclaringClass(),
57 field->GetAccessFlags(),
58 &calling_class,
59 1)) {
60 ThrowIllegalAccessException(
61 StringPrintf("Class %s cannot access %s field %s of class %s",
62 calling_class == nullptr ? "null" : calling_class->PrettyClass().c_str(),
63 PrettyJavaAccessFlags(field->GetAccessFlags()).c_str(),
64 ArtField::PrettyField(field->GetArtField()).c_str(),
65 field->GetDeclaringClass() == nullptr ? "null" :
66 field->GetDeclaringClass()->PrettyClass().c_str()).c_str());
67 return false;
68 }
69 return true;
70 }
71
72 template<bool kAllowReferences>
GetFieldValue(ObjPtr<mirror::Object> o,ObjPtr<mirror::Field> f,Primitive::Type field_type,JValue * value)73 ALWAYS_INLINE inline static bool GetFieldValue(ObjPtr<mirror::Object> o,
74 ObjPtr<mirror::Field> f,
75 Primitive::Type field_type,
76 JValue* value)
77 REQUIRES_SHARED(Locks::mutator_lock_) {
78 DCHECK_EQ(value->GetJ(), INT64_C(0));
79 MemberOffset offset(f->GetOffset());
80 const bool is_volatile = f->IsVolatile();
81 switch (field_type) {
82 case Primitive::kPrimBoolean:
83 value->SetZ(is_volatile ? o->GetFieldBooleanVolatile(offset) : o->GetFieldBoolean(offset));
84 return true;
85 case Primitive::kPrimByte:
86 value->SetB(is_volatile ? o->GetFieldByteVolatile(offset) : o->GetFieldByte(offset));
87 return true;
88 case Primitive::kPrimChar:
89 value->SetC(is_volatile ? o->GetFieldCharVolatile(offset) : o->GetFieldChar(offset));
90 return true;
91 case Primitive::kPrimInt:
92 case Primitive::kPrimFloat:
93 value->SetI(is_volatile ? o->GetField32Volatile(offset) : o->GetField32(offset));
94 return true;
95 case Primitive::kPrimLong:
96 case Primitive::kPrimDouble:
97 value->SetJ(is_volatile ? o->GetField64Volatile(offset) : o->GetField64(offset));
98 return true;
99 case Primitive::kPrimShort:
100 value->SetS(is_volatile ? o->GetFieldShortVolatile(offset) : o->GetFieldShort(offset));
101 return true;
102 case Primitive::kPrimNot:
103 if (kAllowReferences) {
104 value->SetL(is_volatile ? o->GetFieldObjectVolatile<mirror::Object>(offset) :
105 o->GetFieldObject<mirror::Object>(offset));
106 return true;
107 }
108 // Else break to report an error.
109 break;
110 case Primitive::kPrimVoid:
111 // Never okay.
112 break;
113 }
114 ThrowIllegalArgumentException(
115 StringPrintf("Not a primitive field: %s",
116 ArtField::PrettyField(f->GetArtField()).c_str()).c_str());
117 return false;
118 }
119
CheckReceiver(const ScopedFastNativeObjectAccess & soa,jobject j_rcvr,ObjPtr<mirror::Field> * f,ObjPtr<mirror::Object> * class_or_rcvr)120 ALWAYS_INLINE inline static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa,
121 jobject j_rcvr,
122 ObjPtr<mirror::Field>* f,
123 ObjPtr<mirror::Object>* class_or_rcvr)
124 REQUIRES_SHARED(Locks::mutator_lock_) {
125 soa.Self()->AssertThreadSuspensionIsAllowable();
126 ObjPtr<mirror::Class> declaring_class = (*f)->GetDeclaringClass();
127 if ((*f)->IsStatic()) {
128 if (UNLIKELY(!declaring_class->IsInitialized())) {
129 StackHandleScope<2> hs(soa.Self());
130 HandleWrapperObjPtr<mirror::Field> h_f(hs.NewHandleWrapper(f));
131 HandleWrapperObjPtr<mirror::Class> h_klass(hs.NewHandleWrapper(&declaring_class));
132 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
133 if (UNLIKELY(!class_linker->EnsureInitialized(soa.Self(), h_klass, true, true))) {
134 DCHECK(soa.Self()->IsExceptionPending());
135 return false;
136 }
137 }
138 *class_or_rcvr = declaring_class;
139 return true;
140 }
141 *class_or_rcvr = soa.Decode<mirror::Object>(j_rcvr);
142 if (!VerifyObjectIsClass(*class_or_rcvr, declaring_class)) {
143 DCHECK(soa.Self()->IsExceptionPending());
144 return false;
145 }
146 return true;
147 }
148
Field_get(JNIEnv * env,jobject javaField,jobject javaObj)149 static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
150 ScopedFastNativeObjectAccess soa(env);
151 ObjPtr<mirror::Field> f = soa.Decode<mirror::Field>(javaField);
152 ObjPtr<mirror::Object> o;
153 if (!CheckReceiver(soa, javaObj, &f, &o)) {
154 DCHECK(soa.Self()->IsExceptionPending());
155 return nullptr;
156 }
157 // If field is not set to be accessible, verify it can be accessed by the caller.
158 if (!f->IsAccessible() && !VerifyFieldAccess<false>(soa.Self(), f, o)) {
159 DCHECK(soa.Self()->IsExceptionPending());
160 return nullptr;
161 }
162 // We now don't expect suspension unless an exception is thrown.
163 // Get the field's value, boxing if necessary.
164 Primitive::Type field_type = f->GetTypeAsPrimitiveType();
165 JValue value;
166 if (!GetFieldValue<true>(o, f, field_type, &value)) {
167 DCHECK(soa.Self()->IsExceptionPending());
168 return nullptr;
169 }
170 return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value));
171 }
172
173 template<Primitive::Type kPrimitiveType>
GetPrimitiveField(JNIEnv * env,jobject javaField,jobject javaObj)174 ALWAYS_INLINE inline static JValue GetPrimitiveField(JNIEnv* env,
175 jobject javaField,
176 jobject javaObj) {
177 ScopedFastNativeObjectAccess soa(env);
178 ObjPtr<mirror::Field> f = soa.Decode<mirror::Field>(javaField);
179 ObjPtr<mirror::Object> o;
180 if (!CheckReceiver(soa, javaObj, &f, &o)) {
181 DCHECK(soa.Self()->IsExceptionPending());
182 return JValue();
183 }
184
185 // If field is not set to be accessible, verify it can be accessed by the caller.
186 if (!f->IsAccessible() && !VerifyFieldAccess<false>(soa.Self(), f, o)) {
187 DCHECK(soa.Self()->IsExceptionPending());
188 return JValue();
189 }
190
191 // We now don't expect suspension unless an exception is thrown.
192 // Read the value.
193 Primitive::Type field_type = f->GetTypeAsPrimitiveType();
194 JValue field_value;
195 if (field_type == kPrimitiveType) {
196 // This if statement should get optimized out since we only pass in valid primitive types.
197 if (UNLIKELY(!GetFieldValue<false>(o, f, kPrimitiveType, &field_value))) {
198 DCHECK(soa.Self()->IsExceptionPending());
199 return JValue();
200 }
201 return field_value;
202 }
203 if (!GetFieldValue<false>(o, f, field_type, &field_value)) {
204 DCHECK(soa.Self()->IsExceptionPending());
205 return JValue();
206 }
207 // Widen it if necessary (and possible).
208 JValue wide_value;
209 if (!ConvertPrimitiveValue(false, field_type, kPrimitiveType, field_value,
210 &wide_value)) {
211 DCHECK(soa.Self()->IsExceptionPending());
212 return JValue();
213 }
214 return wide_value;
215 }
216
Field_getBoolean(JNIEnv * env,jobject javaField,jobject javaObj)217 static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
218 return GetPrimitiveField<Primitive::kPrimBoolean>(env, javaField, javaObj).GetZ();
219 }
220
Field_getByte(JNIEnv * env,jobject javaField,jobject javaObj)221 static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
222 return GetPrimitiveField<Primitive::kPrimByte>(env, javaField, javaObj).GetB();
223 }
224
Field_getChar(JNIEnv * env,jobject javaField,jobject javaObj)225 static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
226 return GetPrimitiveField<Primitive::kPrimChar>(env, javaField, javaObj).GetC();
227 }
228
Field_getDouble(JNIEnv * env,jobject javaField,jobject javaObj)229 static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
230 return GetPrimitiveField<Primitive::kPrimDouble>(env, javaField, javaObj).GetD();
231 }
232
Field_getFloat(JNIEnv * env,jobject javaField,jobject javaObj)233 static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
234 return GetPrimitiveField<Primitive::kPrimFloat>(env, javaField, javaObj).GetF();
235 }
236
Field_getInt(JNIEnv * env,jobject javaField,jobject javaObj)237 static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
238 return GetPrimitiveField<Primitive::kPrimInt>(env, javaField, javaObj).GetI();
239 }
240
Field_getLong(JNIEnv * env,jobject javaField,jobject javaObj)241 static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
242 return GetPrimitiveField<Primitive::kPrimLong>(env, javaField, javaObj).GetJ();
243 }
244
Field_getShort(JNIEnv * env,jobject javaField,jobject javaObj)245 static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
246 return GetPrimitiveField<Primitive::kPrimShort>(env, javaField, javaObj).GetS();
247 }
248
SetFieldValue(ObjPtr<mirror::Object> o,ObjPtr<mirror::Field> f,Primitive::Type field_type,bool allow_references,const JValue & new_value)249 ALWAYS_INLINE inline static void SetFieldValue(ObjPtr<mirror::Object> o,
250 ObjPtr<mirror::Field> f,
251 Primitive::Type field_type,
252 bool allow_references,
253 const JValue& new_value)
254 REQUIRES_SHARED(Locks::mutator_lock_) {
255 DCHECK(f->GetDeclaringClass()->IsInitialized());
256 MemberOffset offset(f->GetOffset());
257 const bool is_volatile = f->IsVolatile();
258 switch (field_type) {
259 case Primitive::kPrimBoolean:
260 if (is_volatile) {
261 o->SetFieldBooleanVolatile<false>(offset, new_value.GetZ());
262 } else {
263 o->SetFieldBoolean<false>(offset, new_value.GetZ());
264 }
265 break;
266 case Primitive::kPrimByte:
267 if (is_volatile) {
268 o->SetFieldBooleanVolatile<false>(offset, new_value.GetB());
269 } else {
270 o->SetFieldBoolean<false>(offset, new_value.GetB());
271 }
272 break;
273 case Primitive::kPrimChar:
274 if (is_volatile) {
275 o->SetFieldCharVolatile<false>(offset, new_value.GetC());
276 } else {
277 o->SetFieldChar<false>(offset, new_value.GetC());
278 }
279 break;
280 case Primitive::kPrimInt:
281 case Primitive::kPrimFloat:
282 if (is_volatile) {
283 o->SetField32Volatile<false>(offset, new_value.GetI());
284 } else {
285 o->SetField32<false>(offset, new_value.GetI());
286 }
287 break;
288 case Primitive::kPrimLong:
289 case Primitive::kPrimDouble:
290 if (is_volatile) {
291 o->SetField64Volatile<false>(offset, new_value.GetJ());
292 } else {
293 o->SetField64<false>(offset, new_value.GetJ());
294 }
295 break;
296 case Primitive::kPrimShort:
297 if (is_volatile) {
298 o->SetFieldShortVolatile<false>(offset, new_value.GetS());
299 } else {
300 o->SetFieldShort<false>(offset, new_value.GetS());
301 }
302 break;
303 case Primitive::kPrimNot:
304 if (allow_references) {
305 if (is_volatile) {
306 o->SetFieldObjectVolatile<false>(offset, new_value.GetL());
307 } else {
308 o->SetFieldObject<false>(offset, new_value.GetL());
309 }
310 break;
311 }
312 // Else fall through to report an error.
313 FALLTHROUGH_INTENDED;
314 case Primitive::kPrimVoid:
315 // Never okay.
316 ThrowIllegalArgumentException(
317 StringPrintf("Not a primitive field: %s",
318 ArtField::PrettyField(f->GetArtField()).c_str()).c_str());
319 return;
320 }
321 }
322
Field_set(JNIEnv * env,jobject javaField,jobject javaObj,jobject javaValue)323 static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
324 ScopedFastNativeObjectAccess soa(env);
325 ObjPtr<mirror::Field> f = soa.Decode<mirror::Field>(javaField);
326 // Check that the receiver is non-null and an instance of the field's declaring class.
327 ObjPtr<mirror::Object> o;
328 if (!CheckReceiver(soa, javaObj, &f, &o)) {
329 DCHECK(soa.Self()->IsExceptionPending());
330 return;
331 }
332 ObjPtr<mirror::Class> field_type;
333 const char* field_type_desciptor = f->GetArtField()->GetTypeDescriptor();
334 Primitive::Type field_prim_type = Primitive::GetType(field_type_desciptor[0]);
335 if (field_prim_type == Primitive::kPrimNot) {
336 field_type = f->GetType();
337 DCHECK(field_type != nullptr);
338 } else {
339 field_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(field_type_desciptor[0]);
340 }
341 // We now don't expect suspension unless an exception is thrown.
342 // Unbox the value, if necessary.
343 ObjPtr<mirror::Object> boxed_value = soa.Decode<mirror::Object>(javaValue);
344 JValue unboxed_value;
345 if (!UnboxPrimitiveForField(boxed_value,
346 field_type,
347 f->GetArtField(),
348 &unboxed_value)) {
349 DCHECK(soa.Self()->IsExceptionPending());
350 return;
351 }
352 // If field is not set to be accessible, verify it can be accessed by the caller.
353 if (!f->IsAccessible() && !VerifyFieldAccess<true>(soa.Self(), f, o)) {
354 DCHECK(soa.Self()->IsExceptionPending());
355 return;
356 }
357 SetFieldValue(o, f, field_prim_type, true, unboxed_value);
358 }
359
360 template<Primitive::Type kPrimitiveType>
SetPrimitiveField(JNIEnv * env,jobject javaField,jobject javaObj,const JValue & new_value)361 static void SetPrimitiveField(JNIEnv* env,
362 jobject javaField,
363 jobject javaObj,
364 const JValue& new_value) {
365 ScopedFastNativeObjectAccess soa(env);
366 ObjPtr<mirror::Field> f = soa.Decode<mirror::Field>(javaField);
367 ObjPtr<mirror::Object> o;
368 if (!CheckReceiver(soa, javaObj, &f, &o)) {
369 return;
370 }
371 Primitive::Type field_type = f->GetTypeAsPrimitiveType();
372 if (UNLIKELY(field_type == Primitive::kPrimNot)) {
373 ThrowIllegalArgumentException(
374 StringPrintf("Not a primitive field: %s",
375 ArtField::PrettyField(f->GetArtField()).c_str()).c_str());
376 return;
377 }
378
379 // Widen the value if necessary (and possible).
380 JValue wide_value;
381 if (!ConvertPrimitiveValue(false, kPrimitiveType, field_type, new_value, &wide_value)) {
382 DCHECK(soa.Self()->IsExceptionPending());
383 return;
384 }
385
386 // If field is not set to be accessible, verify it can be accessed by the caller.
387 if (!f->IsAccessible() && !VerifyFieldAccess<true>(soa.Self(), f, o)) {
388 DCHECK(soa.Self()->IsExceptionPending());
389 return;
390 }
391
392 // Write the value.
393 SetFieldValue(o, f, field_type, false, wide_value);
394 }
395
Field_setBoolean(JNIEnv * env,jobject javaField,jobject javaObj,jboolean z)396 static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
397 JValue value;
398 value.SetZ(z);
399 SetPrimitiveField<Primitive::kPrimBoolean>(env, javaField, javaObj, value);
400 }
401
Field_setByte(JNIEnv * env,jobject javaField,jobject javaObj,jbyte b)402 static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
403 JValue value;
404 value.SetB(b);
405 SetPrimitiveField<Primitive::kPrimByte>(env, javaField, javaObj, value);
406 }
407
Field_setChar(JNIEnv * env,jobject javaField,jobject javaObj,jchar c)408 static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
409 JValue value;
410 value.SetC(c);
411 SetPrimitiveField<Primitive::kPrimChar>(env, javaField, javaObj, value);
412 }
413
Field_setDouble(JNIEnv * env,jobject javaField,jobject javaObj,jdouble d)414 static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
415 JValue value;
416 value.SetD(d);
417 SetPrimitiveField<Primitive::kPrimDouble>(env, javaField, javaObj, value);
418 }
419
Field_setFloat(JNIEnv * env,jobject javaField,jobject javaObj,jfloat f)420 static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
421 JValue value;
422 value.SetF(f);
423 SetPrimitiveField<Primitive::kPrimFloat>(env, javaField, javaObj, value);
424 }
425
Field_setInt(JNIEnv * env,jobject javaField,jobject javaObj,jint i)426 static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
427 JValue value;
428 value.SetI(i);
429 SetPrimitiveField<Primitive::kPrimInt>(env, javaField, javaObj, value);
430 }
431
Field_setLong(JNIEnv * env,jobject javaField,jobject javaObj,jlong j)432 static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
433 JValue value;
434 value.SetJ(j);
435 SetPrimitiveField<Primitive::kPrimLong>(env, javaField, javaObj, value);
436 }
437
Field_setShort(JNIEnv * env,jobject javaField,jobject javaObj,jshort s)438 static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
439 JValue value;
440 value.SetS(s);
441 SetPrimitiveField<Primitive::kPrimShort>(env, javaField, javaObj, value);
442 }
443
Field_getAnnotationNative(JNIEnv * env,jobject javaField,jclass annotationType)444 static jobject Field_getAnnotationNative(JNIEnv* env, jobject javaField, jclass annotationType) {
445 ScopedFastNativeObjectAccess soa(env);
446 StackHandleScope<1> hs(soa.Self());
447 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
448 if (field->GetDeclaringClass()->IsProxyClass()) {
449 return nullptr;
450 }
451 Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class>(annotationType)));
452 return soa.AddLocalReference<jobject>(annotations::GetAnnotationForField(field, klass));
453 }
454
Field_getArtField(JNIEnv * env,jobject javaField)455 static jlong Field_getArtField(JNIEnv* env, jobject javaField) {
456 ScopedFastNativeObjectAccess soa(env);
457 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
458 return reinterpret_cast<jlong>(field);
459 }
460
Field_getNameInternal(JNIEnv * env,jobject javaField)461 static jobject Field_getNameInternal(JNIEnv* env, jobject javaField) {
462 ScopedFastNativeObjectAccess soa(env);
463 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
464 return soa.AddLocalReference<jobject>(
465 field->GetStringName(soa.Self(), true /* resolve */));
466 }
467
Field_getDeclaredAnnotations(JNIEnv * env,jobject javaField)468 static jobjectArray Field_getDeclaredAnnotations(JNIEnv* env, jobject javaField) {
469 ScopedFastNativeObjectAccess soa(env);
470 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
471 if (field->GetDeclaringClass()->IsProxyClass()) {
472 // Return an empty array instead of a null pointer.
473 ObjPtr<mirror::Class> annotation_array_class =
474 soa.Decode<mirror::Class>(WellKnownClasses::java_lang_annotation_Annotation__array);
475 ObjPtr<mirror::ObjectArray<mirror::Object>> empty_array =
476 mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), annotation_array_class.Ptr(), 0);
477 return soa.AddLocalReference<jobjectArray>(empty_array);
478 }
479 return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForField(field));
480 }
481
Field_getSignatureAnnotation(JNIEnv * env,jobject javaField)482 static jobjectArray Field_getSignatureAnnotation(JNIEnv* env, jobject javaField) {
483 ScopedFastNativeObjectAccess soa(env);
484 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
485 if (field->GetDeclaringClass()->IsProxyClass()) {
486 return nullptr;
487 }
488 return soa.AddLocalReference<jobjectArray>(annotations::GetSignatureAnnotationForField(field));
489 }
490
Field_isAnnotationPresentNative(JNIEnv * env,jobject javaField,jclass annotationType)491 static jboolean Field_isAnnotationPresentNative(JNIEnv* env,
492 jobject javaField,
493 jclass annotationType) {
494 ScopedFastNativeObjectAccess soa(env);
495 StackHandleScope<1> hs(soa.Self());
496 ArtField* field = soa.Decode<mirror::Field>(javaField)->GetArtField();
497 if (field->GetDeclaringClass()->IsProxyClass()) {
498 return false;
499 }
500 Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class>(annotationType)));
501 return annotations::IsFieldAnnotationPresent(field, klass);
502 }
503
504 static JNINativeMethod gMethods[] = {
505 FAST_NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"),
506 FAST_NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"),
507 FAST_NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"),
508 FAST_NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"),
509 FAST_NATIVE_METHOD(Field, getAnnotationNative,
510 "(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"),
511 FAST_NATIVE_METHOD(Field, getArtField, "()J"),
512 FAST_NATIVE_METHOD(Field, getDeclaredAnnotations, "()[Ljava/lang/annotation/Annotation;"),
513 FAST_NATIVE_METHOD(Field, getSignatureAnnotation, "()[Ljava/lang/String;"),
514 FAST_NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"),
515 FAST_NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"),
516 FAST_NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"),
517 FAST_NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"),
518 FAST_NATIVE_METHOD(Field, getNameInternal, "()Ljava/lang/String;"),
519 FAST_NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"),
520 FAST_NATIVE_METHOD(Field, isAnnotationPresentNative, "(Ljava/lang/Class;)Z"),
521 FAST_NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"),
522 FAST_NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"),
523 FAST_NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"),
524 FAST_NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"),
525 FAST_NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"),
526 FAST_NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"),
527 FAST_NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"),
528 FAST_NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"),
529 FAST_NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"),
530 };
531
register_java_lang_reflect_Field(JNIEnv * env)532 void register_java_lang_reflect_Field(JNIEnv* env) {
533 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
534 }
535
536 } // namespace art
537