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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_STACK_H_ |
| 18 | #define ART_RUNTIME_STACK_H_ |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 21 | #include <string> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 22 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 23 | #include "arch/instruction_set.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 24 | #include "dex_file.h" |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 25 | #include "gc_root.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 26 | #include "mirror/object_reference.h" |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 27 | #include "read_barrier.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 28 | #include "utils.h" |
| 29 | #include "verify_object.h" |
| 30 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 31 | namespace art { |
| 32 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | namespace mirror { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 34 | class ArtMethod; |
| 35 | class Object; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | } // namespace mirror |
| 37 | |
| 38 | class Context; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 39 | class HandleScope; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 40 | class InlineInfo; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 41 | class ScopedObjectAccess; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 42 | class ShadowFrame; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 43 | class StackVisitor; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 44 | class Thread; |
| 45 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 46 | // The kind of vreg being accessed in calls to Set/GetVReg. |
| 47 | enum VRegKind { |
| 48 | kReferenceVReg, |
| 49 | kIntVReg, |
| 50 | kFloatVReg, |
| 51 | kLongLoVReg, |
| 52 | kLongHiVReg, |
| 53 | kDoubleLoVReg, |
| 54 | kDoubleHiVReg, |
| 55 | kConstant, |
| 56 | kImpreciseConstant, |
| 57 | kUndefined, |
| 58 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 59 | std::ostream& operator<<(std::ostream& os, const VRegKind& rhs); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 60 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 61 | // A reference from the shadow stack to a MirrorType object within the Java heap. |
| 62 | template<class MirrorType> |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 63 | class MANAGED StackReference : public mirror::CompressedReference<MirrorType> { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 66 | // ShadowFrame has 2 possible layouts: |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 67 | // - interpreter - separate VRegs and reference arrays. References are in the reference array. |
| 68 | // - JNI - just VRegs, but where every VReg holds a reference. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 69 | class ShadowFrame { |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 70 | public: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 71 | // Compute size of ShadowFrame in bytes assuming it has a reference array. |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 72 | static size_t ComputeSize(uint32_t num_vregs) { |
| 73 | return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) + |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 74 | (sizeof(StackReference<mirror::Object>) * num_vregs); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // Create ShadowFrame in heap for deoptimization. |
Christopher Ferris | 241a958 | 2015-04-27 15:19:41 -0700 | [diff] [blame] | 78 | static ShadowFrame* CreateDeoptimizedFrame(uint32_t num_vregs, ShadowFrame* link, |
| 79 | mirror::ArtMethod* method, uint32_t dex_pc) { |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 80 | uint8_t* memory = new uint8_t[ComputeSize(num_vregs)]; |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 81 | return Create(num_vregs, link, method, dex_pc, memory); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Christopher Ferris | 241a958 | 2015-04-27 15:19:41 -0700 | [diff] [blame] | 84 | // Delete a ShadowFrame allocated on the heap for deoptimization. |
| 85 | static void DeleteDeoptimizedFrame(ShadowFrame* sf) { |
| 86 | uint8_t* memory = reinterpret_cast<uint8_t*>(sf); |
| 87 | delete[] memory; |
| 88 | } |
| 89 | |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 90 | // Create ShadowFrame for interpreter using provided memory. |
| 91 | static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 92 | mirror::ArtMethod* method, uint32_t dex_pc, void* memory) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 93 | ShadowFrame* sf = new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true); |
| 94 | return sf; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 95 | } |
| 96 | ~ShadowFrame() {} |
| 97 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 98 | bool HasReferenceArray() const { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 99 | return true; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 100 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 101 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 102 | uint32_t NumberOfVRegs() const { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 103 | return number_of_vregs_; |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 106 | uint32_t GetDexPC() const { |
| 107 | return dex_pc_; |
| 108 | } |
| 109 | |
| 110 | void SetDexPC(uint32_t dex_pc) { |
| 111 | dex_pc_ = dex_pc; |
| 112 | } |
| 113 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 114 | ShadowFrame* GetLink() const { |
| 115 | return link_; |
| 116 | } |
| 117 | |
| 118 | void SetLink(ShadowFrame* frame) { |
| 119 | DCHECK_NE(this, frame); |
| 120 | link_ = frame; |
| 121 | } |
| 122 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 123 | int32_t GetVReg(size_t i) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 124 | DCHECK_LT(i, NumberOfVRegs()); |
| 125 | const uint32_t* vreg = &vregs_[i]; |
| 126 | return *reinterpret_cast<const int32_t*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | float GetVRegFloat(size_t i) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 130 | DCHECK_LT(i, NumberOfVRegs()); |
| 131 | // NOTE: Strict-aliasing? |
| 132 | const uint32_t* vreg = &vregs_[i]; |
| 133 | return *reinterpret_cast<const float*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | int64_t GetVRegLong(size_t i) const { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 137 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 138 | const uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 139 | // Alignment attribute required for GCC 4.8 |
| 140 | typedef const int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 141 | return *reinterpret_cast<unaligned_int64*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | double GetVRegDouble(size_t i) const { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 145 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 146 | const uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 147 | // Alignment attribute required for GCC 4.8 |
| 148 | typedef const double unaligned_double __attribute__ ((aligned (4))); |
| 149 | return *reinterpret_cast<unaligned_double*>(vreg); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 152 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 153 | mirror::Object* GetVRegReference(size_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 154 | DCHECK_LT(i, NumberOfVRegs()); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 155 | mirror::Object* ref; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 156 | if (HasReferenceArray()) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 157 | ref = References()[i].AsMirrorPtr(); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 158 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 159 | const uint32_t* vreg_ptr = &vregs_[i]; |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 160 | ref = reinterpret_cast<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr(); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 161 | } |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 162 | if (kUseReadBarrier) { |
| 163 | ReadBarrier::AssertToSpaceInvariant(ref); |
| 164 | } |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 165 | if (kVerifyFlags & kVerifyReads) { |
| 166 | VerifyObject(ref); |
| 167 | } |
| 168 | return ref; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 171 | // Get view of vregs as range of consecutive arguments starting at i. |
| 172 | uint32_t* GetVRegArgs(size_t i) { |
| 173 | return &vregs_[i]; |
| 174 | } |
| 175 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 176 | void SetVReg(size_t i, int32_t val) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 177 | DCHECK_LT(i, NumberOfVRegs()); |
| 178 | uint32_t* vreg = &vregs_[i]; |
| 179 | *reinterpret_cast<int32_t*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 180 | // This is needed for moving collectors since these can update the vreg references if they |
| 181 | // happen to agree with references in the reference array. |
| 182 | if (kMovingCollector && HasReferenceArray()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 183 | References()[i].Clear(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 184 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void SetVRegFloat(size_t i, float val) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 188 | DCHECK_LT(i, NumberOfVRegs()); |
| 189 | uint32_t* vreg = &vregs_[i]; |
| 190 | *reinterpret_cast<float*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 191 | // This is needed for moving collectors since these can update the vreg references if they |
| 192 | // happen to agree with references in the reference array. |
| 193 | if (kMovingCollector && HasReferenceArray()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 194 | References()[i].Clear(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 195 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void SetVRegLong(size_t i, int64_t val) { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 199 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 200 | uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 201 | // Alignment attribute required for GCC 4.8 |
| 202 | typedef int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 203 | *reinterpret_cast<unaligned_int64*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 204 | // This is needed for moving collectors since these can update the vreg references if they |
| 205 | // happen to agree with references in the reference array. |
| 206 | if (kMovingCollector && HasReferenceArray()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 207 | References()[i].Clear(); |
| 208 | References()[i + 1].Clear(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 209 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void SetVRegDouble(size_t i, double val) { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 213 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 214 | uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 215 | // Alignment attribute required for GCC 4.8 |
| 216 | typedef double unaligned_double __attribute__ ((aligned (4))); |
| 217 | *reinterpret_cast<unaligned_double*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 218 | // This is needed for moving collectors since these can update the vreg references if they |
| 219 | // happen to agree with references in the reference array. |
| 220 | if (kMovingCollector && HasReferenceArray()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 221 | References()[i].Clear(); |
| 222 | References()[i + 1].Clear(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 223 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 226 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 227 | void SetVRegReference(size_t i, mirror::Object* val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 228 | DCHECK_LT(i, NumberOfVRegs()); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 229 | if (kVerifyFlags & kVerifyWrites) { |
| 230 | VerifyObject(val); |
| 231 | } |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 232 | if (kUseReadBarrier) { |
| 233 | ReadBarrier::AssertToSpaceInvariant(val); |
| 234 | } |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 235 | uint32_t* vreg = &vregs_[i]; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 236 | reinterpret_cast<StackReference<mirror::Object>*>(vreg)->Assign(val); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 237 | if (HasReferenceArray()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 238 | References()[i].Assign(val); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 239 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 242 | mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 243 | DCHECK(method_ != nullptr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 244 | return method_; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Hiroshi Yamauchi | 92d1a66 | 2014-05-15 21:43:59 -0700 | [diff] [blame] | 247 | mirror::ArtMethod** GetMethodAddress() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 248 | DCHECK(method_ != nullptr); |
| 249 | return &method_; |
| 250 | } |
| 251 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 252 | mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 253 | |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 254 | mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 255 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 256 | bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 257 | if (HasReferenceArray()) { |
| 258 | return ((&References()[0] <= shadow_frame_entry_obj) && |
| 259 | (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1]))); |
| 260 | } else { |
| 261 | uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj); |
| 262 | return ((&vregs_[0] <= shadow_frame_entry) && |
| 263 | (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1]))); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 264 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 267 | static size_t LinkOffset() { |
| 268 | return OFFSETOF_MEMBER(ShadowFrame, link_); |
| 269 | } |
| 270 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 271 | static size_t MethodOffset() { |
| 272 | return OFFSETOF_MEMBER(ShadowFrame, method_); |
| 273 | } |
| 274 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 275 | static size_t DexPCOffset() { |
| 276 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
| 277 | } |
| 278 | |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 279 | static size_t NumberOfVRegsOffset() { |
| 280 | return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_); |
| 281 | } |
| 282 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 283 | static size_t VRegsOffset() { |
| 284 | return OFFSETOF_MEMBER(ShadowFrame, vregs_); |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 287 | private: |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 288 | ShadowFrame(uint32_t num_vregs, ShadowFrame* link, mirror::ArtMethod* method, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 289 | uint32_t dex_pc, bool has_reference_array) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 290 | : number_of_vregs_(num_vregs), link_(link), method_(method), dex_pc_(dex_pc) { |
| 291 | if (has_reference_array) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 292 | memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>))); |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 293 | } else { |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 294 | memset(vregs_, 0, num_vregs * sizeof(uint32_t)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 297 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 298 | const StackReference<mirror::Object>* References() const { |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 299 | DCHECK(HasReferenceArray()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 300 | const uint32_t* vreg_end = &vregs_[NumberOfVRegs()]; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 301 | return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 304 | StackReference<mirror::Object>* References() { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 305 | return const_cast<StackReference<mirror::Object>*>( |
| 306 | const_cast<const ShadowFrame*>(this)->References()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 309 | const uint32_t number_of_vregs_; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 310 | // Link to previous shadow frame or null. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 311 | ShadowFrame* link_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 312 | mirror::ArtMethod* method_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 313 | uint32_t dex_pc_; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 314 | uint32_t vregs_[0]; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 315 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 316 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 319 | class JavaFrameRootInfo : public RootInfo { |
| 320 | public: |
| 321 | JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg) |
| 322 | : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) { |
| 323 | } |
| 324 | virtual void Describe(std::ostream& os) const OVERRIDE |
| 325 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 326 | |
| 327 | private: |
| 328 | const StackVisitor* const stack_visitor_; |
| 329 | const size_t vreg_; |
| 330 | }; |
| 331 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 332 | // The managed stack is used to record fragments of managed code stacks. Managed code stacks |
| 333 | // may either be shadow frames or lists of frames using fixed frame sizes. Transition records are |
| 334 | // necessary for transitions between code using different frame layouts and transitions into native |
| 335 | // code. |
Ian Rogers | df1ce91 | 2012-11-27 17:07:11 -0800 | [diff] [blame] | 336 | class PACKED(4) ManagedStack { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 337 | public: |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 338 | ManagedStack() |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 339 | : top_quick_frame_(nullptr), link_(nullptr), top_shadow_frame_(nullptr) {} |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 340 | |
| 341 | void PushManagedStackFragment(ManagedStack* fragment) { |
| 342 | // Copy this top fragment into given fragment. |
| 343 | memcpy(fragment, this, sizeof(ManagedStack)); |
| 344 | // Clear this fragment, which has become the top. |
| 345 | memset(this, 0, sizeof(ManagedStack)); |
| 346 | // Link our top fragment onto the given fragment. |
| 347 | link_ = fragment; |
| 348 | } |
| 349 | |
| 350 | void PopManagedStackFragment(const ManagedStack& fragment) { |
| 351 | DCHECK(&fragment == link_); |
| 352 | // Copy this given fragment back to the top. |
| 353 | memcpy(this, &fragment, sizeof(ManagedStack)); |
| 354 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 355 | |
| 356 | ManagedStack* GetLink() const { |
| 357 | return link_; |
| 358 | } |
| 359 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 360 | StackReference<mirror::ArtMethod>* GetTopQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 361 | return top_quick_frame_; |
| 362 | } |
| 363 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 364 | void SetTopQuickFrame(StackReference<mirror::ArtMethod>* top) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 365 | DCHECK(top_shadow_frame_ == nullptr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 366 | top_quick_frame_ = top; |
| 367 | } |
| 368 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 369 | static size_t TopQuickFrameOffset() { |
| 370 | return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_); |
| 371 | } |
| 372 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 373 | ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 374 | DCHECK(top_quick_frame_ == nullptr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 375 | ShadowFrame* old_frame = top_shadow_frame_; |
| 376 | top_shadow_frame_ = new_top_frame; |
| 377 | new_top_frame->SetLink(old_frame); |
| 378 | return old_frame; |
| 379 | } |
| 380 | |
| 381 | ShadowFrame* PopShadowFrame() { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 382 | DCHECK(top_quick_frame_ == nullptr); |
| 383 | CHECK(top_shadow_frame_ != nullptr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 384 | ShadowFrame* frame = top_shadow_frame_; |
| 385 | top_shadow_frame_ = frame->GetLink(); |
| 386 | return frame; |
| 387 | } |
| 388 | |
| 389 | ShadowFrame* GetTopShadowFrame() const { |
| 390 | return top_shadow_frame_; |
| 391 | } |
| 392 | |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 393 | void SetTopShadowFrame(ShadowFrame* top) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 394 | DCHECK(top_quick_frame_ == nullptr); |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 395 | top_shadow_frame_ = top; |
| 396 | } |
| 397 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 398 | static size_t TopShadowFrameOffset() { |
| 399 | return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_); |
| 400 | } |
| 401 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 402 | size_t NumJniShadowFrameReferences() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 403 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 404 | bool ShadowFramesContain(StackReference<mirror::Object>* shadow_frame_entry) const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 405 | |
| 406 | private: |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 407 | StackReference<mirror::ArtMethod>* top_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 408 | ManagedStack* link_; |
| 409 | ShadowFrame* top_shadow_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | class StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 413 | public: |
| 414 | // This enum defines a flag to control whether inlined frames are included |
| 415 | // when walking the stack. |
| 416 | enum class StackWalkKind { |
| 417 | kIncludeInlinedFrames, |
| 418 | kSkipInlinedFrames, |
| 419 | }; |
| 420 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 421 | protected: |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 422 | StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind) |
| 423 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 424 | |
| 425 | public: |
| 426 | virtual ~StackVisitor() {} |
| 427 | |
| 428 | // Return 'true' if we should continue to visit more frames, 'false' to stop. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 429 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 430 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 431 | void WalkStack(bool include_transitions = false) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 432 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 433 | |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 434 | mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 92d1a66 | 2014-05-15 21:43:59 -0700 | [diff] [blame] | 435 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 436 | bool IsShadowFrame() const { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 437 | return cur_shadow_frame_ != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 440 | uint32_t GetDexPc(bool abort_on_failure = true) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 441 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 442 | mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 443 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 444 | size_t GetNativePcOffset() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 445 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 446 | uintptr_t* CalleeSaveAddress(int num, size_t frame_size) const |
| 447 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 448 | // Callee saves are held at the top of the frame |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 449 | DCHECK(GetMethod() != nullptr); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 450 | uint8_t* save_addr = |
| 451 | reinterpret_cast<uint8_t*>(cur_quick_frame_) + frame_size - ((num + 1) * sizeof(void*)); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 452 | #if defined(__i386__) || defined(__x86_64__) |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 453 | save_addr -= sizeof(void*); // account for return address |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 454 | #endif |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 455 | return reinterpret_cast<uintptr_t*>(save_addr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 458 | // Returns the height of the stack in the managed stack frames, including transitions. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 459 | size_t GetFrameHeight() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 460 | return GetNumFrames() - cur_depth_ - 1; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 463 | // Returns a frame ID for JDWP use, starting from 1. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 464 | size_t GetFrameId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 465 | return GetFrameHeight() + 1; |
| 466 | } |
| 467 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 468 | size_t GetNumFrames() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 469 | if (num_frames_ == 0) { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 470 | num_frames_ = ComputeNumFrames(thread_, walk_kind_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 471 | } |
| 472 | return num_frames_; |
| 473 | } |
| 474 | |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 475 | size_t GetFrameDepth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 476 | return cur_depth_; |
| 477 | } |
| 478 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 479 | // Get the method and dex pc immediately after the one that's currently being visited. |
| 480 | bool GetNextMethodAndDexPc(mirror::ArtMethod** next_method, uint32_t* next_dex_pc) |
| 481 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 482 | |
Mathieu Chartier | 50030ef | 2015-05-08 14:19:26 -0700 | [diff] [blame] | 483 | bool IsReferenceVReg(mirror::ArtMethod* m, uint16_t vreg) |
| 484 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 485 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 486 | bool GetVReg(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, uint32_t* val) const |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 487 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 488 | |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 489 | bool GetVRegPair(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi, |
| 490 | uint64_t* val) const |
| 491 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 492 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 493 | bool SetVReg(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 494 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 495 | |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 496 | bool SetVRegPair(mirror::ArtMethod* m, uint16_t vreg, uint64_t new_value, |
| 497 | VRegKind kind_lo, VRegKind kind_hi) |
| 498 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 499 | |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 500 | uintptr_t* GetGPRAddress(uint32_t reg) const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 501 | |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 502 | // This is a fast-path for getting/setting values in a quick frame. |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 503 | uint32_t* GetVRegAddrFromQuickCode(StackReference<mirror::ArtMethod>* cur_quick_frame, |
| 504 | const DexFile::CodeItem* code_item, |
| 505 | uint32_t core_spills, uint32_t fp_spills, size_t frame_size, |
| 506 | uint16_t vreg) const { |
| 507 | int offset = GetVRegOffsetFromQuickCode( |
| 508 | code_item, core_spills, fp_spills, frame_size, vreg, kRuntimeISA); |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 509 | DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame()); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 510 | uint8_t* vreg_addr = reinterpret_cast<uint8_t*>(cur_quick_frame) + offset; |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 511 | return reinterpret_cast<uint32_t*>(vreg_addr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 514 | uintptr_t GetReturnPc() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 515 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 516 | void SetReturnPc(uintptr_t new_ret_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * Return sp-relative offset for a Dalvik virtual register, compiler |
| 520 | * spill or Method* in bytes using Method*. |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 521 | * Note that (reg == -1) denotes an invalid Dalvik register. For the |
| 522 | * positive values, the Dalvik registers come first, followed by the |
| 523 | * Method*, followed by other special temporaries if any, followed by |
| 524 | * regular compiler temporary. As of now we only have the Method* as |
| 525 | * as a special compiler temporary. |
| 526 | * A compiler temporary can be thought of as a virtual register that |
| 527 | * does not exist in the dex but holds intermediate values to help |
| 528 | * optimizations and code generation. A special compiler temporary is |
| 529 | * one whose location in frame is well known while non-special ones |
| 530 | * do not have a requirement on location in frame as long as code |
| 531 | * generator itself knows how to access them. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 532 | * |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 533 | * +-------------------------------+ |
| 534 | * | IN[ins-1] | {Note: resides in caller's frame} |
| 535 | * | . | |
| 536 | * | IN[0] | |
| 537 | * | caller's ArtMethod | ... StackReference<ArtMethod> |
| 538 | * +===============================+ {Note: start of callee's frame} |
| 539 | * | core callee-save spill | {variable sized} |
| 540 | * +-------------------------------+ |
| 541 | * | fp callee-save spill | |
| 542 | * +-------------------------------+ |
| 543 | * | filler word | {For compatibility, if V[locals-1] used as wide |
| 544 | * +-------------------------------+ |
| 545 | * | V[locals-1] | |
| 546 | * | V[locals-2] | |
| 547 | * | . | |
| 548 | * | . | ... (reg == 2) |
| 549 | * | V[1] | ... (reg == 1) |
| 550 | * | V[0] | ... (reg == 0) <---- "locals_start" |
| 551 | * +-------------------------------+ |
| 552 | * | stack alignment padding | {0 to (kStackAlignWords-1) of padding} |
| 553 | * +-------------------------------+ |
| 554 | * | Compiler temp region | ... (reg >= max_num_special_temps) |
| 555 | * | . | |
| 556 | * | . | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 557 | * | V[max_num_special_temps + 1] | |
| 558 | * | V[max_num_special_temps + 0] | |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 559 | * +-------------------------------+ |
| 560 | * | OUT[outs-1] | |
| 561 | * | OUT[outs-2] | |
| 562 | * | . | |
| 563 | * | OUT[0] | |
| 564 | * | StackReference<ArtMethod> | ... (reg == num_total_code_regs == special_temp_value) <<== sp, 16-byte aligned |
| 565 | * +===============================+ |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 566 | */ |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 567 | static int GetVRegOffsetFromQuickCode(const DexFile::CodeItem* code_item, |
| 568 | uint32_t core_spills, uint32_t fp_spills, |
| 569 | size_t frame_size, int reg, InstructionSet isa) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 570 | DCHECK_EQ(frame_size & (kStackAlignment - 1), 0U); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 571 | DCHECK_NE(reg, -1); |
Vladimir Marko | 8194963 | 2014-05-02 11:53:22 +0100 | [diff] [blame] | 572 | int spill_size = POPCOUNT(core_spills) * GetBytesPerGprSpillLocation(isa) |
| 573 | + POPCOUNT(fp_spills) * GetBytesPerFprSpillLocation(isa) |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 574 | + sizeof(uint32_t); // Filler. |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 575 | int num_regs = code_item->registers_size_ - code_item->ins_size_; |
| 576 | int temp_threshold = code_item->registers_size_; |
| 577 | const int max_num_special_temps = 1; |
| 578 | if (reg == temp_threshold) { |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 579 | // The current method pointer corresponds to special location on stack. |
| 580 | return 0; |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 581 | } else if (reg >= temp_threshold + max_num_special_temps) { |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 582 | /* |
| 583 | * Special temporaries may have custom locations and the logic above deals with that. |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 584 | * However, non-special temporaries are placed relative to the outs. |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 585 | */ |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 586 | int temps_start = sizeof(StackReference<mirror::ArtMethod>) + |
| 587 | code_item->outs_size_ * sizeof(uint32_t); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 588 | int relative_offset = (reg - (temp_threshold + max_num_special_temps)) * sizeof(uint32_t); |
| 589 | return temps_start + relative_offset; |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 590 | } else if (reg < num_regs) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 591 | int locals_start = frame_size - spill_size - num_regs * sizeof(uint32_t); |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 592 | return locals_start + (reg * sizeof(uint32_t)); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 593 | } else { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 594 | // Handle ins. |
buzbee | 8281864 | 2014-06-04 15:35:41 -0700 | [diff] [blame] | 595 | return frame_size + ((reg - num_regs) * sizeof(uint32_t)) + |
| 596 | sizeof(StackReference<mirror::ArtMethod>); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 600 | static int GetOutVROffset(uint16_t out_num, InstructionSet isa) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 601 | UNUSED(isa); |
buzbee | 8281864 | 2014-06-04 15:35:41 -0700 | [diff] [blame] | 602 | // According to stack model, the first out is above the Method referernce. |
| 603 | return sizeof(StackReference<mirror::ArtMethod>) + (out_num * sizeof(uint32_t)); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 606 | bool IsInInlinedFrame() const { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 607 | return current_inlining_depth_ != 0; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 608 | } |
| 609 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 610 | uintptr_t GetCurrentQuickFramePc() const { |
| 611 | return cur_quick_frame_pc_; |
| 612 | } |
| 613 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 614 | StackReference<mirror::ArtMethod>* GetCurrentQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 615 | return cur_quick_frame_; |
| 616 | } |
| 617 | |
| 618 | ShadowFrame* GetCurrentShadowFrame() const { |
| 619 | return cur_shadow_frame_; |
| 620 | } |
| 621 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 622 | HandleScope* GetCurrentHandleScope() const { |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 623 | StackReference<mirror::ArtMethod>* sp = GetCurrentQuickFrame(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 624 | ++sp; // Skip Method*; handle scope comes next; |
| 625 | return reinterpret_cast<HandleScope*>(sp); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 628 | std::string DescribeLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 629 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 630 | static size_t ComputeNumFrames(Thread* thread, StackWalkKind walk_kind) |
| 631 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 632 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 633 | static void DescribeStack(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 634 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 635 | private: |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 636 | // Private constructor known in the case that num_frames_ has already been computed. |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 637 | StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind, size_t num_frames) |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 638 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 639 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 640 | bool IsAccessibleRegister(uint32_t reg, bool is_float) const { |
| 641 | return is_float ? IsAccessibleFPR(reg) : IsAccessibleGPR(reg); |
| 642 | } |
| 643 | uintptr_t GetRegister(uint32_t reg, bool is_float) const { |
| 644 | DCHECK(IsAccessibleRegister(reg, is_float)); |
| 645 | return is_float ? GetFPR(reg) : GetGPR(reg); |
| 646 | } |
| 647 | void SetRegister(uint32_t reg, uintptr_t value, bool is_float) { |
| 648 | DCHECK(IsAccessibleRegister(reg, is_float)); |
| 649 | if (is_float) { |
| 650 | SetFPR(reg, value); |
| 651 | } else { |
| 652 | SetGPR(reg, value); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | bool IsAccessibleGPR(uint32_t reg) const; |
| 657 | uintptr_t GetGPR(uint32_t reg) const; |
| 658 | void SetGPR(uint32_t reg, uintptr_t value); |
| 659 | |
| 660 | bool IsAccessibleFPR(uint32_t reg) const; |
| 661 | uintptr_t GetFPR(uint32_t reg) const; |
| 662 | void SetFPR(uint32_t reg, uintptr_t value); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 663 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 664 | bool GetVRegFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, |
| 665 | uint32_t* val) const |
| 666 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 667 | bool GetVRegFromOptimizedCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, |
| 668 | uint32_t* val) const |
| 669 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 670 | bool GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const |
| 671 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 672 | |
| 673 | bool GetVRegPairFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo, |
| 674 | VRegKind kind_hi, uint64_t* val) const |
| 675 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 676 | bool GetVRegPairFromOptimizedCode(mirror::ArtMethod* m, uint16_t vreg, |
| 677 | VRegKind kind_lo, VRegKind kind_hi, |
| 678 | uint64_t* val) const |
| 679 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 680 | bool GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, VRegKind kind_lo, |
| 681 | uint64_t* val) const |
| 682 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 683 | |
| 684 | bool SetVRegFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, |
| 685 | VRegKind kind) |
| 686 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 687 | bool SetRegisterIfAccessible(uint32_t reg, uint32_t new_value, VRegKind kind) |
| 688 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 689 | |
| 690 | bool SetVRegPairFromQuickCode(mirror::ArtMethod* m, uint16_t vreg, uint64_t new_value, |
| 691 | VRegKind kind_lo, VRegKind kind_hi) |
| 692 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 693 | bool SetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, uint64_t new_value, |
| 694 | bool is_float) |
| 695 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 696 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 697 | void SanityCheckFrame() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 698 | |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 699 | InlineInfo GetCurrentInlineInfo() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 700 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 701 | Thread* const thread_; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 702 | const StackWalkKind walk_kind_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 703 | ShadowFrame* cur_shadow_frame_; |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 704 | StackReference<mirror::ArtMethod>* cur_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 705 | uintptr_t cur_quick_frame_pc_; |
| 706 | // Lazily computed, number of frames in the stack. |
| 707 | size_t num_frames_; |
| 708 | // Depth of the frame we're currently at. |
| 709 | size_t cur_depth_; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame^] | 710 | // Current inlining depth of the method we are currently at. |
| 711 | // 0 if there is no inlined frame. |
| 712 | size_t current_inlining_depth_; |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 713 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 714 | protected: |
| 715 | Context* const context_; |
| 716 | }; |
| 717 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 718 | } // namespace art |
| 719 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 720 | #endif // ART_RUNTIME_STACK_H_ |