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