| 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" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // No need to flush the instruction cache, since the code is not modified. | 135 // No need to flush the instruction cache, since the code is not modified. |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 uword start_; | 139 uword start_; |
| 140 const Array& object_pool_; | 140 const Array& object_pool_; |
| 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); | 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 | 144 |
| 145 // The expected code pattern of a dart closure call: | 145 // The expected code pattern of a Dart closure call: |
| 146 // 00: 49 ba imm64 mov R10, immediate 2 ; 10 bytes | 146 // 00: 49 ba imm64 mov R10, immediate 2 ; 10 bytes |
| 147 // 10: 4d 8b 9f imm32 mov R11, [PP + off] | 147 // 10: 4d 8b 9f imm32 mov R11, [PP + off] |
| 148 // 17: 41 ff d3 call R11 ; 3 bytes | 148 // 17: 41 ff d3 call R11 ; 3 bytes |
| 149 // 20: <- return_address | 149 // 20: <- return_address |
| 150 class ClosureCall : public ValueObject { | 150 class ClosureCall : public ValueObject { |
| 151 public: | 151 public: |
| 152 explicit ClosureCall(uword return_address) | 152 explicit ClosureCall(uword return_address) |
| 153 : start_(return_address - kCallPatternSize) { | 153 : start_(return_address - kCallPatternSize) { |
| 154 ASSERT(IsValid(return_address)); | 154 ASSERT(IsValid(return_address)); |
| 155 } | 155 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ASSERT(code.ContainsInstructionAt(return_address)); | 241 ASSERT(code.ContainsInstructionAt(return_address)); |
| 242 UnoptimizedStaticCall static_call(return_address, code); | 242 UnoptimizedStaticCall static_call(return_address, code); |
| 243 ICData& ic_data = ICData::Handle(); | 243 ICData& ic_data = ICData::Handle(); |
| 244 ic_data ^= static_call.ic_data(); | 244 ic_data ^= static_call.ic_data(); |
| 245 if (ic_data_result != NULL) { | 245 if (ic_data_result != NULL) { |
| 246 *ic_data_result = ic_data.raw(); | 246 *ic_data_result = ic_data.raw(); |
| 247 } | 247 } |
| 248 return ic_data.GetTargetAt(0); | 248 return ic_data.GetTargetAt(0); |
| 249 } | 249 } |
| 250 | 250 |
| 251 |
| 252 // The expected code pattern of an edge counter in unoptimized code: |
| 253 // 49 8b 87 imm32 mov RAX, [PP + offset] |
| 254 class EdgeCounter : public ValueObject { |
| 255 public: |
| 256 EdgeCounter(uword pc, const Code& code) |
| 257 : end_(pc - kAdjust), object_pool_(Array::Handle(code.ObjectPool())) { |
| 258 ASSERT(IsValid(end_)); |
| 259 } |
| 260 |
| 261 static bool IsValid(uword end) { |
| 262 uint8_t* bytes = reinterpret_cast<uint8_t*>(end - 7); |
| 263 return (bytes[0] == 0x49) && (bytes[1] == 0x8b) && (bytes[2] == 0x87); |
| 264 } |
| 265 |
| 266 RawObject* edge_counter() const { |
| 267 return object_pool_.At(InstructionPattern::IndexFromPPLoad(end_ - 4)); |
| 268 } |
| 269 |
| 270 private: |
| 271 // The edge counter load is followed by the fixed-size edge counter |
| 272 // incrementing code: |
| 273 // 49 c7 c3 02 00 00 00 movq r11,0x2 |
| 274 // 4c 01 58 17 addq [rax+0x17],r11 |
| 275 static const intptr_t kAdjust = 11; |
| 276 |
| 277 uword end_; |
| 278 const Array& object_pool_; |
| 279 }; |
| 280 |
| 281 |
| 282 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
| 283 ASSERT(code.ContainsInstructionAt(pc)); |
| 284 EdgeCounter counter(pc, code); |
| 285 return counter.edge_counter(); |
| 286 } |
| 287 |
| 251 } // namespace dart | 288 } // namespace dart |
| 252 | 289 |
| 253 #endif // defined TARGET_ARCH_X64 | 290 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |