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

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

Issue 11419073: Remove loading of function object in static calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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_x64.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/instructions.h" 11 #include "vm/instructions.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/raw_object.h" 13 #include "vm/raw_object.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 // The pattern of a Dart call is: 17 // The pattern of a Dart instance call is:
18 // 1: mov ECX, immediate 1 18 // 1: mov ECX, immediate 1
19 // 2: mov EDX, immediate 2 19 // 2: mov EDX, immediate 2
20 // 3: call target_address 20 // 3: call target_address
21 // <- return_address 21 // <- return_address
22 class DartCallPattern : public ValueObject { 22 class DartCallPattern : public ValueObject {
23 public: 23 public:
24 explicit DartCallPattern(uword return_address) 24 explicit DartCallPattern(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);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 uword call_address() const { 91 uword call_address() const {
92 return start_ + 2 * kInstructionSize; 92 return start_ + 2 * kInstructionSize;
93 } 93 }
94 94
95 uword start_; 95 uword start_;
96 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern); 96 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern);
97 }; 97 };
98 98
99 99
100 // The expected pattern of a dart static call:
101 // mov ECX, function_object
102 // mov EDX, argument_descriptor_array
103 // call target_address
104 // <- return address
105 class StaticCall : public DartCallPattern {
106 public:
107 explicit StaticCall(uword return_address)
108 : DartCallPattern(return_address) {}
109
110 RawFunction* function() const {
111 Function& f = Function::Handle();
112 f ^= reinterpret_cast<RawObject*>(immediate_one());
113 return f.raw();
114 }
115
116 private:
117 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall);
118 };
119
120
121 // The expected pattern of a dart instance call: 100 // The expected pattern of a dart instance call:
122 // mov ECX, ic-data 101 // mov ECX, ic-data
123 // mov EDX, argument_descriptor_array 102 // mov EDX, argument_descriptor_array
124 // call target_address 103 // call target_address
125 // <- return address 104 // <- return address
126 class InstanceCall : public DartCallPattern { 105 class InstanceCall : public DartCallPattern {
127 public: 106 public:
128 explicit InstanceCall(uword return_address) 107 explicit InstanceCall(uword return_address)
129 : DartCallPattern(return_address) {} 108 : DartCallPattern(return_address) {}
130 109
131 RawICData* ic_data() const { 110 RawICData* ic_data() const {
132 ICData& ic_data = ICData::Handle(); 111 ICData& ic_data = ICData::Handle();
133 ic_data ^= reinterpret_cast<RawObject*>(immediate_one()); 112 ic_data ^= reinterpret_cast<RawObject*>(immediate_one());
134 return ic_data.raw(); 113 return ic_data.raw();
135 } 114 }
136 115
137 private: 116 private:
138 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); 117 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall);
139 }; 118 };
140 119
141 120
121 // The expected pattern of a dart static call:
122 // mov EDX, argument_descriptor_array
123 // call target_address
124 // <- return address
125 class StaticCall : public ValueObject {
126 public:
127 explicit StaticCall(uword return_address)
128 : start_(return_address - (kNumInstructions * kInstructionSize)) {
129 ASSERT(IsValid(return_address));
130 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
131 }
132
133 static bool IsValid(uword return_address) {
134 uint8_t* code_bytes =
135 reinterpret_cast<uint8_t*>(
136 return_address - (kNumInstructions * kInstructionSize));
137 return (code_bytes[0] == 0xBA) &&
138 (code_bytes[1 * kInstructionSize] == 0xE8);
139 }
140
141 uword target() const {
142 const uword offset = *reinterpret_cast<uword*>(call_address() + 1);
143 return return_address() + offset;
144 }
145
146 void set_target(uword target) const {
147 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1);
148 uword offset = target - return_address();
149 *target_addr = offset;
150 CPU::FlushICache(call_address(), kInstructionSize);
151 }
152
153 static const int kNumInstructions = 2;
154 static const int kInstructionSize = 5; // All instructions have same length.
155
156 private:
157 uword return_address() const {
158 return start_ + kNumInstructions * kInstructionSize;
159 }
160
161 uword call_address() const {
162 return start_ + 1 * kInstructionSize;
163 }
164
165 uword start_;
166
167 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall);
168 };
169
170
142 uword CodePatcher::GetStaticCallTargetAt(uword return_address) { 171 uword CodePatcher::GetStaticCallTargetAt(uword return_address) {
143 StaticCall call(return_address); 172 StaticCall call(return_address);
144 return call.target(); 173 return call.target();
145 } 174 }
146 175
147 176
148 void CodePatcher::PatchStaticCallAt(uword return_address, uword new_target) { 177 void CodePatcher::PatchStaticCallAt(uword return_address, uword new_target) {
149 StaticCall call(return_address); 178 StaticCall call(return_address);
150 call.set_target(new_target); 179 call.set_target(new_target);
151 } 180 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 *reinterpret_cast<uint8_t*>(start) = 0xE8; 288 *reinterpret_cast<uint8_t*>(start) = 0xE8;
260 CallPattern call(start); 289 CallPattern call(start);
261 call.SetTargetAddress(target); 290 call.SetTargetAddress(target);
262 CPU::FlushICache(start, CallPattern::InstructionLength()); 291 CPU::FlushICache(start, CallPattern::InstructionLength());
263 } 292 }
264 293
265 294
266 } // namespace dart 295 } // namespace dart
267 296
268 #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_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698