| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 __ subsd(result, double_scratch); | 671 __ subsd(result, double_scratch); |
| 672 __ addsd(result, Operand(kScratchRegister, 8 * kDoubleSize)); | 672 __ addsd(result, Operand(kScratchRegister, 8 * kDoubleSize)); |
| 673 __ mulsd(result, input); | 673 __ mulsd(result, input); |
| 674 | 674 |
| 675 __ bind(&done); | 675 __ bind(&done); |
| 676 } | 676 } |
| 677 | 677 |
| 678 #undef __ | 678 #undef __ |
| 679 | 679 |
| 680 | 680 |
| 681 static const int kNoCodeAgeSequenceLength = 6; | 681 static const int kCodeAgeSequenceLength = 7; |
| 682 | 682 |
| 683 static byte* GetNoCodeAgeSequence(uint32_t* length) { | 683 static byte* GetNoCodeAgeSequence(uint32_t* length) { |
| 684 static bool initialized = false; | 684 static bool initialized = false; |
| 685 static byte sequence[kNoCodeAgeSequenceLength]; | 685 static byte sequence[kCodeAgeSequenceLength]; |
| 686 *length = kNoCodeAgeSequenceLength; | 686 *length = kCodeAgeSequenceLength; |
| 687 if (!initialized) { | 687 if (!initialized) { |
| 688 // The sequence of instructions that is patched out for aging code is the | 688 // The sequence of instructions that is patched out for aging code is the |
| 689 // following boilerplate stack-building prologue that is found both in | 689 // following boilerplate stack-building prologue that is found both in |
| 690 // FUNCTION and OPTIMIZED_FUNCTION code: | 690 // FUNCTION and OPTIMIZED_FUNCTION code: |
| 691 CodePatcher patcher(sequence, kNoCodeAgeSequenceLength); | 691 CodePatcher patcher(sequence, kCodeAgeSequenceLength); |
| 692 patcher.masm()->push(rbp); | 692 patcher.masm()->push(rbp); |
| 693 patcher.masm()->movq(rbp, rsp); | 693 patcher.masm()->movq(rbp, rsp); |
| 694 patcher.masm()->nop(); |
| 694 patcher.masm()->push(rsi); | 695 patcher.masm()->push(rsi); |
| 695 patcher.masm()->push(rdi); | 696 patcher.masm()->push(rdi); |
| 696 initialized = true; | 697 initialized = true; |
| 697 } | 698 } |
| 698 return sequence; | 699 return sequence; |
| 699 } | 700 } |
| 700 | 701 |
| 701 | 702 |
| 703 static byte* GetPreAgedCodeAgeSequence(uint32_t* length) { |
| 704 static bool initialized = false; |
| 705 static byte sequence[kCodeAgeSequenceLength]; |
| 706 *length = kCodeAgeSequenceLength; |
| 707 if (!initialized) { |
| 708 // If code is "pre-aged" then this sequence of instructions is found in the |
| 709 // boilerplate stack-building prologue that is found in FUNCTIONS and |
| 710 // OPTIMIZED_FUNCTION code, and is patched out for code aging. |
| 711 CodePatcher patcher(sequence, kCodeAgeSequenceLength); |
| 712 patcher.masm()->push(rbp); |
| 713 patcher.masm()->movq(rbp, rsp); |
| 714 patcher.masm()->push(rsi); |
| 715 patcher.masm()->nop(); |
| 716 patcher.masm()->push(rdi); |
| 717 initialized = true; |
| 718 } |
| 719 return sequence; |
| 720 } |
| 721 |
| 722 |
| 702 bool Code::IsYoungSequence(byte* sequence) { | 723 bool Code::IsYoungSequence(byte* sequence) { |
| 703 uint32_t young_length; | 724 uint32_t young_length; |
| 704 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 725 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 705 bool result = (!memcmp(sequence, young_sequence, young_length)); | 726 bool result = (!memcmp(sequence, young_sequence, young_length)); |
| 706 ASSERT(result || *sequence == kCallOpcode); | 727 ASSERT(result || *sequence == kCallOpcode || IsPreAgedSequence(sequence)); |
| 707 return result; | 728 return result; |
| 708 } | 729 } |
| 709 | 730 |
| 731 |
| 732 bool Code::IsPreAgedSequence(byte* sequence) { |
| 733 uint32_t pre_aged_length; |
| 734 byte* pre_aged_sequence = GetPreAgedCodeAgeSequence(&pre_aged_length); |
| 735 bool result = (!memcmp(sequence, pre_aged_sequence, pre_aged_length)); |
| 736 ASSERT(result || *sequence == kCallOpcode || IsYoungSequence(sequence)); |
| 737 return result; |
| 738 } |
| 739 |
| 710 | 740 |
| 711 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, | 741 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, |
| 712 MarkingParity* parity) { | 742 MarkingParity* parity) { |
| 713 if (IsYoungSequence(sequence)) { | 743 if (IsYoungSequence(sequence)) { |
| 714 *age = kNoAge; | 744 *age = kNoAge; |
| 715 *parity = NO_MARKING_PARITY; | 745 *parity = NO_MARKING_PARITY; |
| 746 } else if (IsPreAgedSequence(sequence)) { |
| 747 *age = kPreAgedCodeAge; |
| 748 *parity = NO_MARKING_PARITY; |
| 716 } else { | 749 } else { |
| 717 sequence++; // Skip the kCallOpcode byte | 750 sequence++; // Skip the kCallOpcode byte |
| 718 Address target_address = sequence + *reinterpret_cast<int*>(sequence) + | 751 Address target_address = sequence + *reinterpret_cast<int*>(sequence) + |
| 719 Assembler::kCallTargetAddressOffset; | 752 Assembler::kCallTargetAddressOffset; |
| 720 Code* stub = GetCodeFromTargetAddress(target_address); | 753 Code* stub = GetCodeFromTargetAddress(target_address); |
| 721 GetCodeAgeAndParity(stub, age, parity); | 754 GetCodeAgeAndParity(stub, age, parity); |
| 722 } | 755 } |
| 723 } | 756 } |
| 724 | 757 |
| 725 | 758 |
| 726 void Code::PatchPlatformCodeAge(Isolate* isolate, | 759 void Code::PatchPlatformCodeAge(Isolate* isolate, |
| 727 byte* sequence, | 760 byte* sequence, |
| 728 Code::Age age, | 761 Code::Age age, |
| 729 MarkingParity parity) { | 762 MarkingParity parity) { |
| 730 uint32_t young_length; | 763 uint32_t young_length; |
| 731 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 764 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 732 if (age == kNoAge) { | 765 if (age == kNoAge) { |
| 733 CopyBytes(sequence, young_sequence, young_length); | 766 CopyBytes(sequence, young_sequence, young_length); |
| 734 CPU::FlushICache(sequence, young_length); | 767 CPU::FlushICache(sequence, young_length); |
| 735 } else { | 768 } else { |
| 736 Code* stub = GetCodeAgeStub(isolate, age, parity); | 769 Code* stub = GetCodeAgeStub(isolate, age, parity); |
| 737 CodePatcher patcher(sequence, young_length); | 770 CodePatcher patcher(sequence, young_length); |
| 738 patcher.masm()->call(stub->instruction_start()); | 771 patcher.masm()->call(stub->instruction_start()); |
| 739 for (int i = 0; | 772 for (int i = 0; |
| 740 i < kNoCodeAgeSequenceLength - Assembler::kShortCallInstructionLength; | 773 i < kCodeAgeSequenceLength - Assembler::kShortCallInstructionLength; |
| 741 i++) { | 774 i++) { |
| 742 patcher.masm()->nop(); | 775 patcher.masm()->nop(); |
| 743 } | 776 } |
| 744 } | 777 } |
| 745 } | 778 } |
| 746 | 779 |
| 747 | 780 |
| 748 Operand StackArgumentsAccessor::GetArgumentOperand(int index) { | 781 Operand StackArgumentsAccessor::GetArgumentOperand(int index) { |
| 749 ASSERT(index >= 0); | 782 ASSERT(index >= 0); |
| 750 ASSERT(base_reg_.is(rsp) || base_reg_.is(rbp)); | 783 ASSERT(base_reg_.is(rsp) || base_reg_.is(rbp)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 763 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. | 796 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. |
| 764 return Operand(base_reg_, argument_count_reg_, times_pointer_size, | 797 return Operand(base_reg_, argument_count_reg_, times_pointer_size, |
| 765 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); | 798 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); |
| 766 } | 799 } |
| 767 } | 800 } |
| 768 | 801 |
| 769 | 802 |
| 770 } } // namespace v8::internal | 803 } } // namespace v8::internal |
| 771 | 804 |
| 772 #endif // V8_TARGET_ARCH_X64 | 805 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |