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

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

Issue 1192103004: VM: New calling convention for generated code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: ARM working, x64 cleanup Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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" 5 #include "vm/globals.h"
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/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 274
275 // Input parameters: 275 // Input parameters:
276 // R10: arguments descriptor array. 276 // R10: arguments descriptor array.
277 void StubCode::GenerateCallStaticFunctionStub(Assembler* assembler) { 277 void StubCode::GenerateCallStaticFunctionStub(Assembler* assembler) {
278 __ EnterStubFrame(); 278 __ EnterStubFrame();
279 __ pushq(R10); // Preserve arguments descriptor array. 279 __ pushq(R10); // Preserve arguments descriptor array.
280 // Setup space on stack for return value. 280 // Setup space on stack for return value.
281 __ PushObject(Object::null_object()); 281 __ PushObject(Object::null_object());
282 __ CallRuntime(kPatchStaticCallRuntimeEntry, 0); 282 __ CallRuntime(kPatchStaticCallRuntimeEntry, 0);
283 __ popq(RAX); // Get Code object result. 283 __ popq(CODE_REG); // Get Code object result.
284 __ popq(R10); // Restore arguments descriptor array. 284 __ popq(R10); // Restore arguments descriptor array.
285 // Remove the stub frame as we are about to jump to the dart function. 285 // Remove the stub frame as we are about to jump to the dart function.
286 __ LeaveStubFrame(); 286 __ LeaveStubFrame();
287 287
288 __ movq(RBX, FieldAddress(RAX, Code::entry_point_offset())); 288 __ movq(RBX, FieldAddress(CODE_REG, Code::entry_point_offset()));
289 __ jmp(RBX); 289 __ jmp(RBX);
290 } 290 }
291 291
292 292
293 // Called from a static call only when an invalid code has been entered 293 // Called from a static call only when an invalid code has been entered
294 // (invalid because its function was optimized or deoptimized). 294 // (invalid because its function was optimized or deoptimized).
295 // R10: arguments descriptor array. 295 // R10: arguments descriptor array.
296 void StubCode::GenerateFixCallersTargetStub(Assembler* assembler) { 296 void StubCode::GenerateFixCallersTargetStub(Assembler* assembler) {
297 // Load code pointer to this stub from the thread:
298 // The one that is passed in, is not correct - it points to the code object
299 // that needs to be replaced.
300 __ movq(CODE_REG, Address(THR, Thread::fix_callers_target_code_offset()));
297 __ EnterStubFrame(); 301 __ EnterStubFrame();
298 __ pushq(R10); // Preserve arguments descriptor array. 302 __ pushq(R10); // Preserve arguments descriptor array.
299 // Setup space on stack for return value. 303 // Setup space on stack for return value.
300 __ PushObject(Object::null_object()); 304 __ PushObject(Object::null_object());
301 __ CallRuntime(kFixCallersTargetRuntimeEntry, 0); 305 __ CallRuntime(kFixCallersTargetRuntimeEntry, 0);
302 __ popq(RAX); // Get Code object. 306 __ popq(CODE_REG); // Get Code object.
303 __ popq(R10); // Restore arguments descriptor array. 307 __ popq(R10); // Restore arguments descriptor array.
304 __ movq(RAX, FieldAddress(RAX, Code::entry_point_offset())); 308 __ movq(RAX, FieldAddress(CODE_REG, Code::entry_point_offset()));
305 __ LeaveStubFrame(); 309 __ LeaveStubFrame();
306 __ jmp(RAX); 310 __ jmp(RAX);
307 __ int3(); 311 __ int3();
308 } 312 }
309 313
310 314
311 // Called from object allocate instruction when the allocation stub has been 315 // Called from object allocate instruction when the allocation stub has been
312 // disabled. 316 // disabled.
313 void StubCode::GenerateFixAllocationStubTargetStub(Assembler* assembler) { 317 void StubCode::GenerateFixAllocationStubTargetStub(Assembler* assembler) {
318 // Load code pointer to this stub from the thread:
319 // The one that is passed in, is not correct - it points to the code object
320 // that needs to be replaced.
321 __ movq(CODE_REG, Address(THR, Thread::fix_allocation_stub_code_offset()));
314 __ EnterStubFrame(); 322 __ EnterStubFrame();
315 // Setup space on stack for return value. 323 // Setup space on stack for return value.
316 __ PushObject(Object::null_object()); 324 __ PushObject(Object::null_object());
317 __ CallRuntime(kFixAllocationStubTargetRuntimeEntry, 0); 325 __ CallRuntime(kFixAllocationStubTargetRuntimeEntry, 0);
318 __ popq(RAX); // Get Code object. 326 __ popq(CODE_REG); // Get Code object.
319 __ movq(RAX, FieldAddress(RAX, Code::entry_point_offset())); 327 __ movq(RAX, FieldAddress(CODE_REG, Code::entry_point_offset()));
320 __ LeaveStubFrame(); 328 __ LeaveStubFrame();
321 __ jmp(RAX); 329 __ jmp(RAX);
322 __ int3(); 330 __ int3();
323 } 331 }
324 332
325 333
326 // Input parameters: 334 // Input parameters:
327 // R10: smi-tagged argument count, may be zero. 335 // R10: smi-tagged argument count, may be zero.
328 // RBP[kParamEndSlotFromFp + 1]: last argument. 336 // RBP[kParamEndSlotFromFp + 1]: last argument.
329 static void PushArgumentsArray(Assembler* assembler) { 337 static void PushArgumentsArray(Assembler* assembler) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // Stack after EnterDartFrame(0, PP, kNoRegister) below: 380 // Stack after EnterDartFrame(0, PP, kNoRegister) below:
373 // +------------------+ 381 // +------------------+
374 // | Saved PP | <- PP 382 // | Saved PP | <- PP
375 // +------------------+ 383 // +------------------+
376 // | PC marker | <- TOS 384 // | PC marker | <- TOS
377 // +------------------+ 385 // +------------------+
378 // | Saved FP | <- FP of stub 386 // | Saved FP | <- FP of stub
379 // +------------------+ 387 // +------------------+
380 // | return-address | (deoptimization point) 388 // | return-address | (deoptimization point)
381 // +------------------+ 389 // +------------------+
390 // | Saved CODE_REG |
391 // +------------------+
382 // | ... | <- SP of optimized frame 392 // | ... | <- SP of optimized frame
383 // 393 //
384 // Parts of the code cannot GC, part of the code can GC. 394 // Parts of the code cannot GC, part of the code can GC.
385 static void GenerateDeoptimizationSequence(Assembler* assembler, 395 static void GenerateDeoptimizationSequence(Assembler* assembler,
386 bool preserve_result) { 396 DeoptStubKind kind) {
387 // DeoptimizeCopyFrame expects a Dart frame, i.e. EnterDartFrame(0), but there 397 // DeoptimizeCopyFrame expects a Dart frame, i.e. EnterDartFrame(0), but there
388 // is no need to set the correct PC marker or load PP, since they get patched. 398 // is no need to set the correct PC marker or load PP, since they get patched.
389 __ EnterStubFrame(); 399 __ EnterStubFrame();
390 400
391 // The code in this frame may not cause GC. kDeoptimizeCopyFrameRuntimeEntry 401 // The code in this frame may not cause GC. kDeoptimizeCopyFrameRuntimeEntry
392 // and kDeoptimizeFillFrameRuntimeEntry are leaf runtime calls. 402 // and kDeoptimizeFillFrameRuntimeEntry are leaf runtime calls.
393 const intptr_t saved_result_slot_from_fp = 403 const intptr_t saved_result_slot_from_fp =
394 kFirstLocalSlotFromFp + 1 - (kNumberOfCpuRegisters - RAX); 404 kFirstLocalSlotFromFp + 1 - (kNumberOfCpuRegisters - RAX);
395 // Result in RAX is preserved as part of pushing all registers below. 405 // Result in RAX is preserved as part of pushing all registers below.
396 406
397 // Push registers in their enumeration order: lowest register number at 407 // Push registers in their enumeration order: lowest register number at
398 // lowest address. 408 // lowest address.
399 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) { 409 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) {
400 __ pushq(static_cast<Register>(i)); 410 if (i == CODE_REG) {
411 __ pushq(Address(RBP, 2 * kWordSize));
412 } else {
413 __ pushq(static_cast<Register>(i));
414 }
401 } 415 }
402 __ subq(RSP, Immediate(kNumberOfXmmRegisters * kFpuRegisterSize)); 416 __ subq(RSP, Immediate(kNumberOfXmmRegisters * kFpuRegisterSize));
403 intptr_t offset = 0; 417 intptr_t offset = 0;
404 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) { 418 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) {
405 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx); 419 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx);
406 __ movups(Address(RSP, offset), xmm_reg); 420 __ movups(Address(RSP, offset), xmm_reg);
407 offset += kFpuRegisterSize; 421 offset += kFpuRegisterSize;
408 } 422 }
409 423
410 // Pass address of saved registers block. 424 // Pass address of saved registers block.
411 __ movq(CallingConventions::kArg1Reg, RSP); 425 __ movq(CallingConventions::kArg1Reg, RSP);
426 __ movq(CallingConventions::kArg2Reg, Immediate(kind == kLazyDeopt ? 1 : 0));
412 __ ReserveAlignedFrameSpace(0); // Ensure stack is aligned before the call. 427 __ ReserveAlignedFrameSpace(0); // Ensure stack is aligned before the call.
413 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry, 1); 428 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry, 2);
414 // Result (RAX) is stack-size (FP - SP) in bytes. 429 // Result (RAX) is stack-size (FP - SP) in bytes.
415 430
431 const bool preserve_result = (kind == kLazyDeopt);
416 if (preserve_result) { 432 if (preserve_result) {
417 // Restore result into RBX temporarily. 433 // Restore result into RBX temporarily.
418 __ movq(RBX, Address(RBP, saved_result_slot_from_fp * kWordSize)); 434 __ movq(RBX, Address(RBP, saved_result_slot_from_fp * kWordSize));
419 } 435 }
420 436
421 // There is a Dart Frame on the stack. We must restore PP and leave frame. 437 // There is a Dart Frame on the stack. We must restore PP and leave frame.
438 __ RestoreCodePointer();
422 __ LeaveStubFrame(); 439 __ LeaveStubFrame();
423 440
424 __ popq(RCX); // Preserve return address. 441 __ popq(RCX); // Preserve return address.
425 __ movq(RSP, RBP); // Discard optimized frame. 442 __ movq(RSP, RBP); // Discard optimized frame.
426 __ subq(RSP, RAX); // Reserve space for deoptimized frame. 443 __ subq(RSP, RAX); // Reserve space for deoptimized frame.
427 __ pushq(RCX); // Restore return address. 444 __ pushq(RCX); // Restore return address.
428 445
429 // DeoptimizeFillFrame expects a Dart frame, i.e. EnterDartFrame(0), but there 446 // DeoptimizeFillFrame expects a Dart frame, i.e. EnterDartFrame(0), but there
430 // is no need to set the correct PC marker or load PP, since they get patched. 447 // is no need to set the correct PC marker or load PP, since they get patched.
431 __ EnterStubFrame(); 448 __ EnterStubFrame();
432 449
433 if (preserve_result) { 450 if (preserve_result) {
434 __ pushq(RBX); // Preserve result as first local. 451 __ pushq(RBX); // Preserve result as first local.
435 } 452 }
436 __ ReserveAlignedFrameSpace(0); 453 __ ReserveAlignedFrameSpace(0);
437 // Pass last FP as a parameter. 454 // Pass last FP as a parameter.
438 __ movq(CallingConventions::kArg1Reg, RBP); 455 __ movq(CallingConventions::kArg1Reg, RBP);
439 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry, 1); 456 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry, 1);
440 if (preserve_result) { 457 if (preserve_result) {
441 // Restore result into RBX. 458 // Restore result into RBX.
442 __ movq(RBX, Address(RBP, kFirstLocalSlotFromFp * kWordSize)); 459 __ movq(RBX, Address(RBP, kFirstLocalSlotFromFp * kWordSize));
443 } 460 }
444 // Code above cannot cause GC. 461 // Code above cannot cause GC.
445 // There is a Dart Frame on the stack. We must restore PP and leave frame. 462 // There is a Dart Frame on the stack. We must restore PP and leave frame.
463 __ RestoreCodePointer();
446 __ LeaveStubFrame(); 464 __ LeaveStubFrame();
447 465
448 // Frame is fully rewritten at this point and it is safe to perform a GC. 466 // Frame is fully rewritten at this point and it is safe to perform a GC.
449 // Materialize any objects that were deferred by FillFrame because they 467 // Materialize any objects that were deferred by FillFrame because they
450 // require allocation. 468 // require allocation.
451 // Enter stub frame with loading PP. The caller's PP is not materialized yet. 469 // Enter stub frame with loading PP. The caller's PP is not materialized yet.
452 __ EnterStubFrame(); 470 __ EnterStubFrame();
453 if (preserve_result) { 471 if (preserve_result) {
454 __ pushq(RBX); // Preserve result, it will be GC-d here. 472 __ pushq(RBX); // Preserve result, it will be GC-d here.
455 } 473 }
(...skipping 15 matching lines...) Expand all
471 } 489 }
472 490
473 491
474 // TOS: return address + call-instruction-size (5 bytes). 492 // TOS: return address + call-instruction-size (5 bytes).
475 // RAX: result, must be preserved 493 // RAX: result, must be preserved
476 void StubCode::GenerateDeoptimizeLazyStub(Assembler* assembler) { 494 void StubCode::GenerateDeoptimizeLazyStub(Assembler* assembler) {
477 // Correct return address to point just after the call that is being 495 // Correct return address to point just after the call that is being
478 // deoptimized. 496 // deoptimized.
479 __ popq(RBX); 497 __ popq(RBX);
480 __ subq(RBX, Immediate(ShortCallPattern::pattern_length_in_bytes())); 498 __ subq(RBX, Immediate(ShortCallPattern::pattern_length_in_bytes()));
499 // Push zap value instead of CODE_REG for lazy deopt.
500 __ pushq(Immediate(0xf1f1f1f1));
481 __ pushq(RBX); 501 __ pushq(RBX);
482 GenerateDeoptimizationSequence(assembler, true); // Preserve RAX. 502 GenerateDeoptimizationSequence(assembler, kLazyDeopt);
483 } 503 }
484 504
485 505
486 void StubCode::GenerateDeoptimizeStub(Assembler* assembler) { 506 void StubCode::GenerateDeoptimizeStub(Assembler* assembler) {
487 GenerateDeoptimizationSequence(assembler, false); // Don't preserve RAX. 507 GenerateDeoptimizationSequence(assembler, kEagerDeopt);
488 } 508 }
489 509
490 510
491 static void GenerateDispatcherCode(Assembler* assembler, 511 static void GenerateDispatcherCode(Assembler* assembler,
492 Label* call_target_function) { 512 Label* call_target_function) {
493 __ Comment("NoSuchMethodDispatch"); 513 __ Comment("NoSuchMethodDispatch");
494 // When lazily generated invocation dispatchers are disabled, the 514 // When lazily generated invocation dispatchers are disabled, the
495 // miss-handler may return null. 515 // miss-handler may return null.
496 const Immediate& raw_null = 516 const Immediate& raw_null =
497 Immediate(reinterpret_cast<intptr_t>(Object::null())); 517 Immediate(reinterpret_cast<intptr_t>(Object::null()));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 __ pushq(RBX); // IC data. 557 __ pushq(RBX); // IC data.
538 __ pushq(R10); // Arguments descriptor. 558 __ pushq(R10); // Arguments descriptor.
539 __ CallRuntime(kMegamorphicCacheMissHandlerRuntimeEntry, 3); 559 __ CallRuntime(kMegamorphicCacheMissHandlerRuntimeEntry, 3);
540 // Discard arguments. 560 // Discard arguments.
541 __ popq(RAX); 561 __ popq(RAX);
542 __ popq(RAX); 562 __ popq(RAX);
543 __ popq(RAX); 563 __ popq(RAX);
544 __ popq(RAX); // Return value from the runtime call (function). 564 __ popq(RAX); // Return value from the runtime call (function).
545 __ popq(R10); // Restore arguments descriptor. 565 __ popq(R10); // Restore arguments descriptor.
546 __ popq(RBX); // Restore IC data. 566 __ popq(RBX); // Restore IC data.
567 __ RestoreCodePointer();
547 __ LeaveStubFrame(); 568 __ LeaveStubFrame();
548
549 if (!FLAG_lazy_dispatchers) { 569 if (!FLAG_lazy_dispatchers) {
550 Label call_target_function; 570 Label call_target_function;
551 GenerateDispatcherCode(assembler, &call_target_function); 571 GenerateDispatcherCode(assembler, &call_target_function);
552 __ Bind(&call_target_function); 572 __ Bind(&call_target_function);
553 } 573 }
554 574 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset()));
555 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset())); 575 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset()));
556 __ jmp(RCX); 576 __ jmp(RCX);
557 } 577 }
558 578
559 579
560 // Called for inline allocation of arrays. 580 // Called for inline allocation of arrays.
561 // Input parameters: 581 // Input parameters:
562 // R10 : Array length as Smi. 582 // R10 : Array length as Smi.
563 // RBX : array element type (either NULL or an instantiated type). 583 // RBX : array element type (either NULL or an instantiated type).
564 // NOTE: R10 cannot be clobbered here as the caller relies on it being saved. 584 // NOTE: R10 cannot be clobbered here as the caller relies on it being saved.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 __ popq(R10); // Pop array length argument. 708 __ popq(R10); // Pop array length argument.
689 __ popq(RAX); // Pop return value from return slot. 709 __ popq(RAX); // Pop return value from return slot.
690 __ LeaveStubFrame(); 710 __ LeaveStubFrame();
691 __ ret(); 711 __ ret();
692 } 712 }
693 713
694 714
695 // Called when invoking Dart code from C++ (VM code). 715 // Called when invoking Dart code from C++ (VM code).
696 // Input parameters: 716 // Input parameters:
697 // RSP : points to return address. 717 // RSP : points to return address.
698 // RDI : entrypoint of the Dart function to call. 718 // RDI : target code
699 // RSI : arguments descriptor array. 719 // RSI : arguments descriptor array.
700 // RDX : arguments array. 720 // RDX : arguments array.
701 // RCX : current thread. 721 // RCX : current thread.
702 void StubCode::GenerateInvokeDartCodeStub(Assembler* assembler) { 722 void StubCode::GenerateInvokeDartCodeStub(Assembler* assembler) {
703 // Save frame pointer coming in. 723 // Save frame pointer coming in.
704 __ EnterFrame(0); 724 __ EnterFrame(0);
705 725
706 const Register kEntryPointReg = CallingConventions::kArg1Reg; 726 const Register kTargetCodeReg = CallingConventions::kArg1Reg;
707 const Register kArgDescReg = CallingConventions::kArg2Reg; 727 const Register kArgDescReg = CallingConventions::kArg2Reg;
708 const Register kArgsReg = CallingConventions::kArg3Reg; 728 const Register kArgsReg = CallingConventions::kArg3Reg;
709 const Register kThreadReg = CallingConventions::kArg4Reg; 729 const Register kThreadReg = CallingConventions::kArg4Reg;
710 730
711 // At this point, the stack looks like: 731 // At this point, the stack looks like:
712 // | saved RBP | <-- RBP 732 // | saved RBP | <-- RBP
713 // | saved PC (return to DartEntry::InvokeFunction) | 733 // | saved PC (return to DartEntry::InvokeFunction) |
714 734
715 const intptr_t kInitialOffset = 1; 735 const intptr_t kInitialOffset = 1;
716 // Save arguments descriptor array. 736 // Save arguments descriptor array.
717 const intptr_t kArgumentsDescOffset = -(kInitialOffset) * kWordSize; 737 const intptr_t kArgumentsDescOffset = -(kInitialOffset) * kWordSize;
718 __ pushq(kArgDescReg); 738 __ pushq(kArgDescReg);
719 739
720 // Save C++ ABI callee-saved registers. 740 // Save C++ ABI callee-saved registers.
721 __ PushRegisters(CallingConventions::kCalleeSaveCpuRegisters, 741 __ PushRegisters(CallingConventions::kCalleeSaveCpuRegisters,
722 CallingConventions::kCalleeSaveXmmRegisters); 742 CallingConventions::kCalleeSaveXmmRegisters);
723 743
724 // We now load the pool pointer(PP) as we are about to invoke dart code and we
725 // could potentially invoke some intrinsic functions which need the PP to be
726 // set up.
727 __ LoadPoolPointer();
728
729 // If any additional (or fewer) values are pushed, the offsets in 744 // If any additional (or fewer) values are pushed, the offsets in
730 // kExitLinkSlotFromEntryFp will need to be changed. 745 // kExitLinkSlotFromEntryFp will need to be changed.
731 746
732 // Set up THR, which caches the current thread in Dart code. 747 // Set up THR, which caches the current thread in Dart code.
733 if (THR != kThreadReg) { 748 if (THR != kThreadReg) {
734 __ movq(THR, kThreadReg); 749 __ movq(THR, kThreadReg);
735 } 750 }
736 // Load Isolate pointer into kIsolateReg. 751 // Load Isolate pointer into kIsolateReg.
737 const Register kIsolateReg = RBX; 752 const Register kIsolateReg = RBX;
738 __ LoadIsolate(kIsolateReg); 753 __ LoadIsolate(kIsolateReg);
(...skipping 25 matching lines...) Expand all
764 __ Stop("kExitLinkSlotFromEntryFp mismatch"); 779 __ Stop("kExitLinkSlotFromEntryFp mismatch");
765 __ Bind(&ok); 780 __ Bind(&ok);
766 } 781 }
767 #endif 782 #endif
768 __ movq(Address(THR, Thread::top_exit_frame_info_offset()), 783 __ movq(Address(THR, Thread::top_exit_frame_info_offset()),
769 Immediate(0)); 784 Immediate(0));
770 785
771 // Load arguments descriptor array into R10, which is passed to Dart code. 786 // Load arguments descriptor array into R10, which is passed to Dart code.
772 __ movq(R10, Address(kArgDescReg, VMHandles::kOffsetOfRawPtrInHandle)); 787 __ movq(R10, Address(kArgDescReg, VMHandles::kOffsetOfRawPtrInHandle));
773 788
774 // Push arguments. At this point we only need to preserve kEntryPointReg. 789 // Push arguments. At this point we only need to preserve kTargetCodeReg.
775 ASSERT(kEntryPointReg != RDX); 790 ASSERT(kTargetCodeReg != RDX);
776 791
777 // Load number of arguments into RBX. 792 // Load number of arguments into RBX.
778 __ movq(RBX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 793 __ movq(RBX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
779 __ SmiUntag(RBX); 794 __ SmiUntag(RBX);
780 795
781 // Compute address of 'arguments array' data area into RDX. 796 // Compute address of 'arguments array' data area into RDX.
782 __ movq(RDX, Address(kArgsReg, VMHandles::kOffsetOfRawPtrInHandle)); 797 __ movq(RDX, Address(kArgsReg, VMHandles::kOffsetOfRawPtrInHandle));
783 __ leaq(RDX, FieldAddress(RDX, Array::data_offset())); 798 __ leaq(RDX, FieldAddress(RDX, Array::data_offset()));
784 799
785 // Set up arguments for the Dart call. 800 // Set up arguments for the Dart call.
786 Label push_arguments; 801 Label push_arguments;
787 Label done_push_arguments; 802 Label done_push_arguments;
788 __ testq(RBX, RBX); // check if there are arguments. 803 __ testq(RBX, RBX); // check if there are arguments.
789 __ j(ZERO, &done_push_arguments, Assembler::kNearJump); 804 __ j(ZERO, &done_push_arguments, Assembler::kNearJump);
790 __ movq(RAX, Immediate(0)); 805 __ movq(RAX, Immediate(0));
791 __ Bind(&push_arguments); 806 __ Bind(&push_arguments);
792 __ pushq(Address(RDX, RAX, TIMES_8, 0)); 807 __ pushq(Address(RDX, RAX, TIMES_8, 0));
793 __ incq(RAX); 808 __ incq(RAX);
794 __ cmpq(RAX, RBX); 809 __ cmpq(RAX, RBX);
795 __ j(LESS, &push_arguments, Assembler::kNearJump); 810 __ j(LESS, &push_arguments, Assembler::kNearJump);
796 __ Bind(&done_push_arguments); 811 __ Bind(&done_push_arguments);
797 812
798 // Call the Dart code entrypoint. 813 // Call the Dart code entrypoint.
799 __ call(kEntryPointReg); // R10 is the arguments descriptor array. 814 __ xorq(PP, PP); // GC-safe value into PP.
815 __ movq(CODE_REG,
816 Address(kTargetCodeReg, VMHandles::kOffsetOfRawPtrInHandle));
817 __ movq(kTargetCodeReg, FieldAddress(CODE_REG, Code::entry_point_offset()));
818 __ call(kTargetCodeReg); // R10 is the arguments descriptor array.
800 819
801 // Read the saved arguments descriptor array to obtain the number of passed 820 // Read the saved arguments descriptor array to obtain the number of passed
802 // arguments. 821 // arguments.
803 __ movq(kArgDescReg, Address(RBP, kArgumentsDescOffset)); 822 __ movq(kArgDescReg, Address(RBP, kArgumentsDescOffset));
804 __ movq(R10, Address(kArgDescReg, VMHandles::kOffsetOfRawPtrInHandle)); 823 __ movq(R10, Address(kArgDescReg, VMHandles::kOffsetOfRawPtrInHandle));
805 __ movq(RDX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 824 __ movq(RDX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
806 // Get rid of arguments pushed on the stack. 825 // Get rid of arguments pushed on the stack.
807 __ leaq(RSP, Address(RSP, RDX, TIMES_4, 0)); // RDX is a Smi. 826 __ leaq(RSP, Address(RSP, RDX, TIMES_4, 0)); // RDX is a Smi.
808 827
809 // Restore the saved top exit frame info and top resource back into the 828 // Restore the saved top exit frame info and top resource back into the
(...skipping 16 matching lines...) Expand all
826 __ ret(); 845 __ ret();
827 } 846 }
828 847
829 848
830 // Called for inline allocation of contexts. 849 // Called for inline allocation of contexts.
831 // Input: 850 // Input:
832 // R10: number of context variables. 851 // R10: number of context variables.
833 // Output: 852 // Output:
834 // RAX: new allocated RawContext object. 853 // RAX: new allocated RawContext object.
835 void StubCode::GenerateAllocateContextStub(Assembler* assembler) { 854 void StubCode::GenerateAllocateContextStub(Assembler* assembler) {
836 __ LoadObject(R12, Object::null_object()); 855 __ LoadObject(R9, Object::null_object());
837 if (FLAG_inline_alloc) { 856 if (FLAG_inline_alloc) {
838 Label slow_case; 857 Label slow_case;
839 // First compute the rounded instance size. 858 // First compute the rounded instance size.
840 // R10: number of context variables. 859 // R10: number of context variables.
841 intptr_t fixed_size = (sizeof(RawContext) + kObjectAlignment - 1); 860 intptr_t fixed_size = (sizeof(RawContext) + kObjectAlignment - 1);
842 __ leaq(R13, Address(R10, TIMES_8, fixed_size)); 861 __ leaq(R13, Address(R10, TIMES_8, fixed_size));
843 __ andq(R13, Immediate(-kObjectAlignment)); 862 __ andq(R13, Immediate(-kObjectAlignment));
844 863
845 // Check for allocation tracing. 864 // Check for allocation tracing.
846 __ MaybeTraceAllocation(kContextCid, 865 __ MaybeTraceAllocation(kContextCid,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 // RAX: new object. 929 // RAX: new object.
911 // R10: number of context variables as integer value (not object). 930 // R10: number of context variables as integer value (not object).
912 __ movq(FieldAddress(RAX, Context::num_variables_offset()), R10); 931 __ movq(FieldAddress(RAX, Context::num_variables_offset()), R10);
913 932
914 // Setup the parent field. 933 // Setup the parent field.
915 // RAX: new object. 934 // RAX: new object.
916 // R10: number of context variables. 935 // R10: number of context variables.
917 // No generational barrier needed, since we are storing null. 936 // No generational barrier needed, since we are storing null.
918 __ InitializeFieldNoBarrier(RAX, 937 __ InitializeFieldNoBarrier(RAX,
919 FieldAddress(RAX, Context::parent_offset()), 938 FieldAddress(RAX, Context::parent_offset()),
920 R12); 939 R9);
921 940
922 // Initialize the context variables. 941 // Initialize the context variables.
923 // RAX: new object. 942 // RAX: new object.
924 // R10: number of context variables. 943 // R10: number of context variables.
925 { 944 {
926 Label loop, entry; 945 Label loop, entry;
927 __ leaq(R13, FieldAddress(RAX, Context::variable_offset(0))); 946 __ leaq(R13, FieldAddress(RAX, Context::variable_offset(0)));
928 #if defined(DEBUG) 947 #if defined(DEBUG)
929 static const bool kJumpLength = Assembler::kFarJump; 948 static const bool kJumpLength = Assembler::kFarJump;
930 #else 949 #else
931 static const bool kJumpLength = Assembler::kNearJump; 950 static const bool kJumpLength = Assembler::kNearJump;
932 #endif // DEBUG 951 #endif // DEBUG
933 __ jmp(&entry, kJumpLength); 952 __ jmp(&entry, kJumpLength);
934 __ Bind(&loop); 953 __ Bind(&loop);
935 __ decq(R10); 954 __ decq(R10);
936 // No generational barrier needed, since we are storing null. 955 // No generational barrier needed, since we are storing null.
937 __ InitializeFieldNoBarrier(RAX, 956 __ InitializeFieldNoBarrier(RAX,
938 Address(R13, R10, TIMES_8, 0), 957 Address(R13, R10, TIMES_8, 0),
939 R12); 958 R9);
940 __ Bind(&entry); 959 __ Bind(&entry);
941 __ cmpq(R10, Immediate(0)); 960 __ cmpq(R10, Immediate(0));
942 __ j(NOT_EQUAL, &loop, Assembler::kNearJump); 961 __ j(NOT_EQUAL, &loop, Assembler::kNearJump);
943 } 962 }
944 963
945 // Done allocating and initializing the context. 964 // Done allocating and initializing the context.
946 // RAX: new object. 965 // RAX: new object.
947 __ ret(); 966 __ ret();
948 967
949 __ Bind(&slow_case); 968 __ Bind(&slow_case);
950 } 969 }
951 // Create a stub frame. 970 // Create a stub frame.
952 __ EnterStubFrame(); 971 __ EnterStubFrame();
953 __ pushq(R12); // Setup space on stack for the return value. 972 __ pushq(R9); // Setup space on stack for the return value.
954 __ SmiTag(R10); 973 __ SmiTag(R10);
955 __ pushq(R10); // Push number of context variables. 974 __ pushq(R10); // Push number of context variables.
956 __ CallRuntime(kAllocateContextRuntimeEntry, 1); // Allocate context. 975 __ CallRuntime(kAllocateContextRuntimeEntry, 1); // Allocate context.
957 __ popq(RAX); // Pop number of context variables argument. 976 __ popq(RAX); // Pop number of context variables argument.
958 __ popq(RAX); // Pop the new context object. 977 __ popq(RAX); // Pop the new context object.
959 // RAX: new object 978 // RAX: new object
960 // Restore the frame pointer. 979 // Restore the frame pointer.
961 __ LeaveStubFrame(); 980 __ LeaveStubFrame();
962 __ ret(); 981 __ ret();
963 } 982 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 __ CallRuntime(kStoreBufferBlockProcessRuntimeEntry, 1); 1042 __ CallRuntime(kStoreBufferBlockProcessRuntimeEntry, 1);
1024 __ LeaveCallRuntimeFrame(); 1043 __ LeaveCallRuntimeFrame();
1025 __ ret(); 1044 __ ret();
1026 } 1045 }
1027 1046
1028 1047
1029 // Called for inline allocation of objects. 1048 // Called for inline allocation of objects.
1030 // Input parameters: 1049 // Input parameters:
1031 // RSP + 8 : type arguments object (only if class is parameterized). 1050 // RSP + 8 : type arguments object (only if class is parameterized).
1032 // RSP : points to return address. 1051 // RSP : points to return address.
1033 void StubCode::GenerateAllocationStubForClass( 1052 void StubCode::GenerateAllocationStubForClass(Assembler* assembler,
1034 Assembler* assembler, const Class& cls, 1053 const Class& cls) {
1035 uword* entry_patch_offset, uword* patch_code_pc_offset) {
1036 // Must load pool pointer before being able to patch.
1037 Register new_pp = R13;
1038 __ LoadPoolPointer(new_pp);
1039 *entry_patch_offset = assembler->CodeSize();
1040
1041 const intptr_t kObjectTypeArgumentsOffset = 1 * kWordSize; 1054 const intptr_t kObjectTypeArgumentsOffset = 1 * kWordSize;
1042 // The generated code is different if the class is parameterized. 1055 // The generated code is different if the class is parameterized.
1043 const bool is_cls_parameterized = cls.NumTypeArguments() > 0; 1056 const bool is_cls_parameterized = cls.NumTypeArguments() > 0;
1044 ASSERT(!is_cls_parameterized || 1057 ASSERT(!is_cls_parameterized ||
1045 (cls.type_arguments_field_offset() != Class::kNoTypeArguments)); 1058 (cls.type_arguments_field_offset() != Class::kNoTypeArguments));
1046 // kInlineInstanceSize is a constant used as a threshold for determining 1059 // kInlineInstanceSize is a constant used as a threshold for determining
1047 // when the object initialization should be done as a loop or as 1060 // when the object initialization should be done as a loop or as
1048 // straight line code. 1061 // straight line code.
1049 const int kInlineInstanceSize = 12; // In words. 1062 const int kInlineInstanceSize = 12; // In words.
1050 const intptr_t instance_size = cls.instance_size(); 1063 const intptr_t instance_size = cls.instance_size();
1051 ASSERT(instance_size > 0); 1064 ASSERT(instance_size > 0);
1052 __ LoadObject(R12, Object::null_object()); 1065 __ LoadObject(R9, Object::null_object());
1053 if (is_cls_parameterized) { 1066 if (is_cls_parameterized) {
1054 __ movq(RDX, Address(RSP, kObjectTypeArgumentsOffset)); 1067 __ movq(RDX, Address(RSP, kObjectTypeArgumentsOffset));
1055 // RDX: instantiated type arguments. 1068 // RDX: instantiated type arguments.
1056 } 1069 }
1057 Isolate* isolate = Isolate::Current(); 1070 Isolate* isolate = Isolate::Current();
1058 if (FLAG_inline_alloc && Heap::IsAllocatableInNewSpace(instance_size) && 1071 if (FLAG_inline_alloc && Heap::IsAllocatableInNewSpace(instance_size) &&
1059 !cls.TraceAllocation(isolate)) { 1072 !cls.TraceAllocation(isolate)) {
1060 Label slow_case; 1073 Label slow_case;
1061 // Allocate the object and update top to point to 1074 // Allocate the object and update top to point to
1062 // next object start and initialize the allocated object. 1075 // next object start and initialize the allocated object.
(...skipping 23 matching lines...) Expand all
1086 tags = RawObject::SizeTag::update(instance_size, tags); 1099 tags = RawObject::SizeTag::update(instance_size, tags);
1087 ASSERT(cls.id() != kIllegalCid); 1100 ASSERT(cls.id() != kIllegalCid);
1088 tags = RawObject::ClassIdTag::update(cls.id(), tags); 1101 tags = RawObject::ClassIdTag::update(cls.id(), tags);
1089 __ movq(Address(RAX, Instance::tags_offset()), Immediate(tags)); 1102 __ movq(Address(RAX, Instance::tags_offset()), Immediate(tags));
1090 __ addq(RAX, Immediate(kHeapObjectTag)); 1103 __ addq(RAX, Immediate(kHeapObjectTag));
1091 1104
1092 // Initialize the remaining words of the object. 1105 // Initialize the remaining words of the object.
1093 // RAX: new object (tagged). 1106 // RAX: new object (tagged).
1094 // RBX: next object start. 1107 // RBX: next object start.
1095 // RDX: new object type arguments (if is_cls_parameterized). 1108 // RDX: new object type arguments (if is_cls_parameterized).
1096 // R12: raw null. 1109 // R9: raw null.
1097 // First try inlining the initialization without a loop. 1110 // First try inlining the initialization without a loop.
1098 if (instance_size < (kInlineInstanceSize * kWordSize)) { 1111 if (instance_size < (kInlineInstanceSize * kWordSize)) {
1099 // Check if the object contains any non-header fields. 1112 // Check if the object contains any non-header fields.
1100 // Small objects are initialized using a consecutive set of writes. 1113 // Small objects are initialized using a consecutive set of writes.
1101 for (intptr_t current_offset = Instance::NextFieldOffset(); 1114 for (intptr_t current_offset = Instance::NextFieldOffset();
1102 current_offset < instance_size; 1115 current_offset < instance_size;
1103 current_offset += kWordSize) { 1116 current_offset += kWordSize) {
1104 __ InitializeFieldNoBarrier(RAX, 1117 __ InitializeFieldNoBarrier(RAX,
1105 FieldAddress(RAX, current_offset), 1118 FieldAddress(RAX, current_offset),
1106 R12); 1119 R9);
1107 } 1120 }
1108 } else { 1121 } else {
1109 __ leaq(RCX, FieldAddress(RAX, Instance::NextFieldOffset())); 1122 __ leaq(RCX, FieldAddress(RAX, Instance::NextFieldOffset()));
1110 // Loop until the whole object is initialized. 1123 // Loop until the whole object is initialized.
1111 // RAX: new object (tagged). 1124 // RAX: new object (tagged).
1112 // RBX: next object start. 1125 // RBX: next object start.
1113 // RCX: next word to be initialized. 1126 // RCX: next word to be initialized.
1114 // RDX: new object type arguments (if is_cls_parameterized). 1127 // RDX: new object type arguments (if is_cls_parameterized).
1115 Label init_loop; 1128 Label init_loop;
1116 Label done; 1129 Label done;
1117 __ Bind(&init_loop); 1130 __ Bind(&init_loop);
1118 __ cmpq(RCX, RBX); 1131 __ cmpq(RCX, RBX);
1119 #if defined(DEBUG) 1132 #if defined(DEBUG)
1120 static const bool kJumpLength = Assembler::kFarJump; 1133 static const bool kJumpLength = Assembler::kFarJump;
1121 #else 1134 #else
1122 static const bool kJumpLength = Assembler::kNearJump; 1135 static const bool kJumpLength = Assembler::kNearJump;
1123 #endif // DEBUG 1136 #endif // DEBUG
1124 __ j(ABOVE_EQUAL, &done, kJumpLength); 1137 __ j(ABOVE_EQUAL, &done, kJumpLength);
1125 __ InitializeFieldNoBarrier(RAX, Address(RCX, 0), R12); 1138 __ InitializeFieldNoBarrier(RAX, Address(RCX, 0), R9);
1126 __ addq(RCX, Immediate(kWordSize)); 1139 __ addq(RCX, Immediate(kWordSize));
1127 __ jmp(&init_loop, Assembler::kNearJump); 1140 __ jmp(&init_loop, Assembler::kNearJump);
1128 __ Bind(&done); 1141 __ Bind(&done);
1129 } 1142 }
1130 if (is_cls_parameterized) { 1143 if (is_cls_parameterized) {
1131 // RDX: new object type arguments. 1144 // RDX: new object type arguments.
1132 // Set the type arguments in the new object. 1145 // Set the type arguments in the new object.
1133 intptr_t offset = cls.type_arguments_field_offset(); 1146 intptr_t offset = cls.type_arguments_field_offset();
1134 __ InitializeFieldNoBarrier(RAX, FieldAddress(RAX, offset), RDX); 1147 __ InitializeFieldNoBarrier(RAX, FieldAddress(RAX, offset), RDX);
1135 } 1148 }
1136 // Done allocating and initializing the instance. 1149 // Done allocating and initializing the instance.
1137 // RAX: new object (tagged). 1150 // RAX: new object (tagged).
1138 __ ret(); 1151 __ ret();
1139 1152
1140 __ Bind(&slow_case); 1153 __ Bind(&slow_case);
1141 } 1154 }
1142 // If is_cls_parameterized: 1155 // If is_cls_parameterized:
1143 // RDX: new object type arguments. 1156 // RDX: new object type arguments.
1144 // Create a stub frame. 1157 // Create a stub frame.
1145 __ EnterStubFrame(); // Uses PP to access class object. 1158 __ EnterStubFrame(); // Uses PP to access class object.
1146 __ pushq(R12); // Setup space on stack for return value. 1159 __ pushq(R9); // Setup space on stack for return value.
1147 __ PushObject(cls); // Push class of object to be allocated. 1160 __ PushObject(cls); // Push class of object to be allocated.
1148 if (is_cls_parameterized) { 1161 if (is_cls_parameterized) {
1149 __ pushq(RDX); // Push type arguments of object to be allocated. 1162 __ pushq(RDX); // Push type arguments of object to be allocated.
1150 } else { 1163 } else {
1151 __ pushq(R12); // Push null type arguments. 1164 __ pushq(R9); // Push null type arguments.
1152 } 1165 }
1153 __ CallRuntime(kAllocateObjectRuntimeEntry, 2); // Allocate object. 1166 __ CallRuntime(kAllocateObjectRuntimeEntry, 2); // Allocate object.
1154 __ popq(RAX); // Pop argument (type arguments of object). 1167 __ popq(RAX); // Pop argument (type arguments of object).
1155 __ popq(RAX); // Pop argument (class of object). 1168 __ popq(RAX); // Pop argument (class of object).
1156 __ popq(RAX); // Pop result (newly allocated object). 1169 __ popq(RAX); // Pop result (newly allocated object).
1157 // RAX: new object 1170 // RAX: new object
1158 // Restore the frame pointer. 1171 // Restore the frame pointer.
1159 __ LeaveStubFrame(); 1172 __ LeaveStubFrame();
1160 __ ret(); 1173 __ ret();
1161 *patch_code_pc_offset = assembler->CodeSize();
1162 __ JmpPatchable(*StubCode::FixAllocationStubTarget_entry(), new_pp);
1163 } 1174 }
1164 1175
1165 1176
1166 // Called for invoking "dynamic noSuchMethod(Invocation invocation)" function 1177 // Called for invoking "dynamic noSuchMethod(Invocation invocation)" function
1167 // from the entry code of a dart function after an error in passed argument 1178 // from the entry code of a dart function after an error in passed argument
1168 // name or number is detected. 1179 // name or number is detected.
1169 // Input parameters: 1180 // Input parameters:
1170 // RSP : points to return address. 1181 // RSP : points to return address.
1171 // RSP + 8 : address of last argument. 1182 // RSP + 8 : address of last argument.
1172 // R10 : arguments descriptor array. 1183 // R10 : arguments descriptor array.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 Label* not_smi_or_overflow, 1249 Label* not_smi_or_overflow,
1239 bool should_update_result_range) { 1250 bool should_update_result_range) {
1240 __ Comment("Fast Smi op"); 1251 __ Comment("Fast Smi op");
1241 if (FLAG_throw_on_javascript_int_overflow) { 1252 if (FLAG_throw_on_javascript_int_overflow) {
1242 // The overflow check is more complex than implemented below. 1253 // The overflow check is more complex than implemented below.
1243 return; 1254 return;
1244 } 1255 }
1245 ASSERT(num_args == 2); 1256 ASSERT(num_args == 2);
1246 __ movq(RCX, Address(RSP, + 1 * kWordSize)); // Right 1257 __ movq(RCX, Address(RSP, + 1 * kWordSize)); // Right
1247 __ movq(RAX, Address(RSP, + 2 * kWordSize)); // Left. 1258 __ movq(RAX, Address(RSP, + 2 * kWordSize)); // Left.
1248 __ movq(R12, RCX); 1259 __ movq(R13, RCX);
1249 __ orq(R12, RAX); 1260 __ orq(R13, RAX);
1250 __ testq(R12, Immediate(kSmiTagMask)); 1261 __ testq(R13, Immediate(kSmiTagMask));
1251 __ j(NOT_ZERO, not_smi_or_overflow); 1262 __ j(NOT_ZERO, not_smi_or_overflow);
1252 switch (kind) { 1263 switch (kind) {
1253 case Token::kADD: { 1264 case Token::kADD: {
1254 __ addq(RAX, RCX); 1265 __ addq(RAX, RCX);
1255 __ j(OVERFLOW, not_smi_or_overflow); 1266 __ j(OVERFLOW, not_smi_or_overflow);
1256 break; 1267 break;
1257 } 1268 }
1258 case Token::kSUB: { 1269 case Token::kSUB: {
1259 __ subq(RAX, RCX); 1270 __ subq(RAX, RCX);
1260 __ j(OVERFLOW, not_smi_or_overflow); 1271 __ j(OVERFLOW, not_smi_or_overflow);
(...skipping 15 matching lines...) Expand all
1276 1287
1277 1288
1278 if (should_update_result_range) { 1289 if (should_update_result_range) {
1279 Label done; 1290 Label done;
1280 __ movq(RSI, RAX); 1291 __ movq(RSI, RAX);
1281 __ UpdateRangeFeedback(RSI, 2, RBX, RCX, &done); 1292 __ UpdateRangeFeedback(RSI, 2, RBX, RCX, &done);
1282 __ Bind(&done); 1293 __ Bind(&done);
1283 } 1294 }
1284 1295
1285 // RBX: IC data object (preserved). 1296 // RBX: IC data object (preserved).
1286 __ movq(R12, FieldAddress(RBX, ICData::ic_data_offset())); 1297 __ movq(R13, FieldAddress(RBX, ICData::ic_data_offset()));
1287 // R12: ic_data_array with check entries: classes and target functions. 1298 // R13: ic_data_array with check entries: classes and target functions.
1288 __ leaq(R12, FieldAddress(R12, Array::data_offset())); 1299 __ leaq(R13, FieldAddress(R13, Array::data_offset()));
1289 // R12: points directly to the first ic data array element. 1300 // R13: points directly to the first ic data array element.
1290 #if defined(DEBUG) 1301 #if defined(DEBUG)
1291 // Check that first entry is for Smi/Smi. 1302 // Check that first entry is for Smi/Smi.
1292 Label error, ok; 1303 Label error, ok;
1293 const Immediate& imm_smi_cid = 1304 const Immediate& imm_smi_cid =
1294 Immediate(reinterpret_cast<intptr_t>(Smi::New(kSmiCid))); 1305 Immediate(reinterpret_cast<intptr_t>(Smi::New(kSmiCid)));
1295 __ cmpq(Address(R12, 0 * kWordSize), imm_smi_cid); 1306 __ cmpq(Address(R13, 0 * kWordSize), imm_smi_cid);
1296 __ j(NOT_EQUAL, &error, Assembler::kNearJump); 1307 __ j(NOT_EQUAL, &error, Assembler::kNearJump);
1297 __ cmpq(Address(R12, 1 * kWordSize), imm_smi_cid); 1308 __ cmpq(Address(R13, 1 * kWordSize), imm_smi_cid);
1298 __ j(EQUAL, &ok, Assembler::kNearJump); 1309 __ j(EQUAL, &ok, Assembler::kNearJump);
1299 __ Bind(&error); 1310 __ Bind(&error);
1300 __ Stop("Incorrect IC data"); 1311 __ Stop("Incorrect IC data");
1301 __ Bind(&ok); 1312 __ Bind(&ok);
1302 #endif 1313 #endif
1303 1314
1304 if (FLAG_optimization_counter_threshold >= 0) { 1315 if (FLAG_optimization_counter_threshold >= 0) {
1305 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize; 1316 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize;
1306 // Update counter. 1317 // Update counter.
1307 __ movq(R8, Address(R12, count_offset)); 1318 __ movq(R8, Address(R13, count_offset));
1308 __ addq(R8, Immediate(Smi::RawValue(1))); 1319 __ addq(R8, Immediate(Smi::RawValue(1)));
1309 __ movq(R13, Immediate(Smi::RawValue(Smi::kMaxValue))); 1320 __ movq(R9, Immediate(Smi::RawValue(Smi::kMaxValue)));
1310 __ cmovnoq(R13, R8); 1321 __ cmovnoq(R9, R8);
1311 __ StoreIntoSmiField(Address(R12, count_offset), R13); 1322 __ StoreIntoSmiField(Address(R13, count_offset), R9);
1312 } 1323 }
1313 1324
1314 __ ret(); 1325 __ ret();
1315 } 1326 }
1316 1327
1317 1328
1318 // Generate inline cache check for 'num_args'. 1329 // Generate inline cache check for 'num_args'.
1319 // RBX: Inline cache data object. 1330 // RBX: Inline cache data object.
1320 // TOS(0): return address 1331 // TOS(0): return address
1321 // Control flow: 1332 // Control flow:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 range_collection_mode == kCollectRanges); 1388 range_collection_mode == kCollectRanges);
1378 } 1389 }
1379 __ Bind(&not_smi_or_overflow); 1390 __ Bind(&not_smi_or_overflow);
1380 1391
1381 __ Comment("Extract ICData initial values and receiver cid"); 1392 __ Comment("Extract ICData initial values and receiver cid");
1382 // Load arguments descriptor into R10. 1393 // Load arguments descriptor into R10.
1383 __ movq(R10, FieldAddress(RBX, ICData::arguments_descriptor_offset())); 1394 __ movq(R10, FieldAddress(RBX, ICData::arguments_descriptor_offset()));
1384 // Loop that checks if there is an IC data match. 1395 // Loop that checks if there is an IC data match.
1385 Label loop, update, test, found; 1396 Label loop, update, test, found;
1386 // RBX: IC data object (preserved). 1397 // RBX: IC data object (preserved).
1387 __ movq(R12, FieldAddress(RBX, ICData::ic_data_offset())); 1398 __ movq(R13, FieldAddress(RBX, ICData::ic_data_offset()));
1388 // R12: ic_data_array with check entries: classes and target functions. 1399 // R13: ic_data_array with check entries: classes and target functions.
1389 __ leaq(R12, FieldAddress(R12, Array::data_offset())); 1400 __ leaq(R13, FieldAddress(R13, Array::data_offset()));
1390 // R12: points directly to the first ic data array element. 1401 // R13: points directly to the first ic data array element.
1391 1402
1392 // Get the receiver's class ID (first read number of arguments from 1403 // Get the receiver's class ID (first read number of arguments from
1393 // arguments descriptor array and then access the receiver from the stack). 1404 // arguments descriptor array and then access the receiver from the stack).
1394 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 1405 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
1395 __ movq(R13, Address(RSP, RAX, TIMES_4, 0)); // RAX (argument count) is Smi. 1406 __ movq(R9, Address(RSP, RAX, TIMES_4, 0)); // RAX (argument count) is Smi.
1396 __ LoadTaggedClassIdMayBeSmi(RAX, R13); 1407 __ LoadTaggedClassIdMayBeSmi(RAX, R9);
1397 // RAX: receiver's class ID as smi. 1408 // RAX: receiver's class ID as smi.
1398 __ movq(R13, Address(R12, 0)); // First class ID (Smi) to check. 1409 __ movq(R9, Address(R13, 0)); // First class ID (Smi) to check.
1399 __ jmp(&test); 1410 __ jmp(&test);
1400 1411
1401 __ Comment("ICData loop"); 1412 __ Comment("ICData loop");
1402 __ Bind(&loop); 1413 __ Bind(&loop);
1403 for (int i = 0; i < num_args; i++) { 1414 for (int i = 0; i < num_args; i++) {
1404 if (i > 0) { 1415 if (i > 0) {
1405 // If not the first, load the next argument's class ID. 1416 // If not the first, load the next argument's class ID.
1406 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 1417 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
1407 __ movq(R13, Address(RSP, RAX, TIMES_4, - i * kWordSize)); 1418 __ movq(R9, Address(RSP, RAX, TIMES_4, - i * kWordSize));
1408 __ LoadTaggedClassIdMayBeSmi(RAX, R13); 1419 __ LoadTaggedClassIdMayBeSmi(RAX, R9);
1409 // RAX: next argument class ID (smi). 1420 // RAX: next argument class ID (smi).
1410 __ movq(R13, Address(R12, i * kWordSize)); 1421 __ movq(R9, Address(R13, i * kWordSize));
1411 // R13: next class ID to check (smi). 1422 // R9: next class ID to check (smi).
1412 } 1423 }
1413 __ cmpq(RAX, R13); // Class id match? 1424 __ cmpq(RAX, R9); // Class id match?
1414 if (i < (num_args - 1)) { 1425 if (i < (num_args - 1)) {
1415 __ j(NOT_EQUAL, &update); // Continue. 1426 __ j(NOT_EQUAL, &update); // Continue.
1416 } else { 1427 } else {
1417 // Last check, all checks before matched. 1428 // Last check, all checks before matched.
1418 __ j(EQUAL, &found); // Break. 1429 __ j(EQUAL, &found); // Break.
1419 } 1430 }
1420 } 1431 }
1421 __ Bind(&update); 1432 __ Bind(&update);
1422 // Reload receiver class ID. It has not been destroyed when num_args == 1. 1433 // Reload receiver class ID. It has not been destroyed when num_args == 1.
1423 if (num_args > 1) { 1434 if (num_args > 1) {
1424 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 1435 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
1425 __ movq(R13, Address(RSP, RAX, TIMES_4, 0)); 1436 __ movq(R9, Address(RSP, RAX, TIMES_4, 0));
1426 __ LoadTaggedClassIdMayBeSmi(RAX, R13); 1437 __ LoadTaggedClassIdMayBeSmi(RAX, R9);
1427 } 1438 }
1428 1439
1429 const intptr_t entry_size = ICData::TestEntryLengthFor(num_args) * kWordSize; 1440 const intptr_t entry_size = ICData::TestEntryLengthFor(num_args) * kWordSize;
1430 __ addq(R12, Immediate(entry_size)); // Next entry. 1441 __ addq(R13, Immediate(entry_size)); // Next entry.
1431 __ movq(R13, Address(R12, 0)); // Next class ID. 1442 __ movq(R9, Address(R13, 0)); // Next class ID.
1432 1443
1433 __ Bind(&test); 1444 __ Bind(&test);
1434 __ cmpq(R13, Immediate(Smi::RawValue(kIllegalCid))); // Done? 1445 __ cmpq(R9, Immediate(Smi::RawValue(kIllegalCid))); // Done?
1435 __ j(NOT_EQUAL, &loop, Assembler::kNearJump); 1446 __ j(NOT_EQUAL, &loop, Assembler::kNearJump);
1436 1447
1437 __ Comment("IC miss"); 1448 __ Comment("IC miss");
1438 __ LoadObject(R12, Object::null_object()); 1449 __ LoadObject(R13, Object::null_object());
1439 // Compute address of arguments (first read number of arguments from 1450 // Compute address of arguments (first read number of arguments from
1440 // arguments descriptor array and then compute address on the stack). 1451 // arguments descriptor array and then compute address on the stack).
1441 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); 1452 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset()));
1442 __ leaq(RAX, Address(RSP, RAX, TIMES_4, 0)); // RAX is Smi. 1453 __ leaq(RAX, Address(RSP, RAX, TIMES_4, 0)); // RAX is Smi.
1443 __ EnterStubFrame(); 1454 __ EnterStubFrame();
1444 __ pushq(R10); // Preserve arguments descriptor array. 1455 __ pushq(R10); // Preserve arguments descriptor array.
1445 __ pushq(RBX); // Preserve IC data object. 1456 __ pushq(RBX); // Preserve IC data object.
1446 __ pushq(R12); // Setup space on stack for result (target code object). 1457 __ pushq(R13); // Setup space on stack for result (target code object).
1447 // Push call arguments. 1458 // Push call arguments.
1448 for (intptr_t i = 0; i < num_args; i++) { 1459 for (intptr_t i = 0; i < num_args; i++) {
1449 __ movq(RCX, Address(RAX, -kWordSize * i)); 1460 __ movq(RCX, Address(RAX, -kWordSize * i));
1450 __ pushq(RCX); 1461 __ pushq(RCX);
1451 } 1462 }
1452 __ pushq(RBX); // Pass IC data object. 1463 __ pushq(RBX); // Pass IC data object.
1453 __ CallRuntime(handle_ic_miss, num_args + 1); 1464 __ CallRuntime(handle_ic_miss, num_args + 1);
1454 // Remove the call arguments pushed earlier, including the IC data object. 1465 // Remove the call arguments pushed earlier, including the IC data object.
1455 for (intptr_t i = 0; i < num_args + 1; i++) { 1466 for (intptr_t i = 0; i < num_args + 1; i++) {
1456 __ popq(RAX); 1467 __ popq(RAX);
1457 } 1468 }
1458 __ popq(RAX); // Pop returned function object into RAX. 1469 __ popq(RAX); // Pop returned function object into RAX.
1459 __ popq(RBX); // Restore IC data array. 1470 __ popq(RBX); // Restore IC data array.
1460 __ popq(R10); // Restore arguments descriptor array. 1471 __ popq(R10); // Restore arguments descriptor array.
1472 if (range_collection_mode == kCollectRanges) {
1473 __ RestoreCodePointer();
1474 }
1461 __ LeaveStubFrame(); 1475 __ LeaveStubFrame();
1462 Label call_target_function; 1476 Label call_target_function;
1463 if (!FLAG_lazy_dispatchers) { 1477 if (!FLAG_lazy_dispatchers) {
1464 GenerateDispatcherCode(assembler, &call_target_function); 1478 GenerateDispatcherCode(assembler, &call_target_function);
1465 } else { 1479 } else {
1466 __ jmp(&call_target_function); 1480 __ jmp(&call_target_function);
1467 } 1481 }
1468 1482
1469 __ Bind(&found); 1483 __ Bind(&found);
1470 // R12: Pointer to an IC data check group. 1484 // R13: Pointer to an IC data check group.
1471 const intptr_t target_offset = ICData::TargetIndexFor(num_args) * kWordSize; 1485 const intptr_t target_offset = ICData::TargetIndexFor(num_args) * kWordSize;
1472 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize; 1486 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize;
1473 __ movq(RAX, Address(R12, target_offset)); 1487 __ movq(RAX, Address(R13, target_offset));
1474 1488
1475 if (FLAG_optimization_counter_threshold >= 0) { 1489 if (FLAG_optimization_counter_threshold >= 0) {
1476 // Update counter. 1490 // Update counter.
1477 __ Comment("Update caller's counter"); 1491 __ Comment("Update caller's counter");
1478 __ movq(R8, Address(R12, count_offset)); 1492 __ movq(R8, Address(R13, count_offset));
1479 __ addq(R8, Immediate(Smi::RawValue(1))); 1493 __ addq(R8, Immediate(Smi::RawValue(1)));
1480 __ movq(R13, Immediate(Smi::RawValue(Smi::kMaxValue))); 1494 __ movq(R9, Immediate(Smi::RawValue(Smi::kMaxValue)));
1481 __ cmovnoq(R13, R8); 1495 __ cmovnoq(R9, R8);
1482 __ StoreIntoSmiField(Address(R12, count_offset), R13); 1496 __ StoreIntoSmiField(Address(R13, count_offset), R9);
1483 } 1497 }
1484 1498
1485 __ Comment("Call target"); 1499 __ Comment("Call target");
1486 __ Bind(&call_target_function); 1500 __ Bind(&call_target_function);
1487 // RAX: Target function. 1501 // RAX: Target function.
1488 Label is_compiled; 1502 Label is_compiled;
1489 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset()));
1490 if (range_collection_mode == kCollectRanges) { 1503 if (range_collection_mode == kCollectRanges) {
1504 __ movq(R13, FieldAddress(RAX, Function::code_offset()));
1505 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset()));
1491 __ movq(R8, Address(RSP, + 1 * kWordSize)); 1506 __ movq(R8, Address(RSP, + 1 * kWordSize));
1492 if (num_args == 2) { 1507 if (num_args == 2) {
1493 __ movq(R13, Address(RSP, + 2 * kWordSize)); 1508 __ movq(R9, Address(RSP, + 2 * kWordSize));
1494 } 1509 }
1495 __ EnterStubFrame(); 1510 __ EnterStubFrame();
1496 __ pushq(RBX); 1511 __ pushq(RBX);
1497 if (num_args == 2) { 1512 if (num_args == 2) {
1498 __ pushq(R13); 1513 __ pushq(R9);
1499 } 1514 }
1500 __ pushq(R8); 1515 __ pushq(R8);
1516 __ movq(CODE_REG, R13);
1501 __ call(RCX); 1517 __ call(RCX);
1502 1518
1503 Label done; 1519 Label done;
1504 __ movq(RDX, RAX); 1520 __ movq(RDX, RAX);
1505 __ movq(RBX, Address(RBP, kFirstLocalSlotFromFp * kWordSize)); 1521 __ movq(RBX, Address(RBP, kFirstLocalSlotFromFp * kWordSize));
1506 __ UpdateRangeFeedback(RDX, 2, RBX, RCX, &done); 1522 __ UpdateRangeFeedback(RDX, 2, RBX, RCX, &done);
1507 __ Bind(&done); 1523 __ Bind(&done);
1508 __ LeaveStubFrame(); 1524 __ LeaveStubFrame();
1509 __ ret(); 1525 __ ret();
1510 } else { 1526 } else {
1527 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset()));
1528 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset()));
1511 __ jmp(RCX); 1529 __ jmp(RCX);
1512 } 1530 }
1513 1531
1514 if (FLAG_support_debugger && !optimized) { 1532 if (FLAG_support_debugger && !optimized) {
1515 __ Bind(&stepping); 1533 __ Bind(&stepping);
1516 __ EnterStubFrame(); 1534 __ EnterStubFrame();
1517 __ pushq(RBX); 1535 __ pushq(RBX);
1518 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0); 1536 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0);
1519 __ popq(RBX); 1537 __ popq(RBX);
1538 __ RestoreCodePointer();
1520 __ LeaveStubFrame(); 1539 __ LeaveStubFrame();
1521 __ jmp(&done_stepping); 1540 __ jmp(&done_stepping);
1522 } 1541 }
1523 } 1542 }
1524 1543
1525 1544
1526 // Use inline cache data array to invoke the target or continue in inline 1545 // Use inline cache data array to invoke the target or continue in inline
1527 // cache miss handler. Stub for 1-argument check (receiver class). 1546 // cache miss handler. Stub for 1-argument check (receiver class).
1528 // RBX: Inline cache data object. 1547 // RBX: Inline cache data object.
1529 // TOS(0): Return address. 1548 // TOS(0): Return address.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 __ movq(R13, Immediate(Smi::RawValue(Smi::kMaxValue))); 1697 __ movq(R13, Immediate(Smi::RawValue(Smi::kMaxValue)));
1679 __ cmovnoq(R13, R8); 1698 __ cmovnoq(R13, R8);
1680 __ StoreIntoSmiField(Address(R12, count_offset), R13); 1699 __ StoreIntoSmiField(Address(R12, count_offset), R13);
1681 } 1700 }
1682 1701
1683 // Load arguments descriptor into R10. 1702 // Load arguments descriptor into R10.
1684 __ movq(R10, FieldAddress(RBX, ICData::arguments_descriptor_offset())); 1703 __ movq(R10, FieldAddress(RBX, ICData::arguments_descriptor_offset()));
1685 1704
1686 // Get function and call it, if possible. 1705 // Get function and call it, if possible.
1687 __ movq(RAX, Address(R12, target_offset)); 1706 __ movq(RAX, Address(R12, target_offset));
1707 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset()));
1688 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset())); 1708 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset()));
1689 __ jmp(RCX); 1709 __ jmp(RCX);
1690 1710
1691 if (FLAG_support_debugger) { 1711 if (FLAG_support_debugger) {
1692 __ Bind(&stepping); 1712 __ Bind(&stepping);
1693 __ EnterStubFrame(); 1713 __ EnterStubFrame();
1694 __ pushq(RBX); // Preserve IC data object. 1714 __ pushq(RBX); // Preserve IC data object.
1695 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0); 1715 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0);
1696 __ popq(RBX); 1716 __ popq(RBX);
1717 __ RestoreCodePointer();
1697 __ LeaveStubFrame(); 1718 __ LeaveStubFrame();
1698 __ jmp(&done_stepping, Assembler::kNearJump); 1719 __ jmp(&done_stepping, Assembler::kNearJump);
1699 } 1720 }
1700 } 1721 }
1701 1722
1702 1723
1703 void StubCode::GenerateOneArgUnoptimizedStaticCallStub(Assembler* assembler) { 1724 void StubCode::GenerateOneArgUnoptimizedStaticCallStub(Assembler* assembler) {
1704 GenerateUsageCounterIncrement(assembler, RCX); 1725 GenerateUsageCounterIncrement(assembler, RCX);
1705 GenerateNArgsCheckInlineCacheStub( 1726 GenerateNArgsCheckInlineCacheStub(
1706 assembler, 1727 assembler,
(...skipping 22 matching lines...) Expand all
1729 __ EnterStubFrame(); 1750 __ EnterStubFrame();
1730 __ pushq(R10); // Preserve arguments descriptor array. 1751 __ pushq(R10); // Preserve arguments descriptor array.
1731 __ pushq(RBX); // Preserve IC data object. 1752 __ pushq(RBX); // Preserve IC data object.
1732 __ pushq(RAX); // Pass function. 1753 __ pushq(RAX); // Pass function.
1733 __ CallRuntime(kCompileFunctionRuntimeEntry, 1); 1754 __ CallRuntime(kCompileFunctionRuntimeEntry, 1);
1734 __ popq(RAX); // Restore function. 1755 __ popq(RAX); // Restore function.
1735 __ popq(RBX); // Restore IC data array. 1756 __ popq(RBX); // Restore IC data array.
1736 __ popq(R10); // Restore arguments descriptor array. 1757 __ popq(R10); // Restore arguments descriptor array.
1737 __ LeaveStubFrame(); 1758 __ LeaveStubFrame();
1738 1759
1760 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset()));
1739 __ movq(RAX, FieldAddress(RAX, Function::entry_point_offset())); 1761 __ movq(RAX, FieldAddress(RAX, Function::entry_point_offset()));
1740 __ jmp(RAX); 1762 __ jmp(RAX);
1741 } 1763 }
1742 1764
1743 1765
1744 // RBX: Contains an ICData. 1766 // RBX: Contains an ICData.
1745 // TOS(0): return address (Dart code). 1767 // TOS(0): return address (Dart code).
1746 void StubCode::GenerateICCallBreakpointStub(Assembler* assembler) { 1768 void StubCode::GenerateICCallBreakpointStub(Assembler* assembler) {
1747 __ EnterStubFrame(); 1769 __ EnterStubFrame();
1748 // Preserve IC data. 1770 // Preserve IC data.
1749 __ pushq(RBX); 1771 __ pushq(RBX);
1750 // Room for result. Debugger stub returns address of the 1772 // Room for result. Debugger stub returns address of the
1751 // unpatched runtime stub. 1773 // unpatched runtime stub.
1752 __ LoadObject(R12, Object::null_object()); 1774 __ LoadObject(R12, Object::null_object());
1753 __ pushq(R12); // Room for result. 1775 __ pushq(R12); // Room for result.
1754 __ CallRuntime(kBreakpointRuntimeHandlerRuntimeEntry, 0); 1776 __ CallRuntime(kBreakpointRuntimeHandlerRuntimeEntry, 0);
1755 __ popq(RAX); // Address of original. 1777 __ popq(CODE_REG); // Address of original.
1756 __ popq(RBX); // Restore IC data. 1778 __ popq(RBX); // Restore IC data.
1757 __ LeaveStubFrame(); 1779 __ LeaveStubFrame();
1780
1781 __ movq(RAX, FieldAddress(CODE_REG, Code::entry_point_offset()));
1758 __ jmp(RAX); // Jump to original stub. 1782 __ jmp(RAX); // Jump to original stub.
1759 } 1783 }
1760 1784
1761 1785
1762 // TOS(0): return address (Dart code). 1786 // TOS(0): return address (Dart code).
1763 void StubCode::GenerateRuntimeCallBreakpointStub(Assembler* assembler) { 1787 void StubCode::GenerateRuntimeCallBreakpointStub(Assembler* assembler) {
1764 __ EnterStubFrame(); 1788 __ EnterStubFrame();
1765 // Room for result. Debugger stub returns address of the 1789 // Room for result. Debugger stub returns address of the
1766 // unpatched runtime stub. 1790 // unpatched runtime stub.
1767 __ LoadObject(R12, Object::null_object()); 1791 __ LoadObject(R12, Object::null_object());
1768 __ pushq(R12); // Room for result. 1792 __ pushq(R12); // Room for result.
1769 __ CallRuntime(kBreakpointRuntimeHandlerRuntimeEntry, 0); 1793 __ CallRuntime(kBreakpointRuntimeHandlerRuntimeEntry, 0);
1770 __ popq(RAX); // Address of original. 1794 __ popq(CODE_REG); // Address of original.
1771 __ LeaveStubFrame(); 1795 __ LeaveStubFrame();
1796
1797 __ movq(RAX, FieldAddress(CODE_REG, Code::entry_point_offset()));
1772 __ jmp(RAX); // Jump to original stub. 1798 __ jmp(RAX); // Jump to original stub.
1773 } 1799 }
1774 1800
1775 1801
1776 // Called only from unoptimized code. 1802 // Called only from unoptimized code.
1777 void StubCode::GenerateDebugStepCheckStub(Assembler* assembler) { 1803 void StubCode::GenerateDebugStepCheckStub(Assembler* assembler) {
1778 // Check single stepping. 1804 // Check single stepping.
1779 Label stepping, done_stepping; 1805 Label stepping, done_stepping;
1780 __ LoadIsolate(RAX); 1806 __ LoadIsolate(RAX);
1781 __ movzxb(RAX, Address(RAX, Isolate::single_step_offset())); 1807 __ movzxb(RAX, Address(RAX, Isolate::single_step_offset()));
(...skipping 15 matching lines...) Expand all
1797 // TOS + 1: instantiator type arguments (can be NULL). 1823 // TOS + 1: instantiator type arguments (can be NULL).
1798 // TOS + 2: instance. 1824 // TOS + 2: instance.
1799 // TOS + 3: SubtypeTestCache. 1825 // TOS + 3: SubtypeTestCache.
1800 // Result in RCX: null -> not found, otherwise result (true or false). 1826 // Result in RCX: null -> not found, otherwise result (true or false).
1801 static void GenerateSubtypeNTestCacheStub(Assembler* assembler, int n) { 1827 static void GenerateSubtypeNTestCacheStub(Assembler* assembler, int n) {
1802 ASSERT((1 <= n) && (n <= 3)); 1828 ASSERT((1 <= n) && (n <= 3));
1803 const intptr_t kInstantiatorTypeArgumentsInBytes = 1 * kWordSize; 1829 const intptr_t kInstantiatorTypeArgumentsInBytes = 1 * kWordSize;
1804 const intptr_t kInstanceOffsetInBytes = 2 * kWordSize; 1830 const intptr_t kInstanceOffsetInBytes = 2 * kWordSize;
1805 const intptr_t kCacheOffsetInBytes = 3 * kWordSize; 1831 const intptr_t kCacheOffsetInBytes = 3 * kWordSize;
1806 __ movq(RAX, Address(RSP, kInstanceOffsetInBytes)); 1832 __ movq(RAX, Address(RSP, kInstanceOffsetInBytes));
1807 __ LoadObject(R12, Object::null_object()); 1833 __ LoadObject(R9, Object::null_object());
1808 if (n > 1) { 1834 if (n > 1) {
1809 __ LoadClass(R10, RAX); 1835 __ LoadClass(R10, RAX);
1810 // Compute instance type arguments into R13. 1836 // Compute instance type arguments into R13.
1811 Label has_no_type_arguments; 1837 Label has_no_type_arguments;
1812 __ movq(R13, R12); 1838 __ movq(R13, R9);
1813 __ movl(RDI, FieldAddress(R10, 1839 __ movl(RDI, FieldAddress(R10,
1814 Class::type_arguments_field_offset_in_words_offset())); 1840 Class::type_arguments_field_offset_in_words_offset()));
1815 __ cmpl(RDI, Immediate(Class::kNoTypeArguments)); 1841 __ cmpl(RDI, Immediate(Class::kNoTypeArguments));
1816 __ j(EQUAL, &has_no_type_arguments, Assembler::kNearJump); 1842 __ j(EQUAL, &has_no_type_arguments, Assembler::kNearJump);
1817 __ movq(R13, FieldAddress(RAX, RDI, TIMES_8, 0)); 1843 __ movq(R13, FieldAddress(RAX, RDI, TIMES_8, 0));
1818 __ Bind(&has_no_type_arguments); 1844 __ Bind(&has_no_type_arguments);
1819 } 1845 }
1820 __ LoadClassId(R10, RAX); 1846 __ LoadClassId(R10, RAX);
1821 // RAX: instance, R10: instance class id. 1847 // RAX: instance, R10: instance class id.
1822 // R13: instance type arguments or null, used only if n > 1. 1848 // R13: instance type arguments or null, used only if n > 1.
1823 __ movq(RDX, Address(RSP, kCacheOffsetInBytes)); 1849 __ movq(RDX, Address(RSP, kCacheOffsetInBytes));
1824 // RDX: SubtypeTestCache. 1850 // RDX: SubtypeTestCache.
1825 __ movq(RDX, FieldAddress(RDX, SubtypeTestCache::cache_offset())); 1851 __ movq(RDX, FieldAddress(RDX, SubtypeTestCache::cache_offset()));
1826 __ addq(RDX, Immediate(Array::data_offset() - kHeapObjectTag)); 1852 __ addq(RDX, Immediate(Array::data_offset() - kHeapObjectTag));
1827 // RDX: Entry start. 1853 // RDX: Entry start.
1828 // R10: instance class id. 1854 // R10: instance class id.
1829 // R13: instance type arguments. 1855 // R13: instance type arguments.
1830 Label loop, found, not_found, next_iteration; 1856 Label loop, found, not_found, next_iteration;
1831 __ SmiTag(R10); 1857 __ SmiTag(R10);
1832 __ Bind(&loop); 1858 __ Bind(&loop);
1833 __ movq(RDI, Address(RDX, kWordSize * SubtypeTestCache::kInstanceClassId)); 1859 __ movq(RDI, Address(RDX, kWordSize * SubtypeTestCache::kInstanceClassId));
1834 __ cmpq(RDI, R12); 1860 __ cmpq(RDI, R9);
1835 __ j(EQUAL, &not_found, Assembler::kNearJump); 1861 __ j(EQUAL, &not_found, Assembler::kNearJump);
1836 __ cmpq(RDI, R10); 1862 __ cmpq(RDI, R10);
1837 if (n == 1) { 1863 if (n == 1) {
1838 __ j(EQUAL, &found, Assembler::kNearJump); 1864 __ j(EQUAL, &found, Assembler::kNearJump);
1839 } else { 1865 } else {
1840 __ j(NOT_EQUAL, &next_iteration, Assembler::kNearJump); 1866 __ j(NOT_EQUAL, &next_iteration, Assembler::kNearJump);
1841 __ movq(RDI, 1867 __ movq(RDI,
1842 Address(RDX, kWordSize * SubtypeTestCache::kInstanceTypeArguments)); 1868 Address(RDX, kWordSize * SubtypeTestCache::kInstanceTypeArguments));
1843 __ cmpq(RDI, R13); 1869 __ cmpq(RDI, R13);
1844 if (n == 2) { 1870 if (n == 2) {
1845 __ j(EQUAL, &found, Assembler::kNearJump); 1871 __ j(EQUAL, &found, Assembler::kNearJump);
1846 } else { 1872 } else {
1847 __ j(NOT_EQUAL, &next_iteration, Assembler::kNearJump); 1873 __ j(NOT_EQUAL, &next_iteration, Assembler::kNearJump);
1848 __ movq(RDI, 1874 __ movq(RDI,
1849 Address(RDX, 1875 Address(RDX,
1850 kWordSize * SubtypeTestCache::kInstantiatorTypeArguments)); 1876 kWordSize * SubtypeTestCache::kInstantiatorTypeArguments));
1851 __ cmpq(RDI, Address(RSP, kInstantiatorTypeArgumentsInBytes)); 1877 __ cmpq(RDI, Address(RSP, kInstantiatorTypeArgumentsInBytes));
1852 __ j(EQUAL, &found, Assembler::kNearJump); 1878 __ j(EQUAL, &found, Assembler::kNearJump);
1853 } 1879 }
1854 } 1880 }
1855 1881
1856 __ Bind(&next_iteration); 1882 __ Bind(&next_iteration);
1857 __ addq(RDX, Immediate(kWordSize * SubtypeTestCache::kTestEntryLength)); 1883 __ addq(RDX, Immediate(kWordSize * SubtypeTestCache::kTestEntryLength));
1858 __ jmp(&loop, Assembler::kNearJump); 1884 __ jmp(&loop, Assembler::kNearJump);
1859 // Fall through to not found. 1885 // Fall through to not found.
1860 __ Bind(&not_found); 1886 __ Bind(&not_found);
1861 __ movq(RCX, R12); 1887 __ movq(RCX, R9);
1862 __ ret(); 1888 __ ret();
1863 1889
1864 __ Bind(&found); 1890 __ Bind(&found);
1865 __ movq(RCX, Address(RDX, kWordSize * SubtypeTestCache::kTestResult)); 1891 __ movq(RCX, Address(RDX, kWordSize * SubtypeTestCache::kTestResult));
1866 __ ret(); 1892 __ ret();
1867 } 1893 }
1868 1894
1869 1895
1870 // Used to check class and type arguments. Arguments passed on stack: 1896 // Used to check class and type arguments. Arguments passed on stack:
1871 // TOS + 0: return address. 1897 // TOS + 0: return address.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 // RDI: function to be reoptimized. 1980 // RDI: function to be reoptimized.
1955 // R10: argument descriptor (preserved). 1981 // R10: argument descriptor (preserved).
1956 void StubCode::GenerateOptimizeFunctionStub(Assembler* assembler) { 1982 void StubCode::GenerateOptimizeFunctionStub(Assembler* assembler) {
1957 __ EnterStubFrame(); 1983 __ EnterStubFrame();
1958 __ LoadObject(R12, Object::null_object()); 1984 __ LoadObject(R12, Object::null_object());
1959 __ pushq(R10); 1985 __ pushq(R10);
1960 __ pushq(R12); // Setup space on stack for return value. 1986 __ pushq(R12); // Setup space on stack for return value.
1961 __ pushq(RDI); 1987 __ pushq(RDI);
1962 __ CallRuntime(kOptimizeInvokedFunctionRuntimeEntry, 1); 1988 __ CallRuntime(kOptimizeInvokedFunctionRuntimeEntry, 1);
1963 __ popq(RAX); // Disard argument. 1989 __ popq(RAX); // Disard argument.
1964 __ popq(RAX); // Get Code object. 1990 __ popq(CODE_REG); // Get Code object.
1965 __ popq(R10); // Restore argument descriptor. 1991 __ popq(R10); // Restore argument descriptor.
1966 __ movq(RAX, FieldAddress(RAX, Code::entry_point_offset())); 1992 __ movq(RAX, FieldAddress(CODE_REG, Code::entry_point_offset()));
1967 __ LeaveStubFrame(); 1993 __ LeaveStubFrame();
1968 __ jmp(RAX); 1994 __ jmp(RAX);
1969 __ int3(); 1995 __ int3();
1970 } 1996 }
1971 1997
1972 1998
1973 // Does identical check (object references are equal or not equal) with special 1999 // Does identical check (object references are equal or not equal) with special
1974 // checks for boxed numbers. 2000 // checks for boxed numbers.
1975 // Left and right are pushed on stack. 2001 // Left and right are pushed on stack.
1976 // Return ZF set. 2002 // Return ZF set.
1977 // Note: A Mint cannot contain a value that would fit in Smi, a Bigint 2003 // Note: A Mint cannot contain a value that would fit in Smi, a Bigint
1978 // cannot contain a value that fits in Mint or Smi. 2004 // cannot contain a value that fits in Mint or Smi.
1979 static void GenerateIdenticalWithNumberCheckStub(Assembler* assembler, 2005 static void GenerateIdenticalWithNumberCheckStub(Assembler* assembler,
1980 const Register left, 2006 const Register left,
1981 const Register right) { 2007 const Register right) {
1982 Label reference_compare, done, check_mint, check_bigint; 2008 Label reference_compare, done, check_mint, check_bigint;
1983 // If any of the arguments is Smi do reference compare. 2009 // If any of the arguments is Smi do reference compare.
1984 __ testq(left, Immediate(kSmiTagMask)); 2010 __ testq(left, Immediate(kSmiTagMask));
1985 __ j(ZERO, &reference_compare); 2011 __ j(ZERO, &reference_compare);
1986 __ testq(right, Immediate(kSmiTagMask)); 2012 __ testq(right, Immediate(kSmiTagMask));
1987 __ j(ZERO, &reference_compare); 2013 __ j(ZERO, &reference_compare);
1988 2014
1989 // Value compare for two doubles. 2015 // Value compare for two doubles.
1990 __ CompareClassId(left, kDoubleCid); 2016 __ CompareClassId(left, kDoubleCid);
1991 __ j(NOT_EQUAL, &check_mint, Assembler::kNearJump); 2017 __ j(NOT_EQUAL, &check_mint, Assembler::kNearJump);
1992 __ CompareClassId(right, kDoubleCid); 2018 __ CompareClassId(right, kDoubleCid);
1993 __ j(NOT_EQUAL, &done, Assembler::kNearJump); 2019 __ j(NOT_EQUAL, &done, Assembler::kFarJump);
1994 2020
1995 // Double values bitwise compare. 2021 // Double values bitwise compare.
1996 __ movq(left, FieldAddress(left, Double::value_offset())); 2022 __ movq(left, FieldAddress(left, Double::value_offset()));
1997 __ cmpq(left, FieldAddress(right, Double::value_offset())); 2023 __ cmpq(left, FieldAddress(right, Double::value_offset()));
1998 __ jmp(&done, Assembler::kNearJump); 2024 __ jmp(&done, Assembler::kFarJump);
1999 2025
2000 __ Bind(&check_mint); 2026 __ Bind(&check_mint);
2001 __ CompareClassId(left, kMintCid); 2027 __ CompareClassId(left, kMintCid);
2002 __ j(NOT_EQUAL, &check_bigint, Assembler::kNearJump); 2028 __ j(NOT_EQUAL, &check_bigint, Assembler::kNearJump);
2003 __ CompareClassId(right, kMintCid); 2029 __ CompareClassId(right, kMintCid);
2004 __ j(NOT_EQUAL, &done, Assembler::kNearJump); 2030 __ j(NOT_EQUAL, &done, Assembler::kFarJump);
2005 __ movq(left, FieldAddress(left, Mint::value_offset())); 2031 __ movq(left, FieldAddress(left, Mint::value_offset()));
2006 __ cmpq(left, FieldAddress(right, Mint::value_offset())); 2032 __ cmpq(left, FieldAddress(right, Mint::value_offset()));
2007 __ jmp(&done, Assembler::kNearJump); 2033 __ jmp(&done, Assembler::kFarJump);
2008 2034
2009 __ Bind(&check_bigint); 2035 __ Bind(&check_bigint);
2010 __ CompareClassId(left, kBigintCid); 2036 __ CompareClassId(left, kBigintCid);
2011 __ j(NOT_EQUAL, &reference_compare, Assembler::kNearJump); 2037 __ j(NOT_EQUAL, &reference_compare, Assembler::kFarJump);
2012 __ CompareClassId(right, kBigintCid); 2038 __ CompareClassId(right, kBigintCid);
2013 __ j(NOT_EQUAL, &done, Assembler::kNearJump); 2039 __ j(NOT_EQUAL, &done, Assembler::kFarJump);
2014 __ EnterStubFrame(); 2040 __ EnterStubFrame();
2015 __ ReserveAlignedFrameSpace(0); 2041 __ ReserveAlignedFrameSpace(0);
2016 __ movq(CallingConventions::kArg1Reg, left); 2042 __ movq(CallingConventions::kArg1Reg, left);
2017 __ movq(CallingConventions::kArg2Reg, right); 2043 __ movq(CallingConventions::kArg2Reg, right);
2018 __ CallRuntime(kBigintCompareRuntimeEntry, 2); 2044 __ CallRuntime(kBigintCompareRuntimeEntry, 2);
2019 // Result in RAX, 0 means equal. 2045 // Result in RAX, 0 means equal.
2020 __ LeaveStubFrame(); 2046 __ LeaveStubFrame();
2021 __ cmpq(RAX, Immediate(0)); 2047 __ cmpq(RAX, Immediate(0));
2022 __ jmp(&done); 2048 __ jmp(&done);
2023 2049
(...skipping 25 matching lines...) Expand all
2049 2075
2050 __ movq(left, Address(RSP, 2 * kWordSize)); 2076 __ movq(left, Address(RSP, 2 * kWordSize));
2051 __ movq(right, Address(RSP, 1 * kWordSize)); 2077 __ movq(right, Address(RSP, 1 * kWordSize));
2052 GenerateIdenticalWithNumberCheckStub(assembler, left, right); 2078 GenerateIdenticalWithNumberCheckStub(assembler, left, right);
2053 __ ret(); 2079 __ ret();
2054 2080
2055 if (FLAG_support_debugger) { 2081 if (FLAG_support_debugger) {
2056 __ Bind(&stepping); 2082 __ Bind(&stepping);
2057 __ EnterStubFrame(); 2083 __ EnterStubFrame();
2058 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0); 2084 __ CallRuntime(kSingleStepHandlerRuntimeEntry, 0);
2085 __ RestoreCodePointer();
2059 __ LeaveStubFrame(); 2086 __ LeaveStubFrame();
2060 __ jmp(&done_stepping); 2087 __ jmp(&done_stepping);
2061 } 2088 }
2062 } 2089 }
2063 2090
2064 2091
2065 // Called from optimized code only. 2092 // Called from optimized code only.
2066 // TOS + 0: return address 2093 // TOS + 0: return address
2067 // TOS + 1: right argument. 2094 // TOS + 1: right argument.
2068 // TOS + 2: left argument. 2095 // TOS + 2: left argument.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 __ j(ZERO, &call_target_function, Assembler::kNearJump); 2133 __ j(ZERO, &call_target_function, Assembler::kNearJump);
2107 __ cmpq(RDX, RAX); 2134 __ cmpq(RDX, RAX);
2108 __ j(NOT_EQUAL, &update, Assembler::kNearJump); 2135 __ j(NOT_EQUAL, &update, Assembler::kNearJump);
2109 2136
2110 __ Bind(&call_target_function); 2137 __ Bind(&call_target_function);
2111 // Call the target found in the cache. For a class id match, this is a 2138 // Call the target found in the cache. For a class id match, this is a
2112 // proper target for the given name and arguments descriptor. If the 2139 // proper target for the given name and arguments descriptor. If the
2113 // illegal class id was found, the target is a cache miss handler that can 2140 // illegal class id was found, the target is a cache miss handler that can
2114 // be invoked as a normal Dart function. 2141 // be invoked as a normal Dart function.
2115 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); 2142 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize));
2143 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset()));
2116 __ movq(target, FieldAddress(RAX, Function::entry_point_offset())); 2144 __ movq(target, FieldAddress(RAX, Function::entry_point_offset()));
2117 } 2145 }
2118 2146
2119 2147
2120 // Called from megamorphic calls. 2148 // Called from megamorphic calls.
2121 // RDI: receiver. 2149 // RDI: receiver.
2122 // RBX: lookup cache. 2150 // RBX: lookup cache.
2123 // Result: 2151 // Result:
2124 // RCX: entry point. 2152 // RCX: entry point.
2125 void StubCode::GenerateMegamorphicLookupStub(Assembler* assembler) { 2153 void StubCode::GenerateMegamorphicLookupStub(Assembler* assembler) {
2126 EmitMegamorphicLookup(assembler, RDI, RBX, RCX); 2154 EmitMegamorphicLookup(assembler, RDI, RBX, RCX);
2127 __ ret(); 2155 __ ret();
2128 } 2156 }
2129 2157
2130 } // namespace dart 2158 } // namespace dart
2131 2159
2132 #endif // defined TARGET_ARCH_X64 2160 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698