Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |
| 18 | #define ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |
| 19 | |
| 20 | #include "interpreter.h" |
| 21 | |
| 22 | #include <math.h> |
| 23 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 24 | #include <iostream> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 25 | #include <sstream> |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 26 | #include <atomic> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 27 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame^] | 28 | #include "android-base/stringprintf.h" |
| 29 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 30 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "art_method-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 32 | #include "base/enums.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 33 | #include "base/logging.h" |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 34 | #include "base/macros.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 35 | #include "class_linker-inl.h" |
| 36 | #include "common_throws.h" |
| 37 | #include "dex_file-inl.h" |
| 38 | #include "dex_instruction-inl.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 39 | #include "entrypoints/entrypoint_utils-inl.h" |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 40 | #include "handle_scope-inl.h" |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 41 | #include "jit/jit.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 42 | #include "mirror/class-inl.h" |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 43 | #include "mirror/dex_cache.h" |
| 44 | #include "mirror/method.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 45 | #include "mirror/object-inl.h" |
| 46 | #include "mirror/object_array-inl.h" |
Douglas Leung | 4965c02 | 2014-06-11 11:41:11 -0700 | [diff] [blame] | 47 | #include "mirror/string-inl.h" |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 48 | #include "obj_ptr.h" |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 49 | #include "stack.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 50 | #include "thread.h" |
| 51 | #include "well_known_classes.h" |
| 52 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 53 | namespace art { |
| 54 | namespace interpreter { |
| 55 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 56 | void ThrowNullPointerExceptionFromInterpreter() |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 57 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | da843e1 | 2014-05-28 19:28:31 +0200 | [diff] [blame] | 58 | |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 59 | template <bool kMonitorCounting> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 60 | static inline void DoMonitorEnter(Thread* self, ShadowFrame* frame, ObjPtr<mirror::Object> ref) |
Mathieu Chartier | 2d096c9 | 2015-10-12 16:18:20 -0700 | [diff] [blame] | 61 | NO_THREAD_SAFETY_ANALYSIS |
| 62 | REQUIRES(!Roles::uninterruptible_) { |
| 63 | StackHandleScope<1> hs(self); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 64 | Handle<mirror::Object> h_ref(hs.NewHandle(ref)); |
Mathieu Chartier | 2d096c9 | 2015-10-12 16:18:20 -0700 | [diff] [blame] | 65 | h_ref->MonitorEnter(self); |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 66 | if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) { |
| 67 | frame->GetLockCountData().AddMonitor(self, h_ref.Get()); |
| 68 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 71 | template <bool kMonitorCounting> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 72 | static inline void DoMonitorExit(Thread* self, ShadowFrame* frame, ObjPtr<mirror::Object> ref) |
Mathieu Chartier | 2d096c9 | 2015-10-12 16:18:20 -0700 | [diff] [blame] | 73 | NO_THREAD_SAFETY_ANALYSIS |
| 74 | REQUIRES(!Roles::uninterruptible_) { |
| 75 | StackHandleScope<1> hs(self); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 76 | Handle<mirror::Object> h_ref(hs.NewHandle(ref)); |
Mathieu Chartier | 2d096c9 | 2015-10-12 16:18:20 -0700 | [diff] [blame] | 77 | h_ref->MonitorExit(self); |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 78 | if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) { |
| 79 | frame->GetLockCountData().RemoveMonitorOrThrow(self, h_ref.Get()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | template <bool kMonitorCounting> |
| 84 | static inline bool DoMonitorCheckOnExit(Thread* self, ShadowFrame* frame) |
| 85 | NO_THREAD_SAFETY_ANALYSIS |
| 86 | REQUIRES(!Roles::uninterruptible_) { |
| 87 | if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) { |
| 88 | return frame->GetLockCountData().CheckAllMonitorsReleasedOrThrow(self); |
| 89 | } |
| 90 | return true; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 93 | void AbortTransactionF(Thread* self, const char* fmt, ...) |
| 94 | __attribute__((__format__(__printf__, 2, 3))) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 95 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 96 | |
| 97 | void AbortTransactionV(Thread* self, const char* fmt, va_list args) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 98 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 99 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 100 | void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 101 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 102 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 103 | // Invokes the given method. This is part of the invocation support and is used by DoInvoke and |
| 104 | // DoInvokeVirtualQuick functions. |
| 105 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 106 | template<bool is_range, bool do_assignability_check> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 107 | bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 108 | const Instruction* inst, uint16_t inst_data, JValue* result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 109 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 110 | // Handles all invoke-XXX/range instructions except for invoke-polymorphic[/range]. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 111 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 112 | template<InvokeType type, bool is_range, bool do_access_check> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 113 | static inline bool DoInvoke(Thread* self, |
| 114 | ShadowFrame& shadow_frame, |
| 115 | const Instruction* inst, |
| 116 | uint16_t inst_data, |
| 117 | JValue* result) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 118 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 119 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 120 | ObjPtr<mirror::Object> receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 121 | ArtMethod* sf_method = shadow_frame.GetMethod(); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 122 | ArtMethod* const called_method = FindMethodFromCode<type, do_access_check>( |
Andreas Gampe | 3a35714 | 2015-08-07 17:20:11 -0700 | [diff] [blame] | 123 | method_idx, &receiver, sf_method, self); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 124 | // The shadow frame should already be pushed, so we don't need to update it. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 125 | if (UNLIKELY(called_method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 126 | CHECK(self->IsExceptionPending()); |
| 127 | result->SetJ(0); |
| 128 | return false; |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 129 | } else if (UNLIKELY(!called_method->IsInvokable())) { |
| 130 | called_method->ThrowInvocationTimeError(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 131 | result->SetJ(0); |
| 132 | return false; |
| 133 | } else { |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 134 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 135 | if (jit != nullptr) { |
| 136 | if (type == kVirtual || type == kInterface) { |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 137 | jit->InvokeVirtualOrInterface(receiver, sf_method, shadow_frame.GetDexPC(), called_method); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 138 | } |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 139 | jit->AddSamples(self, sf_method, 1, /*with_backedges*/false); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 140 | } |
| 141 | // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT. |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 142 | if (type == kVirtual || type == kInterface) { |
| 143 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 144 | if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) { |
| 145 | instrumentation->InvokeVirtualOrInterface( |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 146 | self, receiver.Ptr(), sf_method, shadow_frame.GetDexPC(), called_method); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 149 | return DoCall<is_range, do_access_check>(called_method, self, shadow_frame, inst, inst_data, |
| 150 | result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 151 | } |
| 152 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 153 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 154 | // Performs a signature polymorphic invoke (invoke-polymorphic/invoke-polymorphic-range). |
| 155 | template<bool is_range, bool do_access_check> |
| 156 | bool DoInvokePolymorphic(Thread* self, ShadowFrame& shadow_frame, |
| 157 | const Instruction* inst, uint16_t inst_data, |
| 158 | JValue* result); |
| 159 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 160 | // Handles invoke-virtual-quick and invoke-virtual-quick-range instructions. |
| 161 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 162 | template<bool is_range> |
| 163 | static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame, |
| 164 | const Instruction* inst, uint16_t inst_data, |
| 165 | JValue* result) { |
| 166 | const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 167 | ObjPtr<mirror::Object> const receiver = shadow_frame.GetVRegReference(vregC); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 168 | if (UNLIKELY(receiver == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 169 | // We lost the reference to the method index so we cannot get a more |
| 170 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 171 | ThrowNullPointerExceptionFromDexPC(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 172 | return false; |
| 173 | } |
| 174 | const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Hiroshi Yamauchi | a10ae78 | 2016-10-05 18:13:23 -0700 | [diff] [blame] | 175 | // Debug code for b/31357497. To be removed. |
| 176 | if (kUseReadBarrier) { |
| 177 | CHECK(receiver->GetClass() != nullptr) |
| 178 | << "Null class found in object " << receiver << " in region type " |
| 179 | << Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()-> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 180 | RegionSpace()->GetRegionType(receiver.Ptr()); |
Hiroshi Yamauchi | a10ae78 | 2016-10-05 18:13:23 -0700 | [diff] [blame] | 181 | } |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 182 | CHECK(receiver->GetClass()->ShouldHaveEmbeddedVTable()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 183 | ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 184 | vtable_idx, kRuntimePointerSize); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 185 | if (UNLIKELY(called_method == nullptr)) { |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 186 | CHECK(self->IsExceptionPending()); |
| 187 | result->SetJ(0); |
| 188 | return false; |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 189 | } else if (UNLIKELY(!called_method->IsInvokable())) { |
| 190 | called_method->ThrowInvocationTimeError(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 191 | result->SetJ(0); |
| 192 | return false; |
| 193 | } else { |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 194 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 195 | if (jit != nullptr) { |
| 196 | jit->InvokeVirtualOrInterface( |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 197 | receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method); |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 198 | jit->AddSamples(self, shadow_frame.GetMethod(), 1, /*with_backedges*/false); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 199 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 200 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 201 | // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT. |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 202 | if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) { |
| 203 | instrumentation->InvokeVirtualOrInterface( |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 204 | self, receiver.Ptr(), shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 205 | } |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 206 | // No need to check since we've been quickened. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 207 | return DoCall<is_range, false>(called_method, self, shadow_frame, inst, inst_data, result); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 208 | } |
| 209 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 210 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 211 | // Handles iget-XXX and sget-XXX 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<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 214 | bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | uint16_t inst_data) REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 216 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 217 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 218 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 219 | template<Primitive::Type field_type> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 220 | bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 221 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 222 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 223 | // Handles iput-XXX and sput-XXX instructions. |
| 224 | // Returns true on success, otherwise throws an exception and returns false. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 225 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 226 | bool transaction_active> |
| 227 | bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 228 | uint16_t inst_data) REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 229 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 230 | // Handles iput-quick, iput-wide-quick and iput-object-quick instructions. |
| 231 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 232 | template<Primitive::Type field_type, bool transaction_active> |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 233 | bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 235 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 236 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 237 | // Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the |
| 238 | // java.lang.String class is initialized. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 239 | static inline ObjPtr<mirror::String> ResolveString(Thread* self, |
| 240 | ShadowFrame& shadow_frame, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 241 | dex::StringIndex string_idx) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 243 | ObjPtr<mirror::Class> java_lang_string_class = mirror::String::GetJavaLangString(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 244 | if (UNLIKELY(!java_lang_string_class->IsInitialized())) { |
| 245 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 246 | StackHandleScope<1> hs(self); |
| 247 | Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class)); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 248 | if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 249 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 250 | return nullptr; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 251 | } |
| 252 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 253 | ArtMethod* method = shadow_frame.GetMethod(); |
Alex Light | b81a984 | 2016-12-15 00:59:05 +0000 | [diff] [blame] | 254 | ObjPtr<mirror::Class> declaring_class = method->GetDeclaringClass(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 255 | // MethodVerifier refuses methods with string_idx out of bounds. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 256 | DCHECK_LT(string_idx.index_ % mirror::DexCache::kDexCacheStringCacheSize, |
Alex Light | b81a984 | 2016-12-15 00:59:05 +0000 | [diff] [blame] | 257 | declaring_class->GetDexFile().NumStringIds()); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 258 | ObjPtr<mirror::String> string_ptr = |
Alex Light | b81a984 | 2016-12-15 00:59:05 +0000 | [diff] [blame] | 259 | mirror::StringDexCachePair::Lookup(declaring_class->GetDexCacheStrings(), |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 260 | string_idx.index_, |
Narayan Kamath | c38a6f8 | 2016-09-29 17:07:20 +0100 | [diff] [blame] | 261 | mirror::DexCache::kDexCacheStringCacheSize).Read(); |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 262 | if (UNLIKELY(string_ptr == nullptr)) { |
Ian Rogers | 6786a58 | 2014-10-28 12:49:06 -0700 | [diff] [blame] | 263 | StackHandleScope<1> hs(self); |
Alex Light | b81a984 | 2016-12-15 00:59:05 +0000 | [diff] [blame] | 264 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache())); |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 265 | string_ptr = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), |
| 266 | string_idx, |
| 267 | dex_cache); |
Ian Rogers | 6786a58 | 2014-10-28 12:49:06 -0700 | [diff] [blame] | 268 | } |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 269 | return string_ptr; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 272 | // Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions. |
| 273 | // 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] | 274 | static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg, |
| 275 | int32_t dividend, int32_t divisor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 276 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | f72a11d | 2014-10-30 15:41:08 -0700 | [diff] [blame] | 277 | constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 278 | if (UNLIKELY(divisor == 0)) { |
| 279 | ThrowArithmeticExceptionDivideByZero(); |
| 280 | return false; |
| 281 | } |
| 282 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 283 | shadow_frame.SetVReg(result_reg, kMinInt); |
| 284 | } else { |
| 285 | shadow_frame.SetVReg(result_reg, dividend / divisor); |
| 286 | } |
| 287 | return true; |
| 288 | } |
| 289 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 290 | // Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions. |
| 291 | // 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] | 292 | static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg, |
| 293 | int32_t dividend, int32_t divisor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 294 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | f72a11d | 2014-10-30 15:41:08 -0700 | [diff] [blame] | 295 | constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 296 | if (UNLIKELY(divisor == 0)) { |
| 297 | ThrowArithmeticExceptionDivideByZero(); |
| 298 | return false; |
| 299 | } |
| 300 | if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 301 | shadow_frame.SetVReg(result_reg, 0); |
| 302 | } else { |
| 303 | shadow_frame.SetVReg(result_reg, dividend % divisor); |
| 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 308 | // Handles div-long and div-long-2addr instructions. |
| 309 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 310 | static inline bool DoLongDivide(ShadowFrame& shadow_frame, |
| 311 | size_t result_reg, |
| 312 | int64_t dividend, |
| 313 | int64_t divisor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 314 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 315 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 316 | if (UNLIKELY(divisor == 0)) { |
| 317 | ThrowArithmeticExceptionDivideByZero(); |
| 318 | return false; |
| 319 | } |
| 320 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 321 | shadow_frame.SetVRegLong(result_reg, kMinLong); |
| 322 | } else { |
| 323 | shadow_frame.SetVRegLong(result_reg, dividend / divisor); |
| 324 | } |
| 325 | return true; |
| 326 | } |
| 327 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 328 | // Handles rem-long and rem-long-2addr instructions. |
| 329 | // Returns true on success, otherwise throws a java.lang.ArithmeticException and return false. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 330 | static inline bool DoLongRemainder(ShadowFrame& shadow_frame, |
| 331 | size_t result_reg, |
| 332 | int64_t dividend, |
| 333 | int64_t divisor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 334 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 2e2deeb | 2013-09-23 11:58:57 -0700 | [diff] [blame] | 335 | const int64_t kMinLong = std::numeric_limits<int64_t>::min(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 336 | if (UNLIKELY(divisor == 0)) { |
| 337 | ThrowArithmeticExceptionDivideByZero(); |
| 338 | return false; |
| 339 | } |
| 340 | if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 341 | shadow_frame.SetVRegLong(result_reg, 0); |
| 342 | } else { |
| 343 | shadow_frame.SetVRegLong(result_reg, dividend % divisor); |
| 344 | } |
| 345 | return true; |
| 346 | } |
| 347 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 348 | // Handles filled-new-array and filled-new-array-range instructions. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 349 | // Returns true on success, otherwise throws an exception and returns false. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 350 | template <bool is_range, bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 351 | bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 352 | Thread* self, JValue* result); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 353 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 354 | // Handles packed-switch instruction. |
| 355 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 356 | static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 357 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 358 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 359 | DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH); |
| 360 | 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] | 361 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 362 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 363 | uint16_t size = switch_data[1]; |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 364 | if (size == 0) { |
| 365 | // Empty packed switch, move forward by 3 (size of PACKED_SWITCH). |
| 366 | return 3; |
| 367 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 368 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 369 | DCHECK_ALIGNED(keys, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 370 | int32_t first_key = keys[0]; |
| 371 | const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 372 | DCHECK_ALIGNED(targets, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 373 | int32_t index = test_val - first_key; |
| 374 | if (index >= 0 && index < size) { |
| 375 | return targets[index]; |
| 376 | } else { |
| 377 | // No corresponding value: move forward by 3 (size of PACKED_SWITCH). |
| 378 | return 3; |
| 379 | } |
| 380 | } |
| 381 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 382 | // Handles sparse-switch instruction. |
| 383 | // Returns the branch offset to the next instruction to execute. |
Sebastien Hertz | 3b588e0 | 2013-09-11 14:33:18 +0200 | [diff] [blame] | 384 | static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 385 | uint16_t inst_data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 386 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 387 | DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH); |
| 388 | 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] | 389 | int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 390 | DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 391 | uint16_t size = switch_data[1]; |
Jeff Hao | 935e01a | 2015-03-20 19:44:35 -0700 | [diff] [blame] | 392 | // Return length of SPARSE_SWITCH if size is 0. |
| 393 | if (size == 0) { |
| 394 | return 3; |
| 395 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 396 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 397 | DCHECK_ALIGNED(keys, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 398 | const int32_t* entries = keys + size; |
Roland Levillain | 14d9057 | 2015-07-16 10:52:26 +0100 | [diff] [blame] | 399 | DCHECK_ALIGNED(entries, 4); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 400 | int lo = 0; |
| 401 | int hi = size - 1; |
| 402 | while (lo <= hi) { |
| 403 | int mid = (lo + hi) / 2; |
| 404 | int32_t foundVal = keys[mid]; |
| 405 | if (test_val < foundVal) { |
| 406 | hi = mid - 1; |
| 407 | } else if (test_val > foundVal) { |
| 408 | lo = mid + 1; |
| 409 | } else { |
| 410 | return entries[mid]; |
| 411 | } |
| 412 | } |
| 413 | // No corresponding value: move forward by 3 (size of SPARSE_SWITCH). |
| 414 | return 3; |
| 415 | } |
| 416 | |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 417 | uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 418 | uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 419 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 420 | |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 421 | NO_RETURN void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) |
| 422 | __attribute__((cold)) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 423 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 424 | |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 425 | // Set true if you want TraceExecution invocation before each bytecode execution. |
| 426 | constexpr bool kTraceExecutionEnabled = false; |
Serguei Katkov | 9fb0ac7 | 2016-02-20 12:55:24 +0600 | [diff] [blame] | 427 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 428 | static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst, |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 429 | const uint32_t dex_pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 430 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Bill Buzbee | d47fd90 | 2016-07-07 14:42:43 +0000 | [diff] [blame] | 431 | if (kTraceExecutionEnabled) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 432 | #define TRACE_LOG std::cerr |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 433 | std::ostringstream oss; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 434 | oss << shadow_frame.GetMethod()->PrettyMethod() |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame^] | 435 | << android::base::StringPrintf("\n0x%x: ", dex_pc) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 436 | << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()) << "\n"; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 437 | for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 438 | uint32_t raw_value = shadow_frame.GetVReg(i); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 439 | ObjPtr<mirror::Object> ref_value = shadow_frame.GetVRegReference(i); |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame^] | 440 | oss << android::base::StringPrintf(" vreg%u=0x%08X", i, raw_value); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 441 | if (ref_value != nullptr) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 442 | if (ref_value->GetClass()->IsStringClass() && |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 443 | !ref_value->AsString()->IsValueNull()) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 444 | oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\""; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 445 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 446 | oss << "/" << ref_value->PrettyTypeOf(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | } |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 450 | TRACE_LOG << oss.str() << "\n"; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 451 | #undef TRACE_LOG |
| 452 | } |
| 453 | } |
| 454 | |
Sebastien Hertz | 1eda226 | 2013-09-09 16:53:14 +0200 | [diff] [blame] | 455 | static inline bool IsBackwardBranch(int32_t branch_offset) { |
| 456 | return branch_offset <= 0; |
| 457 | } |
| 458 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 459 | // Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame. |
| 460 | static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame, |
| 461 | size_t dest_reg, size_t src_reg) |
| 462 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 463 | // Uint required, so that sign extension does not make this wrong on 64b systems |
| 464 | uint32_t src_value = shadow_frame.GetVReg(src_reg); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 465 | ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 466 | |
| 467 | // If both register locations contains the same value, the register probably holds a reference. |
| 468 | // Note: As an optimization, non-moving collectors leave a stale reference value |
| 469 | // in the references array even after the original vreg was overwritten to a non-reference. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 470 | if (src_value == reinterpret_cast<uintptr_t>(o.Ptr())) { |
| 471 | new_shadow_frame->SetVRegReference(dest_reg, o.Ptr()); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 472 | } else { |
| 473 | new_shadow_frame->SetVReg(dest_reg, src_value); |
| 474 | } |
| 475 | } |
| 476 | |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 477 | void ArtInterpreterToCompiledCodeBridge(Thread* self, |
| 478 | ArtMethod* caller, |
| 479 | const DexFile::CodeItem* code_item, |
| 480 | ShadowFrame* shadow_frame, |
| 481 | JValue* result); |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 482 | |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 483 | // Set string value created from StringFactory.newStringFromXXX() into all aliases of |
| 484 | // StringFactory.newEmptyString(). |
| 485 | void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame, |
| 486 | uint16_t this_obj_vreg, |
| 487 | JValue result); |
| 488 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 489 | // Explicitly instantiate all DoInvoke functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 490 | #define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 491 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 492 | bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \ |
| 493 | const Instruction* inst, uint16_t inst_data, \ |
| 494 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 495 | |
| 496 | #define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \ |
| 497 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \ |
| 498 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \ |
| 499 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \ |
| 500 | EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true); |
| 501 | |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 502 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range. |
| 503 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range. |
| 504 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range. |
| 505 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range. |
| 506 | EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 507 | #undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL |
| 508 | #undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL |
| 509 | |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 510 | // Explicitly instantiate all DoInvokeVirtualQuick functions. |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 511 | #define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 512 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 513 | bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \ |
| 514 | const Instruction* inst, uint16_t inst_data, \ |
| 515 | JValue* result) |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 516 | |
| 517 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick. |
| 518 | EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range. |
| 519 | #undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK |
| 520 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 521 | } // namespace interpreter |
| 522 | } // namespace art |
| 523 | |
| 524 | #endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_ |