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

Powered by Google App Engine
This is Rietveld 408576698