OLD | NEW |
1 // Copyright 2008-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2008-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 | 967 |
968 // No allocations before calling the regexp, but we can't use | 968 // No allocations before calling the regexp, but we can't use |
969 // AssertNoAllocation, since regexps might be preempted, and another thread | 969 // AssertNoAllocation, since regexps might be preempted, and another thread |
970 // might do allocation anyway. | 970 // might do allocation anyway. |
971 | 971 |
972 String* subject_ptr = *subject; | 972 String* subject_ptr = *subject; |
973 // Character offsets into string. | 973 // Character offsets into string. |
974 int start_offset = previous_index; | 974 int start_offset = previous_index; |
975 int end_offset = subject_ptr->length(); | 975 int end_offset = subject_ptr->length(); |
976 | 976 |
977 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | 977 bool is_ascii = subject->IsAsciiRepresentation(); |
978 | 978 |
979 if (StringShape(subject_ptr).IsCons()) { | 979 if (StringShape(subject_ptr).IsCons()) { |
980 subject_ptr = ConsString::cast(subject_ptr)->first(); | 980 subject_ptr = ConsString::cast(subject_ptr)->first(); |
981 } else if (StringShape(subject_ptr).IsSliced()) { | 981 } else if (StringShape(subject_ptr).IsSliced()) { |
982 SlicedString* slice = SlicedString::cast(subject_ptr); | 982 SlicedString* slice = SlicedString::cast(subject_ptr); |
983 start_offset += slice->start(); | 983 start_offset += slice->start(); |
984 end_offset += slice->start(); | 984 end_offset += slice->start(); |
985 subject_ptr = slice->buffer(); | 985 subject_ptr = slice->buffer(); |
986 } | 986 } |
987 // Ensure that an underlying string has the same ascii-ness. | 987 // Ensure that an underlying string has the same ascii-ness. |
988 ASSERT(StringShape(subject_ptr).IsAsciiRepresentation() == is_ascii); | 988 ASSERT(subject_ptr->IsAsciiRepresentation() == is_ascii); |
989 ASSERT(subject_ptr->IsExternalString() || subject_ptr->IsSeqString()); | 989 ASSERT(subject_ptr->IsExternalString() || subject_ptr->IsSeqString()); |
990 // String is now either Sequential or External | 990 // String is now either Sequential or External |
991 int char_size_shift = is_ascii ? 0 : 1; | 991 int char_size_shift = is_ascii ? 0 : 1; |
992 int char_length = end_offset - start_offset; | 992 int char_length = end_offset - start_offset; |
993 | 993 |
994 const byte* input_start = | 994 const byte* input_start = |
995 StringCharacterPosition(subject_ptr, start_offset); | 995 StringCharacterPosition(subject_ptr, start_offset); |
996 int byte_length = char_length << char_size_shift; | 996 int byte_length = char_length << char_size_shift; |
997 const byte* input_end = input_start + byte_length; | 997 const byte* input_end = input_start + byte_length; |
998 RegExpMacroAssemblerIA32::Result res = Execute(*regexp_code, | 998 RegExpMacroAssemblerIA32::Result res = Execute(*regexp_code, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1105 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
1106 } | 1106 } |
1107 | 1107 |
1108 | 1108 |
1109 const byte* RegExpMacroAssemblerIA32::StringCharacterPosition(String* subject, | 1109 const byte* RegExpMacroAssemblerIA32::StringCharacterPosition(String* subject, |
1110 int start_index) { | 1110 int start_index) { |
1111 // Not just flat, but ultra flat. | 1111 // Not just flat, but ultra flat. |
1112 ASSERT(subject->IsExternalString() || subject->IsSeqString()); | 1112 ASSERT(subject->IsExternalString() || subject->IsSeqString()); |
1113 ASSERT(start_index >= 0); | 1113 ASSERT(start_index >= 0); |
1114 ASSERT(start_index <= subject->length()); | 1114 ASSERT(start_index <= subject->length()); |
1115 if (StringShape(subject).IsAsciiRepresentation()) { | 1115 if (subject->IsAsciiRepresentation()) { |
1116 const byte* address; | 1116 const byte* address; |
1117 if (StringShape(subject).IsExternal()) { | 1117 if (StringShape(subject).IsExternal()) { |
1118 const char* data = ExternalAsciiString::cast(subject)->resource()->data(); | 1118 const char* data = ExternalAsciiString::cast(subject)->resource()->data(); |
1119 address = reinterpret_cast<const byte*>(data); | 1119 address = reinterpret_cast<const byte*>(data); |
1120 } else { | 1120 } else { |
1121 ASSERT(subject->IsSeqAsciiString()); | 1121 ASSERT(subject->IsSeqAsciiString()); |
1122 char* data = SeqAsciiString::cast(subject)->GetChars(); | 1122 char* data = SeqAsciiString::cast(subject)->GetChars(); |
1123 address = reinterpret_cast<const byte*>(data); | 1123 address = reinterpret_cast<const byte*>(data); |
1124 } | 1124 } |
1125 return address + start_index; | 1125 return address + start_index; |
(...skipping 19 matching lines...) Expand all Loading... |
1145 | 1145 |
1146 // If not real stack overflow the stack guard was used to interrupt | 1146 // If not real stack overflow the stack guard was used to interrupt |
1147 // execution for another purpose. | 1147 // execution for another purpose. |
1148 | 1148 |
1149 // Prepare for possible GC. | 1149 // Prepare for possible GC. |
1150 HandleScope handles; | 1150 HandleScope handles; |
1151 Handle<Code> code_handle(re_code); | 1151 Handle<Code> code_handle(re_code); |
1152 | 1152 |
1153 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); | 1153 Handle<String> subject(frame_entry<String*>(re_frame, kInputString)); |
1154 // Current string. | 1154 // Current string. |
1155 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | 1155 bool is_ascii = subject->IsAsciiRepresentation(); |
1156 | 1156 |
1157 ASSERT(re_code->instruction_start() <= *return_address); | 1157 ASSERT(re_code->instruction_start() <= *return_address); |
1158 ASSERT(*return_address <= | 1158 ASSERT(*return_address <= |
1159 re_code->instruction_start() + re_code->instruction_size()); | 1159 re_code->instruction_start() + re_code->instruction_size()); |
1160 | 1160 |
1161 Object* result = Execution::HandleStackGuardInterrupt(); | 1161 Object* result = Execution::HandleStackGuardInterrupt(); |
1162 | 1162 |
1163 if (*code_handle != re_code) { // Return address no longer valid | 1163 if (*code_handle != re_code) { // Return address no longer valid |
1164 int delta = *code_handle - re_code; | 1164 int delta = *code_handle - re_code; |
1165 // Overwrite the return address on the stack. | 1165 // Overwrite the return address on the stack. |
1166 *return_address += delta; | 1166 *return_address += delta; |
1167 } | 1167 } |
1168 | 1168 |
1169 if (result->IsException()) { | 1169 if (result->IsException()) { |
1170 return EXCEPTION; | 1170 return EXCEPTION; |
1171 } | 1171 } |
1172 | 1172 |
1173 // String might have changed. | 1173 // String might have changed. |
1174 if (StringShape(*subject).IsAsciiRepresentation() != is_ascii) { | 1174 if (subject->IsAsciiRepresentation() != is_ascii) { |
1175 // If we changed between an ASCII and an UC16 string, the specialized | 1175 // If we changed between an ASCII and an UC16 string, the specialized |
1176 // code cannot be used, and we need to restart regexp matching from | 1176 // code cannot be used, and we need to restart regexp matching from |
1177 // scratch (including, potentially, compiling a new version of the code). | 1177 // scratch (including, potentially, compiling a new version of the code). |
1178 return RETRY; | 1178 return RETRY; |
1179 } | 1179 } |
1180 | 1180 |
1181 // Otherwise, the content of the string might have moved. It must still | 1181 // Otherwise, the content of the string might have moved. It must still |
1182 // be a sequential or external string with the same content. | 1182 // be a sequential or external string with the same content. |
1183 // Update the start and end pointers in the stack frame to the current | 1183 // Update the start and end pointers in the stack frame to the current |
1184 // location (whether it has actually moved or not). | 1184 // location (whether it has actually moved or not). |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 | 1381 |
1382 | 1382 |
1383 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, | 1383 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, |
1384 ArraySlice* buffer) { | 1384 ArraySlice* buffer) { |
1385 __ mov(reg, buffer->array()); | 1385 __ mov(reg, buffer->array()); |
1386 __ add(Operand(reg), Immediate(buffer->base_offset())); | 1386 __ add(Operand(reg), Immediate(buffer->base_offset())); |
1387 } | 1387 } |
1388 | 1388 |
1389 #undef __ | 1389 #undef __ |
1390 }} // namespace v8::internal | 1390 }} // namespace v8::internal |
OLD | NEW |