Line data Source code
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
3 : // found in the LICENSE file.
4 : //
5 : // Review notes:
6 : //
7 : // - The use of macros in these inline functions may seem superfluous
8 : // but it is absolutely needed to make sure gcc generates optimal
9 : // code. gcc is not happy when attempting to inline too deep.
10 : //
11 :
12 : #ifndef V8_OBJECTS_INL_H_
13 : #define V8_OBJECTS_INL_H_
14 :
15 : #include "src/base/atomicops.h"
16 : #include "src/base/bits.h"
17 : #include "src/base/tsan.h"
18 : #include "src/builtins/builtins.h"
19 : #include "src/contexts-inl.h"
20 : #include "src/conversions-inl.h"
21 : #include "src/factory.h"
22 : #include "src/feedback-vector-inl.h"
23 : #include "src/field-index-inl.h"
24 : #include "src/field-type.h"
25 : #include "src/handles-inl.h"
26 : #include "src/heap/heap-inl.h"
27 : #include "src/heap/heap.h"
28 : #include "src/isolate-inl.h"
29 : #include "src/isolate.h"
30 : #include "src/keys.h"
31 : #include "src/layout-descriptor-inl.h"
32 : #include "src/lookup-cache-inl.h"
33 : #include "src/lookup.h"
34 : #include "src/objects.h"
35 : #include "src/objects/arguments-inl.h"
36 : #include "src/objects/bigint-inl.h"
37 : #include "src/objects/hash-table-inl.h"
38 : #include "src/objects/hash-table.h"
39 : #include "src/objects/js-array-inl.h"
40 : #include "src/objects/js-regexp-inl.h"
41 : #include "src/objects/literal-objects.h"
42 : #include "src/objects/module-inl.h"
43 : #include "src/objects/regexp-match-info.h"
44 : #include "src/objects/scope-info.h"
45 : #include "src/objects/template-objects.h"
46 : #include "src/property.h"
47 : #include "src/prototype.h"
48 : #include "src/transitions-inl.h"
49 : #include "src/v8memory.h"
50 :
51 : // Has to be the last include (doesn't have include guards):
52 : #include "src/objects/object-macros.h"
53 :
54 : namespace v8 {
55 : namespace internal {
56 :
57 0 : PropertyDetails::PropertyDetails(Smi* smi) {
58 3502676201 : value_ = smi->value();
59 0 : }
60 :
61 :
62 180 : Smi* PropertyDetails::AsSmi() const {
63 : // Ensure the upper 2 bits have the same value by sign extending it. This is
64 : // necessary to be able to use the 31st bit of the property details.
65 841697673 : int value = value_ << 1;
66 841697853 : return Smi::FromInt(value >> 1);
67 : }
68 :
69 :
70 22337 : int PropertyDetails::field_width_in_words() const {
71 : DCHECK_EQ(location(), kField);
72 : if (!FLAG_unbox_double_fields) return 1;
73 : if (kDoubleSize == kPointerSize) return 1;
74 : return representation().IsDouble() ? kDoubleSize / kPointerSize : 1;
75 : }
76 :
77 17341 : TYPE_CHECKER(BreakPoint, TUPLE2_TYPE)
78 1417 : TYPE_CHECKER(BreakPointInfo, TUPLE2_TYPE)
79 19408691 : TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE)
80 202294 : TYPE_CHECKER(CallHandlerInfo, TUPLE2_TYPE)
81 11396810 : TYPE_CHECKER(Cell, CELL_TYPE)
82 648034 : TYPE_CHECKER(ConstantElementsPair, TUPLE2_TYPE)
83 : TYPE_CHECKER(CoverageInfo, FIXED_ARRAY_TYPE)
84 1288846 : TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE)
85 1530 : TYPE_CHECKER(Foreign, FOREIGN_TYPE)
86 149880 : TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE)
87 29546449 : TYPE_CHECKER(HashTable, HASH_TABLE_TYPE)
88 235830556 : TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE)
89 : TYPE_CHECKER(JSAsyncFromSyncIterator, JS_ASYNC_FROM_SYNC_ITERATOR_TYPE)
90 16680216 : TYPE_CHECKER(JSAsyncGeneratorObject, JS_ASYNC_GENERATOR_OBJECT_TYPE)
91 5364709 : TYPE_CHECKER(JSBoundFunction, JS_BOUND_FUNCTION_TYPE)
92 4933674 : TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE)
93 7016269 : TYPE_CHECKER(JSDataView, JS_DATA_VIEW_TYPE)
94 137830 : TYPE_CHECKER(JSDate, JS_DATE_TYPE)
95 6879388 : TYPE_CHECKER(JSError, JS_ERROR_TYPE)
96 141920603 : TYPE_CHECKER(JSFunction, JS_FUNCTION_TYPE)
97 221036021 : TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE)
98 570331 : TYPE_CHECKER(JSMap, JS_MAP_TYPE)
99 : TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
100 7722472 : TYPE_CHECKER(JSPromise, JS_PROMISE_TYPE)
101 442997 : TYPE_CHECKER(JSSet, JS_SET_TYPE)
102 : TYPE_CHECKER(JSStringIterator, JS_STRING_ITERATOR_TYPE)
103 2927071 : TYPE_CHECKER(JSValue, JS_VALUE_TYPE)
104 585028 : TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE)
105 541988 : TYPE_CHECKER(JSWeakSet, JS_WEAK_SET_TYPE)
106 513245739 : TYPE_CHECKER(Map, MAP_TYPE)
107 389885 : TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE)
108 61338196 : TYPE_CHECKER(Oddball, ODDBALL_TYPE)
109 611940 : TYPE_CHECKER(PreParsedScopeData, TUPLE2_TYPE)
110 23853603 : TYPE_CHECKER(PropertyArray, PROPERTY_ARRAY_TYPE)
111 9062032 : TYPE_CHECKER(PropertyCell, PROPERTY_CELL_TYPE)
112 : TYPE_CHECKER(SmallOrderedHashMap, SMALL_ORDERED_HASH_MAP_TYPE)
113 : TYPE_CHECKER(SmallOrderedHashSet, SMALL_ORDERED_HASH_SET_TYPE)
114 77587 : TYPE_CHECKER(SourcePositionTableWithFrameCache, TUPLE2_TYPE)
115 : TYPE_CHECKER(TemplateMap, HASH_TABLE_TYPE)
116 2310 : TYPE_CHECKER(TemplateObjectDescription, TUPLE3_TYPE)
117 403382434 : TYPE_CHECKER(TransitionArray, TRANSITION_ARRAY_TYPE)
118 : TYPE_CHECKER(TypeFeedbackInfo, TUPLE3_TYPE)
119 26433861 : TYPE_CHECKER(WasmInstanceObject, WASM_INSTANCE_TYPE)
120 7000 : TYPE_CHECKER(WasmMemoryObject, WASM_MEMORY_TYPE)
121 148358 : TYPE_CHECKER(WasmModuleObject, WASM_MODULE_TYPE)
122 26888 : TYPE_CHECKER(WasmTableObject, WASM_TABLE_TYPE)
123 101498334 : TYPE_CHECKER(WeakCell, WEAK_CELL_TYPE)
124 11807706 : TYPE_CHECKER(WeakFixedArray, FIXED_ARRAY_TYPE)
125 :
126 : #define TYPED_ARRAY_TYPE_CHECKER(Type, type, TYPE, ctype, size) \
127 : TYPE_CHECKER(Fixed##Type##Array, FIXED_##TYPE##_ARRAY_TYPE)
128 : TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER)
129 : #undef TYPED_ARRAY_TYPE_CHECKER
130 :
131 :
132 : bool HeapObject::IsFixedArrayBase() const {
133 : return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase();
134 : }
135 :
136 : bool HeapObject::IsFixedArray() const {
137 96066786 : InstanceType instance_type = map()->instance_type();
138 95882070 : return instance_type == FIXED_ARRAY_TYPE || instance_type == HASH_TABLE_TYPE;
139 : }
140 :
141 : bool HeapObject::IsSloppyArgumentsElements() const { return IsFixedArray(); }
142 :
143 : bool HeapObject::IsJSSloppyArgumentsObject() const {
144 : return IsJSArgumentsObject();
145 : }
146 :
147 : bool HeapObject::IsJSGeneratorObject() const {
148 33365788 : return map()->instance_type() == JS_GENERATOR_OBJECT_TYPE ||
149 : IsJSAsyncGeneratorObject();
150 : }
151 :
152 : bool HeapObject::IsBoilerplateDescription() const { return IsFixedArray(); }
153 :
154 : bool HeapObject::IsExternal() const {
155 221967 : return map()->FindRootMap() == GetHeap()->external_map();
156 : }
157 :
158 : #define IS_TYPE_FUNCTION_DEF(type_) \
159 : bool Object::Is##type_() const { \
160 : return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \
161 : }
162 5120234056 : HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF)
163 : #undef IS_TYPE_FUNCTION_DEF
164 :
165 : #define IS_TYPE_FUNCTION_DEF(Type, Value) \
166 : bool Object::Is##Type(Isolate* isolate) const { \
167 : return this == isolate->heap()->Value(); \
168 : } \
169 : bool HeapObject::Is##Type(Isolate* isolate) const { \
170 : return this == isolate->heap()->Value(); \
171 : }
172 1616660389 : ODDBALL_LIST(IS_TYPE_FUNCTION_DEF)
173 : #undef IS_TYPE_FUNCTION_DEF
174 :
175 : bool Object::IsNullOrUndefined(Isolate* isolate) const {
176 86291227 : Heap* heap = isolate->heap();
177 86302469 : return this == heap->null_value() || this == heap->undefined_value();
178 : }
179 :
180 : bool HeapObject::IsNullOrUndefined(Isolate* isolate) const {
181 7954 : Heap* heap = isolate->heap();
182 7954 : return this == heap->null_value() || this == heap->undefined_value();
183 : }
184 :
185 : bool HeapObject::IsString() const {
186 1615048430 : return map()->instance_type() < FIRST_NONSTRING_TYPE;
187 : }
188 :
189 : bool HeapObject::IsName() const {
190 107037128 : return map()->instance_type() <= LAST_NAME_TYPE;
191 : }
192 :
193 : bool HeapObject::IsUniqueName() const {
194 10358052 : return IsInternalizedString() || IsSymbol();
195 : }
196 :
197 : bool HeapObject::IsFunction() const {
198 : STATIC_ASSERT(LAST_FUNCTION_TYPE == LAST_TYPE);
199 44865128 : return map()->instance_type() >= FIRST_FUNCTION_TYPE;
200 : }
201 :
202 17758129 : bool HeapObject::IsCallable() const { return map()->is_callable(); }
203 :
204 129990 : bool HeapObject::IsConstructor() const { return map()->is_constructor(); }
205 :
206 : bool HeapObject::IsTemplateInfo() const {
207 970704 : return IsObjectTemplateInfo() || IsFunctionTemplateInfo();
208 : }
209 :
210 : bool HeapObject::IsInternalizedString() const {
211 122605219 : uint32_t type = map()->instance_type();
212 : STATIC_ASSERT(kNotInternalizedTag != 0);
213 122605219 : return (type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
214 705 : (kStringTag | kInternalizedTag);
215 : }
216 :
217 : bool HeapObject::IsConsString() const {
218 62333041 : if (!IsString()) return false;
219 62333042 : return StringShape(String::cast(this)).IsCons();
220 : }
221 :
222 : bool HeapObject::IsThinString() const {
223 185698159 : if (!IsString()) return false;
224 185698160 : return StringShape(String::cast(this)).IsThin();
225 : }
226 :
227 : bool HeapObject::IsSlicedString() const {
228 3714281 : if (!IsString()) return false;
229 3714281 : return StringShape(String::cast(this)).IsSliced();
230 : }
231 :
232 : bool HeapObject::IsSeqString() const {
233 403 : if (!IsString()) return false;
234 403 : return StringShape(String::cast(this)).IsSequential();
235 : }
236 :
237 : bool HeapObject::IsSeqOneByteString() const {
238 85644688 : if (!IsString()) return false;
239 155691308 : return StringShape(String::cast(this)).IsSequential() &&
240 71378281 : String::cast(this)->IsOneByteRepresentation();
241 : }
242 :
243 : bool HeapObject::IsSeqTwoByteString() const {
244 1427423 : if (!IsString()) return false;
245 190336 : return StringShape(String::cast(this)).IsSequential() &&
246 94575 : String::cast(this)->IsTwoByteRepresentation();
247 : }
248 :
249 : bool HeapObject::IsExternalString() const {
250 23637621 : if (!IsString()) return false;
251 22305959 : return StringShape(String::cast(this)).IsExternal();
252 : }
253 :
254 : bool HeapObject::IsExternalOneByteString() const {
255 416070186 : if (!IsString()) return false;
256 71348443 : return StringShape(String::cast(this)).IsExternal() &&
257 653023 : String::cast(this)->IsOneByteRepresentation();
258 : }
259 :
260 : bool HeapObject::IsExternalTwoByteString() const {
261 4595705 : if (!IsString()) return false;
262 4595797 : return StringShape(String::cast(this)).IsExternal() &&
263 92 : String::cast(this)->IsTwoByteRepresentation();
264 : }
265 :
266 283799809 : bool Object::IsNumber() const { return IsSmi() || IsHeapNumber(); }
267 :
268 : bool HeapObject::IsFiller() const {
269 223471396 : InstanceType instance_type = map()->instance_type();
270 223471530 : return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE;
271 : }
272 :
273 : bool HeapObject::IsFixedTypedArrayBase() const {
274 412329412 : InstanceType instance_type = map()->instance_type();
275 412327012 : return (instance_type >= FIRST_FIXED_TYPED_ARRAY_TYPE &&
276 : instance_type <= LAST_FIXED_TYPED_ARRAY_TYPE);
277 : }
278 :
279 : bool HeapObject::IsJSReceiver() const {
280 : STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
281 240326744 : return map()->instance_type() >= FIRST_JS_RECEIVER_TYPE;
282 : }
283 :
284 : bool HeapObject::IsJSObject() const {
285 : STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
286 238871021 : return map()->IsJSObjectMap();
287 : }
288 :
289 61106383 : bool HeapObject::IsJSProxy() const { return map()->IsJSProxyMap(); }
290 :
291 : bool HeapObject::IsJSMapIterator() const {
292 7011255 : InstanceType instance_type = map()->instance_type();
293 7011255 : return (instance_type >= JS_MAP_KEY_ITERATOR_TYPE &&
294 : instance_type <= JS_MAP_VALUE_ITERATOR_TYPE);
295 : }
296 :
297 : bool HeapObject::IsJSSetIterator() const {
298 7010635 : InstanceType instance_type = map()->instance_type();
299 7010635 : return (instance_type == JS_SET_VALUE_ITERATOR_TYPE ||
300 : instance_type == JS_SET_KEY_VALUE_ITERATOR_TYPE);
301 : }
302 :
303 : bool HeapObject::IsJSArrayIterator() const {
304 : InstanceType instance_type = map()->instance_type();
305 : return (instance_type >= FIRST_ARRAY_ITERATOR_TYPE &&
306 : instance_type <= LAST_ARRAY_ITERATOR_TYPE);
307 : }
308 :
309 : bool HeapObject::IsJSWeakCollection() const {
310 260513 : return IsJSWeakMap() || IsJSWeakSet();
311 : }
312 :
313 0 : bool HeapObject::IsJSCollection() const { return IsJSMap() || IsJSSet(); }
314 :
315 : bool HeapObject::IsDescriptorArray() const { return IsFixedArray(); }
316 :
317 : bool HeapObject::IsPropertyDescriptorObject() const { return IsFixedArray(); }
318 :
319 : bool HeapObject::IsEnumCache() const { return IsTuple2(); }
320 :
321 : bool HeapObject::IsFrameArray() const { return IsFixedArray(); }
322 :
323 : bool HeapObject::IsArrayList() const { return IsFixedArray(); }
324 :
325 : bool HeapObject::IsRegExpMatchInfo() const { return IsFixedArray(); }
326 :
327 0 : bool Object::IsLayoutDescriptor() const { return IsSmi() || IsByteArray(); }
328 :
329 : bool HeapObject::IsFeedbackVector() const {
330 22234777 : return map() == GetHeap()->feedback_vector_map();
331 : }
332 :
333 : bool HeapObject::IsFeedbackMetadata() const { return IsFixedArray(); }
334 :
335 : bool HeapObject::IsDeoptimizationData() const {
336 : // Must be a fixed array.
337 : if (!IsFixedArray()) return false;
338 :
339 : // There's no sure way to detect the difference between a fixed array and
340 : // a deoptimization data array. Since this is used for asserts we can
341 : // check that the length is zero or else the fixed size plus a multiple of
342 : // the entry size.
343 : int length = FixedArray::cast(this)->length();
344 : if (length == 0) return true;
345 :
346 : length -= DeoptimizationData::kFirstDeoptEntryIndex;
347 : return length >= 0 && length % DeoptimizationData::kDeoptEntrySize == 0;
348 : }
349 :
350 : bool HeapObject::IsHandlerTable() const {
351 : if (!IsFixedArray()) return false;
352 : // There's actually no way to see the difference between a fixed array and
353 : // a handler table array.
354 : return true;
355 : }
356 :
357 : bool HeapObject::IsTemplateList() const {
358 : if (!IsFixedArray()) return false;
359 : // There's actually no way to see the difference between a fixed array and
360 : // a template list.
361 : if (FixedArray::cast(this)->length() < 1) return false;
362 : return true;
363 : }
364 :
365 : bool HeapObject::IsDependentCode() const {
366 491672 : if (!IsFixedArray()) return false;
367 : // There's actually no way to see the difference between a fixed array and
368 : // a dependent codes array.
369 : return true;
370 : }
371 :
372 : bool HeapObject::IsContext() const {
373 29853683 : Map* map = this->map();
374 146391104 : Heap* heap = GetHeap();
375 : return (
376 76738061 : map == heap->function_context_map() || map == heap->catch_context_map() ||
377 56394324 : map == heap->with_context_map() || map == heap->native_context_map() ||
378 28116294 : map == heap->block_context_map() || map == heap->module_context_map() ||
379 57251585 : map == heap->eval_context_map() || map == heap->script_context_map() ||
380 8824553 : map == heap->debug_evaluate_context_map());
381 : }
382 :
383 : bool HeapObject::IsNativeContext() const {
384 2662711 : return map() == GetHeap()->native_context_map();
385 : }
386 :
387 : bool HeapObject::IsScriptContextTable() const {
388 : return map() == GetHeap()->script_context_table_map();
389 : }
390 :
391 : bool HeapObject::IsScopeInfo() const {
392 1935229 : return map() == GetHeap()->scope_info_map();
393 : }
394 :
395 : template <>
396 : inline bool Is<JSFunction>(Object* obj) {
397 : return obj->IsJSFunction();
398 : }
399 :
400 : bool HeapObject::IsAbstractCode() const {
401 71160016 : return IsBytecodeArray() || IsCode();
402 : }
403 :
404 : bool HeapObject::IsStringWrapper() const {
405 2134304 : return IsJSValue() && JSValue::cast(this)->value()->IsString();
406 : }
407 :
408 : bool HeapObject::IsBoolean() const {
409 39217602 : return IsOddball() &&
410 10359270 : ((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0);
411 : }
412 :
413 : bool HeapObject::IsJSArrayBufferView() const {
414 294950 : return IsJSDataView() || IsJSTypedArray();
415 : }
416 :
417 : bool HeapObject::IsWeakHashTable() const { return IsHashTable(); }
418 :
419 : bool HeapObject::IsDictionary() const {
420 28114808 : return IsHashTable() && this != GetHeap()->string_table();
421 : }
422 :
423 : bool Object::IsNameDictionary() const { return IsDictionary(); }
424 :
425 : bool Object::IsGlobalDictionary() const { return IsDictionary(); }
426 :
427 : bool Object::IsSeededNumberDictionary() const { return IsDictionary(); }
428 :
429 : bool HeapObject::IsUnseededNumberDictionary() const {
430 67080 : return map() == GetHeap()->unseeded_number_dictionary_map();
431 : }
432 :
433 : bool HeapObject::IsStringTable() const { return IsHashTable(); }
434 :
435 : bool HeapObject::IsStringSet() const { return IsHashTable(); }
436 :
437 : bool HeapObject::IsObjectHashSet() const { return IsHashTable(); }
438 :
439 : bool HeapObject::IsNormalizedMapCache() const {
440 : return NormalizedMapCache::IsNormalizedMapCache(this);
441 : }
442 :
443 : bool HeapObject::IsCompilationCacheTable() const { return IsHashTable(); }
444 :
445 : bool HeapObject::IsMapCache() const { return IsHashTable(); }
446 :
447 : bool HeapObject::IsObjectHashTable() const { return IsHashTable(); }
448 :
449 : bool HeapObject::IsOrderedHashTable() const {
450 176 : return map() == GetHeap()->ordered_hash_table_map();
451 : }
452 :
453 : bool Object::IsOrderedHashSet() const { return IsOrderedHashTable(); }
454 :
455 : bool Object::IsOrderedHashMap() const { return IsOrderedHashTable(); }
456 :
457 : bool Object::IsSmallOrderedHashTable() const {
458 : return IsSmallOrderedHashSet() || IsSmallOrderedHashMap();
459 : }
460 :
461 : bool Object::IsPrimitive() const {
462 9885906 : return IsSmi() || HeapObject::cast(this)->map()->IsPrimitiveMap();
463 : }
464 :
465 : // static
466 : Maybe<bool> Object::IsArray(Handle<Object> object) {
467 1220739 : if (object->IsSmi()) return Just(false);
468 1220711 : Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object);
469 1220711 : if (heap_object->IsJSArray()) return Just(true);
470 1190584 : if (!heap_object->IsJSProxy()) return Just(false);
471 1079 : return JSProxy::IsArray(Handle<JSProxy>::cast(object));
472 : }
473 :
474 : bool HeapObject::IsJSGlobalProxy() const {
475 182282045 : bool result = map()->instance_type() == JS_GLOBAL_PROXY_TYPE;
476 : DCHECK(!result || map()->is_access_check_needed());
477 : return result;
478 : }
479 :
480 26113 : bool HeapObject::IsUndetectable() const { return map()->is_undetectable(); }
481 :
482 : bool HeapObject::IsAccessCheckNeeded() const {
483 40417121 : if (IsJSGlobalProxy()) {
484 : const JSGlobalProxy* proxy = JSGlobalProxy::cast(this);
485 89301 : JSGlobalObject* global = proxy->GetIsolate()->context()->global_object();
486 89301 : return proxy->IsDetachedFrom(global);
487 : }
488 40327820 : return map()->is_access_check_needed();
489 : }
490 :
491 : bool HeapObject::IsStruct() const {
492 : switch (map()->instance_type()) {
493 : #define MAKE_STRUCT_CASE(NAME, Name, name) \
494 : case NAME##_TYPE: \
495 : return true;
496 : STRUCT_LIST(MAKE_STRUCT_CASE)
497 : #undef MAKE_STRUCT_CASE
498 : default:
499 : return false;
500 : }
501 : }
502 :
503 : #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \
504 : bool Object::Is##Name() const { \
505 : return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \
506 : } \
507 : bool HeapObject::Is##Name() const { \
508 : return map()->instance_type() == NAME##_TYPE; \
509 : }
510 1101883376 : STRUCT_LIST(MAKE_STRUCT_PREDICATE)
511 : #undef MAKE_STRUCT_PREDICATE
512 :
513 1382737 : double Object::Number() const {
514 : DCHECK(IsNumber());
515 : return IsSmi()
516 : ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value())
517 295826964 : : reinterpret_cast<const HeapNumber*>(this)->value();
518 : }
519 :
520 : bool Object::IsNaN() const {
521 6846 : return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value());
522 : }
523 :
524 : bool Object::IsMinusZero() const {
525 5878 : return this->IsHeapNumber() &&
526 2748 : i::IsMinusZero(HeapNumber::cast(this)->value());
527 : }
528 :
529 : // ------------------------------------
530 : // Cast operations
531 :
532 : CAST_ACCESSOR(AccessCheckInfo)
533 : CAST_ACCESSOR(AccessorInfo)
534 : CAST_ACCESSOR(AccessorPair)
535 : CAST_ACCESSOR(AllocationMemento)
536 : CAST_ACCESSOR(AllocationSite)
537 : CAST_ACCESSOR(ArrayList)
538 : CAST_ACCESSOR(AsyncGeneratorRequest)
539 : CAST_ACCESSOR(BigInt)
540 : CAST_ACCESSOR(BoilerplateDescription)
541 : CAST_ACCESSOR(ByteArray)
542 : CAST_ACCESSOR(CallHandlerInfo)
543 : CAST_ACCESSOR(Cell)
544 : CAST_ACCESSOR(ConstantElementsPair)
545 : CAST_ACCESSOR(ContextExtension)
546 : CAST_ACCESSOR(DescriptorArray)
547 : CAST_ACCESSOR(EnumCache)
548 : CAST_ACCESSOR(FixedArray)
549 : CAST_ACCESSOR(FixedArrayBase)
550 : CAST_ACCESSOR(FixedDoubleArray)
551 : CAST_ACCESSOR(FixedTypedArrayBase)
552 : CAST_ACCESSOR(Foreign)
553 : CAST_ACCESSOR(FunctionTemplateInfo)
554 : CAST_ACCESSOR(GlobalDictionary)
555 : CAST_ACCESSOR(HeapObject)
556 : CAST_ACCESSOR(InterceptorInfo)
557 : CAST_ACCESSOR(JSAsyncFromSyncIterator)
558 : CAST_ACCESSOR(JSAsyncGeneratorObject)
559 : CAST_ACCESSOR(JSBoundFunction)
560 : CAST_ACCESSOR(JSDataView)
561 : CAST_ACCESSOR(JSDate)
562 : CAST_ACCESSOR(JSFunction)
563 : CAST_ACCESSOR(JSGeneratorObject)
564 : CAST_ACCESSOR(JSGlobalObject)
565 : CAST_ACCESSOR(JSGlobalProxy)
566 : CAST_ACCESSOR(JSMap)
567 : CAST_ACCESSOR(JSMapIterator)
568 : CAST_ACCESSOR(JSMessageObject)
569 : CAST_ACCESSOR(JSObject)
570 : CAST_ACCESSOR(JSPromise)
571 : CAST_ACCESSOR(JSProxy)
572 : CAST_ACCESSOR(JSReceiver)
573 : CAST_ACCESSOR(JSSet)
574 : CAST_ACCESSOR(JSSetIterator)
575 : CAST_ACCESSOR(JSStringIterator)
576 : CAST_ACCESSOR(JSValue)
577 : CAST_ACCESSOR(JSWeakCollection)
578 : CAST_ACCESSOR(JSWeakMap)
579 : CAST_ACCESSOR(JSWeakSet)
580 : CAST_ACCESSOR(LayoutDescriptor)
581 : CAST_ACCESSOR(NameDictionary)
582 : CAST_ACCESSOR(NormalizedMapCache)
583 : CAST_ACCESSOR(Object)
584 : CAST_ACCESSOR(ObjectHashSet)
585 : CAST_ACCESSOR(ObjectHashTable)
586 : CAST_ACCESSOR(ObjectTemplateInfo)
587 : CAST_ACCESSOR(Oddball)
588 : CAST_ACCESSOR(OrderedHashMap)
589 : CAST_ACCESSOR(OrderedHashSet)
590 : CAST_ACCESSOR(PromiseCapability)
591 : CAST_ACCESSOR(PromiseReactionJobInfo)
592 : CAST_ACCESSOR(PromiseResolveThenableJobInfo)
593 : CAST_ACCESSOR(PropertyArray)
594 : CAST_ACCESSOR(PropertyCell)
595 : CAST_ACCESSOR(PrototypeInfo)
596 : CAST_ACCESSOR(RegExpMatchInfo)
597 : CAST_ACCESSOR(ScopeInfo)
598 : CAST_ACCESSOR(SeededNumberDictionary)
599 : CAST_ACCESSOR(SmallOrderedHashMap)
600 : CAST_ACCESSOR(SmallOrderedHashSet)
601 : CAST_ACCESSOR(Smi)
602 : CAST_ACCESSOR(SourcePositionTableWithFrameCache)
603 : CAST_ACCESSOR(StackFrameInfo)
604 : CAST_ACCESSOR(StringSet)
605 : CAST_ACCESSOR(StringTable)
606 : CAST_ACCESSOR(Struct)
607 : CAST_ACCESSOR(TemplateInfo)
608 : CAST_ACCESSOR(TemplateList)
609 : CAST_ACCESSOR(TemplateMap)
610 : CAST_ACCESSOR(TemplateObjectDescription)
611 : CAST_ACCESSOR(Tuple2)
612 : CAST_ACCESSOR(Tuple3)
613 : CAST_ACCESSOR(TypeFeedbackInfo)
614 : CAST_ACCESSOR(UnseededNumberDictionary)
615 : CAST_ACCESSOR(WeakCell)
616 : CAST_ACCESSOR(WeakFixedArray)
617 : CAST_ACCESSOR(WeakHashTable)
618 :
619 : bool Object::HasValidElements() {
620 : // Dictionary is covered under FixedArray.
621 : return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase();
622 : }
623 :
624 : bool Object::KeyEquals(Object* second) {
625 : Object* first = this;
626 : if (second->IsNumber()) {
627 : if (first->IsNumber()) return first->Number() == second->Number();
628 : Object* temp = first;
629 : first = second;
630 : second = temp;
631 : }
632 : if (first->IsNumber()) {
633 : DCHECK_LE(0, first->Number());
634 : uint32_t expected = static_cast<uint32_t>(first->Number());
635 : uint32_t index;
636 : return Name::cast(second)->AsArrayIndex(&index) && index == expected;
637 : }
638 : return Name::cast(first)->Equals(Name::cast(second));
639 : }
640 :
641 10348704 : bool Object::FilterKey(PropertyFilter filter) {
642 : DCHECK(!IsPropertyCell());
643 10348704 : if (IsSymbol()) {
644 78306 : if (filter & SKIP_SYMBOLS) return true;
645 25237 : if (Symbol::cast(this)->is_private()) return true;
646 : } else {
647 10270398 : if (filter & SKIP_STRINGS) return true;
648 : }
649 7932827 : return false;
650 : }
651 :
652 1955 : Handle<Object> Object::NewStorageFor(Isolate* isolate, Handle<Object> object,
653 : Representation representation) {
654 1955 : if (!representation.IsDouble()) return object;
655 1955 : Handle<HeapNumber> result = isolate->factory()->NewHeapNumber(MUTABLE);
656 1955 : if (object->IsUninitialized(isolate)) {
657 : result->set_value_as_bits(kHoleNanInt64);
658 1316 : } else if (object->IsMutableHeapNumber()) {
659 : // Ensure that all bits of the double value are preserved.
660 : result->set_value_as_bits(HeapNumber::cast(*object)->value_as_bits());
661 : } else {
662 : result->set_value(object->Number());
663 : }
664 1955 : return result;
665 : }
666 :
667 35073026 : Handle<Object> Object::WrapForRead(Isolate* isolate, Handle<Object> object,
668 : Representation representation) {
669 : DCHECK(!object->IsUninitialized(isolate));
670 35073026 : if (!representation.IsDouble()) {
671 : DCHECK(object->FitsRepresentation(representation));
672 35070552 : return object;
673 : }
674 2474 : return isolate->factory()->NewHeapNumber(HeapNumber::cast(*object)->value());
675 : }
676 :
677 16618273 : Representation Object::OptimalRepresentation() {
678 16618273 : if (!FLAG_track_fields) return Representation::Tagged();
679 16618273 : if (IsSmi()) {
680 : return Representation::Smi();
681 25996116 : } else if (FLAG_track_double_fields && IsHeapNumber()) {
682 : return Representation::Double();
683 25966266 : } else if (FLAG_track_computed_fields &&
684 : IsUninitialized(HeapObject::cast(this)->GetIsolate())) {
685 : return Representation::None();
686 12678208 : } else if (FLAG_track_heap_object_fields) {
687 : DCHECK(IsHeapObject());
688 : return Representation::HeapObject();
689 : } else {
690 : return Representation::Tagged();
691 : }
692 : }
693 :
694 :
695 13518694 : ElementsKind Object::OptimalElementsKind() {
696 13518694 : if (IsSmi()) return PACKED_SMI_ELEMENTS;
697 1856142 : if (IsNumber()) return PACKED_DOUBLE_ELEMENTS;
698 618703 : return PACKED_ELEMENTS;
699 : }
700 :
701 :
702 40898240 : bool Object::FitsRepresentation(Representation representation) {
703 40898240 : if (FLAG_track_fields && representation.IsSmi()) {
704 3706149 : return IsSmi();
705 37192091 : } else if (FLAG_track_double_fields && representation.IsDouble()) {
706 83004 : return IsMutableHeapNumber() || IsNumber();
707 37150589 : } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
708 35100380 : return IsHeapObject();
709 2050209 : } else if (FLAG_track_fields && representation.IsNone()) {
710 : return false;
711 : }
712 1769852 : return true;
713 : }
714 :
715 90874950 : bool Object::ToUint32(uint32_t* value) const {
716 90874950 : if (IsSmi()) {
717 : int num = Smi::ToInt(this);
718 37970184 : if (num < 0) return false;
719 37940791 : *value = static_cast<uint32_t>(num);
720 37940791 : return true;
721 : }
722 52904766 : if (IsHeapNumber()) {
723 : double num = HeapNumber::cast(this)->value();
724 19260 : return DoubleToUint32IfEqualToSelf(num, value);
725 : }
726 : return false;
727 : }
728 :
729 : // static
730 12317331 : MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
731 : Handle<Object> object,
732 : const char* method_name) {
733 12317331 : if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object);
734 6361 : return ToObject(isolate, object, isolate->native_context(), method_name);
735 : }
736 :
737 :
738 : // static
739 44071297 : MaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> input) {
740 44071296 : if (input->IsName()) return Handle<Name>::cast(input);
741 3048727 : return ConvertToName(isolate, input);
742 : }
743 :
744 : // static
745 353158 : MaybeHandle<Object> Object::ToPropertyKey(Isolate* isolate,
746 : Handle<Object> value) {
747 652223 : if (value->IsSmi() || HeapObject::cast(*value)->IsName()) return value;
748 479 : return ConvertToPropertyKey(isolate, value);
749 : }
750 :
751 : // static
752 3110566 : MaybeHandle<Object> Object::ToPrimitive(Handle<Object> input,
753 : ToPrimitiveHint hint) {
754 3110566 : if (input->IsPrimitive()) return input;
755 3004973 : return JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), hint);
756 : }
757 :
758 : // static
759 13019768 : MaybeHandle<Object> Object::ToNumber(Handle<Object> input) {
760 13019768 : if (input->IsNumber()) return input; // Shortcut.
761 : return ConvertToNumberOrNumeric(HeapObject::cast(*input)->GetIsolate(), input,
762 1853678 : Conversion::kToNumber);
763 : }
764 :
765 : // static
766 860 : MaybeHandle<Object> Object::ToNumeric(Handle<Object> input) {
767 1720 : if (input->IsNumber() || input->IsBigInt()) return input; // Shortcut.
768 : return ConvertToNumberOrNumeric(HeapObject::cast(*input)->GetIsolate(), input,
769 860 : Conversion::kToNumeric);
770 : }
771 :
772 : // static
773 8383 : MaybeHandle<Object> Object::ToInteger(Isolate* isolate, Handle<Object> input) {
774 11312777 : if (input->IsSmi()) return input;
775 19540 : return ConvertToInteger(isolate, input);
776 : }
777 :
778 : // static
779 : MaybeHandle<Object> Object::ToInt32(Isolate* isolate, Handle<Object> input) {
780 7441 : if (input->IsSmi()) return input;
781 456 : return ConvertToInt32(isolate, input);
782 : }
783 :
784 : // static
785 473837 : MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) {
786 473875 : if (input->IsSmi()) return handle(Smi::cast(*input)->ToUint32Smi(), isolate);
787 473799 : return ConvertToUint32(isolate, input);
788 : }
789 :
790 : // static
791 19200466 : MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) {
792 19200466 : if (input->IsString()) return Handle<String>::cast(input);
793 5961382 : return ConvertToString(isolate, input);
794 : }
795 :
796 : // static
797 52051 : MaybeHandle<Object> Object::ToLength(Isolate* isolate, Handle<Object> input) {
798 52051 : if (input->IsSmi()) {
799 151335 : int value = std::max(Smi::ToInt(*input), 0);
800 50445 : return handle(Smi::FromInt(value), isolate);
801 : }
802 1606 : return ConvertToLength(isolate, input);
803 : }
804 :
805 : // static
806 15968 : MaybeHandle<Object> Object::ToIndex(Isolate* isolate, Handle<Object> input,
807 : MessageTemplate::Template error_index) {
808 28793 : if (input->IsSmi() && Smi::ToInt(*input) >= 0) return input;
809 3561 : return ConvertToIndex(isolate, input, error_index);
810 : }
811 :
812 41424165 : bool Object::HasSpecificClassOf(String* name) {
813 41424165 : return this->IsJSObject() && (JSObject::cast(this)->class_name() == name);
814 : }
815 :
816 1204333 : MaybeHandle<Object> Object::GetProperty(Handle<Object> object,
817 : Handle<Name> name) {
818 1204333 : LookupIterator it(object, name);
819 1310600 : if (!it.IsFound()) return it.factory()->undefined_value();
820 1098066 : return GetProperty(&it);
821 : }
822 :
823 26305639 : MaybeHandle<Object> JSReceiver::GetProperty(Handle<JSReceiver> receiver,
824 : Handle<Name> name) {
825 26305639 : LookupIterator it(receiver, name, receiver);
826 37328965 : if (!it.IsFound()) return it.factory()->undefined_value();
827 15282313 : return Object::GetProperty(&it);
828 : }
829 :
830 4132 : MaybeHandle<Object> Object::GetElement(Isolate* isolate, Handle<Object> object,
831 : uint32_t index) {
832 4132 : LookupIterator it(isolate, object, index);
833 4170 : if (!it.IsFound()) return it.factory()->undefined_value();
834 4094 : return GetProperty(&it);
835 : }
836 :
837 96020279 : MaybeHandle<Object> JSReceiver::GetElement(Isolate* isolate,
838 : Handle<JSReceiver> receiver,
839 : uint32_t index) {
840 : LookupIterator it(isolate, receiver, index, receiver);
841 146609702 : if (!it.IsFound()) return it.factory()->undefined_value();
842 45430856 : return Object::GetProperty(&it);
843 : }
844 :
845 5608134 : Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object,
846 : Handle<Name> name) {
847 : LookupIterator it(object, name, object,
848 5608134 : LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
849 8208608 : if (!it.IsFound()) return it.factory()->undefined_value();
850 3007660 : return GetDataProperty(&it);
851 : }
852 :
853 75015 : MaybeHandle<Object> Object::SetElement(Isolate* isolate, Handle<Object> object,
854 : uint32_t index, Handle<Object> value,
855 : LanguageMode language_mode) {
856 75015 : LookupIterator it(isolate, object, index);
857 75015 : MAYBE_RETURN_NULL(
858 : SetProperty(&it, value, language_mode, MAY_BE_STORE_FROM_KEYED));
859 75015 : return value;
860 : }
861 :
862 3330406 : MaybeHandle<Object> JSReceiver::GetPrototype(Isolate* isolate,
863 : Handle<JSReceiver> receiver) {
864 : // We don't expect access checks to be needed on JSProxy objects.
865 : DCHECK(!receiver->IsAccessCheckNeeded() || receiver->IsJSObject());
866 : PrototypeIterator iter(isolate, receiver, kStartAtReceiver,
867 3330406 : PrototypeIterator::END_AT_NON_HIDDEN);
868 3353234 : do {
869 3353270 : if (!iter.AdvanceFollowingProxies()) return MaybeHandle<Object>();
870 3353234 : } while (!iter.IsAtEnd());
871 3330370 : return PrototypeIterator::GetCurrent(iter);
872 : }
873 :
874 345521 : MaybeHandle<Object> JSReceiver::GetProperty(Isolate* isolate,
875 : Handle<JSReceiver> receiver,
876 : const char* name) {
877 345521 : Handle<String> str = isolate->factory()->InternalizeUtf8String(name);
878 345521 : return GetProperty(receiver, str);
879 : }
880 :
881 : // static
882 984 : MUST_USE_RESULT MaybeHandle<FixedArray> JSReceiver::OwnPropertyKeys(
883 : Handle<JSReceiver> object) {
884 : return KeyAccumulator::GetKeys(object, KeyCollectionMode::kOwnOnly,
885 : ALL_PROPERTIES,
886 1548 : GetKeysConversion::kConvertToString);
887 : }
888 :
889 7346142 : bool JSObject::PrototypeHasNoElements(Isolate* isolate, JSObject* object) {
890 : DisallowHeapAllocation no_gc;
891 : HeapObject* prototype = HeapObject::cast(object->map()->prototype());
892 7346142 : HeapObject* null = isolate->heap()->null_value();
893 7346142 : HeapObject* empty_fixed_array = isolate->heap()->empty_fixed_array();
894 : HeapObject* empty_slow_element_dictionary =
895 7346142 : isolate->heap()->empty_slow_element_dictionary();
896 35340543 : while (prototype != null) {
897 : Map* map = prototype->map();
898 20662432 : if (map->instance_type() <= LAST_CUSTOM_ELEMENTS_RECEIVER) return false;
899 : HeapObject* elements = JSObject::cast(prototype)->elements();
900 41319642 : if (elements != empty_fixed_array &&
901 20659821 : elements != empty_slow_element_dictionary) {
902 : return false;
903 : }
904 : prototype = HeapObject::cast(map->prototype());
905 : }
906 : return true;
907 : }
908 :
909 91783693 : Object** HeapObject::RawField(HeapObject* obj, int byte_offset) {
910 619581812 : return reinterpret_cast<Object**>(FIELD_ADDR(obj, byte_offset));
911 : }
912 :
913 614386 : int Smi::ToInt(const Object* object) { return Smi::cast(object)->value(); }
914 :
915 106212760 : MapWord MapWord::FromMap(const Map* map) {
916 852273802 : return MapWord(reinterpret_cast<uintptr_t>(map));
917 : }
918 :
919 25388841673 : Map* MapWord::ToMap() const { return reinterpret_cast<Map*>(value_); }
920 :
921 : bool MapWord::IsForwardingAddress() const {
922 617554240 : return HAS_SMI_TAG(reinterpret_cast<Object*>(value_));
923 : }
924 :
925 :
926 105867682 : MapWord MapWord::FromForwardingAddress(HeapObject* object) {
927 106814282 : Address raw = reinterpret_cast<Address>(object) - kHeapObjectTag;
928 106814282 : return MapWord(reinterpret_cast<uintptr_t>(raw));
929 : }
930 :
931 :
932 1173969 : HeapObject* MapWord::ToForwardingAddress() {
933 : DCHECK(IsForwardingAddress());
934 91017343 : return HeapObject::FromAddress(reinterpret_cast<Address>(value_));
935 : }
936 :
937 :
938 : #ifdef VERIFY_HEAP
939 : void HeapObject::VerifyObjectField(int offset) {
940 : VerifyPointer(READ_FIELD(this, offset));
941 : }
942 :
943 : void HeapObject::VerifySmiField(int offset) {
944 : CHECK(READ_FIELD(this, offset)->IsSmi());
945 : }
946 : #endif
947 :
948 :
949 84672470 : Heap* HeapObject::GetHeap() const {
950 : Heap* heap = MemoryChunk::FromAddress(
951 : reinterpret_cast<Address>(const_cast<HeapObject*>(this)))
952 7447780465 : ->heap();
953 : SLOW_DCHECK(heap != nullptr);
954 84672470 : return heap;
955 : }
956 :
957 :
958 490881473 : Isolate* HeapObject::GetIsolate() const {
959 490881473 : return GetHeap()->isolate();
960 : }
961 :
962 8770428001 : Map* HeapObject::map() const {
963 8770428001 : return map_word().ToMap();
964 : }
965 :
966 :
967 13713850 : void HeapObject::set_map(Map* value) {
968 : if (value != nullptr) {
969 : #ifdef VERIFY_HEAP
970 : value->GetHeap()->VerifyObjectLayoutChange(this, value);
971 : #endif
972 : }
973 : set_map_word(MapWord::FromMap(value));
974 13713850 : if (value != nullptr) {
975 : // TODO(1600) We are passing nullptr as a slot because maps can never be on
976 : // evacuation candidate.
977 13713851 : value->GetHeap()->incremental_marking()->RecordWrite(this, nullptr, value);
978 : }
979 13713853 : }
980 :
981 : Map* HeapObject::synchronized_map() const {
982 : return synchronized_map_word().ToMap();
983 : }
984 :
985 :
986 60402468 : void HeapObject::synchronized_set_map(Map* value) {
987 : if (value != nullptr) {
988 : #ifdef VERIFY_HEAP
989 : value->GetHeap()->VerifyObjectLayoutChange(this, value);
990 : #endif
991 : }
992 : synchronized_set_map_word(MapWord::FromMap(value));
993 60402468 : if (value != nullptr) {
994 : // TODO(1600) We are passing nullptr as a slot because maps can never be on
995 : // evacuation candidate.
996 60402469 : value->GetHeap()->incremental_marking()->RecordWrite(this, nullptr, value);
997 : }
998 60402470 : }
999 :
1000 :
1001 : // Unsafe accessor omitting write barrier.
1002 : void HeapObject::set_map_no_write_barrier(Map* value) {
1003 : if (value != nullptr) {
1004 : #ifdef VERIFY_HEAP
1005 : value->GetHeap()->VerifyObjectLayoutChange(this, value);
1006 : #endif
1007 : }
1008 : set_map_word(MapWord::FromMap(value));
1009 : }
1010 :
1011 649783252 : void HeapObject::set_map_after_allocation(Map* value, WriteBarrierMode mode) {
1012 : set_map_word(MapWord::FromMap(value));
1013 649783252 : if (mode != SKIP_WRITE_BARRIER) {
1014 : DCHECK_NOT_NULL(value);
1015 : // TODO(1600) We are passing nullptr as a slot because maps can never be on
1016 : // evacuation candidate.
1017 28360201 : value->GetHeap()->incremental_marking()->RecordWrite(this, nullptr, value);
1018 : }
1019 649783251 : }
1020 :
1021 145025978 : HeapObject** HeapObject::map_slot() {
1022 145025978 : return reinterpret_cast<HeapObject**>(FIELD_ADDR(this, kMapOffset));
1023 : }
1024 :
1025 1176680 : MapWord HeapObject::map_word() const {
1026 : return MapWord(
1027 24602296408 : reinterpret_cast<uintptr_t>(RELAXED_READ_FIELD(this, kMapOffset)));
1028 : }
1029 :
1030 :
1031 106175284 : void HeapObject::set_map_word(MapWord map_word) {
1032 791833858 : RELAXED_WRITE_FIELD(this, kMapOffset,
1033 : reinterpret_cast<Object*>(map_word.value_));
1034 106175284 : }
1035 :
1036 :
1037 : MapWord HeapObject::synchronized_map_word() const {
1038 : return MapWord(
1039 1145838560 : reinterpret_cast<uintptr_t>(ACQUIRE_READ_FIELD(this, kMapOffset)));
1040 : }
1041 :
1042 :
1043 : void HeapObject::synchronized_set_map_word(MapWord map_word) {
1044 60402468 : RELEASE_WRITE_FIELD(
1045 : this, kMapOffset, reinterpret_cast<Object*>(map_word.value_));
1046 : }
1047 :
1048 1579693974 : int HeapObject::Size() const { return SizeFromMap(map()); }
1049 :
1050 5671 : double HeapNumber::value() const {
1051 5671 : return READ_DOUBLE_FIELD(this, kValueOffset);
1052 : }
1053 :
1054 :
1055 : void HeapNumber::set_value(double value) {
1056 : WRITE_DOUBLE_FIELD(this, kValueOffset, value);
1057 : }
1058 :
1059 : uint64_t HeapNumber::value_as_bits() const {
1060 66321 : return READ_UINT64_FIELD(this, kValueOffset);
1061 : }
1062 :
1063 : void HeapNumber::set_value_as_bits(uint64_t bits) {
1064 39361 : WRITE_UINT64_FIELD(this, kValueOffset, bits);
1065 : }
1066 :
1067 : int HeapNumber::get_exponent() {
1068 : return ((READ_INT_FIELD(this, kExponentOffset) & kExponentMask) >>
1069 : kExponentShift) - kExponentBias;
1070 : }
1071 :
1072 :
1073 : int HeapNumber::get_sign() {
1074 : return READ_INT_FIELD(this, kExponentOffset) & kSignMask;
1075 : }
1076 :
1077 5176 : inline Object* OrderedHashMap::ValueAt(int entry) {
1078 : DCHECK_LT(entry, this->UsedCapacity());
1079 10352 : return get(EntryToIndex(entry) + kValueOffset);
1080 : }
1081 :
1082 460965475 : ACCESSORS(JSReceiver, raw_properties_or_hash, Object, kPropertiesOrHashOffset)
1083 :
1084 7735313 : Object** FixedArray::GetFirstElementAddress() {
1085 7735313 : return reinterpret_cast<Object**>(FIELD_ADDR(this, OffsetOfElementAt(0)));
1086 : }
1087 :
1088 :
1089 : bool FixedArray::ContainsOnlySmisOrHoles() {
1090 : Object* the_hole = GetHeap()->the_hole_value();
1091 : Object** current = GetFirstElementAddress();
1092 : for (int i = 0; i < length(); ++i) {
1093 : Object* candidate = *current++;
1094 : if (!candidate->IsSmi() && candidate != the_hole) return false;
1095 : }
1096 : return true;
1097 : }
1098 :
1099 :
1100 1057789 : FixedArrayBase* JSObject::elements() const {
1101 412730845 : Object* array = READ_FIELD(this, kElementsOffset);
1102 1057789 : return static_cast<FixedArrayBase*>(array);
1103 : }
1104 :
1105 339188 : void AllocationSite::Initialize() {
1106 339188 : set_transition_info_or_boilerplate(Smi::kZero);
1107 339188 : SetElementsKind(GetInitialFastElementsKind());
1108 339188 : set_nested_site(Smi::kZero);
1109 : set_pretenure_data(0);
1110 : set_pretenure_create_count(0);
1111 339188 : set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()),
1112 339188 : SKIP_WRITE_BARRIER);
1113 339188 : }
1114 :
1115 : bool AllocationSite::IsZombie() const {
1116 : return pretenure_decision() == kZombie;
1117 : }
1118 :
1119 : bool AllocationSite::IsMaybeTenure() const {
1120 : return pretenure_decision() == kMaybeTenure;
1121 : }
1122 :
1123 : bool AllocationSite::PretenuringDecisionMade() const {
1124 : return pretenure_decision() != kUndecided;
1125 : }
1126 :
1127 :
1128 : void AllocationSite::MarkZombie() {
1129 : DCHECK(!IsZombie());
1130 93131 : Initialize();
1131 93131 : set_pretenure_decision(kZombie);
1132 : }
1133 :
1134 338373 : ElementsKind AllocationSite::GetElementsKind() const {
1135 1199553 : return ElementsKindBits::decode(transition_info());
1136 : }
1137 :
1138 :
1139 358026 : void AllocationSite::SetElementsKind(ElementsKind kind) {
1140 716052 : set_transition_info(ElementsKindBits::update(transition_info(), kind));
1141 358026 : }
1142 :
1143 : bool AllocationSite::CanInlineCall() const {
1144 1032 : return DoNotInlineBit::decode(transition_info()) == 0;
1145 : }
1146 :
1147 :
1148 2356 : void AllocationSite::SetDoNotInlineCall() {
1149 4712 : set_transition_info(DoNotInlineBit::update(transition_info(), true));
1150 2356 : }
1151 :
1152 : bool AllocationSite::PointsToLiteral() const {
1153 : Object* raw_value = transition_info_or_boilerplate();
1154 : DCHECK_EQ(!raw_value->IsSmi(),
1155 : raw_value->IsJSArray() || raw_value->IsJSObject());
1156 : return !raw_value->IsSmi();
1157 : }
1158 :
1159 :
1160 : // Heuristic: We only need to create allocation site info if the boilerplate
1161 : // elements kind is the initial elements kind.
1162 502011 : bool AllocationSite::ShouldTrack(ElementsKind boilerplate_elements_kind) {
1163 502011 : return IsSmiElementsKind(boilerplate_elements_kind);
1164 : }
1165 :
1166 : inline bool AllocationSite::CanTrack(InstanceType type) {
1167 128599258 : if (FLAG_allocation_site_pretenuring) {
1168 : // TurboFan doesn't care at all about String pretenuring feedback,
1169 : // so don't bother even trying to track that.
1170 128599258 : return type == JS_ARRAY_TYPE || type == JS_OBJECT_TYPE;
1171 : }
1172 0 : return type == JS_ARRAY_TYPE;
1173 : }
1174 :
1175 : AllocationSite::PretenureDecision AllocationSite::pretenure_decision() const {
1176 927570 : return PretenureDecisionBits::decode(pretenure_data());
1177 : }
1178 :
1179 93948 : void AllocationSite::set_pretenure_decision(PretenureDecision decision) {
1180 : int value = pretenure_data();
1181 187896 : set_pretenure_data(PretenureDecisionBits::update(value, decision));
1182 93948 : }
1183 :
1184 : bool AllocationSite::deopt_dependent_code() const {
1185 209 : return DeoptDependentCodeBit::decode(pretenure_data());
1186 : }
1187 :
1188 187 : void AllocationSite::set_deopt_dependent_code(bool deopt) {
1189 : int value = pretenure_data();
1190 374 : set_pretenure_data(DeoptDependentCodeBit::update(value, deopt));
1191 187 : }
1192 :
1193 : int AllocationSite::memento_found_count() const {
1194 : return MementoFoundCountBits::decode(pretenure_data());
1195 : }
1196 :
1197 99901 : inline void AllocationSite::set_memento_found_count(int count) {
1198 : int value = pretenure_data();
1199 : // Verify that we can count more mementos than we can possibly find in one
1200 : // new space collection.
1201 : DCHECK((GetHeap()->MaxSemiSpaceSize() /
1202 : (Heap::kMinObjectSizeInWords * kPointerSize +
1203 : AllocationMemento::kSize)) < MementoFoundCountBits::kMax);
1204 : DCHECK_LT(count, MementoFoundCountBits::kMax);
1205 199802 : set_pretenure_data(MementoFoundCountBits::update(value, count));
1206 99901 : }
1207 :
1208 : int AllocationSite::memento_create_count() const {
1209 : return pretenure_create_count();
1210 : }
1211 :
1212 : void AllocationSite::set_memento_create_count(int count) {
1213 : set_pretenure_create_count(count);
1214 : }
1215 :
1216 99080 : bool AllocationSite::IncrementMementoFoundCount(int increment) {
1217 99080 : if (IsZombie()) return false;
1218 :
1219 : int value = memento_found_count();
1220 99080 : set_memento_found_count(value + increment);
1221 99080 : return memento_found_count() >= kPretenureMinimumCreated;
1222 : }
1223 :
1224 :
1225 2132406 : inline void AllocationSite::IncrementMementoCreateCount() {
1226 : DCHECK(FLAG_allocation_site_pretenuring);
1227 : int value = memento_create_count();
1228 2132406 : set_memento_create_count(value + 1);
1229 2132406 : }
1230 :
1231 546852 : bool AllocationMemento::IsValid() const {
1232 1093704 : return allocation_site()->IsAllocationSite() &&
1233 546852 : !AllocationSite::cast(allocation_site())->IsZombie();
1234 : }
1235 :
1236 : AllocationSite* AllocationMemento::GetAllocationSite() const {
1237 : DCHECK(IsValid());
1238 : return AllocationSite::cast(allocation_site());
1239 : }
1240 :
1241 : Address AllocationMemento::GetAllocationSiteUnchecked() const {
1242 : return reinterpret_cast<Address>(allocation_site());
1243 : }
1244 :
1245 123140 : void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) {
1246 123140 : JSObject::ValidateElements(*object);
1247 : ElementsKind elements_kind = object->map()->elements_kind();
1248 123140 : if (!IsObjectElementsKind(elements_kind)) {
1249 0 : if (IsHoleyElementsKind(elements_kind)) {
1250 0 : TransitionElementsKind(object, HOLEY_ELEMENTS);
1251 : } else {
1252 0 : TransitionElementsKind(object, PACKED_ELEMENTS);
1253 : }
1254 : }
1255 123140 : }
1256 :
1257 :
1258 505938 : void JSObject::EnsureCanContainElements(Handle<JSObject> object,
1259 : Object** objects,
1260 : uint32_t count,
1261 : EnsureElementsMode mode) {
1262 : ElementsKind current_kind = object->GetElementsKind();
1263 : ElementsKind target_kind = current_kind;
1264 : {
1265 : DisallowHeapAllocation no_allocation;
1266 : DCHECK(mode != ALLOW_COPIED_DOUBLE_ELEMENTS);
1267 : bool is_holey = IsHoleyElementsKind(current_kind);
1268 1011876 : if (current_kind == HOLEY_ELEMENTS) return;
1269 505932 : Object* the_hole = object->GetHeap()->the_hole_value();
1270 17988447 : for (uint32_t i = 0; i < count; ++i) {
1271 17482515 : Object* current = *objects++;
1272 17482515 : if (current == the_hole) {
1273 : is_holey = true;
1274 : target_kind = GetHoleyElementsKind(target_kind);
1275 15973799 : } else if (!current->IsSmi()) {
1276 10928875 : if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) {
1277 1905817 : if (IsSmiElementsKind(target_kind)) {
1278 235 : if (is_holey) {
1279 : target_kind = HOLEY_DOUBLE_ELEMENTS;
1280 : } else {
1281 : target_kind = PACKED_DOUBLE_ELEMENTS;
1282 : }
1283 : }
1284 3755628 : } else if (is_holey) {
1285 : target_kind = HOLEY_ELEMENTS;
1286 : break;
1287 : } else {
1288 : target_kind = PACKED_ELEMENTS;
1289 : }
1290 : }
1291 : }
1292 : }
1293 505932 : if (target_kind != current_kind) {
1294 95137 : TransitionElementsKind(object, target_kind);
1295 : }
1296 : }
1297 :
1298 :
1299 93724 : void JSObject::EnsureCanContainElements(Handle<JSObject> object,
1300 : Handle<FixedArrayBase> elements,
1301 : uint32_t length,
1302 : EnsureElementsMode mode) {
1303 93724 : Heap* heap = object->GetHeap();
1304 93724 : if (elements->map() != heap->fixed_double_array_map()) {
1305 : DCHECK(elements->map() == heap->fixed_array_map() ||
1306 : elements->map() == heap->fixed_cow_array_map());
1307 93724 : if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) {
1308 : mode = DONT_ALLOW_DOUBLE_ELEMENTS;
1309 : }
1310 : Object** objects =
1311 93724 : Handle<FixedArray>::cast(elements)->GetFirstElementAddress();
1312 93724 : EnsureCanContainElements(object, objects, length, mode);
1313 93724 : return;
1314 : }
1315 :
1316 : DCHECK(mode == ALLOW_COPIED_DOUBLE_ELEMENTS);
1317 0 : if (object->GetElementsKind() == HOLEY_SMI_ELEMENTS) {
1318 0 : TransitionElementsKind(object, HOLEY_DOUBLE_ELEMENTS);
1319 0 : } else if (object->GetElementsKind() == PACKED_SMI_ELEMENTS) {
1320 : Handle<FixedDoubleArray> double_array =
1321 : Handle<FixedDoubleArray>::cast(elements);
1322 0 : for (uint32_t i = 0; i < length; ++i) {
1323 0 : if (double_array->is_the_hole(i)) {
1324 0 : TransitionElementsKind(object, HOLEY_DOUBLE_ELEMENTS);
1325 : return;
1326 : }
1327 : }
1328 0 : TransitionElementsKind(object, PACKED_DOUBLE_ELEMENTS);
1329 : }
1330 : }
1331 :
1332 :
1333 1545640 : void JSObject::SetMapAndElements(Handle<JSObject> object,
1334 : Handle<Map> new_map,
1335 : Handle<FixedArrayBase> value) {
1336 1545640 : JSObject::MigrateToMap(object, new_map);
1337 : DCHECK((object->map()->has_fast_smi_or_object_elements() ||
1338 : (*value == object->GetHeap()->empty_fixed_array()) ||
1339 : object->map()->has_fast_string_wrapper_elements()) ==
1340 : (value->map() == object->GetHeap()->fixed_array_map() ||
1341 : value->map() == object->GetHeap()->fixed_cow_array_map()));
1342 : DCHECK((*value == object->GetHeap()->empty_fixed_array()) ||
1343 : (object->map()->has_fast_double_elements() ==
1344 : value->IsFixedDoubleArray()));
1345 1545640 : object->set_elements(*value);
1346 1545640 : }
1347 :
1348 :
1349 15285079 : void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) {
1350 15285079 : WRITE_FIELD(this, kElementsOffset, value);
1351 55094113 : CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kElementsOffset, value, mode);
1352 15285079 : }
1353 :
1354 :
1355 41251758 : void JSObject::initialize_elements() {
1356 41251758 : FixedArrayBase* elements = map()->GetInitialElements();
1357 41251762 : WRITE_FIELD(this, kElementsOffset, elements);
1358 41251762 : }
1359 :
1360 :
1361 621484 : InterceptorInfo* JSObject::GetIndexedInterceptor() {
1362 621484 : return map()->GetIndexedInterceptor();
1363 : }
1364 :
1365 1630328 : InterceptorInfo* JSObject::GetNamedInterceptor() {
1366 1630328 : return map()->GetNamedInterceptor();
1367 : }
1368 :
1369 : double Oddball::to_number_raw() const {
1370 : return READ_DOUBLE_FIELD(this, kToNumberRawOffset);
1371 : }
1372 :
1373 : void Oddball::set_to_number_raw(double value) {
1374 : WRITE_DOUBLE_FIELD(this, kToNumberRawOffset, value);
1375 : }
1376 :
1377 : void Oddball::set_to_number_raw_as_bits(uint64_t bits) {
1378 62 : WRITE_UINT64_FIELD(this, kToNumberRawOffset, bits);
1379 : }
1380 :
1381 2097840 : ACCESSORS(Oddball, to_string, String, kToStringOffset)
1382 2326741 : ACCESSORS(Oddball, to_number, Object, kToNumberOffset)
1383 3087 : ACCESSORS(Oddball, type_of, String, kTypeOfOffset)
1384 :
1385 42151408 : byte Oddball::kind() const { return Smi::ToInt(READ_FIELD(this, kKindOffset)); }
1386 :
1387 : void Oddball::set_kind(byte value) {
1388 496 : WRITE_FIELD(this, kKindOffset, Smi::FromInt(value));
1389 : }
1390 :
1391 :
1392 : // static
1393 2325036 : Handle<Object> Oddball::ToNumber(Handle<Oddball> input) {
1394 2325036 : return handle(input->to_number(), input->GetIsolate());
1395 : }
1396 :
1397 :
1398 109402429 : ACCESSORS(Cell, value, Object, kValueOffset)
1399 17576563 : ACCESSORS(PropertyCell, dependent_code, DependentCode, kDependentCodeOffset)
1400 146352528 : ACCESSORS(PropertyCell, name, Name, kNameOffset)
1401 132977107 : ACCESSORS(PropertyCell, value, Object, kValueOffset)
1402 268585385 : ACCESSORS(PropertyCell, property_details_raw, Object, kDetailsOffset)
1403 :
1404 : PropertyDetails PropertyCell::property_details() {
1405 : return PropertyDetails(Smi::cast(property_details_raw()));
1406 : }
1407 :
1408 :
1409 : void PropertyCell::set_property_details(PropertyDetails details) {
1410 23886989 : set_property_details_raw(details.AsSmi());
1411 : }
1412 :
1413 :
1414 271691077 : Object* WeakCell::value() const { return READ_FIELD(this, kValueOffset); }
1415 :
1416 :
1417 : void WeakCell::clear() {
1418 : // Either the garbage collector is clearing the cell or we are simply
1419 : // initializing the root empty weak cell.
1420 : DCHECK(GetHeap()->gc_state() == Heap::MARK_COMPACT ||
1421 : this == GetHeap()->empty_weak_cell());
1422 2673051 : WRITE_FIELD(this, kValueOffset, Smi::kZero);
1423 : }
1424 :
1425 :
1426 29978179 : void WeakCell::initialize(HeapObject* val) {
1427 29978179 : WRITE_FIELD(this, kValueOffset, val);
1428 : // We just have to execute the generational barrier here because we never
1429 : // mark through a weak cell and collect evacuation candidates when we process
1430 : // all weak cells.
1431 3726164 : Heap* heap = val->GetHeap();
1432 : WriteBarrierMode mode =
1433 : heap->incremental_marking()->marking_state()->IsBlack(this)
1434 : ? UPDATE_WRITE_BARRIER
1435 29978178 : : UPDATE_WEAK_WRITE_BARRIER;
1436 59956359 : CONDITIONAL_WRITE_BARRIER(heap, this, kValueOffset, val, mode);
1437 29978178 : }
1438 :
1439 44482432 : bool WeakCell::cleared() const { return value() == Smi::kZero; }
1440 :
1441 34570276 : int JSObject::GetHeaderSize() const { return GetHeaderSize(map()); }
1442 :
1443 19061478 : int JSObject::GetHeaderSize(const Map* map) {
1444 : // Check for the most common kind of JavaScript object before
1445 : // falling into the generic switch. This speeds up the internal
1446 : // field operations considerably on average.
1447 : InstanceType instance_type = map->instance_type();
1448 : return instance_type == JS_OBJECT_TYPE
1449 : ? JSObject::kHeaderSize
1450 25880416 : : GetHeaderSize(instance_type, map->has_prototype_slot());
1451 : }
1452 :
1453 : inline bool IsSpecialReceiverInstanceType(InstanceType instance_type) {
1454 10771 : return instance_type <= LAST_SPECIAL_RECEIVER_TYPE;
1455 : }
1456 :
1457 : // static
1458 1776287 : int JSObject::GetEmbedderFieldCount(const Map* map) {
1459 : int instance_size = map->instance_size();
1460 1776287 : if (instance_size == kVariableSizeSentinel) return 0;
1461 1776287 : return ((instance_size - GetHeaderSize(map)) >> kPointerSizeLog2) -
1462 1776287 : map->GetInObjectProperties();
1463 : }
1464 :
1465 662814 : int JSObject::GetEmbedderFieldCount() const {
1466 662814 : return GetEmbedderFieldCount(map());
1467 : }
1468 :
1469 : int JSObject::GetEmbedderFieldOffset(int index) {
1470 : DCHECK(index < GetEmbedderFieldCount() && index >= 0);
1471 130 : return GetHeaderSize() + (kPointerSize * index);
1472 : }
1473 :
1474 23 : Object* JSObject::GetEmbedderField(int index) {
1475 : DCHECK(index < GetEmbedderFieldCount() && index >= 0);
1476 : // Internal objects do follow immediately after the header, whereas in-object
1477 : // properties are at the end of the object. Therefore there is no need
1478 : // to adjust the index here.
1479 11364043 : return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index));
1480 : }
1481 :
1482 9122 : void JSObject::SetEmbedderField(int index, Object* value) {
1483 : DCHECK(index < GetEmbedderFieldCount() && index >= 0);
1484 : // Internal objects do follow immediately after the header, whereas in-object
1485 : // properties are at the end of the object. Therefore there is no need
1486 : // to adjust the index here.
1487 9122 : int offset = GetHeaderSize() + (kPointerSize * index);
1488 9122 : WRITE_FIELD(this, offset, value);
1489 18244 : WRITE_BARRIER(GetHeap(), this, offset, value);
1490 9122 : }
1491 :
1492 517957 : void JSObject::SetEmbedderField(int index, Smi* value) {
1493 : DCHECK(index < GetEmbedderFieldCount() && index >= 0);
1494 : // Internal objects do follow immediately after the header, whereas in-object
1495 : // properties are at the end of the object. Therefore there is no need
1496 : // to adjust the index here.
1497 517957 : int offset = GetHeaderSize() + (kPointerSize * index);
1498 517957 : WRITE_FIELD(this, offset, value);
1499 517957 : }
1500 :
1501 :
1502 81758614 : bool JSObject::IsUnboxedDoubleField(FieldIndex index) {
1503 : if (!FLAG_unbox_double_fields) return false;
1504 81758614 : return map()->IsUnboxedDoubleField(index);
1505 : }
1506 :
1507 84172323 : bool Map::IsUnboxedDoubleField(FieldIndex index) const {
1508 : if (!FLAG_unbox_double_fields) return false;
1509 168344646 : if (index.is_hidden_field() || !index.is_inobject()) return false;
1510 32649650 : return !layout_descriptor()->IsTagged(index.property_index());
1511 : }
1512 :
1513 :
1514 : // Access fast-case object properties at index. The use of these routines
1515 : // is needed to correctly distinguish between properties stored in-object and
1516 : // properties stored in the properties array.
1517 81574922 : Object* JSObject::RawFastPropertyAt(FieldIndex index) {
1518 : DCHECK(!IsUnboxedDoubleField(index));
1519 81574922 : if (index.is_inobject()) {
1520 30037552 : return READ_FIELD(this, index.offset());
1521 : } else {
1522 51537370 : return property_array()->get(index.outobject_array_index());
1523 : }
1524 : }
1525 :
1526 :
1527 : double JSObject::RawFastDoublePropertyAt(FieldIndex index) {
1528 : DCHECK(IsUnboxedDoubleField(index));
1529 35246 : return READ_DOUBLE_FIELD(this, index.offset());
1530 : }
1531 :
1532 : uint64_t JSObject::RawFastDoublePropertyAsBitsAt(FieldIndex index) {
1533 : DCHECK(IsUnboxedDoubleField(index));
1534 5087 : return READ_UINT64_FIELD(this, index.offset());
1535 : }
1536 :
1537 61752188 : void JSObject::RawFastPropertyAtPut(FieldIndex index, Object* value) {
1538 61752188 : if (index.is_inobject()) {
1539 : int offset = index.offset();
1540 34858046 : WRITE_FIELD(this, offset, value);
1541 69716093 : WRITE_BARRIER(GetHeap(), this, offset, value);
1542 : } else {
1543 26894142 : property_array()->set(index.outobject_array_index(), value);
1544 : }
1545 61752187 : }
1546 :
1547 : void JSObject::RawFastDoublePropertyAsBitsAtPut(FieldIndex index,
1548 : uint64_t bits) {
1549 : // Double unboxing is enabled only on 64-bit platforms.
1550 : DCHECK_EQ(kDoubleSize, kPointerSize);
1551 51967 : Address field_addr = FIELD_ADDR(this, index.offset());
1552 : base::Relaxed_Store(reinterpret_cast<base::AtomicWord*>(field_addr),
1553 : static_cast<base::AtomicWord>(bits));
1554 : }
1555 :
1556 457510 : void JSObject::FastPropertyAtPut(FieldIndex index, Object* value) {
1557 457510 : if (IsUnboxedDoubleField(index)) {
1558 : DCHECK(value->IsMutableHeapNumber());
1559 : // Ensure that all bits of the double value are preserved.
1560 : RawFastDoublePropertyAsBitsAtPut(index,
1561 : HeapNumber::cast(value)->value_as_bits());
1562 : } else {
1563 457504 : RawFastPropertyAtPut(index, value);
1564 : }
1565 457510 : }
1566 :
1567 47477762 : void JSObject::WriteToField(int descriptor, PropertyDetails details,
1568 : Object* value) {
1569 : DCHECK_EQ(kField, details.location());
1570 : DCHECK_EQ(kData, details.kind());
1571 : DisallowHeapAllocation no_gc;
1572 47477762 : FieldIndex index = FieldIndex::ForDescriptor(map(), descriptor);
1573 47477763 : if (details.representation().IsDouble()) {
1574 : // Nothing more to be done.
1575 54765 : if (value->IsUninitialized(this->GetIsolate())) {
1576 845 : return;
1577 : }
1578 : // Manipulating the signaling NaN used for the hole and uninitialized
1579 : // double field sentinel in C++, e.g. with bit_cast or value()/set_value(),
1580 : // will change its value on ia32 (the x87 stack is used to return values
1581 : // and stores to the stack silently clear the signalling bit).
1582 : uint64_t bits;
1583 53920 : if (value->IsSmi()) {
1584 6218 : bits = bit_cast<uint64_t>(static_cast<double>(Smi::ToInt(value)));
1585 : } else {
1586 : DCHECK(value->IsHeapNumber());
1587 : bits = HeapNumber::cast(value)->value_as_bits();
1588 : }
1589 53920 : if (IsUnboxedDoubleField(index)) {
1590 : RawFastDoublePropertyAsBitsAtPut(index, bits);
1591 : } else {
1592 8483 : HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(index));
1593 : DCHECK(box->IsMutableHeapNumber());
1594 : box->set_value_as_bits(bits);
1595 : }
1596 : } else {
1597 47422998 : RawFastPropertyAtPut(index, value);
1598 : }
1599 : }
1600 :
1601 847945 : int JSObject::GetInObjectPropertyOffset(int index) {
1602 847945 : return map()->GetInObjectPropertyOffset(index);
1603 : }
1604 :
1605 :
1606 : Object* JSObject::InObjectPropertyAt(int index) {
1607 270238 : int offset = GetInObjectPropertyOffset(index);
1608 270238 : return READ_FIELD(this, offset);
1609 : }
1610 :
1611 :
1612 577707 : Object* JSObject::InObjectPropertyAtPut(int index,
1613 : Object* value,
1614 : WriteBarrierMode mode) {
1615 : // Adjust for the number of properties stored in the object.
1616 577707 : int offset = GetInObjectPropertyOffset(index);
1617 577707 : WRITE_FIELD(this, offset, value);
1618 701717 : CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode);
1619 577707 : return value;
1620 : }
1621 :
1622 :
1623 23512367 : void JSObject::InitializeBody(Map* map, int start_offset,
1624 : Object* pre_allocated_value,
1625 : Object* filler_value) {
1626 : DCHECK(!filler_value->IsHeapObject() ||
1627 : !GetHeap()->InNewSpace(filler_value));
1628 : DCHECK(!pre_allocated_value->IsHeapObject() ||
1629 : !GetHeap()->InNewSpace(pre_allocated_value));
1630 : int size = map->instance_size();
1631 : int offset = start_offset;
1632 23512367 : if (filler_value != pre_allocated_value) {
1633 : int end_of_pre_allocated_offset =
1634 252230 : size - (map->UnusedPropertyFields() * kPointerSize);
1635 : DCHECK_LE(kHeaderSize, end_of_pre_allocated_offset);
1636 612118 : while (offset < end_of_pre_allocated_offset) {
1637 107658 : WRITE_FIELD(this, offset, pre_allocated_value);
1638 107658 : offset += kPointerSize;
1639 : }
1640 : }
1641 89847065 : while (offset < size) {
1642 66334698 : WRITE_FIELD(this, offset, filler_value);
1643 66334698 : offset += kPointerSize;
1644 : }
1645 23512367 : }
1646 :
1647 7125404 : bool Map::TooManyFastProperties(StoreFromKeyed store_mode) const {
1648 7125404 : if (UnusedPropertyFields() != 0) return false;
1649 1446736 : if (is_prototype_map()) return false;
1650 1315966 : int minimum = store_mode == CERTAINLY_NOT_STORE_FROM_KEYED ? 128 : 12;
1651 : int limit = Max(minimum, GetInObjectProperties());
1652 2631932 : int external = NumberOfFields() - GetInObjectProperties();
1653 1315966 : return external > limit;
1654 : }
1655 :
1656 :
1657 11643829 : void Struct::InitializeBody(int object_size) {
1658 11643829 : Object* value = GetHeap()->undefined_value();
1659 119592927 : for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
1660 107949098 : WRITE_FIELD(this, offset, value);
1661 : }
1662 11643829 : }
1663 :
1664 19001 : bool Object::ToArrayLength(uint32_t* index) const {
1665 6183313 : return Object::ToUint32(index);
1666 : }
1667 :
1668 24108 : bool Object::ToArrayIndex(uint32_t* index) const {
1669 84639923 : return Object::ToUint32(index) && *index != kMaxUInt32;
1670 : }
1671 :
1672 :
1673 : void Object::VerifyApiCallResultType() {
1674 : #if DEBUG
1675 : if (IsSmi()) return;
1676 : DCHECK(IsHeapObject());
1677 : Isolate* isolate = HeapObject::cast(this)->GetIsolate();
1678 : if (!(IsString() || IsSymbol() || IsJSReceiver() || IsHeapNumber() ||
1679 : IsUndefined(isolate) || IsTrue(isolate) || IsFalse(isolate) ||
1680 : IsNull(isolate))) {
1681 : FATAL("API call returned invalid object");
1682 : }
1683 : #endif // DEBUG
1684 : }
1685 :
1686 :
1687 91438520 : Object* FixedArray::get(int index) const {
1688 : SLOW_DCHECK(index >= 0 && index < this->length());
1689 22714289714 : return RELAXED_READ_FIELD(this, kHeaderSize + index * kPointerSize);
1690 : }
1691 :
1692 : Object* PropertyArray::get(int index) const {
1693 : DCHECK_GE(index, 0);
1694 : DCHECK_LE(index, this->length());
1695 193152864 : return RELAXED_READ_FIELD(this, kHeaderSize + index * kPointerSize);
1696 : }
1697 :
1698 14026535 : Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) {
1699 14026537 : return handle(array->get(index), isolate);
1700 : }
1701 :
1702 : template <class T>
1703 4222879 : MaybeHandle<T> FixedArray::GetValue(Isolate* isolate, int index) const {
1704 : Object* obj = get(index);
1705 4222879 : if (obj->IsUndefined(isolate)) return MaybeHandle<T>();
1706 1035595 : return Handle<T>(T::cast(obj), isolate);
1707 : }
1708 :
1709 : template <class T>
1710 791654 : Handle<T> FixedArray::GetValueChecked(Isolate* isolate, int index) const {
1711 : Object* obj = get(index);
1712 791654 : CHECK(!obj->IsUndefined(isolate));
1713 791654 : return Handle<T>(T::cast(obj), isolate);
1714 : }
1715 446109651 : bool FixedArray::is_the_hole(Isolate* isolate, int index) {
1716 446109651 : return get(index)->IsTheHole(isolate);
1717 : }
1718 :
1719 121139 : void FixedArray::set(int index, Smi* value) {
1720 : DCHECK_NE(map(), GetHeap()->fixed_cow_array_map());
1721 : DCHECK_LT(index, this->length());
1722 : DCHECK(reinterpret_cast<Object*>(value)->IsSmi());
1723 1116034044 : int offset = kHeaderSize + index * kPointerSize;
1724 1281213454 : RELAXED_WRITE_FIELD(this, offset, value);
1725 121139 : }
1726 :
1727 859746930 : void FixedArray::set(int index, Object* value) {
1728 : DCHECK_NE(GetHeap()->fixed_cow_array_map(), map());
1729 : DCHECK(IsFixedArray() || IsTransitionArray());
1730 : DCHECK_GE(index, 0);
1731 : DCHECK_LT(index, this->length());
1732 859746930 : int offset = kHeaderSize + index * kPointerSize;
1733 859746930 : RELAXED_WRITE_FIELD(this, offset, value);
1734 1719493854 : WRITE_BARRIER(GetHeap(), this, offset, value);
1735 859746958 : }
1736 :
1737 72580995 : void PropertyArray::set(int index, Object* value) {
1738 : DCHECK(IsPropertyArray());
1739 : DCHECK_GE(index, 0);
1740 : DCHECK_LT(index, this->length());
1741 72580995 : int offset = kHeaderSize + index * kPointerSize;
1742 72580995 : RELAXED_WRITE_FIELD(this, offset, value);
1743 145161990 : WRITE_BARRIER(GetHeap(), this, offset, value);
1744 72580994 : }
1745 :
1746 135910 : double FixedDoubleArray::get_scalar(int index) {
1747 : DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
1748 : map() != GetHeap()->fixed_array_map());
1749 : DCHECK(index >= 0 && index < this->length());
1750 : DCHECK(!is_the_hole(index));
1751 8778804 : return READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize);
1752 : }
1753 :
1754 :
1755 : uint64_t FixedDoubleArray::get_representation(int index) {
1756 : DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
1757 : map() != GetHeap()->fixed_array_map());
1758 : DCHECK(index >= 0 && index < this->length());
1759 19870144 : int offset = kHeaderSize + index * kDoubleSize;
1760 19870144 : return READ_UINT64_FIELD(this, offset);
1761 : }
1762 :
1763 9881902 : Handle<Object> FixedDoubleArray::get(FixedDoubleArray* array, int index,
1764 : Isolate* isolate) {
1765 9881902 : if (array->is_the_hole(index)) {
1766 1497945 : return isolate->factory()->the_hole_value();
1767 : } else {
1768 8383957 : return isolate->factory()->NewNumber(array->get_scalar(index));
1769 : }
1770 : }
1771 :
1772 :
1773 4358912 : void FixedDoubleArray::set(int index, double value) {
1774 : DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
1775 : map() != GetHeap()->fixed_array_map());
1776 12815158 : int offset = kHeaderSize + index * kDoubleSize;
1777 12815158 : if (std::isnan(value)) {
1778 122221 : WRITE_DOUBLE_FIELD(this, offset, std::numeric_limits<double>::quiet_NaN());
1779 : } else {
1780 12692937 : WRITE_DOUBLE_FIELD(this, offset, value);
1781 : }
1782 : DCHECK(!is_the_hole(index));
1783 4358912 : }
1784 :
1785 : void FixedDoubleArray::set_the_hole(Isolate* isolate, int index) {
1786 : set_the_hole(index);
1787 : }
1788 :
1789 : void FixedDoubleArray::set_the_hole(int index) {
1790 : DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
1791 : map() != GetHeap()->fixed_array_map());
1792 71772826 : int offset = kHeaderSize + index * kDoubleSize;
1793 71772826 : WRITE_UINT64_FIELD(this, offset, kHoleNanInt64);
1794 : }
1795 :
1796 : bool FixedDoubleArray::is_the_hole(Isolate* isolate, int index) {
1797 : return is_the_hole(index);
1798 : }
1799 :
1800 : bool FixedDoubleArray::is_the_hole(int index) {
1801 : return get_representation(index) == kHoleNanInt64;
1802 : }
1803 :
1804 :
1805 : double* FixedDoubleArray::data_start() {
1806 : return reinterpret_cast<double*>(FIELD_ADDR(this, kHeaderSize));
1807 : }
1808 :
1809 :
1810 : void FixedDoubleArray::FillWithHoles(int from, int to) {
1811 425721 : for (int i = from; i < to; i++) {
1812 : set_the_hole(i);
1813 : }
1814 : }
1815 :
1816 64028188 : Object* WeakFixedArray::Get(int index) const {
1817 64028188 : Object* raw = FixedArray::cast(this)->get(index + kFirstIndex);
1818 64028188 : if (raw->IsSmi()) return raw;
1819 : DCHECK(raw->IsWeakCell());
1820 52749922 : return WeakCell::cast(raw)->value();
1821 : }
1822 :
1823 :
1824 : bool WeakFixedArray::IsEmptySlot(int index) const {
1825 : DCHECK(index < Length());
1826 54377260 : return Get(index)->IsSmi();
1827 : }
1828 :
1829 :
1830 : void WeakFixedArray::Clear(int index) {
1831 : FixedArray::cast(this)->set(index + kFirstIndex, Smi::kZero);
1832 : }
1833 :
1834 :
1835 : int WeakFixedArray::Length() const {
1836 16156049 : return FixedArray::cast(this)->length() - kFirstIndex;
1837 : }
1838 :
1839 :
1840 : int WeakFixedArray::last_used_index() const {
1841 : return Smi::ToInt(FixedArray::cast(this)->get(kLastUsedIndexIndex));
1842 : }
1843 :
1844 :
1845 : void WeakFixedArray::set_last_used_index(int index) {
1846 : FixedArray::cast(this)->set(kLastUsedIndexIndex, Smi::FromInt(index));
1847 : }
1848 :
1849 :
1850 : template <class T>
1851 3634689 : T* WeakFixedArray::Iterator::Next() {
1852 3634689 : if (list_ != nullptr) {
1853 : // Assert that list did not change during iteration.
1854 : DCHECK_EQ(last_used_index_, list_->last_used_index());
1855 7930020 : while (index_ < list_->Length()) {
1856 3850090 : Object* item = list_->Get(index_++);
1857 3850090 : if (item != Empty()) return T::cast(item);
1858 : }
1859 114920 : list_ = nullptr;
1860 : }
1861 : return nullptr;
1862 : }
1863 :
1864 933056 : int ArrayList::Length() const {
1865 933056 : if (FixedArray::cast(this)->length() == 0) return 0;
1866 898738 : return Smi::ToInt(FixedArray::cast(this)->get(kLengthIndex));
1867 : }
1868 :
1869 :
1870 : void ArrayList::SetLength(int length) {
1871 : return FixedArray::cast(this)->set(kLengthIndex, Smi::FromInt(length));
1872 : }
1873 :
1874 : Object* ArrayList::Get(int index) const {
1875 835957 : return FixedArray::cast(this)->get(kFirstIndex + index);
1876 : }
1877 :
1878 :
1879 : Object** ArrayList::Slot(int index) {
1880 488284 : return data_start() + kFirstIndex + index;
1881 : }
1882 :
1883 : void ArrayList::Set(int index, Object* obj, WriteBarrierMode mode) {
1884 1276223 : FixedArray::cast(this)->set(kFirstIndex + index, obj, mode);
1885 : }
1886 :
1887 :
1888 : void ArrayList::Clear(int index, Object* undefined) {
1889 : DCHECK(undefined->IsUndefined(GetIsolate()));
1890 : FixedArray::cast(this)
1891 6524 : ->set(kFirstIndex + index, undefined, SKIP_WRITE_BARRIER);
1892 : }
1893 :
1894 293 : int RegExpMatchInfo::NumberOfCaptureRegisters() {
1895 : DCHECK_GE(length(), kLastMatchOverhead);
1896 : Object* obj = get(kNumberOfCapturesIndex);
1897 293 : return Smi::ToInt(obj);
1898 : }
1899 :
1900 : void RegExpMatchInfo::SetNumberOfCaptureRegisters(int value) {
1901 : DCHECK_GE(length(), kLastMatchOverhead);
1902 : set(kNumberOfCapturesIndex, Smi::FromInt(value));
1903 : }
1904 :
1905 : String* RegExpMatchInfo::LastSubject() {
1906 : DCHECK_GE(length(), kLastMatchOverhead);
1907 : Object* obj = get(kLastSubjectIndex);
1908 : return String::cast(obj);
1909 : }
1910 :
1911 : void RegExpMatchInfo::SetLastSubject(String* value) {
1912 : DCHECK_GE(length(), kLastMatchOverhead);
1913 309485 : set(kLastSubjectIndex, value);
1914 : }
1915 :
1916 : Object* RegExpMatchInfo::LastInput() {
1917 : DCHECK_GE(length(), kLastMatchOverhead);
1918 : return get(kLastInputIndex);
1919 : }
1920 :
1921 : void RegExpMatchInfo::SetLastInput(Object* value) {
1922 : DCHECK_GE(length(), kLastMatchOverhead);
1923 309531 : set(kLastInputIndex, value);
1924 : }
1925 :
1926 586 : int RegExpMatchInfo::Capture(int i) {
1927 : DCHECK_LT(i, NumberOfCaptureRegisters());
1928 566082 : Object* obj = get(kFirstCaptureIndex + i);
1929 586 : return Smi::ToInt(obj);
1930 : }
1931 :
1932 : void RegExpMatchInfo::SetCapture(int i, int value) {
1933 : DCHECK_LT(i, NumberOfCaptureRegisters());
1934 : set(kFirstCaptureIndex + i, Smi::FromInt(value));
1935 : }
1936 :
1937 47369165 : WriteBarrierMode HeapObject::GetWriteBarrierMode(
1938 : const DisallowHeapAllocation& promise) {
1939 47369165 : Heap* heap = GetHeap();
1940 47369165 : if (heap->incremental_marking()->IsMarking()) return UPDATE_WRITE_BARRIER;
1941 42548548 : if (heap->InNewSpace(this)) return SKIP_WRITE_BARRIER;
1942 : return UPDATE_WRITE_BARRIER;
1943 : }
1944 :
1945 106757550 : AllocationAlignment HeapObject::RequiredAlignment() const {
1946 : #ifdef V8_HOST_ARCH_32_BIT
1947 : if ((IsFixedFloat64Array() || IsFixedDoubleArray()) &&
1948 : FixedArrayBase::cast(this)->length() != 0) {
1949 : return kDoubleAligned;
1950 : }
1951 : if (IsHeapNumber()) return kDoubleUnaligned;
1952 : #endif // V8_HOST_ARCH_32_BIT
1953 106757550 : return kWordAligned;
1954 : }
1955 :
1956 :
1957 1014849019 : void FixedArray::set(int index,
1958 : Object* value,
1959 : WriteBarrierMode mode) {
1960 : DCHECK_NE(map(), GetHeap()->fixed_cow_array_map());
1961 : DCHECK_GE(index, 0);
1962 : DCHECK_LT(index, this->length());
1963 1014849019 : int offset = kHeaderSize + index * kPointerSize;
1964 1014849019 : RELAXED_WRITE_FIELD(this, offset, value);
1965 1945851945 : CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode);
1966 1014849082 : }
1967 :
1968 45039062 : void PropertyArray::set(int index, Object* value, WriteBarrierMode mode) {
1969 : DCHECK_GE(index, 0);
1970 : DCHECK_LT(index, this->length());
1971 45039062 : int offset = kHeaderSize + index * kPointerSize;
1972 45039062 : RELAXED_WRITE_FIELD(this, offset, value);
1973 66705076 : CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode);
1974 45039062 : }
1975 :
1976 : void FixedArray::NoWriteBarrierSet(FixedArray* array,
1977 : int index,
1978 : Object* value) {
1979 : DCHECK_NE(array->map(), array->GetHeap()->fixed_cow_array_map());
1980 : DCHECK_GE(index, 0);
1981 : DCHECK_LT(index, array->length());
1982 : DCHECK(!array->GetHeap()->InNewSpace(value));
1983 283393674 : RELAXED_WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value);
1984 : }
1985 :
1986 264753725 : void FixedArray::set_undefined(int index) {
1987 : set_undefined(GetIsolate(), index);
1988 264753725 : }
1989 :
1990 : void FixedArray::set_undefined(Isolate* isolate, int index) {
1991 : FixedArray::NoWriteBarrierSet(this, index,
1992 264755252 : isolate->heap()->undefined_value());
1993 : }
1994 :
1995 1078 : void FixedArray::set_null(int index) { set_null(GetIsolate(), index); }
1996 :
1997 : void FixedArray::set_null(Isolate* isolate, int index) {
1998 539 : FixedArray::NoWriteBarrierSet(this, index, isolate->heap()->null_value());
1999 : }
2000 :
2001 1350 : void FixedArray::set_the_hole(int index) { set_the_hole(GetIsolate(), index); }
2002 :
2003 0 : void FixedArray::set_the_hole(Isolate* isolate, int index) {
2004 18613661 : FixedArray::NoWriteBarrierSet(this, index, isolate->heap()->the_hole_value());
2005 0 : }
2006 :
2007 1260252 : void FixedArray::FillWithHoles(int from, int to) {
2008 : Isolate* isolate = GetIsolate();
2009 11228510 : for (int i = from; i < to; i++) {
2010 : set_the_hole(isolate, i);
2011 : }
2012 1260252 : }
2013 :
2014 :
2015 0 : Object** FixedArray::data_start() {
2016 0 : return HeapObject::RawField(this, kHeaderSize);
2017 : }
2018 :
2019 : Object** PropertyArray::data_start() {
2020 : return HeapObject::RawField(this, kHeaderSize);
2021 : }
2022 :
2023 : Object** FixedArray::RawFieldOfElementAt(int index) {
2024 : return HeapObject::RawField(this, OffsetOfElementAt(index));
2025 : }
2026 :
2027 9249972 : ACCESSORS(EnumCache, keys, FixedArray, kKeysOffset)
2028 31973 : ACCESSORS(EnumCache, indices, FixedArray, kIndicesOffset)
2029 :
2030 : int DescriptorArray::number_of_descriptors() {
2031 : return Smi::ToInt(get(kDescriptorLengthIndex));
2032 : }
2033 :
2034 :
2035 : int DescriptorArray::number_of_descriptors_storage() {
2036 7244003 : return (length() - kFirstIndex) / kEntrySize;
2037 : }
2038 :
2039 :
2040 7240952 : int DescriptorArray::NumberOfSlackDescriptors() {
2041 7240952 : return number_of_descriptors_storage() - number_of_descriptors();
2042 : }
2043 :
2044 :
2045 : void DescriptorArray::SetNumberOfDescriptors(int number_of_descriptors) {
2046 : set(kDescriptorLengthIndex, Smi::FromInt(number_of_descriptors));
2047 : }
2048 :
2049 :
2050 : inline int DescriptorArray::number_of_entries() {
2051 : return number_of_descriptors();
2052 : }
2053 :
2054 2414523 : void DescriptorArray::CopyEnumCacheFrom(DescriptorArray* array) {
2055 2414523 : set(kEnumCacheIndex, array->get(kEnumCacheIndex));
2056 2414523 : }
2057 :
2058 : EnumCache* DescriptorArray::GetEnumCache() {
2059 : return EnumCache::cast(get(kEnumCacheIndex));
2060 : }
2061 :
2062 : // Perform a binary search in a fixed array.
2063 : template <SearchMode search_mode, typename T>
2064 25602703 : int BinarySearch(T* array, Name* name, int valid_entries,
2065 : int* out_insertion_index) {
2066 : DCHECK(search_mode == ALL_ENTRIES || out_insertion_index == nullptr);
2067 : int low = 0;
2068 25602703 : int high = array->number_of_entries() - 1;
2069 : uint32_t hash = name->hash_field();
2070 : int limit = high;
2071 :
2072 : DCHECK(low <= high);
2073 :
2074 156526424 : while (low != high) {
2075 105321028 : int mid = low + (high - low) / 2;
2076 79568062 : Name* mid_name = array->GetSortedKey(mid);
2077 : uint32_t mid_hash = mid_name->hash_field();
2078 :
2079 105321018 : if (mid_hash >= hash) {
2080 : high = mid;
2081 : } else {
2082 38932612 : low = mid + 1;
2083 : }
2084 : }
2085 :
2086 6578756 : for (; low <= limit; ++low) {
2087 : int sort_index = array->GetSortedKeyIndex(low);
2088 : Name* entry = array->GetKey(sort_index);
2089 : uint32_t current_hash = entry->hash_field();
2090 25602693 : if (current_hash != hash) {
2091 110519 : if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
2092 55140 : *out_insertion_index = sort_index + (current_hash > hash ? 0 : 1);
2093 : }
2094 : return T::kNotFound;
2095 : }
2096 10621462 : if (entry == name) {
2097 4153225 : if (search_mode == ALL_ENTRIES || sort_index < valid_entries) {
2098 3912741 : return sort_index;
2099 : }
2100 : return T::kNotFound;
2101 : }
2102 : }
2103 :
2104 0 : if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
2105 0 : *out_insertion_index = limit + 1;
2106 : }
2107 : return T::kNotFound;
2108 : }
2109 :
2110 :
2111 : // Perform a linear search in this fixed array. len is the number of entry
2112 : // indices that are valid.
2113 : template <SearchMode search_mode, typename T>
2114 56147505 : int LinearSearch(T* array, Name* name, int valid_entries,
2115 : int* out_insertion_index) {
2116 5953731 : if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
2117 : uint32_t hash = name->hash_field();
2118 : int len = array->number_of_entries();
2119 632952 : for (int number = 0; number < len; number++) {
2120 : int sorted_index = array->GetSortedKeyIndex(number);
2121 : Name* entry = array->GetKey(sorted_index);
2122 : uint32_t current_hash = entry->hash_field();
2123 379412 : if (current_hash > hash) {
2124 97395 : *out_insertion_index = sorted_index;
2125 97395 : return T::kNotFound;
2126 : }
2127 282017 : if (entry == name) return sorted_index;
2128 : }
2129 69066 : *out_insertion_index = len;
2130 69066 : return T::kNotFound;
2131 : } else {
2132 : DCHECK_LE(valid_entries, array->number_of_entries());
2133 : DCHECK_NULL(out_insertion_index); // Not supported here.
2134 132963241 : for (int number = 0; number < valid_entries; number++) {
2135 157111945 : if (array->GetKey(number) == name) return number;
2136 : }
2137 : return T::kNotFound;
2138 : }
2139 : }
2140 :
2141 :
2142 : template <SearchMode search_mode, typename T>
2143 82006742 : int Search(T* array, Name* name, int valid_entries, int* out_insertion_index) {
2144 : SLOW_DCHECK(array->IsSortedNoDuplicates());
2145 :
2146 82006742 : if (valid_entries == 0) {
2147 256553 : if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
2148 244187 : *out_insertion_index = 0;
2149 : }
2150 : return T::kNotFound;
2151 : }
2152 :
2153 : // Fast case: do linear search for small arrays.
2154 : const int kMaxElementsForLinearSearch = 8;
2155 81750198 : if (valid_entries <= kMaxElementsForLinearSearch) {
2156 : return LinearSearch<search_mode>(array, name, valid_entries,
2157 56147504 : out_insertion_index);
2158 : }
2159 :
2160 : // Slow case: perform binary search.
2161 : return BinarySearch<search_mode>(array, name, valid_entries,
2162 25602694 : out_insertion_index);
2163 : }
2164 :
2165 :
2166 : int DescriptorArray::Search(Name* name, int valid_descriptors) {
2167 : DCHECK(name->IsUniqueName());
2168 : return internal::Search<VALID_ENTRIES>(this, name, valid_descriptors,
2169 69217701 : nullptr);
2170 : }
2171 :
2172 193623998 : int DescriptorArray::SearchWithCache(Isolate* isolate, Name* name, Map* map) {
2173 : DCHECK(name->IsUniqueName());
2174 213061929 : int number_of_own_descriptors = map->NumberOfOwnDescriptors();
2175 213061939 : if (number_of_own_descriptors == 0) return kNotFound;
2176 :
2177 193623998 : DescriptorLookupCache* cache = isolate->descriptor_lookup_cache();
2178 193623997 : int number = cache->Lookup(map, name);
2179 :
2180 193623998 : if (number == DescriptorLookupCache::kAbsent) {
2181 : number = Search(name, number_of_own_descriptors);
2182 69217704 : cache->Update(map, name, number);
2183 : }
2184 :
2185 : return number;
2186 : }
2187 :
2188 : PropertyDetails Map::GetLastDescriptorDetails() const {
2189 73234433 : return instance_descriptors()->GetDetails(LastAdded());
2190 : }
2191 :
2192 : int Map::LastAdded() const {
2193 : int number_of_own_descriptors = NumberOfOwnDescriptors();
2194 : DCHECK_GT(number_of_own_descriptors, 0);
2195 126937085 : return number_of_own_descriptors - 1;
2196 : }
2197 :
2198 237058487 : int Map::NumberOfOwnDescriptors() const {
2199 237058487 : return NumberOfOwnDescriptorsBits::decode(bit_field3());
2200 : }
2201 :
2202 :
2203 : void Map::SetNumberOfOwnDescriptors(int number) {
2204 : DCHECK(number <= instance_descriptors()->number_of_descriptors());
2205 : set_bit_field3(NumberOfOwnDescriptorsBits::update(bit_field3(), number));
2206 : }
2207 :
2208 : int Map::EnumLength() const { return EnumLengthBits::decode(bit_field3()); }
2209 :
2210 : void Map::SetEnumLength(int length) {
2211 : if (length != kInvalidEnumCacheSentinel) {
2212 : DCHECK_GE(length, 0);
2213 : DCHECK(length <= NumberOfOwnDescriptors());
2214 : }
2215 : set_bit_field3(EnumLengthBits::update(bit_field3(), length));
2216 : }
2217 :
2218 41251779 : FixedArrayBase* Map::GetInitialElements() const {
2219 : FixedArrayBase* result = nullptr;
2220 41251779 : if (has_fast_elements() || has_fast_string_wrapper_elements()) {
2221 41245178 : result = GetHeap()->empty_fixed_array();
2222 6601 : } else if (has_fast_sloppy_arguments_elements()) {
2223 16 : result = GetHeap()->empty_sloppy_arguments_elements();
2224 6585 : } else if (has_fixed_typed_array_elements()) {
2225 0 : result = GetHeap()->EmptyFixedTypedArrayForMap(this);
2226 3607 : } else if (has_dictionary_elements()) {
2227 3607 : result = GetHeap()->empty_slow_element_dictionary();
2228 : } else {
2229 0 : UNREACHABLE();
2230 : }
2231 : DCHECK(!GetHeap()->InNewSpace(result));
2232 41251779 : return result;
2233 : }
2234 :
2235 : Object** DescriptorArray::GetKeySlot(int descriptor_number) {
2236 : DCHECK(descriptor_number < number_of_descriptors());
2237 : return RawFieldOfElementAt(ToKeyIndex(descriptor_number));
2238 : }
2239 :
2240 :
2241 14400950 : Object** DescriptorArray::GetDescriptorStartSlot(int descriptor_number) {
2242 14400950 : return GetKeySlot(descriptor_number);
2243 : }
2244 :
2245 :
2246 22136263 : Object** DescriptorArray::GetDescriptorEndSlot(int descriptor_number) {
2247 44272526 : return GetValueSlot(descriptor_number - 1) + 1;
2248 : }
2249 :
2250 :
2251 805383 : Name* DescriptorArray::GetKey(int descriptor_number) {
2252 : DCHECK(descriptor_number < number_of_descriptors());
2253 805383 : return Name::cast(get(ToKeyIndex(descriptor_number)));
2254 : }
2255 :
2256 :
2257 : int DescriptorArray::GetSortedKeyIndex(int descriptor_number) {
2258 2307610520 : return GetDetails(descriptor_number).pointer();
2259 : }
2260 :
2261 :
2262 667870588 : Name* DescriptorArray::GetSortedKey(int descriptor_number) {
2263 667871394 : return GetKey(GetSortedKeyIndex(descriptor_number));
2264 : }
2265 :
2266 :
2267 680315286 : void DescriptorArray::SetSortedKey(int descriptor_index, int pointer) {
2268 680315286 : PropertyDetails details = GetDetails(descriptor_index);
2269 : set(ToDetailsIndex(descriptor_index), details.set_pointer(pointer).AsSmi());
2270 680315778 : }
2271 :
2272 :
2273 : Object** DescriptorArray::GetValueSlot(int descriptor_number) {
2274 : DCHECK(descriptor_number < number_of_descriptors());
2275 : return RawFieldOfElementAt(ToValueIndex(descriptor_number));
2276 : }
2277 :
2278 :
2279 : int DescriptorArray::GetValueOffset(int descriptor_number) {
2280 : return OffsetOfElementAt(ToValueIndex(descriptor_number));
2281 : }
2282 :
2283 :
2284 : Object* DescriptorArray::GetValue(int descriptor_number) {
2285 : DCHECK(descriptor_number < number_of_descriptors());
2286 : return get(ToValueIndex(descriptor_number));
2287 : }
2288 :
2289 :
2290 : void DescriptorArray::SetValue(int descriptor_index, Object* value) {
2291 142549 : set(ToValueIndex(descriptor_index), value);
2292 : }
2293 :
2294 :
2295 3265408554 : PropertyDetails DescriptorArray::GetDetails(int descriptor_number) {
2296 : DCHECK(descriptor_number < number_of_descriptors());
2297 : Object* details = get(ToDetailsIndex(descriptor_number));
2298 3265408554 : return PropertyDetails(Smi::cast(details));
2299 : }
2300 :
2301 : int DescriptorArray::GetFieldIndex(int descriptor_number) {
2302 : DCHECK_EQ(GetDetails(descriptor_number).location(), kField);
2303 91708476 : return GetDetails(descriptor_number).field_index();
2304 : }
2305 :
2306 40094357 : FieldType* DescriptorArray::GetFieldType(int descriptor_number) {
2307 : DCHECK_EQ(GetDetails(descriptor_number).location(), kField);
2308 : Object* wrapped_type = GetValue(descriptor_number);
2309 40094357 : return Map::UnwrapFieldType(wrapped_type);
2310 : }
2311 :
2312 : void DescriptorArray::Get(int descriptor_number, Descriptor* desc) {
2313 : desc->Init(handle(GetKey(descriptor_number), GetIsolate()),
2314 : handle(GetValue(descriptor_number), GetIsolate()),
2315 : GetDetails(descriptor_number));
2316 : }
2317 :
2318 122953633 : void DescriptorArray::Set(int descriptor_number, Name* key, Object* value,
2319 : PropertyDetails details) {
2320 : // Range check.
2321 : DCHECK(descriptor_number < number_of_descriptors());
2322 122953633 : set(ToKeyIndex(descriptor_number), key);
2323 122953630 : set(ToValueIndex(descriptor_number), value);
2324 : set(ToDetailsIndex(descriptor_number), details.AsSmi());
2325 122953626 : }
2326 :
2327 18202573 : void DescriptorArray::Set(int descriptor_number, Descriptor* desc) {
2328 : Name* key = *desc->GetKey();
2329 : Object* value = *desc->GetValue();
2330 18202573 : Set(descriptor_number, key, value, desc->GetDetails());
2331 18202568 : }
2332 :
2333 :
2334 15515264 : void DescriptorArray::Append(Descriptor* desc) {
2335 : DisallowHeapAllocation no_gc;
2336 : int descriptor_number = number_of_descriptors();
2337 15515264 : SetNumberOfDescriptors(descriptor_number + 1);
2338 15515264 : Set(descriptor_number, desc);
2339 :
2340 : uint32_t hash = desc->GetKey()->Hash();
2341 :
2342 : int insertion;
2343 :
2344 158354217 : for (insertion = descriptor_number; insertion > 0; --insertion) {
2345 136427374 : Name* key = GetSortedKey(insertion - 1);
2346 136427372 : if (key->Hash() <= hash) break;
2347 127323692 : SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1));
2348 : }
2349 :
2350 15515264 : SetSortedKey(insertion, descriptor_number);
2351 15515264 : }
2352 :
2353 :
2354 226171221 : void DescriptorArray::SwapSortedKeys(int first, int second) {
2355 : int first_key = GetSortedKeyIndex(first);
2356 226171419 : SetSortedKey(first, GetSortedKeyIndex(second));
2357 226171452 : SetSortedKey(second, first_key);
2358 226171527 : }
2359 :
2360 969 : int HashTableBase::NumberOfElements() const {
2361 969 : return Smi::ToInt(get(kNumberOfElementsIndex));
2362 : }
2363 :
2364 : int HashTableBase::NumberOfDeletedElements() const {
2365 : return Smi::ToInt(get(kNumberOfDeletedElementsIndex));
2366 : }
2367 :
2368 : int HashTableBase::Capacity() const { return Smi::ToInt(get(kCapacityIndex)); }
2369 :
2370 37558830 : void HashTableBase::ElementAdded() {
2371 37558830 : SetNumberOfElements(NumberOfElements() + 1);
2372 37558830 : }
2373 :
2374 :
2375 113417 : void HashTableBase::ElementRemoved() {
2376 113417 : SetNumberOfElements(NumberOfElements() - 1);
2377 113417 : SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2378 113417 : }
2379 :
2380 :
2381 56975 : void HashTableBase::ElementsRemoved(int n) {
2382 56975 : SetNumberOfElements(NumberOfElements() - n);
2383 56975 : SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2384 56975 : }
2385 :
2386 :
2387 : // static
2388 : int HashTableBase::ComputeCapacity(int at_least_space_for) {
2389 : // Add 50% slack to make slot collisions sufficiently unlikely.
2390 : // See matching computation in HashTable::HasSufficientCapacityToAdd().
2391 : // Must be kept in sync with CodeStubAssembler::HashTableComputeCapacity().
2392 2127846 : int raw_cap = at_least_space_for + (at_least_space_for >> 1);
2393 2127852 : int capacity = base::bits::RoundUpToPowerOfTwo32(raw_cap);
2394 : return Max(capacity, kMinCapacity);
2395 : }
2396 :
2397 : void HashTableBase::SetNumberOfElements(int nof) {
2398 : set(kNumberOfElementsIndex, Smi::FromInt(nof));
2399 : }
2400 :
2401 :
2402 : void HashTableBase::SetNumberOfDeletedElements(int nod) {
2403 : set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
2404 : }
2405 :
2406 : template <typename Key>
2407 : Map* BaseShape<Key>::GetMap(Isolate* isolate) {
2408 2118295 : return isolate->heap()->hash_table_map();
2409 : }
2410 :
2411 : template <typename Derived, typename Shape>
2412 2592 : int HashTable<Derived, Shape>::FindEntry(Key key) {
2413 133139460 : return FindEntry(GetIsolate(), key);
2414 : }
2415 :
2416 : template <typename Derived, typename Shape>
2417 227285703 : int HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key) {
2418 227288295 : return FindEntry(isolate, key, Shape::Hash(isolate, key));
2419 : }
2420 :
2421 : // Find entry for key otherwise return kNotFound.
2422 : template <typename Derived, typename Shape>
2423 227506112 : int HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key,
2424 : int32_t hash) {
2425 227506112 : uint32_t capacity = Capacity();
2426 227506112 : uint32_t entry = FirstProbe(hash, capacity);
2427 : uint32_t count = 1;
2428 : // EnsureCapacity will guarantee the hash table is never full.
2429 227506112 : Object* undefined = isolate->heap()->undefined_value();
2430 167722109 : Object* the_hole = isolate->heap()->the_hole_value();
2431 : USE(the_hole);
2432 : while (true) {
2433 403734811 : Object* element = KeyAt(entry);
2434 : // Empty entry. Uses raw unchecked accessors because it is called by the
2435 : // string table during bootstrapping.
2436 403734811 : if (element == undefined) break;
2437 192834916 : if (!(Shape::kNeedsHoleCheck && the_hole == element)) {
2438 254443061 : if (Shape::IsMatch(key, element)) return entry;
2439 : }
2440 176228699 : entry = NextProbe(entry, count++, capacity);
2441 : }
2442 176228699 : return kNotFound;
2443 : }
2444 :
2445 : bool ObjectHashSet::Has(Isolate* isolate, Handle<Object> key, int32_t hash) {
2446 59909 : return FindEntry(isolate, key, hash) != kNotFound;
2447 : }
2448 :
2449 12619 : bool ObjectHashSet::Has(Isolate* isolate, Handle<Object> key) {
2450 12619 : Object* hash = key->GetHash();
2451 12619 : if (!hash->IsSmi()) return false;
2452 12001 : return FindEntry(isolate, key, Smi::ToInt(hash)) != kNotFound;
2453 : }
2454 :
2455 : bool StringSetShape::IsMatch(String* key, Object* value) {
2456 : DCHECK(value->IsString());
2457 1830116 : return key->Equals(String::cast(value));
2458 : }
2459 :
2460 : uint32_t StringSetShape::Hash(Isolate* isolate, String* key) {
2461 : return key->Hash();
2462 : }
2463 :
2464 : uint32_t StringSetShape::HashForObject(Isolate* isolate, Object* object) {
2465 : return String::cast(object)->Hash();
2466 : }
2467 :
2468 : StringTableKey::StringTableKey(uint32_t hash_field)
2469 118536843 : : HashTableKey(hash_field >> Name::kHashShift), hash_field_(hash_field) {}
2470 :
2471 : void StringTableKey::set_hash_field(uint32_t hash_field) {
2472 12049613 : hash_field_ = hash_field;
2473 12049613 : set_hash(hash_field >> Name::kHashShift);
2474 : }
2475 :
2476 : Handle<Object> StringTableShape::AsHandle(Isolate* isolate,
2477 : StringTableKey* key) {
2478 : return key->AsHandle(isolate);
2479 : }
2480 :
2481 : uint32_t StringTableShape::HashForObject(Isolate* isolate, Object* object) {
2482 : return String::cast(object)->Hash();
2483 : }
2484 :
2485 3274099 : bool SeededNumberDictionary::requires_slow_elements() {
2486 : Object* max_index_object = get(kMaxNumberKeyIndex);
2487 3274099 : if (!max_index_object->IsSmi()) return false;
2488 2861629 : return 0 != (Smi::ToInt(max_index_object) & kRequiresSlowElementsMask);
2489 : }
2490 :
2491 :
2492 2056899 : uint32_t SeededNumberDictionary::max_number_key() {
2493 : DCHECK(!requires_slow_elements());
2494 : Object* max_index_object = get(kMaxNumberKeyIndex);
2495 2056899 : if (!max_index_object->IsSmi()) return 0;
2496 2055686 : uint32_t value = static_cast<uint32_t>(Smi::ToInt(max_index_object));
2497 2055686 : return value >> kRequiresSlowElementsTagSize;
2498 : }
2499 :
2500 :
2501 : void SeededNumberDictionary::set_requires_slow_elements() {
2502 : set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask));
2503 : }
2504 :
2505 :
2506 : template <class T>
2507 : PodArray<T>* PodArray<T>::cast(Object* object) {
2508 : SLOW_DCHECK(object->IsByteArray());
2509 : return reinterpret_cast<PodArray<T>*>(object);
2510 : }
2511 : template <class T>
2512 : const PodArray<T>* PodArray<T>::cast(const Object* object) {
2513 : SLOW_DCHECK(object->IsByteArray());
2514 : return reinterpret_cast<const PodArray<T>*>(object);
2515 : }
2516 :
2517 : // static
2518 : template <class T>
2519 : Handle<PodArray<T>> PodArray<T>::New(Isolate* isolate, int length,
2520 : PretenureFlag pretenure) {
2521 : return Handle<PodArray<T>>::cast(
2522 86632 : isolate->factory()->NewByteArray(length * sizeof(T), pretenure));
2523 : }
2524 :
2525 : // static
2526 : template <class Traits>
2527 : STATIC_CONST_MEMBER_DEFINITION const InstanceType
2528 : FixedTypedArray<Traits>::kInstanceType;
2529 :
2530 :
2531 : template <class Traits>
2532 : FixedTypedArray<Traits>* FixedTypedArray<Traits>::cast(Object* object) {
2533 : SLOW_DCHECK(object->IsHeapObject() &&
2534 : HeapObject::cast(object)->map()->instance_type() ==
2535 : Traits::kInstanceType);
2536 : return reinterpret_cast<FixedTypedArray<Traits>*>(object);
2537 : }
2538 :
2539 :
2540 : template <class Traits>
2541 : const FixedTypedArray<Traits>*
2542 : FixedTypedArray<Traits>::cast(const Object* object) {
2543 : SLOW_DCHECK(object->IsHeapObject() &&
2544 : HeapObject::cast(object)->map()->instance_type() ==
2545 : Traits::kInstanceType);
2546 : return reinterpret_cast<FixedTypedArray<Traits>*>(object);
2547 : }
2548 :
2549 442528 : DEFINE_DEOPT_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
2550 : DEFINE_DEOPT_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
2551 442528 : DEFINE_DEOPT_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
2552 : DEFINE_DEOPT_ELEMENT_ACCESSORS(OsrBytecodeOffset, Smi)
2553 11618 : DEFINE_DEOPT_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
2554 : DEFINE_DEOPT_ELEMENT_ACCESSORS(OptimizationId, Smi)
2555 232463 : DEFINE_DEOPT_ELEMENT_ACCESSORS(WeakCellCache, Object)
2556 442528 : DEFINE_DEOPT_ELEMENT_ACCESSORS(InliningPositions, PodArray<InliningPosition>)
2557 :
2558 6155264 : DEFINE_DEOPT_ENTRY_ACCESSORS(BytecodeOffsetRaw, Smi)
2559 10329593 : DEFINE_DEOPT_ENTRY_ACCESSORS(TranslationIndex, Smi)
2560 6329693 : DEFINE_DEOPT_ENTRY_ACCESSORS(Pc, Smi)
2561 :
2562 : template <typename Derived, typename Shape>
2563 0 : HashTable<Derived, Shape>* HashTable<Derived, Shape>::cast(Object* obj) {
2564 : SLOW_DCHECK(obj->IsHashTable());
2565 0 : return reinterpret_cast<HashTable*>(obj);
2566 : }
2567 :
2568 : template <typename Derived, typename Shape>
2569 0 : const HashTable<Derived, Shape>* HashTable<Derived, Shape>::cast(
2570 : const Object* obj) {
2571 : SLOW_DCHECK(obj->IsHashTable());
2572 0 : return reinterpret_cast<const HashTable*>(obj);
2573 : }
2574 :
2575 :
2576 1047891318 : SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
2577 502764910 : SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
2578 :
2579 : int PropertyArray::length() const {
2580 17406614 : Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
2581 : int value = Smi::ToInt(value_obj);
2582 : return LengthField::decode(value);
2583 : }
2584 :
2585 : void PropertyArray::initialize_length(int len) {
2586 : SLOW_DCHECK(len >= 0);
2587 : SLOW_DCHECK(len < LengthField::kMax);
2588 7736457 : WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(len));
2589 : }
2590 :
2591 : int PropertyArray::synchronized_length() const {
2592 21993872 : Object* value_obj = ACQUIRE_READ_FIELD(this, kLengthAndHashOffset);
2593 : int value = Smi::ToInt(value_obj);
2594 : return LengthField::decode(value);
2595 : }
2596 :
2597 : int PropertyArray::Hash() const {
2598 1977596 : Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
2599 : int value = Smi::ToInt(value_obj);
2600 1977596 : return HashField::decode(value);
2601 : }
2602 :
2603 85 : void PropertyArray::SetHash(int hash) {
2604 85 : Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
2605 : int value = Smi::ToInt(value_obj);
2606 170 : value = HashField::update(value, hash);
2607 85 : WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(value));
2608 85 : }
2609 :
2610 1557967 : SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
2611 208259663 : RELAXED_SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
2612 :
2613 :
2614 : int FreeSpace::Size() { return size(); }
2615 :
2616 :
2617 : FreeSpace* FreeSpace::next() {
2618 : DCHECK(map() == GetHeap()->root(Heap::kFreeSpaceMapRootIndex) ||
2619 : (!GetHeap()->deserialization_complete() && map() == nullptr));
2620 : DCHECK_LE(kNextOffset + kPointerSize, relaxed_read_size());
2621 : return reinterpret_cast<FreeSpace*>(
2622 1558154 : Memory::Address_at(address() + kNextOffset));
2623 : }
2624 :
2625 :
2626 : void FreeSpace::set_next(FreeSpace* next) {
2627 : DCHECK(map() == GetHeap()->root(Heap::kFreeSpaceMapRootIndex) ||
2628 : (!GetHeap()->deserialization_complete() && map() == nullptr));
2629 : DCHECK_LE(kNextOffset + kPointerSize, relaxed_read_size());
2630 : base::Relaxed_Store(
2631 : reinterpret_cast<base::AtomicWord*>(address() + kNextOffset),
2632 19221916 : reinterpret_cast<base::AtomicWord>(next));
2633 : }
2634 :
2635 :
2636 0 : FreeSpace* FreeSpace::cast(HeapObject* o) {
2637 : SLOW_DCHECK(!o->GetHeap()->deserialization_complete() || o->IsFreeSpace());
2638 0 : return reinterpret_cast<FreeSpace*>(o);
2639 : }
2640 :
2641 2261737 : int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
2642 :
2643 : byte ByteArray::get(int index) const {
2644 : DCHECK(index >= 0 && index < this->length());
2645 248050412 : return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
2646 : }
2647 :
2648 : void ByteArray::set(int index, byte value) {
2649 : DCHECK(index >= 0 && index < this->length());
2650 6812581 : WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value);
2651 : }
2652 :
2653 : void ByteArray::copy_in(int index, const byte* buffer, int length) {
2654 : DCHECK(index >= 0 && length >= 0 && length <= kMaxInt - index &&
2655 : index + length <= this->length());
2656 3988754 : byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize);
2657 3547 : memcpy(dst_addr, buffer, length);
2658 : }
2659 :
2660 : void ByteArray::copy_out(int index, byte* buffer, int length) {
2661 : DCHECK(index >= 0 && length >= 0 && length <= kMaxInt - index &&
2662 : index + length <= this->length());
2663 1466169 : const byte* src_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize);
2664 : memcpy(buffer, src_addr, length);
2665 : }
2666 :
2667 : int ByteArray::get_int(int index) const {
2668 : DCHECK(index >= 0 && index < this->length() / kIntSize);
2669 2804 : return READ_INT_FIELD(this, kHeaderSize + index * kIntSize);
2670 : }
2671 :
2672 : void ByteArray::set_int(int index, int value) {
2673 : DCHECK(index >= 0 && index < this->length() / kIntSize);
2674 756 : WRITE_INT_FIELD(this, kHeaderSize + index * kIntSize, value);
2675 : }
2676 :
2677 : uint32_t ByteArray::get_uint32(int index) const {
2678 : DCHECK(index >= 0 && index < this->length() / kUInt32Size);
2679 1220970 : return READ_UINT32_FIELD(this, kHeaderSize + index * kUInt32Size);
2680 : }
2681 :
2682 : void ByteArray::set_uint32(int index, uint32_t value) {
2683 : DCHECK(index >= 0 && index < this->length() / kUInt32Size);
2684 179369 : WRITE_UINT32_FIELD(this, kHeaderSize + index * kUInt32Size, value);
2685 : }
2686 :
2687 4930277 : void ByteArray::clear_padding() {
2688 4930277 : int data_size = length() + kHeaderSize;
2689 4930277 : memset(address() + data_size, 0, Size() - data_size);
2690 4930277 : }
2691 :
2692 : ByteArray* ByteArray::FromDataStartAddress(Address address) {
2693 : DCHECK_TAG_ALIGNED(address);
2694 : return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag);
2695 : }
2696 :
2697 924 : int ByteArray::DataSize() const { return RoundUp(length(), kPointerSize); }
2698 :
2699 : int ByteArray::ByteArraySize() { return SizeFor(this->length()); }
2700 :
2701 462 : Address ByteArray::GetDataStartAddress() {
2702 462 : return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize;
2703 : }
2704 :
2705 5877284 : ACCESSORS(FixedTypedArrayBase, base_pointer, Object, kBasePointerOffset)
2706 :
2707 :
2708 : void* FixedTypedArrayBase::external_pointer() const {
2709 2666903 : intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset);
2710 5 : return reinterpret_cast<void*>(ptr);
2711 : }
2712 :
2713 :
2714 : void FixedTypedArrayBase::set_external_pointer(void* value,
2715 : WriteBarrierMode mode) {
2716 13256 : intptr_t ptr = reinterpret_cast<intptr_t>(value);
2717 13261 : WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr);
2718 : }
2719 :
2720 :
2721 271 : void* FixedTypedArrayBase::DataPtr() {
2722 : return reinterpret_cast<void*>(
2723 5327028 : reinterpret_cast<intptr_t>(base_pointer()) +
2724 2663514 : reinterpret_cast<intptr_t>(external_pointer()));
2725 : }
2726 :
2727 :
2728 2266494 : int FixedTypedArrayBase::ElementSize(InstanceType type) {
2729 : int element_size;
2730 2266494 : switch (type) {
2731 : #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
2732 : case FIXED_##TYPE##_ARRAY_TYPE: \
2733 : element_size = size; \
2734 : break;
2735 :
2736 255992 : TYPED_ARRAYS(TYPED_ARRAY_CASE)
2737 : #undef TYPED_ARRAY_CASE
2738 : default:
2739 0 : UNREACHABLE();
2740 : }
2741 2266494 : return element_size;
2742 : }
2743 :
2744 : int FixedTypedArrayBase::DataSize(InstanceType type) const {
2745 2692608 : if (base_pointer() == Smi::kZero) return 0;
2746 2263499 : return length() * ElementSize(type);
2747 : }
2748 :
2749 695293 : int FixedTypedArrayBase::DataSize() const {
2750 695292 : return DataSize(map()->instance_type());
2751 : }
2752 :
2753 2998 : size_t FixedTypedArrayBase::ByteLength() const {
2754 5996 : return static_cast<size_t>(length()) *
2755 5996 : static_cast<size_t>(ElementSize(map()->instance_type()));
2756 : }
2757 :
2758 : int FixedTypedArrayBase::size() const {
2759 670248 : return OBJECT_POINTER_ALIGN(kDataOffset + DataSize());
2760 : }
2761 :
2762 1997315 : int FixedTypedArrayBase::TypedArraySize(InstanceType type) const {
2763 1997315 : return OBJECT_POINTER_ALIGN(kDataOffset + DataSize(type));
2764 : }
2765 :
2766 : // static
2767 : int FixedTypedArrayBase::TypedArraySize(InstanceType type, int length) {
2768 : return OBJECT_POINTER_ALIGN(kDataOffset + length * ElementSize(type));
2769 : }
2770 :
2771 :
2772 : uint8_t Uint8ArrayTraits::defaultValue() { return 0; }
2773 :
2774 :
2775 : uint8_t Uint8ClampedArrayTraits::defaultValue() { return 0; }
2776 :
2777 :
2778 : int8_t Int8ArrayTraits::defaultValue() { return 0; }
2779 :
2780 :
2781 : uint16_t Uint16ArrayTraits::defaultValue() { return 0; }
2782 :
2783 :
2784 : int16_t Int16ArrayTraits::defaultValue() { return 0; }
2785 :
2786 :
2787 : uint32_t Uint32ArrayTraits::defaultValue() { return 0; }
2788 :
2789 :
2790 : int32_t Int32ArrayTraits::defaultValue() { return 0; }
2791 :
2792 :
2793 : float Float32ArrayTraits::defaultValue() {
2794 : return std::numeric_limits<float>::quiet_NaN();
2795 : }
2796 :
2797 :
2798 : double Float64ArrayTraits::defaultValue() {
2799 : return std::numeric_limits<double>::quiet_NaN();
2800 : }
2801 :
2802 : template <class Traits>
2803 : typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) {
2804 : DCHECK((index >= 0) && (index < this->length()));
2805 : // The JavaScript memory model allows for racy reads and writes to a
2806 : // SharedArrayBuffer's backing store, which will always be a FixedTypedArray.
2807 : // ThreadSanitizer will catch these racy accesses and warn about them, so we
2808 : // disable TSAN for these reads and writes using annotations.
2809 : //
2810 : // We don't use relaxed atomics here, as it is not a requirement of the
2811 : // JavaScript memory model to have tear-free reads of overlapping accesses,
2812 : // and using relaxed atomics may introduce overhead.
2813 : auto* ptr = reinterpret_cast<ElementType*>(DataPtr());
2814 : TSAN_ANNOTATE_IGNORE_READS_BEGIN;
2815 438764 : auto result = ptr[index];
2816 : TSAN_ANNOTATE_IGNORE_READS_END;
2817 : return result;
2818 : }
2819 :
2820 :
2821 : template <class Traits>
2822 2195232 : void FixedTypedArray<Traits>::set(int index, ElementType value) {
2823 4390464 : CHECK((index >= 0) && (index < this->length()));
2824 : // See the comment in FixedTypedArray<Traits>::get_scalar.
2825 : auto* ptr = reinterpret_cast<ElementType*>(DataPtr());
2826 : TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
2827 2195232 : ptr[index] = value;
2828 : TSAN_ANNOTATE_IGNORE_WRITES_END;
2829 2195232 : }
2830 :
2831 : template <class Traits>
2832 : typename Traits::ElementType FixedTypedArray<Traits>::from(int value) {
2833 1441786 : return static_cast<ElementType>(value);
2834 : }
2835 :
2836 : template <>
2837 : inline uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from(int value) {
2838 24487 : if (value < 0) return 0;
2839 24489 : if (value > 0xFF) return 0xFF;
2840 24002 : return static_cast<uint8_t>(value);
2841 : }
2842 :
2843 : template <class Traits>
2844 : typename Traits::ElementType FixedTypedArray<Traits>::from(uint32_t value) {
2845 432 : return static_cast<ElementType>(value);
2846 : }
2847 :
2848 : template <>
2849 : inline uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from(uint32_t value) {
2850 : // We need this special case for Uint32 -> Uint8Clamped, because the highest
2851 : // Uint32 values will be negative as an int, clamping to 0, rather than 255.
2852 72 : if (value > 0xFF) return 0xFF;
2853 45 : return static_cast<uint8_t>(value);
2854 : }
2855 :
2856 : template <class Traits>
2857 : typename Traits::ElementType FixedTypedArray<Traits>::from(double value) {
2858 293843 : return static_cast<ElementType>(DoubleToInt32(value));
2859 : }
2860 :
2861 : template <>
2862 : inline uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from(double value) {
2863 : // Handle NaNs and less than zero values which clamp to zero.
2864 93537 : if (!(value > 0)) return 0;
2865 92395 : if (value > 0xFF) return 0xFF;
2866 91658 : return static_cast<uint8_t>(lrint(value));
2867 : }
2868 :
2869 : template <>
2870 : inline float FixedTypedArray<Float32ArrayTraits>::from(double value) {
2871 117922 : return static_cast<float>(value);
2872 : }
2873 :
2874 : template <>
2875 : inline double FixedTypedArray<Float64ArrayTraits>::from(double value) {
2876 : return value;
2877 : }
2878 :
2879 : template <class Traits>
2880 409893 : Handle<Object> FixedTypedArray<Traits>::get(FixedTypedArray<Traits>* array,
2881 : int index) {
2882 588274 : return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index));
2883 : }
2884 :
2885 :
2886 : template <class Traits>
2887 898077 : void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) {
2888 : ElementType cast_value = Traits::defaultValue();
2889 898077 : if (value->IsSmi()) {
2890 : int int_value = Smi::ToInt(value);
2891 : cast_value = from(int_value);
2892 520521 : } else if (value->IsHeapNumber()) {
2893 : double double_value = HeapNumber::cast(value)->value();
2894 : cast_value = from(double_value);
2895 : } else {
2896 : // Clamp undefined to the default value. All other types have been
2897 : // converted to a number type further up in the call chain.
2898 : DCHECK(value->IsUndefined(GetIsolate()));
2899 : }
2900 898077 : set(index, cast_value);
2901 898077 : }
2902 :
2903 :
2904 88596 : Handle<Object> Uint8ArrayTraits::ToHandle(Isolate* isolate, uint8_t scalar) {
2905 88596 : return handle(Smi::FromInt(scalar), isolate);
2906 : }
2907 :
2908 :
2909 3128 : Handle<Object> Uint8ClampedArrayTraits::ToHandle(Isolate* isolate,
2910 : uint8_t scalar) {
2911 3128 : return handle(Smi::FromInt(scalar), isolate);
2912 : }
2913 :
2914 :
2915 5532 : Handle<Object> Int8ArrayTraits::ToHandle(Isolate* isolate, int8_t scalar) {
2916 5532 : return handle(Smi::FromInt(scalar), isolate);
2917 : }
2918 :
2919 :
2920 76492 : Handle<Object> Uint16ArrayTraits::ToHandle(Isolate* isolate, uint16_t scalar) {
2921 76492 : return handle(Smi::FromInt(scalar), isolate);
2922 : }
2923 :
2924 :
2925 4633 : Handle<Object> Int16ArrayTraits::ToHandle(Isolate* isolate, int16_t scalar) {
2926 4633 : return handle(Smi::FromInt(scalar), isolate);
2927 : }
2928 :
2929 :
2930 : Handle<Object> Uint32ArrayTraits::ToHandle(Isolate* isolate, uint32_t scalar) {
2931 76036 : return isolate->factory()->NewNumberFromUint(scalar);
2932 : }
2933 :
2934 :
2935 : Handle<Object> Int32ArrayTraits::ToHandle(Isolate* isolate, int32_t scalar) {
2936 4616 : return isolate->factory()->NewNumberFromInt(scalar);
2937 : }
2938 :
2939 :
2940 : Handle<Object> Float32ArrayTraits::ToHandle(Isolate* isolate, float scalar) {
2941 75680 : return isolate->factory()->NewNumber(scalar);
2942 : }
2943 :
2944 :
2945 : Handle<Object> Float64ArrayTraits::ToHandle(Isolate* isolate, double scalar) {
2946 75180 : return isolate->factory()->NewNumber(scalar);
2947 : }
2948 :
2949 913635682 : int Map::visitor_id() const { return READ_BYTE_FIELD(this, kVisitorIdOffset); }
2950 :
2951 : void Map::set_visitor_id(int id) {
2952 : DCHECK_LE(0, id);
2953 : DCHECK_LT(id, 256);
2954 47663721 : WRITE_BYTE_FIELD(this, kVisitorIdOffset, static_cast<byte>(id));
2955 : }
2956 :
2957 39599298 : int Map::instance_size() const {
2958 5155611533 : return RELAXED_READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2;
2959 : }
2960 :
2961 : int Map::inobject_properties_or_constructor_function_index() const {
2962 740818984 : return RELAXED_READ_BYTE_FIELD(
2963 : this, kInObjectPropertiesOrConstructorFunctionIndexOffset);
2964 : }
2965 :
2966 :
2967 : void Map::set_inobject_properties_or_constructor_function_index(int value) {
2968 : DCHECK_LE(0, value);
2969 : DCHECK_LT(value, 256);
2970 26578342 : RELAXED_WRITE_BYTE_FIELD(this,
2971 : kInObjectPropertiesOrConstructorFunctionIndexOffset,
2972 : static_cast<byte>(value));
2973 : }
2974 :
2975 18598629 : int Map::GetInObjectProperties() const {
2976 : DCHECK(IsJSObjectMap());
2977 18598629 : return inobject_properties_or_constructor_function_index();
2978 : }
2979 :
2980 :
2981 : void Map::SetInObjectProperties(int value) {
2982 : DCHECK(IsJSObjectMap());
2983 : set_inobject_properties_or_constructor_function_index(value);
2984 : }
2985 :
2986 : int Map::GetConstructorFunctionIndex() const {
2987 : DCHECK(IsPrimitiveMap());
2988 : return inobject_properties_or_constructor_function_index();
2989 : }
2990 :
2991 :
2992 : void Map::SetConstructorFunctionIndex(int value) {
2993 : DCHECK(IsPrimitiveMap());
2994 : set_inobject_properties_or_constructor_function_index(value);
2995 : }
2996 :
2997 94674310 : int Map::GetInObjectPropertyOffset(int index) const {
2998 : // Adjust for the number of properties stored in the object.
2999 94674310 : index -= GetInObjectProperties();
3000 : DCHECK_LE(index, 0);
3001 94674310 : return instance_size() + (index * kPointerSize);
3002 : }
3003 :
3004 :
3005 : Handle<Map> Map::AddMissingTransitionsForTesting(
3006 : Handle<Map> split_map, Handle<DescriptorArray> descriptors,
3007 : Handle<LayoutDescriptor> full_layout_descriptor) {
3008 78 : return AddMissingTransitions(split_map, descriptors, full_layout_descriptor);
3009 : }
3010 :
3011 2150081805 : int HeapObject::SizeFromMap(Map* map) const {
3012 : int instance_size = map->instance_size();
3013 2150081805 : if (instance_size != kVariableSizeSentinel) return instance_size;
3014 : // Only inline the most frequent cases.
3015 : InstanceType instance_type = map->instance_type();
3016 2050249122 : if (instance_type == FIXED_ARRAY_TYPE || instance_type == HASH_TABLE_TYPE ||
3017 1025124561 : instance_type == TRANSITION_ARRAY_TYPE) {
3018 : return FixedArray::SizeFor(
3019 168957246 : reinterpret_cast<const FixedArray*>(this)->synchronized_length());
3020 : }
3021 1712334630 : if (instance_type == ONE_BYTE_STRING_TYPE ||
3022 856167315 : instance_type == ONE_BYTE_INTERNALIZED_STRING_TYPE) {
3023 : // Strings may get concurrently truncated, hence we have to access its
3024 : // length synchronized.
3025 : return SeqOneByteString::SizeFor(
3026 328118692 : reinterpret_cast<const SeqOneByteString*>(this)->synchronized_length());
3027 : }
3028 528048623 : if (instance_type == BYTE_ARRAY_TYPE) {
3029 : return ByteArray::SizeFor(
3030 231468722 : reinterpret_cast<const ByteArray*>(this)->synchronized_length());
3031 : }
3032 296579901 : if (instance_type == BYTECODE_ARRAY_TYPE) {
3033 : return BytecodeArray::SizeFor(
3034 5599528 : reinterpret_cast<const BytecodeArray*>(this)->synchronized_length());
3035 : }
3036 290980373 : if (instance_type == FREE_SPACE_TYPE) {
3037 2630362 : return reinterpret_cast<const FreeSpace*>(this)->relaxed_read_size();
3038 : }
3039 576700022 : if (instance_type == STRING_TYPE ||
3040 288350011 : instance_type == INTERNALIZED_STRING_TYPE) {
3041 : // Strings may get concurrently truncated, hence we have to access its
3042 : // length synchronized.
3043 : return SeqTwoByteString::SizeFor(
3044 42892591 : reinterpret_cast<const SeqTwoByteString*>(this)->synchronized_length());
3045 : }
3046 245457420 : if (instance_type == FIXED_DOUBLE_ARRAY_TYPE) {
3047 : return FixedDoubleArray::SizeFor(
3048 91344 : reinterpret_cast<const FixedDoubleArray*>(this)->synchronized_length());
3049 : }
3050 245366076 : if (instance_type >= FIRST_FIXED_TYPED_ARRAY_TYPE &&
3051 : instance_type <= LAST_FIXED_TYPED_ARRAY_TYPE) {
3052 : return reinterpret_cast<const FixedTypedArrayBase*>(this)->TypedArraySize(
3053 1997316 : instance_type);
3054 : }
3055 243368760 : if (instance_type == SMALL_ORDERED_HASH_SET_TYPE) {
3056 0 : return reinterpret_cast<const SmallOrderedHashSet*>(this)->Size();
3057 : }
3058 243368760 : if (instance_type == PROPERTY_ARRAY_TYPE) {
3059 : return PropertyArray::SizeFor(
3060 21993872 : reinterpret_cast<const PropertyArray*>(this)->synchronized_length());
3061 : }
3062 221374888 : if (instance_type == SMALL_ORDERED_HASH_MAP_TYPE) {
3063 0 : return reinterpret_cast<const SmallOrderedHashMap*>(this)->Size();
3064 : }
3065 221374888 : if (instance_type == FEEDBACK_VECTOR_TYPE) {
3066 : return FeedbackVector::SizeFor(
3067 24449598 : reinterpret_cast<const FeedbackVector*>(this)->length());
3068 : }
3069 196925290 : if (instance_type == BIGINT_TYPE) {
3070 108 : return BigInt::SizeFor(reinterpret_cast<const BigInt*>(this)->length());
3071 : }
3072 : DCHECK(instance_type == CODE_TYPE);
3073 196925993 : return reinterpret_cast<const Code*>(this)->CodeSize();
3074 : }
3075 :
3076 :
3077 : void Map::set_instance_size(int value) {
3078 : DCHECK_EQ(0, value & (kPointerSize - 1));
3079 26732468 : value >>= kPointerSizeLog2;
3080 : DCHECK(0 <= value && value < 256);
3081 26577823 : RELAXED_WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value));
3082 : }
3083 :
3084 :
3085 8229295833 : InstanceType Map::instance_type() const {
3086 22647938095 : return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset));
3087 : }
3088 :
3089 :
3090 : void Map::set_instance_type(InstanceType value) {
3091 26429924 : WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value);
3092 : }
3093 :
3094 : int Map::unused_property_fields() const {
3095 75311740 : return READ_BYTE_FIELD(this, kUnusedPropertyFieldsOffset);
3096 : }
3097 :
3098 : int Map::UnusedPropertyFields() const {
3099 : VerifyUnusedPropertyFields();
3100 : return unused_property_fields();
3101 : }
3102 :
3103 : void Map::set_unused_property_fields(int value) {
3104 55799357 : WRITE_BYTE_FIELD(this, kUnusedPropertyFieldsOffset, Min(value, 255));
3105 : }
3106 :
3107 : int Map::used_instance_size_in_words() const {
3108 28098979 : return READ_BYTE_FIELD(this, kUsedInstanceSizeInWordsOffset);
3109 : }
3110 :
3111 : void Map::set_used_instance_size_in_words(int value) {
3112 : DCHECK_LE(0, value);
3113 : DCHECK_LE(value, 255);
3114 : WRITE_BYTE_FIELD(this, kUsedInstanceSizeInWordsOffset,
3115 55644652 : static_cast<byte>(value));
3116 : VerifyUnusedPropertyFields();
3117 : }
3118 :
3119 27431888 : void Map::SetInObjectUnusedPropertyFields(int value) {
3120 : STATIC_ASSERT(JSObject::kFieldsAdded == JSObject::kHeaderSize / kPointerSize);
3121 27431888 : if (!IsJSObjectMap()) {
3122 : DCHECK_EQ(0, value);
3123 : set_unused_property_fields(0);
3124 : set_used_instance_size_in_words(0);
3125 27431889 : return;
3126 : }
3127 : DCHECK_LE(0, value);
3128 : DCHECK_LE(value, GetInObjectProperties());
3129 : set_unused_property_fields(value);
3130 27428383 : int used_inobject_properties = GetInObjectProperties() - value;
3131 : set_used_instance_size_in_words(
3132 27428383 : GetInObjectPropertyOffset(used_inobject_properties) / kPointerSize);
3133 : VerifyUnusedPropertyFields();
3134 : }
3135 :
3136 : void Map::SetOutOfObjectUnusedPropertyFields(int value) {
3137 : STATIC_ASSERT(JSObject::kFieldsAdded == JSObject::kHeaderSize / kPointerSize);
3138 : DCHECK_LE(0, value);
3139 : DCHECK_LT(value, JSObject::kFieldsAdded);
3140 : set_unused_property_fields(value);
3141 : // For out of object properties "used_instance_size_in_words" byte encodes
3142 : // the slack in the property array.
3143 : set_used_instance_size_in_words(value);
3144 : VerifyUnusedPropertyFields();
3145 : }
3146 :
3147 : void Map::CopyUnusedPropertyFields(Map* map) {
3148 : set_unused_property_fields(map->unused_property_fields());
3149 : set_used_instance_size_in_words(map->used_instance_size_in_words());
3150 : VerifyUnusedPropertyFields();
3151 : }
3152 :
3153 6826344 : void Map::AccountAddedPropertyField() {
3154 : STATIC_ASSERT(JSObject::kFieldsAdded == JSObject::kHeaderSize / kPointerSize);
3155 : // Update unused_property_fields.
3156 6826344 : int new_unused = unused_property_fields() - 1;
3157 6826344 : if (new_unused < 0) new_unused += JSObject::kFieldsAdded;
3158 : set_unused_property_fields(new_unused);
3159 : // Update used_instance_size_in_words.
3160 : int value = used_instance_size_in_words();
3161 6826344 : if (value >= JSObject::kFieldsAdded) {
3162 3481506 : if (value == instance_size() / kPointerSize) {
3163 : AccountAddedOutOfObjectPropertyField(0);
3164 : } else {
3165 : // The property is added in-object, so simply increment the counter.
3166 3054337 : set_used_instance_size_in_words(value + 1);
3167 : }
3168 : } else {
3169 : AccountAddedOutOfObjectPropertyField(value);
3170 : }
3171 : VerifyUnusedPropertyFields();
3172 6826344 : }
3173 :
3174 : void Map::AccountAddedOutOfObjectPropertyField(int unused_in_property_array) {
3175 3344838 : unused_in_property_array--;
3176 3344838 : if (unused_in_property_array < 0) {
3177 996009 : unused_in_property_array += JSObject::kFieldsAdded;
3178 : }
3179 : DCHECK_GE(unused_in_property_array, 0);
3180 : DCHECK_LT(unused_in_property_array, JSObject::kFieldsAdded);
3181 : set_used_instance_size_in_words(unused_in_property_array);
3182 : }
3183 :
3184 : void Map::VerifyUnusedPropertyFields() const {
3185 : #ifdef DEBUG
3186 : if (!IsJSObjectMap()) {
3187 : DCHECK_EQ(unused_property_fields(), used_instance_size_in_words());
3188 : } else {
3189 : int value = used_instance_size_in_words();
3190 : int unused;
3191 : if (value >= JSObject::kFieldsAdded) {
3192 : unused = instance_size() / kPointerSize - value;
3193 : } else {
3194 : // For out of object properties "used_instance_size_in_words" byte encodes
3195 : // the slack in the property array.
3196 : unused = value;
3197 : }
3198 : DCHECK_EQ(unused_property_fields(), unused);
3199 : }
3200 : #endif
3201 : }
3202 :
3203 189966747 : byte Map::bit_field() const { return READ_BYTE_FIELD(this, kBitFieldOffset); }
3204 :
3205 :
3206 : void Map::set_bit_field(byte value) {
3207 48899840 : WRITE_BYTE_FIELD(this, kBitFieldOffset, value);
3208 : }
3209 :
3210 :
3211 749527288 : byte Map::bit_field2() const { return READ_BYTE_FIELD(this, kBitField2Offset); }
3212 :
3213 :
3214 : void Map::set_bit_field2(byte value) {
3215 78966727 : WRITE_BYTE_FIELD(this, kBitField2Offset, value);
3216 : }
3217 :
3218 :
3219 : void Map::set_non_instance_prototype(bool value) {
3220 : if (value) {
3221 4324 : set_bit_field(bit_field() | (1 << kHasNonInstancePrototype));
3222 : } else {
3223 585403 : set_bit_field(bit_field() & ~(1 << kHasNonInstancePrototype));
3224 : }
3225 : }
3226 :
3227 : bool Map::has_non_instance_prototype() const {
3228 3734031 : if (!has_prototype_slot()) return false;
3229 3734031 : return ((1 << kHasNonInstancePrototype) & bit_field()) != 0;
3230 : }
3231 :
3232 :
3233 : void Map::set_is_constructor(bool value) {
3234 854 : if (value) {
3235 938 : set_bit_field(bit_field() | (1 << kIsConstructor));
3236 : } else {
3237 1098 : set_bit_field(bit_field() & ~(1 << kIsConstructor));
3238 : }
3239 : }
3240 :
3241 :
3242 129990 : bool Map::is_constructor() const {
3243 783658 : return ((1 << kIsConstructor) & bit_field()) != 0;
3244 : }
3245 :
3246 26272658 : BOOL_ACCESSORS(Map, bit_field, has_prototype_slot, kHasPrototypeSlot)
3247 :
3248 : void Map::set_has_hidden_prototype(bool value) {
3249 : set_bit_field3(HasHiddenPrototype::update(bit_field3(), value));
3250 : }
3251 :
3252 458 : bool Map::has_hidden_prototype() const {
3253 458 : return HasHiddenPrototype::decode(bit_field3());
3254 : }
3255 :
3256 :
3257 : void Map::set_has_indexed_interceptor() {
3258 190 : set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
3259 : }
3260 :
3261 160 : bool Map::has_indexed_interceptor() const {
3262 9106225 : return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
3263 : }
3264 :
3265 :
3266 : void Map::set_is_undetectable() {
3267 216 : set_bit_field(bit_field() | (1 << kIsUndetectable));
3268 : }
3269 :
3270 26113 : bool Map::is_undetectable() const {
3271 1332272 : return ((1 << kIsUndetectable) & bit_field()) != 0;
3272 : }
3273 :
3274 :
3275 : void Map::set_has_named_interceptor() {
3276 1115 : set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
3277 : }
3278 :
3279 160 : bool Map::has_named_interceptor() const {
3280 31020339 : return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
3281 : }
3282 :
3283 :
3284 : void Map::set_is_access_check_needed(bool access_check_needed) {
3285 : if (access_check_needed) {
3286 167800 : set_bit_field(bit_field() | (1 << kIsAccessCheckNeeded));
3287 : } else {
3288 247 : set_bit_field(bit_field() & ~(1 << kIsAccessCheckNeeded));
3289 : }
3290 : }
3291 :
3292 40327820 : bool Map::is_access_check_needed() const {
3293 80769911 : return ((1 << kIsAccessCheckNeeded) & bit_field()) != 0;
3294 : }
3295 :
3296 :
3297 : void Map::set_is_extensible(bool value) {
3298 : if (value) {
3299 : set_bit_field2(bit_field2() | (1 << kIsExtensible));
3300 : } else {
3301 154308 : set_bit_field2(bit_field2() & ~(1 << kIsExtensible));
3302 : }
3303 : }
3304 :
3305 : bool Map::is_extensible() const {
3306 57527714 : return ((1 << kIsExtensible) & bit_field2()) != 0;
3307 : }
3308 :
3309 :
3310 : void Map::set_is_prototype_map(bool value) {
3311 : set_bit_field2(IsPrototypeMapBits::update(bit_field2(), value));
3312 : }
3313 :
3314 30397692 : bool Map::is_prototype_map() const {
3315 30397692 : return IsPrototypeMapBits::decode(bit_field2());
3316 : }
3317 :
3318 : bool Map::is_abandoned_prototype_map() const {
3319 753640 : return is_prototype_map() && !owns_descriptors();
3320 : }
3321 :
3322 26751594 : bool Map::should_be_fast_prototype_map() const {
3323 26751590 : if (!prototype_info()->IsPrototypeInfo()) return false;
3324 23271203 : return PrototypeInfo::cast(prototype_info())->should_be_fast_map();
3325 : }
3326 :
3327 : void Map::set_elements_kind(ElementsKind elements_kind) {
3328 : DCHECK_LT(static_cast<int>(elements_kind), kElementsKindCount);
3329 : DCHECK_LE(kElementsKindCount, 1 << Map::ElementsKindBits::kSize);
3330 347772 : set_bit_field2(Map::ElementsKindBits::update(bit_field2(), elements_kind));
3331 : DCHECK(this->elements_kind() == elements_kind);
3332 : }
3333 :
3334 1413551 : ElementsKind Map::elements_kind() const {
3335 1413551 : return Map::ElementsKindBits::decode(bit_field2());
3336 : }
3337 :
3338 : bool Map::has_fast_smi_elements() const {
3339 : return IsSmiElementsKind(elements_kind());
3340 : }
3341 :
3342 : bool Map::has_fast_object_elements() const {
3343 : return IsObjectElementsKind(elements_kind());
3344 : }
3345 :
3346 : bool Map::has_fast_smi_or_object_elements() const {
3347 : return IsSmiOrObjectElementsKind(elements_kind());
3348 : }
3349 :
3350 : bool Map::has_fast_double_elements() const {
3351 : return IsDoubleElementsKind(elements_kind());
3352 : }
3353 :
3354 : bool Map::has_fast_elements() const {
3355 : return IsFastElementsKind(elements_kind());
3356 : }
3357 :
3358 : bool Map::has_sloppy_arguments_elements() const {
3359 : return IsSloppyArgumentsElementsKind(elements_kind());
3360 : }
3361 :
3362 : bool Map::has_fast_sloppy_arguments_elements() const {
3363 : return elements_kind() == FAST_SLOPPY_ARGUMENTS_ELEMENTS;
3364 : }
3365 :
3366 : bool Map::has_fast_string_wrapper_elements() const {
3367 : return elements_kind() == FAST_STRING_WRAPPER_ELEMENTS;
3368 : }
3369 :
3370 : bool Map::has_fixed_typed_array_elements() const {
3371 : return IsFixedTypedArrayElementsKind(elements_kind());
3372 : }
3373 :
3374 : bool Map::has_dictionary_elements() const {
3375 : return IsDictionaryElementsKind(elements_kind());
3376 : }
3377 :
3378 :
3379 : void Map::set_dictionary_map(bool value) {
3380 : uint32_t new_bit_field3 = DictionaryMap::update(bit_field3(), value);
3381 : new_bit_field3 = IsUnstable::update(new_bit_field3, value);
3382 : set_bit_field3(new_bit_field3);
3383 : }
3384 :
3385 122721 : bool Map::is_dictionary_map() const {
3386 122721 : return DictionaryMap::decode(bit_field3());
3387 : }
3388 :
3389 : void Map::set_owns_descriptors(bool owns_descriptors) {
3390 : set_bit_field3(OwnsDescriptors::update(bit_field3(), owns_descriptors));
3391 : }
3392 :
3393 : bool Map::owns_descriptors() const {
3394 : return OwnsDescriptors::decode(bit_field3());
3395 : }
3396 :
3397 :
3398 1243 : void Map::set_is_callable() { set_bit_field(bit_field() | (1 << kIsCallable)); }
3399 :
3400 :
3401 17758129 : bool Map::is_callable() const {
3402 19064686 : return ((1 << kIsCallable) & bit_field()) != 0;
3403 : }
3404 :
3405 :
3406 : void Map::deprecate() {
3407 : set_bit_field3(Deprecated::update(bit_field3(), true));
3408 : }
3409 :
3410 2000036 : bool Map::is_deprecated() const { return Deprecated::decode(bit_field3()); }
3411 :
3412 : void Map::set_migration_target(bool value) {
3413 : set_bit_field3(IsMigrationTarget::update(bit_field3(), value));
3414 : }
3415 :
3416 : bool Map::is_migration_target() const {
3417 : return IsMigrationTarget::decode(bit_field3());
3418 : }
3419 :
3420 : void Map::set_immutable_proto(bool value) {
3421 : set_bit_field3(ImmutablePrototype::update(bit_field3(), value));
3422 : }
3423 :
3424 : bool Map::is_immutable_proto() const {
3425 : return ImmutablePrototype::decode(bit_field3());
3426 : }
3427 :
3428 : void Map::set_new_target_is_base(bool value) {
3429 : set_bit_field3(NewTargetIsBase::update(bit_field3(), value));
3430 : }
3431 :
3432 : bool Map::new_target_is_base() const {
3433 : return NewTargetIsBase::decode(bit_field3());
3434 : }
3435 :
3436 : void Map::set_may_have_interesting_symbols(bool value) {
3437 : set_bit_field3(MayHaveInterestingSymbols::update(bit_field3(), value));
3438 : }
3439 :
3440 : bool Map::may_have_interesting_symbols() const {
3441 : return MayHaveInterestingSymbols::decode(bit_field3());
3442 : }
3443 :
3444 : void Map::set_construction_counter(int value) {
3445 : set_bit_field3(ConstructionCounter::update(bit_field3(), value));
3446 : }
3447 :
3448 : int Map::construction_counter() const {
3449 : return ConstructionCounter::decode(bit_field3());
3450 : }
3451 :
3452 :
3453 : void Map::mark_unstable() {
3454 : set_bit_field3(IsUnstable::update(bit_field3(), true));
3455 : }
3456 :
3457 9428 : bool Map::is_stable() const { return !IsUnstable::decode(bit_field3()); }
3458 :
3459 20434 : bool Map::CanBeDeprecated() const {
3460 : int descriptor = LastAdded();
3461 34180 : for (int i = 0; i <= descriptor; i++) {
3462 25171 : PropertyDetails details = instance_descriptors()->GetDetails(i);
3463 25171 : if (details.representation().IsNone()) return true;
3464 25171 : if (details.representation().IsSmi()) return true;
3465 19904 : if (details.representation().IsDouble()) return true;
3466 19833 : if (details.representation().IsHeapObject()) return true;
3467 27344 : if (details.kind() == kData && details.location() == kDescriptor) {
3468 : return true;
3469 : }
3470 : }
3471 : return false;
3472 : }
3473 :
3474 :
3475 32773510 : void Map::NotifyLeafMapLayoutChange() {
3476 32773510 : if (is_stable()) {
3477 : mark_unstable();
3478 : dependent_code()->DeoptimizeDependentCodeGroup(
3479 : GetIsolate(),
3480 16025087 : DependentCode::kPrototypeCheckGroup);
3481 : }
3482 32773510 : }
3483 :
3484 36766602 : bool Map::CanTransition() const {
3485 : // Only JSObject and subtypes have map transitions and back pointers.
3486 : STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE);
3487 36940438 : return instance_type() >= FIRST_JS_OBJECT_TYPE;
3488 : }
3489 :
3490 212118 : bool Map::IsBooleanMap() const { return this == GetHeap()->boolean_map(); }
3491 9659754 : bool Map::IsPrimitiveMap() const {
3492 : STATIC_ASSERT(FIRST_PRIMITIVE_TYPE == FIRST_TYPE);
3493 9659759 : return instance_type() <= LAST_PRIMITIVE_TYPE;
3494 : }
3495 : bool Map::IsJSReceiverMap() const {
3496 : STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
3497 : return instance_type() >= FIRST_JS_RECEIVER_TYPE;
3498 : }
3499 238870977 : bool Map::IsJSObjectMap() const {
3500 : STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
3501 238870977 : return instance_type() >= FIRST_JS_OBJECT_TYPE;
3502 : }
3503 : bool Map::IsJSArrayMap() const { return instance_type() == JS_ARRAY_TYPE; }
3504 : bool Map::IsJSFunctionMap() const {
3505 : return instance_type() == JS_FUNCTION_TYPE;
3506 : }
3507 326159 : bool Map::IsStringMap() const { return instance_type() < FIRST_NONSTRING_TYPE; }
3508 122212754 : bool Map::IsJSProxyMap() const { return instance_type() == JS_PROXY_TYPE; }
3509 : bool Map::IsJSGlobalProxyMap() const {
3510 : return instance_type() == JS_GLOBAL_PROXY_TYPE;
3511 : }
3512 : bool Map::IsJSGlobalObjectMap() const {
3513 : return instance_type() == JS_GLOBAL_OBJECT_TYPE;
3514 : }
3515 : bool Map::IsJSTypedArrayMap() const {
3516 : return instance_type() == JS_TYPED_ARRAY_TYPE;
3517 : }
3518 : bool Map::IsJSDataViewMap() const {
3519 : return instance_type() == JS_DATA_VIEW_TYPE;
3520 : }
3521 :
3522 10771 : bool Map::IsSpecialReceiverMap() const {
3523 : bool result = IsSpecialReceiverInstanceType(instance_type());
3524 : DCHECK_IMPLIES(!result,
3525 : !has_named_interceptor() && !is_access_check_needed());
3526 10771 : return result;
3527 : }
3528 :
3529 34 : Object* Map::prototype() const {
3530 463799413 : return READ_FIELD(this, kPrototypeOffset);
3531 : }
3532 :
3533 :
3534 53049582 : void Map::set_prototype(Object* value, WriteBarrierMode mode) {
3535 : DCHECK(value->IsNull(GetIsolate()) || value->IsJSReceiver());
3536 53049582 : WRITE_FIELD(this, kPrototypeOffset, value);
3537 119530677 : CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode);
3538 53049582 : }
3539 :
3540 : LayoutDescriptor* Map::layout_descriptor_gc_safe() const {
3541 487126 : Object* layout_desc = RELAXED_READ_FIELD(this, kLayoutDescriptorOffset);
3542 : return LayoutDescriptor::cast_gc_safe(layout_desc);
3543 : }
3544 :
3545 :
3546 : bool Map::HasFastPointerLayout() const {
3547 278232466 : Object* layout_desc = RELAXED_READ_FIELD(this, kLayoutDescriptorOffset);
3548 : return LayoutDescriptor::IsFastPointerLayout(layout_desc);
3549 : }
3550 :
3551 :
3552 22177879 : void Map::UpdateDescriptors(DescriptorArray* descriptors,
3553 : LayoutDescriptor* layout_desc) {
3554 22177879 : set_instance_descriptors(descriptors);
3555 : if (FLAG_unbox_double_fields) {
3556 22177879 : if (layout_descriptor()->IsSlowLayout()) {
3557 3359 : set_layout_descriptor(layout_desc);
3558 : }
3559 : #ifdef VERIFY_HEAP
3560 : // TODO(ishell): remove these checks from VERIFY_HEAP mode.
3561 : if (FLAG_verify_heap) {
3562 : CHECK(layout_descriptor()->IsConsistentWithMap(this));
3563 : CHECK(visitor_id() == Map::GetVisitorId(this));
3564 : }
3565 : #else
3566 : SLOW_DCHECK(layout_descriptor()->IsConsistentWithMap(this));
3567 : DCHECK(visitor_id() == Map::GetVisitorId(this));
3568 : #endif
3569 : }
3570 22177879 : }
3571 :
3572 :
3573 21023590 : void Map::InitializeDescriptors(DescriptorArray* descriptors,
3574 : LayoutDescriptor* layout_desc) {
3575 : int len = descriptors->number_of_descriptors();
3576 21023590 : set_instance_descriptors(descriptors);
3577 : SetNumberOfOwnDescriptors(len);
3578 :
3579 : if (FLAG_unbox_double_fields) {
3580 21023587 : set_layout_descriptor(layout_desc);
3581 : #ifdef VERIFY_HEAP
3582 : // TODO(ishell): remove these checks from VERIFY_HEAP mode.
3583 : if (FLAG_verify_heap) {
3584 : CHECK(layout_descriptor()->IsConsistentWithMap(this));
3585 : }
3586 : #else
3587 : SLOW_DCHECK(layout_descriptor()->IsConsistentWithMap(this));
3588 : #endif
3589 21023587 : set_visitor_id(Map::GetVisitorId(this));
3590 : }
3591 21023589 : }
3592 :
3593 :
3594 1132049622 : ACCESSORS(Map, instance_descriptors, DescriptorArray, kDescriptorsOffset)
3595 304997388 : ACCESSORS(Map, layout_descriptor, LayoutDescriptor, kLayoutDescriptorOffset)
3596 :
3597 : void Map::set_bit_field3(uint32_t bits) {
3598 : if (kInt32Size != kPointerSize) {
3599 124882540 : WRITE_UINT32_FIELD(this, kBitField3Offset + kInt32Size, 0);
3600 : }
3601 151309269 : WRITE_UINT32_FIELD(this, kBitField3Offset, bits);
3602 : }
3603 :
3604 :
3605 : uint32_t Map::bit_field3() const {
3606 1672667779 : return READ_UINT32_FIELD(this, kBitField3Offset);
3607 : }
3608 :
3609 : LayoutDescriptor* Map::GetLayoutDescriptor() const {
3610 : return FLAG_unbox_double_fields ? layout_descriptor()
3611 : : LayoutDescriptor::FastPointerLayout();
3612 : }
3613 :
3614 :
3615 6350 : void Map::AppendDescriptor(Descriptor* desc) {
3616 : DescriptorArray* descriptors = instance_descriptors();
3617 : int number_of_own_descriptors = NumberOfOwnDescriptors();
3618 : DCHECK(descriptors->number_of_descriptors() == number_of_own_descriptors);
3619 6350 : descriptors->Append(desc);
3620 6350 : SetNumberOfOwnDescriptors(number_of_own_descriptors + 1);
3621 :
3622 : // Properly mark the map if the {desc} is an "interesting symbol".
3623 6350 : if (desc->GetKey()->IsInterestingSymbol()) {
3624 : set_may_have_interesting_symbols(true);
3625 : }
3626 : PropertyDetails details = desc->GetDetails();
3627 6350 : if (details.location() == kField) {
3628 : DCHECK_GT(UnusedPropertyFields(), 0);
3629 1586 : AccountAddedPropertyField();
3630 : }
3631 :
3632 : // This function does not support appending double field descriptors and
3633 : // it should never try to (otherwise, layout descriptor must be updated too).
3634 : #ifdef DEBUG
3635 : DCHECK(details.location() != kField || !details.representation().IsDouble());
3636 : #endif
3637 6350 : }
3638 :
3639 115057639 : Object* Map::GetBackPointer() const {
3640 : Object* object = constructor_or_backpointer();
3641 115057639 : if (object->IsMap()) {
3642 : return object;
3643 : }
3644 47761087 : return GetIsolate()->heap()->undefined_value();
3645 : }
3646 :
3647 1651154 : Map* Map::ElementsTransitionMap() {
3648 : DisallowHeapAllocation no_gc;
3649 : return TransitionsAccessor(this, &no_gc)
3650 3302308 : .SearchSpecial(GetHeap()->elements_transition_symbol());
3651 : }
3652 :
3653 :
3654 263539491 : ACCESSORS(Map, raw_transitions, Object, kTransitionsOrPrototypeInfoOffset)
3655 :
3656 :
3657 : Object* Map::prototype_info() const {
3658 : DCHECK(is_prototype_map());
3659 66621700 : return READ_FIELD(this, Map::kTransitionsOrPrototypeInfoOffset);
3660 : }
3661 :
3662 :
3663 8219087 : void Map::set_prototype_info(Object* value, WriteBarrierMode mode) {
3664 : DCHECK(is_prototype_map());
3665 8219087 : WRITE_FIELD(this, Map::kTransitionsOrPrototypeInfoOffset, value);
3666 32876351 : CONDITIONAL_WRITE_BARRIER(
3667 : GetHeap(), this, Map::kTransitionsOrPrototypeInfoOffset, value, mode);
3668 8219087 : }
3669 :
3670 :
3671 : void Map::SetBackPointer(Object* value, WriteBarrierMode mode) {
3672 : DCHECK(instance_type() >= FIRST_JS_RECEIVER_TYPE);
3673 : DCHECK(value->IsMap());
3674 : DCHECK(GetBackPointer()->IsUndefined(GetIsolate()));
3675 : DCHECK(!value->IsMap() ||
3676 : Map::cast(value)->GetConstructor() == constructor_or_backpointer());
3677 6145954 : set_constructor_or_backpointer(value, mode);
3678 : }
3679 :
3680 71390175 : ACCESSORS(Map, dependent_code, DependentCode, kDependentCodeOffset)
3681 183419463 : ACCESSORS(Map, weak_cell_cache, Object, kWeakCellCacheOffset)
3682 685007546 : ACCESSORS(Map, constructor_or_backpointer, Object,
3683 : kConstructorOrBackPointerOffset)
3684 :
3685 83181934 : Object* Map::GetConstructor() const {
3686 : Object* maybe_constructor = constructor_or_backpointer();
3687 : // Follow any back pointers.
3688 422680616 : while (maybe_constructor->IsMap()) {
3689 : maybe_constructor =
3690 : Map::cast(maybe_constructor)->constructor_or_backpointer();
3691 : }
3692 83181925 : return maybe_constructor;
3693 : }
3694 :
3695 2252002 : FunctionTemplateInfo* Map::GetFunctionTemplateInfo() const {
3696 2252002 : Object* constructor = GetConstructor();
3697 2252002 : if (constructor->IsJSFunction()) {
3698 : DCHECK(JSFunction::cast(constructor)->shared()->IsApiFunction());
3699 2252002 : return JSFunction::cast(constructor)->shared()->get_api_func_data();
3700 : }
3701 : DCHECK(constructor->IsFunctionTemplateInfo());
3702 : return FunctionTemplateInfo::cast(constructor);
3703 : }
3704 :
3705 : void Map::SetConstructor(Object* constructor, WriteBarrierMode mode) {
3706 : // Never overwrite a back pointer with a constructor.
3707 : DCHECK(!constructor_or_backpointer()->IsMap());
3708 7460875 : set_constructor_or_backpointer(constructor, mode);
3709 : }
3710 :
3711 :
3712 125601 : Handle<Map> Map::CopyInitialMap(Handle<Map> map) {
3713 : return CopyInitialMap(map, map->instance_size(), map->GetInObjectProperties(),
3714 125601 : map->UnusedPropertyFields());
3715 : }
3716 :
3717 : Object* JSBoundFunction::raw_bound_target_function() const {
3718 : return READ_FIELD(this, kBoundTargetFunctionOffset);
3719 : }
3720 :
3721 3697 : ACCESSORS(JSBoundFunction, bound_target_function, JSReceiver,
3722 : kBoundTargetFunctionOffset)
3723 1537 : ACCESSORS(JSBoundFunction, bound_this, Object, kBoundThisOffset)
3724 2309 : ACCESSORS(JSBoundFunction, bound_arguments, FixedArray, kBoundArgumentsOffset)
3725 :
3726 282765198 : ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset)
3727 185575729 : ACCESSORS(JSFunction, feedback_vector_cell, Cell, kFeedbackVectorOffset)
3728 :
3729 15127394 : ACCESSORS(JSGlobalObject, native_context, Context, kNativeContextOffset)
3730 478021 : ACCESSORS(JSGlobalObject, global_proxy, JSObject, kGlobalProxyOffset)
3731 :
3732 6232006 : ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset)
3733 501794 : ACCESSORS(JSGlobalProxy, hash, Object, kHashOffset)
3734 :
3735 1356398 : ACCESSORS(AccessorInfo, name, Object, kNameOffset)
3736 3887103 : SMI_ACCESSORS(AccessorInfo, flag, kFlagOffset)
3737 1039522 : ACCESSORS(AccessorInfo, expected_receiver_type, Object,
3738 : kExpectedReceiverTypeOffset)
3739 :
3740 1567044 : ACCESSORS(AccessorInfo, getter, Object, kGetterOffset)
3741 1923549 : ACCESSORS(AccessorInfo, setter, Object, kSetterOffset)
3742 793155 : ACCESSORS(AccessorInfo, js_getter, Object, kJsGetterOffset)
3743 1934890 : ACCESSORS(AccessorInfo, data, Object, kDataOffset)
3744 :
3745 25668 : ACCESSORS(PromiseResolveThenableJobInfo, thenable, JSReceiver, kThenableOffset)
3746 25668 : ACCESSORS(PromiseResolveThenableJobInfo, then, JSReceiver, kThenOffset)
3747 25668 : ACCESSORS(PromiseResolveThenableJobInfo, resolve, JSFunction, kResolveOffset)
3748 25668 : ACCESSORS(PromiseResolveThenableJobInfo, reject, JSFunction, kRejectOffset)
3749 25668 : ACCESSORS(PromiseResolveThenableJobInfo, context, Context, kContextOffset);
3750 :
3751 175563 : ACCESSORS(PromiseReactionJobInfo, value, Object, kValueOffset);
3752 175563 : ACCESSORS(PromiseReactionJobInfo, tasks, Object, kTasksOffset);
3753 175563 : ACCESSORS(PromiseReactionJobInfo, deferred_promise, Object,
3754 : kDeferredPromiseOffset);
3755 175564 : ACCESSORS(PromiseReactionJobInfo, deferred_on_resolve, Object,
3756 : kDeferredOnResolveOffset);
3757 175564 : ACCESSORS(PromiseReactionJobInfo, deferred_on_reject, Object,
3758 : kDeferredOnRejectOffset);
3759 175563 : ACCESSORS(PromiseReactionJobInfo, context, Context, kContextOffset);
3760 :
3761 : ACCESSORS(AsyncGeneratorRequest, next, Object, kNextOffset)
3762 : SMI_ACCESSORS(AsyncGeneratorRequest, resume_mode, kResumeModeOffset)
3763 : ACCESSORS(AsyncGeneratorRequest, value, Object, kValueOffset)
3764 : ACCESSORS(AsyncGeneratorRequest, promise, Object, kPromiseOffset)
3765 :
3766 : Map* PrototypeInfo::ObjectCreateMap() {
3767 : return Map::cast(WeakCell::cast(object_create_map())->value());
3768 : }
3769 :
3770 : // static
3771 121562 : void PrototypeInfo::SetObjectCreateMap(Handle<PrototypeInfo> info,
3772 : Handle<Map> map) {
3773 121562 : Handle<WeakCell> cell = Map::WeakCellForMap(map);
3774 121562 : info->set_object_create_map(*cell);
3775 121562 : }
3776 :
3777 121603 : bool PrototypeInfo::HasObjectCreateMap() {
3778 : Object* cache = object_create_map();
3779 121644 : return cache->IsWeakCell() && !WeakCell::cast(cache)->cleared();
3780 : }
3781 :
3782 4448937 : bool FunctionTemplateInfo::instantiated() {
3783 4448936 : return shared_function_info()->IsSharedFunctionInfo();
3784 : }
3785 :
3786 3171540 : FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
3787 : Object* parent = parent_template();
3788 : return parent->IsUndefined(isolate) ? nullptr
3789 3171540 : : FunctionTemplateInfo::cast(parent);
3790 : }
3791 :
3792 427853 : ObjectTemplateInfo* ObjectTemplateInfo::GetParent(Isolate* isolate) {
3793 : Object* maybe_ctor = constructor();
3794 427853 : if (maybe_ctor->IsUndefined(isolate)) return nullptr;
3795 : FunctionTemplateInfo* constructor = FunctionTemplateInfo::cast(maybe_ctor);
3796 : while (true) {
3797 151740 : constructor = constructor->GetParent(isolate);
3798 151740 : if (constructor == nullptr) return nullptr;
3799 : Object* maybe_obj = constructor->instance_template();
3800 365 : if (!maybe_obj->IsUndefined(isolate)) {
3801 : return ObjectTemplateInfo::cast(maybe_obj);
3802 : }
3803 : }
3804 : return nullptr;
3805 : }
3806 :
3807 895918 : ACCESSORS(PrototypeInfo, weak_cell, Object, kWeakCellOffset)
3808 3920419 : ACCESSORS(PrototypeInfo, prototype_users, Object, kPrototypeUsersOffset)
3809 729454 : ACCESSORS(PrototypeInfo, object_create_map, Object, kObjectCreateMap)
3810 2704353 : SMI_ACCESSORS(PrototypeInfo, registry_slot, kRegistrySlotOffset)
3811 5407466 : ACCESSORS(PrototypeInfo, validity_cell, Object, kValidityCellOffset)
3812 24708587 : SMI_ACCESSORS(PrototypeInfo, bit_field, kBitFieldOffset)
3813 995488 : BOOL_ACCESSORS(PrototypeInfo, bit_field, should_be_fast_map, kShouldBeFastBit)
3814 :
3815 5257842 : ACCESSORS(Tuple2, value1, Object, kValue1Offset)
3816 4949407 : ACCESSORS(Tuple2, value2, Object, kValue2Offset)
3817 3276609 : ACCESSORS(Tuple3, value3, Object, kValue3Offset)
3818 :
3819 5278067 : ACCESSORS(ContextExtension, scope_info, ScopeInfo, kScopeInfoOffset)
3820 10392516 : ACCESSORS(ContextExtension, extension, Object, kExtensionOffset)
3821 :
3822 314213 : SMI_ACCESSORS(ConstantElementsPair, elements_kind, kElementsKindOffset)
3823 843855 : ACCESSORS(ConstantElementsPair, constant_values, FixedArrayBase,
3824 : kConstantValuesOffset)
3825 : bool ConstantElementsPair::is_empty() const {
3826 : return constant_values()->length() == 0;
3827 : }
3828 :
3829 7902 : SMI_ACCESSORS(TemplateObjectDescription, hash, kHashOffset)
3830 22385 : ACCESSORS(TemplateObjectDescription, raw_strings, FixedArray, kRawStringsOffset)
3831 8825 : ACCESSORS(TemplateObjectDescription, cooked_strings, FixedArray,
3832 : kCookedStringsOffset)
3833 :
3834 17167868 : ACCESSORS(AccessorPair, getter, Object, kGetterOffset)
3835 2678751 : ACCESSORS(AccessorPair, setter, Object, kSetterOffset)
3836 :
3837 3474 : ACCESSORS(AccessCheckInfo, callback, Object, kCallbackOffset)
3838 1416 : ACCESSORS(AccessCheckInfo, named_interceptor, Object, kNamedInterceptorOffset)
3839 1704 : ACCESSORS(AccessCheckInfo, indexed_interceptor, Object,
3840 : kIndexedInterceptorOffset)
3841 3631 : ACCESSORS(AccessCheckInfo, data, Object, kDataOffset)
3842 :
3843 816937 : ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset)
3844 928604 : ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset)
3845 252250 : ACCESSORS(InterceptorInfo, query, Object, kQueryOffset)
3846 726 : ACCESSORS(InterceptorInfo, descriptor, Object, kDescriptorOffset)
3847 538 : ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset)
3848 1919 : ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset)
3849 700 : ACCESSORS(InterceptorInfo, definer, Object, kDefinerOffset)
3850 1285949 : ACCESSORS(InterceptorInfo, data, Object, kDataOffset)
3851 971180 : SMI_ACCESSORS(InterceptorInfo, flags, kFlagsOffset)
3852 2454 : BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols,
3853 : kCanInterceptSymbolsBit)
3854 2454 : BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit)
3855 2454 : BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking)
3856 :
3857 29061987 : ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset)
3858 29055970 : ACCESSORS(CallHandlerInfo, data, Object, kDataOffset)
3859 :
3860 16995052 : ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
3861 22353539 : ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
3862 9631194 : SMI_ACCESSORS(TemplateInfo, number_of_properties, kNumberOfProperties)
3863 13751472 : ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset)
3864 3726179 : ACCESSORS(TemplateInfo, property_accessors, Object, kPropertyAccessorsOffset)
3865 :
3866 29094562 : ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
3867 3739159 : ACCESSORS(FunctionTemplateInfo, prototype_template, Object,
3868 : kPrototypeTemplateOffset)
3869 5884635 : ACCESSORS(FunctionTemplateInfo, prototype_provider_template, Object,
3870 : kPrototypeProviderTemplateOffset)
3871 :
3872 6162925 : ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset)
3873 7997492 : ACCESSORS(FunctionTemplateInfo, named_property_handler, Object,
3874 : kNamedPropertyHandlerOffset)
3875 6983128 : ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object,
3876 : kIndexedPropertyHandlerOffset)
3877 4790723 : ACCESSORS(FunctionTemplateInfo, instance_template, Object,
3878 : kInstanceTemplateOffset)
3879 3247918 : ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
3880 14824296 : ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
3881 3086418 : ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object,
3882 : kInstanceCallHandlerOffset)
3883 342769 : ACCESSORS(FunctionTemplateInfo, access_check_info, Object,
3884 : kAccessCheckInfoOffset)
3885 22660485 : ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
3886 : kSharedFunctionInfoOffset)
3887 15101419 : ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
3888 : kCachedPropertyNameOffset)
3889 :
3890 66046847 : SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
3891 :
3892 2189320 : ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
3893 3482488 : ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
3894 :
3895 : int ObjectTemplateInfo::embedder_field_count() const {
3896 : Object* value = data();
3897 : DCHECK(value->IsSmi());
3898 334966 : return EmbedderFieldCount::decode(Smi::ToInt(value));
3899 : }
3900 :
3901 93689 : void ObjectTemplateInfo::set_embedder_field_count(int count) {
3902 : return set_data(
3903 281067 : Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
3904 : }
3905 :
3906 : bool ObjectTemplateInfo::immutable_proto() const {
3907 : Object* value = data();
3908 : DCHECK(value->IsSmi());
3909 690455 : return IsImmutablePrototype::decode(Smi::ToInt(value));
3910 : }
3911 :
3912 18 : void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
3913 : return set_data(Smi::FromInt(
3914 54 : IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
3915 : }
3916 :
3917 : int TemplateList::length() const {
3918 : return Smi::ToInt(FixedArray::cast(this)->get(kLengthIndex));
3919 : }
3920 :
3921 : Object* TemplateList::get(int index) const {
3922 103102 : return FixedArray::cast(this)->get(kFirstElementIndex + index);
3923 : }
3924 :
3925 : void TemplateList::set(int index, Object* value) {
3926 155 : FixedArray::cast(this)->set(kFirstElementIndex + index, value);
3927 : }
3928 :
3929 6252517 : ACCESSORS(AllocationSite, transition_info_or_boilerplate, Object,
3930 : kTransitionInfoOrBoilerplateOffset)
3931 :
3932 : JSObject* AllocationSite::boilerplate() const {
3933 : DCHECK(PointsToLiteral());
3934 : return JSObject::cast(transition_info_or_boilerplate());
3935 : }
3936 :
3937 : void AllocationSite::set_boilerplate(JSObject* object, WriteBarrierMode mode) {
3938 246043 : set_transition_info_or_boilerplate(object, mode);
3939 : }
3940 :
3941 : int AllocationSite::transition_info() const {
3942 : DCHECK(!PointsToLiteral());
3943 : return Smi::cast(transition_info_or_boilerplate())->value();
3944 : }
3945 :
3946 : void AllocationSite::set_transition_info(int value) {
3947 : DCHECK(!PointsToLiteral());
3948 360382 : set_transition_info_or_boilerplate(Smi::FromInt(value), SKIP_WRITE_BARRIER);
3949 : }
3950 :
3951 3207148 : ACCESSORS(AllocationSite, nested_site, Object, kNestedSiteOffset)
3952 1754940 : SMI_ACCESSORS(AllocationSite, pretenure_data, kPretenureDataOffset)
3953 4605642 : SMI_ACCESSORS(AllocationSite, pretenure_create_count,
3954 : kPretenureCreateCountOffset)
3955 771894 : ACCESSORS(AllocationSite, dependent_code, DependentCode,
3956 : kDependentCodeOffset)
3957 3974951 : ACCESSORS(AllocationSite, weak_next, Object, kWeakNextOffset)
3958 8095619 : ACCESSORS(AllocationMemento, allocation_site, Object, kAllocationSiteOffset)
3959 :
3960 53874 : SMI_ACCESSORS(StackFrameInfo, line_number, kLineNumberIndex)
3961 53839 : SMI_ACCESSORS(StackFrameInfo, column_number, kColumnNumberIndex)
3962 53560 : SMI_ACCESSORS(StackFrameInfo, script_id, kScriptIdIndex)
3963 101709 : ACCESSORS(StackFrameInfo, script_name, Object, kScriptNameIndex)
3964 134402 : ACCESSORS(StackFrameInfo, script_name_or_source_url, Object,
3965 : kScriptNameOrSourceUrlIndex)
3966 196640 : ACCESSORS(StackFrameInfo, function_name, Object, kFunctionNameIndex)
3967 103884 : SMI_ACCESSORS(StackFrameInfo, flag, kFlagIndex)
3968 19940 : BOOL_ACCESSORS(StackFrameInfo, flag, is_eval, kIsEvalBit)
3969 19940 : BOOL_ACCESSORS(StackFrameInfo, flag, is_constructor, kIsConstructorBit)
3970 20658 : BOOL_ACCESSORS(StackFrameInfo, flag, is_wasm, kIsWasmBit)
3971 51906 : SMI_ACCESSORS(StackFrameInfo, id, kIdIndex)
3972 :
3973 224866 : ACCESSORS(SourcePositionTableWithFrameCache, source_position_table, ByteArray,
3974 : kSourcePositionTableIndex)
3975 100444 : ACCESSORS(SourcePositionTableWithFrameCache, stack_frame_cache,
3976 : UnseededNumberDictionary, kStackFrameCacheIndex)
3977 :
3978 6039310 : SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
3979 506 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype,
3980 : kHiddenPrototypeBit)
3981 6040400 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
3982 6136992 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
3983 : kNeedsAccessCheckBit)
3984 2897090 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
3985 : kReadOnlyPrototypeBit)
3986 60756 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
3987 : kRemovePrototypeBit)
3988 6040092 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache,
3989 : kDoNotCacheBit)
3990 6040106 : BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
3991 : kAcceptAnyReceiver)
3992 :
3993 131789 : FeedbackVector* JSFunction::feedback_vector() const {
3994 : DCHECK(feedback_vector_cell()->value()->IsFeedbackVector());
3995 131789 : return FeedbackVector::cast(feedback_vector_cell()->value());
3996 : }
3997 :
3998 : // Code objects that are marked for deoptimization are not considered to be
3999 : // optimized. This is because the JSFunction might have been already
4000 : // deoptimized but its code() still needs to be unlinked, which will happen on
4001 : // its next activation.
4002 : // TODO(jupvfranco): rename this function. Maybe RunOptimizedCode,
4003 : // or IsValidOptimizedCode.
4004 273433 : bool JSFunction::IsOptimized() {
4005 2280522 : return code()->kind() == Code::OPTIMIZED_FUNCTION &&
4006 273433 : !code()->marked_for_deoptimization();
4007 : }
4008 :
4009 688009 : bool JSFunction::HasOptimizedCode() {
4010 1368493 : return IsOptimized() ||
4011 1639352 : (has_feedback_vector() && feedback_vector()->has_optimized_code() &&
4012 688009 : !feedback_vector()->optimized_code()->marked_for_deoptimization());
4013 : }
4014 :
4015 457031 : bool JSFunction::HasOptimizationMarker() {
4016 914062 : return has_feedback_vector() && feedback_vector()->has_optimization_marker();
4017 : }
4018 :
4019 : void JSFunction::ClearOptimizationMarker() {
4020 : DCHECK(has_feedback_vector());
4021 : DCHECK(!feedback_vector()->has_optimized_code());
4022 307560 : feedback_vector()->SetOptimizationMarker(OptimizationMarker::kNone);
4023 : }
4024 :
4025 4479 : bool JSFunction::IsInterpreted() {
4026 4479 : return code()->is_interpreter_trampoline_builtin();
4027 : }
4028 :
4029 : bool JSFunction::ChecksOptimizationMarker() {
4030 : return code()->checks_optimization_marker();
4031 : }
4032 :
4033 75713 : bool JSFunction::IsMarkedForOptimization() {
4034 151414 : return has_feedback_vector() && feedback_vector()->optimization_marker() ==
4035 75713 : OptimizationMarker::kCompileOptimized;
4036 : }
4037 :
4038 :
4039 69454 : bool JSFunction::IsMarkedForConcurrentOptimization() {
4040 138908 : return has_feedback_vector() &&
4041 : feedback_vector()->optimization_marker() ==
4042 69454 : OptimizationMarker::kCompileOptimizedConcurrent;
4043 : }
4044 :
4045 :
4046 110839 : bool JSFunction::IsInOptimizationQueue() {
4047 221642 : return has_feedback_vector() && feedback_vector()->optimization_marker() ==
4048 110839 : OptimizationMarker::kInOptimizationQueue;
4049 : }
4050 :
4051 :
4052 188648 : void JSFunction::CompleteInobjectSlackTrackingIfActive() {
4053 377296 : if (!has_prototype_slot()) return;
4054 161808 : if (has_initial_map() && initial_map()->IsInobjectSlackTrackingInProgress()) {
4055 28964 : initial_map()->CompleteInobjectSlackTracking();
4056 : }
4057 : }
4058 :
4059 : bool Map::IsInobjectSlackTrackingInProgress() const {
4060 23518563 : return construction_counter() != Map::kNoSlackTracking;
4061 : }
4062 :
4063 :
4064 252230 : void Map::InobjectSlackTrackingStep() {
4065 504460 : if (!IsInobjectSlackTrackingInProgress()) return;
4066 : int counter = construction_counter();
4067 252230 : set_construction_counter(counter - 1);
4068 252230 : if (counter == kSlackTrackingCounterEnd) {
4069 1413 : CompleteInobjectSlackTracking();
4070 : }
4071 : }
4072 :
4073 198 : AbstractCode* JSFunction::abstract_code() {
4074 198 : if (IsInterpreted()) {
4075 148 : return AbstractCode::cast(shared()->bytecode_array());
4076 : } else {
4077 : return AbstractCode::cast(code());
4078 : }
4079 : }
4080 :
4081 7273657 : Code* JSFunction::code() { return Code::cast(READ_FIELD(this, kCodeOffset)); }
4082 :
4083 16909961 : void JSFunction::set_code(Code* value) {
4084 : DCHECK(!GetHeap()->InNewSpace(value));
4085 16909961 : WRITE_FIELD(this, kCodeOffset, value);
4086 : GetHeap()->incremental_marking()->RecordWrite(
4087 33819922 : this, HeapObject::RawField(this, kCodeOffset), value);
4088 16909961 : }
4089 :
4090 :
4091 : void JSFunction::set_code_no_write_barrier(Code* value) {
4092 : DCHECK(!GetHeap()->InNewSpace(value));
4093 38859 : WRITE_FIELD(this, kCodeOffset, value);
4094 : }
4095 :
4096 : void JSFunction::ClearOptimizedCodeSlot(const char* reason) {
4097 : if (has_feedback_vector() && feedback_vector()->has_optimized_code()) {
4098 : if (FLAG_trace_opt) {
4099 : PrintF("[evicting entry from optimizing code feedback slot (%s) for ",
4100 : reason);
4101 : ShortPrint();
4102 : PrintF("]\n");
4103 : }
4104 : feedback_vector()->ClearOptimizedCode();
4105 : }
4106 : }
4107 :
4108 5352 : void JSFunction::SetOptimizationMarker(OptimizationMarker marker) {
4109 : DCHECK(has_feedback_vector());
4110 : DCHECK(ChecksOptimizationMarker());
4111 : DCHECK(!HasOptimizedCode());
4112 :
4113 365981 : feedback_vector()->SetOptimizationMarker(marker);
4114 5352 : }
4115 :
4116 7361326 : bool JSFunction::has_feedback_vector() const {
4117 7361326 : return !feedback_vector_cell()->value()->IsUndefined(GetIsolate());
4118 : }
4119 :
4120 12159297 : JSFunction::FeedbackVectorState JSFunction::GetFeedbackVectorState(
4121 : Isolate* isolate) const {
4122 : Cell* cell = feedback_vector_cell();
4123 12159297 : if (shared()->HasAsmWasmData()) {
4124 : return NO_VECTOR_NEEDED;
4125 12156929 : } else if (cell == isolate->heap()->undefined_cell()) {
4126 : return TOP_LEVEL_SCRIPT_NEEDS_VECTOR;
4127 13523086 : } else if (cell->value() == isolate->heap()->undefined_value() ||
4128 5967722 : !has_feedback_vector()) {
4129 : return NEEDS_VECTOR;
4130 : }
4131 5967722 : return HAS_VECTOR;
4132 : }
4133 :
4134 12220 : Context* JSFunction::context() {
4135 19692965 : return Context::cast(READ_FIELD(this, kContextOffset));
4136 : }
4137 :
4138 223002 : bool JSFunction::has_context() const {
4139 446004 : return READ_FIELD(this, kContextOffset)->IsContext();
4140 : }
4141 :
4142 56 : JSObject* JSFunction::global_proxy() {
4143 1199218 : return context()->global_proxy();
4144 : }
4145 :
4146 :
4147 293646 : Context* JSFunction::native_context() { return context()->native_context(); }
4148 :
4149 :
4150 15088208 : void JSFunction::set_context(Object* value) {
4151 : DCHECK(value->IsUndefined(GetIsolate()) || value->IsContext());
4152 15088208 : WRITE_FIELD(this, kContextOffset, value);
4153 45264623 : WRITE_BARRIER(GetHeap(), this, kContextOffset, value);
4154 15088209 : }
4155 :
4156 128438424 : ACCESSORS_CHECKED(JSFunction, prototype_or_initial_map, Object,
4157 : kPrototypeOrInitialMapOffset, map()->has_prototype_slot())
4158 :
4159 627562 : bool JSFunction::has_prototype_slot() const {
4160 627562 : return map()->has_prototype_slot();
4161 : }
4162 :
4163 3142 : Map* JSFunction::initial_map() {
4164 3142 : return Map::cast(prototype_or_initial_map());
4165 : }
4166 :
4167 :
4168 20068610 : bool JSFunction::has_initial_map() {
4169 : DCHECK(has_prototype_slot());
4170 20068612 : return prototype_or_initial_map()->IsMap();
4171 : }
4172 :
4173 :
4174 565468 : bool JSFunction::has_instance_prototype() {
4175 : DCHECK(has_prototype_slot());
4176 1105980 : return has_initial_map() ||
4177 565468 : !prototype_or_initial_map()->IsTheHole(GetIsolate());
4178 : }
4179 :
4180 :
4181 251883 : bool JSFunction::has_prototype() {
4182 : DCHECK(has_prototype_slot());
4183 251883 : return map()->has_non_instance_prototype() || has_instance_prototype();
4184 : }
4185 :
4186 :
4187 : Object* JSFunction::instance_prototype() {
4188 : DCHECK(has_instance_prototype());
4189 4091565 : if (has_initial_map()) return initial_map()->prototype();
4190 : // When there is no initial map and the prototype is a JSObject, the
4191 : // initial map field is used for the prototype field.
4192 : return prototype_or_initial_map();
4193 : }
4194 :
4195 :
4196 3340602 : Object* JSFunction::prototype() {
4197 : DCHECK(has_prototype());
4198 : // If the function's prototype property has been set to a non-JSObject
4199 : // value, that value is stored in the constructor field of the map.
4200 3340602 : if (map()->has_non_instance_prototype()) {
4201 14273 : Object* prototype = map()->GetConstructor();
4202 : // The map must have a prototype in that field, not a back pointer.
4203 : DCHECK(!prototype->IsMap());
4204 : DCHECK(!prototype->IsFunctionTemplateInfo());
4205 14273 : return prototype;
4206 : }
4207 3326329 : return instance_prototype();
4208 : }
4209 :
4210 :
4211 1037 : bool JSFunction::is_compiled() {
4212 : Builtins* builtins = GetIsolate()->builtins();
4213 1042 : return code() != builtins->builtin(Builtins::kCompileLazy);
4214 : }
4215 :
4216 5983930 : ACCESSORS(JSProxy, target, JSReceiver, kTargetOffset)
4217 10943750 : ACCESSORS(JSProxy, handler, Object, kHandlerOffset)
4218 4048 : ACCESSORS(JSProxy, hash, Object, kHashOffset)
4219 :
4220 5984139 : bool JSProxy::IsRevoked() const { return !handler()->IsJSReceiver(); }
4221 :
4222 884214 : ACCESSORS(JSCollection, table, Object, kTableOffset)
4223 620 : ACCESSORS(JSCollectionIterator, table, Object, kTableOffset)
4224 1393 : ACCESSORS(JSCollectionIterator, index, Object, kIndexOffset)
4225 :
4226 495315 : ACCESSORS(JSWeakCollection, table, Object, kTableOffset)
4227 126977 : ACCESSORS(JSWeakCollection, next, Object, kNextOffset)
4228 :
4229 :
4230 : Address Foreign::foreign_address() {
4231 35138110 : return AddressFrom<Address>(READ_INTPTR_FIELD(this, kForeignAddressOffset));
4232 : }
4233 :
4234 :
4235 : void Foreign::set_foreign_address(Address value) {
4236 4019432 : WRITE_INTPTR_FIELD(this, kForeignAddressOffset, OffsetFrom(value));
4237 : }
4238 :
4239 : template <class Derived>
4240 9216 : void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
4241 : Object* value) {
4242 : int entry_offset = GetDataEntryOffset(entry, relative_index);
4243 9216 : RELAXED_WRITE_FIELD(this, entry_offset, value);
4244 18432 : WRITE_BARRIER(GetHeap(), this, entry_offset, value);
4245 9216 : }
4246 :
4247 66739 : ACCESSORS(JSGeneratorObject, function, JSFunction, kFunctionOffset)
4248 59337 : ACCESSORS(JSGeneratorObject, context, Context, kContextOffset)
4249 56235 : ACCESSORS(JSGeneratorObject, receiver, Object, kReceiverOffset)
4250 1598 : ACCESSORS(JSGeneratorObject, input_or_debug_pos, Object, kInputOrDebugPosOffset)
4251 23 : SMI_ACCESSORS(JSGeneratorObject, resume_mode, kResumeModeOffset)
4252 37103 : SMI_ACCESSORS(JSGeneratorObject, continuation, kContinuationOffset)
4253 56657 : ACCESSORS(JSGeneratorObject, register_file, FixedArray, kRegisterFileOffset)
4254 :
4255 1233 : bool JSGeneratorObject::is_suspended() const {
4256 : DCHECK_LT(kGeneratorExecuting, 0);
4257 : DCHECK_LT(kGeneratorClosed, 0);
4258 1323 : return continuation() >= 0;
4259 : }
4260 :
4261 : bool JSGeneratorObject::is_closed() const {
4262 : return continuation() == kGeneratorClosed;
4263 : }
4264 :
4265 : bool JSGeneratorObject::is_executing() const {
4266 : return continuation() == kGeneratorExecuting;
4267 : }
4268 :
4269 35 : ACCESSORS(JSAsyncGeneratorObject, queue, HeapObject, kQueueOffset)
4270 35 : ACCESSORS(JSAsyncGeneratorObject, awaited_promise, HeapObject,
4271 : kAwaitedPromiseOffset)
4272 :
4273 2705589 : ACCESSORS(JSValue, value, Object, kValueOffset)
4274 :
4275 :
4276 : HeapNumber* HeapNumber::cast(Object* object) {
4277 : SLOW_DCHECK(object->IsHeapNumber() || object->IsMutableHeapNumber());
4278 : return reinterpret_cast<HeapNumber*>(object);
4279 : }
4280 :
4281 :
4282 : const HeapNumber* HeapNumber::cast(const Object* object) {
4283 : SLOW_DCHECK(object->IsHeapNumber() || object->IsMutableHeapNumber());
4284 : return reinterpret_cast<const HeapNumber*>(object);
4285 : }
4286 :
4287 :
4288 915654 : ACCESSORS(JSDate, value, Object, kValueOffset)
4289 342755 : ACCESSORS(JSDate, cache_stamp, Object, kCacheStampOffset)
4290 24063 : ACCESSORS(JSDate, year, Object, kYearOffset)
4291 23413 : ACCESSORS(JSDate, month, Object, kMonthOffset)
4292 23241 : ACCESSORS(JSDate, day, Object, kDayOffset)
4293 23168 : ACCESSORS(JSDate, weekday, Object, kWeekdayOffset)
4294 26310 : ACCESSORS(JSDate, hour, Object, kHourOffset)
4295 24020 : ACCESSORS(JSDate, min, Object, kMinOffset)
4296 23394 : ACCESSORS(JSDate, sec, Object, kSecOffset)
4297 :
4298 :
4299 1187875 : SMI_ACCESSORS(JSMessageObject, type, kTypeOffset)
4300 5948827 : ACCESSORS(JSMessageObject, argument, Object, kArgumentsOffset)
4301 5979726 : ACCESSORS(JSMessageObject, script, Object, kScriptOffset)
4302 5917700 : ACCESSORS(JSMessageObject, stack_frames, Object, kStackFramesOffset)
4303 1263382 : SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset)
4304 1200660 : SMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset)
4305 1216778 : SMI_ACCESSORS(JSMessageObject, error_level, kErrorLevelOffset)
4306 :
4307 :
4308 :
4309 30 : ACCESSORS(PromiseCapability, promise, Object, kPromiseOffset)
4310 30 : ACCESSORS(PromiseCapability, resolve, Object, kResolveOffset)
4311 30 : ACCESSORS(PromiseCapability, reject, Object, kRejectOffset)
4312 :
4313 71 : ACCESSORS(JSPromise, result, Object, kResultOffset)
4314 3669 : ACCESSORS(JSPromise, deferred_promise, Object, kDeferredPromiseOffset)
4315 25 : ACCESSORS(JSPromise, deferred_on_resolve, Object, kDeferredOnResolveOffset)
4316 25 : ACCESSORS(JSPromise, deferred_on_reject, Object, kDeferredOnRejectOffset)
4317 25 : ACCESSORS(JSPromise, fulfill_reactions, Object, kFulfillReactionsOffset)
4318 3669 : ACCESSORS(JSPromise, reject_reactions, Object, kRejectReactionsOffset)
4319 11949 : SMI_ACCESSORS(JSPromise, flags, kFlagsOffset)
4320 9744 : BOOL_ACCESSORS(JSPromise, flags, has_handler, kHasHandlerBit)
4321 650 : BOOL_ACCESSORS(JSPromise, flags, handled_hint, kHandledHintBit)
4322 :
4323 :
4324 1469330 : ElementsKind JSObject::GetElementsKind() {
4325 : ElementsKind kind = map()->elements_kind();
4326 : #if VERIFY_HEAP && DEBUG
4327 : FixedArrayBase* fixed_array =
4328 : reinterpret_cast<FixedArrayBase*>(READ_FIELD(this, kElementsOffset));
4329 :
4330 : // If a GC was caused while constructing this object, the elements
4331 : // pointer may point to a one pointer filler map.
4332 : if (ElementsAreSafeToExamine()) {
4333 : Map* map = fixed_array->map();
4334 : if (IsSmiOrObjectElementsKind(kind)) {
4335 : DCHECK(map == GetHeap()->fixed_array_map() ||
4336 : map == GetHeap()->fixed_cow_array_map());
4337 : } else if (IsDoubleElementsKind(kind)) {
4338 : DCHECK(fixed_array->IsFixedDoubleArray() ||
4339 : fixed_array == GetHeap()->empty_fixed_array());
4340 : } else if (kind == DICTIONARY_ELEMENTS) {
4341 : DCHECK(fixed_array->IsFixedArray());
4342 : DCHECK(fixed_array->IsDictionary());
4343 : } else {
4344 : DCHECK(kind > DICTIONARY_ELEMENTS);
4345 : }
4346 : DCHECK(!IsSloppyArgumentsElementsKind(kind) ||
4347 : (elements()->IsFixedArray() && elements()->length() >= 2));
4348 : }
4349 : #endif
4350 1469330 : return kind;
4351 : }
4352 :
4353 2270276 : bool JSObject::HasObjectElements() {
4354 2270276 : return IsObjectElementsKind(GetElementsKind());
4355 : }
4356 :
4357 2547164 : bool JSObject::HasSmiElements() { return IsSmiElementsKind(GetElementsKind()); }
4358 :
4359 1502121 : bool JSObject::HasSmiOrObjectElements() {
4360 1502121 : return IsSmiOrObjectElementsKind(GetElementsKind());
4361 : }
4362 :
4363 2524007 : bool JSObject::HasDoubleElements() {
4364 2524007 : return IsDoubleElementsKind(GetElementsKind());
4365 : }
4366 :
4367 5500937 : bool JSObject::HasHoleyElements() {
4368 5500937 : return IsHoleyElementsKind(GetElementsKind());
4369 : }
4370 :
4371 :
4372 3432503 : bool JSObject::HasFastElements() {
4373 3432503 : return IsFastElementsKind(GetElementsKind());
4374 : }
4375 :
4376 :
4377 715442 : bool JSObject::HasDictionaryElements() {
4378 715442 : return GetElementsKind() == DICTIONARY_ELEMENTS;
4379 : }
4380 :
4381 :
4382 : bool JSObject::HasFastArgumentsElements() {
4383 : return GetElementsKind() == FAST_SLOPPY_ARGUMENTS_ELEMENTS;
4384 : }
4385 :
4386 :
4387 360734 : bool JSObject::HasSlowArgumentsElements() {
4388 360734 : return GetElementsKind() == SLOW_SLOPPY_ARGUMENTS_ELEMENTS;
4389 : }
4390 :
4391 :
4392 1203327 : bool JSObject::HasSloppyArgumentsElements() {
4393 1203327 : return IsSloppyArgumentsElementsKind(GetElementsKind());
4394 : }
4395 :
4396 93274 : bool JSObject::HasStringWrapperElements() {
4397 93274 : return IsStringWrapperElementsKind(GetElementsKind());
4398 : }
4399 :
4400 1488070 : bool JSObject::HasFastStringWrapperElements() {
4401 1488070 : return GetElementsKind() == FAST_STRING_WRAPPER_ELEMENTS;
4402 : }
4403 :
4404 260756 : bool JSObject::HasSlowStringWrapperElements() {
4405 260756 : return GetElementsKind() == SLOW_STRING_WRAPPER_ELEMENTS;
4406 : }
4407 :
4408 1543289 : bool JSObject::HasFixedTypedArrayElements() {
4409 : DCHECK_NOT_NULL(elements());
4410 1543289 : return map()->has_fixed_typed_array_elements();
4411 : }
4412 :
4413 : #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \
4414 : bool JSObject::HasFixed##Type##Elements() { \
4415 : HeapObject* array = elements(); \
4416 : DCHECK_NOT_NULL(array); \
4417 : if (!array->IsHeapObject()) return false; \
4418 : return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \
4419 : }
4420 :
4421 1620 : TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK)
4422 :
4423 : #undef FIXED_TYPED_ELEMENTS_CHECK
4424 :
4425 :
4426 0 : bool JSObject::HasNamedInterceptor() {
4427 0 : return map()->has_named_interceptor();
4428 : }
4429 :
4430 :
4431 0 : bool JSObject::HasIndexedInterceptor() {
4432 0 : return map()->has_indexed_interceptor();
4433 : }
4434 :
4435 : void JSGlobalObject::set_global_dictionary(GlobalDictionary* dictionary) {
4436 : DCHECK(IsJSGlobalObject());
4437 84635 : set_raw_properties_or_hash(dictionary);
4438 : }
4439 :
4440 : GlobalDictionary* JSGlobalObject::global_dictionary() {
4441 : DCHECK(!HasFastProperties());
4442 : DCHECK(IsJSGlobalObject());
4443 : return GlobalDictionary::cast(raw_properties_or_hash());
4444 : }
4445 :
4446 :
4447 : SeededNumberDictionary* JSObject::element_dictionary() {
4448 : DCHECK(HasDictionaryElements() || HasSlowStringWrapperElements());
4449 : return SeededNumberDictionary::cast(elements());
4450 : }
4451 :
4452 : // static
4453 210 : Maybe<bool> Object::GreaterThan(Handle<Object> x, Handle<Object> y) {
4454 210 : Maybe<ComparisonResult> result = Compare(x, y);
4455 210 : if (result.IsJust()) {
4456 210 : switch (result.FromJust()) {
4457 : case ComparisonResult::kGreaterThan:
4458 : return Just(true);
4459 : case ComparisonResult::kLessThan:
4460 : case ComparisonResult::kEqual:
4461 : case ComparisonResult::kUndefined:
4462 : return Just(false);
4463 : }
4464 : }
4465 : return Nothing<bool>();
4466 : }
4467 :
4468 :
4469 : // static
4470 210 : Maybe<bool> Object::GreaterThanOrEqual(Handle<Object> x, Handle<Object> y) {
4471 210 : Maybe<ComparisonResult> result = Compare(x, y);
4472 210 : if (result.IsJust()) {
4473 210 : switch (result.FromJust()) {
4474 : case ComparisonResult::kEqual:
4475 : case ComparisonResult::kGreaterThan:
4476 : return Just(true);
4477 : case ComparisonResult::kLessThan:
4478 : case ComparisonResult::kUndefined:
4479 : return Just(false);
4480 : }
4481 : }
4482 : return Nothing<bool>();
4483 : }
4484 :
4485 :
4486 : // static
4487 210 : Maybe<bool> Object::LessThan(Handle<Object> x, Handle<Object> y) {
4488 210 : Maybe<ComparisonResult> result = Compare(x, y);
4489 210 : if (result.IsJust()) {
4490 210 : switch (result.FromJust()) {
4491 : case ComparisonResult::kLessThan:
4492 : return Just(true);
4493 : case ComparisonResult::kEqual:
4494 : case ComparisonResult::kGreaterThan:
4495 : case ComparisonResult::kUndefined:
4496 : return Just(false);
4497 : }
4498 : }
4499 : return Nothing<bool>();
4500 : }
4501 :
4502 :
4503 : // static
4504 210 : Maybe<bool> Object::LessThanOrEqual(Handle<Object> x, Handle<Object> y) {
4505 210 : Maybe<ComparisonResult> result = Compare(x, y);
4506 210 : if (result.IsJust()) {
4507 210 : switch (result.FromJust()) {
4508 : case ComparisonResult::kEqual:
4509 : case ComparisonResult::kLessThan:
4510 : return Just(true);
4511 : case ComparisonResult::kGreaterThan:
4512 : case ComparisonResult::kUndefined:
4513 : return Just(false);
4514 : }
4515 : }
4516 : return Nothing<bool>();
4517 : }
4518 :
4519 1081168 : MaybeHandle<Object> Object::GetPropertyOrElement(Handle<Object> object,
4520 : Handle<Name> name) {
4521 : LookupIterator it =
4522 1081168 : LookupIterator::PropertyOrElement(name->GetIsolate(), object, name);
4523 1081168 : return GetProperty(&it);
4524 : }
4525 :
4526 : MaybeHandle<Object> Object::SetPropertyOrElement(Handle<Object> object,
4527 : Handle<Name> name,
4528 : Handle<Object> value,
4529 : LanguageMode language_mode,
4530 : StoreFromKeyed store_mode) {
4531 : LookupIterator it =
4532 : LookupIterator::PropertyOrElement(name->GetIsolate(), object, name);
4533 : MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode));
4534 : return value;
4535 : }
4536 :
4537 9890 : MaybeHandle<Object> Object::GetPropertyOrElement(Handle<Object> receiver,
4538 : Handle<Name> name,
4539 : Handle<JSReceiver> holder) {
4540 : LookupIterator it = LookupIterator::PropertyOrElement(
4541 9890 : name->GetIsolate(), receiver, name, holder);
4542 9890 : return GetProperty(&it);
4543 : }
4544 :
4545 :
4546 15084879 : void JSReceiver::initialize_properties() {
4547 : DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array()));
4548 : DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_property_dictionary()));
4549 15084879 : if (map()->is_dictionary_map()) {
4550 35 : WRITE_FIELD(this, kPropertiesOrHashOffset,
4551 : GetHeap()->empty_property_dictionary());
4552 : } else {
4553 15084844 : WRITE_FIELD(this, kPropertiesOrHashOffset, GetHeap()->empty_fixed_array());
4554 : }
4555 15084879 : }
4556 :
4557 180719658 : bool JSReceiver::HasFastProperties() const {
4558 : DCHECK_EQ(raw_properties_or_hash()->IsDictionary(),
4559 : map()->is_dictionary_map());
4560 180719658 : return !map()->is_dictionary_map();
4561 : }
4562 :
4563 314 : NameDictionary* JSReceiver::property_dictionary() const {
4564 : DCHECK(!IsJSGlobalObject());
4565 : DCHECK(!HasFastProperties());
4566 :
4567 : Object* prop = raw_properties_or_hash();
4568 32955073 : if (prop->IsSmi()) {
4569 0 : return GetHeap()->empty_property_dictionary();
4570 : }
4571 :
4572 : return NameDictionary::cast(prop);
4573 : }
4574 :
4575 : // TODO(gsathya): Pass isolate directly to this function and access
4576 : // the heap from this.
4577 : PropertyArray* JSReceiver::property_array() const {
4578 : DCHECK(HasFastProperties());
4579 :
4580 : Object* prop = raw_properties_or_hash();
4581 191675038 : if (prop->IsSmi() || prop == GetHeap()->empty_fixed_array()) {
4582 10848854 : return GetHeap()->empty_property_array();
4583 : }
4584 :
4585 : return PropertyArray::cast(prop);
4586 : }
4587 :
4588 82763 : Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object,
4589 : Handle<Name> name) {
4590 : LookupIterator it = LookupIterator::PropertyOrElement(object->GetIsolate(),
4591 82763 : object, name, object);
4592 82763 : return HasProperty(&it);
4593 : }
4594 :
4595 :
4596 25 : Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object,
4597 : uint32_t index) {
4598 25 : if (object->IsJSModuleNamespace()) return Just(false);
4599 :
4600 25 : if (object->IsJSObject()) { // Shortcut.
4601 : LookupIterator it(object->GetIsolate(), object, index, object,
4602 : LookupIterator::OWN);
4603 25 : return HasProperty(&it);
4604 : }
4605 :
4606 : Maybe<PropertyAttributes> attributes =
4607 0 : JSReceiver::GetOwnPropertyAttributes(object, index);
4608 0 : MAYBE_RETURN(attributes, Nothing<bool>());
4609 0 : return Just(attributes.FromJust() != ABSENT);
4610 : }
4611 :
4612 2249879 : Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes(
4613 : Handle<JSReceiver> object, Handle<Name> name) {
4614 : LookupIterator it = LookupIterator::PropertyOrElement(name->GetIsolate(),
4615 2249879 : object, name, object);
4616 2249879 : return GetPropertyAttributes(&it);
4617 : }
4618 :
4619 :
4620 1055550 : Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
4621 : Handle<JSReceiver> object, Handle<Name> name) {
4622 : LookupIterator it = LookupIterator::PropertyOrElement(
4623 1055550 : name->GetIsolate(), object, name, object, LookupIterator::OWN);
4624 1055550 : return GetPropertyAttributes(&it);
4625 : }
4626 :
4627 0 : Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
4628 : Handle<JSReceiver> object, uint32_t index) {
4629 : LookupIterator it(object->GetIsolate(), object, index, object,
4630 : LookupIterator::OWN);
4631 0 : return GetPropertyAttributes(&it);
4632 : }
4633 :
4634 1829729 : Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) {
4635 : LookupIterator it(object->GetIsolate(), object, index, object);
4636 1829729 : return HasProperty(&it);
4637 : }
4638 :
4639 :
4640 : Maybe<PropertyAttributes> JSReceiver::GetElementAttributes(
4641 : Handle<JSReceiver> object, uint32_t index) {
4642 : Isolate* isolate = object->GetIsolate();
4643 : LookupIterator it(isolate, object, index, object);
4644 : return GetPropertyAttributes(&it);
4645 : }
4646 :
4647 :
4648 : Maybe<PropertyAttributes> JSReceiver::GetOwnElementAttributes(
4649 : Handle<JSReceiver> object, uint32_t index) {
4650 : Isolate* isolate = object->GetIsolate();
4651 : LookupIterator it(isolate, object, index, object, LookupIterator::OWN);
4652 : return GetPropertyAttributes(&it);
4653 : }
4654 :
4655 :
4656 : bool JSGlobalObject::IsDetached() {
4657 : return JSGlobalProxy::cast(global_proxy())->IsDetachedFrom(this);
4658 : }
4659 :
4660 :
4661 445473 : bool JSGlobalProxy::IsDetachedFrom(JSGlobalObject* global) const {
4662 : const PrototypeIterator iter(this->GetIsolate(),
4663 : const_cast<JSGlobalProxy*>(this));
4664 445473 : return iter.GetCurrent() != global;
4665 : }
4666 :
4667 : inline int JSGlobalProxy::SizeWithEmbedderFields(int embedder_field_count) {
4668 : DCHECK_GE(embedder_field_count, 0);
4669 83526 : return kSize + embedder_field_count * kPointerSize;
4670 : }
4671 :
4672 12799 : Smi* JSReceiver::GetOrCreateIdentityHash(Isolate* isolate) {
4673 : return IsJSProxy() ? JSProxy::cast(this)->GetOrCreateIdentityHash(isolate)
4674 23950 : : JSObject::cast(this)->GetOrCreateIdentityHash(isolate);
4675 : }
4676 :
4677 20560 : Object* JSReceiver::GetIdentityHash(Isolate* isolate) {
4678 : return IsJSProxy() ? JSProxy::cast(this)->GetIdentityHash()
4679 35594 : : JSObject::cast(this)->GetIdentityHash(isolate);
4680 : }
4681 :
4682 :
4683 : bool AccessorInfo::all_can_read() {
4684 : return BooleanBit::get(flag(), kAllCanReadBit);
4685 : }
4686 :
4687 :
4688 106009 : void AccessorInfo::set_all_can_read(bool value) {
4689 : set_flag(BooleanBit::set(flag(), kAllCanReadBit, value));
4690 106009 : }
4691 :
4692 :
4693 : bool AccessorInfo::all_can_write() {
4694 : return BooleanBit::get(flag(), kAllCanWriteBit);
4695 : }
4696 :
4697 :
4698 105985 : void AccessorInfo::set_all_can_write(bool value) {
4699 : set_flag(BooleanBit::set(flag(), kAllCanWriteBit, value));
4700 105985 : }
4701 :
4702 :
4703 : bool AccessorInfo::is_special_data_property() {
4704 : return BooleanBit::get(flag(), kSpecialDataProperty);
4705 : }
4706 :
4707 :
4708 159830 : void AccessorInfo::set_is_special_data_property(bool value) {
4709 : set_flag(BooleanBit::set(flag(), kSpecialDataProperty, value));
4710 159830 : }
4711 :
4712 : bool AccessorInfo::replace_on_access() {
4713 : return BooleanBit::get(flag(), kReplaceOnAccess);
4714 : }
4715 :
4716 159830 : void AccessorInfo::set_replace_on_access(bool value) {
4717 : set_flag(BooleanBit::set(flag(), kReplaceOnAccess, value));
4718 159830 : }
4719 :
4720 : bool AccessorInfo::is_sloppy() { return BooleanBit::get(flag(), kIsSloppy); }
4721 :
4722 265799 : void AccessorInfo::set_is_sloppy(bool value) {
4723 : set_flag(BooleanBit::set(flag(), kIsSloppy, value));
4724 265799 : }
4725 :
4726 : PropertyAttributes AccessorInfo::property_attributes() {
4727 124106 : return AttributesField::decode(static_cast<uint32_t>(flag()));
4728 : }
4729 :
4730 :
4731 159830 : void AccessorInfo::set_property_attributes(PropertyAttributes attributes) {
4732 319660 : set_flag(AttributesField::update(flag(), attributes));
4733 159830 : }
4734 :
4735 15436 : bool FunctionTemplateInfo::IsTemplateFor(JSObject* object) {
4736 15436 : return IsTemplateFor(object->map());
4737 : }
4738 :
4739 908567 : bool AccessorInfo::IsCompatibleReceiver(Object* receiver) {
4740 908567 : if (!HasExpectedReceiverType()) return true;
4741 348 : if (!receiver->IsJSObject()) return false;
4742 : return FunctionTemplateInfo::cast(expected_receiver_type())
4743 348 : ->IsTemplateFor(JSObject::cast(receiver)->map());
4744 : }
4745 :
4746 :
4747 1016730 : bool AccessorInfo::HasExpectedReceiverType() {
4748 1016730 : return expected_receiver_type()->IsFunctionTemplateInfo();
4749 : }
4750 :
4751 :
4752 : Object* AccessorPair::get(AccessorComponent component) {
4753 27992 : return component == ACCESSOR_GETTER ? getter() : setter();
4754 : }
4755 :
4756 :
4757 : void AccessorPair::set(AccessorComponent component, Object* value) {
4758 : if (component == ACCESSOR_GETTER) {
4759 : set_getter(value);
4760 : } else {
4761 : set_setter(value);
4762 : }
4763 : }
4764 :
4765 :
4766 653464 : void AccessorPair::SetComponents(Object* getter, Object* setter) {
4767 : Isolate* isolate = GetIsolate();
4768 653464 : if (!getter->IsNull(isolate)) set_getter(getter);
4769 653464 : if (!setter->IsNull(isolate)) set_setter(setter);
4770 653464 : }
4771 :
4772 :
4773 : bool AccessorPair::Equals(AccessorPair* pair) {
4774 : return (this == pair) || pair->Equals(getter(), setter());
4775 : }
4776 :
4777 :
4778 : bool AccessorPair::Equals(Object* getter_value, Object* setter_value) {
4779 33190 : return (getter() == getter_value) && (setter() == setter_value);
4780 : }
4781 :
4782 :
4783 : bool AccessorPair::ContainsAccessor() {
4784 : return IsJSAccessor(getter()) || IsJSAccessor(setter());
4785 : }
4786 :
4787 :
4788 : bool AccessorPair::IsJSAccessor(Object* obj) {
4789 : return obj->IsCallable() || obj->IsUndefined(GetIsolate());
4790 : }
4791 :
4792 : template <typename Derived, typename Shape>
4793 82841 : void Dictionary<Derived, Shape>::ClearEntry(int entry) {
4794 82841 : Object* the_hole = this->GetHeap()->the_hole_value();
4795 82841 : PropertyDetails details = PropertyDetails::Empty();
4796 82841 : Derived::cast(this)->SetEntry(entry, the_hole, the_hole, details);
4797 82841 : }
4798 :
4799 : template <typename Derived, typename Shape>
4800 16523630 : void Dictionary<Derived, Shape>::SetEntry(int entry, Object* key, Object* value,
4801 : PropertyDetails details) {
4802 : DCHECK(Dictionary::kEntrySize == 2 || Dictionary::kEntrySize == 3);
4803 : DCHECK(!key->IsName() || details.dictionary_index() > 0);
4804 : int index = DerivedHashTable::EntryToIndex(entry);
4805 : DisallowHeapAllocation no_gc;
4806 16523630 : WriteBarrierMode mode = this->GetWriteBarrierMode(no_gc);
4807 16523630 : this->set(index + Derived::kEntryKeyIndex, key, mode);
4808 16523630 : this->set(index + Derived::kEntryValueIndex, value, mode);
4809 : if (Shape::kHasDetails) DetailsAtPut(entry, details);
4810 16523630 : }
4811 :
4812 : Object* GlobalDictionaryShape::Unwrap(Object* object) {
4813 : return PropertyCell::cast(object)->name();
4814 : }
4815 :
4816 : Name* NameDictionary::NameAt(int entry) { return Name::cast(KeyAt(entry)); }
4817 :
4818 : PropertyCell* GlobalDictionary::CellAt(int entry) {
4819 : DCHECK(KeyAt(entry)->IsPropertyCell());
4820 : return PropertyCell::cast(KeyAt(entry));
4821 : }
4822 :
4823 : bool GlobalDictionaryShape::IsLive(Isolate* isolate, Object* k) {
4824 162354139 : Heap* heap = isolate->heap();
4825 : DCHECK_NE(heap->the_hole_value(), k);
4826 : return k != heap->undefined_value();
4827 : }
4828 :
4829 30227866 : bool GlobalDictionaryShape::IsKey(Isolate* isolate, Object* k) {
4830 43716835 : return IsLive(isolate, k) &&
4831 30227866 : !PropertyCell::cast(k)->value()->IsTheHole(isolate);
4832 : }
4833 :
4834 : Name* GlobalDictionary::NameAt(int entry) { return CellAt(entry)->name(); }
4835 : Object* GlobalDictionary::ValueAt(int entry) { return CellAt(entry)->value(); }
4836 :
4837 7165556 : void GlobalDictionary::SetEntry(int entry, Object* key, Object* value,
4838 : PropertyDetails details) {
4839 : DCHECK_EQ(key, PropertyCell::cast(value)->name());
4840 7165556 : set(EntryToIndex(entry) + kEntryKeyIndex, value);
4841 : DetailsAtPut(entry, details);
4842 7165556 : }
4843 :
4844 : void GlobalDictionary::ValueAtPut(int entry, Object* value) {
4845 19912 : set(EntryToIndex(entry), value);
4846 : }
4847 :
4848 : bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) {
4849 : DCHECK(other->IsNumber());
4850 60623470 : return key == static_cast<uint32_t>(other->Number());
4851 : }
4852 :
4853 : uint32_t UnseededNumberDictionaryShape::Hash(Isolate* isolate, uint32_t key) {
4854 : return ComputeIntegerHash(key);
4855 : }
4856 :
4857 2752 : uint32_t UnseededNumberDictionaryShape::HashForObject(Isolate* isolate,
4858 : Object* other) {
4859 : DCHECK(other->IsNumber());
4860 5504 : return ComputeIntegerHash(static_cast<uint32_t>(other->Number()));
4861 : }
4862 :
4863 : Map* UnseededNumberDictionaryShape::GetMap(Isolate* isolate) {
4864 7882 : return isolate->heap()->unseeded_number_dictionary_map();
4865 : }
4866 :
4867 96408620 : uint32_t SeededNumberDictionaryShape::Hash(Isolate* isolate, uint32_t key) {
4868 96408620 : return ComputeIntegerHash(key, isolate->heap()->HashSeed());
4869 : }
4870 :
4871 2536813 : uint32_t SeededNumberDictionaryShape::HashForObject(Isolate* isolate,
4872 : Object* other) {
4873 : DCHECK(other->IsNumber());
4874 : return ComputeIntegerHash(static_cast<uint32_t>(other->Number()),
4875 5073626 : isolate->heap()->HashSeed());
4876 : }
4877 :
4878 :
4879 : Handle<Object> NumberDictionaryShape::AsHandle(Isolate* isolate, uint32_t key) {
4880 4428286 : return isolate->factory()->NewNumberFromUint(key);
4881 : }
4882 :
4883 :
4884 : bool NameDictionaryShape::IsMatch(Handle<Name> key, Object* other) {
4885 : DCHECK(other->IsTheHole(key->GetIsolate()) ||
4886 : Name::cast(other)->IsUniqueName());
4887 : DCHECK(key->IsUniqueName());
4888 : return *key == other;
4889 : }
4890 :
4891 77470845 : uint32_t NameDictionaryShape::Hash(Isolate* isolate, Handle<Name> key) {
4892 77470845 : return key->Hash();
4893 : }
4894 :
4895 : uint32_t NameDictionaryShape::HashForObject(Isolate* isolate, Object* other) {
4896 : return Name::cast(other)->Hash();
4897 : }
4898 :
4899 : bool GlobalDictionaryShape::IsMatch(Handle<Name> key, Object* other) {
4900 : DCHECK(PropertyCell::cast(other)->name()->IsUniqueName());
4901 : return *key == PropertyCell::cast(other)->name();
4902 : }
4903 :
4904 49586084 : uint32_t GlobalDictionaryShape::HashForObject(Isolate* isolate, Object* other) {
4905 49586084 : return PropertyCell::cast(other)->name()->Hash();
4906 : }
4907 :
4908 : Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate,
4909 : Handle<Name> key) {
4910 : DCHECK(key->IsUniqueName());
4911 : return key;
4912 : }
4913 :
4914 :
4915 : template <typename Dictionary>
4916 120200063 : PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) {
4917 : DCHECK_LE(0, entry); // Not found is -1, which is not caught by get().
4918 120200063 : return dict->CellAt(entry)->property_details();
4919 : }
4920 :
4921 :
4922 : template <typename Dictionary>
4923 7175131 : void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry,
4924 : PropertyDetails value) {
4925 : DCHECK_LE(0, entry); // Not found is -1, which is not caught by get().
4926 : PropertyCell* cell = dict->CellAt(entry);
4927 7175131 : if (cell->property_details().IsReadOnly() != value.IsReadOnly()) {
4928 8259 : cell->dependent_code()->DeoptimizeDependentCodeGroup(
4929 : cell->GetIsolate(), DependentCode::kPropertyCellChangedGroup);
4930 : }
4931 : cell->set_property_details(value);
4932 7175131 : }
4933 :
4934 : bool ObjectHashTableShape::IsMatch(Handle<Object> key, Object* other) {
4935 190529 : return key->SameValue(other);
4936 : }
4937 :
4938 : uint32_t ObjectHashTableShape::Hash(Isolate* isolate, Handle<Object> key) {
4939 2400 : return Smi::ToInt(key->GetHash());
4940 : }
4941 :
4942 : uint32_t ObjectHashTableShape::HashForObject(Isolate* isolate, Object* other) {
4943 527880 : return Smi::ToInt(other->GetHash());
4944 : }
4945 :
4946 :
4947 : Handle<Object> ObjectHashTableShape::AsHandle(Isolate* isolate,
4948 : Handle<Object> key) {
4949 : return key;
4950 : }
4951 :
4952 : Handle<ObjectHashTable> ObjectHashTable::Shrink(Handle<ObjectHashTable> table) {
4953 83 : return DerivedHashTable::Shrink(table);
4954 : }
4955 :
4956 : template <int entrysize>
4957 3126738 : bool WeakHashTableShape<entrysize>::IsMatch(Handle<Object> key, Object* other) {
4958 3126738 : if (other->IsWeakCell()) other = WeakCell::cast(other)->value();
4959 : return key->IsWeakCell() ? WeakCell::cast(*key)->value() == other
4960 6253476 : : *key == other;
4961 : }
4962 :
4963 : template <int entrysize>
4964 1094438 : uint32_t WeakHashTableShape<entrysize>::Hash(Isolate* isolate,
4965 : Handle<Object> key) {
4966 : intptr_t hash =
4967 : key->IsWeakCell()
4968 : ? reinterpret_cast<intptr_t>(WeakCell::cast(*key)->value())
4969 2188876 : : reinterpret_cast<intptr_t>(*key);
4970 1094438 : return (uint32_t)(hash & 0xFFFFFFFF);
4971 : }
4972 :
4973 : template <int entrysize>
4974 719364 : uint32_t WeakHashTableShape<entrysize>::HashForObject(Isolate* isolate,
4975 : Object* other) {
4976 719364 : if (other->IsWeakCell()) other = WeakCell::cast(other)->value();
4977 719364 : intptr_t hash = reinterpret_cast<intptr_t>(other);
4978 719364 : return (uint32_t)(hash & 0xFFFFFFFF);
4979 : }
4980 :
4981 :
4982 : template <int entrysize>
4983 : Handle<Object> WeakHashTableShape<entrysize>::AsHandle(Isolate* isolate,
4984 : Handle<Object> key) {
4985 : return key;
4986 : }
4987 :
4988 :
4989 2488303 : int Map::SlackForArraySize(int old_size, int size_limit) {
4990 2488303 : const int max_slack = size_limit - old_size;
4991 2488303 : CHECK_LE(0, max_slack);
4992 2488303 : if (old_size < 4) {
4993 : DCHECK_LE(1, max_slack);
4994 : return 1;
4995 : }
4996 2269384 : return Min(max_slack, old_size / 4);
4997 : }
4998 :
4999 : int TypeFeedbackInfo::ic_total_count() {
5000 : int current = Smi::ToInt(READ_FIELD(this, kStorage1Offset));
5001 : return ICTotalCountField::decode(current);
5002 : }
5003 :
5004 :
5005 : void TypeFeedbackInfo::set_ic_total_count(int count) {
5006 : int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset));
5007 : value = ICTotalCountField::update(value,
5008 : ICTotalCountField::decode(count));
5009 : WRITE_FIELD(this, kStorage1Offset, Smi::FromInt(value));
5010 : }
5011 :
5012 :
5013 : int TypeFeedbackInfo::ic_with_type_info_count() {
5014 : int current = Smi::ToInt(READ_FIELD(this, kStorage2Offset));
5015 : return ICsWithTypeInfoCountField::decode(current);
5016 : }
5017 :
5018 :
5019 : void TypeFeedbackInfo::change_ic_with_type_info_count(int delta) {
5020 : if (delta == 0) return;
5021 : int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset));
5022 : int new_count = ICsWithTypeInfoCountField::decode(value) + delta;
5023 : // We can get negative count here when the type-feedback info is
5024 : // shared between two code objects. The can only happen when
5025 : // the debugger made a shallow copy of code object (see Heap::CopyCode).
5026 : // Since we do not optimize when the debugger is active, we can skip
5027 : // this counter update.
5028 : if (new_count >= 0) {
5029 : new_count &= ICsWithTypeInfoCountField::kMask;
5030 : value = ICsWithTypeInfoCountField::update(value, new_count);
5031 : WRITE_FIELD(this, kStorage2Offset, Smi::FromInt(value));
5032 : }
5033 : }
5034 :
5035 :
5036 : int TypeFeedbackInfo::ic_generic_count() {
5037 : return Smi::ToInt(READ_FIELD(this, kStorage3Offset));
5038 : }
5039 :
5040 :
5041 : void TypeFeedbackInfo::change_ic_generic_count(int delta) {
5042 : if (delta == 0) return;
5043 : int new_count = ic_generic_count() + delta;
5044 : if (new_count >= 0) {
5045 : new_count &= ~Smi::kMinValue;
5046 : WRITE_FIELD(this, kStorage3Offset, Smi::FromInt(new_count));
5047 : }
5048 : }
5049 :
5050 :
5051 0 : void TypeFeedbackInfo::initialize_storage() {
5052 0 : WRITE_FIELD(this, kStorage1Offset, Smi::kZero);
5053 0 : WRITE_FIELD(this, kStorage2Offset, Smi::kZero);
5054 0 : WRITE_FIELD(this, kStorage3Offset, Smi::kZero);
5055 0 : }
5056 :
5057 :
5058 : void TypeFeedbackInfo::change_own_type_change_checksum() {
5059 : int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset));
5060 : int checksum = OwnTypeChangeChecksum::decode(value);
5061 : checksum = (checksum + 1) % (1 << kTypeChangeChecksumBits);
5062 : value = OwnTypeChangeChecksum::update(value, checksum);
5063 : // Ensure packed bit field is in Smi range.
5064 : if (value > Smi::kMaxValue) value |= Smi::kMinValue;
5065 : if (value < Smi::kMinValue) value &= ~Smi::kMinValue;
5066 : WRITE_FIELD(this, kStorage1Offset, Smi::FromInt(value));
5067 : }
5068 :
5069 :
5070 : void TypeFeedbackInfo::set_inlined_type_change_checksum(int checksum) {
5071 : int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset));
5072 : int mask = (1 << kTypeChangeChecksumBits) - 1;
5073 : value = InlinedTypeChangeChecksum::update(value, checksum & mask);
5074 : // Ensure packed bit field is in Smi range.
5075 : if (value > Smi::kMaxValue) value |= Smi::kMinValue;
5076 : if (value < Smi::kMinValue) value &= ~Smi::kMinValue;
5077 : WRITE_FIELD(this, kStorage2Offset, Smi::FromInt(value));
5078 : }
5079 :
5080 :
5081 : int TypeFeedbackInfo::own_type_change_checksum() {
5082 : int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset));
5083 : return OwnTypeChangeChecksum::decode(value);
5084 : }
5085 :
5086 :
5087 : bool TypeFeedbackInfo::matches_inlined_type_change_checksum(int checksum) {
5088 : int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset));
5089 : int mask = (1 << kTypeChangeChecksumBits) - 1;
5090 : return InlinedTypeChangeChecksum::decode(value) == (checksum & mask);
5091 : }
5092 :
5093 37581256 : Relocatable::Relocatable(Isolate* isolate) {
5094 18790628 : isolate_ = isolate;
5095 18790628 : prev_ = isolate->relocatable_top();
5096 : isolate->set_relocatable_top(this);
5097 : }
5098 :
5099 :
5100 18790628 : Relocatable::~Relocatable() {
5101 : DCHECK_EQ(isolate_->relocatable_top(), this);
5102 18790628 : isolate_->set_relocatable_top(prev_);
5103 0 : }
5104 :
5105 :
5106 : template<class Derived, class TableType>
5107 0 : Object* OrderedHashTableIterator<Derived, TableType>::CurrentKey() {
5108 : TableType* table(TableType::cast(this->table()));
5109 : int index = Smi::ToInt(this->index());
5110 0 : Object* key = table->KeyAt(index);
5111 : DCHECK(!key->IsTheHole(table->GetIsolate()));
5112 0 : return key;
5113 : }
5114 :
5115 :
5116 : Object* JSMapIterator::CurrentValue() {
5117 : OrderedHashMap* table(OrderedHashMap::cast(this->table()));
5118 : int index = Smi::ToInt(this->index());
5119 : Object* value = table->ValueAt(index);
5120 : DCHECK(!value->IsTheHole(table->GetIsolate()));
5121 : return value;
5122 : }
5123 :
5124 : // Predictably converts HeapObject* or Address to uint32 by calculating
5125 : // offset of the address in respective MemoryChunk.
5126 : static inline uint32_t ObjectAddressForHashing(void* object) {
5127 65844831 : uint32_t value = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object));
5128 65844831 : return value & MemoryChunk::kAlignmentMask;
5129 : }
5130 :
5131 252 : static inline Handle<Object> MakeEntryPair(Isolate* isolate, uint32_t index,
5132 : Handle<Object> value) {
5133 252 : Handle<Object> key = isolate->factory()->Uint32ToString(index);
5134 : Handle<FixedArray> entry_storage =
5135 252 : isolate->factory()->NewUninitializedFixedArray(2);
5136 : {
5137 252 : entry_storage->set(0, *key, SKIP_WRITE_BARRIER);
5138 252 : entry_storage->set(1, *value, SKIP_WRITE_BARRIER);
5139 : }
5140 : return isolate->factory()->NewJSArrayWithElements(entry_storage,
5141 252 : PACKED_ELEMENTS, 2);
5142 : }
5143 :
5144 360 : static inline Handle<Object> MakeEntryPair(Isolate* isolate, Handle<Object> key,
5145 : Handle<Object> value) {
5146 : Handle<FixedArray> entry_storage =
5147 360 : isolate->factory()->NewUninitializedFixedArray(2);
5148 : {
5149 360 : entry_storage->set(0, *key, SKIP_WRITE_BARRIER);
5150 360 : entry_storage->set(1, *value, SKIP_WRITE_BARRIER);
5151 : }
5152 : return isolate->factory()->NewJSArrayWithElements(entry_storage,
5153 360 : PACKED_ELEMENTS, 2);
5154 : }
5155 :
5156 1507 : ACCESSORS(JSIteratorResult, value, Object, kValueOffset)
5157 90 : ACCESSORS(JSIteratorResult, done, Object, kDoneOffset)
5158 :
5159 1050 : ACCESSORS(JSAsyncFromSyncIterator, sync_iterator, JSReceiver,
5160 : kSyncIteratorOffset)
5161 :
5162 40 : ACCESSORS(JSStringIterator, string, String, kStringOffset)
5163 16 : SMI_ACCESSORS(JSStringIterator, index, kNextIndexOffset)
5164 :
5165 1860230 : bool ScopeInfo::IsAsmModule() { return AsmModuleField::decode(Flags()); }
5166 :
5167 : bool ScopeInfo::HasSimpleParameters() {
5168 62834 : return HasSimpleParametersField::decode(Flags());
5169 : }
5170 :
5171 : #define FIELD_ACCESSORS(name) \
5172 : void ScopeInfo::Set##name(int value) { set(k##name, Smi::FromInt(value)); } \
5173 : int ScopeInfo::name() { \
5174 : if (length() > 0) { \
5175 : return Smi::ToInt(get(k##name)); \
5176 : } else { \
5177 : return 0; \
5178 : } \
5179 : }
5180 238961258 : FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS)
5181 : #undef FIELD_ACCESSORS
5182 :
5183 : } // namespace internal
5184 : } // namespace v8
5185 :
5186 : #include "src/objects/object-macros-undef.h"
5187 :
5188 : #endif // V8_OBJECTS_INL_H_
|