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 | |
| 24 | #include "base/logging.h" |
| 25 | #include "class_linker-inl.h" |
| 26 | #include "common_throws.h" |
| 27 | #include "dex_file-inl.h" |
| 28 | #include "dex_instruction-inl.h" |
| 29 | #include "dex_instruction.h" |
| 30 | #include "entrypoints/entrypoint_utils.h" |
| 31 | #include "gc/accounting/card_table-inl.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 32 | #include "nth_caller_visitor.h" |
| 33 | #include "mirror/art_field-inl.h" |
| 34 | #include "mirror/art_method.h" |
| 35 | #include "mirror/art_method-inl.h" |
| 36 | #include "mirror/class.h" |
| 37 | #include "mirror/class-inl.h" |
| 38 | #include "mirror/object-inl.h" |
| 39 | #include "mirror/object_array-inl.h" |
| 40 | #include "object_utils.h" |
| 41 | #include "ScopedLocalRef.h" |
| 42 | #include "scoped_thread_state_change.h" |
| 43 | #include "thread.h" |
| 44 | #include "well_known_classes.h" |
| 45 | |
| 46 | using ::art::mirror::ArtField; |
| 47 | using ::art::mirror::ArtMethod; |
| 48 | using ::art::mirror::Array; |
| 49 | using ::art::mirror::BooleanArray; |
| 50 | using ::art::mirror::ByteArray; |
| 51 | using ::art::mirror::CharArray; |
| 52 | using ::art::mirror::Class; |
| 53 | using ::art::mirror::ClassLoader; |
| 54 | using ::art::mirror::IntArray; |
| 55 | using ::art::mirror::LongArray; |
| 56 | using ::art::mirror::Object; |
| 57 | using ::art::mirror::ObjectArray; |
| 58 | using ::art::mirror::ShortArray; |
| 59 | using ::art::mirror::String; |
| 60 | using ::art::mirror::Throwable; |
| 61 | |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 62 | // b/14882674 Workaround stack overflow issue with clang |
| 63 | #if defined(__clang__) && defined(__aarch64__) |
| 64 | #define SOMETIMES_INLINE __attribute__((noinline)) |
| 65 | #define SOMETIMES_INLINE_KEYWORD |
| 66 | #else |
| 67 | #define SOMETIMES_INLINE ALWAYS_INLINE |
| 68 | #define SOMETIMES_INLINE_KEYWORD inline |
| 69 | #endif |
| 70 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 71 | namespace art { |
| 72 | namespace interpreter { |
| 73 | |
| 74 | // External references to both interpreter implementations. |
| 75 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 76 | template<bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 77 | extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh, |
| 78 | const DexFile::CodeItem* code_item, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 79 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 80 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 81 | template<bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 82 | extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh, |
| 83 | const DexFile::CodeItem* code_item, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 84 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 85 | |
| 86 | static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 87 | ref->MonitorEnter(self); |
| 88 | } |
| 89 | |
| 90 | static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 91 | ref->MonitorExit(self); |
| 92 | } |
| 93 | |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 94 | void AbortTransaction(Thread* self, const char* fmt, ...) |
| 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 96 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 97 | void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count) |
| 98 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 99 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 100 | // Invokes the given method. This is part of the invocation support and is used by DoInvoke and |
| 101 | // DoInvokeVirtualQuick functions. |
| 102 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 103 | template<bool is_range, bool do_assignability_check> |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 104 | bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 105 | const Instruction* inst, uint16_t inst_data, JValue* result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 106 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 107 | // Handles invoke-XXX/range instructions. |
| 108 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 109 | template<InvokeType type, bool is_range, bool do_access_check> |
| 110 | static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 111 | uint16_t inst_data, JValue* result) { |
| 112 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 113 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 114 | Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 115 | ArtMethod* const method = FindMethodFromCode<type, do_access_check>(method_idx, receiver, |
| 116 | shadow_frame.GetMethod(), |
| 117 | self); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 118 | if (UNLIKELY(method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 119 | CHECK(self->IsExceptionPending()); |
| 120 | result->SetJ(0); |
| 121 | return false; |
| 122 | } else if (UNLIKELY(method->IsAbstract())) { |
| 123 | ThrowAbstractMethodError(method); |
| 124 | result->SetJ(0); |
| 125 | return false; |
| 126 | } else { |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 127 | return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 128 | } |
| 129 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 130 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 131 | // Handles invoke-virtual-quick and invoke-virtual-quick-range instructions. |
| 132 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 133 | template<bool is_range> |
| 134 | static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame, |
| 135 | const Instruction* inst, uint16_t inst_data, |
| 136 | JValue* result) { |
| 137 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
| 138 | Object* const receiver = shadow_frame.GetVRegReference(vregC); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 139 | if (UNLIKELY(receiver == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 140 | // We lost the reference to the method index so we cannot get a more |
| 141 | // precised exception message. |
| 142 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); |
| 143 | return false; |
| 144 | } |
| 145 | const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 146 | ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 147 | if (UNLIKELY(method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 148 | CHECK(self->IsExceptionPending()); |
| 149 | result->SetJ(0); |
| 150 | return false; |
| 151 | } else if (UNLIKELY(method->IsAbstract())) { |
| 152 | ThrowAbstractMethodError(method); |
| 153 | result->SetJ(0); |
| 154 | return false; |
| 155 | } else { |
| 156 | // No need to check since we've been quickened. |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 157 | return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 158 | } |
| 159 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 160 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 161 | // Handles iget-XXX and sget-XXX instructions. |
| 162 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 163 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 164 | static SOMETIMES_INLINE_KEYWORD bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, |
| 165 | const Instruction* inst, uint16_t inst_data) { |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 166 | const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); |
| 167 | const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
| 168 | ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 169 | Primitive::FieldSize(field_type)); |
| 170 | if (UNLIKELY(f == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 171 | CHECK(self->IsExceptionPending()); |
| 172 | return false; |
| 173 | } |
| 174 | Object* obj; |
| 175 | if (is_static) { |
| 176 | obj = f->GetDeclaringClass(); |
| 177 | } else { |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 178 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 179 | if (UNLIKELY(obj == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 180 | ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true); |
| 181 | return false; |
| 182 | } |
| 183 | } |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 184 | // Report this field access to instrumentation if needed. |
| 185 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 186 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
| 187 | Object* this_object = f->IsStatic() ? nullptr : obj; |
| 188 | instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(), |
| 189 | shadow_frame.GetDexPC(), f); |
| 190 | } |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 191 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 192 | switch (field_type) { |
| 193 | case Primitive::kPrimBoolean: |
| 194 | shadow_frame.SetVReg(vregA, f->GetBoolean(obj)); |
| 195 | break; |
| 196 | case Primitive::kPrimByte: |
| 197 | shadow_frame.SetVReg(vregA, f->GetByte(obj)); |
| 198 | break; |
| 199 | case Primitive::kPrimChar: |
| 200 | shadow_frame.SetVReg(vregA, f->GetChar(obj)); |
| 201 | break; |
| 202 | case Primitive::kPrimShort: |
| 203 | shadow_frame.SetVReg(vregA, f->GetShort(obj)); |
| 204 | break; |
| 205 | case Primitive::kPrimInt: |
| 206 | shadow_frame.SetVReg(vregA, f->GetInt(obj)); |
| 207 | break; |
| 208 | case Primitive::kPrimLong: |
| 209 | shadow_frame.SetVRegLong(vregA, f->GetLong(obj)); |
| 210 | break; |
| 211 | case Primitive::kPrimNot: |
| 212 | shadow_frame.SetVRegReference(vregA, f->GetObject(obj)); |
| 213 | break; |
| 214 | default: |
| 215 | LOG(FATAL) << "Unreachable: " << field_type; |
| 216 | } |
| 217 | return true; |
| 218 | } |
| 219 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 220 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 221 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 222 | template<Primitive::Type field_type> |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 223 | static SOMETIMES_INLINE_KEYWORD bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 224 | Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 225 | if (UNLIKELY(obj == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 226 | // We lost the reference to the field index so we cannot get a more |
| 227 | // precised exception message. |
| 228 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); |
| 229 | return false; |
| 230 | } |
| 231 | MemberOffset field_offset(inst->VRegC_22c()); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 232 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 233 | // the field from the base of the object, we need to look for it first. |
| 234 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 235 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
| 236 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 237 | field_offset.Uint32Value()); |
| 238 | DCHECK(f != nullptr); |
| 239 | DCHECK(!f->IsStatic()); |
| 240 | instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(), |
| 241 | shadow_frame.GetDexPC(), f); |
| 242 | } |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 243 | // Note: iget-x-quick instructions are only for non-volatile fields. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 244 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 245 | switch (field_type) { |
| 246 | case Primitive::kPrimInt: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 247 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset))); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 248 | break; |
| 249 | case Primitive::kPrimLong: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 250 | shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset))); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 251 | break; |
| 252 | case Primitive::kPrimNot: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 253 | shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 254 | break; |
| 255 | default: |
| 256 | LOG(FATAL) << "Unreachable: " << field_type; |
| 257 | } |
| 258 | return true; |
| 259 | } |
| 260 | |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 261 | template<Primitive::Type field_type> |
| 262 | static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) |
| 263 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 264 | JValue field_value; |
| 265 | switch (field_type) { |
| 266 | case Primitive::kPrimBoolean: |
| 267 | field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); |
| 268 | break; |
| 269 | case Primitive::kPrimByte: |
| 270 | field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); |
| 271 | break; |
| 272 | case Primitive::kPrimChar: |
| 273 | field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); |
| 274 | break; |
| 275 | case Primitive::kPrimShort: |
| 276 | field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); |
| 277 | break; |
| 278 | case Primitive::kPrimInt: |
| 279 | field_value.SetI(shadow_frame.GetVReg(vreg)); |
| 280 | break; |
| 281 | case Primitive::kPrimLong: |
| 282 | field_value.SetJ(shadow_frame.GetVRegLong(vreg)); |
| 283 | break; |
| 284 | case Primitive::kPrimNot: |
| 285 | field_value.SetL(shadow_frame.GetVRegReference(vreg)); |
| 286 | break; |
| 287 | default: |
| 288 | LOG(FATAL) << "Unreachable: " << field_type; |
| 289 | break; |
| 290 | } |
| 291 | return field_value; |
| 292 | } |
| 293 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 294 | // Handles iput-XXX and sput-XXX instructions. |
| 295 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 296 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active> |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 297 | static SOMETIMES_INLINE_KEYWORD bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, |
| 298 | const Instruction* inst, uint16_t inst_data) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 299 | bool do_assignability_check = do_access_check; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 300 | bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); |
| 301 | uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 302 | ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 303 | Primitive::FieldSize(field_type)); |
| 304 | if (UNLIKELY(f == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 305 | CHECK(self->IsExceptionPending()); |
| 306 | return false; |
| 307 | } |
| 308 | Object* obj; |
| 309 | if (is_static) { |
| 310 | obj = f->GetDeclaringClass(); |
| 311 | } else { |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 312 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 313 | if (UNLIKELY(obj == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 314 | ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), |
| 315 | f, false); |
| 316 | return false; |
| 317 | } |
| 318 | } |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 319 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 320 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 321 | // the field from the base of the object, we need to look for it first. |
| 322 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 323 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 324 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
| 325 | Object* this_object = f->IsStatic() ? nullptr : obj; |
| 326 | instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(), |
| 327 | shadow_frame.GetDexPC(), f, field_value); |
| 328 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 329 | switch (field_type) { |
| 330 | case Primitive::kPrimBoolean: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 331 | f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 332 | break; |
| 333 | case Primitive::kPrimByte: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 334 | f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 335 | break; |
| 336 | case Primitive::kPrimChar: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 337 | f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 338 | break; |
| 339 | case Primitive::kPrimShort: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 340 | f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 341 | break; |
| 342 | case Primitive::kPrimInt: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 343 | f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 344 | break; |
| 345 | case Primitive::kPrimLong: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 346 | f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 347 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 348 | case Primitive::kPrimNot: { |
| 349 | Object* reg = shadow_frame.GetVRegReference(vregA); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 350 | if (do_assignability_check && reg != nullptr) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 351 | Class* field_class = FieldHelper(f).GetType(); |
| 352 | if (!reg->VerifierInstanceOf(field_class)) { |
| 353 | // This should never happen. |
| 354 | self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(), |
| 355 | "Ljava/lang/VirtualMachineError;", |
| 356 | "Put '%s' that is not instance of field '%s' in '%s'", |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 357 | reg->GetClass()->GetDescriptor().c_str(), |
| 358 | field_class->GetDescriptor().c_str(), |
| 359 | f->GetDeclaringClass()->GetDescriptor().c_str()); |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 363 | f->SetObj<transaction_active>(obj, reg); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 364 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 365 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 366 | default: |
| 367 | LOG(FATAL) << "Unreachable: " << field_type; |
| 368 | } |
| 369 | return true; |
| 370 | } |
| 371 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 372 | // Handles iput-quick, iput-wide-quick and iput-object-quick instructions. |
| 373 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 374 | template<Primitive::Type field_type, bool transaction_active> |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 375 | static SOMETIMES_INLINE_KEYWORD bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 376 | Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 377 | if (UNLIKELY(obj == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 378 | // We lost the reference to the field index so we cannot get a more |
| 379 | // precised exception message. |
| 380 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); |
| 381 | return false; |
| 382 | } |
| 383 | MemberOffset field_offset(inst->VRegC_22c()); |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 384 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 385 | // Report this field modification to instrumentation if needed. Since we only have the offset of |
| 386 | // the field from the base of the object, we need to look for it first. |
| 387 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 388 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 389 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 390 | field_offset.Uint32Value()); |
| 391 | DCHECK(f != nullptr); |
| 392 | DCHECK(!f->IsStatic()); |
| 393 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
| 394 | instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(), |
| 395 | shadow_frame.GetDexPC(), f, field_value); |
| 396 | } |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 397 | // Note: iput-x-quick instructions are only for non-volatile fields. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 398 | switch (field_type) { |
| 399 | case Primitive::kPrimInt: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 400 | obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 401 | break; |
| 402 | case Primitive::kPrimLong: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 403 | obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 404 | break; |
| 405 | case Primitive::kPrimNot: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 406 | obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 407 | break; |
| 408 | default: |
| 409 | LOG(FATAL) << "Unreachable: " << field_type; |
| 410 | } |
| 411 | return true; |
| 412 | } |
| 413 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 414 | // Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the |
| 415 | // java.lang.String class is initialized. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 416 | static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx) |
| 417 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 418 | CHECK(!kMovingMethods); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 419 | Class* java_lang_string_class = String::GetJavaLangString(); |
| 420 | if (UNLIKELY(!java_lang_string_class->IsInitialized())) { |
| 421 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 422 | StackHandleScope<1> hs(self); |
| 423 | Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class)); |
| 424 | if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 425 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 426 | return nullptr; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | return mh.ResolveString(string_idx); |
| 430 | } |
| 431 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 432 | // Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions. |
| 433 | // 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] | 434 | static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg, |
| 435 | int32_t dividend, int32_t divisor) |
| 436 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 437 | const int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 438 | if (UNLIKELY(divisor == 0)) { |
| 439 | ThrowArithmeticExceptionDivideByZero(); |
| 440 | return false; |
| 441 | } |
| 442 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 443 | shadow_frame.SetVReg(result_reg, kMinInt); |
| 444 | } else { |
| 445 | shadow_frame.SetVReg(result_reg, dividend / divisor); |
| 446 | } |
| 447 | return true; |
| 448 | } |
| 449 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 450 | // Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions. |
| 451 | // 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] | 452 | static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg, |
| 453 | int32_t dividend, int32_t divisor) |
| 454 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 455 | const int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 456 | if (UNLIKELY(divisor == 0)) { |
| 457 | ThrowArithmeticExceptionDivideByZero(); |
| 458 | return false; |
| 459 | } |
| 460 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 461 | shadow_frame.SetVReg(result_reg, 0); |
| 462 | } else { |
| 463 | shadow_frame.SetVReg(result_reg, dividend % divisor); |
| 464 | } |
| 465 | return true; |
| 466 | } |
| 467 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 468 | // Handles div-long and div-long-2addr instructions. |
| 469 | // 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] | 470 | static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg, |
| 471 | int64_t dividend, int64_t divisor) |
| 472 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 473 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 474 | if (UNLIKELY(divisor == 0)) { |
| 475 | ThrowArithmeticExceptionDivideByZero(); |
| 476 | return false; |
| 477 | } |
| 478 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 479 | shadow_frame.SetVRegLong(result_reg, kMinLong); |
| 480 | } else { |
| 481 | shadow_frame.SetVRegLong(result_reg, dividend / divisor); |
| 482 | } |
| 483 | return true; |
| 484 | } |
| 485 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 486 | // Handles rem-long and rem-long-2addr instructions. |
| 487 | // 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] | 488 | static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg, |
| 489 | int64_t dividend, int64_t divisor) |
| 490 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 491 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 492 | if (UNLIKELY(divisor == 0)) { |
| 493 | ThrowArithmeticExceptionDivideByZero(); |
| 494 | return false; |
| 495 | } |
| 496 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 497 | shadow_frame.SetVRegLong(result_reg, 0); |
| 498 | } else { |
| 499 | shadow_frame.SetVRegLong(result_reg, dividend % divisor); |
| 500 | } |
| 501 | return true; |
| 502 | } |
| 503 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 504 | // Handles filled-new-array and filled-new-array-range instructions. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 505 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 506 | template <bool is_range, bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 507 | bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 508 | Thread* self, JValue* result); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 509 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 510 | // Handles packed-switch instruction. |
| 511 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 512 | static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 513 | uint16_t inst_data) |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 514 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 515 | DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH); |
| 516 | 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] | 517 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 518 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 519 | uint16_t size = switch_data[1]; |
| 520 | DCHECK_GT(size, 0); |
| 521 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
| 522 | DCHECK(IsAligned<4>(keys)); |
| 523 | int32_t first_key = keys[0]; |
| 524 | const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]); |
| 525 | DCHECK(IsAligned<4>(targets)); |
| 526 | int32_t index = test_val - first_key; |
| 527 | if (index >= 0 && index < size) { |
| 528 | return targets[index]; |
| 529 | } else { |
| 530 | // No corresponding value: move forward by 3 (size of PACKED_SWITCH). |
| 531 | return 3; |
| 532 | } |
| 533 | } |
| 534 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 535 | // Handles sparse-switch instruction. |
| 536 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 537 | static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 538 | uint16_t inst_data) |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 539 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 540 | DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH); |
| 541 | 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] | 542 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 543 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 544 | uint16_t size = switch_data[1]; |
| 545 | DCHECK_GT(size, 0); |
| 546 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
| 547 | DCHECK(IsAligned<4>(keys)); |
| 548 | const int32_t* entries = keys + size; |
| 549 | DCHECK(IsAligned<4>(entries)); |
| 550 | int lo = 0; |
| 551 | int hi = size - 1; |
| 552 | while (lo <= hi) { |
| 553 | int mid = (lo + hi) / 2; |
| 554 | int32_t foundVal = keys[mid]; |
| 555 | if (test_val < foundVal) { |
| 556 | hi = mid - 1; |
| 557 | } else if (test_val > foundVal) { |
| 558 | lo = mid + 1; |
| 559 | } else { |
| 560 | return entries[mid]; |
| 561 | } |
| 562 | } |
| 563 | // No corresponding value: move forward by 3 (size of SPARSE_SWITCH). |
| 564 | return 3; |
| 565 | } |
| 566 | |
| 567 | static inline uint32_t FindNextInstructionFollowingException(Thread* self, |
| 568 | ShadowFrame& shadow_frame, |
| 569 | uint32_t dex_pc, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 570 | mirror::Object* this_object, |
| 571 | const instrumentation::Instrumentation* instrumentation) |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 572 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 573 | |
| 574 | static inline uint32_t FindNextInstructionFollowingException(Thread* self, |
| 575 | ShadowFrame& shadow_frame, |
| 576 | uint32_t dex_pc, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 577 | mirror::Object* this_object, |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 578 | const instrumentation::Instrumentation* instrumentation) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 579 | self->VerifyStack(); |
| 580 | ThrowLocation throw_location; |
| 581 | mirror::Throwable* exception = self->GetException(&throw_location); |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 582 | bool clear_exception = false; |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 583 | bool new_exception = false; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 584 | StackHandleScope<3> hs(self); |
| 585 | Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass())); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 586 | uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc, |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 587 | &clear_exception, |
| 588 | &new_exception); |
| 589 | if (UNLIKELY(new_exception)) { |
| 590 | // Update the exception. |
| 591 | exception = self->GetException(&throw_location); |
| 592 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 593 | if (found_dex_pc == DexFile::kDexNoIndex) { |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 594 | instrumentation->MethodUnwindEvent(self, this_object, |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 595 | shadow_frame.GetMethod(), dex_pc); |
| 596 | } else { |
| 597 | instrumentation->ExceptionCaughtEvent(self, throw_location, |
| 598 | shadow_frame.GetMethod(), |
| 599 | found_dex_pc, exception); |
| 600 | if (clear_exception) { |
| 601 | self->ClearException(); |
| 602 | } |
| 603 | } |
| 604 | return found_dex_pc; |
| 605 | } |
| 606 | |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 607 | static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) |
| 608 | __attribute__((cold, noreturn)) |
| 609 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 610 | |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 611 | static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 612 | LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile()); |
| 613 | exit(0); // Unreachable, keep GCC happy. |
| 614 | } |
| 615 | |
| 616 | static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst, |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 617 | const uint32_t dex_pc, MethodHelper& mh) |
| 618 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 619 | constexpr bool kTracing = false; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 620 | if (kTracing) { |
| 621 | #define TRACE_LOG std::cerr |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 622 | std::ostringstream oss; |
| 623 | oss << PrettyMethod(shadow_frame.GetMethod()) |
| 624 | << StringPrintf("\n0x%x: ", dex_pc) |
| 625 | << inst->DumpString(&mh.GetDexFile()) << "\n"; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 626 | for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 627 | uint32_t raw_value = shadow_frame.GetVReg(i); |
| 628 | Object* ref_value = shadow_frame.GetVRegReference(i); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 629 | oss << StringPrintf(" vreg%u=0x%08X", i, raw_value); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 630 | if (ref_value != NULL) { |
| 631 | if (ref_value->GetClass()->IsStringClass() && |
| 632 | ref_value->AsString()->GetCharArray() != NULL) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 633 | oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\""; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 634 | } else { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 635 | oss << "/" << PrettyTypeOf(ref_value); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | } |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 639 | TRACE_LOG << oss.str() << "\n"; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 640 | #undef TRACE_LOG |
| 641 | } |
| 642 | } |
| 643 | |
Sebastien Hertz | 1eda226 | 2013-09-09 16:53:14 +0200 | [diff] [blame] | 644 | static inline bool IsBackwardBranch(int32_t branch_offset) { |
| 645 | return branch_offset <= 0; |
| 646 | } |
| 647 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 648 | // Explicitly instantiate all DoInvoke functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 649 | #define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 650 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 651 | bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \ |
| 652 | const Instruction* inst, uint16_t inst_data, \ |
| 653 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 654 | |
| 655 | #define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \ |
| 656 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \ |
| 657 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \ |
| 658 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \ |
| 659 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true); |
| 660 | |
| 661 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range. |
| 662 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range. |
| 663 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range. |
| 664 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range. |
| 665 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range. |
| 666 | #undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL |
| 667 | #undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL |
| 668 | |
| 669 | // Explicitly instantiate all DoFieldGet functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 670 | #define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 671 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 672 | bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \ |
| 673 | const Instruction* inst, uint16_t inst_data) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 674 | |
| 675 | #define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 676 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \ |
| 677 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true); |
| 678 | |
| 679 | // iget-XXX |
| 680 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean); |
| 681 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte); |
| 682 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar); |
| 683 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort); |
| 684 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt); |
| 685 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong); |
| 686 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot); |
| 687 | |
| 688 | // sget-XXX |
| 689 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean); |
| 690 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte); |
| 691 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar); |
| 692 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort); |
| 693 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt); |
| 694 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong); |
| 695 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot); |
| 696 | |
| 697 | #undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL |
| 698 | #undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL |
| 699 | |
| 700 | // Explicitly instantiate all DoFieldPut functions. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 701 | #define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 702 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 703 | bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \ |
| 704 | const Instruction* inst, uint16_t inst_data) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 705 | |
| 706 | #define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 707 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \ |
| 708 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \ |
| 709 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \ |
| 710 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true); |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 711 | |
| 712 | // iput-XXX |
| 713 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean); |
| 714 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte); |
| 715 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar); |
| 716 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort); |
| 717 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt); |
| 718 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong); |
| 719 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot); |
| 720 | |
| 721 | // sput-XXX |
| 722 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean); |
| 723 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte); |
| 724 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar); |
| 725 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort); |
| 726 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt); |
| 727 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong); |
| 728 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot); |
| 729 | |
| 730 | #undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL |
| 731 | #undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL |
| 732 | |
| 733 | // Explicitly instantiate all DoInvokeVirtualQuick functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 734 | #define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 735 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 736 | bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \ |
| 737 | const Instruction* inst, uint16_t inst_data, \ |
| 738 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 739 | |
| 740 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick. |
| 741 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range. |
| 742 | #undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK |
| 743 | |
| 744 | // Explicitly instantiate all DoIGetQuick functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 745 | #define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 746 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 747 | bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 748 | uint16_t inst_data) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 749 | |
| 750 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. |
| 751 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. |
| 752 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. |
| 753 | #undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL |
| 754 | |
| 755 | // Explicitly instantiate all DoIPutQuick functions. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 756 | #define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \ |
Sebastien Hertz | 82aeddb | 2014-05-20 20:09:45 +0200 | [diff] [blame^] | 757 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 758 | bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \ |
| 759 | const Instruction* inst, \ |
| 760 | uint16_t inst_data) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 761 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 762 | #define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \ |
| 763 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \ |
| 764 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true); |
| 765 | |
| 766 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. |
| 767 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. |
| 768 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. |
| 769 | #undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 770 | #undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL |
| 771 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 772 | } // namespace interpreter |
| 773 | } // namespace art |
| 774 | |
| 775 | #endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |