V8 Project
v8::internal::TemplateHashMapImpl< AllocationPolicy > Class Template Reference

#include <hashmap.h>

+ Inheritance diagram for v8::internal::TemplateHashMapImpl< AllocationPolicy >:
+ Collaboration diagram for v8::internal::TemplateHashMapImpl< AllocationPolicy >:

Classes

struct  Entry
 

Public Types

typedef bool(* MatchFun) (void *key1, void *key2)
 

Public Member Functions

 TemplateHashMapImpl (MatchFun match, uint32_t capacity=kDefaultHashMapCapacity, AllocationPolicy allocator=AllocationPolicy())
 
 ~TemplateHashMapImpl ()
 
EntryLookup (void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
 
void * Remove (void *key, uint32_t hash)
 
void Clear ()
 
uint32_t occupancy () const
 
uint32_t capacity () const
 
EntryStart () const
 
EntryNext (Entry *p) const
 

Static Public Member Functions

static bool PointersMatch (void *key1, void *key2)
 

Static Public Attributes

static const uint32_t kDefaultHashMapCapacity = 8
 

Private Member Functions

Entrymap_end () const
 
EntryProbe (void *key, uint32_t hash)
 
void Initialize (uint32_t capacity, AllocationPolicy allocator)
 
void Resize (AllocationPolicy allocator)
 

Private Attributes

MatchFun match_
 
Entrymap_
 
uint32_t capacity_
 
uint32_t occupancy_
 

Detailed Description

template<class AllocationPolicy>
class v8::internal::TemplateHashMapImpl< AllocationPolicy >

Definition at line 17 of file hashmap.h.

Member Typedef Documentation

◆ MatchFun

template<class AllocationPolicy >
typedef bool(* v8::internal::TemplateHashMapImpl< AllocationPolicy >::MatchFun) (void *key1, void *key2)

Definition at line 19 of file hashmap.h.

Constructor & Destructor Documentation

◆ TemplateHashMapImpl()

Definition at line 99 of file hashmap.h.

100  {
101  match_ = match;
102  Initialize(initial_capacity, allocator);
103 }
void Initialize(uint32_t capacity, AllocationPolicy allocator)
Definition: hashmap.h:261

◆ ~TemplateHashMapImpl()

Definition at line 107 of file hashmap.h.

107  {
108  AllocationPolicy::Delete(map_);
109 }

Member Function Documentation

◆ capacity()

template<class AllocationPolicy >
uint32_t v8::internal::TemplateHashMapImpl< AllocationPolicy >::capacity ( ) const
inline

Definition at line 66 of file hashmap.h.

66 { return capacity_; }

References v8::internal::TemplateHashMapImpl< AllocationPolicy >::capacity_.

Referenced by v8::internal::HeapObjectsMap::GetUsedMemorySize(), and v8::internal::StringsStorage::GetUsedMemorySize().

+ Here is the caller graph for this function:

◆ Clear()

template<class AllocationPolicy >
void v8::internal::TemplateHashMapImpl< AllocationPolicy >::Clear

Definition at line 207 of file hashmap.h.

207  {
208  // Mark all entries as empty.
209  const Entry* end = map_end();
210  for (Entry* p = map_; p < end; p++) {
211  p->key = NULL;
212  }
213  occupancy_ = 0;
214 }
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 NULL.

Referenced by v8::internal::HeapObjectsSet::Clear(), and v8::internal::LargeObjectSpace::SetUp().

+ Here is the caller graph for this function:

◆ Initialize()

template<class AllocationPolicy >
void v8::internal::TemplateHashMapImpl< AllocationPolicy >::Initialize ( uint32_t  capacity,
AllocationPolicy  allocator 
)
private

Definition at line 261 of file hashmap.h.

262  {
264  map_ = reinterpret_cast<Entry*>(allocator.New(capacity * sizeof(Entry)));
265  if (map_ == NULL) {
266  v8::internal::FatalProcessOutOfMemory("HashMap::Initialize");
267  return;
268  }
270  Clear();
271 }
uint32_t capacity() const
Definition: hashmap.h:66
#define DCHECK(condition)
Definition: logging.h:205
bool IsPowerOfTwo32(uint32_t value)
Definition: bits.h:77
void FatalProcessOutOfMemory(const char *message)

References DCHECK, v8::internal::FatalProcessOutOfMemory(), v8::base::bits::IsPowerOfTwo32(), and NULL.

+ Here is the call graph for this function:

◆ Lookup()

template<class AllocationPolicy >
TemplateHashMapImpl< AllocationPolicy >::Entry * v8::internal::TemplateHashMapImpl< AllocationPolicy >::Lookup ( void *  key,
uint32_t  hash,
bool  insert,
AllocationPolicy  allocator = AllocationPolicy() 
)

Definition at line 114 of file hashmap.h.

115  {
116  // Find a matching entry.
117  Entry* p = Probe(key, hash);
118  if (p->key != NULL) {
119  return p;
120  }
121 
122  // No entry found; insert one if necessary.
123  if (insert) {
124  p->key = key;
125  p->value = NULL;
126  p->hash = hash;
127  p->order = occupancy_;
128  occupancy_++;
129 
130  // Grow the map if we reached >= 80% occupancy.
131  if (occupancy_ + occupancy_/4 >= capacity_) {
132  Resize(allocator);
133  p = Probe(key, hash);
134  }
135 
136  return p;
137  }
138 
139  // No entry found and none inserted.
140  return NULL;
141 }
void Resize(AllocationPolicy allocator)
Definition: hashmap.h:275
Entry * Probe(void *key, uint32_t hash)
Definition: hashmap.h:240

References v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::hash, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::key, NULL, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::order, and v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::value.

Referenced by v8::internal::AllocationTracker::AddFunctionInfo(), v8::internal::SerializationAddressMapper::AddMapping(), v8::internal::DuplicateFinder::AddSymbol(), v8::internal::LargeObjectSpace::AllocateRaw(), v8::internal::HeapObjectsSet::Contains(), v8::internal::Interface::DoAdd(), v8::internal::TemplateHashMap< Key, Value, AllocationPolicy >::find(), v8::internal::ProfileNode::FindChild(), v8::internal::HeapObjectsMap::FindEntry(), v8::internal::CodeAddressMap::NameMap::FindEntry(), v8::internal::ProfileNode::FindOrAddChild(), v8::internal::HeapObjectsMap::FindOrAddEntry(), v8::internal::NativeObjectsExplorer::FindOrAddGroupInfo(), v8::internal::CodeAddressMap::NameMap::FindOrCreateEntry(), v8::internal::LargeObjectSpace::FindPage(), v8::internal::HeapObjectsMap::FindUntrackedObjects(), v8::internal::StringsStorage::GetEntry(), v8::internal::NativeObjectsExplorer::GetListMaybeDisposeInfo(), v8::internal::AstValueFactory::GetString(), v8::internal::HeapSnapshotJSONSerializer::GetStringId(), v8::internal::HeapObjectsSet::GetTag(), v8::internal::ScriptCache::HandleWeakScript(), v8::internal::HeapObjectsSet::Insert(), v8::internal::SerializationAddressMapper::IsMapped(), v8::CounterMap::Lookup(), v8::internal::HeapEntriesMap::Map(), v8::internal::SerializationAddressMapper::MappedTo(), v8::internal::HeapObjectsMap::MoveObject(), v8::internal::HeapEntriesMap::Pair(), v8::internal::ExternalReferenceEncoder::Put(), v8::internal::HeapObjectsMap::RemoveDeadEntries(), v8::CounterMap::Set(), and v8::internal::HeapObjectsSet::SetTag().

+ Here is the caller graph for this function:

◆ map_end()

template<class AllocationPolicy >
Entry* v8::internal::TemplateHashMapImpl< AllocationPolicy >::map_end ( ) const
inlineprivate

◆ Next()

◆ occupancy()

◆ PointersMatch()

template<class AllocationPolicy >
static bool v8::internal::TemplateHashMapImpl< AllocationPolicy >::PointersMatch ( void *  key1,
void *  key2 
)
inlinestatic

Definition at line 80 of file hashmap.h.

80  {
81  return key1 == key2;
82  }

◆ Probe()

template<class AllocationPolicy >
TemplateHashMapImpl< AllocationPolicy >::Entry * v8::internal::TemplateHashMapImpl< AllocationPolicy >::Probe ( void *  key,
uint32_t  hash 
)
private

Definition at line 240 of file hashmap.h.

240  {
241  DCHECK(key != NULL);
242 
244  Entry* p = map_ + (hash & (capacity_ - 1));
245  const Entry* end = map_end();
246  DCHECK(map_ <= p && p < end);
247 
248  DCHECK(occupancy_ < capacity_); // Guarantees loop termination.
249  while (p->key != NULL && (hash != p->hash || !match_(key, p->key))) {
250  p++;
251  if (p >= end) {
252  p = map_;
253  }
254  }
255 
256  return p;
257 }

References DCHECK, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::hash, v8::base::bits::IsPowerOfTwo32(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::key, and NULL.

+ Here is the call graph for this function:

◆ Remove()

template<class AllocationPolicy >
void * v8::internal::TemplateHashMapImpl< AllocationPolicy >::Remove ( void *  key,
uint32_t  hash 
)

Definition at line 145 of file hashmap.h.

145  {
146  // Lookup the entry for the key to remove.
147  Entry* p = Probe(key, hash);
148  if (p->key == NULL) {
149  // Key not found nothing to remove.
150  return NULL;
151  }
152 
153  void* value = p->value;
154  // To remove an entry we need to ensure that it does not create an empty
155  // entry that will cause the search for another entry to stop too soon. If all
156  // the entries between the entry to remove and the next empty slot have their
157  // initial position inside this interval, clearing the entry to remove will
158  // not break the search. If, while searching for the next empty entry, an
159  // entry is encountered which does not have its initial position between the
160  // entry to remove and the position looked at, then this entry can be moved to
161  // the place of the entry to remove without breaking the search for it. The
162  // entry made vacant by this move is now the entry to remove and the process
163  // starts over.
164  // Algorithm from http://en.wikipedia.org/wiki/Open_addressing.
165 
166  // This guarantees loop termination as there is at least one empty entry so
167  // eventually the removed entry will have an empty entry after it.
169 
170  // p is the candidate entry to clear. q is used to scan forwards.
171  Entry* q = p; // Start at the entry to remove.
172  while (true) {
173  // Move q to the next entry.
174  q = q + 1;
175  if (q == map_end()) {
176  q = map_;
177  }
178 
179  // All entries between p and q have their initial position between p and q
180  // and the entry p can be cleared without breaking the search for these
181  // entries.
182  if (q->key == NULL) {
183  break;
184  }
185 
186  // Find the initial position for the entry at position q.
187  Entry* r = map_ + (q->hash & (capacity_ - 1));
188 
189  // If the entry at position q has its initial position outside the range
190  // between p and q it can be moved forward to position p and will still be
191  // found. There is now a new candidate entry for clearing.
192  if ((q > p && (r <= p || r > q)) ||
193  (q < p && (r <= p && r > q))) {
194  *p = *q;
195  p = q;
196  }
197  }
198 
199  // Clear the entry which is allowed to en emptied.
200  p->key = NULL;
201  occupancy_--;
202  return value;
203 }

References DCHECK, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::hash, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::key, NULL, and v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::value.

Referenced by v8::internal::LargeObjectSpace::FreeUnmarkedObjects(), v8::internal::ScriptCache::HandleWeakScript(), v8::internal::HeapObjectsMap::MoveObject(), v8::internal::HeapObjectsMap::RemoveDeadEntries(), and v8::internal::CodeAddressMap::NameMap::RemoveEntry().

+ Here is the caller graph for this function:

◆ Resize()

template<class AllocationPolicy >
void v8::internal::TemplateHashMapImpl< AllocationPolicy >::Resize ( AllocationPolicy  allocator)
private

Definition at line 275 of file hashmap.h.

275  {
276  Entry* map = map_;
277  uint32_t n = occupancy_;
278 
279  // Allocate larger map.
280  Initialize(capacity_ * 2, allocator);
281 
282  // Rehash all current entries.
283  for (Entry* p = map; n > 0; p++) {
284  if (p->key != NULL) {
285  Entry* entry = Lookup(p->key, p->hash, true, allocator);
286  entry->value = p->value;
287  entry->order = p->order;
288  n--;
289  }
290  }
291 
292  // Delete old map.
293  AllocationPolicy::Delete(map);
294 }
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
Definition: hashmap.h:114
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

References map, NULL, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::order, and v8::internal::TemplateHashMapImpl< AllocationPolicy >::Entry::value.

◆ Start()

Member Data Documentation

◆ capacity_

◆ kDefaultHashMapCapacity

template<class AllocationPolicy >
const uint32_t v8::internal::TemplateHashMapImpl< AllocationPolicy >::kDefaultHashMapCapacity = 8
static

Definition at line 24 of file hashmap.h.

◆ map_

template<class AllocationPolicy >
Entry* v8::internal::TemplateHashMapImpl< AllocationPolicy >::map_
private

◆ match_

template<class AllocationPolicy >
MatchFun v8::internal::TemplateHashMapImpl< AllocationPolicy >::match_
private

Definition at line 85 of file hashmap.h.

◆ occupancy_

template<class AllocationPolicy >
uint32_t v8::internal::TemplateHashMapImpl< AllocationPolicy >::occupancy_
private

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