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 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 __ pshufd(input, input, static_cast<uint8_t>(0xe1)); // Order: 11 10 00 01 | 1113 __ pshufd(input, input, static_cast<uint8_t>(0xe1)); // Order: 11 10 00 01 |
1114 __ movdbl(double_scratch, Operand::StaticArray( | 1114 __ movdbl(double_scratch, Operand::StaticArray( |
1115 temp2, times_8, ExternalReference::math_exp_log_table())); | 1115 temp2, times_8, ExternalReference::math_exp_log_table())); |
1116 __ por(input, double_scratch); | 1116 __ por(input, double_scratch); |
1117 __ mulsd(result, input); | 1117 __ mulsd(result, input); |
1118 __ bind(&done); | 1118 __ bind(&done); |
1119 } | 1119 } |
1120 | 1120 |
1121 #undef __ | 1121 #undef __ |
1122 | 1122 |
1123 static const int kNoCodeAgeSequenceLength = 5; | 1123 static const int kCodeAgeSequenceLength = 6; |
1124 | 1124 |
1125 static byte* GetNoCodeAgeSequence(uint32_t* length) { | 1125 static byte* GetNoCodeAgeSequence(uint32_t* length) { |
1126 static bool initialized = false; | 1126 static bool initialized = false; |
1127 static byte sequence[kNoCodeAgeSequenceLength]; | 1127 static byte sequence[kCodeAgeSequenceLength]; |
1128 *length = kNoCodeAgeSequenceLength; | 1128 *length = kCodeAgeSequenceLength; |
1129 if (!initialized) { | 1129 if (!initialized) { |
1130 // The sequence of instructions that is patched out for aging code is the | 1130 // The sequence of instructions that is patched out for aging code is the |
1131 // following boilerplate stack-building prologue that is found both in | 1131 // following boilerplate stack-building prologue that is found both in |
1132 // FUNCTION and OPTIMIZED_FUNCTION code: | 1132 // FUNCTION and OPTIMIZED_FUNCTION code: |
1133 CodePatcher patcher(sequence, kNoCodeAgeSequenceLength); | 1133 CodePatcher patcher(sequence, kCodeAgeSequenceLength); |
1134 patcher.masm()->push(ebp); | 1134 patcher.masm()->push(ebp); |
1135 patcher.masm()->mov(ebp, esp); | 1135 patcher.masm()->mov(ebp, esp); |
| 1136 patcher.masm()->nop(); |
1136 patcher.masm()->push(esi); | 1137 patcher.masm()->push(esi); |
1137 patcher.masm()->push(edi); | 1138 patcher.masm()->push(edi); |
1138 initialized = true; | 1139 initialized = true; |
1139 } | 1140 } |
1140 return sequence; | 1141 return sequence; |
1141 } | 1142 } |
1142 | 1143 |
1143 | 1144 |
| 1145 static byte* GetPreAgedCodeAgeSequence(uint32_t* length) { |
| 1146 static bool initialized = false; |
| 1147 static byte sequence[kCodeAgeSequenceLength]; |
| 1148 *length = kCodeAgeSequenceLength; |
| 1149 if (!initialized) { |
| 1150 // If code is "pre-aged" then this sequence of instructions is found in the |
| 1151 // boilerplate stack-building prologue that is found in FUNCTIONS and |
| 1152 // OPTIMIZED_FUNCTION code, and is patched out for code aging. |
| 1153 CodePatcher patcher(sequence, kCodeAgeSequenceLength); |
| 1154 patcher.masm()->push(ebp); |
| 1155 patcher.masm()->mov(ebp, esp); |
| 1156 patcher.masm()->push(esi); |
| 1157 patcher.masm()->nop(); |
| 1158 patcher.masm()->push(edi); |
| 1159 initialized = true; |
| 1160 } |
| 1161 return sequence; |
| 1162 } |
| 1163 |
| 1164 |
1144 bool Code::IsYoungSequence(byte* sequence) { | 1165 bool Code::IsYoungSequence(byte* sequence) { |
1145 uint32_t young_length; | 1166 uint32_t young_length; |
1146 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 1167 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
1147 bool result = (!memcmp(sequence, young_sequence, young_length)); | 1168 bool result = (!memcmp(sequence, young_sequence, young_length)); |
1148 ASSERT(result || *sequence == kCallOpcode); | 1169 ASSERT(result || *sequence == kCallOpcode || IsPreAgedSequence(sequence)); |
1149 return result; | 1170 return result; |
1150 } | 1171 } |
1151 | 1172 |
| 1173 |
| 1174 bool Code::IsPreAgedSequence(byte* sequence) { |
| 1175 uint32_t pre_aged_length; |
| 1176 byte* pre_aged_sequence = GetPreAgedCodeAgeSequence(&pre_aged_length); |
| 1177 bool result = (!memcmp(sequence, pre_aged_sequence, pre_aged_length)); |
| 1178 ASSERT(result || *sequence == kCallOpcode || IsYoungSequence(sequence)); |
| 1179 return result; |
| 1180 } |
| 1181 |
1152 | 1182 |
1153 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, | 1183 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, |
1154 MarkingParity* parity) { | 1184 MarkingParity* parity) { |
1155 if (IsYoungSequence(sequence)) { | 1185 if (IsYoungSequence(sequence)) { |
1156 *age = kNoAge; | 1186 *age = kNoAge; |
1157 *parity = NO_MARKING_PARITY; | 1187 *parity = NO_MARKING_PARITY; |
| 1188 } else if (IsPreAgedSequence(sequence)) { |
| 1189 *age = kPreAgedCodeAge; |
| 1190 *parity = NO_MARKING_PARITY; |
1158 } else { | 1191 } else { |
1159 sequence++; // Skip the kCallOpcode byte | 1192 sequence++; // Skip the kCallOpcode byte |
1160 Address target_address = sequence + *reinterpret_cast<int*>(sequence) + | 1193 Address target_address = sequence + *reinterpret_cast<int*>(sequence) + |
1161 Assembler::kCallTargetAddressOffset; | 1194 Assembler::kCallTargetAddressOffset; |
1162 Code* stub = GetCodeFromTargetAddress(target_address); | 1195 Code* stub = GetCodeFromTargetAddress(target_address); |
1163 GetCodeAgeAndParity(stub, age, parity); | 1196 GetCodeAgeAndParity(stub, age, parity); |
1164 } | 1197 } |
1165 } | 1198 } |
1166 | 1199 |
1167 | 1200 |
1168 void Code::PatchPlatformCodeAge(Isolate* isolate, | 1201 void Code::PatchPlatformCodeAge(Isolate* isolate, |
1169 byte* sequence, | 1202 byte* sequence, |
1170 Code::Age age, | 1203 Code::Age age, |
1171 MarkingParity parity) { | 1204 MarkingParity parity) { |
1172 uint32_t young_length; | 1205 uint32_t young_length; |
1173 byte* young_sequence = GetNoCodeAgeSequence(&young_length); | 1206 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
1174 if (age == kNoAge) { | 1207 if (age == kNoAge) { |
1175 CopyBytes(sequence, young_sequence, young_length); | 1208 CopyBytes(sequence, young_sequence, young_length); |
1176 CPU::FlushICache(sequence, young_length); | 1209 CPU::FlushICache(sequence, young_length); |
1177 } else { | 1210 } else { |
1178 Code* stub = GetCodeAgeStub(isolate, age, parity); | 1211 Code* stub = GetCodeAgeStub(isolate, age, parity); |
1179 CodePatcher patcher(sequence, young_length); | 1212 CodePatcher patcher(sequence, young_length); |
1180 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); | 1213 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); |
| 1214 patcher.masm()->nop(); |
1181 } | 1215 } |
1182 } | 1216 } |
1183 | 1217 |
1184 | 1218 |
1185 } } // namespace v8::internal | 1219 } } // namespace v8::internal |
1186 | 1220 |
1187 #endif // V8_TARGET_ARCH_IA32 | 1221 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |