| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_ARM | 7 #if V8_TARGET_ARCH_ARM |
| 8 | 8 |
| 9 #include "codegen.h" | 9 #include "codegen.h" |
| 10 #include "macro-assembler.h" | 10 #include "macro-assembler.h" |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 __ bind(&done); | 815 __ bind(&done); |
| 816 } | 816 } |
| 817 | 817 |
| 818 #undef __ | 818 #undef __ |
| 819 | 819 |
| 820 #ifdef DEBUG | 820 #ifdef DEBUG |
| 821 // add(r0, pc, Operand(-8)) | 821 // add(r0, pc, Operand(-8)) |
| 822 static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008; | 822 static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008; |
| 823 #endif | 823 #endif |
| 824 | 824 |
| 825 static byte* GetNoCodeAgeSequence(uint32_t* length) { | 825 CodeAgingHelper::CodeAgingHelper() { |
| 826 // The sequence of instructions that is patched out for aging code is the | 826 ASSERT(young_sequence_.length() == kNoCodeAgeSequenceLength); |
| 827 // following boilerplate stack-building prologue that is found in FUNCTIONS | 827 // Since patcher is a large object, allocate it dynamically when needed, |
| 828 static bool initialized = false; | 828 // to avoid overloading the stack in stress conditions. |
| 829 static uint32_t sequence[kNoCodeAgeSequenceLength]; | 829 SmartPointer<CodePatcher> patcher( |
| 830 byte* byte_sequence = reinterpret_cast<byte*>(sequence); | 830 new CodePatcher(young_sequence_.start(), |
| 831 *length = kNoCodeAgeSequenceLength * Assembler::kInstrSize; | 831 young_sequence_.length() / Assembler::kInstrSize)); |
| 832 if (!initialized) { | 832 PredictableCodeSizeScope scope(patcher->masm(), young_sequence_.length()); |
| 833 // Since patcher is a large object, allocate it dynamically when needed, | 833 patcher->masm()->PushFixedFrame(r1); |
| 834 // to avoid overloading the stack in stress conditions. | 834 patcher->masm()->nop(ip.code()); |
| 835 SmartPointer<CodePatcher> | 835 patcher->masm()->add( |
| 836 patcher(new CodePatcher(byte_sequence, kNoCodeAgeSequenceLength)); | 836 fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 837 PredictableCodeSizeScope scope(patcher->masm(), *length); | |
| 838 patcher->masm()->PushFixedFrame(r1); | |
| 839 patcher->masm()->nop(ip.code()); | |
| 840 patcher->masm()->add( | |
| 841 fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | |
| 842 initialized = true; | |
| 843 } | |
| 844 return byte_sequence; | |
| 845 } | 837 } |
| 846 | 838 |
| 847 | 839 |
| 848 bool Code::IsYoungSequence(byte* sequence) { | 840 #ifdef DEBUG |
| 849 uint32_t young_length; | 841 bool CodeAgingHelper::IsOld(byte* candidate) const { |
| 850 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 842 return Memory::uint32_at(candidate) == kCodeAgePatchFirstInstruction; |
| 851 bool result = !memcmp(sequence, young_sequence, young_length); | 843 } |
| 852 ASSERT(result || | 844 #endif |
| 853 Memory::uint32_at(sequence) == kCodeAgePatchFirstInstruction); | 845 |
| 846 |
| 847 bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) { |
| 848 bool result = isolate->code_aging_helper()->IsYoung(sequence); |
| 849 ASSERT(result || isolate->code_aging_helper()->IsOld(sequence)); |
| 854 return result; | 850 return result; |
| 855 } | 851 } |
| 856 | 852 |
| 857 | 853 |
| 858 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, | 854 void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, |
| 859 MarkingParity* parity) { | 855 MarkingParity* parity) { |
| 860 if (IsYoungSequence(sequence)) { | 856 if (IsYoungSequence(isolate, sequence)) { |
| 861 *age = kNoAgeCodeAge; | 857 *age = kNoAgeCodeAge; |
| 862 *parity = NO_MARKING_PARITY; | 858 *parity = NO_MARKING_PARITY; |
| 863 } else { | 859 } else { |
| 864 Address target_address = Memory::Address_at( | 860 Address target_address = Memory::Address_at( |
| 865 sequence + Assembler::kInstrSize * (kNoCodeAgeSequenceLength - 1)); | 861 sequence + (kNoCodeAgeSequenceLength - Assembler::kInstrSize)); |
| 866 Code* stub = GetCodeFromTargetAddress(target_address); | 862 Code* stub = GetCodeFromTargetAddress(target_address); |
| 867 GetCodeAgeAndParity(stub, age, parity); | 863 GetCodeAgeAndParity(stub, age, parity); |
| 868 } | 864 } |
| 869 } | 865 } |
| 870 | 866 |
| 871 | 867 |
| 872 void Code::PatchPlatformCodeAge(Isolate* isolate, | 868 void Code::PatchPlatformCodeAge(Isolate* isolate, |
| 873 byte* sequence, | 869 byte* sequence, |
| 874 Code::Age age, | 870 Code::Age age, |
| 875 MarkingParity parity) { | 871 MarkingParity parity) { |
| 876 uint32_t young_length; | 872 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); |
| 877 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | |
| 878 if (age == kNoAgeCodeAge) { | 873 if (age == kNoAgeCodeAge) { |
| 879 CopyBytes(sequence, young_sequence, young_length); | 874 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); |
| 880 CPU::FlushICache(sequence, young_length); | 875 CPU::FlushICache(sequence, young_length); |
| 881 } else { | 876 } else { |
| 882 Code* stub = GetCodeAgeStub(isolate, age, parity); | 877 Code* stub = GetCodeAgeStub(isolate, age, parity); |
| 883 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); | 878 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); |
| 884 patcher.masm()->add(r0, pc, Operand(-8)); | 879 patcher.masm()->add(r0, pc, Operand(-8)); |
| 885 patcher.masm()->ldr(pc, MemOperand(pc, -4)); | 880 patcher.masm()->ldr(pc, MemOperand(pc, -4)); |
| 886 patcher.masm()->emit_code_stub_address(stub); | 881 patcher.masm()->emit_code_stub_address(stub); |
| 887 } | 882 } |
| 888 } | 883 } |
| 889 | 884 |
| 890 | 885 |
| 891 } } // namespace v8::internal | 886 } } // namespace v8::internal |
| 892 | 887 |
| 893 #endif // V8_TARGET_ARCH_ARM | 888 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |