| 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_MIPS | 7 #if V8_TARGET_ARCH_MIPS |
| 8 | 8 |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/log.h" | 10 #include "src/log.h" |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1093 } |
| 1094 | 1094 |
| 1095 | 1095 |
| 1096 // Helper function for reading a value out of a stack frame. | 1096 // Helper function for reading a value out of a stack frame. |
| 1097 template <typename T> | 1097 template <typename T> |
| 1098 static T& frame_entry(Address re_frame, int frame_offset) { | 1098 static T& frame_entry(Address re_frame, int frame_offset) { |
| 1099 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1099 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 | 1102 |
| 1103 template <typename T> |
| 1104 static T* frame_entry_address(Address re_frame, int frame_offset) { |
| 1105 return reinterpret_cast<T*>(re_frame + frame_offset); |
| 1106 } |
| 1107 |
| 1108 |
| 1103 int RegExpMacroAssemblerMIPS::CheckStackGuardState(Address* return_address, | 1109 int RegExpMacroAssemblerMIPS::CheckStackGuardState(Address* return_address, |
| 1104 Code* re_code, | 1110 Code* re_code, |
| 1105 Address re_frame) { | 1111 Address re_frame) { |
| 1106 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | 1112 return NativeRegExpMacroAssembler::CheckStackGuardState( |
| 1107 StackLimitCheck check(isolate); | 1113 frame_entry<Isolate*>(re_frame, kIsolate), |
| 1108 if (check.JsHasOverflowed()) { | 1114 frame_entry<int>(re_frame, kStartIndex), |
| 1109 isolate->StackOverflow(); | 1115 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code, |
| 1110 return EXCEPTION; | 1116 frame_entry_address<String*>(re_frame, kInputString), |
| 1111 } | 1117 frame_entry_address<const byte*>(re_frame, kInputStart), |
| 1112 | 1118 frame_entry_address<const byte*>(re_frame, kInputEnd)); |
| 1113 // If not real stack overflow the stack guard was used to interrupt | |
| 1114 // execution for another purpose. | |
| 1115 | |
| 1116 // If this is a direct call from JavaScript retry the RegExp forcing the call | |
| 1117 // through the runtime system. Currently the direct call cannot handle a GC. | |
| 1118 if (frame_entry<int>(re_frame, kDirectCall) == 1) { | |
| 1119 return RETRY; | |
| 1120 } | |
| 1121 | |
| 1122 // Prepare for possible GC. | |
| 1123 HandleScope handles(isolate); | |
| 1124 Handle<Code> code_handle(re_code); | |
| 1125 | |
| 1126 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); | |
| 1127 // Current string. | |
| 1128 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | |
| 1129 | |
| 1130 DCHECK(re_code->instruction_start() <= *return_address); | |
| 1131 DCHECK(*return_address <= | |
| 1132 re_code->instruction_start() + re_code->instruction_size()); | |
| 1133 | |
| 1134 Object* result = isolate->stack_guard()->HandleInterrupts(); | |
| 1135 | |
| 1136 if (*code_handle != re_code) { // Return address no longer valid. | |
| 1137 int delta = code_handle->address() - re_code->address(); | |
| 1138 // Overwrite the return address on the stack. | |
| 1139 *return_address += delta; | |
| 1140 } | |
| 1141 | |
| 1142 if (result->IsException()) { | |
| 1143 return EXCEPTION; | |
| 1144 } | |
| 1145 | |
| 1146 Handle<String> subject_tmp = subject; | |
| 1147 int slice_offset = 0; | |
| 1148 | |
| 1149 // Extract the underlying string and the slice offset. | |
| 1150 if (StringShape(*subject_tmp).IsCons()) { | |
| 1151 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first()); | |
| 1152 } else if (StringShape(*subject_tmp).IsSliced()) { | |
| 1153 SlicedString* slice = SlicedString::cast(*subject_tmp); | |
| 1154 subject_tmp = Handle<String>(slice->parent()); | |
| 1155 slice_offset = slice->offset(); | |
| 1156 } | |
| 1157 | |
| 1158 // String might have changed. | |
| 1159 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) { | |
| 1160 // If we changed between an Latin1 and an UC16 string, the specialized | |
| 1161 // code cannot be used, and we need to restart regexp matching from | |
| 1162 // scratch (including, potentially, compiling a new version of the code). | |
| 1163 return RETRY; | |
| 1164 } | |
| 1165 | |
| 1166 // Otherwise, the content of the string might have moved. It must still | |
| 1167 // be a sequential or external string with the same content. | |
| 1168 // Update the start and end pointers in the stack frame to the current | |
| 1169 // location (whether it has actually moved or not). | |
| 1170 DCHECK(StringShape(*subject_tmp).IsSequential() || | |
| 1171 StringShape(*subject_tmp).IsExternal()); | |
| 1172 | |
| 1173 // The original start address of the characters to match. | |
| 1174 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart); | |
| 1175 | |
| 1176 // Find the current start address of the same character at the current string | |
| 1177 // position. | |
| 1178 int start_index = frame_entry<int>(re_frame, kStartIndex); | |
| 1179 const byte* new_address = StringCharacterPosition(*subject_tmp, | |
| 1180 start_index + slice_offset); | |
| 1181 | |
| 1182 if (start_address != new_address) { | |
| 1183 // If there is a difference, update the object pointer and start and end | |
| 1184 // addresses in the RegExp stack frame to match the new value. | |
| 1185 const byte* end_address = frame_entry<const byte* >(re_frame, kInputEnd); | |
| 1186 int byte_length = static_cast<int>(end_address - start_address); | |
| 1187 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
| 1188 frame_entry<const byte*>(re_frame, kInputStart) = new_address; | |
| 1189 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length; | |
| 1190 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) { | |
| 1191 // Subject string might have been a ConsString that underwent | |
| 1192 // short-circuiting during GC. That will not change start_address but | |
| 1193 // will change pointer inside the subject handle. | |
| 1194 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
| 1195 } | |
| 1196 | |
| 1197 return 0; | |
| 1198 } | 1119 } |
| 1199 | 1120 |
| 1200 | 1121 |
| 1201 MemOperand RegExpMacroAssemblerMIPS::register_location(int register_index) { | 1122 MemOperand RegExpMacroAssemblerMIPS::register_location(int register_index) { |
| 1202 DCHECK(register_index < (1<<30)); | 1123 DCHECK(register_index < (1<<30)); |
| 1203 if (num_registers_ <= register_index) { | 1124 if (num_registers_ <= register_index) { |
| 1204 num_registers_ = register_index + 1; | 1125 num_registers_ = register_index + 1; |
| 1205 } | 1126 } |
| 1206 return MemOperand(frame_pointer(), | 1127 return MemOperand(frame_pointer(), |
| 1207 kRegisterZero - register_index * kPointerSize); | 1128 kRegisterZero - register_index * kPointerSize); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 } | 1237 } |
| 1317 | 1238 |
| 1318 | 1239 |
| 1319 #undef __ | 1240 #undef __ |
| 1320 | 1241 |
| 1321 #endif // V8_INTERPRETED_REGEXP | 1242 #endif // V8_INTERPRETED_REGEXP |
| 1322 | 1243 |
| 1323 }} // namespace v8::internal | 1244 }} // namespace v8::internal |
| 1324 | 1245 |
| 1325 #endif // V8_TARGET_ARCH_MIPS | 1246 #endif // V8_TARGET_ARCH_MIPS |
| OLD | NEW |