Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 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 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 17 | #include "entrypoints/entrypoint_utils.h" |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 21 | #include "base/enums.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 22 | #include "base/mutex.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "dex_file-inl.h" |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 25 | #include "entrypoints/entrypoint_utils-inl.h" |
| 26 | #include "entrypoints/quick/callee_save_frame.h" |
| 27 | #include "entrypoints/runtime_asm_entrypoints.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 28 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 30 | #include "mirror/method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | #include "mirror/object-inl.h" |
| 32 | #include "mirror/object_array-inl.h" |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 33 | #include "nth_caller_visitor.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 34 | #include "oat_quick_method_header.h" |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 35 | #include "reflection.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 36 | #include "scoped_thread_state_change-inl.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 37 | #include "well_known_classes.h" |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 38 | |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 39 | namespace art { |
| 40 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 41 | static inline mirror::Class* CheckFilledNewArrayAlloc(dex::TypeIndex type_idx, |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 42 | int32_t component_count, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 43 | ArtMethod* referrer, |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 44 | Thread* self, |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 45 | bool access_check) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 46 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 47 | if (UNLIKELY(component_count < 0)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 48 | ThrowNegativeArraySizeException(component_count); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 49 | return nullptr; // Failure |
Elliott Hughes | 6c8867d | 2011-10-03 16:34:05 -0700 | [diff] [blame] | 50 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 51 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 52 | PointerSize pointer_size = class_linker->GetImagePointerSize(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 53 | mirror::Class* klass = referrer->GetDexCacheResolvedType<false>(type_idx, pointer_size); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 54 | if (UNLIKELY(klass == nullptr)) { // Not in dex cache so try to resolve |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 55 | klass = class_linker->ResolveType(type_idx, referrer); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 56 | if (klass == nullptr) { // Error |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 57 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 58 | return nullptr; // Failure |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 59 | } |
Ian Rogers | ea2a11d | 2011-10-11 16:48:51 -0700 | [diff] [blame] | 60 | } |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 61 | if (UNLIKELY(klass->IsPrimitive() && !klass->IsPrimitiveInt())) { |
| 62 | if (klass->IsPrimitiveLong() || klass->IsPrimitiveDouble()) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 63 | ThrowRuntimeException("Bad filled array request for type %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 64 | klass->PrettyDescriptor().c_str()); |
Ian Rogers | 573db4a | 2011-12-13 15:30:50 -0800 | [diff] [blame] | 65 | } else { |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 66 | self->ThrowNewExceptionF( |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 67 | "Ljava/lang/InternalError;", |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 68 | "Found type %s; filled-new-array not implemented for anything but 'int'", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 69 | klass->PrettyDescriptor().c_str()); |
Ian Rogers | 573db4a | 2011-12-13 15:30:50 -0800 | [diff] [blame] | 70 | } |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 71 | return nullptr; // Failure |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 72 | } |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 73 | if (access_check) { |
| 74 | mirror::Class* referrer_klass = referrer->GetDeclaringClass(); |
| 75 | if (UNLIKELY(!referrer_klass->CanAccess(klass))) { |
| 76 | ThrowIllegalAccessErrorClass(referrer_klass, klass); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 77 | return nullptr; // Failure |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 80 | DCHECK(klass->IsArrayClass()) << klass->PrettyClass(); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 81 | return klass; |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | // Helper function to allocate array for FILLED_NEW_ARRAY. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 85 | mirror::Array* CheckAndAllocArrayFromCode(dex::TypeIndex type_idx, |
| 86 | int32_t component_count, |
| 87 | ArtMethod* referrer, |
| 88 | Thread* self, |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 89 | bool access_check, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 90 | gc::AllocatorType allocator_type ATTRIBUTE_UNUSED) { |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 91 | mirror::Class* klass = CheckFilledNewArrayAlloc(type_idx, component_count, referrer, self, |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 92 | access_check); |
| 93 | if (UNLIKELY(klass == nullptr)) { |
| 94 | return nullptr; |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 95 | } |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 96 | // Always go slow path for now, filled new array is not common. |
| 97 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 98 | // Use the current allocator type in case CheckFilledNewArrayAlloc caused us to suspend and then |
| 99 | // the heap switched the allocator type while we were suspended. |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 100 | return mirror::Array::Alloc<false>(self, klass, component_count, |
| 101 | klass->GetComponentSizeShift(), |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 102 | heap->GetCurrentAllocator()); |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Helper function to allocate array for FILLED_NEW_ARRAY. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 106 | mirror::Array* CheckAndAllocArrayFromCodeInstrumented( |
| 107 | dex::TypeIndex type_idx, |
| 108 | int32_t component_count, |
| 109 | ArtMethod* referrer, |
| 110 | Thread* self, |
| 111 | bool access_check, |
| 112 | gc::AllocatorType allocator_type ATTRIBUTE_UNUSED) { |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 113 | mirror::Class* klass = CheckFilledNewArrayAlloc(type_idx, component_count, referrer, self, |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 114 | access_check); |
| 115 | if (UNLIKELY(klass == nullptr)) { |
| 116 | return nullptr; |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 117 | } |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 118 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 119 | // Use the current allocator type in case CheckFilledNewArrayAlloc caused us to suspend and then |
| 120 | // the heap switched the allocator type while we were suspended. |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 121 | return mirror::Array::Alloc<true>(self, klass, component_count, |
| 122 | klass->GetComponentSizeShift(), |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 123 | heap->GetCurrentAllocator()); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 126 | void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) { |
| 127 | if (o.Get() == nullptr) { |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 128 | return; |
| 129 | } |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 130 | // Make sure that the result is an instance of the type this method was expected to return. |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 131 | ArtMethod* method = self->GetCurrentMethod(nullptr); |
| 132 | mirror::Class* return_type = method->GetReturnType(true /* resolve */, kRuntimePointerSize); |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 133 | |
| 134 | if (!o->InstanceOf(return_type)) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 135 | Runtime::Current()->GetJavaVM()->JniAbortF(nullptr, |
| 136 | "attempt to return an instance of %s from %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 137 | o->PrettyTypeOf().c_str(), |
| 138 | method->PrettyMethod().c_str()); |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 142 | JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty, |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 143 | jobject rcvr_jobj, jobject interface_method_jobj, |
| 144 | std::vector<jvalue>& args) { |
| 145 | DCHECK(soa.Env()->IsInstanceOf(rcvr_jobj, WellKnownClasses::java_lang_reflect_Proxy)); |
| 146 | |
| 147 | // Build argument array possibly triggering GC. |
| 148 | soa.Self()->AssertThreadSuspensionIsAllowable(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 149 | jobjectArray args_jobj = nullptr; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 150 | const JValue zero; |
Jeff Hao | f00571c | 2014-05-29 17:29:47 -0700 | [diff] [blame] | 151 | int32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion(); |
| 152 | // Do not create empty arrays unless needed to maintain Dalvik bug compatibility. |
| 153 | if (args.size() > 0 || (target_sdk_version > 0 && target_sdk_version <= 21)) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 154 | args_jobj = soa.Env()->NewObjectArray(args.size(), WellKnownClasses::java_lang_Object, nullptr); |
| 155 | if (args_jobj == nullptr) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 156 | CHECK(soa.Self()->IsExceptionPending()); |
| 157 | return zero; |
| 158 | } |
| 159 | for (size_t i = 0; i < args.size(); ++i) { |
| 160 | if (shorty[i + 1] == 'L') { |
| 161 | jobject val = args.at(i).l; |
| 162 | soa.Env()->SetObjectArrayElement(args_jobj, i, val); |
| 163 | } else { |
| 164 | JValue jv; |
| 165 | jv.SetJ(args.at(i).j); |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 166 | mirror::Object* val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv).Ptr(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 167 | if (val == nullptr) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 168 | CHECK(soa.Self()->IsExceptionPending()); |
| 169 | return zero; |
| 170 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 171 | soa.Decode<mirror::ObjectArray<mirror::Object>>(args_jobj)->Set<false>(i, val); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 176 | // Call Proxy.invoke(Proxy proxy, Method method, Object[] args). |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 177 | jvalue invocation_args[3]; |
| 178 | invocation_args[0].l = rcvr_jobj; |
| 179 | invocation_args[1].l = interface_method_jobj; |
| 180 | invocation_args[2].l = args_jobj; |
| 181 | jobject result = |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 182 | soa.Env()->CallStaticObjectMethodA(WellKnownClasses::java_lang_reflect_Proxy, |
| 183 | WellKnownClasses::java_lang_reflect_Proxy_invoke, |
| 184 | invocation_args); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 185 | |
| 186 | // Unbox result and handle error conditions. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 187 | if (LIKELY(!soa.Self()->IsExceptionPending())) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 188 | if (shorty[0] == 'V' || (shorty[0] == 'L' && result == nullptr)) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 189 | // Do nothing. |
| 190 | return zero; |
| 191 | } else { |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 192 | ArtMethod* interface_method = |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 193 | soa.Decode<mirror::Method>(interface_method_jobj)->GetArtMethod(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 194 | // This can cause thread suspension. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 195 | PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 196 | mirror::Class* result_type = interface_method->GetReturnType(true /* resolve */, pointer_size); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 197 | ObjPtr<mirror::Object> result_ref = soa.Decode<mirror::Object>(result); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 198 | JValue result_unboxed; |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 199 | if (!UnboxPrimitiveForResult(result_ref.Ptr(), result_type, &result_unboxed)) { |
Ian Rogers | 530f71c | 2013-02-22 23:29:00 -0800 | [diff] [blame] | 200 | DCHECK(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 201 | return zero; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 202 | } |
| 203 | return result_unboxed; |
| 204 | } |
| 205 | } else { |
| 206 | // In the case of checked exceptions that aren't declared, the exception must be wrapped by |
| 207 | // a UndeclaredThrowableException. |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 208 | mirror::Throwable* exception = soa.Self()->GetException(); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 209 | if (exception->IsCheckedException()) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 210 | bool declares_exception = false; |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 211 | { |
| 212 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 213 | ObjPtr<mirror::Object> rcvr = soa.Decode<mirror::Object>(rcvr_jobj); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 214 | mirror::Class* proxy_class = rcvr->GetClass(); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 215 | ObjPtr<mirror::Method> interface_method = soa.Decode<mirror::Method>(interface_method_jobj); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 216 | ArtMethod* proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface( |
| 217 | interface_method->GetArtMethod(), kRuntimePointerSize); |
| 218 | auto virtual_methods = proxy_class->GetVirtualMethodsSlice(kRuntimePointerSize); |
| 219 | size_t num_virtuals = proxy_class->NumVirtualMethods(); |
| 220 | size_t method_size = ArtMethod::Size(kRuntimePointerSize); |
| 221 | // Rely on the fact that the methods are contiguous to determine the index of the method in |
| 222 | // the slice. |
| 223 | int throws_index = (reinterpret_cast<uintptr_t>(proxy_method) - |
| 224 | reinterpret_cast<uintptr_t>(&virtual_methods.At(0))) / method_size; |
| 225 | CHECK_LT(throws_index, static_cast<int>(num_virtuals)); |
| 226 | mirror::ObjectArray<mirror::Class>* declared_exceptions = |
| 227 | proxy_class->GetThrows()->Get(throws_index); |
| 228 | mirror::Class* exception_class = exception->GetClass(); |
| 229 | for (int32_t i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) { |
| 230 | mirror::Class* declared_exception = declared_exceptions->Get(i); |
| 231 | declares_exception = declared_exception->IsAssignableFrom(exception_class); |
| 232 | } |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 233 | } |
| 234 | if (!declares_exception) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 235 | soa.Self()->ThrowNewWrappedException("Ljava/lang/reflect/UndeclaredThrowableException;", |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 236 | nullptr); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | return zero; |
| 240 | } |
| 241 | } |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 242 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 243 | bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload) { |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 244 | DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); |
| 245 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 246 | ThrowNullPointerException("null array in FILL_ARRAY_DATA"); |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 247 | return false; |
| 248 | } |
| 249 | mirror::Array* array = obj->AsArray(); |
| 250 | DCHECK(!array->IsObjectArray()); |
| 251 | if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { |
| 252 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 253 | self->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 254 | "failed FILL_ARRAY_DATA; length=%d, index=%d", |
| 255 | array->GetLength(), payload->element_count); |
| 256 | return false; |
| 257 | } |
| 258 | // Copy data from dex file to memory assuming both are little endian. |
| 259 | uint32_t size_in_bytes = payload->element_count * payload->element_width; |
| 260 | memcpy(array->GetRawData(payload->element_width, 0), payload->data, size_in_bytes); |
| 261 | return true; |
| 262 | } |
| 263 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame^] | 264 | static inline std::pair<ArtMethod*, uintptr_t> DoGetCalleeSaveMethodOuterCallerAndPc( |
| 265 | ArtMethod** sp, Runtime::CalleeSaveType type) REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 266 | DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type)); |
| 267 | |
| 268 | const size_t callee_frame_size = GetCalleeSaveFrameSize(kRuntimeISA, type); |
| 269 | auto** caller_sp = reinterpret_cast<ArtMethod**>( |
| 270 | reinterpret_cast<uintptr_t>(sp) + callee_frame_size); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 271 | const size_t callee_return_pc_offset = GetCalleeSaveReturnPcOffset(kRuntimeISA, type); |
| 272 | uintptr_t caller_pc = *reinterpret_cast<uintptr_t*>( |
| 273 | (reinterpret_cast<uint8_t*>(sp) + callee_return_pc_offset)); |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 274 | ArtMethod* outer_method = *caller_sp; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame^] | 275 | return std::make_pair(outer_method, caller_pc); |
| 276 | } |
| 277 | |
| 278 | static inline ArtMethod* DoGetCalleeSaveMethodCaller(ArtMethod* outer_method, |
| 279 | uintptr_t caller_pc, |
| 280 | bool do_caller_check) |
| 281 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 282 | ArtMethod* caller = outer_method; |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 283 | if (LIKELY(caller_pc != reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()))) { |
| 284 | if (outer_method != nullptr) { |
| 285 | const OatQuickMethodHeader* current_code = outer_method->GetOatQuickMethodHeader(caller_pc); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 286 | DCHECK(current_code != nullptr); |
| 287 | DCHECK(current_code->IsOptimized()); |
| 288 | uintptr_t native_pc_offset = current_code->NativeQuickPcOffset(caller_pc); |
| 289 | CodeInfo code_info = current_code->GetOptimizedCodeInfo(); |
| 290 | CodeInfoEncoding encoding = code_info.ExtractEncoding(); |
| 291 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset, encoding); |
| 292 | DCHECK(stack_map.IsValid()); |
| 293 | if (stack_map.HasInlineInfo(encoding.stack_map_encoding)) { |
| 294 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding); |
| 295 | caller = GetResolvedMethod(outer_method, |
| 296 | inline_info, |
| 297 | encoding.inline_info_encoding, |
| 298 | inline_info.GetDepth(encoding.inline_info_encoding) - 1); |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 301 | if (kIsDebugBuild && do_caller_check) { |
| 302 | // Note that do_caller_check is optional, as this method can be called by |
| 303 | // stubs, and tests without a proper call stack. |
| 304 | NthCallerVisitor visitor(Thread::Current(), 1, true); |
| 305 | visitor.WalkStack(); |
| 306 | CHECK_EQ(caller, visitor.caller); |
| 307 | } |
| 308 | } else { |
| 309 | // We're instrumenting, just use the StackVisitor which knows how to |
| 310 | // handle instrumented frames. |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 311 | NthCallerVisitor visitor(Thread::Current(), 1, true); |
| 312 | visitor.WalkStack(); |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 313 | caller = visitor.caller; |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 314 | } |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 315 | return caller; |
| 316 | } |
| 317 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame^] | 318 | ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp, |
| 319 | Runtime::CalleeSaveType type, |
| 320 | bool do_caller_check) |
| 321 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 322 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
| 323 | auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type); |
| 324 | ArtMethod* outer_method = outer_caller_and_pc.first; |
| 325 | uintptr_t caller_pc = outer_caller_and_pc.second; |
| 326 | ArtMethod* caller = DoGetCalleeSaveMethodCaller(outer_method, caller_pc, do_caller_check); |
| 327 | return caller; |
| 328 | } |
| 329 | |
| 330 | CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, |
| 331 | Runtime::CalleeSaveType type) { |
| 332 | CallerAndOuterMethod result; |
| 333 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
| 334 | ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame(); |
| 335 | auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type); |
| 336 | result.outer_method = outer_caller_and_pc.first; |
| 337 | uintptr_t caller_pc = outer_caller_and_pc.second; |
| 338 | result.caller = |
| 339 | DoGetCalleeSaveMethodCaller(result.outer_method, caller_pc, /* do_caller_check */ true); |
| 340 | return result; |
| 341 | } |
| 342 | |
| 343 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 344 | } // namespace art |