v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
regexp-interpreter.cc
Go to the documentation of this file.
1// Copyright 2011 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// A simple interpreter for the Irregexp byte code.
6
8
10#include "src/base/strings.h"
17#include "src/regexp/regexp-stack.h" // For kMaximumStackSize.
19#include "src/regexp/regexp.h"
20#include "src/strings/unicode.h"
21#include "src/utils/memcopy.h"
22#include "src/utils/utils.h"
23
24#ifdef V8_INTL_SUPPORT
25#include "unicode/uchar.h"
26#endif // V8_INTL_SUPPORT
27
28// Use token threaded dispatch iff the compiler supports computed gotos and the
29// build argument v8_enable_regexp_interpreter_threaded_dispatch was set.
30#if V8_HAS_COMPUTED_GOTO && \
31 defined(V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH)
32#define V8_USE_COMPUTED_GOTO 1
33#endif // V8_HAS_COMPUTED_GOTO
34
35namespace v8 {
36namespace internal {
37
38namespace {
39
40bool BackRefMatchesNoCase(Isolate* isolate, int from, int current, int len,
41 base::Vector<const base::uc16> subject,
42 bool unicode) {
43 Address offset_a =
44 reinterpret_cast<Address>(const_cast<base::uc16*>(&subject.at(from)));
45 Address offset_b =
46 reinterpret_cast<Address>(const_cast<base::uc16*>(&subject.at(current)));
47 size_t length = len * base::kUC16Size;
48
49 bool result = unicode
51 offset_a, offset_b, length, isolate)
52 : RegExpMacroAssembler::CaseInsensitiveCompareNonUnicode(
53 offset_a, offset_b, length, isolate);
54 return result == 1;
55}
56
57bool BackRefMatchesNoCase(Isolate* isolate, int from, int current, int len,
58 base::Vector<const uint8_t> subject, bool unicode) {
59 // For Latin1 characters the unicode flag makes no difference.
60 for (int i = 0; i < len; i++) {
61 unsigned int old_char = subject[from++];
62 unsigned int new_char = subject[current++];
63 if (old_char == new_char) continue;
64 // Convert both characters to lower case.
65 old_char |= 0x20;
66 new_char |= 0x20;
67 if (old_char != new_char) return false;
68 // Not letters in the ASCII range and Latin-1 range.
69 if (!(old_char - 'a' <= 'z' - 'a') &&
70 !(old_char - 224 <= 254 - 224 && old_char != 247)) {
71 return false;
72 }
73 }
74 return true;
75}
76
77#ifdef DEBUG
78void MaybeTraceInterpreter(const uint8_t* code_base, const uint8_t* pc,
79 int stack_depth, int current_position,
80 uint32_t current_char, int bytecode_length,
81 const char* bytecode_name) {
82 if (v8_flags.trace_regexp_bytecodes) {
83 const bool printable = std::isprint(current_char);
84 const char* format =
85 printable
86 ? "pc = %02x, sp = %d, curpos = %d, curchar = %08x (%c), bc = "
87 : "pc = %02x, sp = %d, curpos = %d, curchar = %08x .%c., bc = ";
88 PrintF(format, pc - code_base, stack_depth, current_position, current_char,
89 printable ? current_char : '.');
90
92 }
93}
94#endif // DEBUG
95
96int32_t Load32Aligned(const uint8_t* pc) {
97 DCHECK_EQ(0, reinterpret_cast<intptr_t>(pc) & 3);
98 return *reinterpret_cast<const int32_t*>(pc);
99}
100
101uint32_t Load16AlignedUnsigned(const uint8_t* pc) {
102 DCHECK_EQ(0, reinterpret_cast<intptr_t>(pc) & 1);
103 return *reinterpret_cast<const uint16_t*>(pc);
104}
105
106int32_t Load16AlignedSigned(const uint8_t* pc) {
107 DCHECK_EQ(0, reinterpret_cast<intptr_t>(pc) & 1);
108 return *reinterpret_cast<const int16_t*>(pc);
109}
110
111// Helpers to access the packed argument. Takes the 32 bits containing the
112// current bytecode, where the 8 LSB contain the bytecode and the rest contains
113// a packed 24-bit argument.
114// TODO(jgruber): Specify signed-ness in bytecode signature declarations, and
115// police restrictions during bytecode generation.
116int32_t LoadPacked24Signed(int32_t bytecode_and_packed_arg) {
117 return bytecode_and_packed_arg >> BYTECODE_SHIFT;
118}
119uint32_t LoadPacked24Unsigned(int32_t bytecode_and_packed_arg) {
120 return static_cast<uint32_t>(bytecode_and_packed_arg) >> BYTECODE_SHIFT;
121}
122
123// A simple abstraction over the backtracking stack used by the interpreter.
124//
125// Despite the name 'backtracking' stack, it's actually used as a generic stack
126// that stores both program counters (= offsets into the bytecode) and generic
127// integer values.
128class BacktrackStack {
129 public:
130 BacktrackStack() = default;
131 BacktrackStack(const BacktrackStack&) = delete;
132 BacktrackStack& operator=(const BacktrackStack&) = delete;
133
134 V8_WARN_UNUSED_RESULT bool push(int v) {
135 data_.emplace_back(v);
136 return (static_cast<int>(data_.size()) <= kMaxSize);
137 }
138 int peek() const {
139 SBXCHECK(!data_.empty());
140 return data_.back();
141 }
142 int pop() {
143 int v = peek();
144 data_.pop_back();
145 return v;
146 }
147
148 // The 'sp' is the index of the first empty element in the stack.
149 int sp() const { return static_cast<int>(data_.size()); }
150 void set_sp(uint32_t new_sp) {
151 DCHECK_LE(new_sp, sp());
152 data_.resize(new_sp);
153 }
154
155 private:
156 // Semi-arbitrary. Should be large enough for common cases to remain in the
157 // static stack-allocated backing store, but small enough not to waste space.
158 static constexpr int kStaticCapacity = 64;
159
160 using ValueT = int;
161 base::SmallVector<ValueT, kStaticCapacity> data_;
162
163 static constexpr int kMaxSize =
164 RegExpStack::kMaximumStackSize / sizeof(ValueT);
165};
166
167// Registers used during interpreter execution. These consist of output
168// registers in indices [0, output_register_count[ which will contain matcher
169// results as a {start,end} index tuple for each capture (where the whole match
170// counts as implicit capture 0); and internal registers in indices
171// [output_register_count, total_register_count[.
172class InterpreterRegisters {
173 public:
174 using RegisterT = int;
175
176 InterpreterRegisters(int total_register_count, RegisterT* output_registers,
177 int output_register_count)
178 : registers_(total_register_count),
179 output_registers_(output_registers),
180 total_register_count_(total_register_count),
181 output_register_count_(output_register_count) {
182 // TODO(jgruber): Use int32_t consistently for registers. Currently, CSA
183 // uses int32_t while runtime uses int.
184 static_assert(sizeof(int) == sizeof(int32_t));
185 SBXCHECK_GE(output_register_count, 2); // At least 2 for the match itself.
186 SBXCHECK_GE(total_register_count, output_register_count);
188 DCHECK_NOT_NULL(output_registers);
189
190 // Initialize the output register region to -1 signifying 'no match'.
191 std::memset(registers_.data(), -1,
192 output_register_count * sizeof(RegisterT));
194 }
195
196 const RegisterT& operator[](size_t index) const {
197 SBXCHECK_LT(index, total_register_count_);
198 return registers_[index];
199 }
200 RegisterT& operator[](size_t index) {
201 SBXCHECK_LT(index, total_register_count_);
202 return registers_[index];
203 }
204
205 void CopyToOutputRegisters() {
206 MemCopy(output_registers_, registers_.data(),
207 output_register_count_ * sizeof(RegisterT));
208 }
209
210 private:
211 static constexpr int kStaticCapacity = 64; // Arbitrary.
212 base::SmallVector<RegisterT, kStaticCapacity> registers_;
213 RegisterT* const output_registers_;
216};
217
218IrregexpInterpreter::Result ThrowStackOverflow(Isolate* isolate,
221 // We abort interpreter execution after the stack overflow is thrown, and thus
222 // allow allocation here despite the outer DisallowGarbageCollectionScope.
224 isolate->StackOverflow();
226}
227
228// Only throws if called from the runtime, otherwise just returns the EXCEPTION
229// status code.
230IrregexpInterpreter::Result MaybeThrowStackOverflow(
231 Isolate* isolate, RegExp::CallOrigin call_origin) {
233 return ThrowStackOverflow(isolate, call_origin);
234 } else {
236 }
237}
238
239template <typename Char>
240void UpdateCodeAndSubjectReferences(
241 Isolate* isolate, DirectHandle<TrustedByteArray> code_array,
242 DirectHandle<String> subject_string,
243 Tagged<TrustedByteArray>* code_array_out, const uint8_t** code_base_out,
244 const uint8_t** pc_out, Tagged<String>* subject_string_out,
245 base::Vector<const Char>* subject_string_vector_out) {
247
248 if (*code_base_out != code_array->begin()) {
249 *code_array_out = *code_array;
250 const intptr_t pc_offset = *pc_out - *code_base_out;
252 *code_base_out = code_array->begin();
253 *pc_out = *code_base_out + pc_offset;
254 }
255
256 DCHECK(subject_string->IsFlat());
257 *subject_string_out = *subject_string;
258 *subject_string_vector_out = subject_string->GetCharVector<Char>(no_gc);
259}
260
261// Runs all pending interrupts and updates unhandlified object references if
262// necessary.
263template <typename Char>
264IrregexpInterpreter::Result HandleInterrupts(
265 Isolate* isolate, RegExp::CallOrigin call_origin,
266 Tagged<TrustedByteArray>* code_array_out,
267 Tagged<String>* subject_string_out, const uint8_t** code_base_out,
268 base::Vector<const Char>* subject_string_vector_out,
269 const uint8_t** pc_out) {
271
272 StackLimitCheck check(isolate);
273 bool js_has_overflowed = check.JsHasOverflowed();
274
276 // Direct calls from JavaScript can be interrupted in two ways:
277 // 1. A real stack overflow, in which case we let the caller throw the
278 // exception.
279 // 2. The stack guard was used to interrupt execution for another purpose,
280 // forcing the call through the runtime system.
281 if (js_has_overflowed) {
283 } else if (check.InterruptRequested()) {
285 }
286 } else {
288 // Prepare for possible GC.
289 HandleScope handles(isolate);
290 DirectHandle<TrustedByteArray> code_handle(*code_array_out, isolate);
291 DirectHandle<String> subject_handle(*subject_string_out, isolate);
292
293 if (js_has_overflowed) {
294 return ThrowStackOverflow(isolate, call_origin);
295 } else if (check.InterruptRequested()) {
296 const bool was_one_byte =
299 {
301 result = isolate->stack_guard()->HandleInterrupts();
302 }
303 if (IsException(result, isolate)) {
305 }
306
307 // If we changed between a LATIN1 and a UC16 string, we need to
308 // restart regexp matching with the appropriate template instantiation of
309 // RawMatch.
310 if (String::IsOneByteRepresentationUnderneath(*subject_handle) !=
311 was_one_byte) {
313 }
314
315 UpdateCodeAndSubjectReferences(
316 isolate, code_handle, subject_handle, code_array_out, code_base_out,
317 pc_out, subject_string_out, subject_string_vector_out);
318 }
319 }
320
322}
323
324bool CheckBitInTable(const uint32_t current_char, const uint8_t* const table) {
326 int b = table[(current_char & mask) >> kBitsPerByteLog2];
327 int bit = (current_char & (kBitsPerByte - 1));
328 return (b & (1 << bit)) != 0;
329}
330
331// Returns true iff 0 <= index < length.
332bool IndexIsInBounds(int index, int length) {
333 DCHECK_GE(length, 0);
334 return static_cast<uintptr_t>(index) < static_cast<uintptr_t>(length);
335}
336
337// If computed gotos are supported by the compiler, we can get addresses to
338// labels directly in C/C++. Every bytecode handler has its own label and we
339// store the addresses in a dispatch table indexed by bytecode. To execute the
340// next handler we simply jump (goto) directly to its address.
341#if V8_USE_COMPUTED_GOTO
342#define BC_LABEL(name) BC_##name:
343#define DECODE() \
344 do { \
345 next_insn = Load32Aligned(next_pc); \
346 next_handler_addr = dispatch_table[next_insn & BYTECODE_MASK]; \
347 } while (false)
348#define DISPATCH() \
349 pc = next_pc; \
350 insn = next_insn; \
351 goto* next_handler_addr
352// Without computed goto support, we fall back to a simple switch-based
353// dispatch (A large switch statement inside a loop with a case for every
354// bytecode).
355#else // V8_USE_COMPUTED_GOTO
356#define BC_LABEL(name) case BC_##name:
357#define DECODE() next_insn = Load32Aligned(next_pc)
358#define DISPATCH() \
359 pc = next_pc; \
360 insn = next_insn; \
361 goto switch_dispatch_continuation
362#endif // V8_USE_COMPUTED_GOTO
363
364// ADVANCE/SET_PC_FROM_OFFSET are separated from DISPATCH, because ideally some
365// instructions can be executed between ADVANCE/SET_PC_FROM_OFFSET and DISPATCH.
366// We want those two macros as far apart as possible, because the goto in
367// DISPATCH is dependent on a memory load in ADVANCE/SET_PC_FROM_OFFSET. If we
368// don't hit the cache and have to fetch the next handler address from physical
369// memory, instructions between ADVANCE/SET_PC_FROM_OFFSET and DISPATCH can
370// potentially be executed unconditionally, reducing memory stall.
371#define ADVANCE(name) \
372 next_pc = pc + RegExpBytecodeLength(BC_##name); \
373 DECODE()
374#define SET_PC_FROM_OFFSET(offset) \
375 next_pc = code_base + offset; \
376 DECODE()
377
378// Current position mutations.
379#define SET_CURRENT_POSITION(value) \
380 do { \
381 current = (value); \
382 DCHECK(base::IsInRange(current, 0, subject.length())); \
383 } while (false)
384#define ADVANCE_CURRENT_POSITION(by) SET_CURRENT_POSITION(current + (by))
385
386#ifdef DEBUG
387#define BYTECODE(name) \
388 BC_LABEL(name) \
389 MaybeTraceInterpreter(code_base, pc, backtrack_stack.sp(), current, \
390 current_char, RegExpBytecodeLength(BC_##name), #name);
391#else
392#define BYTECODE(name) BC_LABEL(name)
393#endif // DEBUG
394
395template <typename Char>
397 Isolate* isolate, Tagged<TrustedByteArray>* code_array,
398 Tagged<String>* subject_string, base::Vector<const Char> subject,
399 int* output_registers, int output_register_count, int total_register_count,
400 int current, uint32_t current_char, RegExp::CallOrigin call_origin,
401 const uint32_t backtrack_limit) {
403
404#if V8_USE_COMPUTED_GOTO
405
406// We have to make sure that no OOB access to the dispatch table is possible and
407// all values are valid label addresses.
408// Otherwise jumps to arbitrary addresses could potentially happen.
409// This is ensured as follows:
410// Every index to the dispatch table gets masked using BYTECODE_MASK in
411// DECODE(). This way we can only get values between 0 (only the least
412// significant byte of an integer is used) and kRegExpPaddedBytecodeCount - 1
413// (BYTECODE_MASK is defined to be exactly this value).
414// All entries from kRegExpBytecodeCount to kRegExpPaddedBytecodeCount have to
415// be filled with BREAKs (invalid operation).
416
417// Fill dispatch table from last defined bytecode up to the next power of two
418// with BREAK (invalid operation).
419// TODO(pthier): Find a way to fill up automatically (at compile time)
420// 59 real bytecodes -> 5 fillers
421#define BYTECODE_FILLER_ITERATOR(V) \
422 V(BREAK) /* 1 */ \
423 V(BREAK) /* 2 */ \
424 V(BREAK) /* 3 */ \
425 V(BREAK) /* 4 */ \
426 V(BREAK) /* 5 */
427
428#define COUNT(...) +1
429 static constexpr int kRegExpBytecodeFillerCount =
430 BYTECODE_FILLER_ITERATOR(COUNT);
431#undef COUNT
432
433 // Make sure kRegExpPaddedBytecodeCount is actually the closest possible power
434 // of two.
437
438 // Make sure every bytecode we get by using BYTECODE_MASK is well defined.
440 static_assert(kRegExpBytecodeCount + kRegExpBytecodeFillerCount ==
442
443#define DECLARE_DISPATCH_TABLE_ENTRY(name, ...) &&BC_##name,
444 static const void* const dispatch_table[kRegExpPaddedBytecodeCount] = {
445 BYTECODE_ITERATOR(DECLARE_DISPATCH_TABLE_ENTRY)
446 BYTECODE_FILLER_ITERATOR(DECLARE_DISPATCH_TABLE_ENTRY)};
447#undef DECLARE_DISPATCH_TABLE_ENTRY
448#undef BYTECODE_FILLER_ITERATOR
449
450#endif // V8_USE_COMPUTED_GOTO
451
452 const uint8_t* pc = (*code_array)->begin();
453 const uint8_t* code_base = pc;
454
455 InterpreterRegisters registers(total_register_count, output_registers,
456 output_register_count);
457 BacktrackStack backtrack_stack;
458
459 uint32_t backtrack_count = 0;
460
461#ifdef DEBUG
462 if (v8_flags.trace_regexp_bytecodes) {
463 PrintF("\n\nStart bytecode interpreter\n\n");
464 }
465#endif
466
467 while (true) {
468 const uint8_t* next_pc = pc;
469 int32_t insn;
470 int32_t next_insn;
471#if V8_USE_COMPUTED_GOTO
472 const void* next_handler_addr;
473 DECODE();
474 DISPATCH();
475#else
476 insn = Load32Aligned(pc);
477 switch (insn & BYTECODE_MASK) {
478#endif // V8_USE_COMPUTED_GOTO
480 BYTECODE(PUSH_CP) {
481 ADVANCE(PUSH_CP);
482 if (!backtrack_stack.push(current)) {
483 return MaybeThrowStackOverflow(isolate, call_origin);
484 }
485 DISPATCH();
486 }
487 BYTECODE(PUSH_BT) {
488 ADVANCE(PUSH_BT);
489 if (!backtrack_stack.push(Load32Aligned(pc + 4))) {
490 return MaybeThrowStackOverflow(isolate, call_origin);
491 }
492 DISPATCH();
493 }
494 BYTECODE(PUSH_REGISTER) {
495 ADVANCE(PUSH_REGISTER);
496 if (!backtrack_stack.push(registers[LoadPacked24Unsigned(insn)])) {
497 return MaybeThrowStackOverflow(isolate, call_origin);
498 }
499 DISPATCH();
500 }
501 BYTECODE(SET_REGISTER) {
502 ADVANCE(SET_REGISTER);
503 registers[LoadPacked24Unsigned(insn)] = Load32Aligned(pc + 4);
504 DISPATCH();
505 }
506 BYTECODE(ADVANCE_REGISTER) {
507 ADVANCE(ADVANCE_REGISTER);
508 registers[LoadPacked24Unsigned(insn)] += Load32Aligned(pc + 4);
509 DISPATCH();
510 }
511 BYTECODE(SET_REGISTER_TO_CP) {
512 ADVANCE(SET_REGISTER_TO_CP);
513 registers[LoadPacked24Unsigned(insn)] = current + Load32Aligned(pc + 4);
514 DISPATCH();
515 }
516 BYTECODE(SET_CP_TO_REGISTER) {
517 ADVANCE(SET_CP_TO_REGISTER);
518 SET_CURRENT_POSITION(registers[LoadPacked24Unsigned(insn)]);
519 DISPATCH();
520 }
521 BYTECODE(SET_REGISTER_TO_SP) {
522 ADVANCE(SET_REGISTER_TO_SP);
523 registers[LoadPacked24Unsigned(insn)] = backtrack_stack.sp();
524 DISPATCH();
525 }
526 BYTECODE(SET_SP_TO_REGISTER) {
527 ADVANCE(SET_SP_TO_REGISTER);
528 backtrack_stack.set_sp(registers[LoadPacked24Unsigned(insn)]);
529 DISPATCH();
530 }
531 BYTECODE(POP_CP) {
532 ADVANCE(POP_CP);
533 SET_CURRENT_POSITION(backtrack_stack.pop());
534 DISPATCH();
535 }
536 BYTECODE(POP_BT) {
537 static_assert(JSRegExp::kNoBacktrackLimit == 0);
538 if (++backtrack_count == backtrack_limit) {
539 int return_code = LoadPacked24Signed(insn);
540 return static_cast<IrregexpInterpreter::Result>(return_code);
541 }
542
543 IrregexpInterpreter::Result return_code =
544 HandleInterrupts(isolate, call_origin, code_array, subject_string,
545 &code_base, &subject, &pc);
546 if (return_code != IrregexpInterpreter::SUCCESS) return return_code;
547
548 SET_PC_FROM_OFFSET(backtrack_stack.pop());
549 DISPATCH();
550 }
551 BYTECODE(POP_REGISTER) {
552 ADVANCE(POP_REGISTER);
553 registers[LoadPacked24Unsigned(insn)] = backtrack_stack.pop();
554 DISPATCH();
555 }
556 BYTECODE(FAIL) {
557 isolate->counters()->regexp_backtracks()->AddSample(
558 static_cast<int>(backtrack_count));
560 }
561 BYTECODE(SUCCEED) {
562 isolate->counters()->regexp_backtracks()->AddSample(
563 static_cast<int>(backtrack_count));
564 registers.CopyToOutputRegisters();
566 }
567 BYTECODE(ADVANCE_CP) {
568 ADVANCE(ADVANCE_CP);
569 ADVANCE_CURRENT_POSITION(LoadPacked24Signed(insn));
570 DISPATCH();
571 }
572 BYTECODE(GOTO) {
573 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
574 DISPATCH();
575 }
576 BYTECODE(ADVANCE_CP_AND_GOTO) {
577 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
578 ADVANCE_CURRENT_POSITION(LoadPacked24Signed(insn));
579 DISPATCH();
580 }
581 BYTECODE(CHECK_GREEDY) {
582 if (current == backtrack_stack.peek()) {
583 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
584 backtrack_stack.pop();
585 } else {
586 ADVANCE(CHECK_GREEDY);
587 }
588 DISPATCH();
589 }
590 BYTECODE(LOAD_CURRENT_CHAR) {
591 int pos = current + LoadPacked24Signed(insn);
592 if (pos >= subject.length() || pos < 0) {
593 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
594 } else {
595 ADVANCE(LOAD_CURRENT_CHAR);
596 current_char = subject[pos];
597 }
598 DISPATCH();
599 }
600 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) {
601 ADVANCE(LOAD_CURRENT_CHAR_UNCHECKED);
602 int pos = current + LoadPacked24Signed(insn);
603 current_char = subject[pos];
604 DISPATCH();
605 }
606 BYTECODE(LOAD_2_CURRENT_CHARS) {
607 int pos = current + LoadPacked24Signed(insn);
608 if (pos + 2 > subject.length() || pos < 0) {
609 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
610 } else {
611 ADVANCE(LOAD_2_CURRENT_CHARS);
612 Char next = subject[pos + 1];
613 current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char))));
614 }
615 DISPATCH();
616 }
617 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) {
618 ADVANCE(LOAD_2_CURRENT_CHARS_UNCHECKED);
619 int pos = current + LoadPacked24Signed(insn);
620 Char next = subject[pos + 1];
621 current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char))));
622 DISPATCH();
623 }
624 BYTECODE(LOAD_4_CURRENT_CHARS) {
625 DCHECK_EQ(1, sizeof(Char));
626 int pos = current + LoadPacked24Signed(insn);
627 if (pos + 4 > subject.length() || pos < 0) {
628 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
629 } else {
630 ADVANCE(LOAD_4_CURRENT_CHARS);
631 Char next1 = subject[pos + 1];
632 Char next2 = subject[pos + 2];
633 Char next3 = subject[pos + 3];
634 current_char =
635 (subject[pos] | (next1 << 8) | (next2 << 16) | (next3 << 24));
636 }
637 DISPATCH();
638 }
639 BYTECODE(LOAD_4_CURRENT_CHARS_UNCHECKED) {
640 ADVANCE(LOAD_4_CURRENT_CHARS_UNCHECKED);
641 DCHECK_EQ(1, sizeof(Char));
642 int pos = current + LoadPacked24Signed(insn);
643 Char next1 = subject[pos + 1];
644 Char next2 = subject[pos + 2];
645 Char next3 = subject[pos + 3];
646 current_char =
647 (subject[pos] | (next1 << 8) | (next2 << 16) | (next3 << 24));
648 DISPATCH();
649 }
650 BYTECODE(CHECK_4_CHARS) {
651 uint32_t c = Load32Aligned(pc + 4);
652 if (c == current_char) {
653 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
654 } else {
655 ADVANCE(CHECK_4_CHARS);
656 }
657 DISPATCH();
658 }
659 BYTECODE(CHECK_CHAR) {
660 uint32_t c = LoadPacked24Unsigned(insn);
661 if (c == current_char) {
662 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
663 } else {
664 ADVANCE(CHECK_CHAR);
665 }
666 DISPATCH();
667 }
668 BYTECODE(CHECK_NOT_4_CHARS) {
669 uint32_t c = Load32Aligned(pc + 4);
670 if (c != current_char) {
671 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
672 } else {
673 ADVANCE(CHECK_NOT_4_CHARS);
674 }
675 DISPATCH();
676 }
677 BYTECODE(CHECK_NOT_CHAR) {
678 uint32_t c = LoadPacked24Unsigned(insn);
679 if (c != current_char) {
680 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
681 } else {
682 ADVANCE(CHECK_NOT_CHAR);
683 }
684 DISPATCH();
685 }
686 BYTECODE(AND_CHECK_4_CHARS) {
687 uint32_t c = Load32Aligned(pc + 4);
688 if (c == (current_char & Load32Aligned(pc + 8))) {
689 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
690 } else {
691 ADVANCE(AND_CHECK_4_CHARS);
692 }
693 DISPATCH();
694 }
695 BYTECODE(AND_CHECK_CHAR) {
696 uint32_t c = LoadPacked24Unsigned(insn);
697 if (c == (current_char & Load32Aligned(pc + 4))) {
698 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
699 } else {
700 ADVANCE(AND_CHECK_CHAR);
701 }
702 DISPATCH();
703 }
704 BYTECODE(AND_CHECK_NOT_4_CHARS) {
705 uint32_t c = Load32Aligned(pc + 4);
706 if (c != (current_char & Load32Aligned(pc + 8))) {
707 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
708 } else {
709 ADVANCE(AND_CHECK_NOT_4_CHARS);
710 }
711 DISPATCH();
712 }
713 BYTECODE(AND_CHECK_NOT_CHAR) {
714 uint32_t c = LoadPacked24Unsigned(insn);
715 if (c != (current_char & Load32Aligned(pc + 4))) {
716 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
717 } else {
718 ADVANCE(AND_CHECK_NOT_CHAR);
719 }
720 DISPATCH();
721 }
722 BYTECODE(MINUS_AND_CHECK_NOT_CHAR) {
723 uint32_t c = LoadPacked24Unsigned(insn);
724 uint32_t minus = Load16AlignedUnsigned(pc + 4);
725 uint32_t mask = Load16AlignedUnsigned(pc + 6);
726 if (c != ((current_char - minus) & mask)) {
727 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
728 } else {
729 ADVANCE(MINUS_AND_CHECK_NOT_CHAR);
730 }
731 DISPATCH();
732 }
733 BYTECODE(CHECK_CHAR_IN_RANGE) {
734 uint32_t from = Load16AlignedUnsigned(pc + 4);
735 uint32_t to = Load16AlignedUnsigned(pc + 6);
736 if (from <= current_char && current_char <= to) {
737 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
738 } else {
739 ADVANCE(CHECK_CHAR_IN_RANGE);
740 }
741 DISPATCH();
742 }
743 BYTECODE(CHECK_CHAR_NOT_IN_RANGE) {
744 uint32_t from = Load16AlignedUnsigned(pc + 4);
745 uint32_t to = Load16AlignedUnsigned(pc + 6);
746 if (from > current_char || current_char > to) {
747 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
748 } else {
749 ADVANCE(CHECK_CHAR_NOT_IN_RANGE);
750 }
751 DISPATCH();
752 }
753 BYTECODE(CHECK_BIT_IN_TABLE) {
754 if (CheckBitInTable(current_char, pc + 8)) {
755 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
756 } else {
757 ADVANCE(CHECK_BIT_IN_TABLE);
758 }
759 DISPATCH();
760 }
762 uint32_t limit = LoadPacked24Unsigned(insn);
763 if (current_char < limit) {
764 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
765 } else {
767 }
768 DISPATCH();
769 }
771 uint32_t limit = LoadPacked24Unsigned(insn);
772 if (current_char > limit) {
773 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
774 } else {
776 }
777 DISPATCH();
778 }
779 BYTECODE(CHECK_REGISTER_LT) {
780 if (registers[LoadPacked24Unsigned(insn)] < Load32Aligned(pc + 4)) {
781 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
782 } else {
783 ADVANCE(CHECK_REGISTER_LT);
784 }
785 DISPATCH();
786 }
787 BYTECODE(CHECK_REGISTER_GE) {
788 if (registers[LoadPacked24Unsigned(insn)] >= Load32Aligned(pc + 4)) {
789 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
790 } else {
791 ADVANCE(CHECK_REGISTER_GE);
792 }
793 DISPATCH();
794 }
795 BYTECODE(CHECK_REGISTER_EQ_POS) {
796 if (registers[LoadPacked24Unsigned(insn)] == current) {
797 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
798 } else {
799 ADVANCE(CHECK_REGISTER_EQ_POS);
800 }
801 DISPATCH();
802 }
803 BYTECODE(CHECK_NOT_REGS_EQUAL) {
804 if (registers[LoadPacked24Unsigned(insn)] ==
805 registers[Load32Aligned(pc + 4)]) {
806 ADVANCE(CHECK_NOT_REGS_EQUAL);
807 } else {
808 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
809 }
810 DISPATCH();
811 }
812 BYTECODE(CHECK_NOT_BACK_REF) {
813 int from = registers[LoadPacked24Unsigned(insn)];
814 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
815 if (from >= 0 && len > 0) {
816 if (current + len > subject.length() ||
817 !CompareCharsEqual(&subject[from], &subject[current], len)) {
818 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
819 DISPATCH();
820 }
822 }
823 ADVANCE(CHECK_NOT_BACK_REF);
824 DISPATCH();
825 }
826 BYTECODE(CHECK_NOT_BACK_REF_BACKWARD) {
827 int from = registers[LoadPacked24Unsigned(insn)];
828 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
829 if (from >= 0 && len > 0) {
830 if (current - len < 0 ||
831 !CompareCharsEqual(&subject[from], &subject[current - len], len)) {
832 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
833 DISPATCH();
834 }
835 SET_CURRENT_POSITION(current - len);
836 }
837 ADVANCE(CHECK_NOT_BACK_REF_BACKWARD);
838 DISPATCH();
839 }
840 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE_UNICODE) {
841 int from = registers[LoadPacked24Unsigned(insn)];
842 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
843 if (from >= 0 && len > 0) {
844 if (current + len > subject.length() ||
845 !BackRefMatchesNoCase(isolate, from, current, len, subject, true)) {
846 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
847 DISPATCH();
848 }
850 }
851 ADVANCE(CHECK_NOT_BACK_REF_NO_CASE_UNICODE);
852 DISPATCH();
853 }
854 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE) {
855 int from = registers[LoadPacked24Unsigned(insn)];
856 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
857 if (from >= 0 && len > 0) {
858 if (current + len > subject.length() ||
859 !BackRefMatchesNoCase(isolate, from, current, len, subject,
860 false)) {
861 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
862 DISPATCH();
863 }
865 }
866 ADVANCE(CHECK_NOT_BACK_REF_NO_CASE);
867 DISPATCH();
868 }
869 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE_UNICODE_BACKWARD) {
870 int from = registers[LoadPacked24Unsigned(insn)];
871 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
872 if (from >= 0 && len > 0) {
873 if (current - len < 0 ||
874 !BackRefMatchesNoCase(isolate, from, current - len, len, subject,
875 true)) {
876 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
877 DISPATCH();
878 }
879 SET_CURRENT_POSITION(current - len);
880 }
881 ADVANCE(CHECK_NOT_BACK_REF_NO_CASE_UNICODE_BACKWARD);
882 DISPATCH();
883 }
884 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE_BACKWARD) {
885 int from = registers[LoadPacked24Unsigned(insn)];
886 int len = registers[LoadPacked24Unsigned(insn) + 1] - from;
887 if (from >= 0 && len > 0) {
888 if (current - len < 0 ||
889 !BackRefMatchesNoCase(isolate, from, current - len, len, subject,
890 false)) {
891 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
892 DISPATCH();
893 }
894 SET_CURRENT_POSITION(current - len);
895 }
896 ADVANCE(CHECK_NOT_BACK_REF_NO_CASE_BACKWARD);
897 DISPATCH();
898 }
899 BYTECODE(CHECK_AT_START) {
900 if (current + LoadPacked24Signed(insn) == 0) {
901 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
902 } else {
903 ADVANCE(CHECK_AT_START);
904 }
905 DISPATCH();
906 }
907 BYTECODE(CHECK_NOT_AT_START) {
908 if (current + LoadPacked24Signed(insn) == 0) {
909 ADVANCE(CHECK_NOT_AT_START);
910 } else {
911 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
912 }
913 DISPATCH();
914 }
915 BYTECODE(SET_CURRENT_POSITION_FROM_END) {
916 ADVANCE(SET_CURRENT_POSITION_FROM_END);
917 int by = LoadPacked24Unsigned(insn);
918 if (subject.length() - current > by) {
919 SET_CURRENT_POSITION(subject.length() - by);
920 current_char = subject[current - 1];
921 }
922 DISPATCH();
923 }
924 BYTECODE(CHECK_CURRENT_POSITION) {
925 int pos = current + LoadPacked24Signed(insn);
926 if (pos > subject.length() || pos < 0) {
927 SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
928 } else {
929 ADVANCE(CHECK_CURRENT_POSITION);
930 }
931 DISPATCH();
932 }
933 BYTECODE(SKIP_UNTIL_CHAR) {
934 int32_t load_offset = LoadPacked24Signed(insn);
935 int32_t advance = Load16AlignedSigned(pc + 4);
936 uint32_t c = Load16AlignedUnsigned(pc + 6);
937 while (IndexIsInBounds(current + load_offset, subject.length())) {
938 current_char = subject[current + load_offset];
939 if (c == current_char) {
940 SET_PC_FROM_OFFSET(Load32Aligned(pc + 8));
941 DISPATCH();
942 }
944 }
945 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
946 DISPATCH();
947 }
948 BYTECODE(SKIP_UNTIL_CHAR_AND) {
949 int32_t load_offset = LoadPacked24Signed(insn);
950 int32_t advance = Load16AlignedSigned(pc + 4);
951 uint16_t c = Load16AlignedUnsigned(pc + 6);
952 uint32_t mask = Load32Aligned(pc + 8);
953 int32_t maximum_offset = Load32Aligned(pc + 12);
954 while (static_cast<uintptr_t>(current + maximum_offset) <=
955 static_cast<uintptr_t>(subject.length())) {
956 current_char = subject[current + load_offset];
957 if (c == (current_char & mask)) {
958 SET_PC_FROM_OFFSET(Load32Aligned(pc + 16));
959 DISPATCH();
960 }
962 }
963 SET_PC_FROM_OFFSET(Load32Aligned(pc + 20));
964 DISPATCH();
965 }
966 BYTECODE(SKIP_UNTIL_CHAR_POS_CHECKED) {
967 int32_t load_offset = LoadPacked24Signed(insn);
968 int32_t advance = Load16AlignedSigned(pc + 4);
969 uint16_t c = Load16AlignedUnsigned(pc + 6);
970 int32_t maximum_offset = Load32Aligned(pc + 8);
971 while (static_cast<uintptr_t>(current + maximum_offset) <=
972 static_cast<uintptr_t>(subject.length())) {
973 current_char = subject[current + load_offset];
974 if (c == current_char) {
975 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
976 DISPATCH();
977 }
979 }
980 SET_PC_FROM_OFFSET(Load32Aligned(pc + 16));
981 DISPATCH();
982 }
983 BYTECODE(SKIP_UNTIL_BIT_IN_TABLE) {
984 int32_t load_offset = LoadPacked24Signed(insn);
985 int32_t advance = Load32Aligned(pc + 4);
986 const uint8_t* table = pc + 8;
987 while (IndexIsInBounds(current + load_offset, subject.length())) {
988 current_char = subject[current + load_offset];
989 if (CheckBitInTable(current_char, table)) {
990 SET_PC_FROM_OFFSET(Load32Aligned(pc + 24));
991 DISPATCH();
992 }
994 }
995 SET_PC_FROM_OFFSET(Load32Aligned(pc + 28));
996 DISPATCH();
997 }
998 BYTECODE(SKIP_UNTIL_GT_OR_NOT_BIT_IN_TABLE) {
999 int32_t load_offset = LoadPacked24Signed(insn);
1000 int32_t advance = Load16AlignedSigned(pc + 4);
1001 uint16_t limit = Load16AlignedUnsigned(pc + 6);
1002 const uint8_t* table = pc + 8;
1003 while (IndexIsInBounds(current + load_offset, subject.length())) {
1004 current_char = subject[current + load_offset];
1005 if (current_char > limit) {
1006 SET_PC_FROM_OFFSET(Load32Aligned(pc + 24));
1007 DISPATCH();
1008 }
1009 if (!CheckBitInTable(current_char, table)) {
1010 SET_PC_FROM_OFFSET(Load32Aligned(pc + 24));
1011 DISPATCH();
1012 }
1013 ADVANCE_CURRENT_POSITION(advance);
1014 }
1015 SET_PC_FROM_OFFSET(Load32Aligned(pc + 28));
1016 DISPATCH();
1017 }
1018 BYTECODE(SKIP_UNTIL_CHAR_OR_CHAR) {
1019 int32_t load_offset = LoadPacked24Signed(insn);
1020 int32_t advance = Load32Aligned(pc + 4);
1021 uint16_t c = Load16AlignedUnsigned(pc + 8);
1022 uint16_t c2 = Load16AlignedUnsigned(pc + 10);
1023 while (IndexIsInBounds(current + load_offset, subject.length())) {
1024 current_char = subject[current + load_offset];
1025 // The two if-statements below are split up intentionally, as combining
1026 // them seems to result in register allocation behaving quite
1027 // differently and slowing down the resulting code.
1028 if (c == current_char) {
1029 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
1030 DISPATCH();
1031 }
1032 if (c2 == current_char) {
1033 SET_PC_FROM_OFFSET(Load32Aligned(pc + 12));
1034 DISPATCH();
1035 }
1036 ADVANCE_CURRENT_POSITION(advance);
1037 }
1038 SET_PC_FROM_OFFSET(Load32Aligned(pc + 16));
1039 DISPATCH();
1040 }
1041#if V8_USE_COMPUTED_GOTO
1042// Lint gets confused a lot if we just use !V8_USE_COMPUTED_GOTO or ifndef
1043// V8_USE_COMPUTED_GOTO here.
1044#else
1045 default:
1046 UNREACHABLE();
1047 }
1048 // Label we jump to in DISPATCH(). There must be no instructions between the
1049 // end of the switch, this label and the end of the loop.
1050 switch_dispatch_continuation : {}
1051#endif // V8_USE_COMPUTED_GOTO
1052 }
1053}
1054
1055#undef BYTECODE
1056#undef ADVANCE_CURRENT_POSITION
1057#undef SET_CURRENT_POSITION
1058#undef DISPATCH
1059#undef DECODE
1060#undef SET_PC_FROM_OFFSET
1061#undef ADVANCE
1062#undef BC_LABEL
1063#undef V8_USE_COMPUTED_GOTO
1064
1065} // namespace
1066
1067// static
1069 Tagged<IrRegExpData> regexp_data,
1070 Tagged<String> subject_string,
1071 int* output_registers, int output_register_count,
1072 int start_position,
1074 if (v8_flags.regexp_tier_up) regexp_data->TierUpTick();
1075
1076 bool is_any_unicode =
1077 IsEitherUnicode(JSRegExp::AsRegExpFlags(regexp_data->flags()));
1078 bool is_one_byte = String::IsOneByteRepresentationUnderneath(subject_string);
1079 Tagged<TrustedByteArray> code_array = regexp_data->bytecode(is_one_byte);
1080 int total_register_count = regexp_data->max_register_count();
1081
1082 // MatchInternal only supports returning a single match per call. In global
1083 // mode, i.e. when output_registers has space for more than one match, we
1084 // need to keep running until all matches are filled in.
1085 int registers_per_match =
1086 JSRegExp::RegistersForCaptureCount(regexp_data->capture_count());
1087 DCHECK_LE(registers_per_match, output_register_count);
1088 int number_of_matches_in_output_registers =
1089 output_register_count / registers_per_match;
1090
1091 int backtrack_limit = regexp_data->backtrack_limit();
1092
1093 int num_matches = 0;
1094 int* current_output_registers = output_registers;
1095 for (int i = 0; i < number_of_matches_in_output_registers; i++) {
1096 auto current_result = MatchInternal(
1097 isolate, &code_array, &subject_string, current_output_registers,
1098 registers_per_match, total_register_count, start_position, call_origin,
1099 backtrack_limit);
1100
1101 if (current_result == SUCCESS) {
1102 // Fall through.
1103 } else if (current_result == FAILURE) {
1104 break;
1105 } else {
1106 DCHECK(current_result == EXCEPTION ||
1107 current_result == FALLBACK_TO_EXPERIMENTAL ||
1108 current_result == RETRY);
1109 return current_result;
1110 }
1111
1112 // Found a match. Advance the index.
1113
1114 num_matches++;
1115
1116 int next_start_position = current_output_registers[1];
1117 if (next_start_position == current_output_registers[0]) {
1118 // Zero-length matches.
1119 // TODO(jgruber): Use AdvanceStringIndex based on flat contents instead.
1120 next_start_position = static_cast<int>(RegExpUtils::AdvanceStringIndex(
1121 subject_string, next_start_position, is_any_unicode));
1122 if (next_start_position > static_cast<int>(subject_string->length())) {
1123 break;
1124 }
1125 }
1126
1127 start_position = next_start_position;
1128 current_output_registers += registers_per_match;
1129 }
1130
1131 return num_matches;
1132}
1133
1135 Isolate* isolate, Tagged<TrustedByteArray>* code_array,
1136 Tagged<String>* subject_string, int* output_registers,
1137 int output_register_count, int total_register_count, int start_position,
1138 RegExp::CallOrigin call_origin, uint32_t backtrack_limit) {
1139 DCHECK((*subject_string)->IsFlat());
1140
1141 // Note: Heap allocation *is* allowed in two situations if calling from
1142 // Runtime:
1143 // 1. When creating & throwing a stack overflow exception. The interpreter
1144 // aborts afterwards, and thus possible-moved objects are never used.
1145 // 2. When handling interrupts. We manually relocate unhandlified references
1146 // after interrupts have run.
1148
1149 base::uc16 previous_char = '\n';
1150 String::FlatContent subject_content =
1151 (*subject_string)->GetFlatContent(no_gc);
1152 // Because interrupts can result in GC and string content relocation, the
1153 // checksum verification in FlatContent may fail even though this code is
1154 // safe. See (2) above.
1155 subject_content.UnsafeDisableChecksumVerification();
1156 if (subject_content.IsOneByte()) {
1157 base::Vector<const uint8_t> subject_vector =
1158 subject_content.ToOneByteVector();
1159 if (start_position != 0) previous_char = subject_vector[start_position - 1];
1160 return RawMatch(isolate, code_array, subject_string, subject_vector,
1161 output_registers, output_register_count,
1162 total_register_count, start_position, previous_char,
1163 call_origin, backtrack_limit);
1164 } else {
1165 DCHECK(subject_content.IsTwoByte());
1166 base::Vector<const base::uc16> subject_vector =
1167 subject_content.ToUC16Vector();
1168 if (start_position != 0) previous_char = subject_vector[start_position - 1];
1169 return RawMatch(isolate, code_array, subject_string, subject_vector,
1170 output_registers, output_register_count,
1171 total_register_count, start_position, previous_char,
1172 call_origin, backtrack_limit);
1173 }
1174}
1175
1176#ifndef COMPILING_IRREGEXP_FOR_EXTERNAL_EMBEDDER
1177
1178// This method is called through an external reference from RegExpExecInternal
1179// builtin.
1181 Address subject, int32_t start_position, Address, Address,
1182 int* output_registers, int32_t output_register_count,
1183 RegExp::CallOrigin call_origin, Isolate* isolate, Address regexp_data) {
1184 DCHECK_NOT_NULL(isolate);
1185 DCHECK_NOT_NULL(output_registers);
1187
1189 DisallowJavascriptExecution no_js(isolate);
1190 DisallowHandleAllocation no_handles;
1192
1193 Tagged<String> subject_string = Cast<String>(Tagged<Object>(subject));
1194 Tagged<IrRegExpData> regexp_data_obj =
1195 Cast<IrRegExpData>(Tagged<Object>(regexp_data));
1196
1197 if (regexp_data_obj->MarkedForTierUp()) {
1198 // Returning RETRY will re-enter through runtime, where actual recompilation
1199 // for tier-up takes place.
1201 }
1202
1203 return Match(isolate, regexp_data_obj, subject_string, output_registers,
1204 output_register_count, start_position, call_origin);
1205}
1206
1207#endif // !COMPILING_IRREGEXP_FOR_EXTERNAL_EMBEDDER
1208
1210 Isolate* isolate, DirectHandle<IrRegExpData> regexp_data,
1211 DirectHandle<String> subject_string, int* output_registers,
1212 int output_register_count, int start_position) {
1213 return Match(isolate, *regexp_data, *subject_string, output_registers,
1214 output_register_count, start_position,
1216}
1217
1218} // namespace internal
1219} // namespace v8
#define FAIL(msg)
Definition asm-parser.cc:44
#define GOTO(label,...)
uint8_t data_[MAX_STACK_LENGTH]
#define SBXCHECK_LE(lhs, rhs)
Definition check.h:67
#define SBXCHECK_LT(lhs, rhs)
Definition check.h:66
#define SBXCHECK_GE(lhs, rhs)
Definition check.h:65
#define SBXCHECK(condition)
Definition check.h:61
SourcePosition pos
static int MatchForCallFromRuntime(Isolate *isolate, DirectHandle< IrRegExpData > regexp_data, DirectHandle< String > subject_string, int *output_registers, int output_register_count, int start_position)
static int Match(Isolate *isolate, Tagged< IrRegExpData > regexp_data, Tagged< String > subject_string, int *output_registers, int output_register_count, int start_position, RegExp::CallOrigin call_origin)
static int MatchForCallFromJs(Address subject, int32_t start_position, Address input_start, Address input_end, int *output_registers, int32_t output_register_count, RegExp::CallOrigin call_origin, Isolate *isolate, Address regexp_data)
static Result MatchInternal(Isolate *isolate, Tagged< TrustedByteArray > *code_array, Tagged< String > *subject_string, int *output_registers, int output_register_count, int total_register_count, int start_position, RegExp::CallOrigin call_origin, uint32_t backtrack_limit)
static constexpr RegExpFlags AsRegExpFlags(Flags f)
Definition js-regexp.h:57
static constexpr uint32_t kNoBacktrackLimit
Definition js-regexp.h:133
static constexpr int RegistersForCaptureCount(int count)
Definition js-regexp.h:90
static int CaseInsensitiveCompareUnicode(Address byte_offset1, Address byte_offset2, size_t byte_length, Isolate *isolate)
static constexpr size_t kMaximumStackSize
static uint64_t AdvanceStringIndex(Tagged< String > string, uint64_t index, bool unicode)
base::Vector< const uint8_t > ToOneByteVector() const
Definition string.h:139
base::Vector< const base::uc16 > ToUC16Vector() const
Definition string.h:145
static bool IsOneByteRepresentationUnderneath(Tagged< String > string)
Definition string-inl.h:373
#define DISPATCH(ret, method)
ZoneVector< RpoNumber > & result
int pc_offset
Point from
uint32_t const mask
RegListBase< RegisterT > registers
int int32_t
Definition unicode.cc:40
unsigned short uint16_t
Definition unicode.cc:39
signed short int16_t
Definition unicode.cc:38
V8_BASE_EXPORT constexpr uint32_t RoundUpToPowerOfTwo32(uint32_t value)
Definition bits.h:219
constexpr int kUC16Size
Definition strings.h:20
uint16_t uc16
Definition strings.h:18
void push(LiftoffAssembler *assm, LiftoffRegister reg, ValueKind kind, int padding=0)
static constexpr int kRegExpBytecodeCount
constexpr int kBitsPerByte
Definition globals.h:682
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
const int BYTECODE_SHIFT
void PrintF(const char *format,...)
Definition utils.cc:39
constexpr bool IsEitherUnicode(RegExpFlags f)
Tagged(T object) -> Tagged< T >
void RegExpBytecodeDisassembleSingle(const uint8_t *code_base, const uint8_t *pc)
PerThreadAssertScopeDebugOnly< true, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > AllowGarbageCollection
bool CompareCharsEqual(const lchar *lhs, const rchar *rhs, size_t chars)
Definition utils.h:509
constexpr int BYTECODE_MASK
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr int kBitsPerByteLog2
Definition globals.h:683
void MemCopy(void *dest, const void *src, size_t size)
Definition memcopy.h:124
constexpr int kRegExpPaddedBytecodeCount
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define BYTECODE_ITERATOR(V)
#define COUNT(...)
base::SmallVector< RegisterT, kStaticCapacity > registers_
#define BYTECODE(name)
#define SET_PC_FROM_OFFSET(offset)
RegisterT *const output_registers_
static constexpr int kMaxSize
static constexpr int kStaticCapacity
const int total_register_count_
#define SET_CURRENT_POSITION(value)
#define DECODE()
#define ADVANCE(name)
#define ADVANCE_CURRENT_POSITION(by)
const int output_register_count_
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK(condition)
Definition logging.h:124
#define CHECK_GT(lhs, rhs)
#define CHECK_LT(lhs, rhs)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define DCHECK_GT(v1, v2)
Definition logging.h:487
#define USE(...)
Definition macros.h:293
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671