Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "interpreter_common.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 18 | |
Andreas Gampe | f0e128a | 2015-02-27 20:08:34 -0800 | [diff] [blame] | 19 | #include <cmath> |
| 20 | |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 21 | #include "base/casts.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 22 | #include "base/enums.h" |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 23 | #include "class_root.h" |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 24 | #include "debugger.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 25 | #include "dex/dex_file_types.h" |
Nicolas Geoffray | 7bf2b4f | 2015-07-08 10:11:59 +0000 | [diff] [blame] | 26 | #include "entrypoints/runtime_asm_entrypoints.h" |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 27 | #include "handle.h" |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 28 | #include "intrinsics_enum.h" |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 29 | #include "jit/jit.h" |
Andreas Gampe | c5b7564 | 2018-05-16 15:12:11 -0700 | [diff] [blame] | 30 | #include "jvalue-inl.h" |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 31 | #include "method_handles-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 32 | #include "method_handles.h" |
Andreas Gampe | 8e0f043 | 2018-10-24 13:38:03 -0700 | [diff] [blame] | 33 | #include "mirror/array-alloc-inl.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
Vladimir Marko | 621c880 | 2019-03-27 16:18:18 +0000 | [diff] [blame] | 35 | #include "mirror/call_site-inl.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 36 | #include "mirror/class.h" |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 37 | #include "mirror/emulated_stack_frame.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 38 | #include "mirror/method_handle_impl-inl.h" |
Vladimir Marko | 5aead70 | 2019-03-27 11:00:36 +0000 | [diff] [blame] | 39 | #include "mirror/method_type-inl.h" |
Andreas Gampe | 52ecb65 | 2018-10-24 15:18:21 -0700 | [diff] [blame] | 40 | #include "mirror/object_array-alloc-inl.h" |
| 41 | #include "mirror/object_array-inl.h" |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 42 | #include "mirror/var_handle.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 43 | #include "reflection-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 44 | #include "reflection.h" |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 45 | #include "shadow_frame-inl.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 46 | #include "stack.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 47 | #include "thread-inl.h" |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 48 | #include "transaction.h" |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 49 | #include "var_handles.h" |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 50 | #include "well_known_classes.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 51 | |
| 52 | namespace art { |
| 53 | namespace interpreter { |
| 54 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 55 | void ThrowNullPointerExceptionFromInterpreter() { |
| 56 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 57 | } |
| 58 | |
David Srbecky | 960327b | 2018-10-25 10:11:59 +0000 | [diff] [blame] | 59 | bool CheckStackOverflow(Thread* self, size_t frame_size) |
| 60 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 61 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 62 | uint8_t* stack_end = self->GetStackEndForInterpreter(implicit_check); |
| 63 | if (UNLIKELY(__builtin_frame_address(0) < stack_end + frame_size)) { |
| 64 | ThrowStackOverflowError(self); |
| 65 | return false; |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
David Srbecky | 9581e61 | 2018-10-30 14:29:43 +0000 | [diff] [blame] | 70 | bool UseFastInterpreterToInterpreterInvoke(ArtMethod* method) { |
| 71 | Runtime* runtime = Runtime::Current(); |
| 72 | const void* quick_code = method->GetEntryPointFromQuickCompiledCode(); |
| 73 | if (!runtime->GetClassLinker()->IsQuickToInterpreterBridge(quick_code)) { |
| 74 | return false; |
| 75 | } |
| 76 | if (!method->SkipAccessChecks() || method->IsNative() || method->IsProxyMethod()) { |
| 77 | return false; |
| 78 | } |
| 79 | if (method->IsIntrinsic()) { |
| 80 | return false; |
| 81 | } |
| 82 | if (method->GetDeclaringClass()->IsStringClass() && method->IsConstructor()) { |
| 83 | return false; |
| 84 | } |
Vladimir Marko | baa81b5 | 2019-08-02 10:14:04 +0100 | [diff] [blame^] | 85 | if (method->IsStatic() && !method->GetDeclaringClass()->IsVisiblyInitialized()) { |
David Srbecky | 9581e61 | 2018-10-30 14:29:43 +0000 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | ProfilingInfo* profiling_info = method->GetProfilingInfo(kRuntimePointerSize); |
| 89 | if ((profiling_info != nullptr) && (profiling_info->GetSavedEntryPoint() != nullptr)) { |
| 90 | return false; |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 95 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 96 | bool transaction_active> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 97 | bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 98 | uint16_t inst_data) { |
| 99 | const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); |
| 100 | const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 101 | ArtField* f = |
| 102 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 103 | Primitive::ComponentSize(field_type)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 104 | if (UNLIKELY(f == nullptr)) { |
| 105 | CHECK(self->IsExceptionPending()); |
| 106 | return false; |
| 107 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 108 | ObjPtr<mirror::Object> obj; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 109 | if (is_static) { |
| 110 | obj = f->GetDeclaringClass(); |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 111 | if (transaction_active) { |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 112 | if (Runtime::Current()->GetTransaction()->ReadConstraint(self, obj, f)) { |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 113 | Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Can't read static fields of " |
| 114 | + obj->PrettyTypeOf() + " since it does not belong to clinit's class."); |
| 115 | return false; |
| 116 | } |
| 117 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 118 | } else { |
| 119 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 120 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 121 | ThrowNullPointerExceptionForFieldAccess(f, true); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 122 | return false; |
| 123 | } |
| 124 | } |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 125 | |
| 126 | JValue result; |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 127 | if (UNLIKELY(!DoFieldGetCommon<field_type>(self, shadow_frame, obj, f, &result))) { |
| 128 | // Instrumentation threw an error! |
| 129 | CHECK(self->IsExceptionPending()); |
| 130 | return false; |
| 131 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 132 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 133 | switch (field_type) { |
| 134 | case Primitive::kPrimBoolean: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 135 | shadow_frame.SetVReg(vregA, result.GetZ()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 136 | break; |
| 137 | case Primitive::kPrimByte: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 138 | shadow_frame.SetVReg(vregA, result.GetB()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 139 | break; |
| 140 | case Primitive::kPrimChar: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 141 | shadow_frame.SetVReg(vregA, result.GetC()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 142 | break; |
| 143 | case Primitive::kPrimShort: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 144 | shadow_frame.SetVReg(vregA, result.GetS()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 145 | break; |
| 146 | case Primitive::kPrimInt: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 147 | shadow_frame.SetVReg(vregA, result.GetI()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 148 | break; |
| 149 | case Primitive::kPrimLong: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 150 | shadow_frame.SetVRegLong(vregA, result.GetJ()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 151 | break; |
| 152 | case Primitive::kPrimNot: |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 153 | shadow_frame.SetVRegReference(vregA, result.GetL()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 154 | break; |
| 155 | default: |
| 156 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 157 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 158 | } |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | // Explicitly instantiate all DoFieldGet functions. |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 163 | #define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ |
| 164 | template bool DoFieldGet<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \ |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 165 | ShadowFrame& shadow_frame, \ |
| 166 | const Instruction* inst, \ |
| 167 | uint16_t inst_data) |
| 168 | |
| 169 | #define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 170 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, true); \ |
| 171 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, false); \ |
| 172 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, true); \ |
| 173 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, false); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 174 | |
| 175 | // iget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 176 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean) |
| 177 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte) |
| 178 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar) |
| 179 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort) |
| 180 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt) |
| 181 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong) |
| 182 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 183 | |
| 184 | // sget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 185 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean) |
| 186 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte) |
| 187 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar) |
| 188 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort) |
| 189 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt) |
| 190 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong) |
| 191 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 192 | |
| 193 | #undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL |
| 194 | #undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL |
| 195 | |
| 196 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 197 | // Returns true on success, otherwise throws an exception and returns false. |
| 198 | template<Primitive::Type field_type> |
| 199 | bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 200 | ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 201 | if (UNLIKELY(obj == nullptr)) { |
| 202 | // We lost the reference to the field index so we cannot get a more |
| 203 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 204 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 205 | return false; |
| 206 | } |
| 207 | MemberOffset field_offset(inst->VRegC_22c()); |
| 208 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 209 | // the field from the base of the object, we need to look for it first. |
| 210 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 211 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
| 212 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 213 | field_offset.Uint32Value()); |
| 214 | DCHECK(f != nullptr); |
| 215 | DCHECK(!f->IsStatic()); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 216 | Thread* self = Thread::Current(); |
| 217 | StackHandleScope<1> hs(self); |
Mathieu Chartier | a314773 | 2016-10-26 22:57:02 -0700 | [diff] [blame] | 218 | // Save obj in case the instrumentation event has thread suspension. |
| 219 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 220 | instrumentation->FieldReadEvent(self, |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 221 | obj, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 222 | shadow_frame.GetMethod(), |
| 223 | shadow_frame.GetDexPC(), |
| 224 | f); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 225 | if (UNLIKELY(self->IsExceptionPending())) { |
| 226 | return false; |
| 227 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 228 | } |
| 229 | // Note: iget-x-quick instructions are only for non-volatile fields. |
| 230 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 231 | switch (field_type) { |
| 232 | case Primitive::kPrimInt: |
| 233 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset))); |
| 234 | break; |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 235 | case Primitive::kPrimBoolean: |
| 236 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset))); |
| 237 | break; |
| 238 | case Primitive::kPrimByte: |
| 239 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset))); |
| 240 | break; |
| 241 | case Primitive::kPrimChar: |
| 242 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset))); |
| 243 | break; |
| 244 | case Primitive::kPrimShort: |
| 245 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset))); |
| 246 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 247 | case Primitive::kPrimLong: |
| 248 | shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset))); |
| 249 | break; |
| 250 | case Primitive::kPrimNot: |
| 251 | shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset)); |
| 252 | break; |
| 253 | default: |
| 254 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 255 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 256 | } |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | // Explicitly instantiate all DoIGetQuick functions. |
| 261 | #define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \ |
| 262 | template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 263 | uint16_t inst_data) |
| 264 | |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 265 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. |
| 266 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick. |
| 267 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick. |
| 268 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick. |
| 269 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick. |
| 270 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. |
| 271 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 272 | #undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL |
| 273 | |
| 274 | template<Primitive::Type field_type> |
| 275 | static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 276 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 277 | JValue field_value; |
| 278 | switch (field_type) { |
| 279 | case Primitive::kPrimBoolean: |
| 280 | field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); |
| 281 | break; |
| 282 | case Primitive::kPrimByte: |
| 283 | field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); |
| 284 | break; |
| 285 | case Primitive::kPrimChar: |
| 286 | field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); |
| 287 | break; |
| 288 | case Primitive::kPrimShort: |
| 289 | field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); |
| 290 | break; |
| 291 | case Primitive::kPrimInt: |
| 292 | field_value.SetI(shadow_frame.GetVReg(vreg)); |
| 293 | break; |
| 294 | case Primitive::kPrimLong: |
| 295 | field_value.SetJ(shadow_frame.GetVRegLong(vreg)); |
| 296 | break; |
| 297 | case Primitive::kPrimNot: |
| 298 | field_value.SetL(shadow_frame.GetVRegReference(vreg)); |
| 299 | break; |
| 300 | default: |
| 301 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 302 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 303 | } |
| 304 | return field_value; |
| 305 | } |
| 306 | |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 307 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 308 | bool transaction_active> |
| 309 | bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, |
| 310 | uint16_t inst_data) { |
| 311 | const bool do_assignability_check = do_access_check; |
| 312 | bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); |
| 313 | uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
| 314 | ArtField* f = |
| 315 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 316 | Primitive::ComponentSize(field_type)); |
| 317 | if (UNLIKELY(f == nullptr)) { |
| 318 | CHECK(self->IsExceptionPending()); |
| 319 | return false; |
| 320 | } |
| 321 | ObjPtr<mirror::Object> obj; |
| 322 | if (is_static) { |
| 323 | obj = f->GetDeclaringClass(); |
| 324 | } else { |
| 325 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 326 | if (UNLIKELY(obj == nullptr)) { |
| 327 | ThrowNullPointerExceptionForFieldAccess(f, false); |
| 328 | return false; |
| 329 | } |
| 330 | } |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 331 | if (transaction_active) { |
| 332 | Runtime* runtime = Runtime::Current(); |
| 333 | if (runtime->GetTransaction()->WriteConstraint(self, obj, f)) { |
| 334 | if (is_static) { |
| 335 | runtime->AbortTransactionAndThrowAbortError( |
| 336 | self, "Can't set fields of " + obj->PrettyTypeOf()); |
| 337 | } else { |
| 338 | // This can happen only when compiling a boot image extension. |
| 339 | DCHECK(!runtime->GetTransaction()->IsStrict()); |
| 340 | DCHECK(runtime->GetHeap()->ObjectIsInBootImageSpace(obj)); |
| 341 | runtime->AbortTransactionAndThrowAbortError( |
| 342 | self, "Can't set fields of boot image objects"); |
| 343 | } |
| 344 | return false; |
| 345 | } |
| 346 | } |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 347 | |
| 348 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
Orion Hodson | ba28f9f | 2016-10-26 10:56:25 +0100 | [diff] [blame] | 349 | JValue value = GetFieldValue<field_type>(shadow_frame, vregA); |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 350 | return DoFieldPutCommon<field_type, do_assignability_check, transaction_active>(self, |
| 351 | shadow_frame, |
| 352 | obj, |
| 353 | f, |
Orion Hodson | ba28f9f | 2016-10-26 10:56:25 +0100 | [diff] [blame] | 354 | value); |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 357 | // Explicitly instantiate all DoFieldPut functions. |
| 358 | #define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ |
| 359 | template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \ |
| 360 | const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
| 361 | |
| 362 | #define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 363 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \ |
| 364 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \ |
| 365 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \ |
| 366 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true); |
| 367 | |
| 368 | // iput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 369 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean) |
| 370 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte) |
| 371 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar) |
| 372 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort) |
| 373 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt) |
| 374 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong) |
| 375 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 376 | |
| 377 | // sput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 378 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean) |
| 379 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte) |
| 380 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar) |
| 381 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort) |
| 382 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt) |
| 383 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong) |
| 384 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 385 | |
| 386 | #undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL |
| 387 | #undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL |
| 388 | |
| 389 | template<Primitive::Type field_type, bool transaction_active> |
| 390 | bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 391 | ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 392 | if (UNLIKELY(obj == nullptr)) { |
| 393 | // We lost the reference to the field index so we cannot get a more |
| 394 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 395 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 396 | return false; |
| 397 | } |
| 398 | MemberOffset field_offset(inst->VRegC_22c()); |
| 399 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 400 | // Report this field modification to instrumentation if needed. Since we only have the offset of |
| 401 | // the field from the base of the object, we need to look for it first. |
| 402 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 403 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 404 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 405 | field_offset.Uint32Value()); |
| 406 | DCHECK(f != nullptr); |
| 407 | DCHECK(!f->IsStatic()); |
| 408 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 409 | Thread* self = Thread::Current(); |
| 410 | StackHandleScope<2> hs(self); |
Mathieu Chartier | a314773 | 2016-10-26 22:57:02 -0700 | [diff] [blame] | 411 | // Save obj in case the instrumentation event has thread suspension. |
| 412 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 413 | mirror::Object* fake_root = nullptr; |
| 414 | HandleWrapper<mirror::Object> ret(hs.NewHandleWrapper<mirror::Object>( |
| 415 | field_type == Primitive::kPrimNot ? field_value.GetGCRoot() : &fake_root)); |
| 416 | instrumentation->FieldWriteEvent(self, |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 417 | obj, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 418 | shadow_frame.GetMethod(), |
| 419 | shadow_frame.GetDexPC(), |
| 420 | f, |
| 421 | field_value); |
Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 422 | if (UNLIKELY(self->IsExceptionPending())) { |
| 423 | return false; |
| 424 | } |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 425 | if (UNLIKELY(shadow_frame.GetForcePopFrame())) { |
| 426 | // Don't actually set the field. The next instruction will force us to pop. |
| 427 | DCHECK(Runtime::Current()->AreNonStandardExitsEnabled()); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 428 | return true; |
| 429 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 430 | } |
| 431 | // Note: iput-x-quick instructions are only for non-volatile fields. |
| 432 | switch (field_type) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 433 | case Primitive::kPrimBoolean: |
| 434 | obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 435 | break; |
| 436 | case Primitive::kPrimByte: |
| 437 | obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 438 | break; |
| 439 | case Primitive::kPrimChar: |
| 440 | obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 441 | break; |
| 442 | case Primitive::kPrimShort: |
| 443 | obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 444 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 445 | case Primitive::kPrimInt: |
| 446 | obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 447 | break; |
| 448 | case Primitive::kPrimLong: |
| 449 | obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA)); |
| 450 | break; |
| 451 | case Primitive::kPrimNot: |
| 452 | obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA)); |
| 453 | break; |
| 454 | default: |
| 455 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 456 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 457 | } |
| 458 | return true; |
| 459 | } |
| 460 | |
| 461 | // Explicitly instantiate all DoIPutQuick functions. |
| 462 | #define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \ |
| 463 | template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \ |
| 464 | const Instruction* inst, \ |
| 465 | uint16_t inst_data) |
| 466 | |
| 467 | #define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \ |
| 468 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \ |
| 469 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true); |
| 470 | |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 471 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick. |
| 472 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick. |
| 473 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick. |
| 474 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick. |
| 475 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick. |
| 476 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick. |
| 477 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 478 | #undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL |
| 479 | #undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL |
| 480 | |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 481 | template <typename T> |
| 482 | bool SendMethodExitEvents(Thread* self, |
| 483 | const instrumentation::Instrumentation* instrumentation, |
| 484 | ShadowFrame& frame, |
| 485 | ObjPtr<mirror::Object> thiz, |
| 486 | ArtMethod* method, |
| 487 | uint32_t dex_pc, |
| 488 | T& result) { |
| 489 | bool had_event = false; |
| 490 | // We can get additional ForcePopFrame requests during handling of these events. We should |
| 491 | // respect these and send additional instrumentation events. |
| 492 | StackHandleScope<1> hs(self); |
| 493 | Handle<mirror::Object> h_thiz(hs.NewHandle(thiz)); |
| 494 | do { |
| 495 | frame.SetForcePopFrame(false); |
| 496 | if (UNLIKELY(instrumentation->HasMethodExitListeners() && !frame.GetSkipMethodExitEvents())) { |
| 497 | had_event = true; |
| 498 | instrumentation->MethodExitEvent( |
| 499 | self, h_thiz.Get(), method, dex_pc, instrumentation::OptionalFrame{ frame }, result); |
| 500 | } |
| 501 | // We don't send method-exit if it's a pop-frame. We still send frame_popped though. |
| 502 | if (UNLIKELY(frame.NeedsNotifyPop() && instrumentation->HasWatchedFramePopListeners())) { |
| 503 | had_event = true; |
| 504 | instrumentation->WatchedFramePopped(self, frame); |
| 505 | } |
| 506 | } while (UNLIKELY(frame.GetForcePopFrame())); |
| 507 | if (UNLIKELY(had_event)) { |
| 508 | return !self->IsExceptionPending(); |
| 509 | } else { |
| 510 | return true; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | template |
| 515 | bool SendMethodExitEvents(Thread* self, |
| 516 | const instrumentation::Instrumentation* instrumentation, |
| 517 | ShadowFrame& frame, |
| 518 | ObjPtr<mirror::Object> thiz, |
| 519 | ArtMethod* method, |
| 520 | uint32_t dex_pc, |
| 521 | MutableHandle<mirror::Object>& result); |
| 522 | |
| 523 | template |
| 524 | bool SendMethodExitEvents(Thread* self, |
| 525 | const instrumentation::Instrumentation* instrumentation, |
| 526 | ShadowFrame& frame, |
| 527 | ObjPtr<mirror::Object> thiz, |
| 528 | ArtMethod* method, |
| 529 | uint32_t dex_pc, |
| 530 | JValue& result); |
| 531 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 532 | // We execute any instrumentation events that are triggered by this exception and change the |
| 533 | // shadow_frame's dex_pc to that of the exception handler if there is one in the current method. |
| 534 | // Return true if we should continue executing in the current method and false if we need to go up |
| 535 | // the stack to find an exception handler. |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 536 | // We accept a null Instrumentation* meaning we must not report anything to the instrumentation. |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 537 | // TODO We should have a better way to skip instrumentation reporting or possibly rethink that |
| 538 | // behavior. |
| 539 | bool MoveToExceptionHandler(Thread* self, |
| 540 | ShadowFrame& shadow_frame, |
| 541 | const instrumentation::Instrumentation* instrumentation) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 542 | self->VerifyStack(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 543 | StackHandleScope<2> hs(self); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 544 | Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException())); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 545 | if (instrumentation != nullptr && |
| 546 | instrumentation->HasExceptionThrownListeners() && |
| 547 | self->IsExceptionThrownByCurrentMethod(exception.Get())) { |
| 548 | // See b/65049545 for why we don't need to check to see if the exception has changed. |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 549 | instrumentation->ExceptionThrownEvent(self, exception.Get()); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 550 | if (shadow_frame.GetForcePopFrame()) { |
| 551 | // We will check in the caller for GetForcePopFrame again. We need to bail out early to |
| 552 | // prevent an ExceptionHandledEvent from also being sent before popping. |
| 553 | return true; |
| 554 | } |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 555 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 556 | bool clear_exception = false; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 557 | uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock( |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 558 | hs.NewHandle(exception->GetClass()), shadow_frame.GetDexPC(), &clear_exception); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 559 | if (found_dex_pc == dex::kDexNoIndex) { |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 560 | if (instrumentation != nullptr) { |
| 561 | if (shadow_frame.NeedsNotifyPop()) { |
| 562 | instrumentation->WatchedFramePopped(self, shadow_frame); |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 563 | if (shadow_frame.GetForcePopFrame()) { |
| 564 | // We will check in the caller for GetForcePopFrame again. We need to bail out early to |
| 565 | // prevent an ExceptionHandledEvent from also being sent before popping and to ensure we |
| 566 | // handle other types of non-standard-exits. |
| 567 | return true; |
| 568 | } |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 569 | } |
| 570 | // Exception is not caught by the current method. We will unwind to the |
| 571 | // caller. Notify any instrumentation listener. |
| 572 | instrumentation->MethodUnwindEvent(self, |
| 573 | shadow_frame.GetThisObject(), |
| 574 | shadow_frame.GetMethod(), |
| 575 | shadow_frame.GetDexPC()); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 576 | } |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 577 | return shadow_frame.GetForcePopFrame(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 578 | } else { |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 579 | shadow_frame.SetDexPC(found_dex_pc); |
| 580 | if (instrumentation != nullptr && instrumentation->HasExceptionHandledListeners()) { |
| 581 | self->ClearException(); |
| 582 | instrumentation->ExceptionHandledEvent(self, exception.Get()); |
| 583 | if (UNLIKELY(self->IsExceptionPending())) { |
| 584 | // Exception handled event threw an exception. Try to find the handler for this one. |
| 585 | return MoveToExceptionHandler(self, shadow_frame, instrumentation); |
| 586 | } else if (!clear_exception) { |
| 587 | self->SetException(exception.Get()); |
| 588 | } |
| 589 | } else if (clear_exception) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 590 | self->ClearException(); |
| 591 | } |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 592 | return true; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 593 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 596 | void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) { |
| 597 | LOG(FATAL) << "Unexpected instruction: " |
| 598 | << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()); |
| 599 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 602 | void AbortTransactionF(Thread* self, const char* fmt, ...) { |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 603 | va_list args; |
| 604 | va_start(args, fmt); |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 605 | AbortTransactionV(self, fmt, args); |
| 606 | va_end(args); |
| 607 | } |
| 608 | |
| 609 | void AbortTransactionV(Thread* self, const char* fmt, va_list args) { |
| 610 | CHECK(Runtime::Current()->IsActiveTransaction()); |
| 611 | // Constructs abort message. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 612 | std::string abort_msg; |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 613 | android::base::StringAppendV(&abort_msg, fmt, args); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 614 | // Throws an exception so we can abort the transaction and rollback every change. |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 615 | Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg); |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 618 | // START DECLARATIONS : |
| 619 | // |
| 620 | // These additional declarations are required because clang complains |
| 621 | // about ALWAYS_INLINE (-Werror, -Wgcc-compat) in definitions. |
| 622 | // |
| 623 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 624 | template <bool is_range, bool do_assignability_check> |
Vladimir Marko | d16363a | 2017-02-01 14:09:13 +0000 | [diff] [blame] | 625 | static ALWAYS_INLINE bool DoCallCommon(ArtMethod* called_method, |
| 626 | Thread* self, |
| 627 | ShadowFrame& shadow_frame, |
| 628 | JValue* result, |
| 629 | uint16_t number_of_inputs, |
| 630 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 631 | uint32_t vregC) REQUIRES_SHARED(Locks::mutator_lock_); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 632 | |
| 633 | template <bool is_range> |
Narayan Kamath | 2cb856c | 2016-11-02 12:01:26 +0000 | [diff] [blame] | 634 | ALWAYS_INLINE void CopyRegisters(ShadowFrame& caller_frame, |
| 635 | ShadowFrame* callee_frame, |
| 636 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 637 | const size_t first_src_reg, |
| 638 | const size_t first_dest_reg, |
| 639 | const size_t num_regs) REQUIRES_SHARED(Locks::mutator_lock_); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 640 | |
| 641 | // END DECLARATIONS. |
| 642 | |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 643 | void ArtInterpreterToCompiledCodeBridge(Thread* self, |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 644 | ArtMethod* caller, |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 645 | ShadowFrame* shadow_frame, |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 646 | uint16_t arg_offset, |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 647 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 648 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 649 | ArtMethod* method = shadow_frame->GetMethod(); |
| 650 | // Ensure static methods are initialized. |
| 651 | if (method->IsStatic()) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 652 | ObjPtr<mirror::Class> declaringClass = method->GetDeclaringClass(); |
Vladimir Marko | baa81b5 | 2019-08-02 10:14:04 +0100 | [diff] [blame^] | 653 | if (UNLIKELY(!declaringClass->IsVisiblyInitialized())) { |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 654 | self->PushShadowFrame(shadow_frame); |
| 655 | StackHandleScope<1> hs(self); |
| 656 | Handle<mirror::Class> h_class(hs.NewHandle(declaringClass)); |
Vladimir Marko | baa81b5 | 2019-08-02 10:14:04 +0100 | [diff] [blame^] | 657 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
| 658 | self, h_class, /*can_init_fields=*/ true, /*can_init_parents=*/ true))) { |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 659 | self->PopShadowFrame(); |
| 660 | DCHECK(self->IsExceptionPending()); |
| 661 | return; |
| 662 | } |
| 663 | self->PopShadowFrame(); |
Vladimir Marko | baa81b5 | 2019-08-02 10:14:04 +0100 | [diff] [blame^] | 664 | DCHECK(h_class->IsInitializing()); |
Nicolas Geoffray | 0182229 | 2017-03-09 09:03:19 +0000 | [diff] [blame] | 665 | // Reload from shadow frame in case the method moved, this is faster than adding a handle. |
| 666 | method = shadow_frame->GetMethod(); |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 669 | // Basic checks for the arg_offset. If there's no code item, the arg_offset must be 0. Otherwise, |
| 670 | // check that the arg_offset isn't greater than the number of registers. A stronger check is |
| 671 | // difficult since the frame may contain space for all the registers in the method, or only enough |
| 672 | // space for the arguments. |
| 673 | if (kIsDebugBuild) { |
| 674 | if (method->GetCodeItem() == nullptr) { |
| 675 | DCHECK_EQ(0u, arg_offset) << method->PrettyMethod(); |
| 676 | } else { |
| 677 | DCHECK_LE(arg_offset, shadow_frame->NumberOfVRegs()); |
| 678 | } |
| 679 | } |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 680 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 681 | if (jit != nullptr && caller != nullptr) { |
| 682 | jit->NotifyInterpreterToCompiledCodeTransition(self, caller); |
| 683 | } |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 684 | method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset), |
| 685 | (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 686 | result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty()); |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 689 | void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame, |
| 690 | uint16_t this_obj_vreg, |
| 691 | JValue result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 692 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 693 | ObjPtr<mirror::Object> existing = shadow_frame->GetVRegReference(this_obj_vreg); |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 694 | if (existing == nullptr) { |
| 695 | // If it's null, we come from compiled code that was deoptimized. Nothing to do, |
| 696 | // as the compiler verified there was no alias. |
| 697 | // Set the new string result of the StringFactory. |
| 698 | shadow_frame->SetVRegReference(this_obj_vreg, result.GetL()); |
| 699 | return; |
| 700 | } |
| 701 | // Set the string init result into all aliases. |
| 702 | for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) { |
| 703 | if (shadow_frame->GetVRegReference(i) == existing) { |
| 704 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 705 | reinterpret_cast32<mirror::Object*>(shadow_frame->GetVReg(i))); |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 706 | shadow_frame->SetVRegReference(i, result.GetL()); |
| 707 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 708 | reinterpret_cast32<mirror::Object*>(shadow_frame->GetVReg(i))); |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 713 | template<bool is_range> |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 714 | static bool DoMethodHandleInvokeCommon(Thread* self, |
| 715 | ShadowFrame& shadow_frame, |
| 716 | bool invoke_exact, |
| 717 | const Instruction* inst, |
| 718 | uint16_t inst_data, |
| 719 | JValue* result) |
Orion Hodson | ba28f9f | 2016-10-26 10:56:25 +0100 | [diff] [blame] | 720 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Alex Light | 848574c | 2017-09-25 16:59:39 -0700 | [diff] [blame] | 721 | // Make sure to check for async exceptions |
| 722 | if (UNLIKELY(self->ObserveAsyncException())) { |
| 723 | return false; |
| 724 | } |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 725 | // Invoke-polymorphic instructions always take a receiver. i.e, they are never static. |
| 726 | const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc(); |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 727 | const int invoke_method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc(); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 728 | |
Orion Hodson | 1a06f9f | 2016-11-09 08:32:42 +0000 | [diff] [blame] | 729 | // Initialize |result| to 0 as this is the default return value for |
| 730 | // polymorphic invocations of method handle types with void return |
| 731 | // and provides sane return result in error cases. |
| 732 | result->SetJ(0); |
| 733 | |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 734 | // The invoke_method_idx here is the name of the signature polymorphic method that |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 735 | // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact) |
| 736 | // and not the method that we'll dispatch to in the end. |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 737 | StackHandleScope<2> hs(self); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 738 | Handle<mirror::MethodHandle> method_handle(hs.NewHandle( |
Vladimir Marko | d7e9bbf | 2019-03-28 13:18:57 +0000 | [diff] [blame] | 739 | ObjPtr<mirror::MethodHandle>::DownCast(shadow_frame.GetVRegReference(vRegC)))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 740 | if (UNLIKELY(method_handle == nullptr)) { |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 741 | // Note that the invoke type is kVirtual here because a call to a signature |
| 742 | // polymorphic method is shaped like a virtual call at the bytecode level. |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 743 | ThrowNullPointerExceptionForMethodAccess(invoke_method_idx, InvokeType::kVirtual); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 744 | return false; |
| 745 | } |
| 746 | |
| 747 | // The vRegH value gives the index of the proto_id associated with this |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 748 | // signature polymorphic call site. |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 749 | const uint16_t vRegH = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc(); |
| 750 | const dex::ProtoIndex callsite_proto_id(vRegH); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 751 | |
| 752 | // Call through to the classlinker and ask it to resolve the static type associated |
| 753 | // with the callsite. This information is stored in the dex cache so it's |
| 754 | // guaranteed to be fast after the first resolution. |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 755 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 756 | Handle<mirror::MethodType> callsite_type(hs.NewHandle( |
| 757 | class_linker->ResolveMethodType(self, callsite_proto_id, shadow_frame.GetMethod()))); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 758 | |
| 759 | // This implies we couldn't resolve one or more types in this method handle. |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 760 | if (UNLIKELY(callsite_type == nullptr)) { |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 761 | CHECK(self->IsExceptionPending()); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 762 | return false; |
| 763 | } |
| 764 | |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 765 | // There is a common dispatch method for method handles that takes |
| 766 | // arguments either from a range or an array of arguments depending |
| 767 | // on whether the DEX instruction is invoke-polymorphic/range or |
| 768 | // invoke-polymorphic. The array here is for the latter. |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 769 | if (UNLIKELY(is_range)) { |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 770 | // VRegC is the register holding the method handle. Arguments passed |
| 771 | // to the method handle's target do not include the method handle. |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 772 | RangeInstructionOperands operands(inst->VRegC_4rcc() + 1, inst->VRegA_4rcc() - 1); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 773 | if (invoke_exact) { |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 774 | return MethodHandleInvokeExact(self, |
| 775 | shadow_frame, |
| 776 | method_handle, |
| 777 | callsite_type, |
| 778 | &operands, |
| 779 | result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 780 | } else { |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 781 | return MethodHandleInvoke(self, |
| 782 | shadow_frame, |
| 783 | method_handle, |
| 784 | callsite_type, |
| 785 | &operands, |
| 786 | result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 787 | } |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 788 | } else { |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 789 | // Get the register arguments for the invoke. |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 790 | uint32_t args[Instruction::kMaxVarArgRegs] = {}; |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 791 | inst->GetVarArgs(args, inst_data); |
| 792 | // Drop the first register which is the method handle performing the invoke. |
Alexey Frunze | 8631a46 | 2017-01-19 19:07:37 -0800 | [diff] [blame] | 793 | memmove(args, args + 1, sizeof(args[0]) * (Instruction::kMaxVarArgRegs - 1)); |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 794 | args[Instruction::kMaxVarArgRegs - 1] = 0; |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 795 | VarArgsInstructionOperands operands(args, inst->VRegA_45cc() - 1); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 796 | if (invoke_exact) { |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 797 | return MethodHandleInvokeExact(self, |
| 798 | shadow_frame, |
| 799 | method_handle, |
| 800 | callsite_type, |
| 801 | &operands, |
| 802 | result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 803 | } else { |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 804 | return MethodHandleInvoke(self, |
| 805 | shadow_frame, |
| 806 | method_handle, |
| 807 | callsite_type, |
| 808 | &operands, |
| 809 | result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | bool DoMethodHandleInvokeExact(Thread* self, |
| 815 | ShadowFrame& shadow_frame, |
| 816 | const Instruction* inst, |
| 817 | uint16_t inst_data, |
| 818 | JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 819 | if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) { |
| 820 | static const bool kIsRange = false; |
| 821 | return DoMethodHandleInvokeCommon<kIsRange>( |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 822 | self, shadow_frame, /* invoke_exact= */ true, inst, inst_data, result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 823 | } else { |
| 824 | DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE); |
| 825 | static const bool kIsRange = true; |
| 826 | return DoMethodHandleInvokeCommon<kIsRange>( |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 827 | self, shadow_frame, /* invoke_exact= */ true, inst, inst_data, result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
| 831 | bool DoMethodHandleInvoke(Thread* self, |
| 832 | ShadowFrame& shadow_frame, |
| 833 | const Instruction* inst, |
| 834 | uint16_t inst_data, |
| 835 | JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 836 | if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) { |
| 837 | static const bool kIsRange = false; |
| 838 | return DoMethodHandleInvokeCommon<kIsRange>( |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 839 | self, shadow_frame, /* invoke_exact= */ false, inst, inst_data, result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 840 | } else { |
| 841 | DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE); |
| 842 | static const bool kIsRange = true; |
| 843 | return DoMethodHandleInvokeCommon<kIsRange>( |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 844 | self, shadow_frame, /* invoke_exact= */ false, inst, inst_data, result); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 848 | static bool DoVarHandleInvokeCommon(Thread* self, |
| 849 | ShadowFrame& shadow_frame, |
| 850 | const Instruction* inst, |
| 851 | uint16_t inst_data, |
| 852 | JValue* result, |
| 853 | mirror::VarHandle::AccessMode access_mode) |
| 854 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 855 | // Make sure to check for async exceptions |
| 856 | if (UNLIKELY(self->ObserveAsyncException())) { |
| 857 | return false; |
| 858 | } |
| 859 | |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 860 | StackHandleScope<2> hs(self); |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 861 | bool is_var_args = inst->HasVarArgs(); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 862 | const uint16_t vRegH = is_var_args ? inst->VRegH_45cc() : inst->VRegH_4rcc(); |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 863 | ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); |
| 864 | Handle<mirror::MethodType> callsite_type(hs.NewHandle( |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 865 | class_linker->ResolveMethodType(self, dex::ProtoIndex(vRegH), shadow_frame.GetMethod()))); |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 866 | // This implies we couldn't resolve one or more types in this VarHandle. |
| 867 | if (UNLIKELY(callsite_type == nullptr)) { |
| 868 | CHECK(self->IsExceptionPending()); |
| 869 | return false; |
| 870 | } |
| 871 | |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 872 | const uint32_t vRegC = is_var_args ? inst->VRegC_45cc() : inst->VRegC_4rcc(); |
| 873 | ObjPtr<mirror::Object> receiver(shadow_frame.GetVRegReference(vRegC)); |
Vladimir Marko | 179b7c6 | 2019-03-22 13:38:57 +0000 | [diff] [blame] | 874 | Handle<mirror::VarHandle> var_handle(hs.NewHandle(ObjPtr<mirror::VarHandle>::DownCast(receiver))); |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 875 | if (is_var_args) { |
| 876 | uint32_t args[Instruction::kMaxVarArgRegs]; |
| 877 | inst->GetVarArgs(args, inst_data); |
| 878 | VarArgsInstructionOperands all_operands(args, inst->VRegA_45cc()); |
| 879 | NoReceiverInstructionOperands operands(&all_operands); |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 880 | return VarHandleInvokeAccessor(self, |
| 881 | shadow_frame, |
| 882 | var_handle, |
| 883 | callsite_type, |
| 884 | access_mode, |
| 885 | &operands, |
| 886 | result); |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 887 | } else { |
| 888 | RangeInstructionOperands all_operands(inst->VRegC_4rcc(), inst->VRegA_4rcc()); |
| 889 | NoReceiverInstructionOperands operands(&all_operands); |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 890 | return VarHandleInvokeAccessor(self, |
| 891 | shadow_frame, |
| 892 | var_handle, |
| 893 | callsite_type, |
| 894 | access_mode, |
| 895 | &operands, |
| 896 | result); |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 897 | } |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 898 | } |
| 899 | |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 900 | #define DO_VAR_HANDLE_ACCESSOR(_access_mode) \ |
| 901 | bool DoVarHandle ## _access_mode(Thread* self, \ |
| 902 | ShadowFrame& shadow_frame, \ |
| 903 | const Instruction* inst, \ |
| 904 | uint16_t inst_data, \ |
| 905 | JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { \ |
| 906 | const auto access_mode = mirror::VarHandle::AccessMode::k ## _access_mode; \ |
| 907 | return DoVarHandleInvokeCommon(self, shadow_frame, inst, inst_data, result, access_mode); \ |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 910 | DO_VAR_HANDLE_ACCESSOR(CompareAndExchange) |
| 911 | DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeAcquire) |
| 912 | DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeRelease) |
| 913 | DO_VAR_HANDLE_ACCESSOR(CompareAndSet) |
| 914 | DO_VAR_HANDLE_ACCESSOR(Get) |
| 915 | DO_VAR_HANDLE_ACCESSOR(GetAcquire) |
| 916 | DO_VAR_HANDLE_ACCESSOR(GetAndAdd) |
| 917 | DO_VAR_HANDLE_ACCESSOR(GetAndAddAcquire) |
| 918 | DO_VAR_HANDLE_ACCESSOR(GetAndAddRelease) |
| 919 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAnd) |
| 920 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndAcquire) |
| 921 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndRelease) |
| 922 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOr) |
| 923 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrAcquire) |
| 924 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrRelease) |
| 925 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXor) |
| 926 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorAcquire) |
| 927 | DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorRelease) |
| 928 | DO_VAR_HANDLE_ACCESSOR(GetAndSet) |
| 929 | DO_VAR_HANDLE_ACCESSOR(GetAndSetAcquire) |
| 930 | DO_VAR_HANDLE_ACCESSOR(GetAndSetRelease) |
| 931 | DO_VAR_HANDLE_ACCESSOR(GetOpaque) |
| 932 | DO_VAR_HANDLE_ACCESSOR(GetVolatile) |
| 933 | DO_VAR_HANDLE_ACCESSOR(Set) |
| 934 | DO_VAR_HANDLE_ACCESSOR(SetOpaque) |
| 935 | DO_VAR_HANDLE_ACCESSOR(SetRelease) |
| 936 | DO_VAR_HANDLE_ACCESSOR(SetVolatile) |
| 937 | DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSet) |
| 938 | DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetAcquire) |
| 939 | DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetPlain) |
| 940 | DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetRelease) |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 941 | |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 942 | #undef DO_VAR_HANDLE_ACCESSOR |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 943 | |
| 944 | template<bool is_range> |
| 945 | bool DoInvokePolymorphic(Thread* self, |
| 946 | ShadowFrame& shadow_frame, |
| 947 | const Instruction* inst, |
| 948 | uint16_t inst_data, |
| 949 | JValue* result) { |
| 950 | const int invoke_method_idx = inst->VRegB(); |
| 951 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 952 | ArtMethod* invoke_method = |
| 953 | class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
| 954 | self, invoke_method_idx, shadow_frame.GetMethod(), kVirtual); |
| 955 | |
| 956 | // Ensure intrinsic identifiers are initialized. |
| 957 | DCHECK(invoke_method->IsIntrinsic()); |
| 958 | |
| 959 | // Dispatch based on intrinsic identifier associated with method. |
| 960 | switch (static_cast<art::Intrinsics>(invoke_method->GetIntrinsic())) { |
| 961 | #define CASE_SIGNATURE_POLYMORPHIC_INTRINSIC(Name, ...) \ |
| 962 | case Intrinsics::k##Name: \ |
| 963 | return Do ## Name(self, shadow_frame, inst, inst_data, result); |
| 964 | #include "intrinsics_list.h" |
| 965 | SIGNATURE_POLYMORPHIC_INTRINSICS_LIST(CASE_SIGNATURE_POLYMORPHIC_INTRINSIC) |
| 966 | #undef INTRINSICS_LIST |
| 967 | #undef SIGNATURE_POLYMORPHIC_INTRINSICS_LIST |
| 968 | #undef CASE_SIGNATURE_POLYMORPHIC_INTRINSIC |
| 969 | default: |
| 970 | LOG(FATAL) << "Unreachable: " << invoke_method->GetIntrinsic(); |
| 971 | UNREACHABLE(); |
| 972 | return false; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 976 | static JValue ConvertScalarBootstrapArgument(jvalue value) { |
| 977 | // value either contains a primitive scalar value if it corresponds |
| 978 | // to a primitive type, or it contains an integer value if it |
| 979 | // corresponds to an object instance reference id (e.g. a string id). |
| 980 | return JValue::FromPrimitive(value.j); |
| 981 | } |
| 982 | |
| 983 | static ObjPtr<mirror::Class> GetClassForBootstrapArgument(EncodedArrayValueIterator::ValueType type) |
| 984 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 985 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 986 | ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots = class_linker->GetClassRoots(); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 987 | switch (type) { |
| 988 | case EncodedArrayValueIterator::ValueType::kBoolean: |
| 989 | case EncodedArrayValueIterator::ValueType::kByte: |
| 990 | case EncodedArrayValueIterator::ValueType::kChar: |
| 991 | case EncodedArrayValueIterator::ValueType::kShort: |
| 992 | // These types are disallowed by JVMS. Treat as integers. This |
| 993 | // will result in CCE's being raised if the BSM has one of these |
| 994 | // types. |
| 995 | case EncodedArrayValueIterator::ValueType::kInt: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 996 | return GetClassRoot(ClassRoot::kPrimitiveInt, class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 997 | case EncodedArrayValueIterator::ValueType::kLong: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 998 | return GetClassRoot(ClassRoot::kPrimitiveLong, class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 999 | case EncodedArrayValueIterator::ValueType::kFloat: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1000 | return GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1001 | case EncodedArrayValueIterator::ValueType::kDouble: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1002 | return GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1003 | case EncodedArrayValueIterator::ValueType::kMethodType: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1004 | return GetClassRoot<mirror::MethodType>(class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1005 | case EncodedArrayValueIterator::ValueType::kMethodHandle: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1006 | return GetClassRoot<mirror::MethodHandle>(class_roots); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1007 | case EncodedArrayValueIterator::ValueType::kString: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1008 | return GetClassRoot<mirror::String>(); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1009 | case EncodedArrayValueIterator::ValueType::kType: |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1010 | return GetClassRoot<mirror::Class>(); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1011 | case EncodedArrayValueIterator::ValueType::kField: |
| 1012 | case EncodedArrayValueIterator::ValueType::kMethod: |
| 1013 | case EncodedArrayValueIterator::ValueType::kEnum: |
| 1014 | case EncodedArrayValueIterator::ValueType::kArray: |
| 1015 | case EncodedArrayValueIterator::ValueType::kAnnotation: |
| 1016 | case EncodedArrayValueIterator::ValueType::kNull: |
| 1017 | return nullptr; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | static bool GetArgumentForBootstrapMethod(Thread* self, |
| 1022 | ArtMethod* referrer, |
| 1023 | EncodedArrayValueIterator::ValueType type, |
| 1024 | const JValue* encoded_value, |
| 1025 | JValue* decoded_value) |
| 1026 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1027 | // The encoded_value contains either a scalar value (IJDF) or a |
| 1028 | // scalar DEX file index to a reference type to be materialized. |
| 1029 | switch (type) { |
| 1030 | case EncodedArrayValueIterator::ValueType::kInt: |
| 1031 | case EncodedArrayValueIterator::ValueType::kFloat: |
| 1032 | decoded_value->SetI(encoded_value->GetI()); |
| 1033 | return true; |
| 1034 | case EncodedArrayValueIterator::ValueType::kLong: |
| 1035 | case EncodedArrayValueIterator::ValueType::kDouble: |
| 1036 | decoded_value->SetJ(encoded_value->GetJ()); |
| 1037 | return true; |
| 1038 | case EncodedArrayValueIterator::ValueType::kMethodType: { |
| 1039 | StackHandleScope<2> hs(self); |
| 1040 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); |
| 1041 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 1042 | dex::ProtoIndex proto_idx(encoded_value->GetC()); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1043 | ClassLinker* cl = Runtime::Current()->GetClassLinker(); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 1044 | ObjPtr<mirror::MethodType> o = |
| 1045 | cl->ResolveMethodType(self, proto_idx, dex_cache, class_loader); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1046 | if (UNLIKELY(o.IsNull())) { |
| 1047 | DCHECK(self->IsExceptionPending()); |
| 1048 | return false; |
| 1049 | } |
| 1050 | decoded_value->SetL(o); |
| 1051 | return true; |
| 1052 | } |
| 1053 | case EncodedArrayValueIterator::ValueType::kMethodHandle: { |
| 1054 | uint32_t index = static_cast<uint32_t>(encoded_value->GetI()); |
| 1055 | ClassLinker* cl = Runtime::Current()->GetClassLinker(); |
| 1056 | ObjPtr<mirror::MethodHandle> o = cl->ResolveMethodHandle(self, index, referrer); |
| 1057 | if (UNLIKELY(o.IsNull())) { |
| 1058 | DCHECK(self->IsExceptionPending()); |
| 1059 | return false; |
| 1060 | } |
| 1061 | decoded_value->SetL(o); |
| 1062 | return true; |
| 1063 | } |
| 1064 | case EncodedArrayValueIterator::ValueType::kString: { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1065 | dex::StringIndex index(static_cast<uint32_t>(encoded_value->GetI())); |
| 1066 | ClassLinker* cl = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | 18090d1 | 2018-06-01 16:53:12 +0100 | [diff] [blame] | 1067 | ObjPtr<mirror::String> o = cl->ResolveString(index, referrer); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1068 | if (UNLIKELY(o.IsNull())) { |
| 1069 | DCHECK(self->IsExceptionPending()); |
| 1070 | return false; |
| 1071 | } |
| 1072 | decoded_value->SetL(o); |
| 1073 | return true; |
| 1074 | } |
| 1075 | case EncodedArrayValueIterator::ValueType::kType: { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1076 | dex::TypeIndex index(static_cast<uint32_t>(encoded_value->GetI())); |
| 1077 | ClassLinker* cl = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | 09c5ca4 | 2018-05-31 15:15:31 +0100 | [diff] [blame] | 1078 | ObjPtr<mirror::Class> o = cl->ResolveType(index, referrer); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1079 | if (UNLIKELY(o.IsNull())) { |
| 1080 | DCHECK(self->IsExceptionPending()); |
| 1081 | return false; |
| 1082 | } |
| 1083 | decoded_value->SetL(o); |
| 1084 | return true; |
| 1085 | } |
| 1086 | case EncodedArrayValueIterator::ValueType::kBoolean: |
| 1087 | case EncodedArrayValueIterator::ValueType::kByte: |
| 1088 | case EncodedArrayValueIterator::ValueType::kChar: |
| 1089 | case EncodedArrayValueIterator::ValueType::kShort: |
| 1090 | case EncodedArrayValueIterator::ValueType::kField: |
| 1091 | case EncodedArrayValueIterator::ValueType::kMethod: |
| 1092 | case EncodedArrayValueIterator::ValueType::kEnum: |
| 1093 | case EncodedArrayValueIterator::ValueType::kArray: |
| 1094 | case EncodedArrayValueIterator::ValueType::kAnnotation: |
| 1095 | case EncodedArrayValueIterator::ValueType::kNull: |
| 1096 | // Unreachable - unsupported types that have been checked when |
| 1097 | // determining the effect call site type based on the bootstrap |
| 1098 | // argument types. |
| 1099 | UNREACHABLE(); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | static bool PackArgumentForBootstrapMethod(Thread* self, |
| 1104 | ArtMethod* referrer, |
| 1105 | CallSiteArrayValueIterator* it, |
| 1106 | ShadowFrameSetter* setter) |
| 1107 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1108 | auto type = it->GetValueType(); |
| 1109 | const JValue encoded_value = ConvertScalarBootstrapArgument(it->GetJavaValue()); |
| 1110 | JValue decoded_value; |
| 1111 | if (!GetArgumentForBootstrapMethod(self, referrer, type, &encoded_value, &decoded_value)) { |
| 1112 | return false; |
| 1113 | } |
| 1114 | switch (it->GetValueType()) { |
| 1115 | case EncodedArrayValueIterator::ValueType::kInt: |
| 1116 | case EncodedArrayValueIterator::ValueType::kFloat: |
| 1117 | setter->Set(static_cast<uint32_t>(decoded_value.GetI())); |
| 1118 | return true; |
| 1119 | case EncodedArrayValueIterator::ValueType::kLong: |
| 1120 | case EncodedArrayValueIterator::ValueType::kDouble: |
| 1121 | setter->SetLong(decoded_value.GetJ()); |
| 1122 | return true; |
| 1123 | case EncodedArrayValueIterator::ValueType::kMethodType: |
| 1124 | case EncodedArrayValueIterator::ValueType::kMethodHandle: |
| 1125 | case EncodedArrayValueIterator::ValueType::kString: |
| 1126 | case EncodedArrayValueIterator::ValueType::kType: |
| 1127 | setter->SetReference(decoded_value.GetL()); |
| 1128 | return true; |
| 1129 | case EncodedArrayValueIterator::ValueType::kBoolean: |
| 1130 | case EncodedArrayValueIterator::ValueType::kByte: |
| 1131 | case EncodedArrayValueIterator::ValueType::kChar: |
| 1132 | case EncodedArrayValueIterator::ValueType::kShort: |
| 1133 | case EncodedArrayValueIterator::ValueType::kField: |
| 1134 | case EncodedArrayValueIterator::ValueType::kMethod: |
| 1135 | case EncodedArrayValueIterator::ValueType::kEnum: |
| 1136 | case EncodedArrayValueIterator::ValueType::kArray: |
| 1137 | case EncodedArrayValueIterator::ValueType::kAnnotation: |
| 1138 | case EncodedArrayValueIterator::ValueType::kNull: |
| 1139 | // Unreachable - unsupported types that have been checked when |
| 1140 | // determining the effect call site type based on the bootstrap |
| 1141 | // argument types. |
| 1142 | UNREACHABLE(); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | static bool PackCollectorArrayForBootstrapMethod(Thread* self, |
| 1147 | ArtMethod* referrer, |
| 1148 | ObjPtr<mirror::Class> array_type, |
| 1149 | int32_t array_length, |
| 1150 | CallSiteArrayValueIterator* it, |
| 1151 | ShadowFrameSetter* setter) |
| 1152 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1153 | StackHandleScope<1> hs(self); |
| 1154 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1155 | JValue decoded_value; |
| 1156 | |
| 1157 | #define COLLECT_PRIMITIVE_ARRAY(Descriptor, Type) \ |
| 1158 | Handle<mirror::Type ## Array> array = \ |
| 1159 | hs.NewHandle(mirror::Type ## Array::Alloc(self, array_length)); \ |
| 1160 | if (array.IsNull()) { \ |
| 1161 | return false; \ |
| 1162 | } \ |
| 1163 | for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \ |
| 1164 | auto type = it->GetValueType(); \ |
| 1165 | DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \ |
| 1166 | const JValue encoded_value = \ |
| 1167 | ConvertScalarBootstrapArgument(it->GetJavaValue()); \ |
| 1168 | GetArgumentForBootstrapMethod(self, \ |
| 1169 | referrer, \ |
| 1170 | type, \ |
| 1171 | &encoded_value, \ |
| 1172 | &decoded_value); \ |
| 1173 | array->Set(i, decoded_value.Get ## Descriptor()); \ |
| 1174 | } \ |
| 1175 | setter->SetReference(array.Get()); \ |
| 1176 | return true; |
| 1177 | |
| 1178 | #define COLLECT_REFERENCE_ARRAY(T, Type) \ |
Andreas Gampe | 584771b | 2018-10-18 13:22:23 -0700 | [diff] [blame] | 1179 | Handle<mirror::ObjectArray<T>> array = /* NOLINT */ \ |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1180 | hs.NewHandle(mirror::ObjectArray<T>::Alloc(self, \ |
| 1181 | array_type, \ |
| 1182 | array_length)); \ |
| 1183 | if (array.IsNull()) { \ |
| 1184 | return false; \ |
| 1185 | } \ |
| 1186 | for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \ |
| 1187 | auto type = it->GetValueType(); \ |
| 1188 | DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \ |
| 1189 | const JValue encoded_value = \ |
| 1190 | ConvertScalarBootstrapArgument(it->GetJavaValue()); \ |
| 1191 | if (!GetArgumentForBootstrapMethod(self, \ |
| 1192 | referrer, \ |
| 1193 | type, \ |
| 1194 | &encoded_value, \ |
| 1195 | &decoded_value)) { \ |
| 1196 | return false; \ |
| 1197 | } \ |
| 1198 | ObjPtr<mirror::Object> o = decoded_value.GetL(); \ |
| 1199 | if (Runtime::Current()->IsActiveTransaction()) { \ |
| 1200 | array->Set<true>(i, ObjPtr<T>::DownCast(o)); \ |
| 1201 | } else { \ |
| 1202 | array->Set<false>(i, ObjPtr<T>::DownCast(o)); \ |
| 1203 | } \ |
| 1204 | } \ |
| 1205 | setter->SetReference(array.Get()); \ |
| 1206 | return true; |
| 1207 | |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1208 | ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots = class_linker->GetClassRoots(); |
| 1209 | ObjPtr<mirror::Class> component_type = array_type->GetComponentType(); |
| 1210 | if (component_type == GetClassRoot(ClassRoot::kPrimitiveInt, class_roots)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1211 | COLLECT_PRIMITIVE_ARRAY(I, Int); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1212 | } else if (component_type == GetClassRoot(ClassRoot::kPrimitiveLong, class_roots)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1213 | COLLECT_PRIMITIVE_ARRAY(J, Long); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1214 | } else if (component_type == GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1215 | COLLECT_PRIMITIVE_ARRAY(F, Float); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1216 | } else if (component_type == GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1217 | COLLECT_PRIMITIVE_ARRAY(D, Double); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1218 | } else if (component_type == GetClassRoot<mirror::MethodType>()) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1219 | COLLECT_REFERENCE_ARRAY(mirror::MethodType, MethodType); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1220 | } else if (component_type == GetClassRoot<mirror::MethodHandle>()) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1221 | COLLECT_REFERENCE_ARRAY(mirror::MethodHandle, MethodHandle); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1222 | } else if (component_type == GetClassRoot<mirror::String>(class_roots)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1223 | COLLECT_REFERENCE_ARRAY(mirror::String, String); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1224 | } else if (component_type == GetClassRoot<mirror::Class>()) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1225 | COLLECT_REFERENCE_ARRAY(mirror::Class, Type); |
| 1226 | } else { |
| 1227 | UNREACHABLE(); |
| 1228 | } |
| 1229 | #undef COLLECT_PRIMITIVE_ARRAY |
| 1230 | #undef COLLECT_REFERENCE_ARRAY |
| 1231 | } |
| 1232 | |
| 1233 | static ObjPtr<mirror::MethodType> BuildCallSiteForBootstrapMethod(Thread* self, |
| 1234 | const DexFile* dex_file, |
| 1235 | uint32_t call_site_idx) |
| 1236 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 1237 | const dex::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1238 | CallSiteArrayValueIterator it(*dex_file, csi); |
| 1239 | DCHECK_GE(it.Size(), 1u); |
| 1240 | |
| 1241 | StackHandleScope<2> hs(self); |
| 1242 | // Create array for parameter types. |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1243 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 1244 | ObjPtr<mirror::Class> class_array_type = |
| 1245 | GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1246 | Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle( |
| 1247 | mirror::ObjectArray<mirror::Class>::Alloc(self, |
| 1248 | class_array_type, |
| 1249 | static_cast<int>(it.Size()))); |
| 1250 | if (ptypes.IsNull()) { |
| 1251 | DCHECK(self->IsExceptionPending()); |
| 1252 | return nullptr; |
| 1253 | } |
| 1254 | |
| 1255 | // Populate the first argument with an instance of j.l.i.MethodHandles.Lookup |
| 1256 | // that the runtime will construct. |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1257 | ptypes->Set(0, GetClassRoot<mirror::MethodHandlesLookup>(class_linker)); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1258 | it.Next(); |
| 1259 | |
| 1260 | // The remaining parameter types are derived from the types of |
| 1261 | // arguments present in the DEX file. |
| 1262 | int index = 1; |
| 1263 | while (it.HasNext()) { |
| 1264 | ObjPtr<mirror::Class> ptype = GetClassForBootstrapArgument(it.GetValueType()); |
| 1265 | if (ptype.IsNull()) { |
| 1266 | ThrowClassCastException("Unsupported bootstrap argument type"); |
| 1267 | return nullptr; |
| 1268 | } |
| 1269 | ptypes->Set(index, ptype); |
| 1270 | index++; |
| 1271 | it.Next(); |
| 1272 | } |
| 1273 | DCHECK_EQ(static_cast<size_t>(index), it.Size()); |
| 1274 | |
| 1275 | // By definition, the return type is always a j.l.i.CallSite. |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1276 | Handle<mirror::Class> rtype = hs.NewHandle(GetClassRoot<mirror::CallSite>()); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1277 | return mirror::MethodType::Create(self, rtype, ptypes); |
| 1278 | } |
| 1279 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1280 | static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, |
| 1281 | ShadowFrame& shadow_frame, |
| 1282 | uint32_t call_site_idx) |
| 1283 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1284 | StackHandleScope<5> hs(self); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1285 | // There are three mandatory arguments expected from the call site |
| 1286 | // value array in the DEX file: the bootstrap method handle, the |
| 1287 | // method name to pass to the bootstrap method, and the method type |
| 1288 | // to pass to the bootstrap method. |
| 1289 | static constexpr size_t kMandatoryArgumentsCount = 3; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1290 | ArtMethod* referrer = shadow_frame.GetMethod(); |
| 1291 | const DexFile* dex_file = referrer->GetDexFile(); |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 1292 | const dex::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1293 | CallSiteArrayValueIterator it(*dex_file, csi); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1294 | if (it.Size() < kMandatoryArgumentsCount) { |
| 1295 | ThrowBootstrapMethodError("Truncated bootstrap arguments (%zu < %zu)", |
| 1296 | it.Size(), kMandatoryArgumentsCount); |
| 1297 | return nullptr; |
| 1298 | } |
| 1299 | |
| 1300 | if (it.GetValueType() != EncodedArrayValueIterator::ValueType::kMethodHandle) { |
| 1301 | ThrowBootstrapMethodError("First bootstrap argument is not a method handle"); |
| 1302 | return nullptr; |
| 1303 | } |
| 1304 | |
| 1305 | uint32_t bsm_index = static_cast<uint32_t>(it.GetJavaValue().i); |
| 1306 | it.Next(); |
| 1307 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1308 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1309 | Handle<mirror::MethodHandle> bsm = |
| 1310 | hs.NewHandle(class_linker->ResolveMethodHandle(self, bsm_index, referrer)); |
| 1311 | if (bsm.IsNull()) { |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1312 | DCHECK(self->IsExceptionPending()); |
| 1313 | return nullptr; |
| 1314 | } |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1315 | |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1316 | if (bsm->GetHandleKind() != mirror::MethodHandle::Kind::kInvokeStatic) { |
| 1317 | // JLS suggests also accepting constructors. This is currently |
| 1318 | // hard as constructor invocations happen via transformers in ART |
| 1319 | // today. The constructor would need to be a class derived from java.lang.invoke.CallSite. |
| 1320 | ThrowBootstrapMethodError("Unsupported bootstrap method invocation kind"); |
| 1321 | return nullptr; |
| 1322 | } |
| 1323 | |
| 1324 | // Construct the local call site type information based on the 3 |
| 1325 | // mandatory arguments provided by the runtime and the static arguments |
| 1326 | // in the DEX file. We will use these arguments to build a shadow frame. |
| 1327 | MutableHandle<mirror::MethodType> call_site_type = |
| 1328 | hs.NewHandle(BuildCallSiteForBootstrapMethod(self, dex_file, call_site_idx)); |
| 1329 | if (call_site_type.IsNull()) { |
| 1330 | DCHECK(self->IsExceptionPending()); |
| 1331 | return nullptr; |
| 1332 | } |
| 1333 | |
| 1334 | // Check if this BSM is targeting a variable arity method. If so, |
| 1335 | // we'll need to collect the trailing arguments into an array. |
| 1336 | Handle<mirror::Array> collector_arguments; |
| 1337 | int32_t collector_arguments_length; |
| 1338 | if (bsm->GetTargetMethod()->IsVarargs()) { |
| 1339 | int number_of_bsm_parameters = bsm->GetMethodType()->GetNumberOfPTypes(); |
| 1340 | if (number_of_bsm_parameters == 0) { |
| 1341 | ThrowBootstrapMethodError("Variable arity BSM does not have any arguments"); |
| 1342 | return nullptr; |
| 1343 | } |
| 1344 | Handle<mirror::Class> collector_array_class = |
| 1345 | hs.NewHandle(bsm->GetMethodType()->GetPTypes()->Get(number_of_bsm_parameters - 1)); |
| 1346 | if (!collector_array_class->IsArrayClass()) { |
| 1347 | ThrowBootstrapMethodError("Variable arity BSM does not have array as final argument"); |
| 1348 | return nullptr; |
| 1349 | } |
| 1350 | // The call site may include no arguments to be collected. In this |
| 1351 | // case the number of arguments must be at least the number of BSM |
| 1352 | // parameters less the collector array. |
| 1353 | if (call_site_type->GetNumberOfPTypes() < number_of_bsm_parameters - 1) { |
| 1354 | ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get()); |
| 1355 | return nullptr; |
| 1356 | } |
| 1357 | // Check all the arguments to be collected match the collector array component type. |
| 1358 | for (int i = number_of_bsm_parameters - 1; i < call_site_type->GetNumberOfPTypes(); ++i) { |
| 1359 | if (call_site_type->GetPTypes()->Get(i) != collector_array_class->GetComponentType()) { |
| 1360 | ThrowClassCastException(collector_array_class->GetComponentType(), |
| 1361 | call_site_type->GetPTypes()->Get(i)); |
| 1362 | return nullptr; |
| 1363 | } |
| 1364 | } |
| 1365 | // Update the call site method type so it now includes the collector array. |
| 1366 | int32_t collector_arguments_start = number_of_bsm_parameters - 1; |
| 1367 | collector_arguments_length = call_site_type->GetNumberOfPTypes() - number_of_bsm_parameters + 1; |
| 1368 | call_site_type.Assign( |
| 1369 | mirror::MethodType::CollectTrailingArguments(self, |
| 1370 | call_site_type.Get(), |
| 1371 | collector_array_class.Get(), |
| 1372 | collector_arguments_start)); |
| 1373 | if (call_site_type.IsNull()) { |
| 1374 | DCHECK(self->IsExceptionPending()); |
| 1375 | return nullptr; |
| 1376 | } |
| 1377 | } else { |
| 1378 | collector_arguments_length = 0; |
| 1379 | } |
| 1380 | |
| 1381 | if (call_site_type->GetNumberOfPTypes() != bsm->GetMethodType()->GetNumberOfPTypes()) { |
| 1382 | ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get()); |
| 1383 | return nullptr; |
| 1384 | } |
| 1385 | |
| 1386 | // BSM invocation has a different set of exceptions that |
| 1387 | // j.l.i.MethodHandle.invoke(). Scan arguments looking for CCE |
| 1388 | // "opportunities". Unfortunately we cannot just leave this to the |
| 1389 | // method handle invocation as this might generate a WMTE. |
| 1390 | for (int32_t i = 0; i < call_site_type->GetNumberOfPTypes(); ++i) { |
| 1391 | ObjPtr<mirror::Class> from = call_site_type->GetPTypes()->Get(i); |
| 1392 | ObjPtr<mirror::Class> to = bsm->GetMethodType()->GetPTypes()->Get(i); |
| 1393 | if (!IsParameterTypeConvertible(from, to)) { |
| 1394 | ThrowClassCastException(from, to); |
| 1395 | return nullptr; |
| 1396 | } |
| 1397 | } |
| 1398 | if (!IsReturnTypeConvertible(call_site_type->GetRType(), bsm->GetMethodType()->GetRType())) { |
| 1399 | ThrowClassCastException(bsm->GetMethodType()->GetRType(), call_site_type->GetRType()); |
| 1400 | return nullptr; |
| 1401 | } |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1402 | |
| 1403 | // Set-up a shadow frame for invoking the bootstrap method handle. |
| 1404 | ShadowFrameAllocaUniquePtr bootstrap_frame = |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1405 | CREATE_SHADOW_FRAME(call_site_type->NumberOfVRegs(), |
| 1406 | nullptr, |
| 1407 | referrer, |
| 1408 | shadow_frame.GetDexPC()); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1409 | ScopedStackedShadowFramePusher pusher( |
| 1410 | self, bootstrap_frame.get(), StackedShadowFrameType::kShadowFrameUnderConstruction); |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1411 | ShadowFrameSetter setter(bootstrap_frame.get(), 0u); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1412 | |
| 1413 | // The first parameter is a MethodHandles lookup instance. |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1414 | Handle<mirror::Class> lookup_class = |
| 1415 | hs.NewHandle(shadow_frame.GetMethod()->GetDeclaringClass()); |
| 1416 | ObjPtr<mirror::MethodHandlesLookup> lookup = |
| 1417 | mirror::MethodHandlesLookup::Create(self, lookup_class); |
| 1418 | if (lookup.IsNull()) { |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1419 | DCHECK(self->IsExceptionPending()); |
| 1420 | return nullptr; |
| 1421 | } |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1422 | setter.SetReference(lookup); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1423 | |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1424 | // Pack the remaining arguments into the frame. |
| 1425 | int number_of_arguments = call_site_type->GetNumberOfPTypes(); |
| 1426 | int argument_index; |
| 1427 | for (argument_index = 1; argument_index < number_of_arguments; ++argument_index) { |
| 1428 | if (argument_index == number_of_arguments - 1 && |
| 1429 | call_site_type->GetPTypes()->Get(argument_index)->IsArrayClass()) { |
| 1430 | ObjPtr<mirror::Class> array_type = call_site_type->GetPTypes()->Get(argument_index); |
| 1431 | if (!PackCollectorArrayForBootstrapMethod(self, |
| 1432 | referrer, |
| 1433 | array_type, |
| 1434 | collector_arguments_length, |
| 1435 | &it, |
| 1436 | &setter)) { |
| 1437 | DCHECK(self->IsExceptionPending()); |
| 1438 | return nullptr; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1439 | } |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1440 | } else if (!PackArgumentForBootstrapMethod(self, referrer, &it, &setter)) { |
| 1441 | DCHECK(self->IsExceptionPending()); |
| 1442 | return nullptr; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1443 | } |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1444 | it.Next(); |
| 1445 | } |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1446 | DCHECK(!it.HasNext()); |
| 1447 | DCHECK(setter.Done()); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1448 | |
| 1449 | // Invoke the bootstrap method handle. |
| 1450 | JValue result; |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1451 | RangeInstructionOperands operands(0, bootstrap_frame->NumberOfVRegs()); |
| 1452 | bool invoke_success = MethodHandleInvoke(self, |
| 1453 | *bootstrap_frame, |
| 1454 | bsm, |
| 1455 | call_site_type, |
| 1456 | &operands, |
| 1457 | &result); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1458 | if (!invoke_success) { |
| 1459 | DCHECK(self->IsExceptionPending()); |
| 1460 | return nullptr; |
| 1461 | } |
| 1462 | |
| 1463 | Handle<mirror::Object> object(hs.NewHandle(result.GetL())); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1464 | if (UNLIKELY(object.IsNull())) { |
Orion Hodson | da1cdd0 | 2018-01-31 18:08:28 +0000 | [diff] [blame] | 1465 | // This will typically be for LambdaMetafactory which is not supported. |
Orion Hodson | 76e6adb | 2018-02-23 13:15:55 +0000 | [diff] [blame] | 1466 | ThrowClassCastException("Bootstrap method returned null"); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1467 | return nullptr; |
| 1468 | } |
| 1469 | |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1470 | // Check the result type is a subclass of j.l.i.CallSite. |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 1471 | ObjPtr<mirror::Class> call_site_class = GetClassRoot<mirror::CallSite>(class_linker); |
| 1472 | if (UNLIKELY(!object->InstanceOf(call_site_class))) { |
| 1473 | ThrowClassCastException(object->GetClass(), call_site_class); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1474 | return nullptr; |
| 1475 | } |
| 1476 | |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1477 | // Check the call site target is not null as we're going to invoke it. |
Vladimir Marko | d7e9bbf | 2019-03-28 13:18:57 +0000 | [diff] [blame] | 1478 | ObjPtr<mirror::CallSite> call_site = ObjPtr<mirror::CallSite>::DownCast(result.GetL()); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1479 | ObjPtr<mirror::MethodHandle> target = call_site->GetTarget(); |
| 1480 | if (UNLIKELY(target == nullptr)) { |
Orion Hodson | a5dca52 | 2018-02-27 12:42:11 +0000 | [diff] [blame] | 1481 | ThrowClassCastException("Bootstrap method returned a CallSite with a null target"); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1482 | return nullptr; |
| 1483 | } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1484 | return call_site; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1487 | namespace { |
| 1488 | |
| 1489 | ObjPtr<mirror::CallSite> DoResolveCallSite(Thread* self, |
| 1490 | ShadowFrame& shadow_frame, |
| 1491 | uint32_t call_site_idx) |
| 1492 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1493 | StackHandleScope<1> hs(self); |
| 1494 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(shadow_frame.GetMethod()->GetDexCache())); |
| 1495 | |
| 1496 | // Get the call site from the DexCache if present. |
| 1497 | ObjPtr<mirror::CallSite> call_site = dex_cache->GetResolvedCallSite(call_site_idx); |
| 1498 | if (LIKELY(call_site != nullptr)) { |
| 1499 | return call_site; |
| 1500 | } |
| 1501 | |
| 1502 | // Invoke the bootstrap method to get a candidate call site. |
| 1503 | call_site = InvokeBootstrapMethod(self, shadow_frame, call_site_idx); |
| 1504 | if (UNLIKELY(call_site == nullptr)) { |
| 1505 | if (!self->GetException()->IsError()) { |
| 1506 | // Use a BootstrapMethodError if the exception is not an instance of java.lang.Error. |
| 1507 | ThrowWrappedBootstrapMethodError("Exception from call site #%u bootstrap method", |
| 1508 | call_site_idx); |
| 1509 | } |
| 1510 | return nullptr; |
| 1511 | } |
| 1512 | |
| 1513 | // Attempt to place the candidate call site into the DexCache, return the winning call site. |
| 1514 | return dex_cache->SetResolvedCallSite(call_site_idx, call_site); |
| 1515 | } |
| 1516 | |
| 1517 | } // namespace |
| 1518 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1519 | bool DoInvokeCustom(Thread* self, |
| 1520 | ShadowFrame& shadow_frame, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1521 | uint32_t call_site_idx, |
| 1522 | const InstructionOperands* operands, |
| 1523 | JValue* result) { |
Alex Light | 848574c | 2017-09-25 16:59:39 -0700 | [diff] [blame] | 1524 | // Make sure to check for async exceptions |
| 1525 | if (UNLIKELY(self->ObserveAsyncException())) { |
| 1526 | return false; |
| 1527 | } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1528 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1529 | // invoke-custom is not supported in transactions. In transactions |
| 1530 | // there is a limited set of types supported. invoke-custom allows |
| 1531 | // running arbitrary code and instantiating arbitrary types. |
| 1532 | CHECK(!Runtime::Current()->IsActiveTransaction()); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1533 | |
| 1534 | ObjPtr<mirror::CallSite> call_site = DoResolveCallSite(self, shadow_frame, call_site_idx); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1535 | if (call_site.IsNull()) { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1536 | DCHECK(self->IsExceptionPending()); |
| 1537 | return false; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1540 | StackHandleScope<2> hs(self); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1541 | Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget()); |
| 1542 | Handle<mirror::MethodType> target_method_type = hs.NewHandle(target->GetMethodType()); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1543 | DCHECK_EQ(operands->GetNumberOfOperands(), target_method_type->NumberOfVRegs()) |
| 1544 | << " call_site_idx" << call_site_idx; |
| 1545 | return MethodHandleInvokeExact(self, |
| 1546 | shadow_frame, |
| 1547 | target, |
| 1548 | target_method_type, |
| 1549 | operands, |
| 1550 | result); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 1553 | // Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame. |
| 1554 | static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame, |
| 1555 | size_t dest_reg, size_t src_reg) |
| 1556 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1557 | // Uint required, so that sign extension does not make this wrong on 64b systems |
| 1558 | uint32_t src_value = shadow_frame.GetVReg(src_reg); |
| 1559 | ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg); |
| 1560 | |
| 1561 | // If both register locations contains the same value, the register probably holds a reference. |
| 1562 | // Note: As an optimization, non-moving collectors leave a stale reference value |
| 1563 | // in the references array even after the original vreg was overwritten to a non-reference. |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 1564 | if (src_value == reinterpret_cast32<uint32_t>(o.Ptr())) { |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 1565 | new_shadow_frame->SetVRegReference(dest_reg, o); |
| 1566 | } else { |
| 1567 | new_shadow_frame->SetVReg(dest_reg, src_value); |
| 1568 | } |
| 1569 | } |
| 1570 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1571 | template <bool is_range> |
| 1572 | inline void CopyRegisters(ShadowFrame& caller_frame, |
| 1573 | ShadowFrame* callee_frame, |
| 1574 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 1575 | const size_t first_src_reg, |
| 1576 | const size_t first_dest_reg, |
| 1577 | const size_t num_regs) { |
| 1578 | if (is_range) { |
| 1579 | const size_t dest_reg_bound = first_dest_reg + num_regs; |
| 1580 | for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < dest_reg_bound; |
| 1581 | ++dest_reg, ++src_reg) { |
| 1582 | AssignRegister(callee_frame, caller_frame, dest_reg, src_reg); |
| 1583 | } |
| 1584 | } else { |
| 1585 | DCHECK_LE(num_regs, arraysize(arg)); |
| 1586 | |
| 1587 | for (size_t arg_index = 0; arg_index < num_regs; ++arg_index) { |
| 1588 | AssignRegister(callee_frame, caller_frame, first_dest_reg + arg_index, arg[arg_index]); |
| 1589 | } |
| 1590 | } |
| 1591 | } |
| 1592 | |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1593 | template <bool is_range, |
Narayan Kamath | 370423d | 2016-10-03 16:51:22 +0100 | [diff] [blame] | 1594 | bool do_assignability_check> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1595 | static inline bool DoCallCommon(ArtMethod* called_method, |
| 1596 | Thread* self, |
| 1597 | ShadowFrame& shadow_frame, |
| 1598 | JValue* result, |
| 1599 | uint16_t number_of_inputs, |
Narayan Kamath | 370423d | 2016-10-03 16:51:22 +0100 | [diff] [blame] | 1600 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1601 | uint32_t vregC) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1602 | bool string_init = false; |
| 1603 | // Replace calls to String.<init> with equivalent StringFactory call. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1604 | if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass() |
| 1605 | && called_method->IsConstructor())) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1606 | called_method = WellKnownClasses::StringInitToStringFactory(called_method); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1607 | string_init = true; |
| 1608 | } |
| 1609 | |
Alex Light | daf58c8 | 2016-03-16 23:00:49 +0000 | [diff] [blame] | 1610 | // Compute method information. |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 1611 | CodeItemDataAccessor accessor(called_method->DexInstructionData()); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1612 | // Number of registers for the callee's call frame. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1613 | uint16_t num_regs; |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1614 | // Test whether to use the interpreter or compiler entrypoint, and save that result to pass to |
| 1615 | // PerformCall. A deoptimization could occur at any time, and we shouldn't change which |
| 1616 | // entrypoint to use once we start building the shadow frame. |
Mathieu Chartier | 448bbcf | 2017-07-06 12:05:13 -0700 | [diff] [blame] | 1617 | |
| 1618 | // For unstarted runtimes, always use the interpreter entrypoint. This fixes the case where we are |
| 1619 | // doing cross compilation. Note that GetEntryPointFromQuickCompiledCode doesn't use the image |
| 1620 | // pointer size here and this may case an overflow if it is called from the compiler. b/62402160 |
| 1621 | const bool use_interpreter_entrypoint = !Runtime::Current()->IsStarted() || |
| 1622 | ClassLinker::ShouldUseInterpreterEntrypoint( |
| 1623 | called_method, |
| 1624 | called_method->GetEntryPointFromQuickCompiledCode()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 1625 | if (LIKELY(accessor.HasCodeItem())) { |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1626 | // When transitioning to compiled code, space only needs to be reserved for the input registers. |
| 1627 | // The rest of the frame gets discarded. This also prevents accessing the called method's code |
| 1628 | // item, saving memory by keeping code items of compiled code untouched. |
Mathieu Chartier | 448bbcf | 2017-07-06 12:05:13 -0700 | [diff] [blame] | 1629 | if (!use_interpreter_entrypoint) { |
| 1630 | DCHECK(!Runtime::Current()->IsAotCompiler()) << "Compiler should use interpreter entrypoint"; |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1631 | num_regs = number_of_inputs; |
| 1632 | } else { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 1633 | num_regs = accessor.RegistersSize(); |
| 1634 | DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, accessor.InsSize()); |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1635 | } |
Nicolas Geoffray | 0182229 | 2017-03-09 09:03:19 +0000 | [diff] [blame] | 1636 | } else { |
| 1637 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
| 1638 | num_regs = number_of_inputs; |
Jeff Hao | df79ddb | 2017-02-27 14:47:06 -0800 | [diff] [blame] | 1639 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1640 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1641 | // Hack for String init: |
| 1642 | // |
| 1643 | // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into: |
| 1644 | // invoke-x StringFactory(a, b, c, ...) |
| 1645 | // by effectively dropping the first virtual register from the invoke. |
| 1646 | // |
| 1647 | // (at this point the ArtMethod has already been replaced, |
| 1648 | // so we just need to fix-up the arguments) |
David Brazdil | 65902e8 | 2016-01-15 09:35:13 +0000 | [diff] [blame] | 1649 | // |
| 1650 | // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased |
| 1651 | // to handle the compiler optimization of replacing `this` with null without |
| 1652 | // throwing NullPointerException. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1653 | uint32_t string_init_vreg_this = is_range ? vregC : arg[0]; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1654 | if (UNLIKELY(string_init)) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1655 | DCHECK_GT(num_regs, 0u); // As the method is an instance method, there should be at least 1. |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1656 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1657 | // The new StringFactory call is static and has one fewer argument. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 1658 | if (!accessor.HasCodeItem()) { |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1659 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
| 1660 | num_regs--; |
| 1661 | } // else ... don't need to change num_regs since it comes up from the string_init's code item |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1662 | number_of_inputs--; |
| 1663 | |
| 1664 | // Rewrite the var-args, dropping the 0th argument ("this") |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1665 | for (uint32_t i = 1; i < arraysize(arg); ++i) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1666 | arg[i - 1] = arg[i]; |
| 1667 | } |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1668 | arg[arraysize(arg) - 1] = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1669 | |
| 1670 | // Rewrite the non-var-arg case |
| 1671 | vregC++; // Skips the 0th vreg in the range ("this"). |
| 1672 | } |
| 1673 | |
| 1674 | // Parameter registers go at the end of the shadow frame. |
| 1675 | DCHECK_GE(num_regs, number_of_inputs); |
| 1676 | size_t first_dest_reg = num_regs - number_of_inputs; |
| 1677 | DCHECK_NE(first_dest_reg, (size_t)-1); |
| 1678 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1679 | // Allocate shadow frame on the stack. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1680 | const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon"); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 1681 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 1682 | CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 1683 | ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1684 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1685 | // Initialize new shadow frame by copying the registers from the callee shadow frame. |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1686 | if (do_assignability_check) { |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1687 | // Slow path. |
| 1688 | // We might need to do class loading, which incurs a thread state change to kNative. So |
| 1689 | // register the shadow frame as under construction and allow suspension again. |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 1690 | ScopedStackedShadowFramePusher pusher( |
Sebastien Hertz | f795869 | 2015-06-09 14:09:14 +0200 | [diff] [blame] | 1691 | self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction); |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1692 | self->EndAssertNoThreadSuspension(old_cause); |
| 1693 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1694 | // ArtMethod here is needed to check type information of the call site against the callee. |
| 1695 | // Type information is retrieved from a DexFile/DexCache for that respective declared method. |
| 1696 | // |
| 1697 | // As a special case for proxy methods, which are not dex-backed, |
| 1698 | // we have to retrieve type information from the proxy's method |
| 1699 | // interface method instead (which is dex backed since proxies are never interfaces). |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1700 | ArtMethod* method = |
| 1701 | new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1702 | |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1703 | // We need to do runtime check on reference assignment. We need to load the shorty |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1704 | // to get the exact type of each reference argument. |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 1705 | const dex::TypeList* params = method->GetParameterTypeList(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 1706 | uint32_t shorty_len = 0; |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1707 | const char* shorty = method->GetShorty(&shorty_len); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1708 | |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1709 | // Handle receiver apart since it's not part of the shorty. |
| 1710 | size_t dest_reg = first_dest_reg; |
| 1711 | size_t arg_offset = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1712 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1713 | if (!method->IsStatic()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 1714 | size_t receiver_reg = is_range ? vregC : arg[0]; |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1715 | new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg)); |
| 1716 | ++dest_reg; |
| 1717 | ++arg_offset; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1718 | DCHECK(!string_init); // All StringFactory methods are static. |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1719 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1720 | |
| 1721 | // Copy the caller's invoke-* arguments into the callee's parameter registers. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1722 | for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) { |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1723 | // Skip the 0th 'shorty' type since it represents the return type. |
| 1724 | DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'"; |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1725 | const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset]; |
| 1726 | switch (shorty[shorty_pos + 1]) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1727 | // Handle Object references. 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1728 | case 'L': { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1729 | ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference(src_reg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1730 | if (do_assignability_check && o != nullptr) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1731 | const dex::TypeIndex type_idx = params->GetTypeItem(shorty_pos).type_idx_; |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 1732 | ObjPtr<mirror::Class> arg_type = method->GetDexCache()->GetResolvedType(type_idx); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1733 | if (arg_type == nullptr) { |
Mathieu Chartier | e22305b | 2016-10-26 21:04:58 -0700 | [diff] [blame] | 1734 | StackHandleScope<1> hs(self); |
| 1735 | // Preserve o since it is used below and GetClassFromTypeIndex may cause thread |
| 1736 | // suspension. |
| 1737 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&o); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 1738 | arg_type = method->ResolveClassFromTypeIndex(type_idx); |
Mathieu Chartier | e22305b | 2016-10-26 21:04:58 -0700 | [diff] [blame] | 1739 | if (arg_type == nullptr) { |
| 1740 | CHECK(self->IsExceptionPending()); |
| 1741 | return false; |
| 1742 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1743 | } |
| 1744 | if (!o->VerifierInstanceOf(arg_type)) { |
| 1745 | // This should never happen. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1746 | std::string temp1, temp2; |
Orion Hodson | fef0664 | 2016-11-25 16:07:11 +0000 | [diff] [blame] | 1747 | self->ThrowNewExceptionF("Ljava/lang/InternalError;", |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1748 | "Invoking %s with bad arg %d, type '%s' not instance of '%s'", |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 1749 | new_shadow_frame->GetMethod()->GetName(), shorty_pos, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1750 | o->GetClass()->GetDescriptor(&temp1), |
| 1751 | arg_type->GetDescriptor(&temp2)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1754 | } |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 1755 | new_shadow_frame->SetVRegReference(dest_reg, o); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1756 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1757 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1758 | // Handle doubles and longs. 2 consecutive virtual register slots. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1759 | case 'J': case 'D': { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1760 | uint64_t wide_value = |
| 1761 | (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) | |
| 1762 | static_cast<uint32_t>(shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1763 | new_shadow_frame->SetVRegLong(dest_reg, wide_value); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1764 | // Skip the next virtual register slot since we already used it. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1765 | ++dest_reg; |
| 1766 | ++arg_offset; |
| 1767 | break; |
| 1768 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1769 | // Handle all other primitives that are always 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1770 | default: |
| 1771 | new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg)); |
| 1772 | break; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1773 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1774 | } |
| 1775 | } else { |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1776 | if (is_range) { |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1777 | DCHECK_EQ(num_regs, first_dest_reg + number_of_inputs); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1778 | } |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1779 | |
| 1780 | CopyRegisters<is_range>(shadow_frame, |
| 1781 | new_shadow_frame, |
| 1782 | arg, |
| 1783 | vregC, |
| 1784 | first_dest_reg, |
| 1785 | number_of_inputs); |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1786 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1789 | PerformCall(self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 1790 | accessor, |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 1791 | shadow_frame.GetMethod(), |
| 1792 | first_dest_reg, |
| 1793 | new_shadow_frame, |
| 1794 | result, |
| 1795 | use_interpreter_entrypoint); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1796 | |
| 1797 | if (string_init && !self->IsExceptionPending()) { |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 1798 | SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1799 | } |
| 1800 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1801 | return !self->IsExceptionPending(); |
| 1802 | } |
| 1803 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1804 | template<bool is_range, bool do_assignability_check> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1805 | bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
| 1806 | const Instruction* inst, uint16_t inst_data, JValue* result) { |
| 1807 | // Argument word count. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1808 | const uint16_t number_of_inputs = |
| 1809 | (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1810 | |
| 1811 | // TODO: find a cleaner way to separate non-range and range information without duplicating |
| 1812 | // code. |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1813 | uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1814 | uint32_t vregC = 0; |
| 1815 | if (is_range) { |
| 1816 | vregC = inst->VRegC_3rc(); |
| 1817 | } else { |
| 1818 | vregC = inst->VRegC_35c(); |
| 1819 | inst->GetVarArgs(arg, inst_data); |
| 1820 | } |
| 1821 | |
| 1822 | return DoCallCommon<is_range, do_assignability_check>( |
| 1823 | called_method, self, shadow_frame, |
| 1824 | result, number_of_inputs, arg, vregC); |
| 1825 | } |
| 1826 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1827 | template <bool is_range, bool do_access_check, bool transaction_active> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1828 | bool DoFilledNewArray(const Instruction* inst, |
| 1829 | const ShadowFrame& shadow_frame, |
| 1830 | Thread* self, |
| 1831 | JValue* result) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1832 | DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY || |
| 1833 | inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE); |
| 1834 | const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 1835 | if (!is_range) { |
| 1836 | // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments. |
| 1837 | CHECK_LE(length, 5); |
| 1838 | } |
| 1839 | if (UNLIKELY(length < 0)) { |
| 1840 | ThrowNegativeArraySizeException(length); |
| 1841 | return false; |
| 1842 | } |
| 1843 | uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1844 | ObjPtr<mirror::Class> array_class = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1845 | shadow_frame.GetMethod(), |
| 1846 | self, |
| 1847 | false, |
| 1848 | do_access_check); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1849 | if (UNLIKELY(array_class == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1850 | DCHECK(self->IsExceptionPending()); |
| 1851 | return false; |
| 1852 | } |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1853 | CHECK(array_class->IsArrayClass()); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1854 | ObjPtr<mirror::Class> component_class = array_class->GetComponentType(); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1855 | const bool is_primitive_int_component = component_class->IsPrimitiveInt(); |
| 1856 | if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) { |
| 1857 | if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1858 | ThrowRuntimeException("Bad filled array request for type %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1859 | component_class->PrettyDescriptor().c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1860 | } else { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 1861 | self->ThrowNewExceptionF("Ljava/lang/InternalError;", |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 1862 | "Found type %s; filled-new-array not implemented for anything but 'int'", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1863 | component_class->PrettyDescriptor().c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1864 | } |
| 1865 | return false; |
| 1866 | } |
Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 1867 | ObjPtr<mirror::Object> new_array = mirror::Array::Alloc( |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1868 | self, |
| 1869 | array_class, |
| 1870 | length, |
| 1871 | array_class->GetComponentSizeShift(), |
| 1872 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1873 | if (UNLIKELY(new_array == nullptr)) { |
| 1874 | self->AssertPendingOOMException(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1875 | return false; |
| 1876 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1877 | uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array. |
| 1878 | uint32_t vregC = 0; // only used in filled-new-array-range. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1879 | if (is_range) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1880 | vregC = inst->VRegC_3rc(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1881 | } else { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1882 | inst->GetVarArgs(arg); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1883 | } |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1884 | for (int32_t i = 0; i < length; ++i) { |
| 1885 | size_t src_reg = is_range ? vregC + i : arg[i]; |
| 1886 | if (is_primitive_int_component) { |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1887 | new_array->AsIntArray()->SetWithoutChecks<transaction_active>( |
| 1888 | i, shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1889 | } else { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1890 | new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<transaction_active>( |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1891 | i, shadow_frame.GetVRegReference(src_reg)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1892 | } |
| 1893 | } |
| 1894 | |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1895 | result->SetL(new_array); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1896 | return true; |
| 1897 | } |
| 1898 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1899 | // TODO: Use ObjPtr here. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1900 | template<typename T> |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 1901 | static void RecordArrayElementsInTransactionImpl(ObjPtr<mirror::PrimitiveArray<T>> array, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1902 | int32_t count) |
| 1903 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1904 | Runtime* runtime = Runtime::Current(); |
| 1905 | for (int32_t i = 0; i < count; ++i) { |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 1906 | runtime->RecordWriteArray(array.Ptr(), i, array->GetWithoutChecks(i)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1910 | void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1911 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1912 | DCHECK(Runtime::Current()->IsActiveTransaction()); |
| 1913 | DCHECK(array != nullptr); |
| 1914 | DCHECK_LE(count, array->GetLength()); |
| 1915 | Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType(); |
| 1916 | switch (primitive_component_type) { |
| 1917 | case Primitive::kPrimBoolean: |
| 1918 | RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count); |
| 1919 | break; |
| 1920 | case Primitive::kPrimByte: |
| 1921 | RecordArrayElementsInTransactionImpl(array->AsByteArray(), count); |
| 1922 | break; |
| 1923 | case Primitive::kPrimChar: |
| 1924 | RecordArrayElementsInTransactionImpl(array->AsCharArray(), count); |
| 1925 | break; |
| 1926 | case Primitive::kPrimShort: |
| 1927 | RecordArrayElementsInTransactionImpl(array->AsShortArray(), count); |
| 1928 | break; |
| 1929 | case Primitive::kPrimInt: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1930 | RecordArrayElementsInTransactionImpl(array->AsIntArray(), count); |
| 1931 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1932 | case Primitive::kPrimFloat: |
| 1933 | RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count); |
| 1934 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1935 | case Primitive::kPrimLong: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1936 | RecordArrayElementsInTransactionImpl(array->AsLongArray(), count); |
| 1937 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1938 | case Primitive::kPrimDouble: |
| 1939 | RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count); |
| 1940 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1941 | default: |
| 1942 | LOG(FATAL) << "Unsupported primitive type " << primitive_component_type |
| 1943 | << " in fill-array-data"; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1944 | UNREACHABLE(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1945 | } |
| 1946 | } |
| 1947 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1948 | // Explicit DoCall template function declarations. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 1949 | #define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1950 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1951 | bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \ |
| 1952 | ShadowFrame& shadow_frame, \ |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 1953 | const Instruction* inst, uint16_t inst_data, \ |
| 1954 | JValue* result) |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1955 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false); |
| 1956 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true); |
| 1957 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false); |
| 1958 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true); |
| 1959 | #undef EXPLICIT_DO_CALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1960 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1961 | // Explicit DoInvokePolymorphic template function declarations. |
| 1962 | #define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range) \ |
| 1963 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
| 1964 | bool DoInvokePolymorphic<_is_range>( \ |
| 1965 | Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 1966 | uint16_t inst_data, JValue* result) |
| 1967 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false); |
| 1968 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1969 | #undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL |
| 1970 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1971 | // Explicit DoFilledNewArray template function declarations. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1972 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1973 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1974 | bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \ |
| 1975 | const ShadowFrame& shadow_frame, \ |
| 1976 | Thread* self, JValue* result) |
| 1977 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \ |
| 1978 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \ |
| 1979 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \ |
| 1980 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \ |
| 1981 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active) |
| 1982 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false); |
| 1983 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true); |
| 1984 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1985 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL |
| 1986 | |
| 1987 | } // namespace interpreter |
| 1988 | } // namespace art |