OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return *reinterpret_cast<const uint16_t *>(pc); | 151 return *reinterpret_cast<const uint16_t *>(pc); |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 // A simple abstraction over the backtracking stack used by the interpreter. | 155 // A simple abstraction over the backtracking stack used by the interpreter. |
156 // This backtracking stack does not grow automatically, but it ensures that the | 156 // This backtracking stack does not grow automatically, but it ensures that the |
157 // the memory held by the stack is released or remembered in a cache if the | 157 // the memory held by the stack is released or remembered in a cache if the |
158 // matching terminates. | 158 // matching terminates. |
159 class BacktrackStack { | 159 class BacktrackStack { |
160 public: | 160 public: |
161 explicit BacktrackStack(Isolate* isolate) : isolate_(isolate) { | 161 explicit BacktrackStack() { |
162 data_ = NewArray<int>(kBacktrackStackSize); | 162 data_ = NewArray<int>(kBacktrackStackSize); |
163 } | 163 } |
164 | 164 |
165 ~BacktrackStack() { | 165 ~BacktrackStack() { |
166 DeleteArray(data_); | 166 DeleteArray(data_); |
167 } | 167 } |
168 | 168 |
169 int* data() const { return data_; } | 169 int* data() const { return data_; } |
170 | 170 |
171 int max_size() const { return kBacktrackStackSize; } | 171 int max_size() const { return kBacktrackStackSize; } |
172 | 172 |
173 private: | 173 private: |
174 static const int kBacktrackStackSize = 10000; | 174 static const int kBacktrackStackSize = 10000; |
175 | 175 |
176 int* data_; | 176 int* data_; |
177 Isolate* isolate_; | |
178 | 177 |
179 DISALLOW_COPY_AND_ASSIGN(BacktrackStack); | 178 DISALLOW_COPY_AND_ASSIGN(BacktrackStack); |
180 }; | 179 }; |
181 | 180 |
182 | 181 |
183 template <typename Char> | 182 template <typename Char> |
184 static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, | 183 static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, |
185 const byte* code_base, | 184 const byte* code_base, |
186 Vector<const Char> subject, | 185 Vector<const Char> subject, |
187 int* registers, | 186 int* registers, |
188 int current, | 187 int current, |
189 uint32_t current_char) { | 188 uint32_t current_char) { |
190 const byte* pc = code_base; | 189 const byte* pc = code_base; |
191 // BacktrackStack ensures that the memory allocated for the backtracking stack | 190 // BacktrackStack ensures that the memory allocated for the backtracking stack |
192 // is returned to the system or cached if there is no stack being cached at | 191 // is returned to the system or cached if there is no stack being cached at |
193 // the moment. | 192 // the moment. |
194 BacktrackStack backtrack_stack(isolate); | 193 BacktrackStack backtrack_stack; |
195 int* backtrack_stack_base = backtrack_stack.data(); | 194 int* backtrack_stack_base = backtrack_stack.data(); |
196 int* backtrack_sp = backtrack_stack_base; | 195 int* backtrack_sp = backtrack_stack_base; |
197 int backtrack_stack_space = backtrack_stack.max_size(); | 196 int backtrack_stack_space = backtrack_stack.max_size(); |
198 #ifdef DEBUG | 197 #ifdef DEBUG |
199 if (FLAG_trace_regexp_bytecodes) { | 198 if (FLAG_trace_regexp_bytecodes) { |
200 PrintF("\n\nStart bytecode interpreter\n\n"); | 199 PrintF("\n\nStart bytecode interpreter\n\n"); |
201 } | 200 } |
202 #endif | 201 #endif |
203 while (true) { | 202 while (true) { |
204 int32_t insn = Load32Aligned(pc); | 203 int32_t insn = Load32Aligned(pc); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 return RawMatch(isolate, | 624 return RawMatch(isolate, |
626 code_base, | 625 code_base, |
627 subject_vector, | 626 subject_vector, |
628 registers, | 627 registers, |
629 start_position, | 628 start_position, |
630 previous_char); | 629 previous_char); |
631 } | 630 } |
632 } | 631 } |
633 | 632 |
634 } } // namespace v8::internal | 633 } } // namespace v8::internal |
OLD | NEW |