Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: src/interpreter-irregexp.cc

Issue 151119: - Avoid allocating an overly large stack frame in the irregexp (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 printf("%c", b); 108 printf("%c", b);
109 } else { 109 } else {
110 printf("."); 110 printf(".");
111 } 111 }
112 } 112 }
113 printf("\n"); 113 printf("\n");
114 } 114 }
115 } 115 }
116 116
117 117
118 #define BYTECODE(name) \ 118 #define BYTECODE(name) \
119 case BC_##name: \ 119 case BC_##name: \
120 TraceInterpreter(code_base, \ 120 TraceInterpreter(code_base, \
121 pc, \ 121 pc, \
122 backtrack_sp - backtrack_stack, \ 122 backtrack_sp - backtrack_stack_base, \
123 current, \ 123 current, \
124 current_char, \ 124 current_char, \
125 BC_##name##_LENGTH, \ 125 BC_##name##_LENGTH, \
126 #name); 126 #name);
127 #else 127 #else
128 #define BYTECODE(name) \ 128 #define BYTECODE(name) \
129 case BC_##name: 129 case BC_##name:
130 #endif 130 #endif
131 131
132 132
133 static int32_t Load32Aligned(const byte* pc) { 133 static int32_t Load32Aligned(const byte* pc) {
134 ASSERT((reinterpret_cast<intptr_t>(pc) & 3) == 0); 134 ASSERT((reinterpret_cast<intptr_t>(pc) & 3) == 0);
135 return *reinterpret_cast<const int32_t *>(pc); 135 return *reinterpret_cast<const int32_t *>(pc);
136 } 136 }
137 137
138 138
139 static int32_t Load16Aligned(const byte* pc) { 139 static int32_t Load16Aligned(const byte* pc) {
140 ASSERT((reinterpret_cast<intptr_t>(pc) & 1) == 0); 140 ASSERT((reinterpret_cast<intptr_t>(pc) & 1) == 0);
141 return *reinterpret_cast<const uint16_t *>(pc); 141 return *reinterpret_cast<const uint16_t *>(pc);
142 } 142 }
143 143
144 144
145 template <typename Char> 145 template <typename Char>
146 static bool RawMatch(const byte* code_base, 146 static bool RawMatch(const byte* code_base,
147 Vector<const Char> subject, 147 Vector<const Char> subject,
148 int* registers, 148 int* registers,
149 int current, 149 int current,
150 uint32_t current_char) { 150 uint32_t current_char) {
151 const byte* pc = code_base; 151 const byte* pc = code_base;
152 static const int kBacktrackStackSize = 10000; 152 static const int kBacktrackStackSize = 10000;
153 int backtrack_stack[kBacktrackStackSize]; 153 // Use a SmartPointer here to ensure that the memory gets freed when the
154 // matching finishes.
155 SmartPointer<int> backtrack_stack(NewArray<int>(kBacktrackStackSize));
156 int* backtrack_stack_base = *backtrack_stack;
157 int* backtrack_sp = backtrack_stack_base;
154 int backtrack_stack_space = kBacktrackStackSize; 158 int backtrack_stack_space = kBacktrackStackSize;
155 int* backtrack_sp = backtrack_stack;
156 #ifdef DEBUG 159 #ifdef DEBUG
157 if (FLAG_trace_regexp_bytecodes) { 160 if (FLAG_trace_regexp_bytecodes) {
158 PrintF("\n\nStart bytecode interpreter\n\n"); 161 PrintF("\n\nStart bytecode interpreter\n\n");
159 } 162 }
160 #endif 163 #endif
161 while (true) { 164 while (true) {
162 int32_t insn = Load32Aligned(pc); 165 int32_t insn = Load32Aligned(pc);
163 switch (insn & BYTECODE_MASK) { 166 switch (insn & BYTECODE_MASK) {
164 BYTECODE(BREAK) 167 BYTECODE(BREAK)
165 UNREACHABLE(); 168 UNREACHABLE();
(...skipping 29 matching lines...) Expand all
195 break; 198 break;
196 BYTECODE(SET_REGISTER_TO_CP) 199 BYTECODE(SET_REGISTER_TO_CP)
197 registers[insn >> BYTECODE_SHIFT] = current + Load32Aligned(pc + 4); 200 registers[insn >> BYTECODE_SHIFT] = current + Load32Aligned(pc + 4);
198 pc += BC_SET_REGISTER_TO_CP_LENGTH; 201 pc += BC_SET_REGISTER_TO_CP_LENGTH;
199 break; 202 break;
200 BYTECODE(SET_CP_TO_REGISTER) 203 BYTECODE(SET_CP_TO_REGISTER)
201 current = registers[insn >> BYTECODE_SHIFT]; 204 current = registers[insn >> BYTECODE_SHIFT];
202 pc += BC_SET_CP_TO_REGISTER_LENGTH; 205 pc += BC_SET_CP_TO_REGISTER_LENGTH;
203 break; 206 break;
204 BYTECODE(SET_REGISTER_TO_SP) 207 BYTECODE(SET_REGISTER_TO_SP)
205 registers[insn >> BYTECODE_SHIFT] = backtrack_sp - backtrack_stack; 208 registers[insn >> BYTECODE_SHIFT] = backtrack_sp - backtrack_stack_base;
206 pc += BC_SET_REGISTER_TO_SP_LENGTH; 209 pc += BC_SET_REGISTER_TO_SP_LENGTH;
207 break; 210 break;
208 BYTECODE(SET_SP_TO_REGISTER) 211 BYTECODE(SET_SP_TO_REGISTER)
209 backtrack_sp = backtrack_stack + registers[insn >> BYTECODE_SHIFT]; 212 backtrack_sp = backtrack_stack_base + registers[insn >> BYTECODE_SHIFT];
210 backtrack_stack_space = kBacktrackStackSize - 213 backtrack_stack_space = kBacktrackStackSize -
211 (backtrack_sp - backtrack_stack); 214 (backtrack_sp - backtrack_stack_base);
212 pc += BC_SET_SP_TO_REGISTER_LENGTH; 215 pc += BC_SET_SP_TO_REGISTER_LENGTH;
213 break; 216 break;
214 BYTECODE(POP_CP) 217 BYTECODE(POP_CP)
215 backtrack_stack_space++; 218 backtrack_stack_space++;
216 --backtrack_sp; 219 --backtrack_sp;
217 current = *backtrack_sp; 220 current = *backtrack_sp;
218 pc += BC_POP_CP_LENGTH; 221 pc += BC_POP_CP_LENGTH;
219 break; 222 break;
220 BYTECODE(POP_BT) 223 BYTECODE(POP_BT)
221 backtrack_stack_space++; 224 backtrack_stack_space++;
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 if (start_position != 0) previous_char = subject_vector[start_position - 1]; 591 if (start_position != 0) previous_char = subject_vector[start_position - 1];
589 return RawMatch(code_base, 592 return RawMatch(code_base,
590 subject_vector, 593 subject_vector,
591 registers, 594 registers,
592 start_position, 595 start_position,
593 previous_char); 596 previous_char);
594 } 597 }
595 } 598 }
596 599
597 } } // namespace v8::internal 600 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698