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