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