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

Side by Side Diff: src/ia32/code-stubs-ia32.h

Issue 6824078: Move most of the incremental marking write barrier to generated code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/assembler-ia32.cc ('k') | src/ia32/code-stubs-ia32.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 public: 509 public:
510 RecordWriteStub(Register object, 510 RecordWriteStub(Register object,
511 Register value, 511 Register value,
512 Register address, 512 Register address,
513 EmitRememberedSet emit_remembered_set, 513 EmitRememberedSet emit_remembered_set,
514 SaveFPRegsMode fp_mode) 514 SaveFPRegsMode fp_mode)
515 : object_(object), 515 : object_(object),
516 value_(value), 516 value_(value),
517 address_(address), 517 address_(address),
518 emit_remembered_set_(emit_remembered_set), 518 emit_remembered_set_(emit_remembered_set),
519 save_fp_regs_mode_(fp_mode) { 519 save_fp_regs_mode_(fp_mode),
520 slow_(NULL),
521 regs_(NULL) {
Vyacheslav Egorov (Chromium) 2011/04/24 12:16:47 you can just make RegisterAllocation a member of R
520 } 522 }
521 523
522 static const byte kTwoByteNopInstruction = 0x3c; // Cmpb al, #imm8. 524 static const byte kTwoByteNopInstruction = 0x3c; // Cmpb al, #imm8.
523 static const byte kSkipIncrementalPartInstruction = 0xeb; // Jmp #imm8. 525 static const byte kSkipNonIncrementalPartInstruction = 0xeb; // Jmp #imm8.
524 526
525 static byte GetInstruction(bool enable) { 527 static byte GetInstruction(bool enable) {
526 // Can't use ternary operator here, because gcc makes an undefined 528 // Can't use ternary operator here, because gcc makes an undefined
527 // reference to a static const int. 529 // reference to a static const int.
528 if (enable) { 530 if (enable) {
531 return kSkipNonIncrementalPartInstruction;
532 } else {
529 return kTwoByteNopInstruction; 533 return kTwoByteNopInstruction;
530 } else {
531 return kSkipIncrementalPartInstruction;
532 } 534 }
533 } 535 }
534 536
535 static void Patch(Code* stub, bool enable) { 537 static void Patch(Code* stub, bool enable) {
536 ASSERT(*stub->instruction_start() == GetInstruction(!enable)); 538 ASSERT(*stub->instruction_start() == GetInstruction(!enable));
537 *stub->instruction_start() = GetInstruction(enable); 539 *stub->instruction_start() = GetInstruction(enable);
538 } 540 }
539 541
540 private: 542 private:
543 // This is a helper class for freeing up 3 scratch registers, where the third
544 // is always ecx (needed for shift operations). The input is two registers
545 // that must be preserved and one scratch register provided by the caller.
546 class RegisterAllocation {
547 public:
548 RegisterAllocation(MacroAssembler* masm,
549 Register object,
550 Register address,
551 Register scratch0)
552 : masm_(masm),
553 object_orig_(object),
554 address_orig_(address),
555 scratch0_orig_(scratch0),
556 object_(object),
557 address_(address),
558 scratch0_(scratch0) {
559 ASSERT(!Aliasing(scratch0, object, address, no_reg));
560 if (object.is(ecx)) {
561 object_ = GetRegThatIsNotEcxOr(address_, scratch0_, no_reg);
562 }
563 if (address.is(ecx)) {
564 address_ = GetRegThatIsNotEcxOr(object_, scratch0_, no_reg);
565 }
566 if (scratch0.is(ecx)) {
567 scratch0_ = GetRegThatIsNotEcxOr(object_, address_, no_reg);
568 }
569 ASSERT(!Aliasing(scratch0_, object_, address_, ecx));
570 scratch1_ = GetRegThatIsNotEcxOr(object_, address_, scratch0_);
571 }
572
573 void Save() {
574 // We don't have to save scratch0_orig_ because it was given to us as
575 // a scratch register. But if we had to switch to a different reg then
576 // we should save the new scratch0_.
577 if (!scratch0_.is(scratch0_orig_)) masm_->push(scratch0_);
578 masm_->push(scratch1_);
579 ASSERT(!address_orig_.is(object_));
580 ASSERT(object_.is(object_orig_) || address_.is(address_orig_));
581 masm_->Move(object_, object_orig_);
582 masm_->Move(address_, address_orig_);
583 // We have to save ecx, because we are going to need it for the bit
584 // twiddling, but if we were given ecx as scratch0_orig_ then we don't
585 // need to save it because the caller is expecting it to be trashed.
586 if (!ecx.is(scratch0_orig_)) masm_->push(ecx);
587 }
588
589 void Restore() {
590 // Do this first because ecx may be one of the orig_ registers.
591 if (!ecx.is(scratch0_orig_)) masm_->pop(ecx);
592 // These will have been preserved the entire time, so we just need to move
593 // them back. Only in one case is the orig_ reg different from the plain
594 // one, since only one of them can alias with ecx.
595 ASSERT(object_.is(object_orig_) || address_.is(address_orig_));
596 masm_->Move(address_orig_, address_);
597 masm_->Move(object_orig_, object_);
598 ASSERT(!Aliasing(object_, address_, scratch1_, scratch0_));
599 ASSERT(!Aliasing(object_orig_, address_, scratch1_, scratch0_));
600 ASSERT(!Aliasing(object_, address_orig_, scratch1_, scratch0_));
601 masm_->pop(scratch1_);
602 if (!scratch0_.is(scratch0_orig_)) masm_->pop(scratch0_);
603 }
604
605 // If we have to call into C then we need to save and restore all caller-
606 // saved registers that were not already preserved. The caller saved
607 // registers are eax, ecx and adx. The three scratch registers (incl. ecx)
608 // will be restored by other means so we don't bother pushing them here.
609 void SaveCallerSaveRegisters() {
610 if (!scratch0_.is(eax) && !scratch1_.is(eax)) masm_->push(eax);
611 if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm_->push(edx);
612 }
613
614 void RestoreCallerSaveRegisters() {
615 if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm_->pop(edx);
616 if (!scratch0_.is(eax) && !scratch1_.is(eax)) masm_->pop(eax);
617 }
618
619 Register object() { return object_; }
620 Register address() { return address_; }
621 Register scratch0() { return scratch0_; }
622 Register scratch1() { return scratch1_; }
623
624 private:
625 MacroAssembler* masm_;
626 Register object_orig_;
627 Register address_orig_;
628 Register scratch0_orig_;
629 Register object_;
630 Register address_;
631 Register scratch0_;
632 Register scratch1_;
633 // Third scratch register is always ecx.
634
635 Register GetRegThatIsNotEcxOr(Register r1,
636 Register r2,
637 Register r3) {
638 for (int i = 0; i < Register::kNumAllocatableRegisters; i++) {
639 Register candidate = Register::FromAllocationIndex(i);
640 if (candidate.is(ecx)) continue;
641 if (candidate.is(r1)) continue;
642 if (candidate.is(r2)) continue;
643 if (candidate.is(r3)) continue;
644 return candidate;
645 }
646 UNREACHABLE();
647 return no_reg;
648 }
649 };
650
541 void Generate(MacroAssembler* masm); 651 void Generate(MacroAssembler* masm);
652 void GenerateIncremental(MacroAssembler* masm);
653 void GenerateIncrementalValueIsInNewSpace(MacroAssembler* masm);
654 void GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceRememberedSet(
655 MacroAssembler* masm);
656 void GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceNoRememberedSet(
657 MacroAssembler* masm,
658 Label* value_in_new_space_object_is_black_no_remembered_set);
659 void GenerateIncrementalValueIsInOldSpace(MacroAssembler* masm);
542 660
543 Major MajorKey() { return RecordWrite; } 661 Major MajorKey() { return RecordWrite; }
544 662
545 int MinorKey() { 663 int MinorKey() {
546 return ObjectBits::encode(object_.code()) | 664 return ObjectBits::encode(object_.code()) |
547 ValueBits::encode(value_.code()) | 665 ValueBits::encode(value_.code()) |
548 AddressBits::encode(address_.code()) | 666 AddressBits::encode(address_.code()) |
549 EmitRememberedSetBits::encode(emit_remembered_set_) | 667 EmitRememberedSetBits::encode(emit_remembered_set_) |
550 SaveFPRegsModeBits::encode(save_fp_regs_mode_); 668 SaveFPRegsModeBits::encode(save_fp_regs_mode_);
551 } 669 }
552 670
553 class ObjectBits: public BitField<int, 0, 3> {}; 671 class ObjectBits: public BitField<int, 0, 3> {};
554 class ValueBits: public BitField<int, 3, 3> {}; 672 class ValueBits: public BitField<int, 3, 3> {};
555 class AddressBits: public BitField<int, 6, 3> {}; 673 class AddressBits: public BitField<int, 6, 3> {};
556 class EmitRememberedSetBits: public BitField<EmitRememberedSet, 9, 1> {}; 674 class EmitRememberedSetBits: public BitField<EmitRememberedSet, 9, 1> {};
557 class SaveFPRegsModeBits: public BitField<SaveFPRegsMode, 10, 1> {}; 675 class SaveFPRegsModeBits: public BitField<SaveFPRegsMode, 10, 1> {};
558 676
559 Register object_; 677 Register object_;
560 Register value_; 678 Register value_;
561 Register address_; 679 Register address_;
562 EmitRememberedSet emit_remembered_set_; 680 EmitRememberedSet emit_remembered_set_;
563 SaveFPRegsMode save_fp_regs_mode_; 681 SaveFPRegsMode save_fp_regs_mode_;
682 Label* slow_;
683 RegisterAllocation* regs_;
564 }; 684 };
565 685
566 686
567 // Generate code to load an element from a pixel array. The receiver is assumed 687 // Generate code to load an element from a pixel array. The receiver is assumed
568 // to not be a smi and to have elements, the caller must guarantee this 688 // to not be a smi and to have elements, the caller must guarantee this
569 // precondition. If key is not a smi, then the generated code branches to 689 // precondition. If key is not a smi, then the generated code branches to
570 // key_not_smi. Callers can specify NULL for key_not_smi to signal that a smi 690 // key_not_smi. Callers can specify NULL for key_not_smi to signal that a smi
571 // check has already been performed on key so that the smi check is not 691 // check has already been performed on key so that the smi check is not
572 // generated. If key is not a valid index within the bounds of the pixel array, 692 // generated. If key is not a valid index within the bounds of the pixel array,
573 // the generated code jumps to out_of_range. receiver, key and elements are 693 // the generated code jumps to out_of_range. receiver, key and elements are
(...skipping 27 matching lines...) Expand all
601 Register scratch1, 721 Register scratch1,
602 bool load_elements_from_receiver, 722 bool load_elements_from_receiver,
603 Label* key_not_smi, 723 Label* key_not_smi,
604 Label* value_not_smi, 724 Label* value_not_smi,
605 Label* not_pixel_array, 725 Label* not_pixel_array,
606 Label* out_of_range); 726 Label* out_of_range);
607 727
608 } } // namespace v8::internal 728 } } // namespace v8::internal
609 729
610 #endif // V8_IA32_CODE_STUBS_IA32_H_ 730 #endif // V8_IA32_CODE_STUBS_IA32_H_
OLDNEW
« no previous file with comments | « src/ia32/assembler-ia32.cc ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698