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