Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/elements.h

Issue 1397063002: [runtime] Fancify KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: nits Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/elements.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ELEMENTS_H_ 5 #ifndef V8_ELEMENTS_H_
6 #define V8_ELEMENTS_H_ 6 #define V8_ELEMENTS_H_
7 7
8 #include "src/elements-kind.h" 8 #include "src/elements-kind.h"
9 #include "src/heap/heap.h" 9 #include "src/heap/heap.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
11 #include "src/objects.h" 11 #include "src/objects.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 // Abstract base class for handles that can operate on objects with differing 16 // Abstract base class for handles that can operate on objects with differing
17 // ElementsKinds. 17 // ElementsKinds.
18 class ElementsAccessor { 18 class ElementsAccessor {
19 public: 19 public:
20 explicit ElementsAccessor(const char* name) : name_(name) { } 20 explicit ElementsAccessor(const char* name) : name_(name) { }
21 virtual ~ElementsAccessor() { } 21 virtual ~ElementsAccessor() { }
22 22
23 const char* name() const { return name_; } 23 const char* name() const { return name_; }
24 24
25 // Returns a shared ElementsAccessor for the specified ElementsKind.
26 static ElementsAccessor* ForKind(ElementsKind elements_kind) {
27 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount);
28 return elements_accessors_[elements_kind];
29 }
30
31 static ElementsAccessor* ForArray(Handle<FixedArrayBase> array);
32
25 // Checks the elements of an object for consistency, asserting when a problem 33 // Checks the elements of an object for consistency, asserting when a problem
26 // is found. 34 // is found.
27 virtual void Validate(Handle<JSObject> obj) = 0; 35 virtual void Validate(Handle<JSObject> obj) = 0;
28 36
29 // Returns true if a holder contains an element with the specified index 37 // Returns true if a holder contains an element with the specified index
30 // without iterating up the prototype chain. The caller can optionally pass 38 // without iterating up the prototype chain. The caller can optionally pass
31 // in the backing store to use for the check, which must be compatible with 39 // in the backing store to use for the check, which must be compatible with
32 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the 40 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the
33 // holder->elements() is used as the backing store. 41 // holder->elements() is used as the backing store. If a |filter| is
42 // specified the PropertyAttributes of the element at the given index
43 // are compared to the given |filter|. If they match/overlap the given
44 // index is ignored. Note that only Dictionary elements have custom
45 // PropertyAttributes associated, hence the |filter| argument is ignored for
46 // all but DICTIONARY_ELEMENTS and SLOW_SLOPPY_ARGUMENTS_ELEMENTS.
34 virtual bool HasElement(Handle<JSObject> holder, uint32_t index, 47 virtual bool HasElement(Handle<JSObject> holder, uint32_t index,
35 Handle<FixedArrayBase> backing_store) = 0; 48 Handle<FixedArrayBase> backing_store,
49 PropertyAttributes filter = NONE) = 0;
36 50
37 inline bool HasElement(Handle<JSObject> holder, uint32_t index) { 51 inline bool HasElement(Handle<JSObject> holder, uint32_t index,
38 return HasElement(holder, index, handle(holder->elements())); 52 PropertyAttributes filter = NONE) {
53 return HasElement(holder, index, handle(holder->elements()), filter);
39 } 54 }
40 55
41 // Returns true if the backing store is compact in the given range 56 // Returns true if the backing store is compact in the given range
42 virtual bool IsPacked(Handle<JSObject> holder, 57 virtual bool IsPacked(Handle<JSObject> holder,
43 Handle<FixedArrayBase> backing_store, uint32_t start, 58 Handle<FixedArrayBase> backing_store, uint32_t start,
44 uint32_t end) = 0; 59 uint32_t end) = 0;
45 60
46 virtual Handle<Object> Get(Handle<FixedArrayBase> backing_store, 61 virtual Handle<Object> Get(Handle<FixedArrayBase> backing_store,
47 uint32_t entry) = 0; 62 uint32_t entry) = 0;
48 63
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 int copy_size) = 0; 105 int copy_size) = 0;
91 106
92 inline void CopyElements( 107 inline void CopyElements(
93 Handle<JSObject> from_holder, 108 Handle<JSObject> from_holder,
94 Handle<FixedArrayBase> to, 109 Handle<FixedArrayBase> to,
95 ElementsKind from_kind) { 110 ElementsKind from_kind) {
96 CopyElements( 111 CopyElements(
97 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole); 112 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole);
98 } 113 }
99 114
115 // Copy all indices that have elements from |object| into the given
116 // KeyAccumulator. For Dictionary-based element-kinds we filter out elements
117 // whose PropertyAttribute match |filter|.
118 virtual void CollectElementIndices(Handle<JSObject> object,
119 Handle<FixedArrayBase> backing_store,
120 KeyAccumulator* keys,
121 uint32_t range = kMaxUInt32,
122 PropertyAttributes filter = NONE,
123 uint32_t offset = 0) = 0;
124
125 inline void CollectElementIndices(Handle<JSObject> object,
126 KeyAccumulator* keys,
127 uint32_t range = kMaxUInt32,
128 PropertyAttributes filter = NONE,
129 uint32_t offset = 0) {
130 CollectElementIndices(object, handle(object->elements()), keys, range,
131 filter, offset);
132 }
133
134 virtual void AddElementsToKeyAccumulator(Handle<JSObject> receiver,
135 KeyAccumulator* accumulator,
136 AddKeyConversion convert) = 0;
137
100 virtual void GrowCapacityAndConvert(Handle<JSObject> object, 138 virtual void GrowCapacityAndConvert(Handle<JSObject> object,
101 uint32_t capacity) = 0; 139 uint32_t capacity) = 0;
102 140
103 virtual void AddElementsToKeyAccumulator(Handle<JSObject> receiver,
104 KeyAccumulator* accumulator,
105 KeyFilter filter) = 0;
106
107 // Returns a shared ElementsAccessor for the specified ElementsKind.
108 static ElementsAccessor* ForKind(ElementsKind elements_kind) {
109 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount);
110 return elements_accessors_[elements_kind];
111 }
112
113 static ElementsAccessor* ForArray(Handle<FixedArrayBase> array);
114
115 static void InitializeOncePerProcess(); 141 static void InitializeOncePerProcess();
116 static void TearDown(); 142 static void TearDown();
117 143
118 virtual void Set(FixedArrayBase* backing_store, uint32_t entry, 144 virtual void Set(FixedArrayBase* backing_store, uint32_t entry,
119 Object* value) = 0; 145 Object* value) = 0;
120 146
121 virtual void Reconfigure(Handle<JSObject> object, 147 virtual void Reconfigure(Handle<JSObject> object,
122 Handle<FixedArrayBase> backing_store, uint32_t entry, 148 Handle<FixedArrayBase> backing_store, uint32_t entry,
123 Handle<Object> value, 149 Handle<Object> value,
124 PropertyAttributes attributes) = 0; 150 PropertyAttributes attributes) = 0;
(...skipping 26 matching lines...) Expand all
151 Handle<FixedArrayBase> backing_store) = 0; 177 Handle<FixedArrayBase> backing_store) = 0;
152 178
153 virtual Handle<Object> Shift(Handle<JSArray> receiver, 179 virtual Handle<Object> Shift(Handle<JSArray> receiver,
154 Handle<FixedArrayBase> backing_store) = 0; 180 Handle<FixedArrayBase> backing_store) = 0;
155 181
156 protected: 182 protected:
157 friend class LookupIterator; 183 friend class LookupIterator;
158 184
159 static ElementsAccessor* ForArray(FixedArrayBase* array); 185 static ElementsAccessor* ForArray(FixedArrayBase* array);
160 186
161 virtual uint32_t GetCapacity(JSObject* holder,
162 FixedArrayBase* backing_store) = 0;
163 187
164 // Element handlers distinguish between entries and indices when they 188 // Element handlers distinguish between entries and indices when they
165 // manipulate elements. Entries refer to elements in terms of their location 189 // manipulate elements. Entries refer to elements in terms of their location
166 // in the underlying storage's backing store representation, and are between 0 190 // in the underlying storage's backing store representation, and are between 0
167 // and GetCapacity. Indices refer to elements in terms of the value that would 191 // and GetCapacity. Indices refer to elements in terms of the value that would
168 // be specified in JavaScript to access the element. In most implementations, 192 // be specified in JavaScript to access the element. In most implementations,
169 // indices are equivalent to entries. In the NumberDictionary 193 // indices are equivalent to entries. In the NumberDictionary
170 // ElementsAccessor, entries are mapped to an index using the KeyAt method on 194 // ElementsAccessor, entries are mapped to an index using the KeyAt method on
171 // the NumberDictionary. 195 // the NumberDictionary.
172 virtual uint32_t GetEntryForIndex(JSObject* holder, 196 virtual uint32_t GetEntryForIndex(JSObject* holder,
173 FixedArrayBase* backing_store, 197 FixedArrayBase* backing_store,
174 uint32_t index) = 0; 198 uint32_t index) = 0;
175 virtual PropertyDetails GetDetails(FixedArrayBase* backing_store, 199 virtual PropertyDetails GetDetails(FixedArrayBase* backing_store,
176 uint32_t entry) = 0; 200 uint32_t entry) = 0;
177 201
178 private: 202 private:
203 virtual uint32_t GetCapacity(JSObject* holder,
204 FixedArrayBase* backing_store) = 0;
179 static ElementsAccessor** elements_accessors_; 205 static ElementsAccessor** elements_accessors_;
180 const char* name_; 206 const char* name_;
181 207
182 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); 208 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor);
183 }; 209 };
184 210
185 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t index, 211 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t index,
186 bool allow_appending = false); 212 bool allow_appending = false);
187 213
188 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements( 214 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements(
189 Handle<JSArray> array, 215 Handle<JSArray> array,
190 Arguments* args); 216 Arguments* args);
191 217
192 } // namespace internal 218 } // namespace internal
193 } // namespace v8 219 } // namespace v8
194 220
195 #endif // V8_ELEMENTS_H_ 221 #endif // V8_ELEMENTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/elements.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698