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_Class.h"
18
19 #include <iostream>
20
21 #include "art_field-inl.h"
22 #include "art_method-inl.h"
23 #include "base/enums.h"
24 #include "class_linker-inl.h"
25 #include "class_root.h"
26 #include "common_throws.h"
27 #include "dex/descriptors_names.h"
28 #include "dex/dex_file-inl.h"
29 #include "dex/dex_file_annotations.h"
30 #include "dex/utf.h"
31 #include "hidden_api.h"
32 #include "jni/jni_internal.h"
33 #include "mirror/class-alloc-inl.h"
34 #include "mirror/class-inl.h"
35 #include "mirror/class_loader.h"
36 #include "mirror/field-inl.h"
37 #include "mirror/method.h"
38 #include "mirror/method_handles_lookup.h"
39 #include "mirror/object-inl.h"
40 #include "mirror/object_array-alloc-inl.h"
41 #include "mirror/object_array-inl.h"
42 #include "mirror/proxy.h"
43 #include "mirror/string-alloc-inl.h"
44 #include "mirror/string-inl.h"
45 #include "native_util.h"
46 #include "nativehelper/jni_macros.h"
47 #include "nativehelper/scoped_local_ref.h"
48 #include "nativehelper/scoped_utf_chars.h"
49 #include "nth_caller_visitor.h"
50 #include "obj_ptr-inl.h"
51 #include "reflection.h"
52 #include "reflective_handle_scope-inl.h"
53 #include "scoped_fast_native_object_access-inl.h"
54 #include "scoped_thread_state_change-inl.h"
55 #include "well_known_classes.h"
56
57 namespace art {
58
59 // Should be the same as dalvik.system.VMRuntime.PREVENT_META_REFLECTION_BLACKLIST_ACCESS.
60 // Corresponds to a bug id.
61 static constexpr uint64_t kPreventMetaReflectionBlacklistAccess = 142365358;
62
63 // Walks the stack, finds the caller of this reflective call and returns
64 // a hiddenapi AccessContext formed from its declaring class.
GetReflectionCaller(Thread * self)65 static hiddenapi::AccessContext GetReflectionCaller(Thread* self)
66 REQUIRES_SHARED(Locks::mutator_lock_) {
67 // Walk the stack and find the first frame not from java.lang.Class,
68 // java.lang.invoke or java.lang.reflect. This is very expensive.
69 // Save this till the last.
70 struct FirstExternalCallerVisitor : public StackVisitor {
71 explicit FirstExternalCallerVisitor(Thread* thread)
72 : StackVisitor(thread, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
73 caller(nullptr) {
74 }
75
76 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
77 ArtMethod *m = GetMethod();
78 if (m == nullptr) {
79 // Attached native thread. Assume this is *not* boot class path.
80 caller = nullptr;
81 return false;
82 } else if (m->IsRuntimeMethod()) {
83 // Internal runtime method, continue walking the stack.
84 return true;
85 }
86
87 ObjPtr<mirror::Class> declaring_class = m->GetDeclaringClass();
88 if (declaring_class->IsBootStrapClassLoaded()) {
89 if (declaring_class->IsClassClass()) {
90 return true;
91 }
92 // Check classes in the java.lang.invoke package. At the time of writing, the
93 // classes of interest are MethodHandles and MethodHandles.Lookup, but this
94 // is subject to change so conservatively cover the entire package.
95 // NB Static initializers within java.lang.invoke are permitted and do not
96 // need further stack inspection.
97 ObjPtr<mirror::Class> lookup_class = GetClassRoot<mirror::MethodHandlesLookup>();
98 if ((declaring_class == lookup_class || declaring_class->IsInSamePackage(lookup_class))
99 && !m->IsClassInitializer()) {
100 return true;
101 }
102 // Check for classes in the java.lang.reflect package, except for java.lang.reflect.Proxy.
103 // java.lang.reflect.Proxy does its own hidden api checks (https://r.android.com/915496),
104 // and walking over this frame would cause a null pointer dereference
105 // (e.g. in 691-hiddenapi-proxy).
106 ObjPtr<mirror::Class> proxy_class = GetClassRoot<mirror::Proxy>();
107 if (declaring_class->IsInSamePackage(proxy_class) && declaring_class != proxy_class) {
108 if (Runtime::Current()->isChangeEnabled(kPreventMetaReflectionBlacklistAccess)) {
109 return true;
110 }
111 }
112 }
113
114 caller = m;
115 return false;
116 }
117
118 ArtMethod* caller;
119 };
120
121 FirstExternalCallerVisitor visitor(self);
122 visitor.WalkStack();
123
124 // Construct AccessContext from the calling class found on the stack.
125 // If the calling class cannot be determined, e.g. unattached threads,
126 // we conservatively assume the caller is trusted.
127 ObjPtr<mirror::Class> caller = (visitor.caller == nullptr)
128 ? nullptr : visitor.caller->GetDeclaringClass();
129 return caller.IsNull() ? hiddenapi::AccessContext(/* is_trusted= */ true)
130 : hiddenapi::AccessContext(caller);
131 }
132
GetHiddenapiAccessContextFunction(Thread * self)133 static std::function<hiddenapi::AccessContext()> GetHiddenapiAccessContextFunction(Thread* self) {
134 return [=]() REQUIRES_SHARED(Locks::mutator_lock_) { return GetReflectionCaller(self); };
135 }
136
137 // Returns true if the first non-ClassClass caller up the stack should not be
138 // allowed access to `member`.
139 template<typename T>
ShouldDenyAccessToMember(T * member,Thread * self)140 ALWAYS_INLINE static bool ShouldDenyAccessToMember(T* member, Thread* self)
141 REQUIRES_SHARED(Locks::mutator_lock_) {
142 return hiddenapi::ShouldDenyAccessToMember(member,
143 GetHiddenapiAccessContextFunction(self),
144 hiddenapi::AccessMethod::kReflection);
145 }
146
147 // Returns true if a class member should be discoverable with reflection given
148 // the criteria. Some reflection calls only return public members
149 // (public_only == true), some members should be hidden from non-boot class path
150 // callers (hiddenapi_context).
151 template<typename T>
IsDiscoverable(bool public_only,const hiddenapi::AccessContext & access_context,T * member)152 ALWAYS_INLINE static bool IsDiscoverable(bool public_only,
153 const hiddenapi::AccessContext& access_context,
154 T* member)
155 REQUIRES_SHARED(Locks::mutator_lock_) {
156 if (public_only && ((member->GetAccessFlags() & kAccPublic) == 0)) {
157 return false;
158 }
159
160 return !hiddenapi::ShouldDenyAccessToMember(
161 member, access_context, hiddenapi::AccessMethod::kNone);
162 }
163
DecodeClass(const ScopedFastNativeObjectAccess & soa,jobject java_class)164 ALWAYS_INLINE static inline ObjPtr<mirror::Class> DecodeClass(
165 const ScopedFastNativeObjectAccess& soa, jobject java_class)
166 REQUIRES_SHARED(Locks::mutator_lock_) {
167 ObjPtr<mirror::Class> c = soa.Decode<mirror::Class>(java_class);
168 DCHECK(c != nullptr);
169 DCHECK(c->IsClass());
170 // TODO: we could EnsureInitialized here, rather than on every reflective get/set or invoke .
171 // For now, we conservatively preserve the old dalvik behavior. A quick "IsInitialized" check
172 // every time probably doesn't make much difference to reflection performance anyway.
173 return c;
174 }
175
176 // "name" is in "binary name" format, e.g. "dalvik.system.Debug$1".
Class_classForName(JNIEnv * env,jclass,jstring javaName,jboolean initialize,jobject javaLoader)177 static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean initialize,
178 jobject javaLoader) {
179 ScopedFastNativeObjectAccess soa(env);
180 ScopedUtfChars name(env, javaName);
181 if (name.c_str() == nullptr) {
182 return nullptr;
183 }
184
185 // We need to validate and convert the name (from x.y.z to x/y/z). This
186 // is especially handy for array types, since we want to avoid
187 // auto-generating bogus array classes.
188 if (!IsValidBinaryClassName(name.c_str())) {
189 soa.Self()->ThrowNewExceptionF("Ljava/lang/ClassNotFoundException;",
190 "Invalid name: %s", name.c_str());
191 return nullptr;
192 }
193
194 std::string descriptor(DotToDescriptor(name.c_str()));
195 StackHandleScope<2> hs(soa.Self());
196 Handle<mirror::ClassLoader> class_loader(
197 hs.NewHandle(soa.Decode<mirror::ClassLoader>(javaLoader)));
198 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
199 Handle<mirror::Class> c(
200 hs.NewHandle(class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader)));
201 if (c == nullptr) {
202 ScopedLocalRef<jthrowable> cause(env, env->ExceptionOccurred());
203 env->ExceptionClear();
204 jthrowable cnfe = reinterpret_cast<jthrowable>(
205 env->NewObject(WellKnownClasses::java_lang_ClassNotFoundException,
206 WellKnownClasses::java_lang_ClassNotFoundException_init,
207 javaName,
208 cause.get()));
209 if (cnfe != nullptr) {
210 // Make sure allocation didn't fail with an OOME.
211 env->Throw(cnfe);
212 }
213 return nullptr;
214 }
215 if (initialize) {
216 class_linker->EnsureInitialized(soa.Self(), c, true, true);
217 }
218 return soa.AddLocalReference<jclass>(c.Get());
219 }
220
Class_getPrimitiveClass(JNIEnv * env,jclass,jstring name)221 static jclass Class_getPrimitiveClass(JNIEnv* env, jclass, jstring name) {
222 ScopedFastNativeObjectAccess soa(env);
223 ObjPtr<mirror::Class> klass = mirror::Class::GetPrimitiveClass(soa.Decode<mirror::String>(name));
224 return soa.AddLocalReference<jclass>(klass);
225 }
226
Class_getNameNative(JNIEnv * env,jobject javaThis)227 static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) {
228 ScopedFastNativeObjectAccess soa(env);
229 StackHandleScope<1> hs(soa.Self());
230 ObjPtr<mirror::Class> c = DecodeClass(soa, javaThis);
231 return soa.AddLocalReference<jstring>(mirror::Class::ComputeName(hs.NewHandle(c)));
232 }
233
Class_getInterfacesInternal(JNIEnv * env,jobject javaThis)234 static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) {
235 ScopedFastNativeObjectAccess soa(env);
236 StackHandleScope<1> hs(soa.Self());
237 Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis));
238 if (klass->IsObsoleteObject()) {
239 ThrowRuntimeException("Obsolete Object!");
240 return nullptr;
241 }
242
243 if (klass->IsProxyClass()) {
244 StackHandleScope<1> hs2(soa.Self());
245 Handle<mirror::ObjectArray<mirror::Class>> interfaces =
246 hs2.NewHandle(klass->GetProxyInterfaces());
247 return soa.AddLocalReference<jobjectArray>(
248 mirror::ObjectArray<mirror::Class>::Clone(interfaces, soa.Self()));
249 }
250
251 const dex::TypeList* iface_list = klass->GetInterfaceTypeList();
252 if (iface_list == nullptr) {
253 return nullptr;
254 }
255
256 ClassLinker* linker = Runtime::Current()->GetClassLinker();
257 const uint32_t num_ifaces = iface_list->Size();
258 ObjPtr<mirror::Class> class_array_class =
259 GetClassRoot<mirror::ObjectArray<mirror::Class>>(linker);
260 ObjPtr<mirror::ObjectArray<mirror::Class>> ifaces =
261 mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_ifaces);
262 if (ifaces.IsNull()) {
263 DCHECK(soa.Self()->IsExceptionPending());
264 return nullptr;
265 }
266
267 // Check that we aren't in an active transaction, we call SetWithoutChecks
268 // with kActiveTransaction == false.
269 DCHECK(!Runtime::Current()->IsActiveTransaction());
270
271 for (uint32_t i = 0; i < num_ifaces; ++i) {
272 const dex::TypeIndex type_idx = iface_list->GetTypeItem(i).type_idx_;
273 ObjPtr<mirror::Class> interface = linker->LookupResolvedType(type_idx, klass.Get());
274 DCHECK(interface != nullptr);
275 ifaces->SetWithoutChecks<false>(i, interface);
276 }
277
278 return soa.AddLocalReference<jobjectArray>(ifaces);
279 }
280
GetDeclaredFields(Thread * self,ObjPtr<mirror::Class> klass,bool public_only,bool force_resolve)281 static ObjPtr<mirror::ObjectArray<mirror::Field>> GetDeclaredFields(
282 Thread* self,
283 ObjPtr<mirror::Class> klass,
284 bool public_only,
285 bool force_resolve) REQUIRES_SHARED(Locks::mutator_lock_) {
286 if (UNLIKELY(klass->IsObsoleteObject())) {
287 ThrowRuntimeException("Obsolete Object!");
288 return nullptr;
289 }
290 StackHandleScope<1> hs(self);
291 IterationRange<StrideIterator<ArtField>> ifields = klass->GetIFields();
292 IterationRange<StrideIterator<ArtField>> sfields = klass->GetSFields();
293 size_t array_size = klass->NumInstanceFields() + klass->NumStaticFields();
294 hiddenapi::AccessContext hiddenapi_context = GetReflectionCaller(self);
295 // Lets go subtract all the non discoverable fields.
296 for (ArtField& field : ifields) {
297 if (!IsDiscoverable(public_only, hiddenapi_context, &field)) {
298 --array_size;
299 }
300 }
301 for (ArtField& field : sfields) {
302 if (!IsDiscoverable(public_only, hiddenapi_context, &field)) {
303 --array_size;
304 }
305 }
306 size_t array_idx = 0;
307 auto object_array = hs.NewHandle(mirror::ObjectArray<mirror::Field>::Alloc(
308 self, GetClassRoot<mirror::ObjectArray<mirror::Field>>(), array_size));
309 if (object_array == nullptr) {
310 return nullptr;
311 }
312 for (ArtField& field : ifields) {
313 if (IsDiscoverable(public_only, hiddenapi_context, &field)) {
314 ObjPtr<mirror::Field> reflect_field =
315 mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, &field, force_resolve);
316 if (reflect_field == nullptr) {
317 if (kIsDebugBuild) {
318 self->AssertPendingException();
319 }
320 // Maybe null due to OOME or type resolving exception.
321 return nullptr;
322 }
323 object_array->SetWithoutChecks<false>(array_idx++, reflect_field);
324 }
325 }
326 for (ArtField& field : sfields) {
327 if (IsDiscoverable(public_only, hiddenapi_context, &field)) {
328 ObjPtr<mirror::Field> reflect_field =
329 mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, &field, force_resolve);
330 if (reflect_field == nullptr) {
331 if (kIsDebugBuild) {
332 self->AssertPendingException();
333 }
334 return nullptr;
335 }
336 object_array->SetWithoutChecks<false>(array_idx++, reflect_field);
337 }
338 }
339 DCHECK_EQ(array_idx, array_size);
340 return object_array.Get();
341 }
342
Class_getDeclaredFieldsUnchecked(JNIEnv * env,jobject javaThis,jboolean publicOnly)343 static jobjectArray Class_getDeclaredFieldsUnchecked(JNIEnv* env, jobject javaThis,
344 jboolean publicOnly) {
345 ScopedFastNativeObjectAccess soa(env);
346 return soa.AddLocalReference<jobjectArray>(
347 GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), publicOnly != JNI_FALSE, false));
348 }
349
Class_getDeclaredFields(JNIEnv * env,jobject javaThis)350 static jobjectArray Class_getDeclaredFields(JNIEnv* env, jobject javaThis) {
351 ScopedFastNativeObjectAccess soa(env);
352 return soa.AddLocalReference<jobjectArray>(
353 GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), false, true));
354 }
355
Class_getPublicDeclaredFields(JNIEnv * env,jobject javaThis)356 static jobjectArray Class_getPublicDeclaredFields(JNIEnv* env, jobject javaThis) {
357 ScopedFastNativeObjectAccess soa(env);
358 return soa.AddLocalReference<jobjectArray>(
359 GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), true, true));
360 }
361
362 // Performs a binary search through an array of fields, TODO: Is this fast enough if we don't use
363 // the dex cache for lookups? I think CompareModifiedUtf8ToUtf16AsCodePointValues should be fairly
364 // fast.
FindFieldByName(ObjPtr<mirror::String> name,LengthPrefixedArray<ArtField> * fields)365 ALWAYS_INLINE static inline ArtField* FindFieldByName(ObjPtr<mirror::String> name,
366 LengthPrefixedArray<ArtField>* fields)
367 REQUIRES_SHARED(Locks::mutator_lock_) {
368 if (fields == nullptr) {
369 return nullptr;
370 }
371 size_t low = 0;
372 size_t high = fields->size();
373 const bool is_name_compressed = name->IsCompressed();
374 const uint16_t* const data = (is_name_compressed) ? nullptr : name->GetValue();
375 const uint8_t* const data_compressed = (is_name_compressed) ? name->GetValueCompressed()
376 : nullptr;
377 const size_t length = name->GetLength();
378 while (low < high) {
379 auto mid = (low + high) / 2;
380 ArtField& field = fields->At(mid);
381 int result = 0;
382 if (is_name_compressed) {
383 size_t field_length = strlen(field.GetName());
384 size_t min_size = (length < field_length) ? length : field_length;
385 result = memcmp(field.GetName(), data_compressed, min_size);
386 if (result == 0) {
387 result = field_length - length;
388 }
389 } else {
390 result = CompareModifiedUtf8ToUtf16AsCodePointValues(field.GetName(), data, length);
391 }
392 // Alternate approach, only a few % faster at the cost of more allocations.
393 // int result = field->GetStringName(self, true)->CompareTo(name);
394 if (result < 0) {
395 low = mid + 1;
396 } else if (result > 0) {
397 high = mid;
398 } else {
399 return &field;
400 }
401 }
402 if (kIsDebugBuild) {
403 for (ArtField& field : MakeIterationRangeFromLengthPrefixedArray(fields)) {
404 CHECK_NE(field.GetName(), name->ToModifiedUtf8());
405 }
406 }
407 return nullptr;
408 }
409
GetDeclaredField(Thread * self,ObjPtr<mirror::Class> c,ObjPtr<mirror::String> name)410 ALWAYS_INLINE static inline ObjPtr<mirror::Field> GetDeclaredField(Thread* self,
411 ObjPtr<mirror::Class> c,
412 ObjPtr<mirror::String> name)
413 REQUIRES_SHARED(Locks::mutator_lock_) {
414 if (UNLIKELY(c->IsObsoleteObject())) {
415 ThrowRuntimeException("Obsolete Object!");
416 return nullptr;
417 }
418 ArtField* art_field = FindFieldByName(name, c->GetIFieldsPtr());
419 if (art_field != nullptr) {
420 return mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, art_field, true);
421 }
422 art_field = FindFieldByName(name, c->GetSFieldsPtr());
423 if (art_field != nullptr) {
424 return mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, art_field, true);
425 }
426 return nullptr;
427 }
428
GetPublicFieldRecursive(Thread * self,ObjPtr<mirror::Class> clazz,ObjPtr<mirror::String> name)429 static ObjPtr<mirror::Field> GetPublicFieldRecursive(
430 Thread* self, ObjPtr<mirror::Class> clazz, ObjPtr<mirror::String> name)
431 REQUIRES_SHARED(Locks::mutator_lock_) {
432 DCHECK(clazz != nullptr);
433 DCHECK(name != nullptr);
434 DCHECK(self != nullptr);
435
436 if (UNLIKELY(clazz->IsObsoleteObject())) {
437 ThrowRuntimeException("Obsolete Object!");
438 return nullptr;
439 }
440 StackHandleScope<2> hs(self);
441 MutableHandle<mirror::Class> h_clazz(hs.NewHandle(clazz));
442 Handle<mirror::String> h_name(hs.NewHandle(name));
443
444 // We search the current class, its direct interfaces then its superclass.
445 while (h_clazz != nullptr) {
446 ObjPtr<mirror::Field> result = GetDeclaredField(self, h_clazz.Get(), h_name.Get());
447 if ((result != nullptr) && (result->GetAccessFlags() & kAccPublic)) {
448 return result;
449 } else if (UNLIKELY(self->IsExceptionPending())) {
450 // Something went wrong. Bail out.
451 return nullptr;
452 }
453
454 uint32_t num_direct_interfaces = h_clazz->NumDirectInterfaces();
455 for (uint32_t i = 0; i < num_direct_interfaces; i++) {
456 ObjPtr<mirror::Class> iface = mirror::Class::ResolveDirectInterface(self, h_clazz, i);
457 if (UNLIKELY(iface == nullptr)) {
458 self->AssertPendingException();
459 return nullptr;
460 }
461 result = GetPublicFieldRecursive(self, iface, h_name.Get());
462 if (result != nullptr) {
463 DCHECK(result->GetAccessFlags() & kAccPublic);
464 return result;
465 } else if (UNLIKELY(self->IsExceptionPending())) {
466 // Something went wrong. Bail out.
467 return nullptr;
468 }
469 }
470
471 // We don't try the superclass if we are an interface.
472 if (h_clazz->IsInterface()) {
473 break;
474 }
475
476 // Get the next class.
477 h_clazz.Assign(h_clazz->GetSuperClass());
478 }
479 return nullptr;
480 }
481
Class_getPublicFieldRecursive(JNIEnv * env,jobject javaThis,jstring name)482 static jobject Class_getPublicFieldRecursive(JNIEnv* env, jobject javaThis, jstring name) {
483 ScopedFastNativeObjectAccess soa(env);
484 auto name_string = soa.Decode<mirror::String>(name);
485 if (UNLIKELY(name_string == nullptr)) {
486 ThrowNullPointerException("name == null");
487 return nullptr;
488 }
489
490 StackHandleScope<1> hs(soa.Self());
491 Handle<mirror::Field> field = hs.NewHandle(GetPublicFieldRecursive(
492 soa.Self(), DecodeClass(soa, javaThis), name_string));
493 if (field.Get() == nullptr || ShouldDenyAccessToMember(field->GetArtField(), soa.Self())) {
494 return nullptr;
495 }
496 return soa.AddLocalReference<jobject>(field.Get());
497 }
498
Class_getDeclaredField(JNIEnv * env,jobject javaThis,jstring name)499 static jobject Class_getDeclaredField(JNIEnv* env, jobject javaThis, jstring name) {
500 ScopedFastNativeObjectAccess soa(env);
501 StackHandleScope<3> hs(soa.Self());
502 Handle<mirror::String> h_string = hs.NewHandle(soa.Decode<mirror::String>(name));
503 if (h_string == nullptr) {
504 ThrowNullPointerException("name == null");
505 return nullptr;
506 }
507 Handle<mirror::Class> h_klass = hs.NewHandle(DecodeClass(soa, javaThis));
508 Handle<mirror::Field> result =
509 hs.NewHandle(GetDeclaredField(soa.Self(), h_klass.Get(), h_string.Get()));
510 if (result == nullptr || ShouldDenyAccessToMember(result->GetArtField(), soa.Self())) {
511 std::string name_str = h_string->ToModifiedUtf8();
512 if (name_str == "value" && h_klass->IsStringClass()) {
513 // We log the error for this specific case, as the user might just swallow the exception.
514 // This helps diagnose crashes when applications rely on the String#value field being
515 // there.
516 // Also print on the error stream to test it through run-test.
517 std::string message("The String#value field is not present on Android versions >= 6.0");
518 LOG(ERROR) << message;
519 std::cerr << message << std::endl;
520 }
521 // We may have a pending exception if we failed to resolve.
522 if (!soa.Self()->IsExceptionPending()) {
523 ThrowNoSuchFieldException(h_klass.Get(), name_str.c_str());
524 }
525 return nullptr;
526 }
527 return soa.AddLocalReference<jobject>(result.Get());
528 }
529
Class_getDeclaredConstructorInternal(JNIEnv * env,jobject javaThis,jobjectArray args)530 static jobject Class_getDeclaredConstructorInternal(
531 JNIEnv* env, jobject javaThis, jobjectArray args) {
532 ScopedFastNativeObjectAccess soa(env);
533 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
534 DCHECK(!Runtime::Current()->IsActiveTransaction());
535
536 StackHandleScope<1> hs(soa.Self());
537 ObjPtr<mirror::Class> klass = DecodeClass(soa, javaThis);
538 if (UNLIKELY(klass->IsObsoleteObject())) {
539 ThrowRuntimeException("Obsolete Object!");
540 return nullptr;
541 }
542 Handle<mirror::Constructor> result = hs.NewHandle(
543 mirror::Class::GetDeclaredConstructorInternal<kRuntimePointerSize, false>(
544 soa.Self(),
545 klass,
546 soa.Decode<mirror::ObjectArray<mirror::Class>>(args)));
547 if (result == nullptr || ShouldDenyAccessToMember(result->GetArtMethod(), soa.Self())) {
548 return nullptr;
549 }
550 return soa.AddLocalReference<jobject>(result.Get());
551 }
552
MethodMatchesConstructor(ArtMethod * m,bool public_only,const hiddenapi::AccessContext & hiddenapi_context)553 static ALWAYS_INLINE inline bool MethodMatchesConstructor(
554 ArtMethod* m,
555 bool public_only,
556 const hiddenapi::AccessContext& hiddenapi_context) REQUIRES_SHARED(Locks::mutator_lock_) {
557 DCHECK(m != nullptr);
558 return m->IsConstructor() &&
559 !m->IsStatic() &&
560 IsDiscoverable(public_only, hiddenapi_context, m);
561 }
562
Class_getDeclaredConstructorsInternal(JNIEnv * env,jobject javaThis,jboolean publicOnly)563 static jobjectArray Class_getDeclaredConstructorsInternal(
564 JNIEnv* env, jobject javaThis, jboolean publicOnly) {
565 ScopedFastNativeObjectAccess soa(env);
566 StackHandleScope<2> hs(soa.Self());
567 bool public_only = (publicOnly != JNI_FALSE);
568 hiddenapi::AccessContext hiddenapi_context = GetReflectionCaller(soa.Self());
569 Handle<mirror::Class> h_klass = hs.NewHandle(DecodeClass(soa, javaThis));
570 if (UNLIKELY(h_klass->IsObsoleteObject())) {
571 ThrowRuntimeException("Obsolete Object!");
572 return nullptr;
573 }
574 size_t constructor_count = 0;
575 // Two pass approach for speed.
576 for (auto& m : h_klass->GetDirectMethods(kRuntimePointerSize)) {
577 constructor_count += MethodMatchesConstructor(&m, public_only, hiddenapi_context) ? 1u : 0u;
578 }
579 auto h_constructors = hs.NewHandle(mirror::ObjectArray<mirror::Constructor>::Alloc(
580 soa.Self(), GetClassRoot<mirror::ObjectArray<mirror::Constructor>>(), constructor_count));
581 if (UNLIKELY(h_constructors == nullptr)) {
582 soa.Self()->AssertPendingException();
583 return nullptr;
584 }
585 constructor_count = 0;
586 for (auto& m : h_klass->GetDirectMethods(kRuntimePointerSize)) {
587 if (MethodMatchesConstructor(&m, public_only, hiddenapi_context)) {
588 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
589 DCHECK(!Runtime::Current()->IsActiveTransaction());
590 ObjPtr<mirror::Constructor> constructor =
591 mirror::Constructor::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), &m);
592 if (UNLIKELY(constructor == nullptr)) {
593 soa.Self()->AssertPendingOOMException();
594 return nullptr;
595 }
596 h_constructors->SetWithoutChecks<false>(constructor_count++, constructor);
597 }
598 }
599 return soa.AddLocalReference<jobjectArray>(h_constructors.Get());
600 }
601
Class_getDeclaredMethodInternal(JNIEnv * env,jobject javaThis,jstring name,jobjectArray args)602 static jobject Class_getDeclaredMethodInternal(JNIEnv* env, jobject javaThis,
603 jstring name, jobjectArray args) {
604 ScopedFastNativeObjectAccess soa(env);
605 StackHandleScope<1> hs(soa.Self());
606 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
607 DCHECK(!Runtime::Current()->IsActiveTransaction());
608 ObjPtr<mirror::Class> klass = DecodeClass(soa, javaThis);
609 if (UNLIKELY(klass->IsObsoleteObject())) {
610 ThrowRuntimeException("Obsolete Object!");
611 return nullptr;
612 }
613 Handle<mirror::Method> result = hs.NewHandle(
614 mirror::Class::GetDeclaredMethodInternal<kRuntimePointerSize, false>(
615 soa.Self(),
616 klass,
617 soa.Decode<mirror::String>(name),
618 soa.Decode<mirror::ObjectArray<mirror::Class>>(args),
619 GetHiddenapiAccessContextFunction(soa.Self())));
620 if (result == nullptr || ShouldDenyAccessToMember(result->GetArtMethod(), soa.Self())) {
621 return nullptr;
622 }
623 return soa.AddLocalReference<jobject>(result.Get());
624 }
625
Class_getDeclaredMethodsUnchecked(JNIEnv * env,jobject javaThis,jboolean publicOnly)626 static jobjectArray Class_getDeclaredMethodsUnchecked(JNIEnv* env, jobject javaThis,
627 jboolean publicOnly) {
628 ScopedFastNativeObjectAccess soa(env);
629 StackHandleScope<2> hs(soa.Self());
630
631 hiddenapi::AccessContext hiddenapi_context = GetReflectionCaller(soa.Self());
632 bool public_only = (publicOnly != JNI_FALSE);
633
634 Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis));
635 if (klass->IsObsoleteObject()) {
636 ThrowRuntimeException("Obsolete Object!");
637 return nullptr;
638 }
639 size_t num_methods = 0;
640 for (ArtMethod& m : klass->GetDeclaredMethods(kRuntimePointerSize)) {
641 uint32_t modifiers = m.GetAccessFlags();
642 // Add non-constructor declared methods.
643 if ((modifiers & kAccConstructor) == 0 &&
644 IsDiscoverable(public_only, hiddenapi_context, &m)) {
645 ++num_methods;
646 }
647 }
648 auto ret = hs.NewHandle(mirror::ObjectArray<mirror::Method>::Alloc(
649 soa.Self(), GetClassRoot<mirror::ObjectArray<mirror::Method>>(), num_methods));
650 if (ret == nullptr) {
651 soa.Self()->AssertPendingOOMException();
652 return nullptr;
653 }
654 num_methods = 0;
655 for (ArtMethod& m : klass->GetDeclaredMethods(kRuntimePointerSize)) {
656 uint32_t modifiers = m.GetAccessFlags();
657 if ((modifiers & kAccConstructor) == 0 &&
658 IsDiscoverable(public_only, hiddenapi_context, &m)) {
659 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
660 DCHECK(!Runtime::Current()->IsActiveTransaction());
661 ObjPtr<mirror::Method> method =
662 mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), &m);
663 if (method == nullptr) {
664 soa.Self()->AssertPendingException();
665 return nullptr;
666 }
667 ret->SetWithoutChecks<false>(num_methods++, method);
668 }
669 }
670 return soa.AddLocalReference<jobjectArray>(ret.Get());
671 }
672
Class_getDeclaredAnnotation(JNIEnv * env,jobject javaThis,jclass annotationClass)673 static jobject Class_getDeclaredAnnotation(JNIEnv* env, jobject javaThis, jclass annotationClass) {
674 ScopedFastNativeObjectAccess soa(env);
675 StackHandleScope<2> hs(soa.Self());
676 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
677 if (klass->IsObsoleteObject()) {
678 ThrowRuntimeException("Obsolete Object!");
679 return nullptr;
680 }
681
682 // Handle public contract to throw NPE if the "annotationClass" argument was null.
683 if (UNLIKELY(annotationClass == nullptr)) {
684 ThrowNullPointerException("annotationClass");
685 return nullptr;
686 }
687
688 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
689 return nullptr;
690 }
691 Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationClass)));
692 return soa.AddLocalReference<jobject>(
693 annotations::GetAnnotationForClass(klass, annotation_class));
694 }
695
Class_getDeclaredAnnotations(JNIEnv * env,jobject javaThis)696 static jobjectArray Class_getDeclaredAnnotations(JNIEnv* env, jobject javaThis) {
697 ScopedFastNativeObjectAccess soa(env);
698 StackHandleScope<1> hs(soa.Self());
699 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
700 if (klass->IsObsoleteObject()) {
701 ThrowRuntimeException("Obsolete Object!");
702 return nullptr;
703 }
704 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
705 // Return an empty array instead of a null pointer.
706 ObjPtr<mirror::Class> annotation_array_class =
707 soa.Decode<mirror::Class>(WellKnownClasses::java_lang_annotation_Annotation__array);
708 ObjPtr<mirror::ObjectArray<mirror::Object>> empty_array =
709 mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(),
710 annotation_array_class,
711 /* length= */ 0);
712 return soa.AddLocalReference<jobjectArray>(empty_array);
713 }
714 return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForClass(klass));
715 }
716
Class_getDeclaredClasses(JNIEnv * env,jobject javaThis)717 static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) {
718 ScopedFastNativeObjectAccess soa(env);
719 StackHandleScope<1> hs(soa.Self());
720 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
721 if (klass->IsObsoleteObject()) {
722 ThrowRuntimeException("Obsolete Object!");
723 return nullptr;
724 }
725 ObjPtr<mirror::ObjectArray<mirror::Class>> classes = nullptr;
726 if (!klass->IsProxyClass() && klass->GetDexCache() != nullptr) {
727 classes = annotations::GetDeclaredClasses(klass);
728 }
729 if (classes == nullptr) {
730 // Return an empty array instead of a null pointer.
731 if (soa.Self()->IsExceptionPending()) {
732 // Pending exception from GetDeclaredClasses.
733 return nullptr;
734 }
735 ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
736 DCHECK(class_array_class != nullptr);
737 ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array =
738 mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0);
739 return soa.AddLocalReference<jobjectArray>(empty_array);
740 }
741 return soa.AddLocalReference<jobjectArray>(classes);
742 }
743
Class_getEnclosingClass(JNIEnv * env,jobject javaThis)744 static jclass Class_getEnclosingClass(JNIEnv* env, jobject javaThis) {
745 ScopedFastNativeObjectAccess soa(env);
746 StackHandleScope<1> hs(soa.Self());
747 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
748 if (klass->IsObsoleteObject()) {
749 ThrowRuntimeException("Obsolete Object!");
750 return nullptr;
751 }
752 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
753 return nullptr;
754 }
755 return soa.AddLocalReference<jclass>(annotations::GetEnclosingClass(klass));
756 }
757
Class_getEnclosingConstructorNative(JNIEnv * env,jobject javaThis)758 static jobject Class_getEnclosingConstructorNative(JNIEnv* env, jobject javaThis) {
759 ScopedFastNativeObjectAccess soa(env);
760 StackHandleScope<1> hs(soa.Self());
761 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
762 if (klass->IsObsoleteObject()) {
763 ThrowRuntimeException("Obsolete Object!");
764 return nullptr;
765 }
766 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
767 return nullptr;
768 }
769 ObjPtr<mirror::Object> method = annotations::GetEnclosingMethod(klass);
770 if (method != nullptr) {
771 if (GetClassRoot<mirror::Constructor>() == method->GetClass()) {
772 return soa.AddLocalReference<jobject>(method);
773 }
774 }
775 return nullptr;
776 }
777
Class_getEnclosingMethodNative(JNIEnv * env,jobject javaThis)778 static jobject Class_getEnclosingMethodNative(JNIEnv* env, jobject javaThis) {
779 ScopedFastNativeObjectAccess soa(env);
780 StackHandleScope<1> hs(soa.Self());
781 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
782 if (klass->IsObsoleteObject()) {
783 ThrowRuntimeException("Obsolete Object!");
784 return nullptr;
785 }
786 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
787 return nullptr;
788 }
789 ObjPtr<mirror::Object> method = annotations::GetEnclosingMethod(klass);
790 if (method != nullptr) {
791 if (GetClassRoot<mirror::Method>() == method->GetClass()) {
792 return soa.AddLocalReference<jobject>(method);
793 }
794 }
795 return nullptr;
796 }
797
Class_getInnerClassFlags(JNIEnv * env,jobject javaThis,jint defaultValue)798 static jint Class_getInnerClassFlags(JNIEnv* env, jobject javaThis, jint defaultValue) {
799 ScopedFastNativeObjectAccess soa(env);
800 StackHandleScope<1> hs(soa.Self());
801 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
802 if (klass->IsObsoleteObject()) {
803 ThrowRuntimeException("Obsolete Object!");
804 return 0;
805 }
806 return mirror::Class::GetInnerClassFlags(klass, defaultValue);
807 }
808
Class_getInnerClassName(JNIEnv * env,jobject javaThis)809 static jstring Class_getInnerClassName(JNIEnv* env, jobject javaThis) {
810 ScopedFastNativeObjectAccess soa(env);
811 StackHandleScope<1> hs(soa.Self());
812 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
813 if (klass->IsObsoleteObject()) {
814 ThrowRuntimeException("Obsolete Object!");
815 return nullptr;
816 }
817 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
818 return nullptr;
819 }
820 ObjPtr<mirror::String> class_name = nullptr;
821 if (!annotations::GetInnerClass(klass, &class_name)) {
822 return nullptr;
823 }
824 return soa.AddLocalReference<jstring>(class_name);
825 }
826
Class_getSignatureAnnotation(JNIEnv * env,jobject javaThis)827 static jobjectArray Class_getSignatureAnnotation(JNIEnv* env, jobject javaThis) {
828 ScopedFastNativeObjectAccess soa(env);
829 StackHandleScope<1> hs(soa.Self());
830 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
831 if (klass->IsObsoleteObject()) {
832 ThrowRuntimeException("Obsolete Object!");
833 return nullptr;
834 }
835 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
836 return nullptr;
837 }
838 return soa.AddLocalReference<jobjectArray>(
839 annotations::GetSignatureAnnotationForClass(klass));
840 }
841
Class_isAnonymousClass(JNIEnv * env,jobject javaThis)842 static jboolean Class_isAnonymousClass(JNIEnv* env, jobject javaThis) {
843 ScopedFastNativeObjectAccess soa(env);
844 StackHandleScope<1> hs(soa.Self());
845 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
846 if (klass->IsObsoleteObject()) {
847 ThrowRuntimeException("Obsolete Object!");
848 return 0;
849 }
850 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
851 return false;
852 }
853 ObjPtr<mirror::String> class_name = nullptr;
854 if (!annotations::GetInnerClass(klass, &class_name)) {
855 return false;
856 }
857 return class_name == nullptr;
858 }
859
Class_isDeclaredAnnotationPresent(JNIEnv * env,jobject javaThis,jclass annotationType)860 static jboolean Class_isDeclaredAnnotationPresent(JNIEnv* env, jobject javaThis,
861 jclass annotationType) {
862 ScopedFastNativeObjectAccess soa(env);
863 StackHandleScope<2> hs(soa.Self());
864 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
865 if (klass->IsObsoleteObject()) {
866 ThrowRuntimeException("Obsolete Object!");
867 return false;
868 }
869 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
870 return false;
871 }
872 Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationType)));
873 return annotations::IsClassAnnotationPresent(klass, annotation_class);
874 }
875
Class_getDeclaringClass(JNIEnv * env,jobject javaThis)876 static jclass Class_getDeclaringClass(JNIEnv* env, jobject javaThis) {
877 ScopedFastNativeObjectAccess soa(env);
878 StackHandleScope<1> hs(soa.Self());
879 Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
880 if (klass->IsObsoleteObject()) {
881 ThrowRuntimeException("Obsolete Object!");
882 return nullptr;
883 }
884 if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
885 return nullptr;
886 }
887 // Return null for anonymous classes.
888 if (Class_isAnonymousClass(env, javaThis)) {
889 return nullptr;
890 }
891 return soa.AddLocalReference<jclass>(annotations::GetDeclaringClass(klass));
892 }
893
Class_newInstance(JNIEnv * env,jobject javaThis)894 static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
895 ScopedFastNativeObjectAccess soa(env);
896 StackHandleScope<4> hs(soa.Self());
897 Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis));
898 if (klass->IsObsoleteObject()) {
899 ThrowRuntimeException("Obsolete Object!");
900 return nullptr;
901 }
902 if (UNLIKELY(klass->GetPrimitiveType() != 0 || klass->IsInterface() || klass->IsArrayClass() ||
903 klass->IsAbstract())) {
904 soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
905 "%s cannot be instantiated",
906 klass->PrettyClass().c_str());
907 return nullptr;
908 }
909 auto caller = hs.NewHandle<mirror::Class>(nullptr);
910 // Verify that we can access the class.
911 if (!klass->IsPublic()) {
912 caller.Assign(GetCallingClass(soa.Self(), 1));
913 if (caller != nullptr && !caller->CanAccess(klass.Get())) {
914 soa.Self()->ThrowNewExceptionF(
915 "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
916 klass->PrettyClass().c_str(), caller->PrettyClass().c_str());
917 return nullptr;
918 }
919 }
920 StackArtMethodHandleScope<1> mhs(soa.Self());
921 ReflectiveHandle<ArtMethod> constructor(mhs.NewMethodHandle(klass->GetDeclaredConstructor(
922 soa.Self(), ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), kRuntimePointerSize)));
923 if (UNLIKELY(constructor == nullptr) || ShouldDenyAccessToMember(constructor.Get(), soa.Self())) {
924 soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
925 "%s has no zero argument constructor",
926 klass->PrettyClass().c_str());
927 return nullptr;
928 }
929 // Invoke the string allocator to return an empty string for the string class.
930 if (klass->IsStringClass()) {
931 gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
932 ObjPtr<mirror::Object> obj = mirror::String::AllocEmptyString(soa.Self(), allocator_type);
933 if (UNLIKELY(soa.Self()->IsExceptionPending())) {
934 return nullptr;
935 } else {
936 return soa.AddLocalReference<jobject>(obj);
937 }
938 }
939 auto receiver = hs.NewHandle(klass->AllocObject(soa.Self()));
940 if (UNLIKELY(receiver == nullptr)) {
941 soa.Self()->AssertPendingOOMException();
942 return nullptr;
943 }
944 // Verify that we can access the constructor.
945 ObjPtr<mirror::Class> declaring_class = constructor->GetDeclaringClass();
946 if (!constructor->IsPublic()) {
947 if (caller == nullptr) {
948 caller.Assign(GetCallingClass(soa.Self(), 1));
949 }
950 if (UNLIKELY(caller != nullptr && !VerifyAccess(receiver.Get(),
951 declaring_class,
952 constructor->GetAccessFlags(),
953 caller.Get()))) {
954 soa.Self()->ThrowNewExceptionF(
955 "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
956 constructor->PrettyMethod().c_str(), caller->PrettyClass().c_str());
957 return nullptr;
958 }
959 }
960 // Ensure that we are initialized.
961 if (UNLIKELY(!declaring_class->IsVisiblyInitialized())) {
962 Thread* self = soa.Self();
963 Handle<mirror::Class> h_class = hs.NewHandle(declaring_class);
964 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
965 self, h_class, /*can_init_fields=*/ true, /*can_init_parents=*/ true))) {
966 DCHECK(self->IsExceptionPending());
967 return nullptr;
968 }
969 DCHECK(h_class->IsInitializing());
970 }
971 // Invoke the constructor.
972 JValue result;
973 uint32_t args[1] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(receiver.Get())) };
974 constructor->Invoke(soa.Self(), args, sizeof(args), &result, "V");
975 if (UNLIKELY(soa.Self()->IsExceptionPending())) {
976 return nullptr;
977 }
978 // Constructors are ()V methods, so we shouldn't touch the result of InvokeMethod.
979 return soa.AddLocalReference<jobject>(receiver.Get());
980 }
981
982 static JNINativeMethod gMethods[] = {
983 FAST_NATIVE_METHOD(Class, classForName,
984 "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"),
985 FAST_NATIVE_METHOD(Class, getDeclaredAnnotation,
986 "(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"),
987 FAST_NATIVE_METHOD(Class, getDeclaredAnnotations, "()[Ljava/lang/annotation/Annotation;"),
988 FAST_NATIVE_METHOD(Class, getDeclaredClasses, "()[Ljava/lang/Class;"),
989 FAST_NATIVE_METHOD(Class, getDeclaredConstructorInternal,
990 "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"),
991 FAST_NATIVE_METHOD(Class, getDeclaredConstructorsInternal, "(Z)[Ljava/lang/reflect/Constructor;"),
992 FAST_NATIVE_METHOD(Class, getDeclaredField, "(Ljava/lang/String;)Ljava/lang/reflect/Field;"),
993 FAST_NATIVE_METHOD(Class, getPublicFieldRecursive, "(Ljava/lang/String;)Ljava/lang/reflect/Field;"),
994 FAST_NATIVE_METHOD(Class, getDeclaredFields, "()[Ljava/lang/reflect/Field;"),
995 FAST_NATIVE_METHOD(Class, getDeclaredFieldsUnchecked, "(Z)[Ljava/lang/reflect/Field;"),
996 FAST_NATIVE_METHOD(Class, getDeclaredMethodInternal,
997 "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"),
998 FAST_NATIVE_METHOD(Class, getDeclaredMethodsUnchecked,
999 "(Z)[Ljava/lang/reflect/Method;"),
1000 FAST_NATIVE_METHOD(Class, getDeclaringClass, "()Ljava/lang/Class;"),
1001 FAST_NATIVE_METHOD(Class, getEnclosingClass, "()Ljava/lang/Class;"),
1002 FAST_NATIVE_METHOD(Class, getEnclosingConstructorNative, "()Ljava/lang/reflect/Constructor;"),
1003 FAST_NATIVE_METHOD(Class, getEnclosingMethodNative, "()Ljava/lang/reflect/Method;"),
1004 FAST_NATIVE_METHOD(Class, getInnerClassFlags, "(I)I"),
1005 FAST_NATIVE_METHOD(Class, getInnerClassName, "()Ljava/lang/String;"),
1006 FAST_NATIVE_METHOD(Class, getInterfacesInternal, "()[Ljava/lang/Class;"),
1007 FAST_NATIVE_METHOD(Class, getPrimitiveClass, "(Ljava/lang/String;)Ljava/lang/Class;"),
1008 FAST_NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"),
1009 FAST_NATIVE_METHOD(Class, getPublicDeclaredFields, "()[Ljava/lang/reflect/Field;"),
1010 FAST_NATIVE_METHOD(Class, getSignatureAnnotation, "()[Ljava/lang/String;"),
1011 FAST_NATIVE_METHOD(Class, isAnonymousClass, "()Z"),
1012 FAST_NATIVE_METHOD(Class, isDeclaredAnnotationPresent, "(Ljava/lang/Class;)Z"),
1013 FAST_NATIVE_METHOD(Class, newInstance, "()Ljava/lang/Object;"),
1014 };
1015
register_java_lang_Class(JNIEnv * env)1016 void register_java_lang_Class(JNIEnv* env) {
1017 REGISTER_NATIVE_METHODS("java/lang/Class");
1018 }
1019
1020 } // namespace art
1021