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_X87 | 7 #if V8_TARGET_ARCH_X87 |
8 | 8 |
9 #include "src/cpu-profiler.h" | 9 #include "src/cpu-profiler.h" |
10 #include "src/log.h" | 10 #include "src/log.h" |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 } | 1064 } |
1065 | 1065 |
1066 | 1066 |
1067 // Helper function for reading a value out of a stack frame. | 1067 // Helper function for reading a value out of a stack frame. |
1068 template <typename T> | 1068 template <typename T> |
1069 static T& frame_entry(Address re_frame, int frame_offset) { | 1069 static T& frame_entry(Address re_frame, int frame_offset) { |
1070 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1070 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
1071 } | 1071 } |
1072 | 1072 |
1073 | 1073 |
| 1074 template <typename T> |
| 1075 static T* frame_entry_address(Address re_frame, int frame_offset) { |
| 1076 return reinterpret_cast<T*>(re_frame + frame_offset); |
| 1077 } |
| 1078 |
| 1079 |
1074 int RegExpMacroAssemblerX87::CheckStackGuardState(Address* return_address, | 1080 int RegExpMacroAssemblerX87::CheckStackGuardState(Address* return_address, |
1075 Code* re_code, | 1081 Code* re_code, |
1076 Address re_frame) { | 1082 Address re_frame) { |
1077 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | 1083 return NativeRegExpMacroAssembler::CheckStackGuardState( |
1078 StackLimitCheck check(isolate); | 1084 frame_entry<Isolate*>(re_frame, kIsolate), |
1079 if (check.JsHasOverflowed()) { | 1085 frame_entry<int>(re_frame, kStartIndex), |
1080 isolate->StackOverflow(); | 1086 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code, |
1081 return EXCEPTION; | 1087 frame_entry_address<String*>(re_frame, kInputString), |
1082 } | 1088 frame_entry_address<const byte*>(re_frame, kInputStart), |
1083 | 1089 frame_entry_address<const byte*>(re_frame, kInputEnd)); |
1084 // If not real stack overflow the stack guard was used to interrupt | |
1085 // execution for another purpose. | |
1086 | |
1087 // If this is a direct call from JavaScript retry the RegExp forcing the call | |
1088 // through the runtime system. Currently the direct call cannot handle a GC. | |
1089 if (frame_entry<int>(re_frame, kDirectCall) == 1) { | |
1090 return RETRY; | |
1091 } | |
1092 | |
1093 // Prepare for possible GC. | |
1094 HandleScope handles(isolate); | |
1095 Handle<Code> code_handle(re_code); | |
1096 | |
1097 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); | |
1098 | |
1099 // Current string. | |
1100 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | |
1101 | |
1102 DCHECK(re_code->instruction_start() <= *return_address); | |
1103 DCHECK(*return_address <= | |
1104 re_code->instruction_start() + re_code->instruction_size()); | |
1105 | |
1106 Object* result = isolate->stack_guard()->HandleInterrupts(); | |
1107 | |
1108 if (*code_handle != re_code) { // Return address no longer valid | |
1109 int delta = code_handle->address() - re_code->address(); | |
1110 // Overwrite the return address on the stack. | |
1111 *return_address += delta; | |
1112 } | |
1113 | |
1114 if (result->IsException()) { | |
1115 return EXCEPTION; | |
1116 } | |
1117 | |
1118 Handle<String> subject_tmp = subject; | |
1119 int slice_offset = 0; | |
1120 | |
1121 // Extract the underlying string and the slice offset. | |
1122 if (StringShape(*subject_tmp).IsCons()) { | |
1123 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first()); | |
1124 } else if (StringShape(*subject_tmp).IsSliced()) { | |
1125 SlicedString* slice = SlicedString::cast(*subject_tmp); | |
1126 subject_tmp = Handle<String>(slice->parent()); | |
1127 slice_offset = slice->offset(); | |
1128 } | |
1129 | |
1130 // String might have changed. | |
1131 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) { | |
1132 // If we changed between an LATIN1 and an UC16 string, the specialized | |
1133 // code cannot be used, and we need to restart regexp matching from | |
1134 // scratch (including, potentially, compiling a new version of the code). | |
1135 return RETRY; | |
1136 } | |
1137 | |
1138 // Otherwise, the content of the string might have moved. It must still | |
1139 // be a sequential or external string with the same content. | |
1140 // Update the start and end pointers in the stack frame to the current | |
1141 // location (whether it has actually moved or not). | |
1142 DCHECK(StringShape(*subject_tmp).IsSequential() || | |
1143 StringShape(*subject_tmp).IsExternal()); | |
1144 | |
1145 // The original start address of the characters to match. | |
1146 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart); | |
1147 | |
1148 // Find the current start address of the same character at the current string | |
1149 // position. | |
1150 int start_index = frame_entry<int>(re_frame, kStartIndex); | |
1151 const byte* new_address = StringCharacterPosition(*subject_tmp, | |
1152 start_index + slice_offset); | |
1153 | |
1154 if (start_address != new_address) { | |
1155 // If there is a difference, update the object pointer and start and end | |
1156 // addresses in the RegExp stack frame to match the new value. | |
1157 const byte* end_address = frame_entry<const byte* >(re_frame, kInputEnd); | |
1158 int byte_length = static_cast<int>(end_address - start_address); | |
1159 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
1160 frame_entry<const byte*>(re_frame, kInputStart) = new_address; | |
1161 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length; | |
1162 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) { | |
1163 // Subject string might have been a ConsString that underwent | |
1164 // short-circuiting during GC. That will not change start_address but | |
1165 // will change pointer inside the subject handle. | |
1166 frame_entry<const String*>(re_frame, kInputString) = *subject; | |
1167 } | |
1168 | |
1169 return 0; | |
1170 } | 1090 } |
1171 | 1091 |
1172 | 1092 |
1173 Operand RegExpMacroAssemblerX87::register_location(int register_index) { | 1093 Operand RegExpMacroAssemblerX87::register_location(int register_index) { |
1174 DCHECK(register_index < (1<<30)); | 1094 DCHECK(register_index < (1<<30)); |
1175 if (num_registers_ <= register_index) { | 1095 if (num_registers_ <= register_index) { |
1176 num_registers_ = register_index + 1; | 1096 num_registers_ = register_index + 1; |
1177 } | 1097 } |
1178 return Operand(ebp, kRegisterZero - register_index * kPointerSize); | 1098 return Operand(ebp, kRegisterZero - register_index * kPointerSize); |
1179 } | 1099 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 } | 1219 } |
1300 | 1220 |
1301 | 1221 |
1302 #undef __ | 1222 #undef __ |
1303 | 1223 |
1304 #endif // V8_INTERPRETED_REGEXP | 1224 #endif // V8_INTERPRETED_REGEXP |
1305 | 1225 |
1306 }} // namespace v8::internal | 1226 }} // namespace v8::internal |
1307 | 1227 |
1308 #endif // V8_TARGET_ARCH_X87 | 1228 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |