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

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

Issue 2226893002: Optimize AOT's switchable calls for the monomorphic case. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 4 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
« no previous file with comments | « runtime/vm/code_patcher_mips_test.cc ('k') | runtime/vm/compiler.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_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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 protected: 184 protected:
185 uword start_; 185 uword start_;
186 const ObjectPool& object_pool_; 186 const ObjectPool& object_pool_;
187 187
188 private: 188 private:
189 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); 189 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall);
190 }; 190 };
191 191
192 192
193 // Instance call that can switch from an IC call to a megamorphic call 193 // Instance call that can switch between a direct monomorphic call, an IC call,
194 // load ICData load MegamorphicCache 194 // and a megamorphic call.
195 // call ICLookup stub -> call MegamorphicLookup stub 195 // load guarded cid load ICData load MegamorphicCache
196 // call target call target 196 // load monomorphic target <-> load ICLookup stub -> load MMLookup stub
197 // call target.entry call stub.entry call stub.entry
197 class SwitchableCall : public ValueObject { 198 class SwitchableCall : public ValueObject {
198 public: 199 public:
199 SwitchableCall(uword return_address, const Code& code) 200 SwitchableCall(uword return_address, const Code& code)
200 : start_(return_address - kCallPatternSize), 201 : start_(return_address - kCallPatternSize),
201 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { 202 object_pool_(ObjectPool::Handle(code.GetObjectPool())) {
202 ASSERT(IsValid()); 203 ASSERT(IsValid());
203 } 204 }
204 205
205 static const int kCallPatternSize = 24; 206 static const int kCallPatternSize = 21;
206 207
207 bool IsValid() const { 208 bool IsValid() const {
208 static int16_t pattern[kCallPatternSize] = { 209 static int16_t pattern[kCallPatternSize] = {
209 0x49, 0x8b, 0x9f, -1, -1, -1, -1, // movq rbx, [PP + cache_offs] 210 0x49, 0x8b, 0x9f, -1, -1, -1, -1, // movq rbx, [PP + cache_offs]
210 0x4d, 0x8b, 0xa7, -1, -1, -1, -1, // movq r12, [PP + code_offs] 211 0x4d, 0x8b, 0xa7, -1, -1, -1, -1, // movq r12, [PP + code_offs]
211 0x4d, 0x8b, 0x5c, 0x24, 0x07, // movq r11, [r12 + entrypoint_off] 212 0x49, 0x8b, 0x4c, 0x24, 0x0f, // movq rcx, [r12 + entrypoint_off]
212 0x41, 0xff, 0xd3, // call r11
213 0xff, 0xd1, // call rcx 213 0xff, 0xd1, // call rcx
214 }; 214 };
215 ASSERT(ARRAY_SIZE(pattern) == kCallPatternSize);
215 return MatchesPattern(start_, pattern, kCallPatternSize); 216 return MatchesPattern(start_, pattern, kCallPatternSize);
216 } 217 }
217 218
218 intptr_t cache_index() const { 219 intptr_t data_index() const {
219 return IndexFromPPLoad(start_ + 3); 220 return IndexFromPPLoad(start_ + 3);
220 } 221 }
221 intptr_t lookup_stub_index() const { 222 intptr_t target_index() const {
222 return IndexFromPPLoad(start_ + 10); 223 return IndexFromPPLoad(start_ + 10);
223 } 224 }
224 225
225 RawObject* cache() const { 226 RawObject* data() const {
226 return object_pool_.ObjectAt(cache_index()); 227 return object_pool_.ObjectAt(data_index());
228 }
229 RawCode* target() const {
230 return reinterpret_cast<RawCode*>(object_pool_.ObjectAt(target_index()));
227 } 231 }
228 232
229 void SetCache(const MegamorphicCache& cache) const { 233 void SetData(const Object& data) const {
230 ASSERT(Object::Handle(object_pool_.ObjectAt(cache_index())).IsICData()); 234 ASSERT(!Object::Handle(object_pool_.ObjectAt(data_index())).IsCode());
231 object_pool_.SetObjectAt(cache_index(), cache); 235 object_pool_.SetObjectAt(data_index(), data);
232 // No need to flush the instruction cache, since the code is not modified. 236 // No need to flush the instruction cache, since the code is not modified.
233 } 237 }
234 238
235 void SetLookupStub(const Code& lookup_stub) const { 239 void SetTarget(const Code& target) const {
236 ASSERT(Object::Handle(object_pool_.ObjectAt(lookup_stub_index())).IsCode()); 240 ASSERT(Object::Handle(object_pool_.ObjectAt(target_index())).IsCode());
237 object_pool_.SetObjectAt(lookup_stub_index(), lookup_stub); 241 object_pool_.SetObjectAt(target_index(), target);
238 // No need to flush the instruction cache, since the code is not modified. 242 // No need to flush the instruction cache, since the code is not modified.
239 } 243 }
240 244
241 protected: 245 protected:
242 uword start_; 246 uword start_;
243 const ObjectPool& object_pool_; 247 const ObjectPool& object_pool_;
244 248
245 private: 249 private:
246 DISALLOW_IMPLICIT_CONSTRUCTORS(SwitchableCall); 250 DISALLOW_IMPLICIT_CONSTRUCTORS(SwitchableCall);
247 }; 251 };
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 ICData& ic_data = ICData::Handle(); 310 ICData& ic_data = ICData::Handle();
307 ic_data ^= static_call.ic_data(); 311 ic_data ^= static_call.ic_data();
308 if (ic_data_result != NULL) { 312 if (ic_data_result != NULL) {
309 *ic_data_result = ic_data.raw(); 313 *ic_data_result = ic_data.raw();
310 } 314 }
311 return ic_data.GetTargetAt(0); 315 return ic_data.GetTargetAt(0);
312 } 316 }
313 317
314 318
315 void CodePatcher::PatchSwitchableCallAt(uword return_address, 319 void CodePatcher::PatchSwitchableCallAt(uword return_address,
316 const Code& code, 320 const Code& caller_code,
317 const ICData& ic_data, 321 const Object& data,
318 const MegamorphicCache& cache, 322 const Code& target) {
319 const Code& lookup_stub) { 323 ASSERT(caller_code.ContainsInstructionAt(return_address));
320 ASSERT(code.ContainsInstructionAt(return_address)); 324 SwitchableCall call(return_address, caller_code);
321 SwitchableCall call(return_address, code); 325 call.SetData(data);
322 ASSERT(call.cache() == ic_data.raw()); 326 call.SetTarget(target);
323 call.SetLookupStub(lookup_stub);
324 call.SetCache(cache);
325 } 327 }
326 328
327 329
330 RawCode* CodePatcher::GetSwitchableCallTargetAt(uword return_address,
331 const Code& caller_code) {
332 ASSERT(caller_code.ContainsInstructionAt(return_address));
333 SwitchableCall call(return_address, caller_code);
334 return call.target();
335 }
336
337
338 RawObject* CodePatcher::GetSwitchableCallDataAt(uword return_address,
339 const Code& caller_code) {
340 ASSERT(caller_code.ContainsInstructionAt(return_address));
341 SwitchableCall call(return_address, caller_code);
342 return call.data();
343 }
344
345
328 void CodePatcher::PatchNativeCallAt(uword return_address, 346 void CodePatcher::PatchNativeCallAt(uword return_address,
329 const Code& code, 347 const Code& code,
330 NativeFunction target, 348 NativeFunction target,
331 const Code& trampoline) { 349 const Code& trampoline) {
332 ASSERT(code.ContainsInstructionAt(return_address)); 350 ASSERT(code.ContainsInstructionAt(return_address));
333 NativeCall call(return_address, code); 351 NativeCall call(return_address, code);
334 call.set_target(trampoline); 352 call.set_target(trampoline);
335 call.set_native_function(target); 353 call.set_native_function(target);
336 } 354 }
337 355
338 356
339 RawCode* CodePatcher::GetNativeCallAt(uword return_address, 357 RawCode* CodePatcher::GetNativeCallAt(uword return_address,
340 const Code& code, 358 const Code& code,
341 NativeFunction* target) { 359 NativeFunction* target) {
342 ASSERT(code.ContainsInstructionAt(return_address)); 360 ASSERT(code.ContainsInstructionAt(return_address));
343 NativeCall call(return_address, code); 361 NativeCall call(return_address, code);
344 *target = call.native_function(); 362 *target = call.native_function();
345 return call.target(); 363 return call.target();
346 } 364 }
347 365
348 } // namespace dart 366 } // namespace dart
349 367
350 #endif // defined TARGET_ARCH_X64 368 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher_mips_test.cc ('k') | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698