buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | /* |
| 18 | * Mterp entry point and support functions. |
| 19 | */ |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 20 | #include "mterp.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 21 | |
| 22 | #include "base/quasi_atomic.h" |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 23 | #include "debugger.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 24 | #include "entrypoints/entrypoint_utils-inl.h" |
| 25 | #include "interpreter/interpreter_common.h" |
| 26 | #include "interpreter/interpreter_intrinsics.h" |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 27 | #include "interpreter/shadow_frame-inl.h" |
Andreas Gampe | fd63bbf | 2018-10-29 12:55:35 -0700 | [diff] [blame] | 28 | #include "mirror/string-alloc-inl.h" |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | namespace interpreter { |
| 32 | /* |
| 33 | * Verify some constants used by the mterp interpreter. |
| 34 | */ |
| 35 | void CheckMterpAsmConstants() { |
| 36 | /* |
| 37 | * If we're using computed goto instruction transitions, make sure |
David Srbecky | d88f5f7 | 2018-10-16 14:22:33 +0100 | [diff] [blame] | 38 | * none of the handlers overflows the byte limit. This won't tell |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 39 | * which one did, but if any one is too big the total size will |
| 40 | * overflow. |
| 41 | */ |
David Srbecky | d88f5f7 | 2018-10-16 14:22:33 +0100 | [diff] [blame] | 42 | const int width = kMterpHandlerSize; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 43 | int interp_size = (uintptr_t) artMterpAsmInstructionEnd - |
| 44 | (uintptr_t) artMterpAsmInstructionStart; |
| 45 | if ((interp_size == 0) || (interp_size != (art::kNumPackedOpcodes * width))) { |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 46 | LOG(FATAL) << "ERROR: unexpected asm interp size " << interp_size |
| 47 | << "(did an instruction handler exceed " << width << " bytes?)"; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | void InitMterpTls(Thread* self) { |
David Srbecky | 776f3f7 | 2018-10-15 18:03:55 +0100 | [diff] [blame] | 52 | self->SetMterpCurrentIBase(artMterpAsmInstructionStart); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Find the matching case. Returns the offset to the handler instructions. |
| 57 | * |
| 58 | * Returns 3 if we don't find a match (it's the size of the sparse-switch |
| 59 | * instruction). |
| 60 | */ |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 61 | extern "C" ssize_t MterpDoSparseSwitch(const uint16_t* switchData, int32_t testVal) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 62 | const int kInstrLen = 3; |
| 63 | uint16_t size; |
| 64 | const int32_t* keys; |
| 65 | const int32_t* entries; |
| 66 | |
| 67 | /* |
| 68 | * Sparse switch data format: |
| 69 | * ushort ident = 0x0200 magic value |
| 70 | * ushort size number of entries in the table; > 0 |
| 71 | * int keys[size] keys, sorted low-to-high; 32-bit aligned |
| 72 | * int targets[size] branch targets, relative to switch opcode |
| 73 | * |
| 74 | * Total size is (2+size*4) 16-bit code units. |
| 75 | */ |
| 76 | |
| 77 | uint16_t signature = *switchData++; |
| 78 | DCHECK_EQ(signature, static_cast<uint16_t>(art::Instruction::kSparseSwitchSignature)); |
| 79 | |
| 80 | size = *switchData++; |
| 81 | |
| 82 | /* The keys are guaranteed to be aligned on a 32-bit boundary; |
| 83 | * we can treat them as a native int array. |
| 84 | */ |
| 85 | keys = reinterpret_cast<const int32_t*>(switchData); |
| 86 | |
| 87 | /* The entries are guaranteed to be aligned on a 32-bit boundary; |
| 88 | * we can treat them as a native int array. |
| 89 | */ |
| 90 | entries = keys + size; |
| 91 | |
| 92 | /* |
| 93 | * Binary-search through the array of keys, which are guaranteed to |
| 94 | * be sorted low-to-high. |
| 95 | */ |
| 96 | int lo = 0; |
| 97 | int hi = size - 1; |
| 98 | while (lo <= hi) { |
| 99 | int mid = (lo + hi) >> 1; |
| 100 | |
| 101 | int32_t foundVal = keys[mid]; |
| 102 | if (testVal < foundVal) { |
| 103 | hi = mid - 1; |
| 104 | } else if (testVal > foundVal) { |
| 105 | lo = mid + 1; |
| 106 | } else { |
| 107 | return entries[mid]; |
| 108 | } |
| 109 | } |
| 110 | return kInstrLen; |
| 111 | } |
| 112 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 113 | extern "C" ssize_t MterpDoPackedSwitch(const uint16_t* switchData, int32_t testVal) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 114 | const int kInstrLen = 3; |
| 115 | |
| 116 | /* |
| 117 | * Packed switch data format: |
| 118 | * ushort ident = 0x0100 magic value |
| 119 | * ushort size number of entries in the table |
| 120 | * int first_key first (and lowest) switch case value |
| 121 | * int targets[size] branch targets, relative to switch opcode |
| 122 | * |
| 123 | * Total size is (4+size*2) 16-bit code units. |
| 124 | */ |
| 125 | uint16_t signature = *switchData++; |
| 126 | DCHECK_EQ(signature, static_cast<uint16_t>(art::Instruction::kPackedSwitchSignature)); |
| 127 | |
| 128 | uint16_t size = *switchData++; |
| 129 | |
| 130 | int32_t firstKey = *switchData++; |
| 131 | firstKey |= (*switchData++) << 16; |
| 132 | |
| 133 | int index = testVal - firstKey; |
| 134 | if (index < 0 || index >= size) { |
| 135 | return kInstrLen; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * The entries are guaranteed to be aligned on a 32-bit boundary; |
| 140 | * we can treat them as a native int array. |
| 141 | */ |
| 142 | const int32_t* entries = reinterpret_cast<const int32_t*>(switchData); |
| 143 | return entries[index]; |
| 144 | } |
| 145 | |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 146 | bool CanUseMterp() |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 147 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Alex Light | 848574c | 2017-09-25 16:59:39 -0700 | [diff] [blame] | 148 | const Runtime* const runtime = Runtime::Current(); |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 149 | return |
David Srbecky | cb4f09e | 2018-10-21 08:45:22 +0100 | [diff] [blame] | 150 | runtime->IsStarted() && |
| 151 | !runtime->IsAotCompiler() && |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 152 | !Dbg::IsDebuggerActive() && |
David Srbecky | cb4f09e | 2018-10-21 08:45:22 +0100 | [diff] [blame] | 153 | !runtime->GetInstrumentation()->IsActive() && |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 154 | // mterp only knows how to deal with the normal exits. It cannot handle any of the |
| 155 | // non-standard force-returns. |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 156 | !runtime->AreNonStandardExitsEnabled() && |
Alex Light | 848574c | 2017-09-25 16:59:39 -0700 | [diff] [blame] | 157 | // An async exception has been thrown. We need to go to the switch interpreter. MTerp doesn't |
| 158 | // know how to deal with these so we could end up never dealing with it if we are in an |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 159 | // infinite loop. |
David Srbecky | cb4f09e | 2018-10-21 08:45:22 +0100 | [diff] [blame] | 160 | !runtime->AreAsyncExceptionsThrown() && |
| 161 | (runtime->GetJit() == nullptr || !runtime->GetJit()->JitAtFirstUse()); |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 162 | } |
| 163 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 164 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 165 | extern "C" size_t MterpInvokeVirtual(Thread* self, |
| 166 | ShadowFrame* shadow_frame, |
| 167 | uint16_t* dex_pc_ptr, |
| 168 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 169 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 170 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 171 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 172 | return DoInvoke<kVirtual, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 173 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 176 | extern "C" size_t MterpInvokeSuper(Thread* self, |
| 177 | ShadowFrame* shadow_frame, |
| 178 | uint16_t* dex_pc_ptr, |
| 179 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 180 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 181 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 182 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 183 | return DoInvoke<kSuper, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 184 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 187 | extern "C" size_t MterpInvokeInterface(Thread* self, |
| 188 | ShadowFrame* shadow_frame, |
| 189 | uint16_t* dex_pc_ptr, |
| 190 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 191 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 192 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 193 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 194 | return DoInvoke<kInterface, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 195 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 198 | extern "C" size_t MterpInvokeDirect(Thread* self, |
| 199 | ShadowFrame* shadow_frame, |
| 200 | uint16_t* dex_pc_ptr, |
| 201 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 202 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 203 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 204 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 205 | return DoInvoke<kDirect, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 206 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 209 | extern "C" size_t MterpInvokeStatic(Thread* self, |
| 210 | ShadowFrame* shadow_frame, |
| 211 | uint16_t* dex_pc_ptr, |
| 212 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 213 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 214 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 215 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 216 | return DoInvoke<kStatic, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 217 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 220 | extern "C" size_t MterpInvokeCustom(Thread* self, |
| 221 | ShadowFrame* shadow_frame, |
| 222 | uint16_t* dex_pc_ptr, |
| 223 | uint16_t inst_data) |
| 224 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 225 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 226 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 227 | return DoInvokeCustom</* is_range= */ false>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 228 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | extern "C" size_t MterpInvokePolymorphic(Thread* self, |
| 232 | ShadowFrame* shadow_frame, |
| 233 | uint16_t* dex_pc_ptr, |
| 234 | uint16_t inst_data) |
| 235 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 236 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 237 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 238 | return DoInvokePolymorphic</* is_range= */ false>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 239 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 242 | extern "C" size_t MterpInvokeVirtualRange(Thread* self, |
| 243 | ShadowFrame* shadow_frame, |
| 244 | uint16_t* dex_pc_ptr, |
| 245 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 246 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 247 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 248 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 249 | return DoInvoke<kVirtual, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 250 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 253 | extern "C" size_t MterpInvokeSuperRange(Thread* self, |
| 254 | ShadowFrame* shadow_frame, |
| 255 | uint16_t* dex_pc_ptr, |
| 256 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 257 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 258 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 259 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 260 | return DoInvoke<kSuper, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 261 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 264 | extern "C" size_t MterpInvokeInterfaceRange(Thread* self, |
| 265 | ShadowFrame* shadow_frame, |
| 266 | uint16_t* dex_pc_ptr, |
| 267 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 268 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 269 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 270 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 271 | return DoInvoke<kInterface, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 272 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 275 | extern "C" size_t MterpInvokeDirectRange(Thread* self, |
| 276 | ShadowFrame* shadow_frame, |
| 277 | uint16_t* dex_pc_ptr, |
| 278 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 279 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 280 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 281 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 282 | return DoInvoke<kDirect, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 283 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 286 | extern "C" size_t MterpInvokeStaticRange(Thread* self, |
| 287 | ShadowFrame* shadow_frame, |
| 288 | uint16_t* dex_pc_ptr, |
| 289 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 290 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 291 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 292 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 1f5ab4e | 2018-10-15 11:46:46 +0100 | [diff] [blame] | 293 | return DoInvoke<kStatic, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 294 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 297 | extern "C" size_t MterpInvokeCustomRange(Thread* self, |
| 298 | ShadowFrame* shadow_frame, |
| 299 | uint16_t* dex_pc_ptr, |
| 300 | uint16_t inst_data) |
| 301 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 302 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 303 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 304 | return DoInvokeCustom</*is_range=*/ true>( |
| 305 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | extern "C" size_t MterpInvokePolymorphicRange(Thread* self, |
| 309 | ShadowFrame* shadow_frame, |
| 310 | uint16_t* dex_pc_ptr, |
| 311 | uint16_t inst_data) |
| 312 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 313 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 314 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 315 | return DoInvokePolymorphic</* is_range= */ true>( |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 316 | self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 317 | } |
| 318 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 319 | extern "C" size_t MterpInvokeVirtualQuick(Thread* self, |
| 320 | ShadowFrame* shadow_frame, |
| 321 | uint16_t* dex_pc_ptr, |
| 322 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 323 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 324 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 325 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 08cb738 | 2018-10-30 09:27:59 +0000 | [diff] [blame] | 326 | return DoInvoke<kVirtual, /*is_range=*/ false, /*do_access_check=*/ false, /*is_mterp=*/ true, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 327 | /*is_quick=*/ true>(self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 330 | extern "C" size_t MterpInvokeVirtualQuickRange(Thread* self, |
| 331 | ShadowFrame* shadow_frame, |
| 332 | uint16_t* dex_pc_ptr, |
| 333 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 334 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 335 | JValue* result_register = shadow_frame->GetResultRegister(); |
| 336 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | 08cb738 | 2018-10-30 09:27:59 +0000 | [diff] [blame] | 337 | return DoInvoke<kVirtual, /*is_range=*/ true, /*do_access_check=*/ false, /*is_mterp=*/ true, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 338 | /*is_quick=*/ true>(self, *shadow_frame, inst, inst_data, result_register) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | extern "C" void MterpThreadFenceForConstructor() { |
| 342 | QuasiAtomic::ThreadFenceForConstructor(); |
| 343 | } |
| 344 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 345 | extern "C" size_t MterpConstString(uint32_t index, |
| 346 | uint32_t tgt_vreg, |
| 347 | ShadowFrame* shadow_frame, |
| 348 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 349 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 350 | ObjPtr<mirror::String> s = ResolveString(self, *shadow_frame, dex::StringIndex(index)); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 351 | if (UNLIKELY(s == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 352 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 353 | } |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 354 | shadow_frame->SetVRegReference(tgt_vreg, s); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 355 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 358 | extern "C" size_t MterpConstClass(uint32_t index, |
| 359 | uint32_t tgt_vreg, |
| 360 | ShadowFrame* shadow_frame, |
| 361 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 362 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 363 | ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(index), |
| 364 | shadow_frame->GetMethod(), |
| 365 | self, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 366 | /* can_run_clinit= */ false, |
| 367 | /* verify_access= */ false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 368 | if (UNLIKELY(c == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 369 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 370 | } |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 371 | shadow_frame->SetVRegReference(tgt_vreg, c); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 372 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 375 | extern "C" size_t MterpConstMethodHandle(uint32_t index, |
| 376 | uint32_t tgt_vreg, |
| 377 | ShadowFrame* shadow_frame, |
| 378 | Thread* self) |
| 379 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 380 | ObjPtr<mirror::MethodHandle> mh = ResolveMethodHandle(self, index, shadow_frame->GetMethod()); |
| 381 | if (UNLIKELY(mh == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 382 | return 1u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 383 | } |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 384 | shadow_frame->SetVRegReference(tgt_vreg, mh); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 385 | return 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | extern "C" size_t MterpConstMethodType(uint32_t index, |
| 389 | uint32_t tgt_vreg, |
| 390 | ShadowFrame* shadow_frame, |
| 391 | Thread* self) |
| 392 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 393 | ObjPtr<mirror::MethodType> mt = |
| 394 | ResolveMethodType(self, dex::ProtoIndex(index), shadow_frame->GetMethod()); |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 395 | if (UNLIKELY(mt == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 396 | return 1u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 397 | } |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 398 | shadow_frame->SetVRegReference(tgt_vreg, mt); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 399 | return 0u; |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 402 | extern "C" size_t MterpCheckCast(uint32_t index, |
| 403 | StackReference<mirror::Object>* vreg_addr, |
| 404 | art::ArtMethod* method, |
| 405 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 406 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 407 | ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(index), |
| 408 | method, |
| 409 | self, |
| 410 | false, |
| 411 | false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 412 | if (UNLIKELY(c == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 413 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 414 | } |
buzbee | a2c97a9 | 2016-01-25 15:41:24 -0800 | [diff] [blame] | 415 | // Must load obj from vreg following ResolveVerifyAndClinit due to moving gc. |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 416 | ObjPtr<mirror::Object> obj = vreg_addr->AsMirrorPtr(); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 417 | if (UNLIKELY(obj != nullptr && !obj->InstanceOf(c))) { |
| 418 | ThrowClassCastException(c, obj->GetClass()); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 419 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 420 | } |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 421 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 424 | extern "C" size_t MterpInstanceOf(uint32_t index, |
| 425 | StackReference<mirror::Object>* vreg_addr, |
| 426 | art::ArtMethod* method, |
| 427 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 428 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 429 | ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(index), |
| 430 | method, |
| 431 | self, |
| 432 | false, |
| 433 | false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 434 | if (UNLIKELY(c == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 435 | return 0u; // Caller will check for pending exception. Return value unimportant. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 436 | } |
buzbee | a2c97a9 | 2016-01-25 15:41:24 -0800 | [diff] [blame] | 437 | // Must load obj from vreg following ResolveVerifyAndClinit due to moving gc. |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 438 | ObjPtr<mirror::Object> obj = vreg_addr->AsMirrorPtr(); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 439 | return (obj != nullptr) && obj->InstanceOf(c) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 442 | extern "C" size_t MterpFillArrayData(mirror::Object* obj, |
| 443 | const Instruction::ArrayDataPayload* payload) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 444 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 445 | return FillArrayData(obj, payload) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 448 | extern "C" size_t MterpNewInstance(ShadowFrame* shadow_frame, Thread* self, uint32_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 449 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 450 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 451 | ObjPtr<mirror::Object> obj = nullptr; |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 452 | ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(inst->VRegB_21c()), |
| 453 | shadow_frame->GetMethod(), |
| 454 | self, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 455 | /* can_run_clinit= */ false, |
| 456 | /* verify_access= */ false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 457 | if (LIKELY(c != nullptr)) { |
| 458 | if (UNLIKELY(c->IsStringClass())) { |
| 459 | gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator(); |
Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 460 | obj = mirror::String::AllocEmptyString(self, allocator_type); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 461 | } else { |
Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 462 | obj = AllocObjectFromCode(c, self, Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | if (UNLIKELY(obj == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 466 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 467 | } |
| 468 | obj->GetClass()->AssertInitializedOrInitializingInThread(self); |
| 469 | shadow_frame->SetVRegReference(inst->VRegA_21c(inst_data), obj); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 470 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 473 | extern "C" size_t MterpIputObjectQuick(ShadowFrame* shadow_frame, |
| 474 | uint16_t* dex_pc_ptr, |
| 475 | uint32_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 476 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 477 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 478 | return DoIPutQuick<Primitive::kPrimNot, false>(*shadow_frame, inst, inst_data) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 479 | } |
| 480 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 481 | extern "C" size_t MterpAputObject(ShadowFrame* shadow_frame, |
| 482 | uint16_t* dex_pc_ptr, |
| 483 | uint32_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 484 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 485 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 486 | ObjPtr<mirror::Object> a = shadow_frame->GetVRegReference(inst->VRegB_23x()); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 487 | if (UNLIKELY(a == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 488 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 489 | } |
| 490 | int32_t index = shadow_frame->GetVReg(inst->VRegC_23x()); |
Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 491 | ObjPtr<mirror::Object> val = shadow_frame->GetVRegReference(inst->VRegA_23x(inst_data)); |
| 492 | ObjPtr<mirror::ObjectArray<mirror::Object>> array = a->AsObjectArray<mirror::Object>(); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 493 | if (array->CheckIsValidIndex(index) && array->CheckAssignable(val)) { |
| 494 | array->SetWithoutChecks<false>(index, val); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 495 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 496 | } |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 497 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 500 | extern "C" size_t MterpFilledNewArray(ShadowFrame* shadow_frame, |
| 501 | uint16_t* dex_pc_ptr, |
| 502 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 503 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 504 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
| 505 | return DoFilledNewArray<false, false, false>(inst, *shadow_frame, self, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 506 | shadow_frame->GetResultRegister()) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 509 | extern "C" size_t MterpFilledNewArrayRange(ShadowFrame* shadow_frame, |
| 510 | uint16_t* dex_pc_ptr, |
| 511 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 512 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 513 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
| 514 | return DoFilledNewArray<true, false, false>(inst, *shadow_frame, self, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 515 | shadow_frame->GetResultRegister()) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 518 | extern "C" size_t MterpNewArray(ShadowFrame* shadow_frame, |
| 519 | uint16_t* dex_pc_ptr, |
| 520 | uint32_t inst_data, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 521 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 522 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
| 523 | int32_t length = shadow_frame->GetVReg(inst->VRegB_22c(inst_data)); |
Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 524 | ObjPtr<mirror::Object> obj = AllocArrayFromCode</*kAccessCheck=*/ false>( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 525 | dex::TypeIndex(inst->VRegC_22c()), length, shadow_frame->GetMethod(), self, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 526 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
| 527 | if (UNLIKELY(obj == nullptr)) { |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 528 | return 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 529 | } |
| 530 | shadow_frame->SetVRegReference(inst->VRegA_22c(inst_data), obj); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 531 | return 1u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 534 | extern "C" size_t MterpHandleException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 535 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 536 | DCHECK(self->IsExceptionPending()); |
| 537 | const instrumentation::Instrumentation* const instrumentation = |
| 538 | Runtime::Current()->GetInstrumentation(); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 539 | return MoveToExceptionHandler(self, *shadow_frame, instrumentation) ? 1u : 0u; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 540 | } |
| 541 | |
David Srbecky | 68b926e | 2018-11-28 17:43:42 +0000 | [diff] [blame] | 542 | struct MterpCheckHelper { |
| 543 | DECLARE_RUNTIME_DEBUG_FLAG(kSlowMode); |
| 544 | }; |
| 545 | DEFINE_RUNTIME_DEBUG_FLAG(MterpCheckHelper, kSlowMode); |
| 546 | |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 547 | extern "C" void MterpCheckBefore(Thread* self, ShadowFrame* shadow_frame, uint16_t* dex_pc_ptr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 548 | REQUIRES_SHARED(Locks::mutator_lock_) { |
David Srbecky | d388390 | 2019-02-26 17:29:32 +0000 | [diff] [blame] | 549 | // Check that we are using the right interpreter. |
| 550 | if (kIsDebugBuild && self->UseMterp() != CanUseMterp()) { |
| 551 | // The flag might be currently being updated on all threads. Retry with lock. |
| 552 | MutexLock tll_mu(self, *Locks::thread_list_lock_); |
| 553 | DCHECK_EQ(self->UseMterp(), CanUseMterp()); |
| 554 | } |
David Srbecky | cb4f09e | 2018-10-21 08:45:22 +0100 | [diff] [blame] | 555 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 556 | const Instruction* inst = Instruction::At(dex_pc_ptr); |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame^] | 557 | uint16_t inst_data = inst->Fetch16(0); |
| 558 | if (inst->Opcode(inst_data) == Instruction::MOVE_EXCEPTION) { |
| 559 | self->AssertPendingException(); |
| 560 | } else { |
| 561 | self->AssertNoPendingException(); |
| 562 | } |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 563 | if (kTraceExecutionEnabled) { |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame^] | 564 | uint32_t dex_pc = dex_pc_ptr - shadow_frame->GetDexInstructions(); |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 565 | TraceExecution(*shadow_frame, inst, dex_pc); |
| 566 | } |
| 567 | if (kTestExportPC) { |
| 568 | // Save invalid dex pc to force segfault if improperly used. |
| 569 | shadow_frame->SetDexPCPtr(reinterpret_cast<uint16_t*>(kExportPCPoison)); |
| 570 | } |
David Srbecky | 68b926e | 2018-11-28 17:43:42 +0000 | [diff] [blame] | 571 | if (MterpCheckHelper::kSlowMode) { |
| 572 | shadow_frame->CheckConsistentVRegs(); |
| 573 | } |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | extern "C" void MterpLogDivideByZeroException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 577 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 578 | UNUSED(self); |
| 579 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 580 | uint16_t inst_data = inst->Fetch16(0); |
| 581 | LOG(INFO) << "DivideByZero: " << inst->Opcode(inst_data); |
| 582 | } |
| 583 | |
| 584 | extern "C" void MterpLogArrayIndexException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 585 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 586 | UNUSED(self); |
| 587 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 588 | uint16_t inst_data = inst->Fetch16(0); |
| 589 | LOG(INFO) << "ArrayIndex: " << inst->Opcode(inst_data); |
| 590 | } |
| 591 | |
| 592 | extern "C" void MterpLogNegativeArraySizeException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 593 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 594 | UNUSED(self); |
| 595 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 596 | uint16_t inst_data = inst->Fetch16(0); |
| 597 | LOG(INFO) << "NegativeArraySize: " << inst->Opcode(inst_data); |
| 598 | } |
| 599 | |
| 600 | extern "C" void MterpLogNoSuchMethodException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 601 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 602 | UNUSED(self); |
| 603 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 604 | uint16_t inst_data = inst->Fetch16(0); |
| 605 | LOG(INFO) << "NoSuchMethod: " << inst->Opcode(inst_data); |
| 606 | } |
| 607 | |
| 608 | extern "C" void MterpLogExceptionThrownException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 609 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 610 | UNUSED(self); |
| 611 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 612 | uint16_t inst_data = inst->Fetch16(0); |
| 613 | LOG(INFO) << "ExceptionThrown: " << inst->Opcode(inst_data); |
| 614 | } |
| 615 | |
| 616 | extern "C" void MterpLogNullObjectException(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 617 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 618 | UNUSED(self); |
| 619 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 620 | uint16_t inst_data = inst->Fetch16(0); |
| 621 | LOG(INFO) << "NullObject: " << inst->Opcode(inst_data); |
| 622 | } |
| 623 | |
| 624 | extern "C" void MterpLogFallback(Thread* self, ShadowFrame* shadow_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 625 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 626 | UNUSED(self); |
| 627 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 628 | uint16_t inst_data = inst->Fetch16(0); |
| 629 | LOG(INFO) << "Fallback: " << inst->Opcode(inst_data) << ", Suspend Pending?: " |
| 630 | << self->IsExceptionPending(); |
| 631 | } |
| 632 | |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 633 | extern "C" void MterpLogOSR(Thread* self, ShadowFrame* shadow_frame, int32_t offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 634 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 635 | UNUSED(self); |
| 636 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 637 | uint16_t inst_data = inst->Fetch16(0); |
| 638 | LOG(INFO) << "OSR: " << inst->Opcode(inst_data) << ", offset = " << offset; |
| 639 | } |
| 640 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 641 | extern "C" void MterpLogSuspendFallback(Thread* self, ShadowFrame* shadow_frame, uint32_t flags) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 642 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 643 | UNUSED(self); |
| 644 | const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); |
| 645 | uint16_t inst_data = inst->Fetch16(0); |
| 646 | if (flags & kCheckpointRequest) { |
| 647 | LOG(INFO) << "Checkpoint fallback: " << inst->Opcode(inst_data); |
| 648 | } else if (flags & kSuspendRequest) { |
| 649 | LOG(INFO) << "Suspend fallback: " << inst->Opcode(inst_data); |
Hiroshi Yamauchi | 3049324 | 2016-11-03 13:06:52 -0700 | [diff] [blame] | 650 | } else if (flags & kEmptyCheckpointRequest) { |
| 651 | LOG(INFO) << "Empty checkpoint fallback: " << inst->Opcode(inst_data); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 655 | extern "C" size_t MterpSuspendCheck(Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 656 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 657 | self->AllowThreadSuspension(); |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 658 | return !self->UseMterp(); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 659 | } |
| 660 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 661 | // Execute single field access instruction (get/put, static/instance). |
| 662 | // The template arguments reduce this to fairly small amount of code. |
| 663 | // It requires the target object and field to be already resolved. |
| 664 | template<typename PrimType, FindFieldType kAccessType> |
| 665 | ALWAYS_INLINE void MterpFieldAccess(Instruction* inst, |
| 666 | uint16_t inst_data, |
| 667 | ShadowFrame* shadow_frame, |
| 668 | ObjPtr<mirror::Object> obj, |
| 669 | MemberOffset offset, |
| 670 | bool is_volatile) |
| 671 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 672 | static_assert(std::is_integral<PrimType>::value, "Unexpected primitive type"); |
| 673 | constexpr bool kIsStatic = (kAccessType & FindFieldFlags::StaticBit) != 0; |
| 674 | constexpr bool kIsPrimitive = (kAccessType & FindFieldFlags::PrimitiveBit) != 0; |
| 675 | constexpr bool kIsRead = (kAccessType & FindFieldFlags::ReadBit) != 0; |
| 676 | |
| 677 | uint16_t vRegA = kIsStatic ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 678 | if (kIsPrimitive) { |
| 679 | if (kIsRead) { |
| 680 | PrimType value = UNLIKELY(is_volatile) |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 681 | ? obj->GetFieldPrimitive<PrimType, /*kIsVolatile=*/ true>(offset) |
| 682 | : obj->GetFieldPrimitive<PrimType, /*kIsVolatile=*/ false>(offset); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 683 | if (sizeof(PrimType) == sizeof(uint64_t)) { |
| 684 | shadow_frame->SetVRegLong(vRegA, value); // Set two consecutive registers. |
| 685 | } else { |
| 686 | shadow_frame->SetVReg(vRegA, static_cast<int32_t>(value)); // Sign/zero extend. |
| 687 | } |
| 688 | } else { // Write. |
| 689 | uint64_t value = (sizeof(PrimType) == sizeof(uint64_t)) |
| 690 | ? shadow_frame->GetVRegLong(vRegA) |
| 691 | : shadow_frame->GetVReg(vRegA); |
| 692 | if (UNLIKELY(is_volatile)) { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 693 | obj->SetFieldPrimitive<PrimType, /*kIsVolatile=*/ true>(offset, value); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 694 | } else { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 695 | obj->SetFieldPrimitive<PrimType, /*kIsVolatile=*/ false>(offset, value); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | } else { // Object. |
| 699 | if (kIsRead) { |
| 700 | ObjPtr<mirror::Object> value = UNLIKELY(is_volatile) |
| 701 | ? obj->GetFieldObjectVolatile<mirror::Object>(offset) |
| 702 | : obj->GetFieldObject<mirror::Object>(offset); |
| 703 | shadow_frame->SetVRegReference(vRegA, value); |
| 704 | } else { // Write. |
| 705 | ObjPtr<mirror::Object> value = shadow_frame->GetVRegReference(vRegA); |
| 706 | if (UNLIKELY(is_volatile)) { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 707 | obj->SetFieldObjectVolatile</*kTransactionActive=*/ false>(offset, value); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 708 | } else { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 709 | obj->SetFieldObject</*kTransactionActive=*/ false>(offset, value); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 710 | } |
| 711 | } |
David Srbecky | 104bab6 | 2018-08-07 17:09:01 +0100 | [diff] [blame] | 712 | } |
David Srbecky | 104bab6 | 2018-08-07 17:09:01 +0100 | [diff] [blame] | 713 | } |
| 714 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 715 | template<typename PrimType, FindFieldType kAccessType> |
| 716 | NO_INLINE bool MterpFieldAccessSlow(Instruction* inst, |
| 717 | uint16_t inst_data, |
| 718 | ShadowFrame* shadow_frame, |
| 719 | Thread* self) |
| 720 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 721 | constexpr bool kIsStatic = (kAccessType & FindFieldFlags::StaticBit) != 0; |
| 722 | constexpr bool kIsRead = (kAccessType & FindFieldFlags::ReadBit) != 0; |
| 723 | |
| 724 | // Update the dex pc in shadow frame, just in case anything throws. |
| 725 | shadow_frame->SetDexPCPtr(reinterpret_cast<uint16_t*>(inst)); |
| 726 | ArtMethod* referrer = shadow_frame->GetMethod(); |
| 727 | uint32_t field_idx = kIsStatic ? inst->VRegB_21c() : inst->VRegC_22c(); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 728 | ArtField* field = FindFieldFromCode<kAccessType, /* access_checks= */ false>( |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 729 | field_idx, referrer, self, sizeof(PrimType)); |
| 730 | if (UNLIKELY(field == nullptr)) { |
| 731 | DCHECK(self->IsExceptionPending()); |
| 732 | return false; |
| 733 | } |
| 734 | ObjPtr<mirror::Object> obj = kIsStatic |
| 735 | ? field->GetDeclaringClass().Ptr() |
| 736 | : shadow_frame->GetVRegReference(inst->VRegB_22c(inst_data)); |
| 737 | if (UNLIKELY(obj == nullptr)) { |
| 738 | ThrowNullPointerExceptionForFieldAccess(field, kIsRead); |
| 739 | return false; |
| 740 | } |
| 741 | MterpFieldAccess<PrimType, kAccessType>( |
| 742 | inst, inst_data, shadow_frame, obj, field->GetOffset(), field->IsVolatile()); |
| 743 | return true; |
| 744 | } |
| 745 | |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 746 | // This methods is called from assembly to handle field access instructions. |
| 747 | // |
| 748 | // This method is fairly hot. It is long, but it has been carefully optimized. |
| 749 | // It contains only fully inlined methods -> no spills -> no prologue/epilogue. |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 750 | template<typename PrimType, FindFieldType kAccessType> |
| 751 | ALWAYS_INLINE bool MterpFieldAccessFast(Instruction* inst, |
| 752 | uint16_t inst_data, |
| 753 | ShadowFrame* shadow_frame, |
| 754 | Thread* self) |
| 755 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 756 | constexpr bool kIsStatic = (kAccessType & FindFieldFlags::StaticBit) != 0; |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 757 | |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 758 | // Try to find the field in small thread-local cache first. |
| 759 | InterpreterCache* tls_cache = self->GetInterpreterCache(); |
| 760 | size_t tls_value; |
| 761 | if (LIKELY(tls_cache->Get(inst, &tls_value))) { |
| 762 | // The meaning of the cache value is opcode-specific. |
| 763 | // It is ArtFiled* for static fields and the raw offset for instance fields. |
| 764 | size_t offset = kIsStatic |
| 765 | ? reinterpret_cast<ArtField*>(tls_value)->GetOffset().SizeValue() |
| 766 | : tls_value; |
| 767 | if (kIsDebugBuild) { |
| 768 | uint32_t field_idx = kIsStatic ? inst->VRegB_21c() : inst->VRegC_22c(); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 769 | ArtField* field = FindFieldFromCode<kAccessType, /* access_checks= */ false>( |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 770 | field_idx, shadow_frame->GetMethod(), self, sizeof(PrimType)); |
| 771 | DCHECK_EQ(offset, field->GetOffset().SizeValue()); |
| 772 | } |
| 773 | ObjPtr<mirror::Object> obj = kIsStatic |
| 774 | ? reinterpret_cast<ArtField*>(tls_value)->GetDeclaringClass() |
Vladimir Marko | d7e9bbf | 2019-03-28 13:18:57 +0000 | [diff] [blame] | 775 | : ObjPtr<mirror::Object>(shadow_frame->GetVRegReference(inst->VRegB_22c(inst_data))); |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 776 | if (LIKELY(obj != nullptr)) { |
| 777 | MterpFieldAccess<PrimType, kAccessType>( |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 778 | inst, inst_data, shadow_frame, obj, MemberOffset(offset), /* is_volatile= */ false); |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 779 | return true; |
| 780 | } |
| 781 | } |
| 782 | |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 783 | // This effectively inlines the fast path from ArtMethod::GetDexCache. |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 784 | ArtMethod* referrer = shadow_frame->GetMethod(); |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 785 | if (LIKELY(!referrer->IsObsolete())) { |
| 786 | // Avoid read barriers, since we need only the pointer to the native (non-movable) |
| 787 | // DexCache field array which we can get even through from-space objects. |
| 788 | ObjPtr<mirror::Class> klass = referrer->GetDeclaringClass<kWithoutReadBarrier>(); |
Vladimir Marko | c524e9e | 2019-03-26 10:54:50 +0000 | [diff] [blame] | 789 | ObjPtr<mirror::DexCache> dex_cache = |
| 790 | klass->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>(); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 791 | |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 792 | // Try to find the desired field in DexCache. |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 793 | uint32_t field_idx = kIsStatic ? inst->VRegB_21c() : inst->VRegC_22c(); |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 794 | ArtField* field = dex_cache->GetResolvedField(field_idx, kRuntimePointerSize); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 795 | if (LIKELY(field != nullptr)) { |
| 796 | bool initialized = !kIsStatic || field->GetDeclaringClass()->IsInitialized(); |
| 797 | if (LIKELY(initialized)) { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 798 | DCHECK_EQ(field, (FindFieldFromCode<kAccessType, /* access_checks= */ false>( |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 799 | field_idx, referrer, self, sizeof(PrimType)))); |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 800 | ObjPtr<mirror::Object> obj = kIsStatic |
| 801 | ? field->GetDeclaringClass().Ptr() |
| 802 | : shadow_frame->GetVRegReference(inst->VRegB_22c(inst_data)); |
| 803 | if (LIKELY(kIsStatic || obj != nullptr)) { |
David Srbecky | ef79aa3 | 2018-09-08 18:02:36 +0100 | [diff] [blame] | 804 | // Only non-volatile fields are allowed in the thread-local cache. |
| 805 | if (LIKELY(!field->IsVolatile())) { |
| 806 | if (kIsStatic) { |
| 807 | tls_cache->Set(inst, reinterpret_cast<uintptr_t>(field)); |
| 808 | } else { |
| 809 | tls_cache->Set(inst, field->GetOffset().SizeValue()); |
| 810 | } |
| 811 | } |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 812 | MterpFieldAccess<PrimType, kAccessType>( |
| 813 | inst, inst_data, shadow_frame, obj, field->GetOffset(), field->IsVolatile()); |
| 814 | return true; |
| 815 | } |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 816 | } |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 817 | } |
| 818 | } |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 819 | |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 820 | // Slow path. Last and with identical arguments so that it becomes single instruction tail call. |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 821 | return MterpFieldAccessSlow<PrimType, kAccessType>(inst, inst_data, shadow_frame, self); |
David Srbecky | ffa15ea | 2018-08-16 10:04:11 +0100 | [diff] [blame] | 822 | } |
| 823 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 824 | #define MTERP_FIELD_ACCESSOR(Name, PrimType, AccessType) \ |
| 825 | extern "C" bool Name(Instruction* inst, uint16_t inst_data, ShadowFrame* sf, Thread* self) \ |
| 826 | REQUIRES_SHARED(Locks::mutator_lock_) { \ |
| 827 | return MterpFieldAccessFast<PrimType, AccessType>(inst, inst_data, sf, self); \ |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 828 | } |
| 829 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 830 | #define MTERP_FIELD_ACCESSORS_FOR_TYPE(Sufix, PrimType, Kind) \ |
| 831 | MTERP_FIELD_ACCESSOR(MterpIGet##Sufix, PrimType, Instance##Kind##Read) \ |
| 832 | MTERP_FIELD_ACCESSOR(MterpIPut##Sufix, PrimType, Instance##Kind##Write) \ |
| 833 | MTERP_FIELD_ACCESSOR(MterpSGet##Sufix, PrimType, Static##Kind##Read) \ |
| 834 | MTERP_FIELD_ACCESSOR(MterpSPut##Sufix, PrimType, Static##Kind##Write) |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 835 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 836 | MTERP_FIELD_ACCESSORS_FOR_TYPE(I8, int8_t, Primitive) |
| 837 | MTERP_FIELD_ACCESSORS_FOR_TYPE(U8, uint8_t, Primitive) |
| 838 | MTERP_FIELD_ACCESSORS_FOR_TYPE(I16, int16_t, Primitive) |
| 839 | MTERP_FIELD_ACCESSORS_FOR_TYPE(U16, uint16_t, Primitive) |
| 840 | MTERP_FIELD_ACCESSORS_FOR_TYPE(U32, uint32_t, Primitive) |
| 841 | MTERP_FIELD_ACCESSORS_FOR_TYPE(U64, uint64_t, Primitive) |
| 842 | MTERP_FIELD_ACCESSORS_FOR_TYPE(Obj, uint32_t, Object) |
David Srbecky | 28dfc59 | 2018-08-22 15:29:09 +0100 | [diff] [blame] | 843 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 844 | // Check that the primitive type for Obj variant above is correct. |
| 845 | // It really must be primitive type for the templates to compile. |
| 846 | // In the case of objects, it is only used to get the field size. |
| 847 | static_assert(kHeapReferenceSize == sizeof(uint32_t), "Unexpected kHeapReferenceSize"); |
David Srbecky | 28dfc59 | 2018-08-22 15:29:09 +0100 | [diff] [blame] | 848 | |
David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 849 | #undef MTERP_FIELD_ACCESSORS_FOR_TYPE |
| 850 | #undef MTERP_FIELD_ACCESSOR |
buzbee | fa6adfd | 2017-02-22 13:40:59 -0800 | [diff] [blame] | 851 | |
| 852 | extern "C" mirror::Object* artAGetObjectFromMterp(mirror::Object* arr, |
| 853 | int32_t index) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 854 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 855 | if (UNLIKELY(arr == nullptr)) { |
| 856 | ThrowNullPointerExceptionFromInterpreter(); |
| 857 | return nullptr; |
| 858 | } |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 859 | ObjPtr<mirror::ObjectArray<mirror::Object>> array = arr->AsObjectArray<mirror::Object>(); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 860 | if (LIKELY(array->CheckIsValidIndex(index))) { |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 861 | return array->GetWithoutChecks(index).Ptr(); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 862 | } else { |
| 863 | return nullptr; |
| 864 | } |
| 865 | } |
| 866 | |
buzbee | fa6adfd | 2017-02-22 13:40:59 -0800 | [diff] [blame] | 867 | extern "C" mirror::Object* artIGetObjectFromMterp(mirror::Object* obj, |
| 868 | uint32_t field_offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 869 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 76833da | 2016-01-13 13:06:22 -0800 | [diff] [blame] | 870 | if (UNLIKELY(obj == nullptr)) { |
| 871 | ThrowNullPointerExceptionFromInterpreter(); |
| 872 | return nullptr; |
| 873 | } |
| 874 | return obj->GetFieldObject<mirror::Object>(MemberOffset(field_offset)); |
| 875 | } |
| 876 | |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 877 | /* |
| 878 | * Create a hotness_countdown based on the current method hotness_count and profiling |
| 879 | * mode. In short, determine how many hotness events we hit before reporting back |
| 880 | * to the full instrumentation via MterpAddHotnessBatch. Called once on entry to the method, |
| 881 | * and regenerated following batch updates. |
| 882 | */ |
Vladimir Marko | a710d91 | 2017-09-12 14:56:07 +0100 | [diff] [blame] | 883 | extern "C" ssize_t MterpSetUpHotnessCountdown(ArtMethod* method, |
| 884 | ShadowFrame* shadow_frame, |
| 885 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 886 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 887 | uint16_t hotness_count = method->GetCounter(); |
| 888 | int32_t countdown_value = jit::kJitHotnessDisabled; |
| 889 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 890 | if (jit != nullptr) { |
Nicolas Geoffray | 0402f4b | 2018-11-29 19:18:46 +0000 | [diff] [blame] | 891 | int32_t warm_threshold = jit->WarmMethodThreshold(); |
| 892 | int32_t hot_threshold = jit->HotMethodThreshold(); |
| 893 | int32_t osr_threshold = jit->OSRMethodThreshold(); |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 894 | if (hotness_count < warm_threshold) { |
| 895 | countdown_value = warm_threshold - hotness_count; |
| 896 | } else if (hotness_count < hot_threshold) { |
| 897 | countdown_value = hot_threshold - hotness_count; |
| 898 | } else if (hotness_count < osr_threshold) { |
| 899 | countdown_value = osr_threshold - hotness_count; |
| 900 | } else { |
| 901 | countdown_value = jit::kJitCheckForOSR; |
| 902 | } |
Vladimir Marko | a710d91 | 2017-09-12 14:56:07 +0100 | [diff] [blame] | 903 | if (jit::Jit::ShouldUsePriorityThreadWeight(self)) { |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 904 | int32_t priority_thread_weight = jit->PriorityThreadWeight(); |
Calin Juravle | b2771b4 | 2016-04-07 17:09:25 +0100 | [diff] [blame] | 905 | countdown_value = std::min(countdown_value, countdown_value / priority_thread_weight); |
| 906 | } |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 907 | } |
| 908 | /* |
| 909 | * The actual hotness threshold may exceed the range of our int16_t countdown value. This is |
| 910 | * not a problem, though. We can just break it down into smaller chunks. |
| 911 | */ |
| 912 | countdown_value = std::min(countdown_value, |
| 913 | static_cast<int32_t>(std::numeric_limits<int16_t>::max())); |
| 914 | shadow_frame->SetCachedHotnessCountdown(countdown_value); |
| 915 | shadow_frame->SetHotnessCountdown(countdown_value); |
| 916 | return countdown_value; |
| 917 | } |
| 918 | |
| 919 | /* |
| 920 | * Report a batch of hotness events to the instrumentation and then return the new |
| 921 | * countdown value to the next time we should report. |
| 922 | */ |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 923 | extern "C" ssize_t MterpAddHotnessBatch(ArtMethod* method, |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 924 | ShadowFrame* shadow_frame, |
| 925 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 926 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 927 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 928 | if (jit != nullptr) { |
| 929 | int16_t count = shadow_frame->GetCachedHotnessCountdown() - shadow_frame->GetHotnessCountdown(); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 930 | jit->AddSamples(self, method, count, /*with_backedges=*/ true); |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 931 | } |
Vladimir Marko | a710d91 | 2017-09-12 14:56:07 +0100 | [diff] [blame] | 932 | return MterpSetUpHotnessCountdown(method, shadow_frame, self); |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 935 | extern "C" size_t MterpMaybeDoOnStackReplacement(Thread* self, |
| 936 | ShadowFrame* shadow_frame, |
| 937 | int32_t offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 938 | REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 42a09cb0 | 2017-02-01 09:08:31 -0800 | [diff] [blame] | 939 | int16_t osr_countdown = shadow_frame->GetCachedHotnessCountdown() - 1; |
| 940 | bool did_osr = false; |
| 941 | /* |
| 942 | * To reduce the cost of polling the compiler to determine whether the requested OSR |
| 943 | * compilation has completed, only check every Nth time. NOTE: the "osr_countdown <= 0" |
| 944 | * condition is satisfied either by the decrement below or the initial setting of |
| 945 | * the cached countdown field to kJitCheckForOSR, which elsewhere is asserted to be -1. |
| 946 | */ |
| 947 | if (osr_countdown <= 0) { |
| 948 | ArtMethod* method = shadow_frame->GetMethod(); |
| 949 | JValue* result = shadow_frame->GetResultRegister(); |
| 950 | uint32_t dex_pc = shadow_frame->GetDexPC(); |
| 951 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 952 | osr_countdown = jit::Jit::kJitRecheckOSRThreshold; |
| 953 | if (offset <= 0) { |
| 954 | // Keep updating hotness in case a compilation request was dropped. Eventually it will retry. |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 955 | jit->AddSamples(self, method, osr_countdown, /*with_backedges=*/ true); |
buzbee | 42a09cb0 | 2017-02-01 09:08:31 -0800 | [diff] [blame] | 956 | } |
| 957 | did_osr = jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, result); |
buzbee | 0e6aa6d | 2016-04-11 07:48:18 -0700 | [diff] [blame] | 958 | } |
buzbee | 42a09cb0 | 2017-02-01 09:08:31 -0800 | [diff] [blame] | 959 | shadow_frame->SetCachedHotnessCountdown(osr_countdown); |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 960 | return did_osr ? 1u : 0u; |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 961 | } |
| 962 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 963 | } // namespace interpreter |
| 964 | } // namespace art |