v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
ordered-hash-table-inl.h
Go to the documentation of this file.
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
9// Include the non-inl header before the rest of the headers.
10
11#include "src/heap/heap.h"
16#include "src/objects/slots.h"
17
18// Has to be the last include (doesn't have include guards):
20
21namespace v8 {
22namespace internal {
23
24#include "torque-generated/src/objects/ordered-hash-table-tq-inl.inc"
25
26template <class Derived, int entrysize>
29 return k != roots.the_hole_value();
30}
31
32template <class Derived>
34 : HeapObject(ptr) {}
35
36template <class Derived>
38 InternalIndex entry) const {
39 DCHECK_LT(entry.as_int(), Capacity());
40 Offset entry_offset = GetDataEntryOffset(entry.as_int(), Derived::kKeyIndex);
41 return TaggedField<Object>::load(*this, entry_offset);
42}
43
44template <class Derived>
46 int entry, int relative_index) {
47 DCHECK_LT(entry, Capacity());
48 DCHECK_LE(static_cast<unsigned>(relative_index), Derived::kEntrySize);
49 Offset entry_offset = GetDataEntryOffset(entry, relative_index);
50 return TaggedField<Object>::load(*this, entry_offset);
51}
52
63
65 return roots.ordered_hash_map_map();
66}
67
69 return roots.ordered_name_dictionary_map();
70}
71
73 return roots.small_ordered_name_dictionary_map();
74}
75
77 return roots.small_ordered_hash_map_map();
78}
79
81 return roots.small_ordered_hash_set_map();
82}
83
88
97
98// Parameter |roots| only here for compatibility with HashTable<...>::ToKey.
99template <class Derived, int entrysize>
101 InternalIndex entry,
102 Tagged<Object>* out_key) {
103 Tagged<Object> k = KeyAt(entry);
104 if (!IsKey(roots, k)) return false;
105 *out_key = k;
106 return true;
107}
108
109// Set the value for entry.
111 Tagged<Object> value) {
112 DCHECK_LT(entry.as_int(), UsedCapacity());
113 this->set(EntryToIndex(entry) + kValueOffset, value);
114}
115
116// Returns the property details for the property at entry.
118 DCHECK_LT(entry.as_int(), this->UsedCapacity());
119 // TODO(gsathya): Optimize the cast away.
120 return PropertyDetails(
122}
123
125 PropertyDetails value) {
126 DCHECK_LT(entry.as_int(), this->UsedCapacity());
127 // TODO(gsathya): Optimize the cast away.
128 this->set(EntryToIndex(entry) + kPropertyDetailsOffset, value.AsSmi());
129}
130
135// Set the value for entry.
137 Tagged<Object> value) {
138 this->SetDataEntry(entry.as_int(), kValueIndex, value);
139}
140
141// Returns the property details for the property at entry.
143 InternalIndex entry) {
144 // TODO(gsathya): Optimize the cast away. And store this in the data table.
145 return PropertyDetails(
147}
148
149// Set the details for entry.
151 PropertyDetails value) {
152 // TODO(gsathya): Optimize the cast away. And store this in the data table.
153 this->SetDataEntry(entry.as_int(), kPropertyDetailsIndex, value.AsSmi());
154}
155
157 return IsOrderedHashSet(*table);
158}
159
161 return IsOrderedHashMap(*table);
162}
163
165 return IsOrderedNameDictionary(*table);
166}
167
169 return IsSmallOrderedHashSet(*table);
170}
171
173 return IsSmallOrderedNameDictionary(*table);
174}
175
177 return IsSmallOrderedHashMap(*table);
178}
179
180template <class Derived>
181void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
182 Tagged<Object> value) {
183 DCHECK_NE(kNotFound, entry);
184 int entry_offset = GetDataEntryOffset(entry, relative_index);
185 RELAXED_WRITE_FIELD(*this, entry_offset, value);
186 WRITE_BARRIER(*this, entry_offset, value);
187}
188
189template <class Derived, class TableType>
191 Tagged<TableType> table = Cast<TableType>(this->table());
192 int index = Smi::ToInt(this->index());
193 DCHECK_LE(0, index);
194 InternalIndex entry(index);
195 Tagged<Object> key = table->KeyAt(entry);
196 DCHECK(!IsHashTableHole(key));
197 return key;
198}
199
204
206 int hash = ReadField<int>(PrefixOffset());
208 return hash;
209}
210
211inline void OrderedNameDictionary::SetHash(int hash) {
213 this->set(HashIndex(), Smi::FromInt(hash));
214}
215
217 Tagged<Object> hash_obj = this->get(HashIndex());
218 int hash = Smi::ToInt(hash_obj);
220 return hash;
221}
222
223} // namespace internal
224} // namespace v8
225
227
228#endif // V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
static constexpr bool is_valid(T value)
Definition bit-field.h:50
T ReadField(size_t offset) const
void WriteField(size_t offset, T value) const
constexpr int as_int() const
static Handle< Map > GetMap(RootsTable &roots)
Tagged< Object > ValueAt(InternalIndex entry)
static bool Is(DirectHandle< HeapObject > table)
static bool Is(DirectHandle< HeapObject > table)
bool ToKey(ReadOnlyRoots roots, InternalIndex entry, Tagged< Object > *out_key)
static bool IsKey(ReadOnlyRoots roots, Tagged< Object > k)
Tagged< Object > ValueAt(InternalIndex entry)
void DetailsAtPut(InternalIndex entry, PropertyDetails value)
static Handle< Map > GetMap(RootsTable &roots)
void ValueAtPut(InternalIndex entry, Tagged< Object > value)
PropertyDetails DetailsAt(InternalIndex entry)
Tagged< Name > NameAt(InternalIndex entry)
static bool Is(DirectHandle< HeapObject > table)
static DirectHandle< Map > GetMap(RootsTable &roots)
static bool Is(DirectHandle< HeapObject > table)
static DirectHandle< Map > GetMap(RootsTable &roots)
static bool Is(DirectHandle< HeapObject > table)
V8_INLINE Tagged< Object > GetDataEntry(int entry, int relative_index)
V8_INLINE Tagged< Object > KeyAt(InternalIndex entry) const
void SetDataEntry(int entry, int relative_index, Tagged< Object > value)
static bool Is(DirectHandle< HeapObject > table)
PropertyDetails DetailsAt(InternalIndex entry)
void DetailsAtPut(InternalIndex entry, PropertyDetails value)
Tagged< Object > ValueAt(InternalIndex entry)
void ValueAtPut(InternalIndex entry, Tagged< Object > value)
static DirectHandle< Map > GetMap(RootsTable &roots)
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
void set(int index, Tagged< ElementT > value, WriteBarrierMode mode=kDefaultMode)
static PtrType load(Tagged< HeapObject > host, int offset=0)
constexpr AddrMode Offset
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define OBJECT_CONSTRUCTORS_IMPL(Type, Super)
#define WRITE_BARRIER(object, offset, value)
#define RELAXED_WRITE_FIELD(p, offset, value)
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489