V8 Project
v8::internal::NativeRegExpMacroAssembler Class Reference

#include <regexp-macro-assembler.h>

+ Inheritance diagram for v8::internal::NativeRegExpMacroAssembler:
+ Collaboration diagram for v8::internal::NativeRegExpMacroAssembler:

Public Types

enum  Mode { LATIN1 = 1 , UC16 = 2 }
 
enum  Result { RETRY = -2 , EXCEPTION = -1 , FAILURE = 0 , SUCCESS = 1 }
 
- Public Types inherited from v8::internal::RegExpMacroAssembler
enum  IrregexpImplementation {
  kIA32Implementation , kARMImplementation , kARM64Implementation , kMIPSImplementation ,
  kX64Implementation , kX87Implementation , kBytecodeImplementation
}
 
enum  StackCheckFlag { kNoStackLimitCheck = false , kCheckStackLimit = true }
 
enum  GlobalMode { NOT_GLOBAL , GLOBAL , GLOBAL_NO_ZERO_LENGTH_CHECK }
 

Public Member Functions

 NativeRegExpMacroAssembler (Zone *zone)
 
virtual ~NativeRegExpMacroAssembler ()
 
virtual bool CanReadUnaligned ()
 
- Public Member Functions inherited from v8::internal::RegExpMacroAssembler
 RegExpMacroAssembler (Zone *zone)
 
virtual ~RegExpMacroAssembler ()
 
virtual int stack_limit_slack ()=0
 
virtual void AdvanceCurrentPosition (int by)=0
 
virtual void AdvanceRegister (int reg, int by)=0
 
virtual void Backtrack ()=0
 
virtual void Bind (Label *label)=0
 
virtual void CheckAtStart (Label *on_at_start)=0
 
virtual void CheckCharacter (unsigned c, Label *on_equal)=0
 
virtual void CheckCharacterAfterAnd (unsigned c, unsigned and_with, Label *on_equal)=0
 
virtual void CheckCharacterGT (uc16 limit, Label *on_greater)=0
 
virtual void CheckCharacterLT (uc16 limit, Label *on_less)=0
 
virtual void CheckGreedyLoop (Label *on_tos_equals_current_position)=0
 
virtual void CheckNotAtStart (Label *on_not_at_start)=0
 
virtual void CheckNotBackReference (int start_reg, Label *on_no_match)=0
 
virtual void CheckNotBackReferenceIgnoreCase (int start_reg, Label *on_no_match)=0
 
virtual void CheckNotCharacter (unsigned c, Label *on_not_equal)=0
 
virtual void CheckNotCharacterAfterAnd (unsigned c, unsigned and_with, Label *on_not_equal)=0
 
virtual void CheckNotCharacterAfterMinusAnd (uc16 c, uc16 minus, uc16 and_with, Label *on_not_equal)=0
 
virtual void CheckCharacterInRange (uc16 from, uc16 to, Label *on_in_range)=0
 
virtual void CheckCharacterNotInRange (uc16 from, uc16 to, Label *on_not_in_range)=0
 
virtual void CheckBitInTable (Handle< ByteArray > table, Label *on_bit_set)=0
 
virtual void CheckPosition (int cp_offset, Label *on_outside_input)
 
virtual bool CheckSpecialCharacterClass (uc16 type, Label *on_no_match)
 
virtual void Fail ()=0
 
virtual Handle< HeapObjectGetCode (Handle< String > source)=0
 
virtual void GoTo (Label *label)=0
 
virtual void IfRegisterGE (int reg, int comparand, Label *if_ge)=0
 
virtual void IfRegisterLT (int reg, int comparand, Label *if_lt)=0
 
virtual void IfRegisterEqPos (int reg, Label *if_eq)=0
 
virtual IrregexpImplementation Implementation ()=0
 
virtual void LoadCurrentCharacter (int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)=0
 
virtual void PopCurrentPosition ()=0
 
virtual void PopRegister (int register_index)=0
 
virtual void PushBacktrack (Label *label)=0
 
virtual void PushCurrentPosition ()=0
 
virtual void PushRegister (int register_index, StackCheckFlag check_stack_limit)=0
 
virtual void ReadCurrentPositionFromRegister (int reg)=0
 
virtual void ReadStackPointerFromRegister (int reg)=0
 
virtual void SetCurrentPositionFromEnd (int by)=0
 
virtual void SetRegister (int register_index, int to)=0
 
virtual bool Succeed ()=0
 
virtual void WriteCurrentPositionToRegister (int reg, int cp_offset)=0
 
virtual void ClearRegisters (int reg_from, int reg_to)=0
 
virtual void WriteStackPointerToRegister (int reg)=0
 
void set_slow_safe (bool ssc)
 
bool slow_safe ()
 
void set_global_mode (GlobalMode mode)
 
bool global ()
 
bool global_with_zero_length_check ()
 
Zonezone () const
 

Static Public Member Functions

static Result Match (Handle< Code > regexp, Handle< String > subject, int *offsets_vector, int offsets_vector_length, int previous_index, Isolate *isolate)
 
static int CaseInsensitiveCompareUC16 (Address byte_offset1, Address byte_offset2, size_t byte_length, Isolate *isolate)
 
static Address GrowStack (Address stack_pointer, Address *stack_top, Isolate *isolate)
 
static const byteStringCharacterPosition (String *subject, int start_index)
 
static Address word_character_map_address ()
 
static Result Execute (Code *code, String *input, int start_offset, const byte *input_start, const byte *input_end, int *output, int output_size, Isolate *isolate)
 

Static Public Attributes

static const byte word_character_map [256]
 
- Static Public Attributes inherited from v8::internal::RegExpMacroAssembler
static const int kMaxRegister = (1 << 16) - 1
 
static const int kMaxCPOffset = (1 << 15) - 1
 
static const int kMinCPOffset = -(1 << 15)
 
static const int kTableSizeBits = 7
 
static const int kTableSize = 1 << kTableSizeBits
 
static const int kTableMask = kTableSize - 1
 

Detailed Description

Definition at line 171 of file regexp-macro-assembler.h.

Member Enumeration Documentation

◆ Mode

◆ Result

Constructor & Destructor Documentation

◆ NativeRegExpMacroAssembler()

v8::internal::NativeRegExpMacroAssembler::NativeRegExpMacroAssembler ( Zone zone)
explicit

◆ ~NativeRegExpMacroAssembler()

v8::internal::NativeRegExpMacroAssembler::~NativeRegExpMacroAssembler ( )
virtual

Definition at line 34 of file regexp-macro-assembler.cc.

34  {
35 }

Member Function Documentation

◆ CanReadUnaligned()

bool v8::internal::NativeRegExpMacroAssembler::CanReadUnaligned ( )
virtual

Implements v8::internal::RegExpMacroAssembler.

Reimplemented in v8::internal::RegExpMacroAssemblerMIPS, v8::internal::RegExpMacroAssemblerMIPS, v8::internal::RegExpMacroAssemblerARM64, and v8::internal::RegExpMacroAssemblerARM.

Definition at line 38 of file regexp-macro-assembler.cc.

38  {
39  return FLAG_enable_unaligned_accesses && !slow_safe();
40 }

References v8::internal::RegExpMacroAssembler::slow_safe().

+ Here is the call graph for this function:

◆ CaseInsensitiveCompareUC16()

int v8::internal::NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16 ( Address  byte_offset1,
Address  byte_offset2,
size_t  byte_length,
Isolate isolate 
)
static

Definition at line 204 of file regexp-macro-assembler.cc.

208  {
210  isolate->regexp_macro_assembler_canonicalize();
211  // This function is not allowed to cause a garbage collection.
212  // A GC might move the calling generated code and invalidate the
213  // return address on the stack.
214  DCHECK(byte_length % 2 == 0);
215  uc16* substring1 = reinterpret_cast<uc16*>(byte_offset1);
216  uc16* substring2 = reinterpret_cast<uc16*>(byte_offset2);
217  size_t length = byte_length >> 1;
218 
219  for (size_t i = 0; i < length; i++) {
220  unibrow::uchar c1 = substring1[i];
221  unibrow::uchar c2 = substring2[i];
222  if (c1 != c2) {
223  unibrow::uchar s1[1] = { c1 };
224  canonicalize->get(c1, '\0', s1);
225  if (s1[0] != c2) {
226  unibrow::uchar s2[1] = { c2 };
227  canonicalize->get(c2, '\0', s2);
228  if (s1[0] != s2[0]) {
229  return 0;
230  }
231  }
232  }
233  }
234  return 1;
235 }
int get(uchar c, uchar n, uchar *result)
Definition: unicode-inl.h:27
#define DCHECK(condition)
Definition: logging.h:205
unsigned int uchar
Definition: unicode.h:17
const SwVfpRegister s1
const SwVfpRegister s2
uint16_t uc16
Definition: globals.h:184

References DCHECK, unibrow::Mapping< T, size >::get(), v8::internal::Isolate::regexp_macro_assembler_canonicalize(), v8::internal::s1, and v8::internal::s2.

+ Here is the call graph for this function:

◆ Execute()

NativeRegExpMacroAssembler::Result v8::internal::NativeRegExpMacroAssembler::Execute ( Code code,
String input,
int  start_offset,
const byte input_start,
const byte input_end,
int output,
int  output_size,
Isolate isolate 
)
static

Definition at line 126 of file regexp-macro-assembler.cc.

134  {
135  // Ensure that the minimum stack has been allocated.
136  RegExpStackScope stack_scope(isolate);
137  Address stack_base = stack_scope.stack()->stack_base();
138 
139  int direct_call = 0;
140  int result = CALL_GENERATED_REGEXP_CODE(code->entry(),
141  input,
142  start_offset,
143  input_start,
144  input_end,
145  output,
146  output_size,
147  stack_base,
148  direct_call,
149  isolate);
150  DCHECK(result >= RETRY);
151 
152  if (result == EXCEPTION && !isolate->has_pending_exception()) {
153  // We detected a stack overflow (on the backtrack stack) in RegExp code,
154  // but haven't created the exception yet.
155  isolate->StackOverflow();
156  }
157  return static_cast<Result>(result);
158 }
byte * Address
Definition: globals.h:101
#define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7, p8)
Definition: simulator-arm.h:36

References CALL_GENERATED_REGEXP_CODE, DCHECK, v8::internal::Code::entry(), EXCEPTION, v8::internal::Isolate::has_pending_exception(), RETRY, v8::internal::RegExpStackScope::stack(), v8::internal::RegExpStack::stack_base(), and v8::internal::Isolate::StackOverflow().

Referenced by Match().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GrowStack()

Address v8::internal::NativeRegExpMacroAssembler::GrowStack ( Address  stack_pointer,
Address stack_top,
Isolate isolate 
)
static

Definition at line 238 of file regexp-macro-assembler.cc.

240  {
241  RegExpStack* regexp_stack = isolate->regexp_stack();
242  size_t size = regexp_stack->stack_capacity();
243  Address old_stack_base = regexp_stack->stack_base();
244  DCHECK(old_stack_base == *stack_base);
245  DCHECK(stack_pointer <= old_stack_base);
246  DCHECK(static_cast<size_t>(old_stack_base - stack_pointer) <= size);
247  Address new_stack_base = regexp_stack->EnsureCapacity(size * 2);
248  if (new_stack_base == NULL) {
249  return NULL;
250  }
251  *stack_base = new_stack_base;
252  intptr_t stack_content_size = old_stack_base - stack_pointer;
253  return new_stack_base - stack_content_size;
254 }
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References DCHECK, v8::internal::RegExpStack::EnsureCapacity(), NULL, v8::internal::Isolate::regexp_stack(), size, v8::internal::RegExpStack::stack_base(), and v8::internal::RegExpStack::stack_capacity().

+ Here is the call graph for this function:

◆ Match()

NativeRegExpMacroAssembler::Result v8::internal::NativeRegExpMacroAssembler::Match ( Handle< Code regexp,
Handle< String subject,
int offsets_vector,
int  offsets_vector_length,
int  previous_index,
Isolate isolate 
)
static

Definition at line 72 of file regexp-macro-assembler.cc.

78  {
79 
80  DCHECK(subject->IsFlat());
81  DCHECK(previous_index >= 0);
82  DCHECK(previous_index <= subject->length());
83 
84  // No allocations before calling the regexp, but we can't use
85  // DisallowHeapAllocation, since regexps might be preempted, and another
86  // thread might do allocation anyway.
87 
88  String* subject_ptr = *subject;
89  // Character offsets into string.
90  int start_offset = previous_index;
91  int char_length = subject_ptr->length() - start_offset;
92  int slice_offset = 0;
93 
94  // The string has been flattened, so if it is a cons string it contains the
95  // full string in the first part.
96  if (StringShape(subject_ptr).IsCons()) {
97  DCHECK_EQ(0, ConsString::cast(subject_ptr)->second()->length());
98  subject_ptr = ConsString::cast(subject_ptr)->first();
99  } else if (StringShape(subject_ptr).IsSliced()) {
100  SlicedString* slice = SlicedString::cast(subject_ptr);
101  subject_ptr = slice->parent();
102  slice_offset = slice->offset();
103  }
104  // Ensure that an underlying string has the same representation.
105  bool is_one_byte = subject_ptr->IsOneByteRepresentation();
106  DCHECK(subject_ptr->IsExternalString() || subject_ptr->IsSeqString());
107  // String is now either Sequential or External
108  int char_size_shift = is_one_byte ? 0 : 1;
109 
110  const byte* input_start =
111  StringCharacterPosition(subject_ptr, start_offset + slice_offset);
112  int byte_length = char_length << char_size_shift;
113  const byte* input_end = input_start + byte_length;
114  Result res = Execute(*regexp_code,
115  *subject,
116  start_offset,
117  input_start,
118  input_end,
119  offsets_vector,
120  offsets_vector_length,
121  isolate);
122  return res;
123 }
static Result Execute(Code *code, String *input, int start_offset, const byte *input_start, const byte *input_end, int *output, int output_size, Isolate *isolate)
static const byte * StringCharacterPosition(String *subject, int start_index)
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References DCHECK, DCHECK_EQ, Execute(), v8::internal::String::IsOneByteRepresentation(), v8::internal::String::length(), v8::internal::SlicedString::offset(), v8::internal::SlicedString::parent(), and StringCharacterPosition().

Referenced by v8::internal::RegExpImpl::IrregexpExecRaw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StringCharacterPosition()

const byte * v8::internal::NativeRegExpMacroAssembler::StringCharacterPosition ( String subject,
int  start_index 
)
static

Definition at line 42 of file regexp-macro-assembler.cc.

44  {
45  // Not just flat, but ultra flat.
46  DCHECK(subject->IsExternalString() || subject->IsSeqString());
47  DCHECK(start_index >= 0);
48  DCHECK(start_index <= subject->length());
49  if (subject->IsOneByteRepresentation()) {
50  const byte* address;
51  if (StringShape(subject).IsExternal()) {
52  const uint8_t* data = ExternalOneByteString::cast(subject)->GetChars();
53  address = reinterpret_cast<const byte*>(data);
54  } else {
55  DCHECK(subject->IsSeqOneByteString());
56  const uint8_t* data = SeqOneByteString::cast(subject)->GetChars();
57  address = reinterpret_cast<const byte*>(data);
58  }
59  return address + start_index;
60  }
61  const uc16* data;
62  if (StringShape(subject).IsExternal()) {
63  data = ExternalTwoByteString::cast(subject)->GetChars();
64  } else {
65  DCHECK(subject->IsSeqTwoByteString());
66  data = SeqTwoByteString::cast(subject)->GetChars();
67  }
68  return reinterpret_cast<const byte*>(data + start_index);
69 }

References DCHECK, and v8::internal::String::IsOneByteRepresentation().

Referenced by Match().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ word_character_map_address()

static Address v8::internal::NativeRegExpMacroAssembler::word_character_map_address ( )
inlinestatic

Definition at line 220 of file regexp-macro-assembler.h.

220  {
221  return const_cast<Address>(&word_character_map[0]);
222  }

References word_character_map.

Member Data Documentation

◆ word_character_map

const byte v8::internal::NativeRegExpMacroAssembler::word_character_map
static

Definition at line 218 of file regexp-macro-assembler.h.

Referenced by word_character_map_address().


The documentation for this class was generated from the following files: