Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
6 : #define V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
7 :
8 : #include "src/objects/ordered-hash-table.h"
9 :
10 : #include "src/heap/heap.h"
11 : #include "src/objects/fixed-array-inl.h"
12 :
13 : // Has to be the last include (doesn't have include guards):
14 : #include "src/objects/object-macros.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 :
19 3951535 : CAST_ACCESSOR(OrderedNameDictionary)
20 1296845 : CAST_ACCESSOR(SmallOrderedNameDictionary)
21 2860904 : CAST_ACCESSOR(OrderedHashMap)
22 13614351 : CAST_ACCESSOR(OrderedHashSet)
23 163380 : CAST_ACCESSOR(SmallOrderedHashMap)
24 163380 : CAST_ACCESSOR(SmallOrderedHashSet)
25 :
26 : template <class Derived, int entrysize>
27 : OrderedHashTable<Derived, entrysize>::OrderedHashTable(Address ptr)
28 : : FixedArray(ptr) {}
29 :
30 13614351 : OrderedHashSet::OrderedHashSet(Address ptr)
31 : : OrderedHashTable<OrderedHashSet, 1>(ptr) {
32 : SLOW_DCHECK(IsOrderedHashSet());
33 13614351 : }
34 :
35 2860904 : OrderedHashMap::OrderedHashMap(Address ptr)
36 : : OrderedHashTable<OrderedHashMap, 2>(ptr) {
37 : SLOW_DCHECK(IsOrderedHashMap());
38 2860904 : }
39 :
40 3951535 : OrderedNameDictionary::OrderedNameDictionary(Address ptr)
41 : : OrderedHashTable<OrderedNameDictionary, 3>(ptr) {
42 : SLOW_DCHECK(IsOrderedNameDictionary());
43 3951535 : }
44 :
45 : template <class Derived>
46 : SmallOrderedHashTable<Derived>::SmallOrderedHashTable(Address ptr)
47 : : HeapObject(ptr) {}
48 :
49 326760 : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashSet,
50 : SmallOrderedHashTable<SmallOrderedHashSet>)
51 326760 : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashMap,
52 : SmallOrderedHashTable<SmallOrderedHashMap>)
53 2593690 : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedNameDictionary,
54 : SmallOrderedHashTable<SmallOrderedNameDictionary>)
55 :
56 : RootIndex OrderedHashSet::GetMapRootIndex() {
57 : return RootIndex::kOrderedHashSetMap;
58 : }
59 :
60 : RootIndex OrderedHashMap::GetMapRootIndex() {
61 : return RootIndex::kOrderedHashMapMap;
62 : }
63 :
64 : RootIndex OrderedNameDictionary::GetMapRootIndex() {
65 : return RootIndex::kOrderedNameDictionaryMap;
66 : }
67 :
68 : RootIndex SmallOrderedNameDictionary::GetMapRootIndex() {
69 : return RootIndex::kSmallOrderedNameDictionaryMap;
70 : }
71 :
72 : RootIndex SmallOrderedHashMap::GetMapRootIndex() {
73 : return RootIndex::kSmallOrderedHashMapMap;
74 : }
75 :
76 : RootIndex SmallOrderedHashSet::GetMapRootIndex() {
77 : return RootIndex::kSmallOrderedHashSetMap;
78 : }
79 :
80 5395 : inline Object OrderedHashMap::ValueAt(int entry) {
81 : DCHECK_NE(entry, kNotFound);
82 : DCHECK_LT(entry, UsedCapacity());
83 16185 : return get(EntryToIndex(entry) + kValueOffset);
84 : }
85 :
86 35 : inline Object OrderedNameDictionary::ValueAt(int entry) {
87 : DCHECK_NE(entry, kNotFound);
88 : DCHECK_LT(entry, UsedCapacity());
89 105 : return get(EntryToIndex(entry) + kValueOffset);
90 : }
91 :
92 : // Set the value for entry.
93 10 : inline void OrderedNameDictionary::ValueAtPut(int entry, Object value) {
94 : DCHECK_NE(entry, kNotFound);
95 : DCHECK_LT(entry, UsedCapacity());
96 20 : this->set(EntryToIndex(entry) + kValueOffset, value);
97 10 : }
98 :
99 : // Returns the property details for the property at entry.
100 25 : inline PropertyDetails OrderedNameDictionary::DetailsAt(int entry) {
101 : DCHECK_NE(entry, kNotFound);
102 : DCHECK_LT(entry, this->UsedCapacity());
103 : // TODO(gsathya): Optimize the cast away.
104 : return PropertyDetails(
105 75 : Smi::cast(get(EntryToIndex(entry) + kPropertyDetailsOffset)));
106 : }
107 :
108 10 : inline void OrderedNameDictionary::DetailsAtPut(int entry,
109 : PropertyDetails value) {
110 : DCHECK_NE(entry, kNotFound);
111 : DCHECK_LT(entry, this->UsedCapacity());
112 : // TODO(gsathya): Optimize the cast away.
113 10 : this->set(EntryToIndex(entry) + kPropertyDetailsOffset, value.AsSmi());
114 10 : }
115 :
116 : inline Object SmallOrderedNameDictionary::ValueAt(int entry) {
117 : return this->GetDataEntry(entry, kValueIndex);
118 : }
119 :
120 : // Set the value for entry.
121 : inline void SmallOrderedNameDictionary::ValueAtPut(int entry, Object value) {
122 10 : this->SetDataEntry(entry, kValueIndex, value);
123 : }
124 :
125 : // Returns the property details for the property at entry.
126 1295 : inline PropertyDetails SmallOrderedNameDictionary::DetailsAt(int entry) {
127 : // TODO(gsathya): Optimize the cast away. And store this in the data table.
128 : return PropertyDetails(
129 1295 : Smi::cast(this->GetDataEntry(entry, kPropertyDetailsIndex)));
130 : }
131 :
132 : // Set the details for entry.
133 : inline void SmallOrderedNameDictionary::DetailsAtPut(int entry,
134 : PropertyDetails value) {
135 : // TODO(gsathya): Optimize the cast away. And store this in the data table.
136 10 : this->SetDataEntry(entry, kPropertyDetailsIndex, value.AsSmi());
137 : }
138 :
139 5 : inline bool OrderedHashSet::Is(Handle<HeapObject> table) {
140 10 : return table->IsOrderedHashSet();
141 : }
142 :
143 5 : inline bool OrderedHashMap::Is(Handle<HeapObject> table) {
144 10 : return table->IsOrderedHashMap();
145 : }
146 :
147 2624020 : inline bool SmallOrderedHashSet::Is(Handle<HeapObject> table) {
148 5248040 : return table->IsSmallOrderedHashSet();
149 : }
150 :
151 2624020 : inline bool SmallOrderedHashMap::Is(Handle<HeapObject> table) {
152 5248040 : return table->IsSmallOrderedHashMap();
153 : }
154 :
155 : template <class Derived>
156 51575 : void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
157 : Object value) {
158 : DCHECK_NE(kNotFound, entry);
159 : int entry_offset = GetDataEntryOffset(entry, relative_index);
160 51575 : RELAXED_WRITE_FIELD(*this, entry_offset, value);
161 103150 : WRITE_BARRIER(*this, entry_offset, value);
162 51575 : }
163 :
164 : template <class Derived, class TableType>
165 0 : Object OrderedHashTableIterator<Derived, TableType>::CurrentKey() {
166 0 : TableType table = TableType::cast(this->table());
167 0 : int index = Smi::ToInt(this->index());
168 0 : Object key = table->KeyAt(index);
169 : DCHECK(!key->IsTheHole());
170 0 : return key;
171 : }
172 :
173 : inline void SmallOrderedNameDictionary::SetHash(int hash) {
174 : DCHECK(PropertyArray::HashField::is_valid(hash));
175 370 : WRITE_INT_FIELD(*this, PrefixOffset(), hash);
176 : }
177 :
178 : inline int SmallOrderedNameDictionary::Hash() {
179 1440 : int hash = READ_INT_FIELD(*this, PrefixOffset());
180 : DCHECK(PropertyArray::HashField::is_valid(hash));
181 : return hash;
182 : }
183 :
184 : inline void OrderedNameDictionary::SetHash(int hash) {
185 : DCHECK(PropertyArray::HashField::is_valid(hash));
186 : this->set(PrefixIndex(), Smi::FromInt(hash));
187 : }
188 :
189 5250 : inline int OrderedNameDictionary::Hash() {
190 5250 : Object hash_obj = this->get(PrefixIndex());
191 5250 : int hash = Smi::ToInt(hash_obj);
192 : DCHECK(PropertyArray::HashField::is_valid(hash));
193 5250 : return hash;
194 : }
195 :
196 : } // namespace internal
197 : } // namespace v8
198 :
199 : #include "src/objects/object-macros-undef.h"
200 :
201 : #endif // V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
|