OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 uword call_address() const { | 134 uword call_address() const { |
135 return start_; | 135 return start_; |
136 } | 136 } |
137 | 137 |
138 uword start_; | 138 uword start_; |
139 | 139 |
140 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); | 140 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); |
141 }; | 141 }; |
142 | 142 |
143 | 143 |
| 144 // The expected pattern of a dart closure call: |
| 145 // mov EDX, arguments_descriptor_array |
| 146 // call target_address |
| 147 // <- return address |
| 148 class ClosureCall : public ValueObject { |
| 149 public: |
| 150 explicit ClosureCall(uword return_address) |
| 151 : start_(return_address - (kInstr1Size + kInstr2Size)) { |
| 152 ASSERT(IsValid(return_address)); |
| 153 ASSERT(kInstr2Size == Assembler::kCallExternalLabelSize); |
| 154 } |
| 155 |
| 156 static bool IsValid(uword return_address) { |
| 157 uint8_t* code_bytes = reinterpret_cast<uint8_t*>( |
| 158 return_address - (kInstr1Size + kInstr2Size)); |
| 159 return (code_bytes[0] == 0xBA) && (code_bytes[kInstr1Size] == 0xE8); |
| 160 } |
| 161 |
| 162 RawArray* arguments_descriptor() const { |
| 163 return *reinterpret_cast<RawArray**>(start_ + 1); |
| 164 } |
| 165 |
| 166 private: |
| 167 static const int kInstr1Size = 5; // mov EDX, arguments descriptor array |
| 168 static const int kInstr2Size = 5; // call stub |
| 169 |
| 170 uword return_address() const { |
| 171 return start_ + kInstr1Size + kInstr2Size; |
| 172 } |
| 173 uword call_address() const { return start_; } |
| 174 |
| 175 uword start_; |
| 176 DISALLOW_IMPLICIT_CONSTRUCTORS(ClosureCall); |
| 177 }; |
| 178 |
| 179 |
| 180 |
| 181 RawArray* CodePatcher::GetClosureArgDescAt(uword return_address, |
| 182 const Code& code) { |
| 183 ASSERT(code.ContainsInstructionAt(return_address)); |
| 184 ClosureCall call(return_address); |
| 185 return call.arguments_descriptor(); |
| 186 } |
| 187 |
| 188 |
144 uword CodePatcher::GetStaticCallTargetAt(uword return_address, | 189 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
145 const Code& code) { | 190 const Code& code) { |
146 ASSERT(code.ContainsInstructionAt(return_address)); | 191 ASSERT(code.ContainsInstructionAt(return_address)); |
147 StaticCall call(return_address); | 192 StaticCall call(return_address); |
148 return call.target(); | 193 return call.target(); |
149 } | 194 } |
150 | 195 |
151 | 196 |
152 void CodePatcher::PatchStaticCallAt(uword return_address, | 197 void CodePatcher::PatchStaticCallAt(uword return_address, |
153 const Code& code, | 198 const Code& code, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 239 } |
195 | 240 |
196 | 241 |
197 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 242 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
198 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; | 243 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; |
199 } | 244 } |
200 | 245 |
201 } // namespace dart | 246 } // namespace dart |
202 | 247 |
203 #endif // defined TARGET_ARCH_IA32 | 248 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |