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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 __ orr(temp1, temp1, temp2); | 819 __ orr(temp1, temp1, temp2); |
820 __ vmov(input, ip, temp1); | 820 __ vmov(input, ip, temp1); |
821 __ vmul(result, result, input); | 821 __ vmul(result, result, input); |
822 __ bind(&done); | 822 __ bind(&done); |
823 } | 823 } |
824 | 824 |
825 #undef __ | 825 #undef __ |
826 | 826 |
827 // add(r0, pc, Operand(-8)) | 827 // add(r0, pc, Operand(-8)) |
828 static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008; | 828 static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008; |
| 829 static const uint32_t kThumbCodeAgePatchFirstInstruction = 0x3f2af; |
829 | 830 |
830 static byte* GetNoCodeAgeSequence(uint32_t* length) { | 831 static byte* GetNoCodeAgeSequence(uint32_t* length) { |
831 // The sequence of instructions that is patched out for aging code is the | 832 // The sequence of instructions that is patched out for aging code is the |
832 // following boilerplate stack-building prologue that is found in FUNCTIONS | 833 // following boilerplate stack-building prologue that is found in FUNCTIONS |
833 static bool initialized = false; | 834 static bool initialized = false; |
834 static uint32_t sequence[kNoCodeAgeSequenceLength]; | 835 static uint32_t sequence[kNoCodeAgeSequenceLength]; |
835 byte* byte_sequence = reinterpret_cast<byte*>(sequence); | 836 byte* byte_sequence = reinterpret_cast<byte*>(sequence); |
836 *length = kNoCodeAgeSequenceLength * Assembler::kInstrSize; | 837 *length = kNoCodeAgeSequenceLength * Assembler::kInstrSize; |
837 if (!initialized) { | 838 if (!initialized) { |
838 CodePatcher patcher(byte_sequence, kNoCodeAgeSequenceLength); | 839 CodePatcher patcher(byte_sequence, kNoCodeAgeSequenceLength); |
839 PredictableCodeSizeScope scope(patcher.masm(), *length); | 840 PredictableCodeSizeScope scope(patcher.masm(), *length); |
840 patcher.masm()->stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); | 841 patcher.masm()->stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
841 patcher.masm()->nop(ip.code()); | 842 patcher.masm()->nop(ip.code()); |
842 patcher.masm()->add(fp, sp, Operand(2 * kPointerSize)); | 843 patcher.masm()->add(fp, sp, Operand(2 * kPointerSize)); |
843 initialized = true; | 844 initialized = true; |
844 } | 845 } |
845 return byte_sequence; | 846 return byte_sequence; |
846 } | 847 } |
847 | 848 |
848 | 849 |
849 bool Code::IsYoungSequence(byte* sequence) { | 850 static byte* GetThumbNoCodeAgeSequence(uint32_t* length) { |
| 851 // The sequence of instructions that is patched out for aging code is the |
| 852 // following boilerplate stack-building prologue that is found in FUNCTIONS |
| 853 static bool initialized = false; |
| 854 static uint32_t sequence[kNoCodeAgeSequenceLength]; |
| 855 byte* byte_sequence = reinterpret_cast<byte*>(sequence); |
| 856 *length = kNoCodeAgeSequenceLength * Assembler::kInstrSize; |
| 857 if (!initialized) { |
| 858 CodePatcher patcher(byte_sequence, kNoCodeAgeSequenceLength); |
| 859 PredictableCodeSizeScope scope(patcher.masm(), *length); |
| 860 patcher.masm()->set_thumb_mode(); |
| 861 patcher.masm()->stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 862 patcher.masm()->nop(ip.code()); |
| 863 patcher.masm()->nop(ip.code()); |
| 864 patcher.masm()->add(fp, sp, Operand(2 * kPointerSize)); |
| 865 initialized = true; |
| 866 } |
| 867 return byte_sequence; |
| 868 } |
| 869 |
| 870 |
| 871 bool Code::IsYoungSequence(byte* sequence, bool thumb_mode) { |
850 uint32_t young_length; | 872 uint32_t young_length; |
851 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 873 byte* young_sequence = thumb_mode ? GetThumbNoCodeAgeSequence(&young_length) : |
| 874 GetNoCodeAgeSequence(&young_length); |
852 bool result = !memcmp(sequence, young_sequence, young_length); | 875 bool result = !memcmp(sequence, young_sequence, young_length); |
853 ASSERT(result || | 876 ASSERT(result || |
854 Memory::uint32_at(sequence) == kCodeAgePatchFirstInstruction); | 877 Memory::uint32_at(sequence) == kCodeAgePatchFirstInstruction || |
| 878 Memory::uint32_at(sequence) == kThumbCodeAgePatchFirstInstruction); |
855 return result; | 879 return result; |
856 } | 880 } |
857 | 881 |
858 | 882 |
859 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, | 883 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, |
860 MarkingParity* parity) { | 884 MarkingParity* parity, |
861 if (IsYoungSequence(sequence)) { | 885 bool thumb_mode) { |
| 886 if (IsYoungSequence(sequence, thumb_mode)) { |
862 *age = kNoAge; | 887 *age = kNoAge; |
863 *parity = NO_MARKING_PARITY; | 888 *parity = NO_MARKING_PARITY; |
864 } else { | 889 } else { |
865 Address target_address = Memory::Address_at( | 890 Address target_address = Memory::Address_at( |
866 sequence + Assembler::kInstrSize * (kNoCodeAgeSequenceLength - 1)); | 891 sequence + Assembler::kInstrSize * (kNoCodeAgeSequenceLength - 1)); |
867 Code* stub = GetCodeFromTargetAddress(target_address); | 892 Code* stub = GetCodeFromTargetAddress(target_address); |
868 GetCodeAgeAndParity(stub, age, parity); | 893 GetCodeAgeAndParity(stub, age, parity); |
869 } | 894 } |
870 } | 895 } |
871 | 896 |
872 | 897 |
873 void Code::PatchPlatformCodeAge(byte* sequence, | 898 void Code::PatchPlatformCodeAge(byte* sequence, |
874 Code::Age age, | 899 Code::Age age, |
875 MarkingParity parity) { | 900 MarkingParity parity, |
| 901 bool thumb_mode) { |
876 uint32_t young_length; | 902 uint32_t young_length; |
877 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 903 if (((uint32_t)sequence & 1) == 1) { |
| 904 thumb_mode = true; |
| 905 sequence = reinterpret_cast<byte*>((uint32_t)sequence & ~1); |
| 906 } |
| 907 byte* young_sequence = thumb_mode? GetThumbNoCodeAgeSequence(&young_length) : |
| 908 GetNoCodeAgeSequence(&young_length); |
878 if (age == kNoAge) { | 909 if (age == kNoAge) { |
879 CopyBytes(sequence, young_sequence, young_length); | 910 CopyBytes(sequence, young_sequence, young_length); |
880 CPU::FlushICache(sequence, young_length); | 911 CPU::FlushICache(sequence, young_length); |
881 } else { | 912 } else { |
882 Code* stub = GetCodeAgeStub(age, parity); | 913 Code* stub = GetCodeAgeStub(age, parity); |
883 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); | 914 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); |
884 patcher.masm()->add(r0, pc, Operand(-8)); | 915 if (thumb_mode) { |
885 patcher.masm()->ldr(pc, MemOperand(pc, -4)); | 916 patcher.masm()->set_thumb_mode(); |
| 917 patcher.masm()->sub(r0, pc, Operand(3)); |
| 918 patcher.masm()->ldr(pc, MemOperand(pc, 0)); |
| 919 } else { |
| 920 patcher.masm()->sub(r0, pc, Operand(8)); |
| 921 patcher.masm()->ldr(pc, MemOperand(pc, -4)); |
| 922 } |
886 patcher.masm()->dd(reinterpret_cast<uint32_t>(stub->instruction_start())); | 923 patcher.masm()->dd(reinterpret_cast<uint32_t>(stub->instruction_start())); |
887 } | 924 } |
888 } | 925 } |
889 | 926 |
890 | 927 |
891 } } // namespace v8::internal | 928 } } // namespace v8::internal |
892 | 929 |
893 #endif // V8_TARGET_ARCH_ARM | 930 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |