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

Side by Side Diff: src/ia32/codegen-ia32.cc

Issue 10837037: Age code to allow reclaiming old unexecuted functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 8 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 | Annotate | Revision Log
OLDNEW
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
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 if (kind() == FUNCTION) {
785 byte* start_after_strict =
786 start + kSizeOfFullCodegenStrictModePrologue;
787 ASSERT(!memcmp(start_after_strict, young_sequence, young_length) ||
788 start[kSizeOfFullCodegenStrictModePrologue] == kCallOpcode);
789 return start_after_strict;
790 } else {
791 ASSERT(kind() == OPTIMIZED_FUNCTION);
792 start = instruction_start() + kSizeOfOptimizedStrictModePrologue;
793 if (!memcmp(start, young_sequence, young_length) ||
794 *start == kCallOpcode) {
795 return start;
796 }
797 start = instruction_start() + kSizeOfOptimizedAlignStackPrologue;
798 if (!memcmp(start, young_sequence, young_length) ||
799 *start == kCallOpcode) {
800 return start;
801 }
802 start = instruction_start() + kSizeOfOptimizedAlignStackPrologue +
803 kSizeOfOptimizedStrictModePrologue;
804 ASSERT(!memcmp(start, young_sequence, young_length) ||
805 *start == kCallOpcode);
806 return start;
807 }
808 }
809 }
810
811
812 bool Code::IsYoungSequence(byte* sequence) {
813 uint32_t young_length;
814 byte* young_sequence = GetNoCodeAgeSequence(&young_length);
815 bool result = (!memcmp(sequence, young_sequence, young_length));
816 ASSERT(result || *sequence == kCallOpcode);
817 return result;
818 }
819
820
821 void Code::GetCodeAgeAndParity(byte* sequence, Age* age,
822 MarkingParity* parity) {
823 uint32_t young_length;
824 GetNoCodeAgeSequence(&young_length);
825 if (IsYoungSequence(sequence)) {
826 *age = kNoAge;
827 *parity = NO_MARKING_PARITY;
828 } else {
829 Address target_address =
830 sequence + *reinterpret_cast<int*>(sequence + 1) + young_length;
831 Code* stub = GetCodeFromTargetAddress(target_address);
832 GetCodeAgeAndParity(stub, age, parity);
833 }
834 }
835
836
837 void Code::PatchPlatformCodeAge(byte* sequence,
838 Code::Age age,
839 MarkingParity parity) {
840 uint32_t young_length;
841 byte* young_sequence = GetNoCodeAgeSequence(&young_length);
842 if (IsYoungSequence(sequence)) {
843 memcpy(sequence, young_sequence, young_length);
844 } else {
845 Code* stub = GetCodeAgeStub(age, parity);
846 Address instruction_start = stub->instruction_start();
847 int32_t stub_offset =
848 instruction_start - sequence - young_length;
849 *sequence = kCallOpcode;
850 *reinterpret_cast<int32_t*>(sequence + 1) = stub_offset;
851 }
852 CPU::FlushICache(sequence, young_length);
853 }
854
855
760 } } // namespace v8::internal 856 } } // namespace v8::internal
761 857
762 #endif // V8_TARGET_ARCH_IA32 858 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | src/mark-compact.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698