V8 Project
v8::internal::RegExpResultsCache Class Reference

#include <heap.h>

+ Collaboration diagram for v8::internal::RegExpResultsCache:

Public Types

enum  ResultsCacheType { REGEXP_MULTIPLE_INDICES , STRING_SPLIT_SUBSTRINGS }
 

Static Public Member Functions

static ObjectLookup (Heap *heap, String *key_string, Object *key_pattern, ResultsCacheType type)
 
static void Enter (Isolate *isolate, Handle< String > key_string, Handle< Object > key_pattern, Handle< FixedArray > value_array, ResultsCacheType type)
 
static void Clear (FixedArray *cache)
 

Static Public Attributes

static const int kRegExpResultsCacheSize = 0x100
 

Static Private Attributes

static const int kArrayEntriesPerCacheEntry = 4
 
static const int kStringOffset = 0
 
static const int kPatternOffset = 1
 
static const int kArrayOffset = 2
 

Detailed Description

Definition at line 2366 of file heap.h.

Member Enumeration Documentation

◆ ResultsCacheType

Enumerator
REGEXP_MULTIPLE_INDICES 
STRING_SPLIT_SUBSTRINGS 

Definition at line 2368 of file heap.h.

Member Function Documentation

◆ Clear()

void v8::internal::RegExpResultsCache::Clear ( FixedArray cache)
static

Definition at line 3031 of file heap.cc.

3031  {
3032  for (int i = 0; i < kRegExpResultsCacheSize; i++) {
3033  cache->set(i, Smi::FromInt(0));
3034  }
3035 }
static const int kRegExpResultsCacheSize
Definition: heap.h:2380
static Smi * FromInt(int value)
Definition: objects-inl.h:1321

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

Referenced by v8::internal::Heap::MarkCompactPrologue().

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

◆ Enter()

void v8::internal::RegExpResultsCache::Enter ( Isolate isolate,
Handle< String key_string,
Handle< Object key_pattern,
Handle< FixedArray value_array,
ResultsCacheType  type 
)
static

Definition at line 2977 of file heap.cc.

2980  {
2981  Factory* factory = isolate->factory();
2982  Handle<FixedArray> cache;
2983  if (!key_string->IsInternalizedString()) return;
2984  if (type == STRING_SPLIT_SUBSTRINGS) {
2985  DCHECK(key_pattern->IsString());
2986  if (!key_pattern->IsInternalizedString()) return;
2987  cache = factory->string_split_cache();
2988  } else {
2990  DCHECK(key_pattern->IsFixedArray());
2991  cache = factory->regexp_multiple_cache();
2992  }
2993 
2994  uint32_t hash = key_string->Hash();
2995  uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
2997  if (cache->get(index + kStringOffset) == Smi::FromInt(0)) {
2998  cache->set(index + kStringOffset, *key_string);
2999  cache->set(index + kPatternOffset, *key_pattern);
3000  cache->set(index + kArrayOffset, *value_array);
3001  } else {
3002  uint32_t index2 =
3004  if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) {
3005  cache->set(index2 + kStringOffset, *key_string);
3006  cache->set(index2 + kPatternOffset, *key_pattern);
3007  cache->set(index2 + kArrayOffset, *value_array);
3008  } else {
3009  cache->set(index2 + kStringOffset, Smi::FromInt(0));
3010  cache->set(index2 + kPatternOffset, Smi::FromInt(0));
3011  cache->set(index2 + kArrayOffset, Smi::FromInt(0));
3012  cache->set(index + kStringOffset, *key_string);
3013  cache->set(index + kPatternOffset, *key_pattern);
3014  cache->set(index + kArrayOffset, *value_array);
3015  }
3016  }
3017  // If the array is a reasonably short list of substrings, convert it into a
3018  // list of internalized strings.
3019  if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) {
3020  for (int i = 0; i < value_array->length(); i++) {
3021  Handle<String> str(String::cast(value_array->get(i)), isolate);
3022  Handle<String> internalized_str = factory->InternalizeString(str);
3023  value_array->set(i, *internalized_str);
3024  }
3025  }
3026  // Convert backing store to a copy-on-write array.
3027  value_array->set_map_no_write_barrier(*factory->fixed_cow_array_map());
3028 }
static const int kStringOffset
Definition: heap.h:2384
static const int kPatternOffset
Definition: heap.h:2385
static const int kArrayEntriesPerCacheEntry
Definition: heap.h:2383
static const int kArrayOffset
Definition: heap.h:2386
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, v8::internal::Isolate::factory(), v8::internal::Smi::FromInt(), kArrayEntriesPerCacheEntry, kArrayOffset, kPatternOffset, kRegExpResultsCacheSize, kStringOffset, REGEXP_MULTIPLE_INDICES, and STRING_SPLIT_SUBSTRINGS.

Referenced by v8::internal::RUNTIME_FUNCTION(), and v8::internal::SearchRegExpMultiple().

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

◆ Lookup()

Object * v8::internal::RegExpResultsCache::Lookup ( Heap heap,
String key_string,
Object key_pattern,
ResultsCacheType  type 
)
static

Definition at line 2946 of file heap.cc.

2947  {
2948  FixedArray* cache;
2949  if (!key_string->IsInternalizedString()) return Smi::FromInt(0);
2950  if (type == STRING_SPLIT_SUBSTRINGS) {
2951  DCHECK(key_pattern->IsString());
2952  if (!key_pattern->IsInternalizedString()) return Smi::FromInt(0);
2953  cache = heap->string_split_cache();
2954  } else {
2956  DCHECK(key_pattern->IsFixedArray());
2957  cache = heap->regexp_multiple_cache();
2958  }
2959 
2960  uint32_t hash = key_string->Hash();
2961  uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
2963  if (cache->get(index + kStringOffset) == key_string &&
2964  cache->get(index + kPatternOffset) == key_pattern) {
2965  return cache->get(index + kArrayOffset);
2966  }
2967  index =
2969  if (cache->get(index + kStringOffset) == key_string &&
2970  cache->get(index + kPatternOffset) == key_pattern) {
2971  return cache->get(index + kArrayOffset);
2972  }
2973  return Smi::FromInt(0);
2974 }

References DCHECK, v8::internal::Smi::FromInt(), v8::internal::FixedArray::get(), v8::internal::Name::Hash(), kArrayEntriesPerCacheEntry, kArrayOffset, kPatternOffset, kRegExpResultsCacheSize, kStringOffset, REGEXP_MULTIPLE_INDICES, and STRING_SPLIT_SUBSTRINGS.

Referenced by v8::internal::RUNTIME_FUNCTION(), and v8::internal::SearchRegExpMultiple().

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

Member Data Documentation

◆ kArrayEntriesPerCacheEntry

const int v8::internal::RegExpResultsCache::kArrayEntriesPerCacheEntry = 4
staticprivate

Definition at line 2383 of file heap.h.

Referenced by Enter(), and Lookup().

◆ kArrayOffset

const int v8::internal::RegExpResultsCache::kArrayOffset = 2
staticprivate

Definition at line 2386 of file heap.h.

Referenced by Enter(), and Lookup().

◆ kPatternOffset

const int v8::internal::RegExpResultsCache::kPatternOffset = 1
staticprivate

Definition at line 2385 of file heap.h.

Referenced by Enter(), and Lookup().

◆ kRegExpResultsCacheSize

const int v8::internal::RegExpResultsCache::kRegExpResultsCacheSize = 0x100
static

Definition at line 2380 of file heap.h.

Referenced by Clear(), v8::internal::Heap::CreateInitialObjects(), Enter(), and Lookup().

◆ kStringOffset

const int v8::internal::RegExpResultsCache::kStringOffset = 0
staticprivate

Definition at line 2384 of file heap.h.

Referenced by Enter(), and Lookup().


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