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))); |
| 84 | if (c.Get() == 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)); |
| 140 | if (object_array.Get() == nullptr) { |
| 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. |
| 270 | while (h_clazz.Get() != 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++) { |
| 281 | mirror::Class *iface = mirror::Class::GetDirectInterface(self, h_clazz, i); |
| 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)); |
| 322 | if (h_string.Get() == 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())); |
| 329 | if (result.Get() == nullptr) { |
| 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 | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 357 | DecodeClass(soa, javaThis).Ptr(), |
| 358 | soa.Decode<mirror::ObjectArray<mirror::Class>>(args).Ptr()); |
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)); |
| 380 | if (UNLIKELY(h_constructors.Get() == nullptr)) { |
| 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()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 406 | mirror::Method* result = mirror::Class::GetDeclaredMethodInternal<kRuntimePointerSize, false>( |
Andreas Gampe | bc4d218 | 2016-02-22 10:03:12 -0800 | [diff] [blame] | 407 | soa.Self(), |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 408 | DecodeClass(soa, javaThis).Ptr(), |
| 409 | soa.Decode<mirror::String>(name).Ptr(), |
| 410 | soa.Decode<mirror::ObjectArray<mirror::Class>>(args).Ptr()); |
Andreas Gampe | bc4d218 | 2016-02-22 10:03:12 -0800 | [diff] [blame] | 411 | return soa.AddLocalReference<jobject>(result); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 414 | static jobjectArray Class_getDeclaredMethodsUnchecked(JNIEnv* env, jobject javaThis, |
| 415 | jboolean publicOnly) { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 416 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 281e500 | 2015-06-11 16:21:42 -0700 | [diff] [blame] | 417 | StackHandleScope<2> hs(soa.Self()); |
Mathieu Chartier | 05b7226 | 2015-06-17 16:11:12 -0700 | [diff] [blame] | 418 | Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 419 | size_t num_methods = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 420 | for (auto& m : klass->GetDeclaredMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 421 | auto modifiers = m.GetAccessFlags(); |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 422 | // Add non-constructor declared methods. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 423 | if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && |
| 424 | (modifiers & kAccConstructor) == 0) { |
| 425 | ++num_methods; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | auto ret = hs.NewHandle(mirror::ObjectArray<mirror::Method>::Alloc( |
| 429 | soa.Self(), mirror::Method::ArrayClass(), num_methods)); |
| 430 | num_methods = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 431 | for (auto& m : klass->GetDeclaredMethods(kRuntimePointerSize)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 432 | auto modifiers = m.GetAccessFlags(); |
| 433 | if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 434 | (modifiers & kAccConstructor) == 0) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 435 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 436 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 437 | auto* method = |
| 438 | mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), &m); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 439 | if (method == nullptr) { |
| 440 | soa.Self()->AssertPendingException(); |
| 441 | return nullptr; |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 442 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 443 | ret->SetWithoutChecks<false>(num_methods++, method); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | return soa.AddLocalReference<jobjectArray>(ret.Get()); |
| 447 | } |
| 448 | |
Igor Murashkin | df187e4 | 2016-02-01 11:43:26 -0800 | [diff] [blame] | 449 | static jobject Class_getDeclaredAnnotation(JNIEnv* env, jobject javaThis, jclass annotationClass) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 450 | ScopedFastNativeObjectAccess soa(env); |
| 451 | StackHandleScope<2> hs(soa.Self()); |
| 452 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Igor Murashkin | df187e4 | 2016-02-01 11:43:26 -0800 | [diff] [blame] | 453 | |
| 454 | // Handle public contract to throw NPE if the "annotationClass" argument was null. |
| 455 | if (UNLIKELY(annotationClass == nullptr)) { |
| 456 | ThrowNullPointerException("annotationClass"); |
| 457 | return nullptr; |
| 458 | } |
| 459 | |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 460 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 461 | return nullptr; |
| 462 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 463 | Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationClass))); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 464 | return soa.AddLocalReference<jobject>( |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 465 | annotations::GetAnnotationForClass(klass, annotation_class)); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static jobjectArray Class_getDeclaredAnnotations(JNIEnv* env, jobject javaThis) { |
| 469 | ScopedFastNativeObjectAccess soa(env); |
| 470 | StackHandleScope<1> hs(soa.Self()); |
| 471 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 472 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 473 | // Return an empty array instead of a null pointer. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 474 | ObjPtr<mirror::Class> annotation_array_class = |
| 475 | soa.Decode<mirror::Class>(WellKnownClasses::java_lang_annotation_Annotation__array); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 476 | mirror::ObjectArray<mirror::Object>* empty_array = |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 477 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 478 | annotation_array_class.Ptr(), |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 479 | 0); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 480 | return soa.AddLocalReference<jobjectArray>(empty_array); |
| 481 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 482 | return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForClass(klass)); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 485 | static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) { |
| 486 | ScopedFastNativeObjectAccess soa(env); |
| 487 | StackHandleScope<1> hs(soa.Self()); |
| 488 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
| 489 | mirror::ObjectArray<mirror::Class>* classes = nullptr; |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 490 | if (!klass->IsProxyClass() && klass->GetDexCache() != nullptr) { |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 491 | classes = annotations::GetDeclaredClasses(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 492 | } |
| 493 | if (classes == nullptr) { |
| 494 | // Return an empty array instead of a null pointer. |
Mathieu Chartier | 6cfc2c0 | 2015-10-12 15:06:16 -0700 | [diff] [blame] | 495 | if (soa.Self()->IsExceptionPending()) { |
| 496 | // Pending exception from GetDeclaredClasses. |
| 497 | return nullptr; |
| 498 | } |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 499 | mirror::Class* class_class = mirror::Class::GetJavaLangClass(); |
| 500 | mirror::Class* class_array_class = |
| 501 | Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class); |
| 502 | if (class_array_class == nullptr) { |
| 503 | return nullptr; |
| 504 | } |
| 505 | mirror::ObjectArray<mirror::Class>* empty_array = |
| 506 | mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0); |
| 507 | return soa.AddLocalReference<jobjectArray>(empty_array); |
| 508 | } |
| 509 | return soa.AddLocalReference<jobjectArray>(classes); |
| 510 | } |
| 511 | |
| 512 | static jclass Class_getEnclosingClass(JNIEnv* env, jobject javaThis) { |
| 513 | ScopedFastNativeObjectAccess soa(env); |
| 514 | StackHandleScope<1> hs(soa.Self()); |
| 515 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 516 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 517 | return nullptr; |
| 518 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 519 | return soa.AddLocalReference<jclass>(annotations::GetEnclosingClass(klass)); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static jobject Class_getEnclosingConstructorNative(JNIEnv* env, jobject javaThis) { |
| 523 | ScopedFastNativeObjectAccess soa(env); |
| 524 | StackHandleScope<1> hs(soa.Self()); |
| 525 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 526 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 527 | return nullptr; |
| 528 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 529 | mirror::Object* method = annotations::GetEnclosingMethod(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 530 | if (method != nullptr) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 531 | if (soa.Decode<mirror::Class>(WellKnownClasses::java_lang_reflect_Constructor) == |
| 532 | method->GetClass()) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 533 | return soa.AddLocalReference<jobject>(method); |
| 534 | } |
| 535 | } |
| 536 | return nullptr; |
| 537 | } |
| 538 | |
| 539 | static jobject Class_getEnclosingMethodNative(JNIEnv* env, jobject javaThis) { |
| 540 | ScopedFastNativeObjectAccess soa(env); |
| 541 | StackHandleScope<1> hs(soa.Self()); |
| 542 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 543 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 544 | return nullptr; |
| 545 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 546 | mirror::Object* method = annotations::GetEnclosingMethod(klass); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 547 | if (method != nullptr) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 548 | if (soa.Decode<mirror::Class>(WellKnownClasses::java_lang_reflect_Method) == |
| 549 | method->GetClass()) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 550 | return soa.AddLocalReference<jobject>(method); |
| 551 | } |
| 552 | } |
| 553 | return nullptr; |
| 554 | } |
| 555 | |
| 556 | static jint Class_getInnerClassFlags(JNIEnv* env, jobject javaThis, jint defaultValue) { |
| 557 | ScopedFastNativeObjectAccess soa(env); |
| 558 | StackHandleScope<1> hs(soa.Self()); |
| 559 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Andreas Gampe | 715fdc2 | 2016-04-18 17:07:30 -0700 | [diff] [blame] | 560 | return mirror::Class::GetInnerClassFlags(klass, defaultValue); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static jstring Class_getInnerClassName(JNIEnv* env, jobject javaThis) { |
| 564 | ScopedFastNativeObjectAccess soa(env); |
| 565 | StackHandleScope<1> hs(soa.Self()); |
| 566 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 567 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 568 | return nullptr; |
| 569 | } |
| 570 | mirror::String* class_name = nullptr; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 571 | if (!annotations::GetInnerClass(klass, &class_name)) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 572 | return nullptr; |
| 573 | } |
| 574 | return soa.AddLocalReference<jstring>(class_name); |
| 575 | } |
| 576 | |
Jeff Hao | 1133db7 | 2016-04-04 19:50:14 -0700 | [diff] [blame] | 577 | static jobjectArray Class_getSignatureAnnotation(JNIEnv* env, jobject javaThis) { |
| 578 | ScopedFastNativeObjectAccess soa(env); |
| 579 | StackHandleScope<1> hs(soa.Self()); |
| 580 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
| 581 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
| 582 | return nullptr; |
| 583 | } |
| 584 | return soa.AddLocalReference<jobjectArray>( |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 585 | annotations::GetSignatureAnnotationForClass(klass)); |
Jeff Hao | 1133db7 | 2016-04-04 19:50:14 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 588 | static jboolean Class_isAnonymousClass(JNIEnv* env, jobject javaThis) { |
| 589 | ScopedFastNativeObjectAccess soa(env); |
| 590 | StackHandleScope<1> hs(soa.Self()); |
| 591 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 592 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | mirror::String* class_name = nullptr; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 596 | if (!annotations::GetInnerClass(klass, &class_name)) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 597 | return false; |
| 598 | } |
| 599 | return class_name == nullptr; |
| 600 | } |
| 601 | |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 602 | static jboolean Class_isDeclaredAnnotationPresent(JNIEnv* env, jobject javaThis, |
| 603 | jclass annotationType) { |
| 604 | ScopedFastNativeObjectAccess soa(env); |
| 605 | StackHandleScope<2> hs(soa.Self()); |
| 606 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 607 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 608 | return false; |
| 609 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 610 | Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class>(annotationType))); |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 611 | return annotations::IsClassAnnotationPresent(klass, annotation_class); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 614 | static jclass Class_getDeclaringClass(JNIEnv* env, jobject javaThis) { |
| 615 | ScopedFastNativeObjectAccess soa(env); |
| 616 | StackHandleScope<1> hs(soa.Self()); |
| 617 | Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis))); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 618 | if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) { |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 619 | return nullptr; |
| 620 | } |
| 621 | // Return null for anonymous classes. |
| 622 | if (Class_isAnonymousClass(env, javaThis)) { |
| 623 | return nullptr; |
| 624 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 625 | return soa.AddLocalReference<jclass>(annotations::GetDeclaringClass(klass)); |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 628 | static jobject Class_newInstance(JNIEnv* env, jobject javaThis) { |
| 629 | ScopedFastNativeObjectAccess soa(env); |
| 630 | StackHandleScope<4> hs(soa.Self()); |
Mathieu Chartier | 05b7226 | 2015-06-17 16:11:12 -0700 | [diff] [blame] | 631 | Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis)); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 632 | if (UNLIKELY(klass->GetPrimitiveType() != 0 || klass->IsInterface() || klass->IsArrayClass() || |
| 633 | klass->IsAbstract())) { |
| 634 | soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", |
| 635 | "%s cannot be instantiated", PrettyClass(klass.Get()).c_str()); |
| 636 | return nullptr; |
| 637 | } |
| 638 | auto caller = hs.NewHandle<mirror::Class>(nullptr); |
| 639 | // Verify that we can access the class. |
| 640 | if (!klass->IsPublic()) { |
| 641 | caller.Assign(GetCallingClass(soa.Self(), 1)); |
| 642 | if (caller.Get() != nullptr && !caller->CanAccess(klass.Get())) { |
| 643 | soa.Self()->ThrowNewExceptionF( |
| 644 | "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s", |
| 645 | PrettyClass(klass.Get()).c_str(), PrettyClass(caller.Get()).c_str()); |
| 646 | return nullptr; |
| 647 | } |
| 648 | } |
| 649 | auto* constructor = klass->GetDeclaredConstructor( |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 650 | soa.Self(), |
Andreas Gampe | 6039e56 | 2016-04-05 18:18:43 -0700 | [diff] [blame] | 651 | ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 652 | kRuntimePointerSize); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 653 | if (UNLIKELY(constructor == nullptr)) { |
| 654 | soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", |
| 655 | "%s has no zero argument constructor", |
| 656 | PrettyClass(klass.Get()).c_str()); |
| 657 | return nullptr; |
| 658 | } |
Jeff Hao | 69bdcb2 | 2015-04-27 20:54:07 -0700 | [diff] [blame] | 659 | // Invoke the string allocator to return an empty string for the string class. |
| 660 | if (klass->IsStringClass()) { |
| 661 | gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator(); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 662 | mirror::Object* obj = mirror::String::AllocEmptyString<true>(soa.Self(), allocator_type); |
Jeff Hao | 69bdcb2 | 2015-04-27 20:54:07 -0700 | [diff] [blame] | 663 | if (UNLIKELY(soa.Self()->IsExceptionPending())) { |
| 664 | return nullptr; |
| 665 | } else { |
| 666 | return soa.AddLocalReference<jobject>(obj); |
| 667 | } |
| 668 | } |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 669 | auto receiver = hs.NewHandle(klass->AllocObject(soa.Self())); |
| 670 | if (UNLIKELY(receiver.Get() == nullptr)) { |
| 671 | soa.Self()->AssertPendingOOMException(); |
| 672 | return nullptr; |
| 673 | } |
| 674 | // Verify that we can access the constructor. |
| 675 | auto* declaring_class = constructor->GetDeclaringClass(); |
| 676 | if (!constructor->IsPublic()) { |
| 677 | if (caller.Get() == nullptr) { |
| 678 | caller.Assign(GetCallingClass(soa.Self(), 1)); |
| 679 | } |
Mathieu Chartier | f8ac97f | 2016-10-05 15:56:52 -0700 | [diff] [blame^] | 680 | if (UNLIKELY(caller.Get() != nullptr && !VerifyAccess(receiver.Get(), |
| 681 | declaring_class, |
| 682 | constructor->GetAccessFlags(), |
| 683 | caller.Get()))) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 684 | soa.Self()->ThrowNewExceptionF( |
| 685 | "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s", |
| 686 | PrettyMethod(constructor).c_str(), PrettyClass(caller.Get()).c_str()); |
| 687 | return nullptr; |
| 688 | } |
| 689 | } |
| 690 | // Ensure that we are initialized. |
| 691 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
| 692 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
| 693 | soa.Self(), hs.NewHandle(declaring_class), true, true)) { |
| 694 | soa.Self()->AssertPendingException(); |
| 695 | return nullptr; |
| 696 | } |
| 697 | } |
| 698 | // Invoke the constructor. |
| 699 | JValue result; |
| 700 | uint32_t args[1] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(receiver.Get())) }; |
| 701 | constructor->Invoke(soa.Self(), args, sizeof(args), &result, "V"); |
| 702 | if (UNLIKELY(soa.Self()->IsExceptionPending())) { |
| 703 | return nullptr; |
| 704 | } |
| 705 | // Constructors are ()V methods, so we shouldn't touch the result of InvokeMethod. |
| 706 | return soa.AddLocalReference<jobject>(receiver.Get()); |
| 707 | } |
| 708 | |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 709 | static JNINativeMethod gMethods[] = { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 710 | NATIVE_METHOD(Class, classForName, |
| 711 | "!(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"), |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 712 | NATIVE_METHOD(Class, getDeclaredAnnotation, |
| 713 | "!(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;"), |
| 714 | NATIVE_METHOD(Class, getDeclaredAnnotations, "!()[Ljava/lang/annotation/Annotation;"), |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 715 | NATIVE_METHOD(Class, getDeclaredClasses, "!()[Ljava/lang/Class;"), |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 716 | NATIVE_METHOD(Class, getDeclaredConstructorInternal, |
| 717 | "!([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"), |
| 718 | NATIVE_METHOD(Class, getDeclaredConstructorsInternal, "!(Z)[Ljava/lang/reflect/Constructor;"), |
| 719 | NATIVE_METHOD(Class, getDeclaredField, "!(Ljava/lang/String;)Ljava/lang/reflect/Field;"), |
Alex Light | 72f9075 | 2015-10-01 13:35:09 -0700 | [diff] [blame] | 720 | NATIVE_METHOD(Class, getPublicFieldRecursive, "!(Ljava/lang/String;)Ljava/lang/reflect/Field;"), |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 721 | NATIVE_METHOD(Class, getDeclaredFields, "!()[Ljava/lang/reflect/Field;"), |
| 722 | NATIVE_METHOD(Class, getDeclaredFieldsUnchecked, "!(Z)[Ljava/lang/reflect/Field;"), |
| 723 | NATIVE_METHOD(Class, getDeclaredMethodInternal, |
| 724 | "!(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"), |
| 725 | NATIVE_METHOD(Class, getDeclaredMethodsUnchecked, |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 726 | "!(Z)[Ljava/lang/reflect/Method;"), |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 727 | NATIVE_METHOD(Class, getDeclaringClass, "!()Ljava/lang/Class;"), |
| 728 | NATIVE_METHOD(Class, getEnclosingClass, "!()Ljava/lang/Class;"), |
| 729 | NATIVE_METHOD(Class, getEnclosingConstructorNative, "!()Ljava/lang/reflect/Constructor;"), |
| 730 | NATIVE_METHOD(Class, getEnclosingMethodNative, "!()Ljava/lang/reflect/Method;"), |
| 731 | NATIVE_METHOD(Class, getInnerClassFlags, "!(I)I"), |
| 732 | NATIVE_METHOD(Class, getInnerClassName, "!()Ljava/lang/String;"), |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 733 | NATIVE_METHOD(Class, getNameNative, "!()Ljava/lang/String;"), |
| 734 | NATIVE_METHOD(Class, getProxyInterfaces, "!()[Ljava/lang/Class;"), |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 735 | NATIVE_METHOD(Class, getPublicDeclaredFields, "!()[Ljava/lang/reflect/Field;"), |
Jeff Hao | 1133db7 | 2016-04-04 19:50:14 -0700 | [diff] [blame] | 736 | NATIVE_METHOD(Class, getSignatureAnnotation, "!()[Ljava/lang/String;"), |
Jeff Hao | 2a5892f | 2015-08-31 15:00:40 -0700 | [diff] [blame] | 737 | NATIVE_METHOD(Class, isAnonymousClass, "!()Z"), |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 738 | NATIVE_METHOD(Class, isDeclaredAnnotationPresent, "!(Ljava/lang/Class;)Z"), |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 739 | NATIVE_METHOD(Class, newInstance, "!()Ljava/lang/Object;"), |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 740 | }; |
| 741 | |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 742 | void register_java_lang_Class(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 743 | REGISTER_NATIVE_METHODS("java/lang/Class"); |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | } // namespace art |