V8 Project
v8::internal::BoyerMooreLookahead Class Reference

#include <jsregexp.h>

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

Public Member Functions

 BoyerMooreLookahead (int length, RegExpCompiler *compiler, Zone *zone)
 
int length ()
 
int max_char ()
 
RegExpCompilercompiler ()
 
int Count (int map_number)
 
BoyerMoorePositionInfoat (int i)
 
void Set (int map_number, int character)
 
void SetInterval (int map_number, const Interval &interval)
 
void SetAll (int map_number)
 
void SetRest (int from_map)
 
void EmitSkipInstructions (RegExpMacroAssembler *masm)
 
- Public Member Functions inherited from v8::internal::ZoneObject
 INLINE (void *operator new(size_t size, Zone *zone))
 
void operator delete (void *, size_t)
 
void operator delete (void *pointer, Zone *zone)
 

Private Member Functions

int GetSkipTable (int min_lookahead, int max_lookahead, Handle< ByteArray > boolean_skip_table)
 
bool FindWorthwhileInterval (int *from, int *to)
 
int FindBestInterval (int max_number_of_chars, int old_biggest_points, int *from, int *to)
 

Private Attributes

int length_
 
RegExpCompilercompiler_
 
int max_char_
 
ZoneList< BoyerMoorePositionInfo * > * bitmaps_
 

Detailed Description

Definition at line 1286 of file jsregexp.h.

Constructor & Destructor Documentation

◆ BoyerMooreLookahead()

v8::internal::BoyerMooreLookahead::BoyerMooreLookahead ( int  length,
RegExpCompiler compiler,
Zone zone 
)

Definition at line 3633 of file jsregexp.cc.

3635  : length_(length),
3636  compiler_(compiler) {
3637  if (compiler->one_byte()) {
3639  } else {
3641  }
3642  bitmaps_ = new(zone) ZoneList<BoyerMoorePositionInfo*>(length, zone);
3643  for (int i = 0; i < length; i++) {
3644  bitmaps_->Add(new(zone) BoyerMoorePositionInfo(zone), zone);
3645  }
3646 }
ZoneList< BoyerMoorePositionInfo * > * bitmaps_
Definition: jsregexp.h:1334
RegExpCompiler * compiler()
Definition: jsregexp.h:1292
static const int32_t kMaxOneByteCharCode
Definition: objects.h:8811
static const int kMaxUtf16CodeUnit
Definition: objects.h:8813

References bitmaps_, compiler(), v8::internal::String::kMaxOneByteCharCode, v8::internal::String::kMaxUtf16CodeUnit, length(), max_char_, and v8::internal::RegExpCompiler::one_byte().

+ Here is the call graph for this function:

Member Function Documentation

◆ at()

BoyerMoorePositionInfo* v8::internal::BoyerMooreLookahead::at ( int  i)
inline

Definition at line 1298 of file jsregexp.h.

1298 { return bitmaps_->at(i); }

References bitmaps_.

Referenced by v8::internal::AssertionNode::EmitBoundaryCheck().

+ Here is the caller graph for this function:

◆ compiler()

RegExpCompiler* v8::internal::BoyerMooreLookahead::compiler ( )
inline

Definition at line 1292 of file jsregexp.h.

1292 { return compiler_; }

References compiler_.

Referenced by BoyerMooreLookahead(), and v8::internal::TextNode::FillInBMInfo().

+ Here is the caller graph for this function:

◆ Count()

int v8::internal::BoyerMooreLookahead::Count ( int  map_number)
inline

Definition at line 1294 of file jsregexp.h.

1294  {
1295  return bitmaps_->at(map_number)->map_count();
1296  }

References bitmaps_.

Referenced by FindBestInterval().

+ Here is the caller graph for this function:

◆ EmitSkipInstructions()

void v8::internal::BoyerMooreLookahead::EmitSkipInstructions ( RegExpMacroAssembler masm)

Definition at line 3754 of file jsregexp.cc.

3754  {
3755  const int kSize = RegExpMacroAssembler::kTableSize;
3756 
3757  int min_lookahead = 0;
3758  int max_lookahead = 0;
3759 
3760  if (!FindWorthwhileInterval(&min_lookahead, &max_lookahead)) return;
3761 
3762  bool found_single_character = false;
3763  int single_character = 0;
3764  for (int i = max_lookahead; i >= min_lookahead; i--) {
3765  BoyerMoorePositionInfo* map = bitmaps_->at(i);
3766  if (map->map_count() > 1 ||
3767  (found_single_character && map->map_count() != 0)) {
3768  found_single_character = false;
3769  break;
3770  }
3771  for (int j = 0; j < kSize; j++) {
3772  if (map->at(j)) {
3773  found_single_character = true;
3774  single_character = j;
3775  break;
3776  }
3777  }
3778  }
3779 
3780  int lookahead_width = max_lookahead + 1 - min_lookahead;
3781 
3782  if (found_single_character && lookahead_width == 1 && max_lookahead < 3) {
3783  // The mask-compare can probably handle this better.
3784  return;
3785  }
3786 
3787  if (found_single_character) {
3788  Label cont, again;
3789  masm->Bind(&again);
3790  masm->LoadCurrentCharacter(max_lookahead, &cont, true);
3791  if (max_char_ > kSize) {
3792  masm->CheckCharacterAfterAnd(single_character,
3794  &cont);
3795  } else {
3796  masm->CheckCharacter(single_character, &cont);
3797  }
3798  masm->AdvanceCurrentPosition(lookahead_width);
3799  masm->GoTo(&again);
3800  masm->Bind(&cont);
3801  return;
3802  }
3803 
3804  Factory* factory = masm->zone()->isolate()->factory();
3805  Handle<ByteArray> boolean_skip_table = factory->NewByteArray(kSize, TENURED);
3806  int skip_distance = GetSkipTable(
3807  min_lookahead, max_lookahead, boolean_skip_table);
3808  DCHECK(skip_distance != 0);
3809 
3810  Label cont, again;
3811  masm->Bind(&again);
3812  masm->LoadCurrentCharacter(max_lookahead, &cont, true);
3813  masm->CheckBitInTable(boolean_skip_table, &cont);
3814  masm->AdvanceCurrentPosition(skip_distance);
3815  masm->GoTo(&again);
3816  masm->Bind(&cont);
3817 }
int GetSkipTable(int min_lookahead, int max_lookahead, Handle< ByteArray > boolean_skip_table)
Definition: jsregexp.cc:3727
bool FindWorthwhileInterval(int *from, int *to)
Definition: jsregexp.cc:3652
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 map
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::RegExpMacroAssembler::AdvanceCurrentPosition(), v8::internal::RegExpMacroAssembler::Bind(), bitmaps_, v8::internal::RegExpMacroAssembler::CheckBitInTable(), v8::internal::RegExpMacroAssembler::CheckCharacter(), v8::internal::RegExpMacroAssembler::CheckCharacterAfterAnd(), DCHECK, v8::internal::Isolate::factory(), FindWorthwhileInterval(), GetSkipTable(), v8::internal::RegExpMacroAssembler::GoTo(), v8::internal::Zone::isolate(), v8::internal::RegExpMacroAssembler::kTableMask, v8::internal::RegExpMacroAssembler::kTableSize, v8::internal::RegExpMacroAssembler::LoadCurrentCharacter(), map, max_char_, v8::internal::TENURED, and v8::internal::RegExpMacroAssembler::zone().

Referenced by v8::internal::ChoiceNode::EmitOptimizedUnanchoredSearch().

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

◆ FindBestInterval()

int v8::internal::BoyerMooreLookahead::FindBestInterval ( int  max_number_of_chars,
int  old_biggest_points,
int from,
int to 
)
private

Definition at line 3674 of file jsregexp.cc.

3675  {
3676  int biggest_points = old_biggest_points;
3677  static const int kSize = RegExpMacroAssembler::kTableSize;
3678  for (int i = 0; i < length_; ) {
3679  while (i < length_ && Count(i) > max_number_of_chars) i++;
3680  if (i == length_) break;
3681  int remembered_from = i;
3682  bool union_map[kSize];
3683  for (int j = 0; j < kSize; j++) union_map[j] = false;
3684  while (i < length_ && Count(i) <= max_number_of_chars) {
3685  BoyerMoorePositionInfo* map = bitmaps_->at(i);
3686  for (int j = 0; j < kSize; j++) union_map[j] |= map->at(j);
3687  i++;
3688  }
3689  int frequency = 0;
3690  for (int j = 0; j < kSize; j++) {
3691  if (union_map[j]) {
3692  // Add 1 to the frequency to give a small per-character boost for
3693  // the cases where our sampling is not good enough and many
3694  // characters have a frequency of zero. This means the frequency
3695  // can theoretically be up to 2*kSize though we treat it mostly as
3696  // a fraction of kSize.
3697  frequency += compiler_->frequency_collator()->Frequency(j) + 1;
3698  }
3699  }
3700  // We use the probability of skipping times the distance we are skipping to
3701  // judge the effectiveness of this. Actually we have a cut-off: By
3702  // dividing by 2 we switch off the skipping if the probability of skipping
3703  // is less than 50%. This is because the multibyte mask-and-compare
3704  // skipping in quickcheck is more likely to do well on this case.
3705  bool in_quickcheck_range =
3706  ((i - remembered_from < 4) ||
3707  (compiler_->one_byte() ? remembered_from <= 4 : remembered_from <= 2));
3708  // Called 'probability' but it is only a rough estimate and can actually
3709  // be outside the 0-kSize range.
3710  int probability = (in_quickcheck_range ? kSize / 2 : kSize) - frequency;
3711  int points = (i - remembered_from) * probability;
3712  if (points > biggest_points) {
3713  *from = remembered_from;
3714  *to = i - 1;
3715  biggest_points = points;
3716  }
3717  }
3718  return biggest_points;
3719 }
int Count(int map_number)
Definition: jsregexp.h:1294
int Frequency(int in_character)
Definition: jsregexp.cc:962
FrequencyCollator * frequency_collator()
Definition: jsregexp.cc:1029
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 bitmaps_, compiler_, Count(), v8::internal::FrequencyCollator::Frequency(), v8::internal::RegExpCompiler::frequency_collator(), v8::internal::RegExpMacroAssembler::kTableSize, length_, map, v8::internal::RegExpCompiler::one_byte(), and to().

Referenced by FindWorthwhileInterval().

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

◆ FindWorthwhileInterval()

bool v8::internal::BoyerMooreLookahead::FindWorthwhileInterval ( int from,
int to 
)
private

Definition at line 3652 of file jsregexp.cc.

3652  {
3653  int biggest_points = 0;
3654  // If more than 32 characters out of 128 can occur it is unlikely that we can
3655  // be lucky enough to step forwards much of the time.
3656  const int kMaxMax = 32;
3657  for (int max_number_of_chars = 4;
3658  max_number_of_chars < kMaxMax;
3659  max_number_of_chars *= 2) {
3660  biggest_points =
3661  FindBestInterval(max_number_of_chars, biggest_points, from, to);
3662  }
3663  if (biggest_points == 0) return false;
3664  return true;
3665 }
int FindBestInterval(int max_number_of_chars, int old_biggest_points, int *from, int *to)
Definition: jsregexp.cc:3674

References FindBestInterval(), and to().

Referenced by EmitSkipInstructions().

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

◆ GetSkipTable()

int v8::internal::BoyerMooreLookahead::GetSkipTable ( int  min_lookahead,
int  max_lookahead,
Handle< ByteArray boolean_skip_table 
)
private

Definition at line 3727 of file jsregexp.cc.

3729  {
3730  const int kSize = RegExpMacroAssembler::kTableSize;
3731 
3732  const int kSkipArrayEntry = 0;
3733  const int kDontSkipArrayEntry = 1;
3734 
3735  for (int i = 0; i < kSize; i++) {
3736  boolean_skip_table->set(i, kSkipArrayEntry);
3737  }
3738  int skip = max_lookahead + 1 - min_lookahead;
3739 
3740  for (int i = max_lookahead; i >= min_lookahead; i--) {
3741  BoyerMoorePositionInfo* map = bitmaps_->at(i);
3742  for (int j = 0; j < kSize; j++) {
3743  if (map->at(j)) {
3744  boolean_skip_table->set(j, kDontSkipArrayEntry);
3745  }
3746  }
3747  }
3748 
3749  return skip;
3750 }

References bitmaps_, v8::internal::RegExpMacroAssembler::kTableSize, and map.

Referenced by EmitSkipInstructions().

+ Here is the caller graph for this function:

◆ length()

int v8::internal::BoyerMooreLookahead::length ( )
inline

Definition at line 1290 of file jsregexp.h.

1290 { return length_; }

References length_.

Referenced by BoyerMooreLookahead(), and v8::internal::TextNode::FillInBMInfo().

+ Here is the caller graph for this function:

◆ max_char()

int v8::internal::BoyerMooreLookahead::max_char ( )
inline

Definition at line 1291 of file jsregexp.h.

1291 { return max_char_; }

References max_char_.

Referenced by v8::internal::TextNode::FillInBMInfo().

+ Here is the caller graph for this function:

◆ Set()

void v8::internal::BoyerMooreLookahead::Set ( int  map_number,
int  character 
)
inline

Definition at line 1300 of file jsregexp.h.

1300  {
1301  if (character > max_char_) return;
1302  BoyerMoorePositionInfo* info = bitmaps_->at(map_number);
1303  info->Set(character);
1304  }

References bitmaps_, max_char_, and v8::internal::BoyerMoorePositionInfo::Set().

Referenced by v8::internal::TextNode::FillInBMInfo().

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

◆ SetAll()

void v8::internal::BoyerMooreLookahead::SetAll ( int  map_number)
inline

Definition at line 1316 of file jsregexp.h.

1316  {
1317  bitmaps_->at(map_number)->SetAll();
1318  }

References bitmaps_.

Referenced by v8::internal::TextNode::FillInBMInfo(), and SetRest().

+ Here is the caller graph for this function:

◆ SetInterval()

void v8::internal::BoyerMooreLookahead::SetInterval ( int  map_number,
const Interval interval 
)
inline

Definition at line 1306 of file jsregexp.h.

1306  {
1307  if (interval.from() > max_char_) return;
1308  BoyerMoorePositionInfo* info = bitmaps_->at(map_number);
1309  if (interval.to() > max_char_) {
1310  info->SetInterval(Interval(interval.from(), max_char_));
1311  } else {
1312  info->SetInterval(interval);
1313  }
1314  }

References bitmaps_, v8::internal::Interval::from(), max_char_, v8::internal::BoyerMoorePositionInfo::SetInterval(), and v8::internal::Interval::to().

Referenced by v8::internal::TextNode::FillInBMInfo().

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

◆ SetRest()

void v8::internal::BoyerMooreLookahead::SetRest ( int  from_map)
inline

Definition at line 1320 of file jsregexp.h.

1320  {
1321  for (int i = from_map; i < length_; i++) SetAll(i);
1322  }
void SetAll(int map_number)
Definition: jsregexp.h:1316

References length_, and SetAll().

Referenced by v8::internal::ActionNode::FillInBMInfo(), v8::internal::BackReferenceNode::FillInBMInfo(), v8::internal::ChoiceNode::FillInBMInfo(), and v8::internal::LoopChoiceNode::FillInBMInfo().

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

Member Data Documentation

◆ bitmaps_

ZoneList<BoyerMoorePositionInfo*>* v8::internal::BoyerMooreLookahead::bitmaps_
private

◆ compiler_

RegExpCompiler* v8::internal::BoyerMooreLookahead::compiler_
private

Definition at line 1331 of file jsregexp.h.

Referenced by compiler(), and FindBestInterval().

◆ length_

int v8::internal::BoyerMooreLookahead::length_
private

Definition at line 1330 of file jsregexp.h.

Referenced by FindBestInterval(), length(), and SetRest().

◆ max_char_

int v8::internal::BoyerMooreLookahead::max_char_
private

Definition at line 1333 of file jsregexp.h.

Referenced by BoyerMooreLookahead(), EmitSkipInstructions(), max_char(), Set(), and SetInterval().


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