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