Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "stack.h" |
| 18 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 19 | #include "arch/context.h" |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 20 | #include "base/hex_dump.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 21 | #include "entrypoints/runtime_asm_entrypoints.h" |
Mathieu Chartier | 50030ef | 2015-05-08 14:19:26 -0700 | [diff] [blame] | 22 | #include "gc_map.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 23 | #include "mirror/art_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "mirror/object.h" |
| 26 | #include "mirror/object-inl.h" |
| 27 | #include "mirror/object_array-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 28 | #include "quick/quick_method_frame_info.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 29 | #include "runtime.h" |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 30 | #include "thread.h" |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 31 | #include "thread_list.h" |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 32 | #include "verify_object-inl.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 33 | #include "vmap_table.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 37 | mirror::Object* ShadowFrame::GetThisObject() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 38 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 39 | if (m->IsStatic()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 40 | return nullptr; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 41 | } else if (m->IsNative()) { |
| 42 | return GetVRegReference(0); |
| 43 | } else { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 44 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 45 | CHECK(code_item != nullptr) << PrettyMethod(m); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 46 | uint16_t reg = code_item->registers_size_ - code_item->ins_size_; |
| 47 | return GetVRegReference(reg); |
| 48 | } |
| 49 | } |
| 50 | |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 51 | mirror::Object* ShadowFrame::GetThisObject(uint16_t num_ins) const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 52 | mirror::ArtMethod* m = GetMethod(); |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 53 | if (m->IsStatic()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 54 | return nullptr; |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 55 | } else { |
Jeff Hao | 8d44885 | 2013-06-03 17:26:19 -0700 | [diff] [blame] | 56 | return GetVRegReference(NumberOfVRegs() - num_ins); |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 60 | size_t ManagedStack::NumJniShadowFrameReferences() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 61 | size_t count = 0; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 62 | for (const ManagedStack* current_fragment = this; current_fragment != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 63 | current_fragment = current_fragment->GetLink()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 64 | for (ShadowFrame* current_frame = current_fragment->top_shadow_frame_; current_frame != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 65 | current_frame = current_frame->GetLink()) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 66 | if (current_frame->GetMethod()->IsNative()) { |
| 67 | // The JNI ShadowFrame only contains references. (For indirect reference.) |
| 68 | count += current_frame->NumberOfVRegs(); |
| 69 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | return count; |
| 73 | } |
| 74 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 75 | bool ManagedStack::ShadowFramesContain(StackReference<mirror::Object>* shadow_frame_entry) const { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 76 | for (const ManagedStack* current_fragment = this; current_fragment != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 77 | current_fragment = current_fragment->GetLink()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 78 | for (ShadowFrame* current_frame = current_fragment->top_shadow_frame_; current_frame != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 79 | current_frame = current_frame->GetLink()) { |
| 80 | if (current_frame->Contains(shadow_frame_entry)) { |
| 81 | return true; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | return false; |
| 86 | } |
| 87 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 88 | StackVisitor::StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind) |
| 89 | : StackVisitor(thread, context, walk_kind, 0) {} |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 90 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 91 | StackVisitor::StackVisitor(Thread* thread, |
| 92 | Context* context, |
| 93 | StackWalkKind walk_kind, |
| 94 | size_t num_frames) |
| 95 | : thread_(thread), |
| 96 | walk_kind_(walk_kind), |
| 97 | cur_shadow_frame_(nullptr), |
| 98 | cur_quick_frame_(nullptr), |
| 99 | cur_quick_frame_pc_(0), |
| 100 | num_frames_(num_frames), |
| 101 | cur_depth_(0), |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 102 | current_inlining_depth_(0), |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 103 | context_(context) { |
| 104 | DCHECK(thread == Thread::Current() || thread->IsSuspended()) << *thread; |
| 105 | } |
| 106 | |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 107 | InlineInfo StackVisitor::GetCurrentInlineInfo() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 108 | mirror::ArtMethod* outer_method = GetCurrentQuickFrame()->AsMirrorPtr(); |
| 109 | uint32_t native_pc_offset = outer_method->NativeQuickPcOffset(cur_quick_frame_pc_); |
| 110 | CodeInfo code_info = outer_method->GetOptimizedCodeInfo(); |
| 111 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 112 | DCHECK(stack_map.IsValid()); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 113 | return code_info.GetInlineInfoOf(stack_map); |
| 114 | } |
| 115 | |
| 116 | mirror::ArtMethod* StackVisitor::GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 117 | if (cur_shadow_frame_ != nullptr) { |
| 118 | return cur_shadow_frame_->GetMethod(); |
| 119 | } else if (cur_quick_frame_ != nullptr) { |
| 120 | if (IsInInlinedFrame()) { |
| 121 | size_t depth_in_stack_map = current_inlining_depth_ - 1; |
| 122 | return GetCurrentQuickFrame()->AsMirrorPtr()->GetDexCacheResolvedMethod( |
| 123 | GetCurrentInlineInfo().GetMethodIndexAtDepth(depth_in_stack_map)); |
| 124 | } else { |
| 125 | return cur_quick_frame_->AsMirrorPtr(); |
| 126 | } |
| 127 | } else { |
| 128 | return nullptr; |
| 129 | } |
| 130 | } |
| 131 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 132 | uint32_t StackVisitor::GetDexPc(bool abort_on_failure) const { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 133 | if (cur_shadow_frame_ != nullptr) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 134 | return cur_shadow_frame_->GetDexPC(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 135 | } else if (cur_quick_frame_ != nullptr) { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 136 | if (IsInInlinedFrame()) { |
| 137 | size_t depth_in_stack_map = current_inlining_depth_ - 1; |
| 138 | return GetCurrentInlineInfo().GetDexPcAtDepth(depth_in_stack_map); |
| 139 | } else { |
| 140 | return GetMethod()->ToDexPc(cur_quick_frame_pc_, abort_on_failure); |
| 141 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 142 | } else { |
| 143 | return 0; |
| 144 | } |
| 145 | } |
| 146 | |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 147 | extern "C" mirror::Object* artQuickGetProxyThisObject(StackReference<mirror::ArtMethod>* sp) |
| 148 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 149 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 150 | mirror::Object* StackVisitor::GetThisObject() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 151 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 152 | if (m->IsStatic()) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 153 | return nullptr; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 154 | } else if (m->IsNative()) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 155 | if (cur_quick_frame_ != nullptr) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 156 | HandleScope* hs = reinterpret_cast<HandleScope*>( |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 157 | reinterpret_cast<char*>(cur_quick_frame_) + m->GetHandleScopeOffset().SizeValue()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 158 | return hs->GetReference(0); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 159 | } else { |
| 160 | return cur_shadow_frame_->GetVRegReference(0); |
| 161 | } |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 162 | } else if (m->IsProxyMethod()) { |
| 163 | if (cur_quick_frame_ != nullptr) { |
| 164 | return artQuickGetProxyThisObject(cur_quick_frame_); |
| 165 | } else { |
| 166 | return cur_shadow_frame_->GetVRegReference(0); |
| 167 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 168 | } else { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 169 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 170 | if (code_item == nullptr) { |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 171 | UNIMPLEMENTED(ERROR) << "Failed to determine this object of abstract or proxy method: " |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 172 | << PrettyMethod(m); |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 173 | return nullptr; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 174 | } else { |
| 175 | uint16_t reg = code_item->registers_size_ - code_item->ins_size_; |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 176 | uint32_t value = 0; |
| 177 | bool success = GetVReg(m, reg, kReferenceVReg, &value); |
| 178 | // We currently always guarantee the `this` object is live throughout the method. |
| 179 | CHECK(success) << "Failed to read the this object in " << PrettyMethod(m); |
| 180 | return reinterpret_cast<mirror::Object*>(value); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 185 | size_t StackVisitor::GetNativePcOffset() const { |
| 186 | DCHECK(!IsShadowFrame()); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 187 | return GetMethod()->NativeQuickPcOffset(cur_quick_frame_pc_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Mathieu Chartier | 50030ef | 2015-05-08 14:19:26 -0700 | [diff] [blame] | 190 | bool StackVisitor::IsReferenceVReg(mirror::ArtMethod* m, uint16_t vreg) { |
| 191 | // Process register map (which native and runtime methods don't have) |
| 192 | if (m->IsNative() || m->IsRuntimeMethod() || m->IsProxyMethod()) { |
| 193 | return false; |
| 194 | } |
| 195 | if (m->IsOptimized(sizeof(void*))) { |
| 196 | return true; // TODO: Implement. |
| 197 | } |
| 198 | const uint8_t* native_gc_map = m->GetNativeGcMap(sizeof(void*)); |
| 199 | CHECK(native_gc_map != nullptr) << PrettyMethod(m); |
| 200 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
| 201 | // Can't be null or how would we compile its instructions? |
| 202 | DCHECK(code_item != nullptr) << PrettyMethod(m); |
| 203 | NativePcOffsetToReferenceMap map(native_gc_map); |
| 204 | size_t num_regs = std::min(map.RegWidth() * 8, static_cast<size_t>(code_item->registers_size_)); |
| 205 | const uint8_t* reg_bitmap = nullptr; |
| 206 | if (num_regs > 0) { |
| 207 | Runtime* runtime = Runtime::Current(); |
| 208 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(m, sizeof(void*)); |
| 209 | uintptr_t native_pc_offset = m->NativeQuickPcOffset(GetCurrentQuickFramePc(), entry_point); |
| 210 | reg_bitmap = map.FindBitMap(native_pc_offset); |
| 211 | DCHECK(reg_bitmap != nullptr); |
| 212 | } |
| 213 | // Does this register hold a reference? |
| 214 | return vreg < num_regs && TestBitmap(vreg, reg_bitmap); |
| 215 | } |
| 216 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 217 | bool StackVisitor::GetVReg(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, |
| 218 | uint32_t* val) const { |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 219 | if (cur_quick_frame_ != nullptr) { |
| 220 | DCHECK(context_ != nullptr); // You can't reliably read registers without a context. |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 221 | DCHECK(m == GetMethod()); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 222 | if (m->IsOptimized(sizeof(void*))) { |
| 223 | return GetVRegFromOptimizedCode(m, vreg, kind, val); |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 224 | } else { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 225 | return GetVRegFromQuickCode(m, vreg, kind, val); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 226 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 227 | } else { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 228 | DCHECK(cur_shadow_frame_ != nullptr); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 229 | *val = cur_shadow_frame_->GetVReg(vreg); |
| 230 | return true; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 234 | bool StackVisitor::GetVRegFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, |
| 235 | uint32_t* val) const { |
| 236 | const void* code_pointer = m->GetQuickOatCodePointer(sizeof(void*)); |
| 237 | DCHECK(code_pointer != nullptr); |
| 238 | const VmapTable vmap_table(m->GetVmapTable(code_pointer, sizeof(void*))); |
| 239 | QuickMethodFrameInfo frame_info = m->GetQuickFrameInfo(code_pointer); |
| 240 | uint32_t vmap_offset; |
| 241 | // TODO: IsInContext stops before spotting floating point registers. |
| 242 | if (vmap_table.IsInContext(vreg, kind, &vmap_offset)) { |
| 243 | bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
| 244 | uint32_t spill_mask = is_float ? frame_info.FpSpillMask() : frame_info.CoreSpillMask(); |
| 245 | uint32_t reg = vmap_table.ComputeRegister(spill_mask, vmap_offset, kind); |
| 246 | return GetRegisterIfAccessible(reg, kind, val); |
| 247 | } else { |
| 248 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 249 | DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be null or how would we compile |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 250 | // its instructions? |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 251 | *val = *GetVRegAddrFromQuickCode(cur_quick_frame_, code_item, frame_info.CoreSpillMask(), |
| 252 | frame_info.FpSpillMask(), frame_info.FrameSizeInBytes(), vreg); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | bool StackVisitor::GetVRegFromOptimizedCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, |
| 258 | uint32_t* val) const { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 259 | DCHECK_EQ(m, GetMethod()); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 260 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 261 | DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be null or how would we compile |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 262 | // its instructions? |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 263 | uint16_t number_of_dex_registers = code_item->registers_size_; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 264 | DCHECK_LT(vreg, code_item->registers_size_); |
| 265 | |
| 266 | mirror::ArtMethod* outer_method = GetCurrentQuickFrame()->AsMirrorPtr(); |
| 267 | const void* code_pointer = outer_method->GetQuickOatCodePointer(sizeof(void*)); |
| 268 | DCHECK(code_pointer != nullptr); |
| 269 | CodeInfo code_info = outer_method->GetOptimizedCodeInfo(); |
| 270 | |
| 271 | uint32_t native_pc_offset = outer_method->NativeQuickPcOffset(cur_quick_frame_pc_); |
| 272 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 273 | DCHECK(stack_map.IsValid()); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 274 | size_t depth_in_stack_map = current_inlining_depth_ - 1; |
| 275 | |
| 276 | DexRegisterMap dex_register_map = IsInInlinedFrame() |
| 277 | ? code_info.GetDexRegisterMapAtDepth( |
| 278 | depth_in_stack_map, code_info.GetInlineInfoOf(stack_map), number_of_dex_registers) |
| 279 | : code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); |
| 280 | |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 281 | DexRegisterLocation::Kind location_kind = |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 282 | dex_register_map.GetLocationKind(vreg, number_of_dex_registers, code_info); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 283 | switch (location_kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 284 | case DexRegisterLocation::Kind::kInStack: { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 285 | const int32_t offset = |
| 286 | dex_register_map.GetStackOffsetInBytes(vreg, number_of_dex_registers, code_info); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 287 | const uint8_t* addr = reinterpret_cast<const uint8_t*>(cur_quick_frame_) + offset; |
| 288 | *val = *reinterpret_cast<const uint32_t*>(addr); |
| 289 | return true; |
| 290 | } |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 291 | case DexRegisterLocation::Kind::kInRegister: |
| 292 | case DexRegisterLocation::Kind::kInFpuRegister: { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 293 | uint32_t reg = dex_register_map.GetMachineRegister(vreg, number_of_dex_registers, code_info); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 294 | return GetRegisterIfAccessible(reg, kind, val); |
| 295 | } |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 296 | case DexRegisterLocation::Kind::kConstant: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 297 | *val = dex_register_map.GetConstant(vreg, number_of_dex_registers, code_info); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 298 | return true; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 299 | case DexRegisterLocation::Kind::kNone: |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 300 | return false; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 301 | default: |
| 302 | LOG(FATAL) |
| 303 | << "Unexpected location kind" |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 304 | << DexRegisterLocation::PrettyDescriptor( |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 305 | dex_register_map.GetLocationInternalKind(vreg, number_of_dex_registers, code_info)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 306 | UNREACHABLE(); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 307 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | bool StackVisitor::GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const { |
| 311 | const bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
| 312 | if (!IsAccessibleRegister(reg, is_float)) { |
| 313 | return false; |
| 314 | } |
| 315 | uintptr_t ptr_val = GetRegister(reg, is_float); |
| 316 | const bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 317 | if (target64) { |
| 318 | const bool wide_lo = (kind == kLongLoVReg) || (kind == kDoubleLoVReg); |
| 319 | const bool wide_hi = (kind == kLongHiVReg) || (kind == kDoubleHiVReg); |
| 320 | int64_t value_long = static_cast<int64_t>(ptr_val); |
| 321 | if (wide_lo) { |
| 322 | ptr_val = static_cast<uintptr_t>(Low32Bits(value_long)); |
| 323 | } else if (wide_hi) { |
| 324 | ptr_val = static_cast<uintptr_t>(High32Bits(value_long)); |
| 325 | } |
| 326 | } |
| 327 | *val = ptr_val; |
| 328 | return true; |
| 329 | } |
| 330 | |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 331 | bool StackVisitor::GetVRegPair(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo, |
| 332 | VRegKind kind_hi, uint64_t* val) const { |
| 333 | if (kind_lo == kLongLoVReg) { |
| 334 | DCHECK_EQ(kind_hi, kLongHiVReg); |
| 335 | } else if (kind_lo == kDoubleLoVReg) { |
| 336 | DCHECK_EQ(kind_hi, kDoubleHiVReg); |
| 337 | } else { |
| 338 | LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi; |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 339 | UNREACHABLE(); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 340 | } |
| 341 | if (cur_quick_frame_ != nullptr) { |
| 342 | DCHECK(context_ != nullptr); // You can't reliably read registers without a context. |
| 343 | DCHECK(m == GetMethod()); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 344 | if (m->IsOptimized(sizeof(void*))) { |
| 345 | return GetVRegPairFromOptimizedCode(m, vreg, kind_lo, kind_hi, val); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 346 | } else { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 347 | return GetVRegPairFromQuickCode(m, vreg, kind_lo, kind_hi, val); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 348 | } |
| 349 | } else { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 350 | DCHECK(cur_shadow_frame_ != nullptr); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 351 | *val = cur_shadow_frame_->GetVRegLong(vreg); |
| 352 | return true; |
| 353 | } |
| 354 | } |
| 355 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 356 | bool StackVisitor::GetVRegPairFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo, |
| 357 | VRegKind kind_hi, uint64_t* val) const { |
| 358 | const void* code_pointer = m->GetQuickOatCodePointer(sizeof(void*)); |
| 359 | DCHECK(code_pointer != nullptr); |
| 360 | const VmapTable vmap_table(m->GetVmapTable(code_pointer, sizeof(void*))); |
| 361 | QuickMethodFrameInfo frame_info = m->GetQuickFrameInfo(code_pointer); |
| 362 | uint32_t vmap_offset_lo, vmap_offset_hi; |
| 363 | // TODO: IsInContext stops before spotting floating point registers. |
| 364 | if (vmap_table.IsInContext(vreg, kind_lo, &vmap_offset_lo) && |
| 365 | vmap_table.IsInContext(vreg + 1, kind_hi, &vmap_offset_hi)) { |
| 366 | bool is_float = (kind_lo == kDoubleLoVReg); |
| 367 | uint32_t spill_mask = is_float ? frame_info.FpSpillMask() : frame_info.CoreSpillMask(); |
| 368 | uint32_t reg_lo = vmap_table.ComputeRegister(spill_mask, vmap_offset_lo, kind_lo); |
| 369 | uint32_t reg_hi = vmap_table.ComputeRegister(spill_mask, vmap_offset_hi, kind_hi); |
| 370 | return GetRegisterPairIfAccessible(reg_lo, reg_hi, kind_lo, val); |
| 371 | } else { |
| 372 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 373 | DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be null or how would we compile |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 374 | // its instructions? |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 375 | uint32_t* addr = GetVRegAddrFromQuickCode( |
| 376 | cur_quick_frame_, code_item, frame_info.CoreSpillMask(), |
| 377 | frame_info.FpSpillMask(), frame_info.FrameSizeInBytes(), vreg); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 378 | *val = *reinterpret_cast<uint64_t*>(addr); |
| 379 | return true; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | bool StackVisitor::GetVRegPairFromOptimizedCode(mirror::ArtMethod* m, uint16_t vreg, |
| 384 | VRegKind kind_lo, VRegKind kind_hi, |
| 385 | uint64_t* val) const { |
| 386 | uint32_t low_32bits; |
| 387 | uint32_t high_32bits; |
| 388 | bool success = GetVRegFromOptimizedCode(m, vreg, kind_lo, &low_32bits); |
| 389 | success &= GetVRegFromOptimizedCode(m, vreg + 1, kind_hi, &high_32bits); |
| 390 | if (success) { |
| 391 | *val = (static_cast<uint64_t>(high_32bits) << 32) | static_cast<uint64_t>(low_32bits); |
| 392 | } |
| 393 | return success; |
| 394 | } |
| 395 | |
| 396 | bool StackVisitor::GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, |
| 397 | VRegKind kind_lo, uint64_t* val) const { |
| 398 | const bool is_float = (kind_lo == kDoubleLoVReg); |
| 399 | if (!IsAccessibleRegister(reg_lo, is_float) || !IsAccessibleRegister(reg_hi, is_float)) { |
| 400 | return false; |
| 401 | } |
| 402 | uintptr_t ptr_val_lo = GetRegister(reg_lo, is_float); |
| 403 | uintptr_t ptr_val_hi = GetRegister(reg_hi, is_float); |
| 404 | bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 405 | if (target64) { |
| 406 | int64_t value_long_lo = static_cast<int64_t>(ptr_val_lo); |
| 407 | int64_t value_long_hi = static_cast<int64_t>(ptr_val_hi); |
| 408 | ptr_val_lo = static_cast<uintptr_t>(Low32Bits(value_long_lo)); |
| 409 | ptr_val_hi = static_cast<uintptr_t>(High32Bits(value_long_hi)); |
| 410 | } |
| 411 | *val = (static_cast<uint64_t>(ptr_val_hi) << 32) | static_cast<uint32_t>(ptr_val_lo); |
| 412 | return true; |
| 413 | } |
| 414 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 415 | bool StackVisitor::SetVReg(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 416 | VRegKind kind) { |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 417 | if (cur_quick_frame_ != nullptr) { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 418 | DCHECK(context_ != nullptr); // You can't reliably write registers without a context. |
| 419 | DCHECK(m == GetMethod()); |
| 420 | if (m->IsOptimized(sizeof(void*))) { |
Nicolas Geoffray | 7cc56a1 | 2015-04-24 14:58:19 +0100 | [diff] [blame] | 421 | return false; |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 422 | } else { |
| 423 | return SetVRegFromQuickCode(m, vreg, new_value, kind); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 424 | } |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 425 | } else { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 426 | cur_shadow_frame_->SetVReg(vreg, new_value); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 427 | return true; |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 428 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | bool StackVisitor::SetVRegFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, |
| 432 | VRegKind kind) { |
| 433 | DCHECK(context_ != nullptr); // You can't reliably write registers without a context. |
| 434 | DCHECK(m == GetMethod()); |
| 435 | const void* code_pointer = m->GetQuickOatCodePointer(sizeof(void*)); |
| 436 | DCHECK(code_pointer != nullptr); |
| 437 | const VmapTable vmap_table(m->GetVmapTable(code_pointer, sizeof(void*))); |
| 438 | QuickMethodFrameInfo frame_info = m->GetQuickFrameInfo(code_pointer); |
| 439 | uint32_t vmap_offset; |
| 440 | // TODO: IsInContext stops before spotting floating point registers. |
| 441 | if (vmap_table.IsInContext(vreg, kind, &vmap_offset)) { |
| 442 | bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
| 443 | uint32_t spill_mask = is_float ? frame_info.FpSpillMask() : frame_info.CoreSpillMask(); |
| 444 | uint32_t reg = vmap_table.ComputeRegister(spill_mask, vmap_offset, kind); |
| 445 | return SetRegisterIfAccessible(reg, new_value, kind); |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 446 | } else { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 447 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 448 | DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be null or how would we compile |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 449 | // its instructions? |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 450 | uint32_t* addr = GetVRegAddrFromQuickCode( |
| 451 | cur_quick_frame_, code_item, frame_info.CoreSpillMask(), |
| 452 | frame_info.FpSpillMask(), frame_info.FrameSizeInBytes(), vreg); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 453 | *addr = new_value; |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 454 | return true; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 455 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 458 | bool StackVisitor::SetRegisterIfAccessible(uint32_t reg, uint32_t new_value, VRegKind kind) { |
| 459 | const bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
| 460 | if (!IsAccessibleRegister(reg, is_float)) { |
| 461 | return false; |
| 462 | } |
| 463 | const bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 464 | |
| 465 | // Create a new value that can hold both low 32 and high 32 bits, in |
| 466 | // case we are running 64 bits. |
| 467 | uintptr_t full_new_value = new_value; |
| 468 | // Deal with 32 or 64-bit wide registers in a way that builds on all targets. |
| 469 | if (target64) { |
| 470 | bool wide_lo = (kind == kLongLoVReg) || (kind == kDoubleLoVReg); |
| 471 | bool wide_hi = (kind == kLongHiVReg) || (kind == kDoubleHiVReg); |
| 472 | if (wide_lo || wide_hi) { |
| 473 | uintptr_t old_reg_val = GetRegister(reg, is_float); |
| 474 | uint64_t new_vreg_portion = static_cast<uint64_t>(new_value); |
| 475 | uint64_t old_reg_val_as_wide = static_cast<uint64_t>(old_reg_val); |
| 476 | uint64_t mask = 0xffffffff; |
| 477 | if (wide_lo) { |
| 478 | mask = mask << 32; |
| 479 | } else { |
| 480 | new_vreg_portion = new_vreg_portion << 32; |
| 481 | } |
| 482 | full_new_value = static_cast<uintptr_t>((old_reg_val_as_wide & mask) | new_vreg_portion); |
| 483 | } |
| 484 | } |
| 485 | SetRegister(reg, full_new_value, is_float); |
| 486 | return true; |
| 487 | } |
| 488 | |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 489 | bool StackVisitor::SetVRegPair(mirror::ArtMethod* m, uint16_t vreg, uint64_t new_value, |
| 490 | VRegKind kind_lo, VRegKind kind_hi) { |
| 491 | if (kind_lo == kLongLoVReg) { |
| 492 | DCHECK_EQ(kind_hi, kLongHiVReg); |
| 493 | } else if (kind_lo == kDoubleLoVReg) { |
| 494 | DCHECK_EQ(kind_hi, kDoubleHiVReg); |
| 495 | } else { |
| 496 | LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi; |
| 497 | } |
| 498 | if (cur_quick_frame_ != nullptr) { |
| 499 | DCHECK(context_ != nullptr); // You can't reliably write registers without a context. |
| 500 | DCHECK(m == GetMethod()); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 501 | if (m->IsOptimized(sizeof(void*))) { |
Nicolas Geoffray | 7cc56a1 | 2015-04-24 14:58:19 +0100 | [diff] [blame] | 502 | return false; |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 503 | } else { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 504 | return SetVRegPairFromQuickCode(m, vreg, new_value, kind_lo, kind_hi); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 505 | } |
| 506 | } else { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 507 | DCHECK(cur_shadow_frame_ != nullptr); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 508 | cur_shadow_frame_->SetVRegLong(vreg, new_value); |
| 509 | return true; |
| 510 | } |
| 511 | } |
| 512 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 513 | bool StackVisitor::SetVRegPairFromQuickCode( |
| 514 | mirror::ArtMethod* m, uint16_t vreg, uint64_t new_value, VRegKind kind_lo, VRegKind kind_hi) { |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 515 | const void* code_pointer = m->GetQuickOatCodePointer(sizeof(void*)); |
| 516 | DCHECK(code_pointer != nullptr); |
| 517 | const VmapTable vmap_table(m->GetVmapTable(code_pointer, sizeof(void*))); |
| 518 | QuickMethodFrameInfo frame_info = m->GetQuickFrameInfo(code_pointer); |
| 519 | uint32_t vmap_offset_lo, vmap_offset_hi; |
| 520 | // TODO: IsInContext stops before spotting floating point registers. |
| 521 | if (vmap_table.IsInContext(vreg, kind_lo, &vmap_offset_lo) && |
| 522 | vmap_table.IsInContext(vreg + 1, kind_hi, &vmap_offset_hi)) { |
| 523 | bool is_float = (kind_lo == kDoubleLoVReg); |
| 524 | uint32_t spill_mask = is_float ? frame_info.FpSpillMask() : frame_info.CoreSpillMask(); |
| 525 | uint32_t reg_lo = vmap_table.ComputeRegister(spill_mask, vmap_offset_lo, kind_lo); |
| 526 | uint32_t reg_hi = vmap_table.ComputeRegister(spill_mask, vmap_offset_hi, kind_hi); |
| 527 | return SetRegisterPairIfAccessible(reg_lo, reg_hi, new_value, is_float); |
| 528 | } else { |
| 529 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 530 | DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be null or how would we compile |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 531 | // its instructions? |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 532 | uint32_t* addr = GetVRegAddrFromQuickCode( |
| 533 | cur_quick_frame_, code_item, frame_info.CoreSpillMask(), |
| 534 | frame_info.FpSpillMask(), frame_info.FrameSizeInBytes(), vreg); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 535 | *reinterpret_cast<uint64_t*>(addr) = new_value; |
| 536 | return true; |
| 537 | } |
| 538 | } |
| 539 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 540 | bool StackVisitor::SetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, |
| 541 | uint64_t new_value, bool is_float) { |
| 542 | if (!IsAccessibleRegister(reg_lo, is_float) || !IsAccessibleRegister(reg_hi, is_float)) { |
| 543 | return false; |
| 544 | } |
| 545 | uintptr_t new_value_lo = static_cast<uintptr_t>(new_value & 0xFFFFFFFF); |
| 546 | uintptr_t new_value_hi = static_cast<uintptr_t>(new_value >> 32); |
| 547 | bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 548 | // Deal with 32 or 64-bit wide registers in a way that builds on all targets. |
| 549 | if (target64) { |
| 550 | DCHECK_EQ(reg_lo, reg_hi); |
| 551 | SetRegister(reg_lo, new_value, is_float); |
| 552 | } else { |
| 553 | SetRegister(reg_lo, new_value_lo, is_float); |
| 554 | SetRegister(reg_hi, new_value_hi, is_float); |
| 555 | } |
| 556 | return true; |
| 557 | } |
| 558 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 559 | bool StackVisitor::IsAccessibleGPR(uint32_t reg) const { |
| 560 | DCHECK(context_ != nullptr); |
| 561 | return context_->IsAccessibleGPR(reg); |
| 562 | } |
| 563 | |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 564 | uintptr_t* StackVisitor::GetGPRAddress(uint32_t reg) const { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 565 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 566 | DCHECK(context_ != nullptr); |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 567 | return context_->GetGPRAddress(reg); |
| 568 | } |
| 569 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 570 | uintptr_t StackVisitor::GetGPR(uint32_t reg) const { |
| 571 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 572 | DCHECK(context_ != nullptr); |
| 573 | return context_->GetGPR(reg); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 576 | void StackVisitor::SetGPR(uint32_t reg, uintptr_t value) { |
| 577 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 578 | DCHECK(context_ != nullptr); |
| 579 | context_->SetGPR(reg, value); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 582 | bool StackVisitor::IsAccessibleFPR(uint32_t reg) const { |
| 583 | DCHECK(context_ != nullptr); |
| 584 | return context_->IsAccessibleFPR(reg); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 587 | uintptr_t StackVisitor::GetFPR(uint32_t reg) const { |
| 588 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 589 | DCHECK(context_ != nullptr); |
| 590 | return context_->GetFPR(reg); |
| 591 | } |
| 592 | |
| 593 | void StackVisitor::SetFPR(uint32_t reg, uintptr_t value) { |
| 594 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 595 | DCHECK(context_ != nullptr); |
| 596 | context_->SetFPR(reg, value); |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 599 | uintptr_t StackVisitor::GetReturnPc() const { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 600 | uint8_t* sp = reinterpret_cast<uint8_t*>(GetCurrentQuickFrame()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 601 | DCHECK(sp != nullptr); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 602 | uint8_t* pc_addr = sp + GetMethod()->GetReturnPcOffset().SizeValue(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 603 | return *reinterpret_cast<uintptr_t*>(pc_addr); |
| 604 | } |
| 605 | |
| 606 | void StackVisitor::SetReturnPc(uintptr_t new_ret_pc) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 607 | uint8_t* sp = reinterpret_cast<uint8_t*>(GetCurrentQuickFrame()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 608 | CHECK(sp != nullptr); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 609 | uint8_t* pc_addr = sp + GetMethod()->GetReturnPcOffset().SizeValue(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 610 | *reinterpret_cast<uintptr_t*>(pc_addr) = new_ret_pc; |
| 611 | } |
| 612 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 613 | size_t StackVisitor::ComputeNumFrames(Thread* thread, StackWalkKind walk_kind) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 614 | struct NumFramesVisitor : public StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 615 | NumFramesVisitor(Thread* thread_in, StackWalkKind walk_kind_in) |
| 616 | : StackVisitor(thread_in, nullptr, walk_kind_in), frames(0) {} |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 617 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 618 | bool VisitFrame() OVERRIDE { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 619 | frames++; |
| 620 | return true; |
| 621 | } |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 622 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 623 | size_t frames; |
| 624 | }; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 625 | NumFramesVisitor visitor(thread, walk_kind); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 626 | visitor.WalkStack(true); |
| 627 | return visitor.frames; |
| 628 | } |
| 629 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 630 | bool StackVisitor::GetNextMethodAndDexPc(mirror::ArtMethod** next_method, uint32_t* next_dex_pc) { |
| 631 | struct HasMoreFramesVisitor : public StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 632 | HasMoreFramesVisitor(Thread* thread, |
| 633 | StackWalkKind walk_kind, |
| 634 | size_t num_frames, |
| 635 | size_t frame_height) |
| 636 | : StackVisitor(thread, nullptr, walk_kind, num_frames), |
| 637 | frame_height_(frame_height), |
| 638 | found_frame_(false), |
| 639 | has_more_frames_(false), |
| 640 | next_method_(nullptr), |
| 641 | next_dex_pc_(0) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 645 | if (found_frame_) { |
| 646 | mirror::ArtMethod* method = GetMethod(); |
| 647 | if (method != nullptr && !method->IsRuntimeMethod()) { |
| 648 | has_more_frames_ = true; |
| 649 | next_method_ = method; |
| 650 | next_dex_pc_ = GetDexPc(); |
| 651 | return false; // End stack walk once next method is found. |
| 652 | } |
| 653 | } else if (GetFrameHeight() == frame_height_) { |
| 654 | found_frame_ = true; |
| 655 | } |
| 656 | return true; |
| 657 | } |
| 658 | |
| 659 | size_t frame_height_; |
| 660 | bool found_frame_; |
| 661 | bool has_more_frames_; |
| 662 | mirror::ArtMethod* next_method_; |
| 663 | uint32_t next_dex_pc_; |
| 664 | }; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 665 | HasMoreFramesVisitor visitor(thread_, walk_kind_, GetNumFrames(), GetFrameHeight()); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 666 | visitor.WalkStack(true); |
| 667 | *next_method = visitor.next_method_; |
| 668 | *next_dex_pc = visitor.next_dex_pc_; |
| 669 | return visitor.has_more_frames_; |
| 670 | } |
| 671 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 672 | void StackVisitor::DescribeStack(Thread* thread) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 673 | struct DescribeStackVisitor : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 674 | explicit DescribeStackVisitor(Thread* thread_in) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 675 | : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {} |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 676 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 677 | bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 678 | LOG(INFO) << "Frame Id=" << GetFrameId() << " " << DescribeLocation(); |
| 679 | return true; |
| 680 | } |
| 681 | }; |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 682 | DescribeStackVisitor visitor(thread); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 683 | visitor.WalkStack(true); |
| 684 | } |
| 685 | |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 686 | std::string StackVisitor::DescribeLocation() const { |
| 687 | std::string result("Visiting method '"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 688 | mirror::ArtMethod* m = GetMethod(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 689 | if (m == nullptr) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 690 | return "upcall"; |
| 691 | } |
| 692 | result += PrettyMethod(m); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 693 | result += StringPrintf("' at dex PC 0x%04x", GetDexPc()); |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 694 | if (!IsShadowFrame()) { |
| 695 | result += StringPrintf(" (native PC %p)", reinterpret_cast<void*>(GetCurrentQuickFramePc())); |
| 696 | } |
| 697 | return result; |
| 698 | } |
| 699 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 700 | static instrumentation::InstrumentationStackFrame& GetInstrumentationStackFrame(Thread* thread, |
| 701 | uint32_t depth) { |
| 702 | CHECK_LT(depth, thread->GetInstrumentationStack()->size()); |
| 703 | return thread->GetInstrumentationStack()->at(depth); |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 706 | void StackVisitor::SanityCheckFrame() const { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 707 | if (kIsDebugBuild) { |
| 708 | mirror::ArtMethod* method = GetMethod(); |
Mathieu Chartier | 119c6bd | 2014-05-09 14:11:47 -0700 | [diff] [blame] | 709 | CHECK_EQ(method->GetClass(), mirror::ArtMethod::GetJavaLangReflectArtMethod()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 710 | if (cur_quick_frame_ != nullptr) { |
| 711 | method->AssertPcIsWithinQuickCode(cur_quick_frame_pc_); |
| 712 | // Frame sanity. |
| 713 | size_t frame_size = method->GetFrameSizeInBytes(); |
| 714 | CHECK_NE(frame_size, 0u); |
Andreas Gampe | 5b417b9 | 2014-03-10 14:18:35 -0700 | [diff] [blame] | 715 | // A rough guess at an upper size we expect to see for a frame. |
| 716 | // 256 registers |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 717 | // 2 words HandleScope overhead |
Andreas Gampe | 5b417b9 | 2014-03-10 14:18:35 -0700 | [diff] [blame] | 718 | // 3+3 register spills |
| 719 | // TODO: this seems architecture specific for the case of JNI frames. |
Brian Carlstrom | ed08bd4 | 2014-03-19 18:34:17 -0700 | [diff] [blame] | 720 | // TODO: 083-compiler-regressions ManyFloatArgs shows this estimate is wrong. |
| 721 | // const size_t kMaxExpectedFrameSize = (256 + 2 + 3 + 3) * sizeof(word); |
| 722 | const size_t kMaxExpectedFrameSize = 2 * KB; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 723 | CHECK_LE(frame_size, kMaxExpectedFrameSize); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 724 | size_t return_pc_offset = method->GetReturnPcOffset().SizeValue(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 725 | CHECK_LT(return_pc_offset, frame_size); |
| 726 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 727 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void StackVisitor::WalkStack(bool include_transitions) { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 731 | DCHECK(thread_ == Thread::Current() || thread_->IsSuspended()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 732 | CHECK_EQ(cur_depth_, 0U); |
| 733 | bool exit_stubs_installed = Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 734 | uint32_t instrumentation_stack_depth = 0; |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 735 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 736 | for (const ManagedStack* current_fragment = thread_->GetManagedStack(); |
| 737 | current_fragment != nullptr; current_fragment = current_fragment->GetLink()) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 738 | cur_shadow_frame_ = current_fragment->GetTopShadowFrame(); |
| 739 | cur_quick_frame_ = current_fragment->GetTopQuickFrame(); |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 740 | cur_quick_frame_pc_ = 0; |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 741 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 742 | if (cur_quick_frame_ != nullptr) { // Handle quick stack frames. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 743 | // Can't be both a shadow and a quick fragment. |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 744 | DCHECK(current_fragment->GetTopShadowFrame() == nullptr); |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 745 | mirror::ArtMethod* method = cur_quick_frame_->AsMirrorPtr(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 746 | while (method != nullptr) { |
Dave Allison | 5cd3375 | 2014-04-15 15:57:58 -0700 | [diff] [blame] | 747 | SanityCheckFrame(); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 748 | |
| 749 | if ((walk_kind_ == StackWalkKind::kIncludeInlinedFrames) |
| 750 | && method->IsOptimized(sizeof(void*))) { |
| 751 | CodeInfo code_info = method->GetOptimizedCodeInfo(); |
| 752 | uint32_t native_pc_offset = method->NativeQuickPcOffset(cur_quick_frame_pc_); |
| 753 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 754 | if (stack_map.IsValid() && stack_map.HasInlineInfo(code_info)) { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 755 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); |
| 756 | DCHECK_EQ(current_inlining_depth_, 0u); |
| 757 | for (current_inlining_depth_ = inline_info.GetDepth(); |
| 758 | current_inlining_depth_ != 0; |
| 759 | --current_inlining_depth_) { |
| 760 | bool should_continue = VisitFrame(); |
| 761 | if (UNLIKELY(!should_continue)) { |
| 762 | return; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
Dave Allison | 5cd3375 | 2014-04-15 15:57:58 -0700 | [diff] [blame] | 768 | bool should_continue = VisitFrame(); |
| 769 | if (UNLIKELY(!should_continue)) { |
| 770 | return; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 771 | } |
Dave Allison | 5cd3375 | 2014-04-15 15:57:58 -0700 | [diff] [blame] | 772 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 773 | if (context_ != nullptr) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 774 | context_->FillCalleeSaves(*this); |
| 775 | } |
| 776 | size_t frame_size = method->GetFrameSizeInBytes(); |
| 777 | // Compute PC for next stack frame from return PC. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 778 | size_t return_pc_offset = method->GetReturnPcOffset(frame_size).SizeValue(); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 779 | uint8_t* return_pc_addr = reinterpret_cast<uint8_t*>(cur_quick_frame_) + return_pc_offset; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 780 | uintptr_t return_pc = *reinterpret_cast<uintptr_t*>(return_pc_addr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 781 | if (UNLIKELY(exit_stubs_installed)) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 782 | // While profiling, the return pc is restored from the side stack, except when walking |
| 783 | // the stack for an exception where the side stack will be unwound in VisitFrame. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 784 | if (reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) == return_pc) { |
Sebastien Hertz | 74e256b | 2013-10-04 10:40:37 +0200 | [diff] [blame] | 785 | const instrumentation::InstrumentationStackFrame& instrumentation_frame = |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 786 | GetInstrumentationStackFrame(thread_, instrumentation_stack_depth); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 787 | instrumentation_stack_depth++; |
Jeff Hao | fb2802d | 2013-07-24 13:53:05 -0700 | [diff] [blame] | 788 | if (GetMethod() == Runtime::Current()->GetCalleeSaveMethod(Runtime::kSaveAll)) { |
| 789 | // Skip runtime save all callee frames which are used to deliver exceptions. |
| 790 | } else if (instrumentation_frame.interpreter_entry_) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 791 | mirror::ArtMethod* callee = |
| 792 | Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsAndArgs); |
Jeff Hao | fb2802d | 2013-07-24 13:53:05 -0700 | [diff] [blame] | 793 | CHECK_EQ(GetMethod(), callee) << "Expected: " << PrettyMethod(callee) << " Found: " |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 794 | << PrettyMethod(GetMethod()); |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 795 | } else if (instrumentation_frame.method_ != GetMethod()) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 796 | LOG(FATAL) << "Expected: " << PrettyMethod(instrumentation_frame.method_) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 797 | << " Found: " << PrettyMethod(GetMethod()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 798 | } |
| 799 | if (num_frames_ != 0) { |
| 800 | // Check agreement of frame Ids only if num_frames_ is computed to avoid infinite |
| 801 | // recursion. |
| 802 | CHECK(instrumentation_frame.frame_id_ == GetFrameId()) |
| 803 | << "Expected: " << instrumentation_frame.frame_id_ |
| 804 | << " Found: " << GetFrameId(); |
| 805 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 806 | return_pc = instrumentation_frame.return_pc_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | cur_quick_frame_pc_ = return_pc; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 810 | uint8_t* next_frame = reinterpret_cast<uint8_t*>(cur_quick_frame_) + frame_size; |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 811 | cur_quick_frame_ = reinterpret_cast<StackReference<mirror::ArtMethod>*>(next_frame); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 812 | cur_depth_++; |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 813 | method = cur_quick_frame_->AsMirrorPtr(); |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame] | 814 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 815 | } else if (cur_shadow_frame_ != nullptr) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 816 | do { |
| 817 | SanityCheckFrame(); |
| 818 | bool should_continue = VisitFrame(); |
| 819 | if (UNLIKELY(!should_continue)) { |
| 820 | return; |
| 821 | } |
| 822 | cur_depth_++; |
| 823 | cur_shadow_frame_ = cur_shadow_frame_->GetLink(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 824 | } while (cur_shadow_frame_ != nullptr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 825 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 826 | if (include_transitions) { |
| 827 | bool should_continue = VisitFrame(); |
| 828 | if (!should_continue) { |
| 829 | return; |
| 830 | } |
| 831 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 832 | cur_depth_++; |
| 833 | } |
| 834 | if (num_frames_ != 0) { |
| 835 | CHECK_EQ(cur_depth_, num_frames_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 839 | void JavaFrameRootInfo::Describe(std::ostream& os) const { |
| 840 | const StackVisitor* visitor = stack_visitor_; |
| 841 | CHECK(visitor != nullptr); |
| 842 | os << "Type=" << GetType() << " thread_id=" << GetThreadId() << " location=" << |
| 843 | visitor->DescribeLocation() << " vreg=" << vreg_; |
| 844 | } |
| 845 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 846 | } // namespace art |