5 #include "src/compiler/node-cache.h" 9 #include "src/globals.h" 10 #include "src/zone/zone-containers.h" 11 #include "src/zone/zone.h" 19 enum { kInitialSize = 16u, kLinearProbe = 5u };
24 template <
typename Key,
typename Hash,
typename Pred>
31 template <
typename Key,
typename Hash,
typename Pred>
33 if (size_ >= max_)
return false;
36 Entry* old_entries = entries_;
37 size_t old_size = size_ + kLinearProbe;
39 size_t num_entries = size_ + kLinearProbe;
40 entries_ = zone->NewArray<
Entry>(num_entries);
41 memset(static_cast<void*>(entries_), 0,
sizeof(
Entry) * num_entries);
44 for (
size_t i = 0;
i < old_size; ++
i) {
45 Entry* old = &old_entries[
i];
47 size_t hash = hash_(old->key_);
48 size_t start = hash & (size_ - 1);
49 size_t end = start + kLinearProbe;
50 for (
size_t j = start; j < end; ++j) {
51 Entry* entry = &entries_[j];
53 entry->key_ = old->key_;
54 entry->value_ = old->value_;
64 template <
typename Key,
typename Hash,
typename Pred>
65 Node** NodeCache<Key, Hash, Pred>::Find(Zone* zone, Key key) {
66 size_t hash = hash_(key);
69 size_t num_entries = kInitialSize + kLinearProbe;
70 entries_ = zone->NewArray<Entry>(num_entries);
72 memset(static_cast<void*>(entries_), 0,
sizeof(Entry) * num_entries);
73 Entry* entry = &entries_[hash & (kInitialSize - 1)];
75 return &entry->value_;
80 size_t start = hash & (size_ - 1);
81 size_t end = start + kLinearProbe;
82 for (
size_t i = start;
i < end;
i++) {
83 Entry* entry = &entries_[
i];
84 if (pred_(entry->key_, key))
return &entry->value_;
87 return &entry->value_;
91 if (!Resize(zone))
break;
95 Entry* entry = &entries_[hash & (size_ - 1)];
97 entry->value_ =
nullptr;
98 return &entry->value_;
102 template <
typename Key,
typename Hash,
typename Pred>
103 void NodeCache<Key, Hash, Pred>::GetCachedNodes(ZoneVector<Node*>* nodes) {
105 for (
size_t i = 0;
i < size_ + kLinearProbe;
i++) {
106 if (entries_[
i].value_) nodes->push_back(entries_[
i].value_);
115 template class V8_EXPORT_PRIVATE NodeCache<int32_t>;
116 template class V8_EXPORT_PRIVATE NodeCache<int64_t>;
118 template class V8_EXPORT_PRIVATE NodeCache<RelocInt32Key>;
119 template class V8_EXPORT_PRIVATE NodeCache<RelocInt64Key>;