| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 268 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 269 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize; | 269 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize; |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 // The expected code pattern of an edge counter in unoptimized code: | 273 // The expected code pattern of an edge counter in unoptimized code: |
| 274 // b8 imm32 mov EAX, immediate | 274 // b8 imm32 mov EAX, immediate |
| 275 class EdgeCounter : public ValueObject { | 275 class EdgeCounter : public ValueObject { |
| 276 public: | 276 public: |
| 277 EdgeCounter(uword pc, const Code& ignored) : end_(pc - kAdjust) { | 277 EdgeCounter(uword pc, const Code& ignored) |
| 278 : end_(pc - CodePatcher::EdgeCounterIncrementSizeInBytes()) { |
| 278 ASSERT(IsValid(end_)); | 279 ASSERT(IsValid(end_)); |
| 279 } | 280 } |
| 280 | 281 |
| 281 static bool IsValid(uword end) { | 282 static bool IsValid(uword end) { |
| 282 return (*reinterpret_cast<uint8_t*>(end - 5) == 0xb8); | 283 return (*reinterpret_cast<uint8_t*>(end - 5) == 0xb8); |
| 283 } | 284 } |
| 284 | 285 |
| 285 RawObject* edge_counter() const { | 286 RawObject* edge_counter() const { |
| 286 return *reinterpret_cast<RawObject**>(end_ - 4); | 287 return *reinterpret_cast<RawObject**>(end_ - 4); |
| 287 } | 288 } |
| 288 | 289 |
| 289 private: | 290 private: |
| 291 uword end_; |
| 292 }; |
| 293 |
| 294 |
| 295 int32_t CodePatcher::EdgeCounterIncrementSizeInBytes() { |
| 290 // The edge counter load is followed by the fixed-size edge counter | 296 // The edge counter load is followed by the fixed-size edge counter |
| 291 // incrementing code: | 297 // incrementing code: |
| 292 // 83 40 0b 02 add [eax+0xb],0x2 | 298 // 83 40 0b 02 add [eax+0xb],0x2 |
| 293 static const intptr_t kAdjust = 4; | 299 return 4; |
| 294 | 300 } |
| 295 uword end_; | |
| 296 }; | |
| 297 | 301 |
| 298 | 302 |
| 299 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | 303 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
| 300 ASSERT(code.ContainsInstructionAt(pc)); | 304 ASSERT(code.ContainsInstructionAt(pc)); |
| 301 EdgeCounter counter(pc, code); | 305 EdgeCounter counter(pc, code); |
| 302 return counter.edge_counter(); | 306 return counter.edge_counter(); |
| 303 } | 307 } |
| 304 | 308 |
| 305 } // namespace dart | 309 } // namespace dart |
| 306 | 310 |
| 307 #endif // defined TARGET_ARCH_IA32 | 311 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |