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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 __ bind(&ascii); | 750 __ bind(&ascii); |
751 __ movzx_b(result, FieldOperand(string, | 751 __ movzx_b(result, FieldOperand(string, |
752 index, | 752 index, |
753 times_1, | 753 times_1, |
754 SeqAsciiString::kHeaderSize)); | 754 SeqAsciiString::kHeaderSize)); |
755 __ bind(&done); | 755 __ bind(&done); |
756 } | 756 } |
757 | 757 |
758 #undef __ | 758 #undef __ |
759 | 759 |
| 760 |
| 761 static byte* GetNoCodeAgeSequence(uint32_t* length) { |
| 762 // The sequence of instructions that is patched out for aging code is the |
| 763 // following boilerplate stack-building prologue that is found both in |
| 764 // FUNCTION and OPTIMIZED_FUNCTION code: |
| 765 // |
| 766 // __ push(ebp); |
| 767 // __ mov(ebp, esp); |
| 768 // __ push(esi); |
| 769 // __ push(edi); |
| 770 static byte sequence[] = { 0x55, 0x89, 0xe5, 0x56, 0x57 }; |
| 771 *length = sizeof(sequence); |
| 772 return sequence; |
| 773 } |
| 774 |
| 775 |
| 776 byte* Code::FindPlatformCodeAgeSequence() { |
| 777 byte* start = instruction_start(); |
| 778 uint32_t young_length; |
| 779 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 780 if (!memcmp(start, young_sequence, young_length) || |
| 781 *start == kCallOpcode) { |
| 782 return start; |
| 783 } else { |
| 784 byte* start_after_strict = start + kSizeOfStrictModePrologue; |
| 785 ASSERT(!memcmp(start_after_strict, young_sequence, young_length) || |
| 786 start[kSizeOfStrictModePrologue] == kCallOpcode); |
| 787 return start_after_strict; |
| 788 } |
| 789 } |
| 790 |
| 791 |
| 792 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, |
| 793 MarkingParity* parity) { |
| 794 uint32_t young_length; |
| 795 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 796 if (!memcmp(sequence, young_sequence, young_length)) { |
| 797 *age = kNoAge; |
| 798 *parity = NO_MARKING_PARITY; |
| 799 } else { |
| 800 Address target_address = |
| 801 sequence + *reinterpret_cast<int*>(sequence + 1) + young_length; |
| 802 Code* stub = GetCodeFromTargetAddress(target_address); |
| 803 GetCodeAgeAndParity(stub, age, parity); |
| 804 } |
| 805 } |
| 806 |
| 807 |
| 808 void Code::PatchPlatformCodeAge(byte* sequence, |
| 809 Code::Age age, |
| 810 MarkingParity parity) { |
| 811 uint32_t young_length; |
| 812 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 813 if (age == kNoAge) { |
| 814 memcpy(sequence, young_sequence, young_length); |
| 815 } else { |
| 816 Code* stub = GetCodeAgeStub(age, parity); |
| 817 Address instruction_start = stub->instruction_start(); |
| 818 int32_t stub_offset = |
| 819 instruction_start - sequence - young_length; |
| 820 *sequence = kCallOpcode; |
| 821 *reinterpret_cast<int32_t*>(sequence + 1) = stub_offset; |
| 822 } |
| 823 CPU::FlushICache(sequence, young_length); |
| 824 } |
| 825 |
| 826 |
760 } } // namespace v8::internal | 827 } } // namespace v8::internal |
761 | 828 |
762 #endif // V8_TARGET_ARCH_IA32 | 829 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |