| 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 "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/cpu-profiler.h" | 9 #include "src/cpu-profiler.h" |
| 10 #include "src/log.h" | 10 #include "src/log.h" |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 | 1171 |
| 1172 // Helper function for reading a value out of a stack frame. | 1172 // Helper function for reading a value out of a stack frame. |
| 1173 template <typename T> | 1173 template <typename T> |
| 1174 static T& frame_entry(Address re_frame, int frame_offset) { | 1174 static T& frame_entry(Address re_frame, int frame_offset) { |
| 1175 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1175 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 | 1178 |
| 1179 template <typename T> |
| 1180 static T* frame_entry_address(Address re_frame, int frame_offset) { |
| 1181 return reinterpret_cast<T*>(re_frame + frame_offset); |
| 1182 } |
| 1183 |
| 1184 |
| 1179 int RegExpMacroAssemblerX64::CheckStackGuardState(Address* return_address, | 1185 int RegExpMacroAssemblerX64::CheckStackGuardState(Address* return_address, |
| 1180 Code* re_code, | 1186 Code* re_code, |
| 1181 Address re_frame) { | 1187 Address re_frame) { |
| 1182 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | 1188 return NativeRegExpMacroAssembler::CheckStackGuardState( |
| 1183 StackLimitCheck check(isolate); | 1189 frame_entry<Isolate*>(re_frame, kIsolate), |
| 1184 if (check.JsHasOverflowed()) { | 1190 frame_entry<int>(re_frame, kStartIndex), |
| 1185 isolate->StackOverflow(); | 1191 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code, |
| 1186 return EXCEPTION; | 1192 frame_entry_address<String*>(re_frame, kInputString), |
| 1187 } | 1193 frame_entry_address<const byte*>(re_frame, kInputStart), |
| 1188 | 1194 frame_entry_address<const byte*>(re_frame, kInputEnd)); |
| 1189 // If not real stack overflow the stack guard was used to interrupt | |
| 1190 // execution for another purpose. | |
| 1191 | |
| 1192 // If this is a direct call from JavaScript retry the RegExp forcing the call | |
| 1193 // through the runtime system. Currently the direct call cannot handle a GC. | |
| 1194 if (frame_entry<int>(re_frame, kDirectCall) == 1) { | |
| 1195 return RETRY; | |
| 1196 } | |
| 1197 | |
| 1198 // Prepare for possible GC. | |
| 1199 HandleScope handles(isolate); | |
| 1200 Handle<Code> code_handle(re_code); | |
| 1201 | |
| 1202 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); | |
| 1203 | |
| 1204 // Current string. | |
| 1205 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | |
| 1206 | |
| 1207 DCHECK(re_code->instruction_start() <= *return_address); | |
| 1208 DCHECK(*return_address <= | |
| 1209 re_code->instruction_start() + re_code->instruction_size()); | |
| 1210 | |
| 1211 Object* result = isolate->stack_guard()->HandleInterrupts(); | |
| 1212 | |
| 1213 if (*code_handle != re_code) { // Return address no longer valid | |
| 1214 intptr_t delta = code_handle->address() - re_code->address(); | |
| 1215 // Overwrite the return address on the stack. | |
| 1216 *return_address += delta; | |
| 1217 } | |
| 1218 | |
| 1219 if (result->IsException()) { | |
| 1220 return EXCEPTION; | |
| 1221 } | |
| 1222 | |
| 1223 Handle<String> subject_tmp = subject; | |
| 1224 int slice_offset = 0; | |
| 1225 | |
| 1226 // Extract the underlying string and the slice offset. | |
| 1227 if (StringShape(*subject_tmp).IsCons()) { | |
| 1228 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first()); | |
| 1229 } else if (StringShape(*subject_tmp).IsSliced()) { | |
| 1230 SlicedString* slice = SlicedString::cast(*subject_tmp); | |
| 1231 subject_tmp = Handle<String>(slice->parent()); | |
| 1232 slice_offset = slice->offset(); | |
| 1233 } | |
| 1234 | |
| 1235 // String might have changed. | |
| 1236 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) { | |
| 1237 // If we changed between an Latin1 and an UC16 string, the specialized | |
| 1238 // code cannot be used, and we need to restart regexp matching from | |
| 1239 // scratch (including, potentially, compiling a new version of the code). | |
| 1240 return RETRY; | |
| 1241 } | |
| 1242 | |
| 1243 // Otherwise, the content of the string might have moved. It must still | |
| 1244 // be a sequential or external string with the same content. | |
| 1245 // Update the start and end pointers in the stack frame to the current | |
| 1246 // location (whether it has actually moved or not). | |
| 1247 DCHECK(StringShape(*subject_tmp).IsSequential() || | |
| 1248 StringShape(*subject_tmp).IsExternal()); | |
| 1249 | |
| 1250 // The original start address of the characters to match. | |
| 1251 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart); | |
| 1252 | |
| 1253 // Find the current start address of the same character at the current string | |
| 1254 // position. | |
| 1255 int start_index = frame_entry<int>(re_frame, kStartIndex); | |
| 1256 const byte* new_address = StringCharacterPosition(*subject_tmp, | |
| 1257 start_index + slice_offset); | |
| 1258 | |
| 1259 if (start_address != new_address) { | |
| 1260 // If there is a difference, update the object pointer and start and end | |
| 1261 // addresses in the RegExp stack frame to match the new value. | |
| 1262 const byte* end_address = frame_entry<const byte* >(re_frame, kInputEnd); | |
| 1263 int byte_length = static_cast<int>(end_address - start_address); | |
| 1264 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
| 1265 frame_entry<const byte*>(re_frame, kInputStart) = new_address; | |
| 1266 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length; | |
| 1267 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) { | |
| 1268 // Subject string might have been a ConsString that underwent | |
| 1269 // short-circuiting during GC. That will not change start_address but | |
| 1270 // will change pointer inside the subject handle. | |
| 1271 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
| 1272 } | |
| 1273 | |
| 1274 return 0; | |
| 1275 } | 1195 } |
| 1276 | 1196 |
| 1277 | 1197 |
| 1278 Operand RegExpMacroAssemblerX64::register_location(int register_index) { | 1198 Operand RegExpMacroAssemblerX64::register_location(int register_index) { |
| 1279 DCHECK(register_index < (1<<30)); | 1199 DCHECK(register_index < (1<<30)); |
| 1280 if (num_registers_ <= register_index) { | 1200 if (num_registers_ <= register_index) { |
| 1281 num_registers_ = register_index + 1; | 1201 num_registers_ = register_index + 1; |
| 1282 } | 1202 } |
| 1283 return Operand(rbp, kRegisterZero - register_index * kPointerSize); | 1203 return Operand(rbp, kRegisterZero - register_index * kPointerSize); |
| 1284 } | 1204 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 } | 1352 } |
| 1433 } | 1353 } |
| 1434 | 1354 |
| 1435 #undef __ | 1355 #undef __ |
| 1436 | 1356 |
| 1437 #endif // V8_INTERPRETED_REGEXP | 1357 #endif // V8_INTERPRETED_REGEXP |
| 1438 | 1358 |
| 1439 }} // namespace v8::internal | 1359 }} // namespace v8::internal |
| 1440 | 1360 |
| 1441 #endif // V8_TARGET_ARCH_X64 | 1361 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |