Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |
| 18 | #define ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |
| 19 | |
| 20 | #include "interpreter.h" |
| 21 | |
| 22 | #include <math.h> |
| 23 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 24 | #include <iostream> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 25 | #include <sstream> |
| 26 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 27 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "art_method-inl.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 29 | #include "base/logging.h" |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 30 | #include "base/macros.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 31 | #include "class_linker-inl.h" |
| 32 | #include "common_throws.h" |
| 33 | #include "dex_file-inl.h" |
| 34 | #include "dex_instruction-inl.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 35 | #include "entrypoints/entrypoint_utils-inl.h" |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 36 | #include "handle_scope-inl.h" |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 37 | #include "lambda/box_table.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 38 | #include "mirror/class-inl.h" |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 39 | #include "mirror/method.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 40 | #include "mirror/object-inl.h" |
| 41 | #include "mirror/object_array-inl.h" |
Douglas Leung | 4965c02 | 2014-06-11 11:41:11 -0700 | [diff] [blame] | 42 | #include "mirror/string-inl.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 43 | #include "thread.h" |
| 44 | #include "well_known_classes.h" |
| 45 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 46 | using ::art::ArtMethod; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 47 | using ::art::mirror::Array; |
| 48 | using ::art::mirror::BooleanArray; |
| 49 | using ::art::mirror::ByteArray; |
| 50 | using ::art::mirror::CharArray; |
| 51 | using ::art::mirror::Class; |
| 52 | using ::art::mirror::ClassLoader; |
| 53 | using ::art::mirror::IntArray; |
| 54 | using ::art::mirror::LongArray; |
| 55 | using ::art::mirror::Object; |
| 56 | using ::art::mirror::ObjectArray; |
| 57 | using ::art::mirror::ShortArray; |
| 58 | using ::art::mirror::String; |
| 59 | using ::art::mirror::Throwable; |
| 60 | |
| 61 | namespace art { |
| 62 | namespace interpreter { |
| 63 | |
| 64 | // External references to both interpreter implementations. |
| 65 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 66 | template<bool do_access_check, bool transaction_active> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 67 | extern JValue ExecuteSwitchImpl(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 68 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 69 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 70 | template<bool do_access_check, bool transaction_active> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 71 | extern JValue ExecuteGotoImpl(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 72 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 73 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 74 | void ThrowNullPointerExceptionFromInterpreter() |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 75 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | da843e1 | 2014-05-28 19:28:31 +0200 | [diff] [blame] | 76 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 77 | static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 78 | ref->MonitorEnter(self); |
| 79 | } |
| 80 | |
| 81 | static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 82 | ref->MonitorExit(self); |
| 83 | } |
| 84 | |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 85 | void AbortTransactionF(Thread* self, const char* fmt, ...) |
| 86 | __attribute__((__format__(__printf__, 2, 3))) |
| 87 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 88 | |
| 89 | void AbortTransactionV(Thread* self, const char* fmt, va_list args) |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 90 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 91 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 92 | void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count) |
| 93 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 94 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 95 | // Invokes the given method. This is part of the invocation support and is used by DoInvoke and |
| 96 | // DoInvokeVirtualQuick functions. |
| 97 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 98 | template<bool is_range, bool do_assignability_check> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 99 | bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 100 | const Instruction* inst, uint16_t inst_data, JValue* result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 101 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 102 | // Invokes the given lambda closure. This is part of the invocation support and is used by |
| 103 | // DoLambdaInvoke functions. |
| 104 | // Returns true on success, otherwise throws an exception and returns false. |
| 105 | template<bool is_range, bool do_assignability_check> |
| 106 | bool DoLambdaCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
| 107 | const Instruction* inst, uint16_t inst_data, JValue* result); |
| 108 | |
| 109 | // Validates that the art method corresponding to a lambda method target |
| 110 | // is semantically valid: |
| 111 | // |
| 112 | // Must be ACC_STATIC and ACC_LAMBDA. Must be a concrete managed implementation |
| 113 | // (i.e. not native, not proxy, not abstract, ...). |
| 114 | // |
| 115 | // If the validation fails, return false and raise an exception. |
| 116 | static inline bool IsValidLambdaTargetOrThrow(ArtMethod* called_method) |
| 117 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 118 | bool success = false; |
| 119 | |
| 120 | if (UNLIKELY(called_method == nullptr)) { |
| 121 | // The shadow frame should already be pushed, so we don't need to update it. |
| 122 | } else if (UNLIKELY(called_method->IsAbstract())) { |
| 123 | ThrowAbstractMethodError(called_method); |
| 124 | // TODO(iam): Also handle the case when the method is non-static, what error do we throw? |
| 125 | // TODO(iam): Also make sure that ACC_LAMBDA is set. |
| 126 | } else if (UNLIKELY(called_method->GetCodeItem() == nullptr)) { |
| 127 | // Method could be native, proxy method, etc. Lambda targets have to be concrete impls, |
| 128 | // so don't allow this. |
| 129 | } else { |
| 130 | success = true; |
| 131 | } |
| 132 | |
| 133 | return success; |
| 134 | } |
| 135 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 136 | // Write out the 'ArtMethod*' into vreg and vreg+1 |
| 137 | static inline void WriteLambdaClosureIntoVRegs(ShadowFrame& shadow_frame, |
| 138 | const ArtMethod& called_method, |
| 139 | uint32_t vreg) { |
| 140 | // Split the method into a lo and hi 32 bits so we can encode them into 2 virtual registers. |
| 141 | uint32_t called_method_lo = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&called_method)); |
| 142 | uint32_t called_method_hi = static_cast<uint32_t>(reinterpret_cast<uint64_t>(&called_method) |
| 143 | >> BitSizeOf<uint32_t>()); |
| 144 | // Use uint64_t instead of uintptr_t to allow shifting past the max on 32-bit. |
| 145 | static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible"); |
| 146 | |
| 147 | DCHECK_NE(called_method_lo | called_method_hi, 0u); |
| 148 | |
| 149 | shadow_frame.SetVReg(vreg, called_method_lo); |
| 150 | shadow_frame.SetVReg(vreg + 1, called_method_hi); |
| 151 | } |
| 152 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 153 | // Handles create-lambda instructions. |
| 154 | // Returns true on success, otherwise throws an exception and returns false. |
| 155 | // (Exceptions are thrown by creating a new exception and then being put in the thread TLS) |
| 156 | // |
| 157 | // As a work-in-progress implementation, this shoves the ArtMethod object corresponding |
| 158 | // to the target dex method index into the target register vA and vA + 1. |
| 159 | template<bool do_access_check> |
| 160 | static inline bool DoCreateLambda(Thread* self, ShadowFrame& shadow_frame, |
| 161 | const Instruction* inst) { |
| 162 | /* |
| 163 | * create-lambda is opcode 0x21c |
| 164 | * - vA is the target register where the closure will be stored into |
| 165 | * (also stores into vA + 1) |
| 166 | * - vB is the method index which will be the target for a later invoke-lambda |
| 167 | */ |
| 168 | const uint32_t method_idx = inst->VRegB_21c(); |
| 169 | mirror::Object* receiver = nullptr; // Always static. (see 'kStatic') |
| 170 | ArtMethod* sf_method = shadow_frame.GetMethod(); |
| 171 | ArtMethod* const called_method = FindMethodFromCode<kStatic, do_access_check>( |
| 172 | method_idx, &receiver, &sf_method, self); |
| 173 | |
| 174 | uint32_t vregA = inst->VRegA_21c(); |
| 175 | |
| 176 | if (UNLIKELY(!IsValidLambdaTargetOrThrow(called_method))) { |
| 177 | CHECK(self->IsExceptionPending()); |
| 178 | shadow_frame.SetVReg(vregA, 0u); |
| 179 | shadow_frame.SetVReg(vregA + 1, 0u); |
| 180 | return false; |
| 181 | } |
| 182 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 183 | WriteLambdaClosureIntoVRegs(shadow_frame, *called_method, vregA); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 187 | // Reads out the 'ArtMethod*' stored inside of vreg and vreg+1 |
| 188 | // |
| 189 | // Validates that the art method points to a valid lambda function, otherwise throws |
| 190 | // an exception and returns null. |
| 191 | // (Exceptions are thrown by creating a new exception and then being put in the thread TLS) |
| 192 | static inline ArtMethod* ReadLambdaClosureFromVRegsOrThrow(ShadowFrame& shadow_frame, |
| 193 | uint32_t vreg) |
| 194 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 195 | // TODO(iam): Introduce a closure abstraction that will contain the captured variables |
| 196 | // instead of just an ArtMethod. |
| 197 | // This is temporarily using 2 vregs because a native ArtMethod can be up to 64-bit, |
| 198 | // but once proper variable capture is implemented it will only use 1 vreg. |
| 199 | uint32_t vc_value_lo = shadow_frame.GetVReg(vreg); |
| 200 | uint32_t vc_value_hi = shadow_frame.GetVReg(vreg + 1); |
| 201 | |
| 202 | uint64_t vc_value_ptr = (static_cast<uint64_t>(vc_value_hi) << BitSizeOf<uint32_t>()) |
| 203 | | vc_value_lo; |
| 204 | |
| 205 | // Use uint64_t instead of uintptr_t to allow left-shifting past the max on 32-bit. |
| 206 | static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible"); |
| 207 | ArtMethod* const called_method = reinterpret_cast<ArtMethod* const>(vc_value_ptr); |
| 208 | |
| 209 | // Guard against the user passing a null closure, which is odd but (sadly) semantically valid. |
| 210 | if (UNLIKELY(called_method == nullptr)) { |
| 211 | ThrowNullPointerExceptionFromInterpreter(); |
| 212 | return nullptr; |
| 213 | } else if (UNLIKELY(!IsValidLambdaTargetOrThrow(called_method))) { |
| 214 | return nullptr; |
| 215 | } |
| 216 | |
| 217 | return called_method; |
| 218 | } |
| 219 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 220 | template<bool do_access_check> |
| 221 | static inline bool DoInvokeLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 222 | uint16_t inst_data, JValue* result) { |
| 223 | /* |
| 224 | * invoke-lambda is opcode 0x25 |
| 225 | * |
| 226 | * - vC is the closure register (both vC and vC + 1 will be used to store the closure). |
| 227 | * - vB is the number of additional registers up to |{vD,vE,vF,vG}| (4) |
| 228 | * - the rest of the registers are always var-args |
| 229 | * |
| 230 | * - reading var-args for 0x25 gets us vD,vE,vF,vG (but not vB) |
| 231 | */ |
| 232 | uint32_t vC = inst->VRegC_25x(); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 233 | ArtMethod* const called_method = ReadLambdaClosureFromVRegsOrThrow(shadow_frame, vC); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 234 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 235 | // Failed lambda target runtime check, an exception was raised. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 236 | if (UNLIKELY(called_method == nullptr)) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 237 | CHECK(self->IsExceptionPending()); |
| 238 | result->SetJ(0); |
| 239 | return false; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 240 | } |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 241 | |
| 242 | // Invoke a non-range lambda |
| 243 | return DoLambdaCall<false, do_access_check>(called_method, self, shadow_frame, inst, inst_data, |
| 244 | result); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 247 | // Handles invoke-XXX/range instructions. |
| 248 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 249 | template<InvokeType type, bool is_range, bool do_access_check> |
| 250 | static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 251 | uint16_t inst_data, JValue* result) { |
| 252 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 253 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 254 | Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 255 | ArtMethod* sf_method = shadow_frame.GetMethod(); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 256 | ArtMethod* const called_method = FindMethodFromCode<type, do_access_check>( |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 257 | method_idx, &receiver, &sf_method, self); |
| 258 | // The shadow frame should already be pushed, so we don't need to update it. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 259 | if (UNLIKELY(called_method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 260 | CHECK(self->IsExceptionPending()); |
| 261 | result->SetJ(0); |
| 262 | return false; |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 263 | } else if (UNLIKELY(called_method->IsAbstract())) { |
| 264 | ThrowAbstractMethodError(called_method); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 265 | result->SetJ(0); |
| 266 | return false; |
| 267 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 268 | return DoCall<is_range, do_access_check>(called_method, self, shadow_frame, inst, inst_data, |
| 269 | result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 270 | } |
| 271 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 272 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 273 | // Handles invoke-virtual-quick and invoke-virtual-quick-range instructions. |
| 274 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 275 | template<bool is_range> |
| 276 | static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame, |
| 277 | const Instruction* inst, uint16_t inst_data, |
| 278 | JValue* result) { |
| 279 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
| 280 | Object* const receiver = shadow_frame.GetVRegReference(vregC); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 281 | if (UNLIKELY(receiver == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 282 | // We lost the reference to the method index so we cannot get a more |
| 283 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 284 | ThrowNullPointerExceptionFromDexPC(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 285 | return false; |
| 286 | } |
| 287 | const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 288 | CHECK(receiver->GetClass()->ShouldHaveEmbeddedImtAndVTable()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 289 | ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry( |
| 290 | vtable_idx, sizeof(void*)); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 291 | if (UNLIKELY(called_method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 292 | CHECK(self->IsExceptionPending()); |
| 293 | result->SetJ(0); |
| 294 | return false; |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 295 | } else if (UNLIKELY(called_method->IsAbstract())) { |
| 296 | ThrowAbstractMethodError(called_method); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 297 | result->SetJ(0); |
| 298 | return false; |
| 299 | } else { |
| 300 | // No need to check since we've been quickened. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 301 | return DoCall<is_range, false>(called_method, self, shadow_frame, inst, inst_data, result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 302 | } |
| 303 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 304 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 305 | // Handles iget-XXX and sget-XXX instructions. |
| 306 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 307 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 308 | bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 309 | uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 310 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 311 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 312 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 313 | template<Primitive::Type field_type> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 314 | bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
| 315 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 316 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 317 | // Handles iput-XXX and sput-XXX instructions. |
| 318 | // Returns true on success, otherwise throws an exception and returns false. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 319 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 320 | bool transaction_active> |
| 321 | bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, |
| 322 | uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 323 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 324 | // Handles iput-quick, iput-wide-quick and iput-object-quick instructions. |
| 325 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 326 | template<Primitive::Type field_type, bool transaction_active> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 327 | bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
| 328 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 329 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 330 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 331 | // Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the |
| 332 | // java.lang.String class is initialized. |
Ian Rogers | 6786a58 | 2014-10-28 12:49:06 -0700 | [diff] [blame] | 333 | static inline String* ResolveString(Thread* self, ShadowFrame& shadow_frame, uint32_t string_idx) |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 334 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 335 | Class* java_lang_string_class = String::GetJavaLangString(); |
| 336 | if (UNLIKELY(!java_lang_string_class->IsInitialized())) { |
| 337 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 338 | StackHandleScope<1> hs(self); |
| 339 | Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class)); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 340 | if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 341 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 342 | return nullptr; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 343 | } |
| 344 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 345 | ArtMethod* method = shadow_frame.GetMethod(); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 346 | mirror::Class* declaring_class = method->GetDeclaringClass(); |
| 347 | mirror::String* s = declaring_class->GetDexCacheStrings()->Get(string_idx); |
Ian Rogers | 6786a58 | 2014-10-28 12:49:06 -0700 | [diff] [blame] | 348 | if (UNLIKELY(s == nullptr)) { |
| 349 | StackHandleScope<1> hs(self); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 350 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache())); |
Ian Rogers | 6786a58 | 2014-10-28 12:49:06 -0700 | [diff] [blame] | 351 | s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx, |
| 352 | dex_cache); |
| 353 | } |
| 354 | return s; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 357 | // Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions. |
| 358 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 359 | static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg, |
| 360 | int32_t dividend, int32_t divisor) |
| 361 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | f72a11d | 2014-10-30 15:41:08 -0700 | [diff] [blame] | 362 | constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 363 | if (UNLIKELY(divisor == 0)) { |
| 364 | ThrowArithmeticExceptionDivideByZero(); |
| 365 | return false; |
| 366 | } |
| 367 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 368 | shadow_frame.SetVReg(result_reg, kMinInt); |
| 369 | } else { |
| 370 | shadow_frame.SetVReg(result_reg, dividend / divisor); |
| 371 | } |
| 372 | return true; |
| 373 | } |
| 374 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 375 | // Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions. |
| 376 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 377 | static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg, |
| 378 | int32_t dividend, int32_t divisor) |
| 379 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | f72a11d | 2014-10-30 15:41:08 -0700 | [diff] [blame] | 380 | constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 381 | if (UNLIKELY(divisor == 0)) { |
| 382 | ThrowArithmeticExceptionDivideByZero(); |
| 383 | return false; |
| 384 | } |
| 385 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 386 | shadow_frame.SetVReg(result_reg, 0); |
| 387 | } else { |
| 388 | shadow_frame.SetVReg(result_reg, dividend % divisor); |
| 389 | } |
| 390 | return true; |
| 391 | } |
| 392 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 393 | // Handles div-long and div-long-2addr instructions. |
| 394 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 395 | static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg, |
| 396 | int64_t dividend, int64_t divisor) |
| 397 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 398 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 399 | if (UNLIKELY(divisor == 0)) { |
| 400 | ThrowArithmeticExceptionDivideByZero(); |
| 401 | return false; |
| 402 | } |
| 403 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 404 | shadow_frame.SetVRegLong(result_reg, kMinLong); |
| 405 | } else { |
| 406 | shadow_frame.SetVRegLong(result_reg, dividend / divisor); |
| 407 | } |
| 408 | return true; |
| 409 | } |
| 410 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 411 | // Handles rem-long and rem-long-2addr instructions. |
| 412 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 413 | static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg, |
| 414 | int64_t dividend, int64_t divisor) |
| 415 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 416 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 417 | if (UNLIKELY(divisor == 0)) { |
| 418 | ThrowArithmeticExceptionDivideByZero(); |
| 419 | return false; |
| 420 | } |
| 421 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 422 | shadow_frame.SetVRegLong(result_reg, 0); |
| 423 | } else { |
| 424 | shadow_frame.SetVRegLong(result_reg, dividend % divisor); |
| 425 | } |
| 426 | return true; |
| 427 | } |
| 428 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 429 | // Handles filled-new-array and filled-new-array-range instructions. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 430 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 431 | template <bool is_range, bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 432 | bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 433 | Thread* self, JValue* result); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 434 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 435 | // Handles packed-switch instruction. |
| 436 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 437 | static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 438 | uint16_t inst_data) |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 439 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 440 | DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH); |
| 441 | const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t(); |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 442 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 443 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 444 | uint16_t size = switch_data[1]; |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 445 | if (size == 0) { |
| 446 | // Empty packed switch, move forward by 3 (size of PACKED_SWITCH). |
| 447 | return 3; |
| 448 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 449 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 450 | DCHECK_ALIGNED(keys, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 451 | int32_t first_key = keys[0]; |
| 452 | const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 453 | DCHECK_ALIGNED(targets, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 454 | int32_t index = test_val - first_key; |
| 455 | if (index >= 0 && index < size) { |
| 456 | return targets[index]; |
| 457 | } else { |
| 458 | // No corresponding value: move forward by 3 (size of PACKED_SWITCH). |
| 459 | return 3; |
| 460 | } |
| 461 | } |
| 462 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 463 | // Handles sparse-switch instruction. |
| 464 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 465 | static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 466 | uint16_t inst_data) |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 467 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 468 | DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH); |
| 469 | const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t(); |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 470 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 471 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 472 | uint16_t size = switch_data[1]; |
Jeff Hao | 935e01a | 2015-03-20 19:44:35 -0700 | [diff] [blame] | 473 | // Return length of SPARSE_SWITCH if size is 0. |
| 474 | if (size == 0) { |
| 475 | return 3; |
| 476 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 477 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 478 | DCHECK_ALIGNED(keys, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 479 | const int32_t* entries = keys + size; |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 480 | DCHECK_ALIGNED(entries, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 481 | int lo = 0; |
| 482 | int hi = size - 1; |
| 483 | while (lo <= hi) { |
| 484 | int mid = (lo + hi) / 2; |
| 485 | int32_t foundVal = keys[mid]; |
| 486 | if (test_val < foundVal) { |
| 487 | hi = mid - 1; |
| 488 | } else if (test_val > foundVal) { |
| 489 | lo = mid + 1; |
| 490 | } else { |
| 491 | return entries[mid]; |
| 492 | } |
| 493 | } |
| 494 | // No corresponding value: move forward by 3 (size of SPARSE_SWITCH). |
| 495 | return 3; |
| 496 | } |
| 497 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 498 | template <bool _do_check> |
| 499 | static inline bool DoBoxLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 500 | uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 501 | /* |
| 502 | * box-lambda vA, vB /// opcode 0xf8, format 22x |
| 503 | * - vA is the target register where the Object representation of the closure will be stored into |
| 504 | * - vB is a closure (made by create-lambda) |
| 505 | * (also reads vB + 1) |
| 506 | */ |
| 507 | uint32_t vreg_target_object = inst->VRegA_22x(inst_data); |
| 508 | uint32_t vreg_source_closure = inst->VRegB_22x(); |
| 509 | |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 510 | ArtMethod* closure_method = ReadLambdaClosureFromVRegsOrThrow(shadow_frame, |
| 511 | vreg_source_closure); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 512 | |
| 513 | // Failed lambda target runtime check, an exception was raised. |
| 514 | if (UNLIKELY(closure_method == nullptr)) { |
| 515 | CHECK(self->IsExceptionPending()); |
| 516 | return false; |
| 517 | } |
| 518 | |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 519 | mirror::Object* closure_as_object = |
| 520 | Runtime::Current()->GetLambdaBoxTable()->BoxLambda(closure_method); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 521 | |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 522 | // Failed to box the lambda, an exception was raised. |
| 523 | if (UNLIKELY(closure_as_object == nullptr)) { |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 524 | CHECK(self->IsExceptionPending()); |
| 525 | return false; |
| 526 | } |
| 527 | |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 528 | shadow_frame.SetVRegReference(vreg_target_object, closure_as_object); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 529 | return true; |
| 530 | } |
| 531 | |
| 532 | template <bool _do_check> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 533 | static inline bool DoUnboxLambda(Thread* self, |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 534 | ShadowFrame& shadow_frame, |
| 535 | const Instruction* inst, |
| 536 | uint16_t inst_data) { |
| 537 | /* |
| 538 | * unbox-lambda vA, vB, [type id] /// opcode 0xf9, format 22c |
| 539 | * - vA is the target register where the closure will be written into |
| 540 | * (also writes vA + 1) |
| 541 | * - vB is the Object representation of the closure (made by box-lambda) |
| 542 | */ |
| 543 | uint32_t vreg_target_closure = inst->VRegA_22c(inst_data); |
| 544 | uint32_t vreg_source_object = inst->VRegB_22c(); |
| 545 | |
| 546 | // Raise NullPointerException if object is null |
| 547 | mirror::Object* boxed_closure_object = shadow_frame.GetVRegReference(vreg_source_object); |
| 548 | if (UNLIKELY(boxed_closure_object == nullptr)) { |
| 549 | ThrowNullPointerExceptionFromInterpreter(); |
| 550 | return false; |
| 551 | } |
| 552 | |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame^] | 553 | ArtMethod* unboxed_closure = nullptr; |
| 554 | // Raise an exception if unboxing fails. |
| 555 | if (!Runtime::Current()->GetLambdaBoxTable()->UnboxLambda(boxed_closure_object, |
| 556 | &unboxed_closure)) { |
| 557 | CHECK(self->IsExceptionPending()); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 558 | return false; |
| 559 | } |
| 560 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 561 | DCHECK(unboxed_closure != nullptr); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 562 | WriteLambdaClosureIntoVRegs(shadow_frame, *unboxed_closure, vreg_target_closure); |
| 563 | return true; |
| 564 | } |
| 565 | |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 566 | uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 567 | uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 568 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 569 | |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 570 | NO_RETURN void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) |
| 571 | __attribute__((cold)) |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 572 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 573 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 574 | static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst, |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 575 | const uint32_t dex_pc) |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 576 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 577 | constexpr bool kTracing = false; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 578 | if (kTracing) { |
| 579 | #define TRACE_LOG std::cerr |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 580 | std::ostringstream oss; |
| 581 | oss << PrettyMethod(shadow_frame.GetMethod()) |
| 582 | << StringPrintf("\n0x%x: ", dex_pc) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 583 | << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()) << "\n"; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 584 | for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 585 | uint32_t raw_value = shadow_frame.GetVReg(i); |
| 586 | Object* ref_value = shadow_frame.GetVRegReference(i); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 587 | oss << StringPrintf(" vreg%u=0x%08X", i, raw_value); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 588 | if (ref_value != nullptr) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 589 | if (ref_value->GetClass()->IsStringClass() && |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 590 | ref_value->AsString()->GetValue() != nullptr) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 591 | oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\""; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 592 | } else { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 593 | oss << "/" << PrettyTypeOf(ref_value); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 597 | TRACE_LOG << oss.str() << "\n"; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 598 | #undef TRACE_LOG |
| 599 | } |
| 600 | } |
| 601 | |
Sebastien Hertz | 1eda226 | 2013-09-09 16:53:14 +0200 | [diff] [blame] | 602 | static inline bool IsBackwardBranch(int32_t branch_offset) { |
| 603 | return branch_offset <= 0; |
| 604 | } |
| 605 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 606 | // Explicitly instantiate all DoInvoke functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 607 | #define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \ |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 608 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 609 | bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \ |
| 610 | const Instruction* inst, uint16_t inst_data, \ |
| 611 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 612 | |
| 613 | #define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \ |
| 614 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \ |
| 615 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \ |
| 616 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \ |
| 617 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true); |
| 618 | |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 619 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range. |
| 620 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range. |
| 621 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range. |
| 622 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range. |
| 623 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 624 | #undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL |
| 625 | #undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL |
| 626 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 627 | // Explicitly instantiate all DoInvokeVirtualQuick functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 628 | #define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \ |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 629 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 630 | bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \ |
| 631 | const Instruction* inst, uint16_t inst_data, \ |
| 632 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 633 | |
| 634 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick. |
| 635 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range. |
| 636 | #undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK |
| 637 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 638 | // Explicitly instantiate all DoCreateLambda functions. |
| 639 | #define EXPLICIT_DO_CREATE_LAMBDA_DECL(_do_check) \ |
| 640 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
| 641 | bool DoCreateLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, \ |
| 642 | const Instruction* inst) |
| 643 | |
| 644 | EXPLICIT_DO_CREATE_LAMBDA_DECL(false); // create-lambda |
| 645 | EXPLICIT_DO_CREATE_LAMBDA_DECL(true); // create-lambda |
| 646 | #undef EXPLICIT_DO_CREATE_LAMBDA_DECL |
| 647 | |
| 648 | // Explicitly instantiate all DoInvokeLambda functions. |
| 649 | #define EXPLICIT_DO_INVOKE_LAMBDA_DECL(_do_check) \ |
| 650 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
| 651 | bool DoInvokeLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 652 | uint16_t inst_data, JValue* result); |
| 653 | |
| 654 | EXPLICIT_DO_INVOKE_LAMBDA_DECL(false); // invoke-lambda |
| 655 | EXPLICIT_DO_INVOKE_LAMBDA_DECL(true); // invoke-lambda |
| 656 | #undef EXPLICIT_DO_INVOKE_LAMBDA_DECL |
| 657 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 658 | // Explicitly instantiate all DoBoxLambda functions. |
| 659 | #define EXPLICIT_DO_BOX_LAMBDA_DECL(_do_check) \ |
| 660 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
| 661 | bool DoBoxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 662 | uint16_t inst_data); |
| 663 | |
| 664 | EXPLICIT_DO_BOX_LAMBDA_DECL(false); // box-lambda |
| 665 | EXPLICIT_DO_BOX_LAMBDA_DECL(true); // box-lambda |
| 666 | #undef EXPLICIT_DO_BOX_LAMBDA_DECL |
| 667 | |
| 668 | // Explicitly instantiate all DoUnBoxLambda functions. |
| 669 | #define EXPLICIT_DO_UNBOX_LAMBDA_DECL(_do_check) \ |
| 670 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
| 671 | bool DoUnboxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 672 | uint16_t inst_data); |
| 673 | |
| 674 | EXPLICIT_DO_UNBOX_LAMBDA_DECL(false); // unbox-lambda |
| 675 | EXPLICIT_DO_UNBOX_LAMBDA_DECL(true); // unbox-lambda |
| 676 | #undef EXPLICIT_DO_BOX_LAMBDA_DECL |
| 677 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 678 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 679 | } // namespace interpreter |
| 680 | } // namespace art |
| 681 | |
| 682 | #endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |