OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
7 | 7 |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 void CodePatcher::PatchInstanceCallAt(uword return_address, | 15 void CodePatcher::PatchInstanceCallAt(uword return_address, |
16 const Code& code, | 16 const Code& code, |
17 uword new_target) { | 17 uword new_target) { |
18 ASSERT(code.ContainsInstructionAt(return_address)); | 18 ASSERT(code.ContainsInstructionAt(return_address)); |
19 CallPattern call(return_address, code); | 19 CallPattern call(return_address, code); |
20 call.SetTargetAddress(new_target); | 20 call.SetTargetAddress(new_target); |
21 } | 21 } |
22 | 22 |
23 | 23 |
24 class PoolPointerCall : public ValueObject { | 24 class PoolPointerCall : public ValueObject { |
25 public: | 25 public: |
26 PoolPointerCall(uword pc, const Code& code) | 26 PoolPointerCall(uword pc, const Code& code) |
27 : end_(pc), | 27 : end_(pc), |
28 object_pool_(Array::Handle(code.ObjectPool())) { | 28 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { |
29 // Last instruction: blr ip0. | 29 // Last instruction: blr ip0. |
30 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); | 30 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); |
31 InstructionPattern::DecodeLoadWordFromPool( | 31 InstructionPattern::DecodeLoadWordFromPool( |
32 end_ - Instr::kInstrSize, ®_, &index_); | 32 end_ - Instr::kInstrSize, ®_, &index_); |
33 } | 33 } |
34 | 34 |
35 intptr_t pp_index() const { | 35 intptr_t pp_index() const { |
36 return index_; | 36 return index_; |
37 } | 37 } |
38 | 38 |
39 uword Target() const { | 39 uword Target() const { |
40 return reinterpret_cast<uword>(object_pool_.At(pp_index())); | 40 return reinterpret_cast<uword>(object_pool_.RawValueAt(pp_index())); |
41 } | 41 } |
42 | 42 |
43 void SetTarget(uword target) const { | 43 void SetTarget(uword target) const { |
44 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target)); | 44 object_pool_.SetRawValueAt(pp_index(), target); |
45 object_pool_.SetAt(pp_index(), smi); | |
46 // No need to flush the instruction cache, since the code is not modified. | 45 // No need to flush the instruction cache, since the code is not modified. |
47 } | 46 } |
48 | 47 |
49 private: | 48 private: |
50 static const int kCallPatternSize = 3 * Instr::kInstrSize; | 49 static const int kCallPatternSize = 3 * Instr::kInstrSize; |
51 uword end_; | 50 uword end_; |
52 const Array& object_pool_; | 51 const ObjectPool& object_pool_; |
53 Register reg_; | 52 Register reg_; |
54 intptr_t index_; | 53 intptr_t index_; |
55 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); | 54 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); |
56 }; | 55 }; |
57 | 56 |
58 | 57 |
59 uword CodePatcher::GetStaticCallTargetAt(uword return_address, | 58 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
60 const Code& code) { | 59 const Code& code) { |
61 ASSERT(code.ContainsInstructionAt(return_address)); | 60 ASSERT(code.ContainsInstructionAt(return_address)); |
62 PoolPointerCall call(return_address, code); | 61 PoolPointerCall call(return_address, code); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 118 } |
120 | 119 |
121 | 120 |
122 // This class pattern matches on a load from the object pool. Loading on | 121 // This class pattern matches on a load from the object pool. Loading on |
123 // ARM64 is complicated because it can take more than one form. We | 122 // ARM64 is complicated because it can take more than one form. We |
124 // match backwards from the end of the sequence so we can reuse the code for | 123 // match backwards from the end of the sequence so we can reuse the code for |
125 // matching object pool loads at calls. | 124 // matching object pool loads at calls. |
126 class EdgeCounter : public ValueObject { | 125 class EdgeCounter : public ValueObject { |
127 public: | 126 public: |
128 EdgeCounter(uword pc, const Code& code) | 127 EdgeCounter(uword pc, const Code& code) |
129 : end_(pc - kAdjust), object_pool_(Array::Handle(code.ObjectPool())) { | 128 : end_(pc - kAdjust), |
| 129 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { |
130 // An IsValid predicate is complicated and duplicates the code in the | 130 // An IsValid predicate is complicated and duplicates the code in the |
131 // decoding function. Instead we rely on decoding the pattern which | 131 // decoding function. Instead we rely on decoding the pattern which |
132 // will assert partial validity. | 132 // will assert partial validity. |
133 } | 133 } |
134 | 134 |
135 RawObject* edge_counter() const { | 135 RawObject* edge_counter() const { |
136 Register ignored; | 136 Register ignored; |
137 intptr_t index; | 137 intptr_t index; |
138 InstructionPattern::DecodeLoadWordFromPool(end_, &ignored, &index); | 138 InstructionPattern::DecodeLoadWordFromPool(end_, &ignored, &index); |
139 ASSERT(ignored == R0); | 139 ASSERT(ignored == R0); |
140 return object_pool_.At(index); | 140 return object_pool_.ObjectAt(index); |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 // The object pool load is followed by the fixed-size edge counter | 144 // The object pool load is followed by the fixed-size edge counter |
145 // incrementing code: | 145 // incrementing code: |
146 // ldr ip, [r0, #+11] | 146 // ldr ip, [r0, #+11] |
147 // adds ip, ip, #2 | 147 // adds ip, ip, #2 |
148 // str ip, [r0, #+11] | 148 // str ip, [r0, #+11] |
149 static const intptr_t kAdjust = 3 * Instr::kInstrSize; | 149 static const intptr_t kAdjust = 3 * Instr::kInstrSize; |
150 | 150 |
151 uword end_; | 151 uword end_; |
152 const Array& object_pool_; | 152 const ObjectPool& object_pool_; |
153 }; | 153 }; |
154 | 154 |
155 | 155 |
156 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | 156 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
157 ASSERT(code.ContainsInstructionAt(pc)); | 157 ASSERT(code.ContainsInstructionAt(pc)); |
158 EdgeCounter counter(pc, code); | 158 EdgeCounter counter(pc, code); |
159 return counter.edge_counter(); | 159 return counter.edge_counter(); |
160 } | 160 } |
161 | 161 |
162 } // namespace dart | 162 } // namespace dart |
163 | 163 |
164 #endif // defined TARGET_ARCH_ARM64 | 164 #endif // defined TARGET_ARCH_ARM64 |
OLD | NEW |