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