V8 Project
v8::internal::RegExpImpl Class Reference

#include <jsregexp.h>

+ Collaboration diagram for v8::internal::RegExpImpl:

Classes

class  GlobalCache
 

Public Types

enum  IrregexpResult { RE_FAILURE = 0 , RE_SUCCESS = 1 , RE_EXCEPTION = -1 }
 

Static Public Member Functions

static bool UsesNativeRegExp ()
 
static MUST_USE_RESULT MaybeHandle< ObjectCreateRegExpLiteral (Handle< JSFunction > constructor, Handle< String > pattern, Handle< String > flags)
 
static Handle< StringToString (Handle< Object > value)
 
static MUST_USE_RESULT MaybeHandle< ObjectCompile (Handle< JSRegExp > re, Handle< String > pattern, Handle< String > flags)
 
static MUST_USE_RESULT MaybeHandle< ObjectExec (Handle< JSRegExp > regexp, Handle< String > subject, int index, Handle< JSArray > lastMatchInfo)
 
static void IrregexpInitialize (Handle< JSRegExp > re, Handle< String > pattern, JSRegExp::Flags flags, int capture_register_count)
 
static void AtomCompile (Handle< JSRegExp > re, Handle< String > pattern, JSRegExp::Flags flags, Handle< String > match_pattern)
 
static int AtomExecRaw (Handle< JSRegExp > regexp, Handle< String > subject, int index, int32_t *output, int output_size)
 
static Handle< ObjectAtomExec (Handle< JSRegExp > regexp, Handle< String > subject, int index, Handle< JSArray > lastMatchInfo)
 
static int IrregexpPrepare (Handle< JSRegExp > regexp, Handle< String > subject)
 
static int IrregexpExecRaw (Handle< JSRegExp > regexp, Handle< String > subject, int index, int32_t *output, int output_size)
 
static MUST_USE_RESULT MaybeHandle< ObjectIrregexpExec (Handle< JSRegExp > regexp, Handle< String > subject, int index, Handle< JSArray > lastMatchInfo)
 
static Handle< JSArraySetLastMatchInfo (Handle< JSArray > last_match_info, Handle< String > subject, int capture_count, int32_t *match)
 
static int GetCapture (FixedArray *array, int index)
 
static void SetLastCaptureCount (FixedArray *array, int to)
 
static void SetLastSubject (FixedArray *array, String *to)
 
static void SetLastInput (FixedArray *array, String *to)
 
static void SetCapture (FixedArray *array, int index, int to)
 
static int GetLastCaptureCount (FixedArray *array)
 
static int IrregexpMaxRegisterCount (FixedArray *re)
 
static void SetIrregexpMaxRegisterCount (FixedArray *re, int value)
 
static int IrregexpNumberOfCaptures (FixedArray *re)
 
static int IrregexpNumberOfRegisters (FixedArray *re)
 
static ByteArrayIrregexpByteCode (FixedArray *re, bool is_one_byte)
 
static CodeIrregexpNativeCode (FixedArray *re, bool is_one_byte)
 

Static Public Attributes

static const int kLastCaptureCount = 0
 
static const int kLastSubject = 1
 
static const int kLastInput = 2
 
static const int kFirstCapture = 3
 
static const int kLastMatchOverhead = 3
 
static const int kLastCaptureCountOffset
 
static const int kLastSubjectOffset
 
static const int kLastInputOffset
 
static const int kFirstCaptureOffset
 
static const int kRegExpExecutableMemoryLimit = 16 * MB
 
static const int kRegWxpCompiledLimit = 1 * MB
 

Static Private Member Functions

static bool CompileIrregexp (Handle< JSRegExp > re, Handle< String > sample_subject, bool is_one_byte)
 
static bool EnsureCompiledIrregexp (Handle< JSRegExp > re, Handle< String > sample_subject, bool is_one_byte)
 

Detailed Description

Definition at line 22 of file jsregexp.h.

Member Enumeration Documentation

◆ IrregexpResult

Enumerator
RE_FAILURE 
RE_SUCCESS 
RE_EXCEPTION 

Definition at line 87 of file jsregexp.h.

Member Function Documentation

◆ AtomCompile()

void v8::internal::RegExpImpl::AtomCompile ( Handle< JSRegExp re,
Handle< String pattern,
JSRegExp::Flags  flags,
Handle< String match_pattern 
)
static

Definition at line 245 of file jsregexp.cc.

248  {
249  re->GetIsolate()->factory()->SetRegExpAtomData(re,
251  pattern,
252  flags,
253  match_pattern);
254 }

References v8::internal::JSRegExp::ATOM, and v8::internal::anonymous_namespace{flags.cc}::flags.

Referenced by Compile().

+ Here is the caller graph for this function:

◆ AtomExec()

Handle< Object > v8::internal::RegExpImpl::AtomExec ( Handle< JSRegExp regexp,
Handle< String subject,
int  index,
Handle< JSArray lastMatchInfo 
)
static

Definition at line 322 of file jsregexp.cc.

325  {
326  Isolate* isolate = re->GetIsolate();
327 
328  static const int kNumRegisters = 2;
330  int32_t* output_registers = isolate->jsregexp_static_offsets_vector();
331 
332  int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters);
333 
334  if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value();
335 
337  SealHandleScope shs(isolate);
338  FixedArray* array = FixedArray::cast(last_match_info->elements());
339  SetAtomLastCapture(array, *subject, output_registers[0], output_registers[1]);
340  return last_match_info;
341 }
static const int kJSRegexpStaticOffsetsVectorSize
Definition: isolate.h:984
static int AtomExecRaw(Handle< JSRegExp > regexp, Handle< String > subject, int index, int32_t *output, int output_size)
Definition: jsregexp.cc:270
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
int int32_t
Definition: unicode.cc:24
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
static void SetAtomLastCapture(FixedArray *array, String *subject, int from, int to)
Definition: jsregexp.cc:257
const int kNumRegisters
Definition: constants-arm.h:34

References AtomExecRaw(), DCHECK_EQ, v8::internal::Isolate::factory(), v8::internal::Isolate::kJSRegexpStaticOffsetsVectorSize, v8::internal::kNumRegisters, RE_FAILURE, RE_SUCCESS, v8::internal::SetAtomLastCapture(), and v8::internal::STATIC_ASSERT().

Referenced by Exec().

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

◆ AtomExecRaw()

int v8::internal::RegExpImpl::AtomExecRaw ( Handle< JSRegExp regexp,
Handle< String subject,
int  index,
int32_t *  output,
int  output_size 
)
static

Definition at line 270 of file jsregexp.cc.

274  {
275  Isolate* isolate = regexp->GetIsolate();
276 
277  DCHECK(0 <= index);
278  DCHECK(index <= subject->length());
279 
280  subject = String::Flatten(subject);
281  DisallowHeapAllocation no_gc; // ensure vectors stay valid
282 
283  String* needle = String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex));
284  int needle_len = needle->length();
285  DCHECK(needle->IsFlat());
286  DCHECK_LT(0, needle_len);
287 
288  if (index + needle_len > subject->length()) {
289  return RegExpImpl::RE_FAILURE;
290  }
291 
292  for (int i = 0; i < output_size; i += 2) {
293  String::FlatContent needle_content = needle->GetFlatContent();
294  String::FlatContent subject_content = subject->GetFlatContent();
295  DCHECK(needle_content.IsFlat());
296  DCHECK(subject_content.IsFlat());
297  // dispatch on type of strings
298  index =
299  (needle_content.IsOneByte()
300  ? (subject_content.IsOneByte()
301  ? SearchString(isolate, subject_content.ToOneByteVector(),
302  needle_content.ToOneByteVector(), index)
303  : SearchString(isolate, subject_content.ToUC16Vector(),
304  needle_content.ToOneByteVector(), index))
305  : (subject_content.IsOneByte()
306  ? SearchString(isolate, subject_content.ToOneByteVector(),
307  needle_content.ToUC16Vector(), index)
308  : SearchString(isolate, subject_content.ToUC16Vector(),
309  needle_content.ToUC16Vector(), index)));
310  if (index == -1) {
311  return i / 2; // Return number of matches.
312  } else {
313  output[i] = index;
314  output[i+1] = index + needle_len;
315  index += needle_len;
316  }
317  }
318  return output_size / 2;
319 }
static const int kAtomPatternIndex
Definition: objects.h:7782
static Handle< String > Flatten(Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
Definition: objects-inl.h:3354
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_LT(v1, v2)
Definition: logging.h:209
int SearchString(Isolate *isolate, Vector< const SubjectChar > subject, Vector< const PatternChar > pattern, int start_index)
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110

References DCHECK, DCHECK_LT, v8::internal::String::Flatten(), v8::internal::String::GetFlatContent(), v8::internal::String::FlatContent::IsFlat(), v8::internal::String::IsFlat(), v8::internal::String::FlatContent::IsOneByte(), v8::internal::JSRegExp::kAtomPatternIndex, v8::internal::String::length(), RE_FAILURE, v8::internal::SearchString(), v8::internal::String::FlatContent::ToOneByteVector(), and v8::internal::String::FlatContent::ToUC16Vector().

Referenced by AtomExec().

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

◆ Compile()

MaybeHandle< Object > v8::internal::RegExpImpl::Compile ( Handle< JSRegExp re,
Handle< String pattern,
Handle< String flags 
)
static

Definition at line 156 of file jsregexp.cc.

158  {
159  Isolate* isolate = re->GetIsolate();
160  Zone zone(isolate);
161  JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
162  CompilationCache* compilation_cache = isolate->compilation_cache();
163  MaybeHandle<FixedArray> maybe_cached =
164  compilation_cache->LookupRegExp(pattern, flags);
165  Handle<FixedArray> cached;
166  bool in_cache = maybe_cached.ToHandle(&cached);
167  LOG(isolate, RegExpCompileEvent(re, in_cache));
168 
169  Handle<Object> result;
170  if (in_cache) {
171  re->set_data(*cached);
172  return re;
173  }
174  pattern = String::Flatten(pattern);
175  PostponeInterruptsScope postpone(isolate);
176  RegExpCompileData parse_result;
177  FlatStringReader reader(isolate, pattern);
178  if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(),
179  &parse_result, &zone)) {
180  // Throw an exception if we fail to parse the pattern.
181  return ThrowRegExpException(re,
182  pattern,
183  parse_result.error,
184  "malformed_regexp");
185  }
186 
187  bool has_been_compiled = false;
188 
189  if (parse_result.simple &&
190  !flags.is_ignore_case() &&
191  !flags.is_sticky() &&
192  !HasFewDifferentCharacters(pattern)) {
193  // Parse-tree is a single atom that is equal to the pattern.
194  AtomCompile(re, pattern, flags, pattern);
195  has_been_compiled = true;
196  } else if (parse_result.tree->IsAtom() &&
197  !flags.is_ignore_case() &&
198  !flags.is_sticky() &&
199  parse_result.capture_count == 0) {
200  RegExpAtom* atom = parse_result.tree->AsAtom();
201  Vector<const uc16> atom_pattern = atom->data();
202  Handle<String> atom_string;
204  isolate, atom_string,
205  isolate->factory()->NewStringFromTwoByte(atom_pattern),
206  Object);
207  if (!HasFewDifferentCharacters(atom_string)) {
208  AtomCompile(re, pattern, flags, atom_string);
209  has_been_compiled = true;
210  }
211  }
212  if (!has_been_compiled) {
213  IrregexpInitialize(re, pattern, flags, parse_result.capture_count);
214  }
215  DCHECK(re->data()->IsFixedArray());
216  // Compilation succeeded so the data is set on the regexp
217  // and we can store it in the cache.
218  Handle<FixedArray> data(FixedArray::cast(re->data()));
219  compilation_cache->PutRegExp(pattern, flags, data);
220 
221  return re;
222 }
static void AtomCompile(Handle< JSRegExp > re, Handle< String > pattern, JSRegExp::Flags flags, Handle< String > match_pattern)
Definition: jsregexp.cc:245
static void IrregexpInitialize(Handle< JSRegExp > re, Handle< String > pattern, JSRegExp::Flags flags, int capture_register_count)
Definition: jsregexp.cc:490
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)
Definition: isolate.h:135
#define LOG(isolate, Call)
Definition: log.h:69
kSerializedDataOffset Object
Definition: objects-inl.h:5322
static bool HasFewDifferentCharacters(Handle< String > pattern)
Definition: jsregexp.cc:132
static JSRegExp::Flags RegExpFlagsFromString(Handle< String > str)
Definition: jsregexp.cc:60
static MUST_USE_RESULT MaybeHandle< Object > ThrowRegExpException(Handle< JSRegExp > re, Handle< String > pattern, Handle< String > error_text, const char *message)
Definition: jsregexp.cc:83

References ASSIGN_RETURN_ON_EXCEPTION, AtomCompile(), v8::internal::RegExpCompileData::capture_count, v8::internal::Isolate::compilation_cache(), DCHECK, v8::internal::RegExpCompileData::error, v8::internal::Isolate::factory(), v8::internal::anonymous_namespace{flags.cc}::flags, v8::internal::String::Flatten(), v8::internal::HasFewDifferentCharacters(), IrregexpInitialize(), LOG, v8::internal::CompilationCache::LookupRegExp(), v8::internal::CompilationCache::PutRegExp(), v8::internal::RegExpFlagsFromString(), v8::internal::RegExpCompileData::simple, v8::internal::ThrowRegExpException(), and v8::internal::RegExpCompileData::tree.

Referenced by v8::internal::RUNTIME_FUNCTION().

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

◆ CompileIrregexp()

bool v8::internal::RegExpImpl::CompileIrregexp ( Handle< JSRegExp re,
Handle< String sample_subject,
bool  is_one_byte 
)
staticprivate

Definition at line 389 of file jsregexp.cc.

391  {
392  // Compile the RegExp.
393  Isolate* isolate = re->GetIsolate();
394  Zone zone(isolate);
395  PostponeInterruptsScope postpone(isolate);
396  // If we had a compilation error the last time this is saved at the
397  // saved code index.
398  Object* entry = re->DataAt(JSRegExp::code_index(is_one_byte));
399  // When arriving here entry can only be a smi, either representing an
400  // uncompiled regexp, a previous compilation error, or code that has
401  // been flushed.
402  DCHECK(entry->IsSmi());
403  int entry_value = Smi::cast(entry)->value();
404  DCHECK(entry_value == JSRegExp::kUninitializedValue ||
405  entry_value == JSRegExp::kCompilationErrorValue ||
406  (entry_value < JSRegExp::kCodeAgeMask && entry_value >= 0));
407 
408  if (entry_value == JSRegExp::kCompilationErrorValue) {
409  // A previous compilation failed and threw an error which we store in
410  // the saved code index (we store the error message, not the actual
411  // error). Recreate the error object and throw it.
412  Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_one_byte));
413  DCHECK(error_string->IsString());
414  Handle<String> error_message(String::cast(error_string));
415  CreateRegExpErrorObjectAndThrow(re, error_message, isolate);
416  return false;
417  }
418 
419  JSRegExp::Flags flags = re->GetFlags();
420 
421  Handle<String> pattern(re->Pattern());
422  pattern = String::Flatten(pattern);
423  RegExpCompileData compile_data;
424  FlatStringReader reader(isolate, pattern);
425  if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(),
426  &compile_data,
427  &zone)) {
428  // Throw an exception if we fail to parse the pattern.
429  // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once.
431  pattern,
432  compile_data.error,
433  "malformed_regexp"));
434  return false;
435  }
436  RegExpEngine::CompilationResult result = RegExpEngine::Compile(
437  &compile_data, flags.is_ignore_case(), flags.is_global(),
438  flags.is_multiline(), flags.is_sticky(), pattern, sample_subject,
439  is_one_byte, &zone);
440  if (result.error_message != NULL) {
441  // Unable to compile regexp.
442  Handle<String> error_message = isolate->factory()->NewStringFromUtf8(
443  CStrVector(result.error_message)).ToHandleChecked();
444  CreateRegExpErrorObjectAndThrow(re, error_message, isolate);
445  return false;
446  }
447 
448  Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data()));
449  data->set(JSRegExp::code_index(is_one_byte), result.code);
450  int register_max = IrregexpMaxRegisterCount(*data);
451  if (result.num_registers > register_max) {
452  SetIrregexpMaxRegisterCount(*data, result.num_registers);
453  }
454 
455  return true;
456 }
static const int kUninitializedValue
Definition: objects.h:7829
static const int kCompilationErrorValue
Definition: objects.h:7833
static int saved_code_index(bool is_latin1)
Definition: objects.h:7758
static int code_index(bool is_latin1)
Definition: objects.h:7750
static CompilationResult Compile(RegExpCompileData *input, bool ignore_case, bool global, bool multiline, bool sticky, Handle< String > pattern, Handle< String > sample_subject, bool is_one_byte, Zone *zone)
Definition: jsregexp.cc:6034
static void SetIrregexpMaxRegisterCount(FixedArray *re, int value)
Definition: jsregexp.cc:465
static int IrregexpMaxRegisterCount(FixedArray *re)
Definition: jsregexp.cc:459
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
void USE(T)
Definition: macros.h:322
Vector< const char > CStrVector(const char *data)
Definition: vector.h:158
static void CreateRegExpErrorObjectAndThrow(Handle< JSRegExp > re, Handle< String > error_message, Isolate *isolate)
Definition: jsregexp.cc:374

References v8::internal::RegExpEngine::CompilationResult::code, v8::internal::JSRegExp::code_index(), v8::internal::RegExpEngine::Compile(), v8::internal::CreateRegExpErrorObjectAndThrow(), v8::internal::CStrVector(), DCHECK, v8::internal::RegExpCompileData::error, v8::internal::RegExpEngine::CompilationResult::error_message, v8::internal::Isolate::factory(), v8::internal::anonymous_namespace{flags.cc}::flags, v8::internal::String::Flatten(), IrregexpMaxRegisterCount(), v8::internal::JSRegExp::kCompilationErrorValue, v8::internal::JSRegExp::kUninitializedValue, NULL, v8::internal::RegExpEngine::CompilationResult::num_registers, v8::internal::JSRegExp::saved_code_index(), SetIrregexpMaxRegisterCount(), v8::internal::ThrowRegExpException(), and USE().

Referenced by EnsureCompiledIrregexp().

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

◆ CreateRegExpLiteral()

MaybeHandle< Object > v8::internal::RegExpImpl::CreateRegExpLiteral ( Handle< JSFunction constructor,
Handle< String pattern,
Handle< String flags 
)
static

Definition at line 50 of file jsregexp.cc.

53  {
54  // Call the construct code with 2 arguments.
55  Handle<Object> argv[] = { pattern, flags };
56  return Execution::New(constructor, arraysize(argv), argv);
57 }
#define arraysize(array)
Definition: macros.h:86

References arraysize, and v8::internal::anonymous_namespace{flags.cc}::flags.

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the caller graph for this function:

◆ EnsureCompiledIrregexp()

bool v8::internal::RegExpImpl::EnsureCompiledIrregexp ( Handle< JSRegExp re,
Handle< String sample_subject,
bool  is_one_byte 
)
inlinestaticprivate

Definition at line 352 of file jsregexp.cc.

354  {
355  Object* compiled_code = re->DataAt(JSRegExp::code_index(is_one_byte));
356 #ifdef V8_INTERPRETED_REGEXP
357  if (compiled_code->IsByteArray()) return true;
358 #else // V8_INTERPRETED_REGEXP (RegExp native code)
359  if (compiled_code->IsCode()) return true;
360 #endif
361  // We could potentially have marked this as flushable, but have kept
362  // a saved version if we did not flush it yet.
363  Object* saved_code = re->DataAt(JSRegExp::saved_code_index(is_one_byte));
364  if (saved_code->IsCode()) {
365  // Reinstate the code in the original place.
366  re->SetDataAt(JSRegExp::code_index(is_one_byte), saved_code);
367  DCHECK(compiled_code->IsSmi());
368  return true;
369  }
370  return CompileIrregexp(re, sample_subject, is_one_byte);
371 }
static bool CompileIrregexp(Handle< JSRegExp > re, Handle< String > sample_subject, bool is_one_byte)
Definition: jsregexp.cc:389

References v8::internal::JSRegExp::code_index(), CompileIrregexp(), DCHECK, and v8::internal::JSRegExp::saved_code_index().

Referenced by IrregexpExecRaw(), and IrregexpPrepare().

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

◆ Exec()

MaybeHandle< Object > v8::internal::RegExpImpl::Exec ( Handle< JSRegExp regexp,
Handle< String subject,
int  index,
Handle< JSArray lastMatchInfo 
)
static

Definition at line 225 of file jsregexp.cc.

228  {
229  switch (regexp->TypeTag()) {
230  case JSRegExp::ATOM:
231  return AtomExec(regexp, subject, index, last_match_info);
232  case JSRegExp::IRREGEXP: {
233  return IrregexpExec(regexp, subject, index, last_match_info);
234  }
235  default:
236  UNREACHABLE();
237  return MaybeHandle<Object>();
238  }
239 }
static MUST_USE_RESULT MaybeHandle< Object > IrregexpExec(Handle< JSRegExp > regexp, Handle< String > subject, int index, Handle< JSArray > lastMatchInfo)
Definition: jsregexp.cc:614
static Handle< Object > AtomExec(Handle< JSRegExp > regexp, Handle< String > subject, int index, Handle< JSArray > lastMatchInfo)
Definition: jsregexp.cc:322
#define UNREACHABLE()
Definition: logging.h:30

References v8::internal::JSRegExp::ATOM, AtomExec(), v8::internal::JSRegExp::IRREGEXP, IrregexpExec(), and UNREACHABLE.

Referenced by v8::internal::RUNTIME_FUNCTION().

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

◆ GetCapture()

static int v8::internal::RegExpImpl::GetCapture ( FixedArray array,
int  index 
)
inlinestatic

Definition at line 178 of file jsregexp.h.

178  {
179  return Smi::cast(array->get(index + kFirstCapture))->value();
180  }
static const int kFirstCapture
Definition: jsregexp.h:164

References v8::internal::FixedArray::get(), and kFirstCapture.

+ Here is the call graph for this function:

◆ GetLastCaptureCount()

static int v8::internal::RegExpImpl::GetLastCaptureCount ( FixedArray array)
inlinestatic

Definition at line 198 of file jsregexp.h.

198  {
199  return Smi::cast(array->get(kLastCaptureCount))->value();
200  }
static const int kLastCaptureCount
Definition: jsregexp.h:161

References v8::internal::FixedArray::get(), and kLastCaptureCount.

+ Here is the call graph for this function:

◆ IrregexpByteCode()

ByteArray * v8::internal::RegExpImpl::IrregexpByteCode ( FixedArray re,
bool  is_one_byte 
)
static

Definition at line 480 of file jsregexp.cc.

480  {
481  return ByteArray::cast(re->get(JSRegExp::code_index(is_one_byte)));
482 }

References v8::internal::JSRegExp::code_index(), and v8::internal::FixedArray::get().

Referenced by IrregexpExecRaw().

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

◆ IrregexpExec()

MaybeHandle< Object > v8::internal::RegExpImpl::IrregexpExec ( Handle< JSRegExp regexp,
Handle< String subject,
int  index,
Handle< JSArray lastMatchInfo 
)
static

Definition at line 614 of file jsregexp.cc.

617  {
618  Isolate* isolate = regexp->GetIsolate();
619  DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
620 
621  // Prepare space for the return values.
622 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG)
623  if (FLAG_trace_regexp_bytecodes) {
624  String* pattern = regexp->Pattern();
625  PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get());
626  PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get());
627  }
628 #endif
629  int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
630  if (required_registers < 0) {
631  // Compiling failed with an exception.
632  DCHECK(isolate->has_pending_exception());
633  return MaybeHandle<Object>();
634  }
635 
636  int32_t* output_registers = NULL;
637  if (required_registers > Isolate::kJSRegexpStaticOffsetsVectorSize) {
638  output_registers = NewArray<int32_t>(required_registers);
639  }
640  SmartArrayPointer<int32_t> auto_release(output_registers);
641  if (output_registers == NULL) {
642  output_registers = isolate->jsregexp_static_offsets_vector();
643  }
644 
645  int res = RegExpImpl::IrregexpExecRaw(
646  regexp, subject, previous_index, output_registers, required_registers);
647  if (res == RE_SUCCESS) {
648  int capture_count =
649  IrregexpNumberOfCaptures(FixedArray::cast(regexp->data()));
650  return SetLastMatchInfo(
651  last_match_info, subject, capture_count, output_registers);
652  }
653  if (res == RE_EXCEPTION) {
654  DCHECK(isolate->has_pending_exception());
655  return MaybeHandle<Object>();
656  }
657  DCHECK(res == RE_FAILURE);
658  return isolate->factory()->null_value();
659 }
static Handle< JSArray > SetLastMatchInfo(Handle< JSArray > last_match_info, Handle< String > subject, int capture_count, int32_t *match)
Definition: jsregexp.cc:662
static int IrregexpPrepare(Handle< JSRegExp > regexp, Handle< String > subject)
Definition: jsregexp.cc:503
static int IrregexpExecRaw(Handle< JSRegExp > regexp, Handle< String > subject, int index, int32_t *output, int output_size)
Definition: jsregexp.cc:526
static int IrregexpNumberOfCaptures(FixedArray *re)
Definition: jsregexp.cc:470
void PrintF(const char *format,...)
Definition: utils.cc:80

References DCHECK, DCHECK_EQ, v8::internal::Isolate::factory(), v8::internal::Isolate::has_pending_exception(), v8::internal::JSRegExp::IRREGEXP, IrregexpExecRaw(), IrregexpNumberOfCaptures(), IrregexpPrepare(), v8::internal::Isolate::kJSRegexpStaticOffsetsVectorSize, NULL, v8::internal::PrintF(), RE_EXCEPTION, RE_FAILURE, RE_SUCCESS, SetLastMatchInfo(), and v8::internal::String::ToCString().

Referenced by Exec().

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

◆ IrregexpExecRaw()

int v8::internal::RegExpImpl::IrregexpExecRaw ( Handle< JSRegExp regexp,
Handle< String subject,
int  index,
int32_t *  output,
int  output_size 
)
static

Definition at line 526 of file jsregexp.cc.

530  {
531  Isolate* isolate = regexp->GetIsolate();
532 
533  Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate);
534 
535  DCHECK(index >= 0);
536  DCHECK(index <= subject->length());
537  DCHECK(subject->IsFlat());
538 
539  bool is_one_byte = subject->IsOneByteRepresentationUnderneath();
540 
541 #ifndef V8_INTERPRETED_REGEXP
542  DCHECK(output_size >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2);
543  do {
544  EnsureCompiledIrregexp(regexp, subject, is_one_byte);
545  Handle<Code> code(IrregexpNativeCode(*irregexp, is_one_byte), isolate);
546  // The stack is used to allocate registers for the compiled regexp code.
547  // This means that in case of failure, the output registers array is left
548  // untouched and contains the capture results from the previous successful
549  // match. We can use that to set the last match info lazily.
552  subject,
553  output,
554  output_size,
555  index,
556  isolate);
559  isolate->has_pending_exception());
561  static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS);
563  static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE);
565  == RE_EXCEPTION);
566  return static_cast<IrregexpResult>(res);
567  }
568  // If result is RETRY, the string has changed representation, and we
569  // must restart from scratch.
570  // In this case, it means we must make sure we are prepared to handle
571  // the, potentially, different subject (the string can switch between
572  // being internal and external, and even between being Latin1 and UC16,
573  // but the characters are always the same).
574  IrregexpPrepare(regexp, subject);
575  is_one_byte = subject->IsOneByteRepresentationUnderneath();
576  } while (true);
577  UNREACHABLE();
578  return RE_EXCEPTION;
579 #else // V8_INTERPRETED_REGEXP
580 
581  DCHECK(output_size >= IrregexpNumberOfRegisters(*irregexp));
582  // We must have done EnsureCompiledIrregexp, so we can get the number of
583  // registers.
584  int number_of_capture_registers =
585  (IrregexpNumberOfCaptures(*irregexp) + 1) * 2;
586  int32_t* raw_output = &output[number_of_capture_registers];
587  // We do not touch the actual capture result registers until we know there
588  // has been a match so that we can use those capture results to set the
589  // last match info.
590  for (int i = number_of_capture_registers - 1; i >= 0; i--) {
591  raw_output[i] = -1;
592  }
593  Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_one_byte),
594  isolate);
595 
597  byte_codes,
598  subject,
599  raw_output,
600  index);
601  if (result == RE_SUCCESS) {
602  // Copy capture results to the start of the registers array.
603  MemCopy(output, raw_output, number_of_capture_registers * sizeof(int32_t));
604  }
605  if (result == RE_EXCEPTION) {
606  DCHECK(!isolate->has_pending_exception());
607  isolate->StackOverflow();
608  }
609  return result;
610 #endif // V8_INTERPRETED_REGEXP
611 }
static RegExpImpl::IrregexpResult Match(Isolate *isolate, Handle< ByteArray > code, Handle< String > subject, int *captures, int start_position)
static Result Match(Handle< Code > regexp, Handle< String > subject, int *offsets_vector, int offsets_vector_length, int previous_index, Isolate *isolate)
static ByteArray * IrregexpByteCode(FixedArray *re, bool is_one_byte)
Definition: jsregexp.cc:480
static Code * IrregexpNativeCode(FixedArray *re, bool is_one_byte)
Definition: jsregexp.cc:485
static int IrregexpNumberOfRegisters(FixedArray *re)
Definition: jsregexp.cc:475
static bool EnsureCompiledIrregexp(Handle< JSRegExp > re, Handle< String > sample_subject, bool is_one_byte)
Definition: jsregexp.cc:352
void MemCopy(void *dest, const void *src, size_t size)
Definition: utils.h:350

References DCHECK, EnsureCompiledIrregexp(), v8::internal::NativeRegExpMacroAssembler::EXCEPTION, v8::internal::NativeRegExpMacroAssembler::FAILURE, v8::internal::Isolate::has_pending_exception(), IrregexpByteCode(), IrregexpNativeCode(), IrregexpNumberOfCaptures(), IrregexpNumberOfRegisters(), IrregexpPrepare(), v8::internal::NativeRegExpMacroAssembler::Match(), v8::internal::IrregexpInterpreter::Match(), v8::internal::MemCopy(), RE_EXCEPTION, RE_FAILURE, RE_SUCCESS, v8::internal::NativeRegExpMacroAssembler::RETRY, v8::internal::Isolate::StackOverflow(), v8::internal::STATIC_ASSERT(), v8::internal::NativeRegExpMacroAssembler::SUCCESS, and UNREACHABLE.

Referenced by IrregexpExec().

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

◆ IrregexpInitialize()

void v8::internal::RegExpImpl::IrregexpInitialize ( Handle< JSRegExp re,
Handle< String pattern,
JSRegExp::Flags  flags,
int  capture_register_count 
)
static

Definition at line 490 of file jsregexp.cc.

493  {
494  // Initialize compiled code entries to null.
495  re->GetIsolate()->factory()->SetRegExpIrregexpData(re,
497  pattern,
498  flags,
499  capture_count);
500 }

References v8::internal::anonymous_namespace{flags.cc}::flags, and v8::internal::JSRegExp::IRREGEXP.

Referenced by Compile().

+ Here is the caller graph for this function:

◆ IrregexpMaxRegisterCount()

int v8::internal::RegExpImpl::IrregexpMaxRegisterCount ( FixedArray re)
static

Definition at line 459 of file jsregexp.cc.

459  {
460  return Smi::cast(
461  re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value();
462 }
static const int kIrregexpMaxRegisterCountIndex
Definition: objects.h:7804

References v8::internal::FixedArray::get(), and v8::internal::JSRegExp::kIrregexpMaxRegisterCountIndex.

Referenced by CompileIrregexp().

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

◆ IrregexpNativeCode()

Code * v8::internal::RegExpImpl::IrregexpNativeCode ( FixedArray re,
bool  is_one_byte 
)
static

Definition at line 485 of file jsregexp.cc.

485  {
486  return Code::cast(re->get(JSRegExp::code_index(is_one_byte)));
487 }

References v8::internal::JSRegExp::code_index(), and v8::internal::FixedArray::get().

Referenced by IrregexpExecRaw().

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

◆ IrregexpNumberOfCaptures()

int v8::internal::RegExpImpl::IrregexpNumberOfCaptures ( FixedArray re)
static

Definition at line 470 of file jsregexp.cc.

470  {
471  return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value();
472 }
static const int kIrregexpCaptureCountIndex
Definition: objects.h:7806

References v8::internal::FixedArray::get(), and v8::internal::JSRegExp::kIrregexpCaptureCountIndex.

Referenced by IrregexpExec(), IrregexpExecRaw(), and IrregexpPrepare().

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

◆ IrregexpNumberOfRegisters()

int v8::internal::RegExpImpl::IrregexpNumberOfRegisters ( FixedArray re)
static

Definition at line 475 of file jsregexp.cc.

475  {
476  return Smi::cast(re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value();
477 }

References v8::internal::FixedArray::get(), and v8::internal::JSRegExp::kIrregexpMaxRegisterCountIndex.

Referenced by IrregexpExecRaw(), and IrregexpPrepare().

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

◆ IrregexpPrepare()

int v8::internal::RegExpImpl::IrregexpPrepare ( Handle< JSRegExp regexp,
Handle< String subject 
)
static

Definition at line 503 of file jsregexp.cc.

504  {
505  subject = String::Flatten(subject);
506 
507  // Check representation of the underlying storage.
508  bool is_one_byte = subject->IsOneByteRepresentationUnderneath();
509  if (!EnsureCompiledIrregexp(regexp, subject, is_one_byte)) return -1;
510 
511 #ifdef V8_INTERPRETED_REGEXP
512  // Byte-code regexp needs space allocated for all its registers.
513  // The result captures are copied to the start of the registers array
514  // if the match succeeds. This way those registers are not clobbered
515  // when we set the last match info from last successful match.
516  return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())) +
517  (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2;
518 #else // V8_INTERPRETED_REGEXP
519  // Native regexp only needs room to output captures. Registers are handled
520  // internally.
521  return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2;
522 #endif // V8_INTERPRETED_REGEXP
523 }

References EnsureCompiledIrregexp(), v8::internal::String::Flatten(), IrregexpNumberOfCaptures(), and IrregexpNumberOfRegisters().

Referenced by v8::internal::RegExpImpl::GlobalCache::GlobalCache(), IrregexpExec(), and IrregexpExecRaw().

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

◆ SetCapture()

static void v8::internal::RegExpImpl::SetCapture ( FixedArray array,
int  index,
int  to 
)
inlinestatic

Definition at line 194 of file jsregexp.h.

194  {
195  array->set(index + kFirstCapture, Smi::FromInt(to));
196  }
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
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 expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file

References v8::internal::Smi::FromInt(), kFirstCapture, v8::internal::FixedArray::set(), and to().

Referenced by v8::internal::SetAtomLastCapture(), and SetLastMatchInfo().

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

◆ SetIrregexpMaxRegisterCount()

void v8::internal::RegExpImpl::SetIrregexpMaxRegisterCount ( FixedArray re,
int  value 
)
static

Definition at line 465 of file jsregexp.cc.

465  {
467 }

References v8::internal::Smi::FromInt(), v8::internal::JSRegExp::kIrregexpMaxRegisterCountIndex, and v8::internal::FixedArray::set().

Referenced by CompileIrregexp().

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

◆ SetLastCaptureCount()

static void v8::internal::RegExpImpl::SetLastCaptureCount ( FixedArray array,
int  to 
)
inlinestatic

Definition at line 182 of file jsregexp.h.

182  {
183  array->set(kLastCaptureCount, Smi::FromInt(to));
184  }

References v8::internal::Smi::FromInt(), kLastCaptureCount, v8::internal::FixedArray::set(), and to().

Referenced by v8::internal::SetAtomLastCapture(), and SetLastMatchInfo().

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

◆ SetLastInput()

static void v8::internal::RegExpImpl::SetLastInput ( FixedArray array,
String to 
)
inlinestatic

Definition at line 190 of file jsregexp.h.

190  {
191  array->set(kLastInput, to);
192  }
static const int kLastInput
Definition: jsregexp.h:163

References kLastInput, v8::internal::FixedArray::set(), and to().

Referenced by v8::internal::SetAtomLastCapture(), and SetLastMatchInfo().

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

◆ SetLastMatchInfo()

Handle< JSArray > v8::internal::RegExpImpl::SetLastMatchInfo ( Handle< JSArray last_match_info,
Handle< String subject,
int  capture_count,
int32_t *  match 
)
static

Definition at line 662 of file jsregexp.cc.

665  {
666  DCHECK(last_match_info->HasFastObjectElements());
667  int capture_register_count = (capture_count + 1) * 2;
668  JSArray::EnsureSize(last_match_info,
669  capture_register_count + kLastMatchOverhead);
670  DisallowHeapAllocation no_allocation;
671  FixedArray* array = FixedArray::cast(last_match_info->elements());
672  if (match != NULL) {
673  for (int i = 0; i < capture_register_count; i += 2) {
674  SetCapture(array, i, match[i]);
675  SetCapture(array, i + 1, match[i + 1]);
676  }
677  }
678  SetLastCaptureCount(array, capture_register_count);
679  SetLastSubject(array, *subject);
680  SetLastInput(array, *subject);
681  return last_match_info;
682 }
static void EnsureSize(Handle< JSArray > array, int minimum_size_of_backing_fixed_array)
Definition: objects-inl.h:6955
static void SetLastCaptureCount(FixedArray *array, int to)
Definition: jsregexp.h:182
static void SetLastSubject(FixedArray *array, String *to)
Definition: jsregexp.h:186
static const int kLastMatchOverhead
Definition: jsregexp.h:165
static void SetCapture(FixedArray *array, int index, int to)
Definition: jsregexp.h:194
static void SetLastInput(FixedArray *array, String *to)
Definition: jsregexp.h:190

References DCHECK, v8::internal::JSArray::EnsureSize(), kLastMatchOverhead, NULL, SetCapture(), SetLastCaptureCount(), SetLastInput(), and SetLastSubject().

Referenced by IrregexpExec(), v8::internal::RUNTIME_FUNCTION(), v8::internal::SearchRegExpMultiple(), v8::internal::StringReplaceGlobalAtomRegExpWithString(), v8::internal::StringReplaceGlobalRegExpWithEmptyString(), and v8::internal::StringReplaceGlobalRegExpWithString().

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

◆ SetLastSubject()

static void v8::internal::RegExpImpl::SetLastSubject ( FixedArray array,
String to 
)
inlinestatic

Definition at line 186 of file jsregexp.h.

186  {
187  array->set(kLastSubject, to);
188  }
static const int kLastSubject
Definition: jsregexp.h:162

References kLastSubject, v8::internal::FixedArray::set(), and to().

Referenced by v8::internal::SetAtomLastCapture(), and SetLastMatchInfo().

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

◆ ToString()

static Handle<String> v8::internal::RegExpImpl::ToString ( Handle< Object value)
static

◆ UsesNativeRegExp()

static bool v8::internal::RegExpImpl::UsesNativeRegExp ( )
inlinestatic

Definition at line 25 of file jsregexp.h.

25  {
26 #ifdef V8_INTERPRETED_REGEXP
27  return false;
28 #else
29  return true;
30 #endif
31  }

Member Data Documentation

◆ kFirstCapture

const int v8::internal::RegExpImpl::kFirstCapture = 3
static

Definition at line 164 of file jsregexp.h.

Referenced by GetCapture(), and SetCapture().

◆ kFirstCaptureOffset

const int v8::internal::RegExpImpl::kFirstCaptureOffset
static
Initial value:

Definition at line 174 of file jsregexp.h.

◆ kLastCaptureCount

const int v8::internal::RegExpImpl::kLastCaptureCount = 0
static

Definition at line 161 of file jsregexp.h.

Referenced by GetLastCaptureCount(), and SetLastCaptureCount().

◆ kLastCaptureCountOffset

const int v8::internal::RegExpImpl::kLastCaptureCountOffset
static
Initial value:

Definition at line 168 of file jsregexp.h.

◆ kLastInput

const int v8::internal::RegExpImpl::kLastInput = 2
static

Definition at line 163 of file jsregexp.h.

Referenced by SetLastInput().

◆ kLastInputOffset

const int v8::internal::RegExpImpl::kLastInputOffset
static
Initial value:

Definition at line 172 of file jsregexp.h.

◆ kLastMatchOverhead

const int v8::internal::RegExpImpl::kLastMatchOverhead = 3
static

Definition at line 165 of file jsregexp.h.

Referenced by SetLastMatchInfo().

◆ kLastSubject

const int v8::internal::RegExpImpl::kLastSubject = 1
static

Definition at line 162 of file jsregexp.h.

Referenced by SetLastSubject().

◆ kLastSubjectOffset

const int v8::internal::RegExpImpl::kLastSubjectOffset
static
Initial value:

Definition at line 170 of file jsregexp.h.

◆ kRegExpExecutableMemoryLimit

const int v8::internal::RegExpImpl::kRegExpExecutableMemoryLimit = 16 * MB
static

Definition at line 215 of file jsregexp.h.

Referenced by v8::internal::RegExpCompiler::Assemble().

◆ kRegWxpCompiledLimit

const int v8::internal::RegExpImpl::kRegWxpCompiledLimit = 1 * MB
static

Definition at line 216 of file jsregexp.h.

Referenced by v8::internal::RegExpCompiler::Assemble().


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