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" |
David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 23 | #include "base/sdk_version.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "class_linker-inl.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 25 | #include "dex/dex_file-inl.h" |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 26 | #include "entrypoints/entrypoint_utils-inl.h" |
| 27 | #include "entrypoints/quick/callee_save_frame.h" |
| 28 | #include "entrypoints/runtime_asm_entrypoints.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 29 | #include "gc/accounting/card_table-inl.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 30 | #include "jni/java_vm_ext.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | #include "mirror/class-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" |
| 34 | #include "mirror/object_array-inl.h" |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 35 | #include "nth_caller_visitor.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 36 | #include "oat_quick_method_header.h" |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [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" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 39 | #include "well_known_classes.h" |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 40 | |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 41 | namespace art { |
| 42 | |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 43 | void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 44 | if (o == nullptr) { |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 47 | // 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] | 48 | ArtMethod* method = self->GetCurrentMethod(nullptr); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 49 | ObjPtr<mirror::Class> return_type = method->ResolveReturnType(); |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 50 | |
| 51 | if (!o->InstanceOf(return_type)) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 52 | Runtime::Current()->GetJavaVM()->JniAbortF(nullptr, |
| 53 | "attempt to return an instance of %s from %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 54 | o->PrettyTypeOf().c_str(), |
| 55 | method->PrettyMethod().c_str()); |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 59 | JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, |
| 60 | const char* shorty, |
| 61 | jobject rcvr_jobj, |
| 62 | jobject interface_method_jobj, |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 63 | std::vector<jvalue>& args) { |
| 64 | DCHECK(soa.Env()->IsInstanceOf(rcvr_jobj, WellKnownClasses::java_lang_reflect_Proxy)); |
| 65 | |
| 66 | // Build argument array possibly triggering GC. |
| 67 | soa.Self()->AssertThreadSuspensionIsAllowable(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 68 | jobjectArray args_jobj = nullptr; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 69 | const JValue zero; |
David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 70 | uint32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion(); |
Jeff Hao | f00571c | 2014-05-29 17:29:47 -0700 | [diff] [blame] | 71 | // Do not create empty arrays unless needed to maintain Dalvik bug compatibility. |
David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 72 | if (args.size() > 0 || IsSdkVersionSetAndAtMost(target_sdk_version, SdkVersion::kL)) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 73 | args_jobj = soa.Env()->NewObjectArray(args.size(), WellKnownClasses::java_lang_Object, nullptr); |
| 74 | if (args_jobj == nullptr) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 75 | CHECK(soa.Self()->IsExceptionPending()); |
| 76 | return zero; |
| 77 | } |
| 78 | for (size_t i = 0; i < args.size(); ++i) { |
| 79 | if (shorty[i + 1] == 'L') { |
Vladimir Marko | 35d5b8a | 2018-07-03 09:18:32 +0100 | [diff] [blame] | 80 | jobject val = args[i].l; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 81 | soa.Env()->SetObjectArrayElement(args_jobj, i, val); |
| 82 | } else { |
| 83 | JValue jv; |
Vladimir Marko | 35d5b8a | 2018-07-03 09:18:32 +0100 | [diff] [blame] | 84 | jv.SetJ(args[i].j); |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 85 | ObjPtr<mirror::Object> val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 86 | if (val == nullptr) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 87 | CHECK(soa.Self()->IsExceptionPending()); |
| 88 | return zero; |
| 89 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 90 | soa.Decode<mirror::ObjectArray<mirror::Object>>(args_jobj)->Set<false>(i, val); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 95 | // Call Proxy.invoke(Proxy proxy, Method method, Object[] args). |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 96 | jvalue invocation_args[3]; |
| 97 | invocation_args[0].l = rcvr_jobj; |
| 98 | invocation_args[1].l = interface_method_jobj; |
| 99 | invocation_args[2].l = args_jobj; |
| 100 | jobject result = |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 101 | soa.Env()->CallStaticObjectMethodA(WellKnownClasses::java_lang_reflect_Proxy, |
| 102 | WellKnownClasses::java_lang_reflect_Proxy_invoke, |
| 103 | invocation_args); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 104 | |
| 105 | // Unbox result and handle error conditions. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 106 | if (LIKELY(!soa.Self()->IsExceptionPending())) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 107 | if (shorty[0] == 'V' || (shorty[0] == 'L' && result == nullptr)) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 108 | // Do nothing. |
| 109 | return zero; |
| 110 | } else { |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 111 | ArtMethod* interface_method = |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 112 | soa.Decode<mirror::Method>(interface_method_jobj)->GetArtMethod(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 113 | // This can cause thread suspension. |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 114 | ObjPtr<mirror::Class> result_type = interface_method->ResolveReturnType(); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 115 | ObjPtr<mirror::Object> result_ref = soa.Decode<mirror::Object>(result); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 116 | JValue result_unboxed; |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 117 | if (!UnboxPrimitiveForResult(result_ref, result_type, &result_unboxed)) { |
Ian Rogers | 530f71c | 2013-02-22 23:29:00 -0800 | [diff] [blame] | 118 | DCHECK(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 119 | return zero; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 120 | } |
| 121 | return result_unboxed; |
| 122 | } |
| 123 | } else { |
| 124 | // In the case of checked exceptions that aren't declared, the exception must be wrapped by |
| 125 | // a UndeclaredThrowableException. |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 126 | ObjPtr<mirror::Throwable> exception = soa.Self()->GetException(); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 127 | if (exception->IsCheckedException()) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 128 | bool declares_exception = false; |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 129 | { |
| 130 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 131 | ObjPtr<mirror::Object> rcvr = soa.Decode<mirror::Object>(rcvr_jobj); |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 132 | ObjPtr<mirror::Class> proxy_class = rcvr->GetClass(); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 133 | ObjPtr<mirror::Method> interface_method = soa.Decode<mirror::Method>(interface_method_jobj); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 134 | ArtMethod* proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface( |
| 135 | interface_method->GetArtMethod(), kRuntimePointerSize); |
| 136 | auto virtual_methods = proxy_class->GetVirtualMethodsSlice(kRuntimePointerSize); |
| 137 | size_t num_virtuals = proxy_class->NumVirtualMethods(); |
| 138 | size_t method_size = ArtMethod::Size(kRuntimePointerSize); |
| 139 | // Rely on the fact that the methods are contiguous to determine the index of the method in |
| 140 | // the slice. |
| 141 | int throws_index = (reinterpret_cast<uintptr_t>(proxy_method) - |
Vladimir Marko | 9ac7749 | 2017-06-14 18:07:03 +0100 | [diff] [blame] | 142 | reinterpret_cast<uintptr_t>(&virtual_methods[0])) / method_size; |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 143 | CHECK_LT(throws_index, static_cast<int>(num_virtuals)); |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 144 | ObjPtr<mirror::ObjectArray<mirror::Class>> declared_exceptions = |
Narayan Kamath | 6b2dc31 | 2017-03-14 13:26:12 +0000 | [diff] [blame] | 145 | proxy_class->GetProxyThrows()->Get(throws_index); |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 146 | ObjPtr<mirror::Class> exception_class = exception->GetClass(); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 147 | for (int32_t i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) { |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 148 | ObjPtr<mirror::Class> declared_exception = declared_exceptions->Get(i); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 149 | declares_exception = declared_exception->IsAssignableFrom(exception_class); |
| 150 | } |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 151 | } |
| 152 | if (!declares_exception) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 153 | soa.Self()->ThrowNewWrappedException("Ljava/lang/reflect/UndeclaredThrowableException;", |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 154 | nullptr); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | return zero; |
| 158 | } |
| 159 | } |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 160 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 161 | bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload) { |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 162 | DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); |
| 163 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 164 | ThrowNullPointerException("null array in FILL_ARRAY_DATA"); |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 165 | return false; |
| 166 | } |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 167 | ObjPtr<mirror::Array> array = obj->AsArray(); |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 168 | DCHECK(!array->IsObjectArray()); |
| 169 | if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { |
| 170 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 171 | self->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 172 | "failed FILL_ARRAY_DATA; length=%d, index=%d", |
| 173 | array->GetLength(), payload->element_count); |
| 174 | return false; |
| 175 | } |
| 176 | // Copy data from dex file to memory assuming both are little endian. |
| 177 | uint32_t size_in_bytes = payload->element_count * payload->element_width; |
| 178 | memcpy(array->GetRawData(payload->element_width, 0), payload->data, size_in_bytes); |
| 179 | return true; |
| 180 | } |
| 181 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 182 | static inline std::pair<ArtMethod*, uintptr_t> DoGetCalleeSaveMethodOuterCallerAndPc( |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 183 | ArtMethod** sp, CalleeSaveType type) REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 184 | DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type)); |
| 185 | |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 186 | const size_t callee_frame_size = RuntimeCalleeSaveFrame::GetFrameSize(type); |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 187 | auto** caller_sp = reinterpret_cast<ArtMethod**>( |
| 188 | reinterpret_cast<uintptr_t>(sp) + callee_frame_size); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 189 | const size_t callee_return_pc_offset = RuntimeCalleeSaveFrame::GetReturnPcOffset(type); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 190 | uintptr_t caller_pc = *reinterpret_cast<uintptr_t*>( |
| 191 | (reinterpret_cast<uint8_t*>(sp) + callee_return_pc_offset)); |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 192 | ArtMethod* outer_method = *caller_sp; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 193 | return std::make_pair(outer_method, caller_pc); |
| 194 | } |
| 195 | |
| 196 | static inline ArtMethod* DoGetCalleeSaveMethodCaller(ArtMethod* outer_method, |
| 197 | uintptr_t caller_pc, |
| 198 | bool do_caller_check) |
| 199 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 200 | ArtMethod* caller = outer_method; |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 201 | if (LIKELY(caller_pc != reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()))) { |
| 202 | if (outer_method != nullptr) { |
| 203 | const OatQuickMethodHeader* current_code = outer_method->GetOatQuickMethodHeader(caller_pc); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 204 | DCHECK(current_code != nullptr); |
| 205 | DCHECK(current_code->IsOptimized()); |
David Srbecky | e42a4b9 | 2019-05-26 00:10:25 +0100 | [diff] [blame] | 206 | if (CodeInfo::HasInlineInfo(current_code->GetOptimizedCodeInfoPtr())) { |
| 207 | uintptr_t native_pc_offset = current_code->NativeQuickPcOffset(caller_pc); |
| 208 | CodeInfo code_info(current_code, CodeInfo::DecodeFlags::InlineInfoOnly); |
| 209 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
| 210 | DCHECK(stack_map.IsValid()); |
| 211 | BitTableRange<InlineInfo> inline_infos = code_info.GetInlineInfosOf(stack_map); |
| 212 | if (!inline_infos.empty()) { |
| 213 | caller = GetResolvedMethod(outer_method, code_info, inline_infos); |
| 214 | } |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 217 | if (kIsDebugBuild && do_caller_check) { |
| 218 | // Note that do_caller_check is optional, as this method can be called by |
| 219 | // stubs, and tests without a proper call stack. |
| 220 | NthCallerVisitor visitor(Thread::Current(), 1, true); |
| 221 | visitor.WalkStack(); |
| 222 | CHECK_EQ(caller, visitor.caller); |
| 223 | } |
| 224 | } else { |
| 225 | // We're instrumenting, just use the StackVisitor which knows how to |
| 226 | // handle instrumented frames. |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 227 | NthCallerVisitor visitor(Thread::Current(), 1, true); |
| 228 | visitor.WalkStack(); |
Nicolas Geoffray | 63e47f4 | 2015-11-05 13:26:17 +0000 | [diff] [blame] | 229 | caller = visitor.caller; |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 230 | } |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 231 | return caller; |
| 232 | } |
| 233 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 234 | ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp, CalleeSaveType type, bool do_caller_check) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 235 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 236 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
| 237 | auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type); |
| 238 | ArtMethod* outer_method = outer_caller_and_pc.first; |
| 239 | uintptr_t caller_pc = outer_caller_and_pc.second; |
| 240 | ArtMethod* caller = DoGetCalleeSaveMethodCaller(outer_method, caller_pc, do_caller_check); |
| 241 | return caller; |
| 242 | } |
| 243 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 244 | CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 245 | CallerAndOuterMethod result; |
| 246 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 247 | ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrameKnownNotTagged(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 248 | auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type); |
| 249 | result.outer_method = outer_caller_and_pc.first; |
| 250 | uintptr_t caller_pc = outer_caller_and_pc.second; |
| 251 | result.caller = |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 252 | DoGetCalleeSaveMethodCaller(result.outer_method, caller_pc, /* do_caller_check= */ true); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 253 | return result; |
| 254 | } |
| 255 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 256 | ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type) { |
Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 257 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 258 | ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrameKnownNotTagged(); |
Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 259 | return DoGetCalleeSaveMethodOuterCallerAndPc(sp, type).first; |
| 260 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 262 | ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer, |
| 263 | uint32_t method_handle_idx) { |
| 264 | Thread::PoisonObjectPointersIfDebug(); |
| 265 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 266 | return class_linker->ResolveMethodHandle(Thread::Current(), method_handle_idx, referrer); |
| 267 | } |
| 268 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 269 | ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 270 | dex::ProtoIndex proto_idx) { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 271 | Thread::PoisonObjectPointersIfDebug(); |
| 272 | ObjPtr<mirror::MethodType> method_type = |
| 273 | referrer->GetDexCache()->GetResolvedMethodType(proto_idx); |
| 274 | if (UNLIKELY(method_type == nullptr)) { |
| 275 | StackHandleScope<2> hs(Thread::Current()); |
| 276 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); |
| 277 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); |
| 278 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 279 | method_type = class_linker->ResolveMethodType(hs.Self(), proto_idx, dex_cache, class_loader); |
| 280 | } |
| 281 | return method_type; |
| 282 | } |
| 283 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 284 | } // namespace art |