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_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
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" |
11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
| 12 #include "vm/flow_graph_compiler.h" |
12 #include "vm/instructions.h" | 13 #include "vm/instructions.h" |
13 #include "vm/object.h" | 14 #include "vm/object.h" |
14 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
15 | 16 |
16 namespace dart { | 17 namespace dart { |
17 | 18 |
18 // The expected pattern of a Dart unoptimized call (static and instance): | 19 // The expected pattern of a Dart unoptimized call (static and instance): |
19 // 00: 49 8b 9f imm32 mov RBX, [PP + off] | 20 // 00: 49 8b 9f imm32 mov RBX, [PP + off] |
20 // 07: 4d 8b 9f imm32 mov R11, [PP + off] | 21 // 07: 4d 8b 9f imm32 mov R11, [PP + off] |
21 // 14: 41 ff d3 call R11 | 22 // 14: 41 ff d3 call R11 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 297 } |
297 return ic_data.GetTargetAt(0); | 298 return ic_data.GetTargetAt(0); |
298 } | 299 } |
299 | 300 |
300 | 301 |
301 // The expected code pattern of an edge counter in unoptimized code: | 302 // The expected code pattern of an edge counter in unoptimized code: |
302 // 49 8b 87 imm32 mov RAX, [PP + offset] | 303 // 49 8b 87 imm32 mov RAX, [PP + offset] |
303 class EdgeCounter : public ValueObject { | 304 class EdgeCounter : public ValueObject { |
304 public: | 305 public: |
305 EdgeCounter(uword pc, const Code& code) | 306 EdgeCounter(uword pc, const Code& code) |
306 : end_(pc - kAdjust), object_pool_(Array::Handle(code.ObjectPool())) { | 307 : end_(pc - FlowGraphCompiler::EdgeCounterIncrementSizeInBytes()), |
| 308 object_pool_(Array::Handle(code.ObjectPool())) { |
307 ASSERT(IsValid(end_)); | 309 ASSERT(IsValid(end_)); |
308 } | 310 } |
309 | 311 |
310 static bool IsValid(uword end) { | 312 static bool IsValid(uword end) { |
311 uint8_t* bytes = reinterpret_cast<uint8_t*>(end - 7); | 313 uint8_t* bytes = reinterpret_cast<uint8_t*>(end - 7); |
312 return (bytes[0] == 0x49) && (bytes[1] == 0x8b) && (bytes[2] == 0x87); | 314 return (bytes[0] == 0x49) && (bytes[1] == 0x8b) && (bytes[2] == 0x87); |
313 } | 315 } |
314 | 316 |
315 RawObject* edge_counter() const { | 317 RawObject* edge_counter() const { |
316 return object_pool_.At(InstructionPattern::IndexFromPPLoad(end_ - 4)); | 318 return object_pool_.At(InstructionPattern::IndexFromPPLoad(end_ - 4)); |
317 } | 319 } |
318 | 320 |
319 private: | 321 private: |
320 // The edge counter load is followed by the fixed-size edge counter | |
321 // incrementing code: | |
322 // 48 83 40 17 02 addq [rax+0x17],0x2 | |
323 static const intptr_t kAdjust = 5; | |
324 | |
325 uword end_; | 322 uword end_; |
326 const Array& object_pool_; | 323 const Array& object_pool_; |
327 }; | 324 }; |
328 | 325 |
329 | 326 |
330 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | 327 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
331 ASSERT(code.ContainsInstructionAt(pc)); | 328 ASSERT(code.ContainsInstructionAt(pc)); |
332 EdgeCounter counter(pc, code); | 329 EdgeCounter counter(pc, code); |
333 return counter.edge_counter(); | 330 return counter.edge_counter(); |
334 } | 331 } |
335 | 332 |
336 } // namespace dart | 333 } // namespace dart |
337 | 334 |
338 #endif // defined TARGET_ARCH_X64 | 335 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |