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

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

Issue 17554003: Change static calls in unoptimized code to always call via a stub. Using ICData, the call count of … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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_test.cc ('k') | runtime/vm/code_patcher_ia32_test.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"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/instructions.h" 12 #include "vm/instructions.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/raw_object.h" 14 #include "vm/raw_object.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 // The expected pattern of a dart instance call: 18 // The expected pattern of a Dart unoptimized call (static and instance):
19 // mov ECX, ic-data 19 // mov ECX, ic-data
20 // call target_address 20 // call target_address (stub)
21 // <- return address 21 // <- return address
22 class InstanceCall : public ValueObject { 22 class UnoptimizedCall : public ValueObject {
23 public: 23 public:
24 explicit InstanceCall(uword return_address) 24 explicit UnoptimizedCall(uword return_address)
25 : start_(return_address - (kNumInstructions * kInstructionSize)) { 25 : start_(return_address - (kNumInstructions * kInstructionSize)) {
26 ASSERT(IsValid(return_address)); 26 ASSERT(IsValid(return_address));
27 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); 27 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
28 } 28 }
29 29
30 static bool IsValid(uword return_address) { 30 static bool IsValid(uword return_address) {
31 uint8_t* code_bytes = 31 uint8_t* code_bytes =
32 reinterpret_cast<uint8_t*>( 32 reinterpret_cast<uint8_t*>(
33 return_address - (kNumInstructions * kInstructionSize)); 33 return_address - (kNumInstructions * kInstructionSize));
34 return (code_bytes[0] == 0xB9) && 34 return (code_bytes[0] == 0xB9) &&
(...skipping 22 matching lines...) Expand all
57 private: 57 private:
58 uword return_address() const { 58 uword return_address() const {
59 return start_ + kNumInstructions * kInstructionSize; 59 return start_ + kNumInstructions * kInstructionSize;
60 } 60 }
61 61
62 uword call_address() const { 62 uword call_address() const {
63 return start_ + 1 * kInstructionSize; 63 return start_ + 1 * kInstructionSize;
64 } 64 }
65 65
66 uword start_; 66 uword start_;
67 DISALLOW_IMPLICIT_CONSTRUCTORS(UnoptimizedCall);
68 };
69
70
71 class InstanceCall : public UnoptimizedCall {
72 public:
73 explicit InstanceCall(uword return_address)
74 : UnoptimizedCall(return_address) {
75 #if defined(DEBUG)
76 ICData& test_ic_data = ICData::Handle();
77 test_ic_data ^= ic_data();
78 ASSERT(test_ic_data.num_args_tested() > 0);
79 #endif // DEBUG
80 }
81
82 private:
67 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); 83 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall);
68 }; 84 };
69 85
70 86
87 class UnoptimizedStaticCall : public UnoptimizedCall {
88 public:
89 explicit UnoptimizedStaticCall(uword return_address)
90 : UnoptimizedCall(return_address) {
91 #if defined(DEBUG)
92 ICData& test_ic_data = ICData::Handle();
93 test_ic_data ^= ic_data();
94 ASSERT(test_ic_data.num_args_tested() == 0);
95 #endif // DEBUG
96 }
97
98 private:
99 DISALLOW_IMPLICIT_CONSTRUCTORS(UnoptimizedStaticCall);
100 };
101
102
71 // The expected pattern of a dart static call: 103 // The expected pattern of a dart static call:
72 // mov EDX, arguments_descriptor_array (optional in polymorphic calls) 104 // mov EDX, arguments_descriptor_array (optional in polymorphic calls)
73 // call target_address 105 // call target_address
74 // <- return address 106 // <- return address
75 class StaticCall : public ValueObject { 107 class StaticCall : public ValueObject {
76 public: 108 public:
77 explicit StaticCall(uword return_address) 109 explicit StaticCall(uword return_address)
78 : start_(return_address - (kNumInstructions * kInstructionSize)) { 110 : start_(return_address - (kNumInstructions * kInstructionSize)) {
79 ASSERT(IsValid(return_address)); 111 ASSERT(IsValid(return_address));
80 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); 112 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ICData* ic_data) { 236 ICData* ic_data) {
205 ASSERT(code.ContainsInstructionAt(return_address)); 237 ASSERT(code.ContainsInstructionAt(return_address));
206 InstanceCall call(return_address); 238 InstanceCall call(return_address);
207 if (ic_data != NULL) { 239 if (ic_data != NULL) {
208 *ic_data ^= call.ic_data(); 240 *ic_data ^= call.ic_data();
209 } 241 }
210 return call.target(); 242 return call.target();
211 } 243 }
212 244
213 245
246 RawFunction* CodePatcher::GetUnoptimizedStaticCallTargetAt(
247 uword return_address, const Code& code) {
248 ASSERT(code.ContainsInstructionAt(return_address));
249 UnoptimizedStaticCall static_call(return_address);
250 ICData& ic_data = ICData::Handle();
251 ic_data ^= static_call.ic_data();
252 return ic_data.GetTargetAt(0);
253 }
254
255
214 intptr_t CodePatcher::InstanceCallSizeInBytes() { 256 intptr_t CodePatcher::InstanceCallSizeInBytes() {
215 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize; 257 return InstanceCall::kNumInstructions * InstanceCall::kInstructionSize;
216 } 258 }
217 259
218 } // namespace dart 260 } // namespace dart
219 261
220 #endif // defined TARGET_ARCH_IA32 262 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher_arm_test.cc ('k') | runtime/vm/code_patcher_ia32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698