Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/mips64/regexp-macro-assembler-mips64.cc

Issue 1034173002: Always update raw pointers when handling interrupts inside RegExp code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/mips/regexp-macro-assembler-mips.cc ('k') | src/ppc/regexp-macro-assembler-ppc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_MIPS64 7 #if V8_TARGET_ARCH_MIPS64
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 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1139 }
1140 1140
1141 1141
1142 // Helper function for reading a value out of a stack frame. 1142 // Helper function for reading a value out of a stack frame.
1143 template <typename T> 1143 template <typename T>
1144 static T& frame_entry(Address re_frame, int frame_offset) { 1144 static T& frame_entry(Address re_frame, int frame_offset) {
1145 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); 1145 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset));
1146 } 1146 }
1147 1147
1148 1148
1149 int64_t RegExpMacroAssemblerMIPS::CheckStackGuardState(Address* return_address, 1149 template <typename T>
1150 Code* re_code, 1150 static T* frame_entry_address(Address re_frame, int frame_offset) {
1151 Address re_frame) { 1151 return reinterpret_cast<T*>(re_frame + frame_offset);
1152 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate);
1153 StackLimitCheck check(isolate);
1154 if (check.JsHasOverflowed()) {
1155 isolate->StackOverflow();
1156 return EXCEPTION;
1157 }
1158
1159 // If not real stack overflow the stack guard was used to interrupt
1160 // execution for another purpose.
1161
1162 // If this is a direct call from JavaScript retry the RegExp forcing the call
1163 // through the runtime system. Currently the direct call cannot handle a GC.
1164 if (frame_entry<int>(re_frame, kDirectCall) == 1) {
1165 return RETRY;
1166 }
1167
1168 // Prepare for possible GC.
1169 HandleScope handles(isolate);
1170 Handle<Code> code_handle(re_code);
1171
1172 Handle<String> subject(frame_entry<String*>(re_frame, kInputString));
1173 // Current string.
1174 bool is_one_byte = subject->IsOneByteRepresentationUnderneath();
1175
1176 DCHECK(re_code->instruction_start() <= *return_address);
1177 DCHECK(*return_address <=
1178 re_code->instruction_start() + re_code->instruction_size());
1179
1180 Object* result = isolate->stack_guard()->HandleInterrupts();
1181
1182 if (*code_handle != re_code) { // Return address no longer valid.
1183 int delta = code_handle->address() - re_code->address();
1184 // Overwrite the return address on the stack.
1185 *return_address += delta;
1186 }
1187
1188 if (result->IsException()) {
1189 return EXCEPTION;
1190 }
1191
1192 Handle<String> subject_tmp = subject;
1193 int slice_offset = 0;
1194
1195 // Extract the underlying string and the slice offset.
1196 if (StringShape(*subject_tmp).IsCons()) {
1197 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first());
1198 } else if (StringShape(*subject_tmp).IsSliced()) {
1199 SlicedString* slice = SlicedString::cast(*subject_tmp);
1200 subject_tmp = Handle<String>(slice->parent());
1201 slice_offset = slice->offset();
1202 }
1203
1204 // String might have changed.
1205 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) {
1206 // If we changed between an Latin1 and an UC16 string, the specialized
1207 // code cannot be used, and we need to restart regexp matching from
1208 // scratch (including, potentially, compiling a new version of the code).
1209 return RETRY;
1210 }
1211
1212 // Otherwise, the content of the string might have moved. It must still
1213 // be a sequential or external string with the same content.
1214 // Update the start and end pointers in the stack frame to the current
1215 // location (whether it has actually moved or not).
1216 DCHECK(StringShape(*subject_tmp).IsSequential() ||
1217 StringShape(*subject_tmp).IsExternal());
1218
1219 // The original start address of the characters to match.
1220 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart);
1221
1222 // Find the current start address of the same character at the current string
1223 // position.
1224 int start_index = frame_entry<int>(re_frame, kStartIndex);
1225 const byte* new_address = StringCharacterPosition(*subject_tmp,
1226 start_index + slice_offset);
1227
1228 if (start_address != new_address) {
1229 // If there is a difference, update the object pointer and start and end
1230 // addresses in the RegExp stack frame to match the new value.
1231 const byte* end_address = frame_entry<const byte* >(re_frame, kInputEnd);
1232 int byte_length = static_cast<int>(end_address - start_address);
1233 frame_entry<const String*>(re_frame, kInputString) = *subject;
1234 frame_entry<const byte*>(re_frame, kInputStart) = new_address;
1235 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length;
1236 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) {
1237 // Subject string might have been a ConsString that underwent
1238 // short-circuiting during GC. That will not change start_address but
1239 // will change pointer inside the subject handle.
1240 frame_entry<const String*>(re_frame, kInputString) = *subject;
1241 }
1242
1243 return 0;
1244 } 1152 }
1245 1153
1246 1154
1155 int64 RegExpMacroAssemblerMIPS::CheckStackGuardState(Address* return_address,
1156 Code* re_code,
1157 Address re_frame) {
1158 return NativeRegExpMacroAssembler::CheckStackGuardState(
1159 frame_entry<Isolate*>(re_frame, kIsolate),
1160 frame_entry<int>(re_frame, kStartIndex),
1161 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code,
1162 frame_entry_address<String*>(re_frame, kInputString),
1163 frame_entry_address<const byte*>(re_frame, kInputStart),
1164 frame_entry_address<const byte*>(re_frame, kInputEnd));
1165 }
1166
1167
1247 MemOperand RegExpMacroAssemblerMIPS::register_location(int register_index) { 1168 MemOperand RegExpMacroAssemblerMIPS::register_location(int register_index) {
1248 DCHECK(register_index < (1<<30)); 1169 DCHECK(register_index < (1<<30));
1249 if (num_registers_ <= register_index) { 1170 if (num_registers_ <= register_index) {
1250 num_registers_ = register_index + 1; 1171 num_registers_ = register_index + 1;
1251 } 1172 }
1252 return MemOperand(frame_pointer(), 1173 return MemOperand(frame_pointer(),
1253 kRegisterZero - register_index * kPointerSize); 1174 kRegisterZero - register_index * kPointerSize);
1254 } 1175 }
1255 1176
1256 1177
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 } 1282 }
1362 } 1283 }
1363 1284
1364 #undef __ 1285 #undef __
1365 1286
1366 #endif // V8_INTERPRETED_REGEXP 1287 #endif // V8_INTERPRETED_REGEXP
1367 1288
1368 }} // namespace v8::internal 1289 }} // namespace v8::internal
1369 1290
1370 #endif // V8_TARGET_ARCH_MIPS64 1291 #endif // V8_TARGET_ARCH_MIPS64
OLDNEW
« no previous file with comments | « src/mips/regexp-macro-assembler-mips.cc ('k') | src/ppc/regexp-macro-assembler-ppc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698