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