Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 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 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 17 | #include "java_lang_Class.h" |
| 18 | |
Nicolas Geoffray | 0e7fa6b | 2016-01-13 15:28:58 +0000 | [diff] [blame] | 19 | #include <iostream> |
| 20 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 21 | #include "art_field-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 22 | #include "base/enums.h" |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 23 | #include "class_linker.h" |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 24 | #include "common_throws.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 26 | #include "dex_file_annotations.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 27 | #include "jni_internal.h" |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 28 | #include "nth_caller_visitor.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "mirror/class_loader.h" |
Hiroshi Yamauchi | 02d2f29 | 2015-04-03 13:35:16 -0700 | [diff] [blame] | 31 | #include "mirror/field-inl.h" |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 32 | #include "mirror/method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "mirror/object-inl.h" |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 34 | #include "mirror/object_array-inl.h" |
| 35 | #include "mirror/string-inl.h" |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 36 | #include "obj_ptr-inl.h" |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 37 | #include "reflection.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 38 | #include "scoped_thread_state_change-inl.h" |
| 39 | #include "scoped_fast_native_object_access-inl.h" |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 40 | #include "ScopedLocalRef.h" |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 41 | #include "ScopedUtfChars.h" |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 42 | #include "utf.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 43 | #include "well_known_classes.h" |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 44 | |
| 45 | namespace art { |
| 46 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 47 | ALWAYS_INLINE static inline ObjPtr<mirror::Class> DecodeClass( |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 48 | const ScopedFastNativeObjectAccess& soa, jobject java_class) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 49 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 50 | ObjPtr<mirror::Class> c = soa.Decode<mirror::Class>(java_class); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 51 | DCHECK(c != nullptr); |
Elliott Hughes | 1521693 | 2012-03-21 21:53:06 -0700 | [diff] [blame] | 52 | DCHECK(c->IsClass()); |
Elliott Hughes | 923e8b8 | 2012-03-23 11:44:07 -0700 | [diff] [blame] | 53 | // TODO: we could EnsureInitialized here, rather than on every reflective get/set or invoke . |
| 54 | // For now, we conservatively preserve the old dalvik behavior. A quick "IsInitialized" check |
| 55 | // every time probably doesn't make much difference to reflection performance anyway. |
| 56 | return c; |
Elliott Hughes | 1521693 | 2012-03-21 21:53:06 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 59 | // "name" is in "binary name" format, e.g. "dalvik.system.Debug$1". |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 60 | static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean initialize, |
| 61 | jobject javaLoader) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 62 | ScopedFastNativeObjectAccess soa(env); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 63 | ScopedUtfChars name(env, javaName); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 64 | if (name.c_str() == nullptr) { |
| 65 | return nullptr; |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // We need to validate and convert the name (from x.y.z to x/y/z). This |
| 69 | // is especially handy for array types, since we want to avoid |
| 70 | // auto-generating bogus array classes. |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 71 | if (!IsValidBinaryClassName(name.c_str())) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 72 | soa.Self()->ThrowNewExceptionF("Ljava/lang/ClassNotFoundException;", |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 73 | "Invalid name: %s", name.c_str()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 74 | return nullptr; |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | std::string descriptor(DotToDescriptor(name.c_str())); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 78 | StackHandleScope<2> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 79 | Handle<mirror::ClassLoader> class_loader( |
| 80 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(javaLoader))); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 81 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 82 | Handle<mirror::Class> c( |
| 83 | hs.NewHandle(class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 84 | if (c == nullptr) { |
Elliott Hughes | 844f9a0 | 2012-01-24 20:19:58 -0800 | [diff] [blame] | 85 | ScopedLocalRef<jthrowable> cause(env, env->ExceptionOccurred()); |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 86 | env->ExceptionClear(); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 87 | jthrowable cnfe = reinterpret_cast<jthrowable>( |
| 88 | env->NewObject(WellKnownClasses::java_lang_ClassNotFoundException, |
| 89 | WellKnownClasses::java_lang_ClassNotFoundException_init, |
| 90 | javaName, |
| 91 | cause.get())); |
Ian Rogers | c114b5f | 2014-07-21 08:55:01 -0700 | [diff] [blame] | 92 | if (cnfe != nullptr) { |
| 93 | // Make sure allocation didn't fail with an OOME. |
| 94 | env->Throw(cnfe); |
| 95 | } |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 96 | return nullptr; |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 97 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 98 | if (initialize) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 99 | class_linker->EnsureInitialized(soa.Self(), c, true, true); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 100 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 101 | return soa.AddLocalReference<jclass>(c.Get()); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 104 | static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 105 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 106 | StackHandleScope<1> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 107 | ObjPtr<mirror::Class> c = DecodeClass(soa, javaThis); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 108 | return soa.AddLocalReference<jstring>(mirror::Class::ComputeName(hs.NewHandle(c))); |
Elliott Hughes | 6bdc3b2 | 2011-09-16 19:24:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Elliott Hughes | 2ed52c4 | 2012-03-21 16:56:56 -0700 | [diff] [blame] | 111 | static jobjectArray Class_getProxyInterfaces(JNIEnv* env, jobject javaThis) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 112 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 113 | ObjPtr<mirror::Class> c = DecodeClass(soa, javaThis); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 114 | return soa.AddLocalReference<jobjectArray>(c->GetInterfaces()->Clone(soa.Self())); |
Elliott Hughes | 2ed52c4 | 2012-03-21 16:56:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 117 | static mirror::ObjectArray<mirror::Field>* GetDeclaredFields( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 118 | Thread* self, ObjPtr<mirror::Class> klass, bool public_only, bool force_resolve) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 119 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 120 | StackHandleScope<1> hs(self); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 121 | IterationRange<StrideIterator<ArtField>> ifields = klass->GetIFields(); |
| 122 | IterationRange<StrideIterator<ArtField>> sfields = klass->GetSFields(); |
| 123 | size_t array_size = klass->NumInstanceFields() + klass->NumStaticFields(); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 124 | if (public_only) { |
| 125 | // Lets go subtract all the non public fields. |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 126 | for (ArtField& field : ifields) { |
| 127 | if (!field.IsPublic()) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 128 | --array_size; |
| 129 | } |
| 130 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 131 | for (ArtField& field : sfields) { |
| 132 | if (!field.IsPublic()) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 133 | --array_size; |
| 134 | } |
| 135 | } |
| 136 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 137 | size_t array_idx = 0; |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 138 | auto object_array = hs.NewHandle(mirror::ObjectArray<mirror::Field>::Alloc( |
| 139 | self, mirror::Field::ArrayClass(), array_size)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 140 | if (object_array == nullptr) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 141 | return nullptr; |
| 142 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 143 | for (ArtField& field : ifields) { |
| 144 | if (!public_only || field.IsPublic()) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 145 | auto* reflect_field = mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, |
| 146 | &field, |
| 147 | force_resolve); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 148 | if (reflect_field == nullptr) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 149 | if (kIsDebugBuild) { |
| 150 | self->AssertPendingException(); |
| 151 | } |
| 152 | // Maybe null due to OOME or type resolving exception. |
| 153 | return nullptr; |
| 154 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 155 | object_array->SetWithoutChecks<false>(array_idx++, reflect_field); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 158 | for (ArtField& field : sfields) { |
| 159 | if (!public_only || field.IsPublic()) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 160 | auto* reflect_field = mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, |
| 161 | &field, |
| 162 | force_resolve); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 163 | if (reflect_field == nullptr) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 164 | if (kIsDebugBuild) { |
| 165 | self->AssertPendingException(); |
| 166 | } |
| 167 | return nullptr; |
| 168 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 169 | object_array->SetWithoutChecks<false>(array_idx++, reflect_field); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 172 | DCHECK_EQ(array_idx, array_size); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 173 | return object_array.Get(); |
| 174 | } |
| 175 | |
| 176 | static jobjectArray Class_getDeclaredFieldsUnchecked(JNIEnv* env, jobject javaThis, |
| 177 | jboolean publicOnly) { |
| 178 | ScopedFastNativeObjectAccess soa(env); |
| 179 | return soa.AddLocalReference<jobjectArray>( |
| 180 | GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), publicOnly != JNI_FALSE, false)); |
| 181 | } |
| 182 | |
| 183 | static jobjectArray Class_getDeclaredFields(JNIEnv* env, jobject javaThis) { |
| 184 | ScopedFastNativeObjectAccess soa(env); |
| 185 | return soa.AddLocalReference<jobjectArray>( |
| 186 | GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), false, true)); |
| 187 | } |
| 188 | |
| 189 | static jobjectArray Class_getPublicDeclaredFields(JNIEnv* env, jobject javaThis) { |
| 190 | ScopedFastNativeObjectAccess soa(env); |
| 191 | return soa.AddLocalReference<jobjectArray>( |
| 192 | GetDeclaredFields(soa.Self(), DecodeClass(soa, javaThis), true, true)); |
| 193 | } |
| 194 | |
| 195 | // Performs a binary search through an array of fields, TODO: Is this fast enough if we don't use |
| 196 | // the dex cache for lookups? I think CompareModifiedUtf8ToUtf16AsCodePointValues should be fairly |
| 197 | // fast. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 198 | ALWAYS_INLINE static inline ArtField* FindFieldByName(ObjPtr<mirror::String> name, |
| 199 | LengthPrefixedArray<ArtField>* fields) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 200 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 201 | if (fields == nullptr) { |
| 202 | return nullptr; |
| 203 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 204 | size_t low = 0; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 205 | size_t high = fields->size(); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 206 | const bool is_name_compressed = name->IsCompressed(); |
| 207 | const uint16_t* const data = (is_name_compressed) ? nullptr : name->GetValue(); |
| 208 | const uint8_t* const data_compressed = (is_name_compressed) ? name->GetValueCompressed() |
| 209 | : nullptr; |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 210 | const size_t length = name->GetLength(); |
| 211 | while (low < high) { |
| 212 | auto mid = (low + high) / 2; |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 213 | ArtField& field = fields->At(mid); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 214 | int result = 0; |
| 215 | if (is_name_compressed) { |
| 216 | size_t field_length = strlen(field.GetName()); |
| 217 | size_t min_size = (length < field_length) ? length : field_length; |
| 218 | result = memcmp(field.GetName(), data_compressed, min_size); |
| 219 | if (result == 0) { |
| 220 | result = field_length - length; |
| 221 | } |
| 222 | } else { |
| 223 | result = CompareModifiedUtf8ToUtf16AsCodePointValues(field.GetName(), data, length); |
| 224 | } |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 225 | // Alternate approach, only a few % faster at the cost of more allocations. |
| 226 | // int result = field->GetStringName(self, true)->CompareTo(name); |
| 227 | if (result < 0) { |
| 228 | low = mid + 1; |
| 229 | } else if (result > 0) { |
| 230 | high = mid; |
| 231 | } else { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 232 | return &field; |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | if (kIsDebugBuild) { |
Vladimir Marko | cf36d49 | 2015-08-12 19:27:26 +0100 | [diff] [blame] | 236 | for (ArtField& field : MakeIterationRangeFromLengthPrefixedArray(fields)) { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 237 | CHECK_NE(field.GetName(), name->ToModifiedUtf8()); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | return nullptr; |
| 241 | } |
| 242 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 243 | ALWAYS_INLINE static inline mirror::Field* GetDeclaredField(Thread* self, |
| 244 | ObjPtr<mirror::Class> c, |
| 245 | ObjPtr<mirror::String> name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 246 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 247 | ArtField* art_field = FindFieldByName(name, c->GetIFieldsPtr()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 248 | if (art_field != nullptr) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 249 | return mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, art_field, true); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 250 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 251 | art_field = FindFieldByName(name, c->GetSFieldsPtr()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 252 | if (art_field != nullptr) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 253 | return mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, art_field, true); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 254 | } |
| 255 | return nullptr; |
| 256 | } |
| 257 | |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 258 | static mirror::Field* GetPublicFieldRecursive( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 259 | Thread* self, ObjPtr<mirror::Class> clazz, ObjPtr<mirror::String> name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 260 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 261 | DCHECK(clazz != nullptr); |
| 262 | DCHECK(name != nullptr); |
| 263 | DCHECK(self != nullptr); |
| 264 | |
Nicolas Geoffray | a96f316 | 2016-05-03 14:04:02 +0100 | [diff] [blame] | 265 | StackHandleScope<2> hs(self); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 266 | MutableHandle<mirror::Class> h_clazz(hs.NewHandle(clazz)); |
Nicolas Geoffray | a96f316 | 2016-05-03 14:04:02 +0100 | [diff] [blame] | 267 | Handle<mirror::String> h_name(hs.NewHandle(name)); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 268 | |
| 269 | // We search the current class, its direct interfaces then its superclass. |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 270 | while (h_clazz != nullptr) { |
Nicolas Geoffray | a96f316 | 2016-05-03 14:04:02 +0100 | [diff] [blame] | 271 | mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), h_name.Get()); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 272 | if ((result != nullptr) && (result->GetAccessFlags() & kAccPublic)) { |
| 273 | return result; |
| 274 | } else if (UNLIKELY(self->IsExceptionPending())) { |
| 275 | // Something went wrong. Bail out. |
| 276 | return nullptr; |
| 277 | } |
| 278 | |
| 279 | uint32_t num_direct_interfaces = h_clazz->NumDirectInterfaces(); |
| 280 | for (uint32_t i = 0; i < num_direct_interfaces; i++) { |
Vladimir Marko | 19a4d37 | 2016-12-08 14:41:46 +0000 | [diff] [blame] | 281 | ObjPtr<mirror::Class> iface = mirror::Class::ResolveDirectInterface(self, h_clazz, i); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 282 | if (UNLIKELY(iface == nullptr)) { |
| 283 | self->AssertPendingException(); |
| 284 | return nullptr; |
| 285 | } |
Nicolas Geoffray | a96f316 | 2016-05-03 14:04:02 +0100 | [diff] [blame] | 286 | result = GetPublicFieldRecursive(self, iface, h_name.Get()); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 287 | if (result != nullptr) { |
| 288 | DCHECK(result->GetAccessFlags() & kAccPublic); |
| 289 | return result; |
| 290 | } else if (UNLIKELY(self->IsExceptionPending())) { |
| 291 | // Something went wrong. Bail out. |
| 292 | return nullptr; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // We don't try the superclass if we are an interface. |
| 297 | if (h_clazz->IsInterface()) { |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | // Get the next class. |
| 302 | h_clazz.Assign(h_clazz->GetSuperClass()); |
| 303 | } |
| 304 | return nullptr; |
| 305 | } |
| 306 | |
| 307 | static jobject Class_getPublicFieldRecursive(JNIEnv* env, jobject javaThis, jstring name) { |
| 308 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 309 | auto name_string = soa.Decode<mirror::String>(name); |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 310 | if (UNLIKELY(name_string == nullptr)) { |
| 311 | ThrowNullPointerException("name == null"); |
| 312 | return nullptr; |
| 313 | } |
| 314 | return soa.AddLocalReference<jobject>( |
| 315 | GetPublicFieldRecursive(soa.Self(), DecodeClass(soa, javaThis), name_string)); |
| 316 | } |
| 317 | |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 318 | static jobject Class_getDeclaredField(JNIEnv* env, jobject javaThis, jstring name) { |
| 319 | ScopedFastNativeObjectAccess soa(env); |
Nicolas Geoffray | 9d07414 | 2016-09-30 09:51:32 +0100 | [diff] [blame] | 320 | StackHandleScope<3> hs(soa.Self()); |
| 321 | Handle<mirror::String> h_string = hs.NewHandle(soa.Decode<mirror::String>(name)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 322 | if (h_string == nullptr) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 323 | ThrowNullPointerException("name == null"); |
| 324 | return nullptr; |
| 325 | } |
Nicolas Geoffray | 9d07414 | 2016-09-30 09:51:32 +0100 | [diff] [blame] | 326 | Handle<mirror::Class> h_klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
| 327 | Handle<mirror::Field> result = |
| 328 | hs.NewHandle(GetDeclaredField(soa.Self(), h_klass.Get(), h_string.Get())); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 329 | if (result == nullptr) { |
Nicolas Geoffray | 9d07414 | 2016-09-30 09:51:32 +0100 | [diff] [blame] | 330 | std::string name_str = h_string->ToModifiedUtf8(); |
| 331 | if (name_str == "value" && h_klass->IsStringClass()) { |
Nicolas Geoffray | 7ea4c09 | 2016-01-07 10:55:14 +0000 | [diff] [blame] | 332 | // We log the error for this specific case, as the user might just swallow the exception. |
| 333 | // This helps diagnose crashes when applications rely on the String#value field being |
| 334 | // there. |
Nicolas Geoffray | 0e7fa6b | 2016-01-13 15:28:58 +0000 | [diff] [blame] | 335 | // Also print on the error stream to test it through run-test. |
| 336 | std::string message("The String#value field is not present on Android versions >= 6.0"); |
| 337 | LOG(ERROR) << message; |
| 338 | std::cerr << message << std::endl; |
Nicolas Geoffray | 7ea4c09 | 2016-01-07 10:55:14 +0000 | [diff] [blame] | 339 | } |
Mathieu Chartier | ca239af | 2015-03-29 18:27:50 -0700 | [diff] [blame] | 340 | // We may have a pending exception if we failed to resolve. |
| 341 | if (!soa.Self()->IsExceptionPending()) { |
Nicolas Geoffray | 9d07414 | 2016-09-30 09:51:32 +0100 | [diff] [blame] | 342 | ThrowNoSuchFieldException(h_klass.Get(), name_str.c_str()); |
Mathieu Chartier | ca239af | 2015-03-29 18:27:50 -0700 | [diff] [blame] | 343 | } |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 344 | return nullptr; |
| 345 | } |
Nicolas Geoffray | 9d07414 | 2016-09-30 09:51:32 +0100 | [diff] [blame] | 346 | return soa.AddLocalReference<jobject>(result.Get()); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 349 | static jobject Class_getDeclaredConstructorInternal( |
| 350 | JNIEnv* env, jobject javaThis, jobjectArray args) { |
| 351 | ScopedFastNativeObjectAccess soa(env); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 352 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 353 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 354 | ObjPtr<mirror::Constructor> result = |
| 355 | mirror::Class::GetDeclaredConstructorInternal<kRuntimePointerSize, false>( |
Andreas Gampe | 6039e56 | 2016-04-05 18:18:43 -0700 | [diff] [blame] | 356 | soa.Self(), |
Mathieu Chartier | 1a5337f | 2016-10-13 13:48:23 -0700 | [diff] [blame] | 357 | DecodeClass(soa, javaThis), |
| 358 | soa.Decode<mirror::ObjectArray<mirror::Class>>(args)); |
Andreas Gampe | 6039e56 | 2016-04-05 18:18:43 -0700 | [diff] [blame] | 359 | return soa.AddLocalReference<jobject>(result); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 362 | static ALWAYS_INLINE inline bool MethodMatchesConstructor(ArtMethod* m, bool public_only) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 363 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 364 | DCHECK(m != nullptr); |
| 365 | return (!public_only || m->IsPublic()) && !m->IsStatic() && m->IsConstructor(); |
| 366 | } |
| 367 | |
| 368 | static jobjectArray Class_getDeclaredConstructorsInternal( |
| 369 | JNIEnv* env, jobject javaThis, jboolean publicOnly) { |
| 370 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 05b7226 | 2015-06-17 16:11:12 -0700 | [diff] [blame] | 371 | StackHandleScope<2> hs(soa.Self()); |
| 372 | Handle<mirror::Class> h_klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 373 | size_t constructor_count = 0; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 374 | // Two pass approach for speed. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 375 | for (auto& m : h_klass->GetDirectMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 376 | constructor_count += MethodMatchesConstructor(&m, publicOnly != JNI_FALSE) ? 1u : 0u; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 377 | } |
| 378 | auto h_constructors = hs.NewHandle(mirror::ObjectArray<mirror::Constructor>::Alloc( |
| 379 | soa.Self(), mirror::Constructor::ArrayClass(), constructor_count)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 380 | if (UNLIKELY(h_constructors == nullptr)) { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 381 | soa.Self()->AssertPendingException(); |
| 382 | return nullptr; |
| 383 | } |
| 384 | constructor_count = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 385 | for (auto& m : h_klass->GetDirectMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 386 | if (MethodMatchesConstructor(&m, publicOnly != JNI_FALSE)) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 387 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 388 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 389 | auto* constructor = mirror::Constructor::CreateFromArtMethod<kRuntimePointerSize, false>( |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 390 | soa.Self(), &m); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 391 | if (UNLIKELY(constructor == nullptr)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 392 | soa.Self()->AssertPendingOOMException(); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 393 | return nullptr; |
| 394 | } |
| 395 | h_constructors->SetWithoutChecks<false>(constructor_count++, constructor); |
| 396 | } |
| 397 | } |
| 398 | return soa.AddLocalReference<jobjectArray>(h_constructors.Get()); |
| 399 | } |
| 400 | |
| 401 | static jobject Class_getDeclaredMethodInternal(JNIEnv* env, jobject javaThis, |
| 402 | jobject name, jobjectArray args) { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 403 | ScopedFastNativeObjectAccess soa(env); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 404 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 405 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 406 | ObjPtr<mirror::Method> result = |
| 407 | mirror::Class::GetDeclaredMethodInternal<kRuntimePointerSize, false>( |
| 408 | soa.Self(), |
| 409 | DecodeClass(soa, javaThis), |
| 410 | soa.Decode<mirror::String>(name), |
| 411 | soa.Decode<mirror::ObjectArray<mirror::Class>>(args)); |
Andreas Gampe | bc4d218 | 2016-02-22 10:03:12 -0800 | [diff] [blame] | 412 | return soa.AddLocalReference<jobject>(result); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 415 | static jobjectArray Class_getDeclaredMethodsUnchecked(JNIEnv* env, jobject javaThis, |
| 416 | jboolean publicOnly) { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 417 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 281e500 | 2015-06-11 16:21:42 -0700 | [diff] [blame] | 418 | StackHandleScope<2> hs(soa.Self()); |
Mathieu Chartier | 05b7226 | 2015-06-17 16:11:12 -0700 | [diff] [blame] | 419 | Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 420 | size_t num_methods = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 421 | for (auto& m : klass->GetDeclaredMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 422 | auto modifiers = m.GetAccessFlags(); |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 423 | // Add non-constructor declared methods. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 424 | if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && |
| 425 | (modifiers & kAccConstructor) == 0) { |
| 426 | ++num_methods; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | auto ret = hs.NewHandle(mirror::ObjectArray<mirror::Method>::Alloc( |
| 430 | soa.Self(), mirror::Method::ArrayClass(), num_methods)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 431 | if (ret == nullptr) { |
Vladimir Marko | a35510d | 2017-01-16 22:42:09 +0000 | [diff] [blame] | 432 | soa.Self()->AssertPendingOOMException(); |
| 433 | return nullptr; |
| 434 | } |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 435 | num_methods = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 436 | for (auto& m : klass->GetDeclaredMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 437 | auto modifiers = m.GetAccessFlags(); |
| 438 | if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 439 | (modifiers & kAccConstructor) == 0) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 440 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 441 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 442 | auto* method = |
| 443 | mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), &m); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 444 | if (method == nullptr) { |
| 445 | soa.Self()->AssertPendingException(); |
| 446 | return nullptr; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 447 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 448 | ret->SetWithoutChecks<false>(num_methods++, method); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | return soa.AddLocalReference<jobjectArray>(ret.Get()); |
| 452 | } |
| 453 | |
Igor Murashkin | df187e4 | 2016-02-01 11:43:26 -0800 | [diff] [blame] | 454 | static jobject Class_getDeclaredAnnotation(JNIEnv* env, jobject javaThis, jclass annotationClass) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 455 | ScopedFastNativeObjectAccess soa(env); |
| 456 | StackHandleScope<2> hs(soa.Self()); |
| 457 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Igor Murashkin | df187e4 | 2016-02-01 11:43:26 -0800 | [diff] [blame] | 458 | |
| 459 | // Handle public contract to throw NPE if the "annotationClass" argument was null. |
| 460 | if (UNLIKELY(annotationClass == nullptr)) { |
| 461 | ThrowNullPointerException("annotationClass"); |
| 462 | return nullptr; |
| 463 | } |
| 464 | |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 465 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 466 | return nullptr; |
| 467 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 468 | Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationClass))); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 469 | return soa.AddLocalReference<jobject>( |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 470 | annotations::GetAnnotationForClass(klass, annotation_class)); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static jobjectArray Class_getDeclaredAnnotations(JNIEnv* env, jobject javaThis) { |
| 474 | ScopedFastNativeObjectAccess soa(env); |
| 475 | StackHandleScope<1> hs(soa.Self()); |
| 476 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 477 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 478 | // Return an empty array instead of a null pointer. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 479 | ObjPtr<mirror::Class> annotation_array_class = |
| 480 | soa.Decode<mirror::Class>(WellKnownClasses::java_lang_annotation_Annotation__array); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 481 | mirror::ObjectArray<mirror::Object>* empty_array = |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 482 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 483 | annotation_array_class.Ptr(), |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 484 | 0); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 485 | return soa.AddLocalReference<jobjectArray>(empty_array); |
| 486 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 487 | return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForClass(klass)); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 490 | static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) { |
| 491 | ScopedFastNativeObjectAccess soa(env); |
| 492 | StackHandleScope<1> hs(soa.Self()); |
| 493 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
| 494 | mirror::ObjectArray<mirror::Class>* classes = nullptr; |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 495 | if (!klass->IsProxyClass() && klass->GetDexCache() != nullptr) { |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 496 | classes = annotations::GetDeclaredClasses(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 497 | } |
| 498 | if (classes == nullptr) { |
| 499 | // Return an empty array instead of a null pointer. |
Mathieu Chartier | 6cfc2c0 | 2015-10-12 15:06:16 -0700 | [diff] [blame] | 500 | if (soa.Self()->IsExceptionPending()) { |
| 501 | // Pending exception from GetDeclaredClasses. |
| 502 | return nullptr; |
| 503 | } |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 504 | ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); |
| 505 | ObjPtr<mirror::Class> class_array_class = |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 506 | Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class); |
| 507 | if (class_array_class == nullptr) { |
| 508 | return nullptr; |
| 509 | } |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 510 | ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array = |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 511 | mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0); |
| 512 | return soa.AddLocalReference<jobjectArray>(empty_array); |
| 513 | } |
| 514 | return soa.AddLocalReference<jobjectArray>(classes); |
| 515 | } |
| 516 | |
| 517 | static jclass Class_getEnclosingClass(JNIEnv* env, jobject javaThis) { |
| 518 | ScopedFastNativeObjectAccess soa(env); |
| 519 | StackHandleScope<1> hs(soa.Self()); |
| 520 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 521 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 522 | return nullptr; |
| 523 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 524 | return soa.AddLocalReference<jclass>(annotations::GetEnclosingClass(klass)); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | static jobject Class_getEnclosingConstructorNative(JNIEnv* env, jobject javaThis) { |
| 528 | ScopedFastNativeObjectAccess soa(env); |
| 529 | StackHandleScope<1> hs(soa.Self()); |
| 530 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 531 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 532 | return nullptr; |
| 533 | } |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 534 | ObjPtr<mirror::Object> method = annotations::GetEnclosingMethod(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 535 | if (method != nullptr) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 536 | if (soa.Decode<mirror::Class>(WellKnownClasses::java_lang_reflect_Constructor) == |
| 537 | method->GetClass()) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 538 | return soa.AddLocalReference<jobject>(method); |
| 539 | } |
| 540 | } |
| 541 | return nullptr; |
| 542 | } |
| 543 | |
| 544 | static jobject Class_getEnclosingMethodNative(JNIEnv* env, jobject javaThis) { |
| 545 | ScopedFastNativeObjectAccess soa(env); |
| 546 | StackHandleScope<1> hs(soa.Self()); |
| 547 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 548 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 549 | return nullptr; |
| 550 | } |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 551 | ObjPtr<mirror::Object> method = annotations::GetEnclosingMethod(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 552 | if (method != nullptr) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 553 | if (soa.Decode<mirror::Class>(WellKnownClasses::java_lang_reflect_Method) == |
| 554 | method->GetClass()) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 555 | return soa.AddLocalReference<jobject>(method); |
| 556 | } |
| 557 | } |
| 558 | return nullptr; |
| 559 | } |
| 560 | |
| 561 | static jint Class_getInnerClassFlags(JNIEnv* env, jobject javaThis, jint defaultValue) { |
| 562 | ScopedFastNativeObjectAccess soa(env); |
| 563 | StackHandleScope<1> hs(soa.Self()); |
| 564 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Andreas Gampe | 715fdc2 | 2016-04-18 17:07:30 -0700 | [diff] [blame] | 565 | return mirror::Class::GetInnerClassFlags(klass, defaultValue); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static jstring Class_getInnerClassName(JNIEnv* env, jobject javaThis) { |
| 569 | ScopedFastNativeObjectAccess soa(env); |
| 570 | StackHandleScope<1> hs(soa.Self()); |
| 571 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 572 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 573 | return nullptr; |
| 574 | } |
| 575 | mirror::String* class_name = nullptr; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 576 | if (!annotations::GetInnerClass(klass, &class_name)) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 577 | return nullptr; |
| 578 | } |
| 579 | return soa.AddLocalReference<jstring>(class_name); |
| 580 | } |
| 581 | |
Jeff Hao | 1133db7 | 2016-04-04 19:50:14 -0700 | [diff] [blame] | 582 | static jobjectArray Class_getSignatureAnnotation(JNIEnv* env, jobject javaThis) { |
| 583 | ScopedFastNativeObjectAccess soa(env); |
| 584 | StackHandleScope<1> hs(soa.Self()); |
| 585 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
| 586 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
| 587 | return nullptr; |
| 588 | } |
| 589 | return soa.AddLocalReference<jobjectArray>( |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 590 | annotations::GetSignatureAnnotationForClass(klass)); |
Jeff Hao | 1133db7 | 2016-04-04 19:50:14 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 593 | static jboolean Class_isAnonymousClass(JNIEnv* env, jobject javaThis) { |
| 594 | ScopedFastNativeObjectAccess soa(env); |
| 595 | StackHandleScope<1> hs(soa.Self()); |
| 596 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 597 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | mirror::String* class_name = nullptr; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 601 | if (!annotations::GetInnerClass(klass, &class_name)) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 602 | return false; |
| 603 | } |
| 604 | return class_name == nullptr; |
| 605 | } |
| 606 | |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 607 | static jboolean Class_isDeclaredAnnotationPresent(JNIEnv* env, jobject javaThis, |
| 608 | jclass annotationType) { |
| 609 | ScopedFastNativeObjectAccess soa(env); |
| 610 | StackHandleScope<2> hs(soa.Self()); |
| 611 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 612 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 613 | return false; |
| 614 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 615 | Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationType))); |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 616 | return annotations::IsClassAnnotationPresent(klass, annotation_class); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 619 | static jclass Class_getDeclaringClass(JNIEnv* env, jobject javaThis) { |
| 620 | ScopedFastNativeObjectAccess soa(env); |
| 621 | StackHandleScope<1> hs(soa.Self()); |
| 622 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 623 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 624 | return nullptr; |
| 625 | } |
| 626 | // Return null for anonymous classes. |
| 627 | if (Class_isAnonymousClass(env, javaThis)) { |
| 628 | return nullptr; |
| 629 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 630 | return soa.AddLocalReference<jclass>(annotations::GetDeclaringClass(klass)); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 633 | static jobject Class_newInstance(JNIEnv* env, jobject javaThis) { |
| 634 | ScopedFastNativeObjectAccess soa(env); |
| 635 | StackHandleScope<4> hs(soa.Self()); |
Mathieu Chartier | 05b7226 | 2015-06-17 16:11:12 -0700 | [diff] [blame] | 636 | Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 637 | if (UNLIKELY(klass->GetPrimitiveType() != 0 || klass->IsInterface() || klass->IsArrayClass() || |
| 638 | klass->IsAbstract())) { |
| 639 | soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 640 | "%s cannot be instantiated", |
| 641 | klass->PrettyClass().c_str()); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 642 | return nullptr; |
| 643 | } |
| 644 | auto caller = hs.NewHandle<mirror::Class>(nullptr); |
| 645 | // Verify that we can access the class. |
| 646 | if (!klass->IsPublic()) { |
| 647 | caller.Assign(GetCallingClass(soa.Self(), 1)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 648 | if (caller != nullptr && !caller->CanAccess(klass.Get())) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 649 | soa.Self()->ThrowNewExceptionF( |
| 650 | "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 651 | klass->PrettyClass().c_str(), caller->PrettyClass().c_str()); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 652 | return nullptr; |
| 653 | } |
| 654 | } |
| 655 | auto* constructor = klass->GetDeclaredConstructor( |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 656 | soa.Self(), |
Andreas Gampe | 6039e56 | 2016-04-05 18:18:43 -0700 | [diff] [blame] | 657 | ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 658 | kRuntimePointerSize); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 659 | if (UNLIKELY(constructor == nullptr)) { |
| 660 | soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", |
| 661 | "%s has no zero argument constructor", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 662 | klass->PrettyClass().c_str()); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 663 | return nullptr; |
| 664 | } |
Jeff Hao | 69bdcb2 | 2015-04-27 20:54:07 -0700 | [diff] [blame] | 665 | // Invoke the string allocator to return an empty string for the string class. |
| 666 | if (klass->IsStringClass()) { |
| 667 | gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator(); |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 668 | ObjPtr<mirror::Object> obj = mirror::String::AllocEmptyString<true>(soa.Self(), allocator_type); |
Jeff Hao | 69bdcb2 | 2015-04-27 20:54:07 -0700 | [diff] [blame] | 669 | if (UNLIKELY(soa.Self()->IsExceptionPending())) { |
| 670 | return nullptr; |
| 671 | } else { |
| 672 | return soa.AddLocalReference<jobject>(obj); |
| 673 | } |
| 674 | } |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 675 | auto receiver = hs.NewHandle(klass->AllocObject(soa.Self())); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 676 | if (UNLIKELY(receiver == nullptr)) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 677 | soa.Self()->AssertPendingOOMException(); |
| 678 | return nullptr; |
| 679 | } |
| 680 | // Verify that we can access the constructor. |
| 681 | auto* declaring_class = constructor->GetDeclaringClass(); |
| 682 | if (!constructor->IsPublic()) { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 683 | if (caller == nullptr) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 684 | caller.Assign(GetCallingClass(soa.Self(), 1)); |
| 685 | } |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 686 | if (UNLIKELY(caller != nullptr && !VerifyAccess(receiver.Get(), |
Mathieu Chartier | f8ac97f | 2016-10-05 15:56:52 -0700 | [diff] [blame] | 687 | declaring_class, |
| 688 | constructor->GetAccessFlags(), |
| 689 | caller.Get()))) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 690 | soa.Self()->ThrowNewExceptionF( |
| 691 | "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 692 | constructor->PrettyMethod().c_str(), caller->PrettyClass().c_str()); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 693 | return nullptr; |
| 694 | } |
| 695 | } |
| 696 | // Ensure that we are initialized. |
| 697 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
| 698 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
| 699 | soa.Self(), hs.NewHandle(declaring_class), true, true)) { |
| 700 | soa.Self()->AssertPendingException(); |
| 701 | return nullptr; |
| 702 | } |
| 703 | } |
| 704 | // Invoke the constructor. |
| 705 | JValue result; |
| 706 | uint32_t args[1] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(receiver.Get())) }; |
| 707 | constructor->Invoke(soa.Self(), args, sizeof(args), &result, "V"); |
| 708 | if (UNLIKELY(soa.Self()->IsExceptionPending())) { |
| 709 | return nullptr; |
| 710 | } |
| 711 | // Constructors are ()V methods, so we shouldn't touch the result of InvokeMethod. |
| 712 | return soa.AddLocalReference<jobject>(receiver.Get()); |
| 713 | } |
| 714 | |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 715 | static JNINativeMethod gMethods[] = { |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 716 | FAST_NATIVE_METHOD(Class, classForName, |
| 717 | "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"), |
| 718 | FAST_NATIVE_METHOD(Class, getDeclaredAnnotation, |
| 719 | "(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"), |
| 720 | FAST_NATIVE_METHOD(Class, getDeclaredAnnotations, "()[Ljava/lang/annotation/Annotation;"), |
| 721 | FAST_NATIVE_METHOD(Class, getDeclaredClasses, "()[Ljava/lang/Class;"), |
| 722 | FAST_NATIVE_METHOD(Class, getDeclaredConstructorInternal, |
| 723 | "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"), |
| 724 | FAST_NATIVE_METHOD(Class, getDeclaredConstructorsInternal, "(Z)[Ljava/lang/reflect/Constructor;"), |
| 725 | FAST_NATIVE_METHOD(Class, getDeclaredField, "(Ljava/lang/String;)Ljava/lang/reflect/Field;"), |
| 726 | FAST_NATIVE_METHOD(Class, getPublicFieldRecursive, "(Ljava/lang/String;)Ljava/lang/reflect/Field;"), |
| 727 | FAST_NATIVE_METHOD(Class, getDeclaredFields, "()[Ljava/lang/reflect/Field;"), |
| 728 | FAST_NATIVE_METHOD(Class, getDeclaredFieldsUnchecked, "(Z)[Ljava/lang/reflect/Field;"), |
| 729 | FAST_NATIVE_METHOD(Class, getDeclaredMethodInternal, |
| 730 | "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"), |
| 731 | FAST_NATIVE_METHOD(Class, getDeclaredMethodsUnchecked, |
| 732 | "(Z)[Ljava/lang/reflect/Method;"), |
| 733 | FAST_NATIVE_METHOD(Class, getDeclaringClass, "()Ljava/lang/Class;"), |
| 734 | FAST_NATIVE_METHOD(Class, getEnclosingClass, "()Ljava/lang/Class;"), |
| 735 | FAST_NATIVE_METHOD(Class, getEnclosingConstructorNative, "()Ljava/lang/reflect/Constructor;"), |
| 736 | FAST_NATIVE_METHOD(Class, getEnclosingMethodNative, "()Ljava/lang/reflect/Method;"), |
| 737 | FAST_NATIVE_METHOD(Class, getInnerClassFlags, "(I)I"), |
| 738 | FAST_NATIVE_METHOD(Class, getInnerClassName, "()Ljava/lang/String;"), |
| 739 | FAST_NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"), |
| 740 | FAST_NATIVE_METHOD(Class, getProxyInterfaces, "()[Ljava/lang/Class;"), |
| 741 | FAST_NATIVE_METHOD(Class, getPublicDeclaredFields, "()[Ljava/lang/reflect/Field;"), |
| 742 | FAST_NATIVE_METHOD(Class, getSignatureAnnotation, "()[Ljava/lang/String;"), |
| 743 | FAST_NATIVE_METHOD(Class, isAnonymousClass, "()Z"), |
| 744 | FAST_NATIVE_METHOD(Class, isDeclaredAnnotationPresent, "(Ljava/lang/Class;)Z"), |
| 745 | FAST_NATIVE_METHOD(Class, newInstance, "()Ljava/lang/Object;"), |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 746 | }; |
| 747 | |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 748 | void register_java_lang_Class(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 749 | REGISTER_NATIVE_METHODS("java/lang/Class"); |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | } // namespace art |