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_ARM | 7 #if V8_TARGET_ARCH_ARM |
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 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 } | 1033 } |
1034 | 1034 |
1035 | 1035 |
1036 // Helper function for reading a value out of a stack frame. | 1036 // Helper function for reading a value out of a stack frame. |
1037 template <typename T> | 1037 template <typename T> |
1038 static T& frame_entry(Address re_frame, int frame_offset) { | 1038 static T& frame_entry(Address re_frame, int frame_offset) { |
1039 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1039 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
1040 } | 1040 } |
1041 | 1041 |
1042 | 1042 |
| 1043 template <typename T> |
| 1044 static T* frame_entry_address(Address re_frame, int frame_offset) { |
| 1045 return reinterpret_cast<T*>(re_frame + frame_offset); |
| 1046 } |
| 1047 |
| 1048 |
1043 int RegExpMacroAssemblerARM::CheckStackGuardState(Address* return_address, | 1049 int RegExpMacroAssemblerARM::CheckStackGuardState(Address* return_address, |
1044 Code* re_code, | 1050 Code* re_code, |
1045 Address re_frame) { | 1051 Address re_frame) { |
1046 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | 1052 return NativeRegExpMacroAssembler::CheckStackGuardState( |
1047 StackLimitCheck check(isolate); | 1053 frame_entry<Isolate*>(re_frame, kIsolate), |
1048 if (check.JsHasOverflowed()) { | 1054 frame_entry<int>(re_frame, kStartIndex), |
1049 isolate->StackOverflow(); | 1055 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code, |
1050 return EXCEPTION; | 1056 frame_entry_address<String*>(re_frame, kInputString), |
1051 } | 1057 frame_entry_address<const byte*>(re_frame, kInputStart), |
1052 | 1058 frame_entry_address<const byte*>(re_frame, kInputEnd)); |
1053 // If not real stack overflow the stack guard was used to interrupt | |
1054 // execution for another purpose. | |
1055 | |
1056 // If this is a direct call from JavaScript retry the RegExp forcing the call | |
1057 // through the runtime system. Currently the direct call cannot handle a GC. | |
1058 if (frame_entry<int>(re_frame, kDirectCall) == 1) { | |
1059 return RETRY; | |
1060 } | |
1061 | |
1062 // Prepare for possible GC. | |
1063 HandleScope handles(isolate); | |
1064 Handle<Code> code_handle(re_code); | |
1065 | |
1066 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); | |
1067 | |
1068 // Current string. | |
1069 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | |
1070 | |
1071 DCHECK(re_code->instruction_start() <= *return_address); | |
1072 DCHECK(*return_address <= | |
1073 re_code->instruction_start() + re_code->instruction_size()); | |
1074 | |
1075 Object* result = isolate->stack_guard()->HandleInterrupts(); | |
1076 | |
1077 if (*code_handle != re_code) { // Return address no longer valid | |
1078 int delta = code_handle->address() - re_code->address(); | |
1079 // Overwrite the return address on the stack. | |
1080 *return_address += delta; | |
1081 } | |
1082 | |
1083 if (result->IsException()) { | |
1084 return EXCEPTION; | |
1085 } | |
1086 | |
1087 Handle<String> subject_tmp = subject; | |
1088 int slice_offset = 0; | |
1089 | |
1090 // Extract the underlying string and the slice offset. | |
1091 if (StringShape(*subject_tmp).IsCons()) { | |
1092 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first()); | |
1093 } else if (StringShape(*subject_tmp).IsSliced()) { | |
1094 SlicedString* slice = SlicedString::cast(*subject_tmp); | |
1095 subject_tmp = Handle<String>(slice->parent()); | |
1096 slice_offset = slice->offset(); | |
1097 } | |
1098 | |
1099 // String might have changed. | |
1100 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) { | |
1101 // If we changed between an Latin1 and an UC16 string, the specialized | |
1102 // code cannot be used, and we need to restart regexp matching from | |
1103 // scratch (including, potentially, compiling a new version of the code). | |
1104 return RETRY; | |
1105 } | |
1106 | |
1107 // Otherwise, the content of the string might have moved. It must still | |
1108 // be a sequential or external string with the same content. | |
1109 // Update the start and end pointers in the stack frame to the current | |
1110 // location (whether it has actually moved or not). | |
1111 DCHECK(StringShape(*subject_tmp).IsSequential() || | |
1112 StringShape(*subject_tmp).IsExternal()); | |
1113 | |
1114 // The original start address of the characters to match. | |
1115 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart); | |
1116 | |
1117 // Find the current start address of the same character at the current string | |
1118 // position. | |
1119 int start_index = frame_entry<int>(re_frame, kStartIndex); | |
1120 const byte* new_address = StringCharacterPosition(*subject_tmp, | |
1121 start_index + slice_offset); | |
1122 | |
1123 if (start_address != new_address) { | |
1124 // If there is a difference, update the object pointer and start and end | |
1125 // addresses in the RegExp stack frame to match the new value. | |
1126 const byte* end_address = frame_entry<const byte* >(re_frame, kInputEnd); | |
1127 int byte_length = static_cast<int>(end_address - start_address); | |
1128 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
1129 frame_entry<const byte*>(re_frame, kInputStart) = new_address; | |
1130 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length; | |
1131 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) { | |
1132 // Subject string might have been a ConsString that underwent | |
1133 // short-circuiting during GC. That will not change start_address but | |
1134 // will change pointer inside the subject handle. | |
1135 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
1136 } | |
1137 | |
1138 return 0; | |
1139 } | 1059 } |
1140 | 1060 |
1141 | 1061 |
1142 MemOperand RegExpMacroAssemblerARM::register_location(int register_index) { | 1062 MemOperand RegExpMacroAssemblerARM::register_location(int register_index) { |
1143 DCHECK(register_index < (1<<30)); | 1063 DCHECK(register_index < (1<<30)); |
1144 if (num_registers_ <= register_index) { | 1064 if (num_registers_ <= register_index) { |
1145 num_registers_ = register_index + 1; | 1065 num_registers_ = register_index + 1; |
1146 } | 1066 } |
1147 return MemOperand(frame_pointer(), | 1067 return MemOperand(frame_pointer(), |
1148 kRegisterZero - register_index * kPointerSize); | 1068 kRegisterZero - register_index * kPointerSize); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 } | 1189 } |
1270 | 1190 |
1271 | 1191 |
1272 #undef __ | 1192 #undef __ |
1273 | 1193 |
1274 #endif // V8_INTERPRETED_REGEXP | 1194 #endif // V8_INTERPRETED_REGEXP |
1275 | 1195 |
1276 }} // namespace v8::internal | 1196 }} // namespace v8::internal |
1277 | 1197 |
1278 #endif // V8_TARGET_ARCH_ARM | 1198 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |