| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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_ARM64 | 7 #if V8_TARGET_ARCH_ARM64 |
| 8 | 8 |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/cpu-profiler.h" | 10 #include "src/cpu-profiler.h" |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 } | 1278 } |
| 1279 | 1279 |
| 1280 | 1280 |
| 1281 // Helper function for reading a value out of a stack frame. | 1281 // Helper function for reading a value out of a stack frame. |
| 1282 template <typename T> | 1282 template <typename T> |
| 1283 static T& frame_entry(Address re_frame, int frame_offset) { | 1283 static T& frame_entry(Address re_frame, int frame_offset) { |
| 1284 return *reinterpret_cast<T*>(re_frame + frame_offset); | 1284 return *reinterpret_cast<T*>(re_frame + frame_offset); |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 | 1287 |
| 1288 int RegExpMacroAssemblerARM64::CheckStackGuardState(Address* return_address, | 1288 template <typename T> |
| 1289 Code* re_code, | 1289 static T* frame_entry_address(Address re_frame, int frame_offset) { |
| 1290 Address re_frame, | 1290 return reinterpret_cast<T*>(re_frame + frame_offset); |
| 1291 int start_offset, | |
| 1292 const byte** input_start, | |
| 1293 const byte** input_end) { | |
| 1294 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | |
| 1295 StackLimitCheck check(isolate); | |
| 1296 if (check.JsHasOverflowed()) { | |
| 1297 isolate->StackOverflow(); | |
| 1298 return EXCEPTION; | |
| 1299 } | |
| 1300 | |
| 1301 // If not real stack overflow the stack guard was used to interrupt | |
| 1302 // execution for another purpose. | |
| 1303 | |
| 1304 // If this is a direct call from JavaScript retry the RegExp forcing the call | |
| 1305 // through the runtime system. Currently the direct call cannot handle a GC. | |
| 1306 if (frame_entry<int>(re_frame, kDirectCall) == 1) { | |
| 1307 return RETRY; | |
| 1308 } | |
| 1309 | |
| 1310 // Prepare for possible GC. | |
| 1311 HandleScope handles(isolate); | |
| 1312 Handle<Code> code_handle(re_code); | |
| 1313 | |
| 1314 Handle<String> subject(frame_entry<String*>(re_frame, kInput)); | |
| 1315 | |
| 1316 // Current string. | |
| 1317 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | |
| 1318 | |
| 1319 DCHECK(re_code->instruction_start() <= *return_address); | |
| 1320 DCHECK(*return_address <= | |
| 1321 re_code->instruction_start() + re_code->instruction_size()); | |
| 1322 | |
| 1323 Object* result = isolate->stack_guard()->HandleInterrupts(); | |
| 1324 | |
| 1325 if (*code_handle != re_code) { // Return address no longer valid | |
| 1326 int delta = code_handle->address() - re_code->address(); | |
| 1327 // Overwrite the return address on the stack. | |
| 1328 *return_address += delta; | |
| 1329 } | |
| 1330 | |
| 1331 if (result->IsException()) { | |
| 1332 return EXCEPTION; | |
| 1333 } | |
| 1334 | |
| 1335 Handle<String> subject_tmp = subject; | |
| 1336 int slice_offset = 0; | |
| 1337 | |
| 1338 // Extract the underlying string and the slice offset. | |
| 1339 if (StringShape(*subject_tmp).IsCons()) { | |
| 1340 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first()); | |
| 1341 } else if (StringShape(*subject_tmp).IsSliced()) { | |
| 1342 SlicedString* slice = SlicedString::cast(*subject_tmp); | |
| 1343 subject_tmp = Handle<String>(slice->parent()); | |
| 1344 slice_offset = slice->offset(); | |
| 1345 } | |
| 1346 | |
| 1347 // String might have changed. | |
| 1348 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) { | |
| 1349 // If we changed between an Latin1 and an UC16 string, the specialized | |
| 1350 // code cannot be used, and we need to restart regexp matching from | |
| 1351 // scratch (including, potentially, compiling a new version of the code). | |
| 1352 return RETRY; | |
| 1353 } | |
| 1354 | |
| 1355 // Otherwise, the content of the string might have moved. It must still | |
| 1356 // be a sequential or external string with the same content. | |
| 1357 // Update the start and end pointers in the stack frame to the current | |
| 1358 // location (whether it has actually moved or not). | |
| 1359 DCHECK(StringShape(*subject_tmp).IsSequential() || | |
| 1360 StringShape(*subject_tmp).IsExternal()); | |
| 1361 | |
| 1362 // The original start address of the characters to match. | |
| 1363 const byte* start_address = *input_start; | |
| 1364 | |
| 1365 // Find the current start address of the same character at the current string | |
| 1366 // position. | |
| 1367 const byte* new_address = StringCharacterPosition(*subject_tmp, | |
| 1368 start_offset + slice_offset); | |
| 1369 | |
| 1370 if (start_address != new_address) { | |
| 1371 // If there is a difference, update the object pointer and start and end | |
| 1372 // addresses in the RegExp stack frame to match the new value. | |
| 1373 const byte* end_address = *input_end; | |
| 1374 int byte_length = static_cast<int>(end_address - start_address); | |
| 1375 frame_entry<const String*>(re_frame, kInput) = *subject; | |
| 1376 *input_start = new_address; | |
| 1377 *input_end = new_address + byte_length; | |
| 1378 } else if (frame_entry<const String*>(re_frame, kInput) != *subject) { | |
| 1379 // Subject string might have been a ConsString that underwent | |
| 1380 // short-circuiting during GC. That will not change start_address but | |
| 1381 // will change pointer inside the subject handle. | |
| 1382 frame_entry<const String*>(re_frame, kInput) = *subject; | |
| 1383 } | |
| 1384 | |
| 1385 return 0; | |
| 1386 } | 1291 } |
| 1387 | 1292 |
| 1388 | 1293 |
| 1294 int RegExpMacroAssemblerARM64::CheckStackGuardState( |
| 1295 Address* return_address, Code* re_code, Address re_frame, int start_index, |
| 1296 const byte** input_start, const byte** input_end) { |
| 1297 return NativeRegExpMacroAssembler::CheckStackGuardState( |
| 1298 frame_entry<Isolate*>(re_frame, kIsolate), start_index, |
| 1299 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code, |
| 1300 frame_entry_address<String*>(re_frame, kInput), input_start, input_end); |
| 1301 } |
| 1302 |
| 1303 |
| 1389 void RegExpMacroAssemblerARM64::CheckPosition(int cp_offset, | 1304 void RegExpMacroAssemblerARM64::CheckPosition(int cp_offset, |
| 1390 Label* on_outside_input) { | 1305 Label* on_outside_input) { |
| 1391 CompareAndBranchOrBacktrack(current_input_offset(), | 1306 CompareAndBranchOrBacktrack(current_input_offset(), |
| 1392 -cp_offset * char_size(), | 1307 -cp_offset * char_size(), |
| 1393 ge, | 1308 ge, |
| 1394 on_outside_input); | 1309 on_outside_input); |
| 1395 } | 1310 } |
| 1396 | 1311 |
| 1397 | 1312 |
| 1398 bool RegExpMacroAssemblerARM64::CanReadUnaligned() { | 1313 bool RegExpMacroAssemblerARM64::CanReadUnaligned() { |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 __ Ldrh(current_character(), MemOperand(input_end(), offset, SXTW)); | 1607 __ Ldrh(current_character(), MemOperand(input_end(), offset, SXTW)); |
| 1693 } | 1608 } |
| 1694 } | 1609 } |
| 1695 } | 1610 } |
| 1696 | 1611 |
| 1697 #endif // V8_INTERPRETED_REGEXP | 1612 #endif // V8_INTERPRETED_REGEXP |
| 1698 | 1613 |
| 1699 }} // namespace v8::internal | 1614 }} // namespace v8::internal |
| 1700 | 1615 |
| 1701 #endif // V8_TARGET_ARCH_ARM64 | 1616 #endif // V8_TARGET_ARCH_ARM64 |
| OLD | NEW |