Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: runtime/vm/code_patcher_ia32.cc

Issue 24744002: Pattern match on generated code to find edge counters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/code_patcher_arm.cc ('k') | runtime/vm/code_patcher_mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 uword call_address() const { 142 uword call_address() const {
143 return start_; 143 return start_;
144 } 144 }
145 145
146 uword start_; 146 uword start_;
147 147
148 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); 148 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall);
149 }; 149 };
150 150
151 151
152 // The expected pattern of a dart closure call: 152 // The expected pattern of a Dart closure call:
153 // mov EDX, arguments_descriptor_array 153 // mov EDX, arguments_descriptor_array
154 // call target_address 154 // call target_address
155 // <- return address 155 // <- return address
156 class ClosureCall : public ValueObject { 156 class ClosureCall : public ValueObject {
157 public: 157 public:
158 explicit ClosureCall(uword return_address) 158 explicit ClosureCall(uword return_address)
159 : start_(return_address - (kInstr1Size + kInstr2Size)) { 159 : start_(return_address - (kInstr1Size + kInstr2Size)) {
160 ASSERT(IsValid(return_address)); 160 ASSERT(IsValid(return_address));
161 ASSERT(kInstr2Size == Assembler::kCallExternalLabelSize); 161 ASSERT(kInstr2Size == Assembler::kCallExternalLabelSize);
162 } 162 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 *ic_data_result = ic_data.raw(); 252 *ic_data_result = ic_data.raw();
253 } 253 }
254 return ic_data.GetTargetAt(0); 254 return ic_data.GetTargetAt(0);
255 } 255 }
256 256
257 257
258 intptr_t CodePatcher::InstanceCallSizeInBytes() { 258 intptr_t CodePatcher::InstanceCallSizeInBytes() {
259 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize; 259 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize;
260 } 260 }
261 261
262
263 // The expected code pattern of an edge counter in unoptimized code:
264 // b8 imm32 mov EAX, immediate
265 class EdgeCounter : public ValueObject {
266 public:
267 EdgeCounter(uword pc, const Code& ignored) : end_(pc - kAdjust) {
268 ASSERT(IsValid(end_));
269 }
270
271 static bool IsValid(uword end) {
272 return (*reinterpret_cast<uint8_t*>(end - 5) == 0xb8);
273 }
274
275 RawObject* edge_counter() const {
276 return *reinterpret_cast<RawObject**>(end_ - 4);
277 }
278
279 private:
280 // The edge counter load is followed by the fixed-size edge counter
281 // incrementing code:
282 // 83 40 0b 02 add [eax+0xb],0x2
283 static const intptr_t kAdjust = 4;
284
285 uword end_;
286 };
287
288
289 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) {
290 ASSERT(code.ContainsInstructionAt(pc));
291 EdgeCounter counter(pc, code);
292 return counter.edge_counter();
293 }
294
262 } // namespace dart 295 } // namespace dart
263 296
264 #endif // defined TARGET_ARCH_IA32 297 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher_arm.cc ('k') | runtime/vm/code_patcher_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698