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.
10 #include "src/allocation.h"
11 #include "src/assert-scope.h"
12 #include "src/bailout-reason.h"
13 #include "src/base/bits.h"
14 #include "src/base/smart-pointers.h"
15 #include "src/builtins.h"
16 #include "src/checks.h"
17 #include "src/elements-kind.h"
18 #include "src/field-index.h"
19 #include "src/flags.h"
21 #include "src/property-details.h"
22 #include "src/unicode.h"
23 #include "src/unicode-decoder.h"
26 #if V8_TARGET_ARCH_ARM
27 #include "src/arm/constants-arm.h" // NOLINT
28 #elif V8_TARGET_ARCH_ARM64
29 #include "src/arm64/constants-arm64.h" // NOLINT
30 #elif V8_TARGET_ARCH_MIPS
31 #include "src/mips/constants-mips.h" // NOLINT
32 #elif V8_TARGET_ARCH_MIPS64
33 #include "src/mips64/constants-mips64.h" // NOLINT
34 #elif V8_TARGET_ARCH_PPC
35 #include "src/ppc/constants-ppc.h" // NOLINT
40 // Most object types in the V8 JavaScript are described in this file.
42 // Inheritance hierarchy:
44 // - Smi (immediate small integer)
45 // - HeapObject (superclass for everything allocated in the heap)
46 // - JSReceiver (suitable for property access)
50 // - JSArrayBufferView
63 // - JSGeneratorObject
82 // - CompilationCacheTable
83 // - CodeCacheHashTable
89 // - TypeFeedbackVector
92 // - ScriptContextTable
103 // - ExternalOneByteString
104 // - ExternalTwoByteString
105 // - InternalizedString
106 // - SeqInternalizedString
107 // - SeqOneByteInternalizedString
108 // - SeqTwoByteInternalizedString
109 // - ConsInternalizedString
110 // - ExternalInternalizedString
111 // - ExternalOneByteInternalizedString
112 // - ExternalTwoByteInternalizedString
132 // - SharedFunctionInfo
136 // - ExecutableAccessorInfo
142 // - FunctionTemplateInfo
143 // - ObjectTemplateInfo
152 // Formats of Object*:
153 // Smi: [31 bit signed int] 0
154 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
159 enum KeyedAccessStoreMode {
161 STORE_TRANSITION_TO_OBJECT,
162 STORE_TRANSITION_TO_DOUBLE,
163 STORE_AND_GROW_NO_TRANSITION,
164 STORE_AND_GROW_TRANSITION_TO_OBJECT,
165 STORE_AND_GROW_TRANSITION_TO_DOUBLE,
166 STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS,
167 STORE_NO_TRANSITION_HANDLE_COW
171 // Valid hints for the abstract operation ToPrimitive,
172 // implemented according to ES6, section 7.1.1.
173 enum class ToPrimitiveHint { kDefault, kNumber, kString };
176 enum TypeofMode { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
185 enum ExternalArrayType {
186 kExternalInt8Array = 1,
189 kExternalUint16Array,
191 kExternalUint32Array,
192 kExternalFloat32Array,
193 kExternalFloat64Array,
194 kExternalUint8ClampedArray,
198 static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) {
199 return store_mode == STORE_TRANSITION_TO_OBJECT ||
200 store_mode == STORE_TRANSITION_TO_DOUBLE ||
201 store_mode == STORE_AND_GROW_TRANSITION_TO_OBJECT ||
202 store_mode == STORE_AND_GROW_TRANSITION_TO_DOUBLE;
206 static inline KeyedAccessStoreMode GetNonTransitioningStoreMode(
207 KeyedAccessStoreMode store_mode) {
208 if (store_mode >= STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) {
211 if (store_mode >= STORE_AND_GROW_NO_TRANSITION) {
212 return STORE_AND_GROW_NO_TRANSITION;
214 return STANDARD_STORE;
218 static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) {
219 return store_mode >= STORE_AND_GROW_NO_TRANSITION &&
220 store_mode <= STORE_AND_GROW_TRANSITION_TO_DOUBLE;
224 enum IcCheckType { ELEMENT, PROPERTY };
227 // SKIP_WRITE_BARRIER skips the write barrier.
228 // UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and
229 // only performs the generational part.
230 // UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational.
231 enum WriteBarrierMode {
233 UPDATE_WEAK_WRITE_BARRIER,
238 // Indicates whether a value can be loaded as a constant.
239 enum StoreMode { ALLOW_IN_DESCRIPTOR, FORCE_FIELD };
242 // PropertyNormalizationMode is used to specify whether to keep
243 // inobject properties when normalizing properties of a JSObject.
244 enum PropertyNormalizationMode {
245 CLEAR_INOBJECT_PROPERTIES,
246 KEEP_INOBJECT_PROPERTIES
250 // Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE
251 // will give the fastest result by tailoring the map to the prototype, but that
252 // will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used
253 // (at least for now) when dynamically modifying the prototype chain of an
254 // object using __proto__ or Object.setPrototypeOf.
255 enum PrototypeOptimizationMode { REGULAR_PROTOTYPE, FAST_PROTOTYPE };
258 // Indicates whether transitions can be added to a source map or not.
259 enum TransitionFlag {
265 // Indicates whether the transition is simple: the target map of the transition
266 // either extends the current map with a new property, or it modifies the
267 // property that was added last to the current map.
268 enum SimpleTransitionFlag {
269 SIMPLE_PROPERTY_TRANSITION,
275 // Indicates whether we are only interested in the descriptors of a particular
276 // map, or in all descriptors in the descriptor array.
277 enum DescriptorFlag {
282 // The GC maintains a bit of information, the MarkingParity, which toggles
283 // from odd to even and back every time marking is completed. Incremental
284 // marking can visit an object twice during a marking phase, so algorithms that
285 // that piggy-back on marking can use the parity to ensure that they only
286 // perform an operation on an object once per marking phase: they record the
287 // MarkingParity when they visit an object, and only re-visit the object when it
288 // is marked again and the MarkingParity changes.
295 // ICs store extra state in a Code object. The default extra state is
297 typedef int ExtraICState;
298 static const ExtraICState kNoExtraICState = 0;
300 // Instance size sentinel for objects of variable size.
301 const int kVariableSizeSentinel = 0;
303 // We may store the unsigned bit field as signed Smi value and do not
305 const int kStubMajorKeyBits = 7;
306 const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
308 // All Maps have a field instance_type containing a InstanceType.
309 // It describes the type of the instances.
311 // As an example, a JavaScript object is a heap object and its map
312 // instance_type is JS_OBJECT_TYPE.
314 // The names of the string instance types are intended to systematically
315 // mirror their encoding in the instance_type field of the map. The default
316 // encoding is considered TWO_BYTE. It is not mentioned in the name. ONE_BYTE
317 // encoding is mentioned explicitly in the name. Likewise, the default
318 // representation is considered sequential. It is not mentioned in the
319 // name. The other representations (e.g. CONS, EXTERNAL) are explicitly
320 // mentioned. Finally, the string is either a STRING_TYPE (if it is a normal
321 // string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string).
323 // NOTE: The following things are some that depend on the string types having
324 // instance_types that are less than those of all other types:
325 // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
328 // NOTE: Everything following JS_VALUE_TYPE is considered a
329 // JSObject for GC purposes. The first four entries here have typeof
330 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
331 #define INSTANCE_TYPE_LIST(V) \
333 V(ONE_BYTE_STRING_TYPE) \
334 V(CONS_STRING_TYPE) \
335 V(CONS_ONE_BYTE_STRING_TYPE) \
336 V(SLICED_STRING_TYPE) \
337 V(SLICED_ONE_BYTE_STRING_TYPE) \
338 V(EXTERNAL_STRING_TYPE) \
339 V(EXTERNAL_ONE_BYTE_STRING_TYPE) \
340 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
341 V(SHORT_EXTERNAL_STRING_TYPE) \
342 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \
343 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
345 V(INTERNALIZED_STRING_TYPE) \
346 V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \
347 V(EXTERNAL_INTERNALIZED_STRING_TYPE) \
348 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
349 V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
350 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \
351 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
352 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
355 V(SIMD128_VALUE_TYPE) \
361 V(PROPERTY_CELL_TYPE) \
363 V(HEAP_NUMBER_TYPE) \
364 V(MUTABLE_HEAP_NUMBER_TYPE) \
367 V(BYTECODE_ARRAY_TYPE) \
370 V(FIXED_INT8_ARRAY_TYPE) \
371 V(FIXED_UINT8_ARRAY_TYPE) \
372 V(FIXED_INT16_ARRAY_TYPE) \
373 V(FIXED_UINT16_ARRAY_TYPE) \
374 V(FIXED_INT32_ARRAY_TYPE) \
375 V(FIXED_UINT32_ARRAY_TYPE) \
376 V(FIXED_FLOAT32_ARRAY_TYPE) \
377 V(FIXED_FLOAT64_ARRAY_TYPE) \
378 V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \
382 V(DECLARED_ACCESSOR_DESCRIPTOR_TYPE) \
383 V(DECLARED_ACCESSOR_INFO_TYPE) \
384 V(EXECUTABLE_ACCESSOR_INFO_TYPE) \
385 V(ACCESSOR_PAIR_TYPE) \
386 V(ACCESS_CHECK_INFO_TYPE) \
387 V(INTERCEPTOR_INFO_TYPE) \
388 V(CALL_HANDLER_INFO_TYPE) \
389 V(FUNCTION_TEMPLATE_INFO_TYPE) \
390 V(OBJECT_TEMPLATE_INFO_TYPE) \
391 V(SIGNATURE_INFO_TYPE) \
392 V(TYPE_SWITCH_INFO_TYPE) \
393 V(ALLOCATION_MEMENTO_TYPE) \
394 V(ALLOCATION_SITE_TYPE) \
397 V(POLYMORPHIC_CODE_CACHE_TYPE) \
398 V(TYPE_FEEDBACK_INFO_TYPE) \
399 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
401 V(PROTOTYPE_INFO_TYPE) \
402 V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \
404 V(FIXED_ARRAY_TYPE) \
405 V(FIXED_DOUBLE_ARRAY_TYPE) \
406 V(SHARED_FUNCTION_INFO_TYPE) \
409 V(JS_MESSAGE_OBJECT_TYPE) \
414 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
415 V(JS_GENERATOR_OBJECT_TYPE) \
417 V(JS_GLOBAL_OBJECT_TYPE) \
418 V(JS_BUILTINS_OBJECT_TYPE) \
419 V(JS_GLOBAL_PROXY_TYPE) \
421 V(JS_ARRAY_BUFFER_TYPE) \
422 V(JS_TYPED_ARRAY_TYPE) \
423 V(JS_DATA_VIEW_TYPE) \
427 V(JS_SET_ITERATOR_TYPE) \
428 V(JS_MAP_ITERATOR_TYPE) \
429 V(JS_WEAK_MAP_TYPE) \
430 V(JS_WEAK_SET_TYPE) \
433 V(JS_FUNCTION_TYPE) \
434 V(JS_FUNCTION_PROXY_TYPE) \
436 V(BREAK_POINT_INFO_TYPE)
439 // Since string types are not consecutive, this macro is used to
440 // iterate over them.
441 #define STRING_TYPE_LIST(V) \
442 V(STRING_TYPE, kVariableSizeSentinel, string, String) \
443 V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \
445 V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \
446 V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \
448 V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \
449 V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \
450 SlicedOneByteString) \
451 V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \
453 V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \
454 external_one_byte_string, ExternalOneByteString) \
455 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \
456 external_string_with_one_byte_data, ExternalStringWithOneByteData) \
457 V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \
458 short_external_string, ShortExternalString) \
459 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \
460 short_external_one_byte_string, ShortExternalOneByteString) \
461 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \
462 ExternalTwoByteString::kShortSize, \
463 short_external_string_with_one_byte_data, \
464 ShortExternalStringWithOneByteData) \
466 V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \
467 InternalizedString) \
468 V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \
469 one_byte_internalized_string, OneByteInternalizedString) \
470 V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \
471 external_internalized_string, ExternalInternalizedString) \
472 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \
473 external_one_byte_internalized_string, ExternalOneByteInternalizedString) \
474 V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
475 ExternalTwoByteString::kSize, \
476 external_internalized_string_with_one_byte_data, \
477 ExternalInternalizedStringWithOneByteData) \
478 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \
479 ExternalTwoByteString::kShortSize, short_external_internalized_string, \
480 ShortExternalInternalizedString) \
481 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \
482 ExternalOneByteString::kShortSize, \
483 short_external_one_byte_internalized_string, \
484 ShortExternalOneByteInternalizedString) \
485 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
486 ExternalTwoByteString::kShortSize, \
487 short_external_internalized_string_with_one_byte_data, \
488 ShortExternalInternalizedStringWithOneByteData)
490 // A struct is a simple object a set of object-valued fields. Including an
491 // object type in this causes the compiler to generate most of the boilerplate
492 // code for the class including allocation and garbage collection routines,
493 // casts and predicates. All you need to define is the class, methods and
494 // object verification routines. Easy, no?
496 // Note that for subtle reasons related to the ordering or numerical values of
497 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
499 #define STRUCT_LIST(V) \
501 V(EXECUTABLE_ACCESSOR_INFO, ExecutableAccessorInfo, \
502 executable_accessor_info) \
503 V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
504 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
505 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
506 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
507 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
508 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
509 V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
510 V(SCRIPT, Script, script) \
511 V(ALLOCATION_SITE, AllocationSite, allocation_site) \
512 V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \
513 V(CODE_CACHE, CodeCache, code_cache) \
514 V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
515 V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
516 V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \
517 V(DEBUG_INFO, DebugInfo, debug_info) \
518 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \
519 V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \
520 V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \
521 SloppyBlockWithEvalContextExtension, \
522 sloppy_block_with_eval_context_extension)
524 // We use the full 8 bits of the instance_type field to encode heap object
525 // instance types. The high-order bit (bit 7) is set if the object is not a
526 // string, and cleared if it is a string.
527 const uint32_t kIsNotStringMask = 0x80;
528 const uint32_t kStringTag = 0x0;
529 const uint32_t kNotStringTag = 0x80;
531 // Bit 6 indicates that the object is an internalized string (if set) or not.
532 // Bit 7 has to be clear as well.
533 const uint32_t kIsNotInternalizedMask = 0x40;
534 const uint32_t kNotInternalizedTag = 0x40;
535 const uint32_t kInternalizedTag = 0x0;
537 // If bit 7 is clear then bit 2 indicates whether the string consists of
538 // two-byte characters or one-byte characters.
539 const uint32_t kStringEncodingMask = 0x4;
540 const uint32_t kTwoByteStringTag = 0x0;
541 const uint32_t kOneByteStringTag = 0x4;
543 // If bit 7 is clear, the low-order 2 bits indicate the representation
545 const uint32_t kStringRepresentationMask = 0x03;
546 enum StringRepresentationTag {
548 kConsStringTag = 0x1,
549 kExternalStringTag = 0x2,
550 kSlicedStringTag = 0x3
552 const uint32_t kIsIndirectStringMask = 0x1;
553 const uint32_t kIsIndirectStringTag = 0x1;
554 STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT
555 STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT
556 STATIC_ASSERT((kConsStringTag &
557 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
558 STATIC_ASSERT((kSlicedStringTag &
559 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
561 // Use this mask to distinguish between cons and slice only after making
562 // sure that the string is one of the two (an indirect string).
563 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
564 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask));
566 // If bit 7 is clear, then bit 3 indicates whether this two-byte
567 // string actually contains one byte data.
568 const uint32_t kOneByteDataHintMask = 0x08;
569 const uint32_t kOneByteDataHintTag = 0x08;
571 // If bit 7 is clear and string representation indicates an external string,
572 // then bit 4 indicates whether the data pointer is cached.
573 const uint32_t kShortExternalStringMask = 0x10;
574 const uint32_t kShortExternalStringTag = 0x10;
577 // A ConsString with an empty string as the right side is a candidate
578 // for being shortcut by the garbage collector. We don't allocate any
579 // non-flat internalized strings, so we do not shortcut them thereby
580 // avoiding turning internalized strings into strings. The bit-masks
581 // below contain the internalized bit as additional safety.
582 // See heap.cc, mark-compact.cc and objects-visiting.cc.
583 const uint32_t kShortcutTypeMask =
585 kIsNotInternalizedMask |
586 kStringRepresentationMask;
587 const uint32_t kShortcutTypeTag = kConsStringTag | kNotInternalizedTag;
589 static inline bool IsShortcutCandidate(int type) {
590 return ((type & kShortcutTypeMask) == kShortcutTypeTag);
596 INTERNALIZED_STRING_TYPE = kTwoByteStringTag | kSeqStringTag |
597 kInternalizedTag, // FIRST_PRIMITIVE_TYPE
598 ONE_BYTE_INTERNALIZED_STRING_TYPE =
599 kOneByteStringTag | kSeqStringTag | kInternalizedTag,
600 EXTERNAL_INTERNALIZED_STRING_TYPE =
601 kTwoByteStringTag | kExternalStringTag | kInternalizedTag,
602 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE =
603 kOneByteStringTag | kExternalStringTag | kInternalizedTag,
604 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE =
605 EXTERNAL_INTERNALIZED_STRING_TYPE | kOneByteDataHintTag |
607 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = EXTERNAL_INTERNALIZED_STRING_TYPE |
608 kShortExternalStringTag |
610 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE =
611 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kShortExternalStringTag |
613 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE =
614 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
615 kShortExternalStringTag | kInternalizedTag,
616 STRING_TYPE = INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
617 ONE_BYTE_STRING_TYPE =
618 ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
619 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag | kNotInternalizedTag,
620 CONS_ONE_BYTE_STRING_TYPE =
621 kOneByteStringTag | kConsStringTag | kNotInternalizedTag,
623 kTwoByteStringTag | kSlicedStringTag | kNotInternalizedTag,
624 SLICED_ONE_BYTE_STRING_TYPE =
625 kOneByteStringTag | kSlicedStringTag | kNotInternalizedTag,
626 EXTERNAL_STRING_TYPE =
627 EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
628 EXTERNAL_ONE_BYTE_STRING_TYPE =
629 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
630 EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
631 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
633 SHORT_EXTERNAL_STRING_TYPE =
634 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
635 SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE =
636 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
637 SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
638 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
642 SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE
644 // Other primitives (cannot contain non-map-word pointers to heap objects).
647 ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE
649 // Objects allocated in their own spaces (never in new space).
653 // "Data", objects that cannot contain non-map-word pointers to heap
655 MUTABLE_HEAP_NUMBER_TYPE,
660 FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE
661 FIXED_UINT8_ARRAY_TYPE,
662 FIXED_INT16_ARRAY_TYPE,
663 FIXED_UINT16_ARRAY_TYPE,
664 FIXED_INT32_ARRAY_TYPE,
665 FIXED_UINT32_ARRAY_TYPE,
666 FIXED_FLOAT32_ARRAY_TYPE,
667 FIXED_FLOAT64_ARRAY_TYPE,
668 FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE
669 FIXED_DOUBLE_ARRAY_TYPE,
670 FILLER_TYPE, // LAST_DATA_TYPE
673 DECLARED_ACCESSOR_DESCRIPTOR_TYPE,
674 DECLARED_ACCESSOR_INFO_TYPE,
675 EXECUTABLE_ACCESSOR_INFO_TYPE,
677 ACCESS_CHECK_INFO_TYPE,
678 INTERCEPTOR_INFO_TYPE,
679 CALL_HANDLER_INFO_TYPE,
680 FUNCTION_TEMPLATE_INFO_TYPE,
681 OBJECT_TEMPLATE_INFO_TYPE,
683 TYPE_SWITCH_INFO_TYPE,
684 ALLOCATION_SITE_TYPE,
685 ALLOCATION_MEMENTO_TYPE,
688 POLYMORPHIC_CODE_CACHE_TYPE,
689 TYPE_FEEDBACK_INFO_TYPE,
690 ALIASED_ARGUMENTS_ENTRY_TYPE,
693 BREAK_POINT_INFO_TYPE,
695 SHARED_FUNCTION_INFO_TYPE,
700 SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE,
702 // All the following types are subtypes of JSReceiver, which corresponds to
703 // objects in the JS sense. The first and the last type in this range are
704 // the two forms of function. This organization enables using the same
705 // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
706 // NONCALLABLE_JS_OBJECT range.
707 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
708 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
709 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
710 JS_MESSAGE_OBJECT_TYPE,
713 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
714 JS_GENERATOR_OBJECT_TYPE,
716 JS_GLOBAL_OBJECT_TYPE,
717 JS_BUILTINS_OBJECT_TYPE,
718 JS_GLOBAL_PROXY_TYPE,
720 JS_ARRAY_BUFFER_TYPE,
725 JS_SET_ITERATOR_TYPE,
726 JS_MAP_ITERATOR_TYPE,
730 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
734 LAST_TYPE = JS_FUNCTION_TYPE,
735 FIRST_NAME_TYPE = FIRST_TYPE,
736 LAST_NAME_TYPE = SYMBOL_TYPE,
737 FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE,
738 LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE,
739 FIRST_NONSTRING_TYPE = SYMBOL_TYPE,
740 FIRST_PRIMITIVE_TYPE = FIRST_NAME_TYPE,
741 LAST_PRIMITIVE_TYPE = ODDBALL_TYPE,
742 // Boundaries for testing for a fixed typed array.
743 FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE,
744 LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE,
745 // Boundary for promotion to old space.
746 LAST_DATA_TYPE = FILLER_TYPE,
747 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
748 // Note that there is no range for JSObject or JSProxy, since their subtypes
749 // are not continuous in this enum! The enum ranges instead reflect the
750 // external class names, where proxies are treated as either ordinary objects,
752 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE,
753 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
754 // Boundaries for testing the types represented as JSObject
755 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
756 LAST_JS_OBJECT_TYPE = LAST_TYPE,
757 // Boundaries for testing the types represented as JSProxy
758 FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE,
759 LAST_JS_PROXY_TYPE = JS_PROXY_TYPE,
760 // Boundaries for testing whether the type is a JavaScript object.
761 FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE,
762 LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE,
763 // Boundaries for testing the types for which typeof is "object".
764 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE,
765 LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE,
766 // Note that the types for which typeof is "function" are not continuous.
767 // Define this so that we can put assertions on discrete checks.
768 NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2
771 STATIC_ASSERT(JS_OBJECT_TYPE == Internals::kJSObjectType);
772 STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
773 STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType);
774 STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType);
777 #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \
778 V(FAST_ELEMENTS_SUB_TYPE) \
779 V(DICTIONARY_ELEMENTS_SUB_TYPE) \
780 V(FAST_PROPERTIES_SUB_TYPE) \
781 V(DICTIONARY_PROPERTIES_SUB_TYPE) \
782 V(MAP_CODE_CACHE_SUB_TYPE) \
783 V(SCOPE_INFO_SUB_TYPE) \
784 V(STRING_TABLE_SUB_TYPE) \
785 V(DESCRIPTOR_ARRAY_SUB_TYPE) \
786 V(TRANSITION_ARRAY_SUB_TYPE)
788 enum FixedArraySubInstanceType {
789 #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name,
790 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE)
791 #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE
792 LAST_FIXED_ARRAY_SUB_TYPE = TRANSITION_ARRAY_SUB_TYPE
805 #define DECL_BOOLEAN_ACCESSORS(name) \
806 inline bool name() const; \
807 inline void set_##name(bool value); \
810 #define DECL_ACCESSORS(name, type) \
811 inline type* name() const; \
812 inline void set_##name(type* value, \
813 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
816 #define DECLARE_CAST(type) \
817 INLINE(static type* cast(Object* object)); \
818 INLINE(static const type* cast(const Object* object));
822 class AllocationSite;
823 class AllocationSiteCreationContext;
824 class AllocationSiteUsageContext;
827 class ElementsAccessor;
828 class FixedArrayBase;
829 class FunctionLiteral;
831 class JSBuiltinsObject;
832 class LayoutDescriptor;
833 class LookupIterator;
834 class ObjectHashTable;
837 class SafepointEntry;
838 class SharedFunctionInfo;
840 class TypeFeedbackInfo;
841 class TypeFeedbackVector;
844 // We cannot just say "class HeapType;" if it is created from a template... =8-?
845 template<class> class TypeImpl;
846 struct HeapTypeConfig;
847 typedef TypeImpl<HeapTypeConfig> HeapType;
850 // A template-ized version of the IsXXX functions.
851 template <class C> inline bool Is(Object* obj);
854 #define DECLARE_VERIFIER(Name) void Name##Verify();
856 #define DECLARE_VERIFIER(Name)
860 #define DECLARE_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT
862 #define DECLARE_PRINTER(Name)
866 #define OBJECT_TYPE_LIST(V) \
871 #define HEAP_OBJECT_TYPE_LIST(V) \
873 V(MutableHeapNumber) \
892 V(ExternalTwoByteString) \
893 V(ExternalOneByteString) \
894 V(SeqTwoByteString) \
895 V(SeqOneByteString) \
896 V(InternalizedString) \
899 V(FixedTypedArrayBase) \
902 V(FixedUint16Array) \
904 V(FixedUint32Array) \
906 V(FixedFloat32Array) \
907 V(FixedFloat64Array) \
908 V(FixedUint8ClampedArray) \
914 V(JSContextExtensionObject) \
915 V(JSGeneratorObject) \
917 V(LayoutDescriptor) \
921 V(TypeFeedbackVector) \
922 V(DeoptimizationInputData) \
923 V(DeoptimizationOutputData) \
927 V(FixedDoubleArray) \
931 V(ScriptContextTable) \
937 V(SharedFunctionInfo) \
946 V(JSArrayBufferView) \
955 V(JSWeakCollection) \
962 V(NormalizedMapCache) \
963 V(CompilationCacheTable) \
964 V(CodeCacheHashTable) \
965 V(PolymorphicCodeCacheHashTable) \
970 V(JSBuiltinsObject) \
972 V(UndetectableObject) \
973 V(AccessCheckNeeded) \
981 // Object is the abstract superclass for all classes in the
983 // Object does not use any virtual functions to avoid the
984 // allocation of the C++ vtable.
985 // Since both Smi and HeapObject are subclasses of Object no
986 // data members can be present in Object.
990 bool IsObject() const { return true; }
992 #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const);
993 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
994 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
995 #undef IS_TYPE_FUNCTION_DECL
997 // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
998 // a keyed store is of the form a[expression] = foo.
999 enum StoreFromKeyed {
1000 MAY_BE_STORE_FROM_KEYED,
1001 CERTAINLY_NOT_STORE_FROM_KEYED
1004 INLINE(bool IsFixedArrayBase() const);
1005 INLINE(bool IsExternal() const);
1006 INLINE(bool IsAccessorInfo() const);
1008 INLINE(bool IsStruct() const);
1009 #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \
1010 INLINE(bool Is##Name() const);
1011 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
1012 #undef DECLARE_STRUCT_PREDICATE
1014 INLINE(bool IsSpecObject()) const;
1015 INLINE(bool IsSpecFunction()) const;
1016 INLINE(bool IsTemplateInfo()) const;
1017 INLINE(bool IsNameDictionary() const);
1018 INLINE(bool IsGlobalDictionary() const);
1019 INLINE(bool IsSeededNumberDictionary() const);
1020 INLINE(bool IsUnseededNumberDictionary() const);
1021 INLINE(bool IsOrderedHashSet() const);
1022 INLINE(bool IsOrderedHashMap() const);
1023 bool IsCallable() const;
1024 static bool IsPromise(Handle<Object> object);
1027 INLINE(bool IsUndefined() const);
1028 INLINE(bool IsNull() const);
1029 INLINE(bool IsTheHole() const);
1030 INLINE(bool IsException() const);
1031 INLINE(bool IsUninitialized() const);
1032 INLINE(bool IsTrue() const);
1033 INLINE(bool IsFalse() const);
1034 INLINE(bool IsArgumentsMarker() const);
1036 // Filler objects (fillers and free space objects).
1037 INLINE(bool IsFiller() const);
1039 // Extract the number.
1040 inline double Number();
1041 INLINE(bool IsNaN() const);
1042 INLINE(bool IsMinusZero() const);
1043 bool ToInt32(int32_t* value);
1044 bool ToUint32(uint32_t* value);
1046 inline Representation OptimalRepresentation();
1048 inline ElementsKind OptimalElementsKind();
1050 inline bool FitsRepresentation(Representation representation);
1052 // Checks whether two valid primitive encodings of a property name resolve to
1053 // the same logical property. E.g., the smi 1, the string "1" and the double
1054 // 1 all refer to the same property, so this helper will return true.
1055 inline bool KeyEquals(Object* other);
1057 Handle<HeapType> OptimalType(Isolate* isolate, Representation representation);
1059 inline static Handle<Object> NewStorageFor(Isolate* isolate,
1060 Handle<Object> object,
1061 Representation representation);
1063 inline static Handle<Object> WrapForRead(Isolate* isolate,
1064 Handle<Object> object,
1065 Representation representation);
1067 // Returns true if the object is of the correct type to be used as a
1068 // implementation of a JSObject's elements.
1069 inline bool HasValidElements();
1071 inline bool HasSpecificClassOf(String* name);
1073 bool BooleanValue(); // ECMA-262 9.2.
1075 // ES6 section 7.2.13 Strict Equality Comparison
1076 bool StrictEquals(Object* that);
1078 // Convert to a JSObject if needed.
1079 // native_context is used when creating wrapper object.
1080 static inline MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
1081 Handle<Object> object);
1082 MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject(
1083 Isolate* isolate, Handle<Object> object, Handle<Context> context);
1085 // ES6 section 7.1.14 ToPropertyKey
1086 MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate,
1087 Handle<Object> input);
1089 // ES6 section 7.1.1 ToPrimitive
1090 MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive(
1091 Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
1093 // ES6 section 7.1.3 ToNumber
1094 MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Isolate* isolate,
1095 Handle<Object> input);
1097 // ES6 section 7.1.12 ToString
1098 MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate,
1099 Handle<Object> input);
1101 // ES6 section 7.3.9 GetMethod
1102 MUST_USE_RESULT static MaybeHandle<Object> GetMethod(
1103 Handle<JSReceiver> receiver, Handle<Name> name);
1105 MUST_USE_RESULT static MaybeHandle<Object> GetProperty(
1106 LookupIterator* it, LanguageMode language_mode = SLOPPY);
1108 // Implementation of [[Put]], ECMA-262 5th edition, section 8.12.5.
1109 MUST_USE_RESULT static MaybeHandle<Object> SetProperty(
1110 Handle<Object> object, Handle<Name> name, Handle<Object> value,
1111 LanguageMode language_mode,
1112 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
1114 MUST_USE_RESULT static MaybeHandle<Object> SetProperty(
1115 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1116 StoreFromKeyed store_mode);
1118 MUST_USE_RESULT static MaybeHandle<Object> SetSuperProperty(
1119 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1120 StoreFromKeyed store_mode);
1122 MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty(
1123 LookupIterator* it, LanguageMode language_mode);
1124 MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty(
1125 Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
1126 LanguageMode language_mode);
1127 MUST_USE_RESULT static MaybeHandle<Object> WriteToReadOnlyProperty(
1128 LookupIterator* it, Handle<Object> value, LanguageMode language_mode);
1129 MUST_USE_RESULT static MaybeHandle<Object> WriteToReadOnlyProperty(
1130 Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
1131 Handle<Object> value, LanguageMode language_mode);
1132 MUST_USE_RESULT static MaybeHandle<Object> RedefineNonconfigurableProperty(
1133 Isolate* isolate, Handle<Object> name, Handle<Object> value,
1134 LanguageMode language_mode);
1135 MUST_USE_RESULT static MaybeHandle<Object> SetDataProperty(
1136 LookupIterator* it, Handle<Object> value);
1137 MUST_USE_RESULT static MaybeHandle<Object> AddDataProperty(
1138 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
1139 LanguageMode language_mode, StoreFromKeyed store_mode);
1140 MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
1141 Handle<Object> object, Handle<Name> name,
1142 LanguageMode language_mode = SLOPPY);
1143 MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
1144 Isolate* isolate, Handle<Object> object, const char* key,
1145 LanguageMode language_mode = SLOPPY);
1146 MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
1147 Handle<Object> object, Handle<Name> name,
1148 LanguageMode language_mode = SLOPPY);
1150 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor(
1151 LookupIterator* it, LanguageMode language_mode);
1152 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithAccessor(
1153 LookupIterator* it, Handle<Object> value, LanguageMode language_mode);
1155 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter(
1156 Handle<Object> receiver,
1157 Handle<JSReceiver> getter);
1158 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithDefinedSetter(
1159 Handle<Object> receiver,
1160 Handle<JSReceiver> setter,
1161 Handle<Object> value);
1163 MUST_USE_RESULT static inline MaybeHandle<Object> GetElement(
1164 Isolate* isolate, Handle<Object> object, uint32_t index,
1165 LanguageMode language_mode = SLOPPY);
1167 MUST_USE_RESULT static inline MaybeHandle<Object> SetElement(
1168 Isolate* isolate, Handle<Object> object, uint32_t index,
1169 Handle<Object> value, LanguageMode language_mode);
1171 static inline Handle<Object> GetPrototypeSkipHiddenPrototypes(
1172 Isolate* isolate, Handle<Object> receiver);
1174 bool HasInPrototypeChain(Isolate* isolate, Object* object);
1176 // Returns the permanent hash code associated with this object. May return
1177 // undefined if not yet created.
1180 // Returns undefined for JSObjects, but returns the hash code for simple
1181 // objects. This avoids a double lookup in the cases where we know we will
1182 // add the hash to the JSObject if it does not already exist.
1183 Object* GetSimpleHash();
1185 // Returns the permanent hash code associated with this object depending on
1186 // the actual object type. May create and store a hash code if needed and none
1188 static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object);
1190 // Checks whether this object has the same value as the given one. This
1191 // function is implemented according to ES5, section 9.12 and can be used
1192 // to implement the Harmony "egal" function.
1193 bool SameValue(Object* other);
1195 // Checks whether this object has the same value as the given one.
1196 // +0 and -0 are treated equal. Everything else is the same as SameValue.
1197 // This function is implemented according to ES6, section 7.2.4 and is used
1198 // by ES6 Map and Set.
1199 bool SameValueZero(Object* other);
1201 // Tries to convert an object to an array length. Returns true and sets the
1202 // output parameter if it succeeds.
1203 inline bool ToArrayLength(uint32_t* index);
1205 // Tries to convert an object to an array index. Returns true and sets the
1206 // output parameter if it succeeds. Equivalent to ToArrayLength, but does not
1207 // allow kMaxUInt32.
1208 inline bool ToArrayIndex(uint32_t* index);
1210 // Returns true if this is a JSValue containing a string and the index is
1211 // < the length of the string. Used to implement [] on strings.
1212 inline bool IsStringObjectWithCharacterAt(uint32_t index);
1214 DECLARE_VERIFIER(Object)
1216 // Verify a pointer is a valid object pointer.
1217 static void VerifyPointer(Object* p);
1220 inline void VerifyApiCallResultType();
1222 // Prints this object without details.
1223 void ShortPrint(FILE* out = stdout);
1225 // Prints this object without details to a message accumulator.
1226 void ShortPrint(StringStream* accumulator);
1228 void ShortPrint(std::ostream& os); // NOLINT
1230 DECLARE_CAST(Object)
1232 // Layout description.
1233 static const int kHeaderSize = 0; // Object does not take up any space.
1236 // For our gdb macros, we should perhaps change these in the future.
1239 // Prints this object with details.
1240 void Print(std::ostream& os); // NOLINT
1242 void Print() { ShortPrint(); }
1243 void Print(std::ostream& os) { ShortPrint(os); } // NOLINT
1247 friend class LookupIterator;
1248 friend class PrototypeIterator;
1250 // Return the map of the root of object's prototype chain.
1251 Map* GetRootMap(Isolate* isolate);
1253 // Helper for SetProperty and SetSuperProperty.
1254 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyInternal(
1255 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1256 StoreFromKeyed store_mode, bool* found);
1258 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
1262 // In objects.h to be usable without objects-inl.h inclusion.
1263 bool Object::IsSmi() const { return HAS_SMI_TAG(this); }
1264 bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); }
1268 explicit Brief(const Object* const v) : value(v) {}
1269 const Object* value;
1273 std::ostream& operator<<(std::ostream& os, const Brief& v);
1276 // Smi represents integer Numbers that can be stored in 31 bits.
1277 // Smis are immediate which means they are NOT allocated in the heap.
1278 // The this pointer has the following format: [31 bit signed int] 0
1279 // For long smis it has the following format:
1280 // [32 bit signed int] [31 bits zero padding] 0
1281 // Smi stands for small integer.
1282 class Smi: public Object {
1284 // Returns the integer value.
1285 inline int value() const { return Internals::SmiValue(this); }
1287 // Convert a value to a Smi object.
1288 static inline Smi* FromInt(int value) {
1289 DCHECK(Smi::IsValid(value));
1290 return reinterpret_cast<Smi*>(Internals::IntToSmi(value));
1293 static inline Smi* FromIntptr(intptr_t value) {
1294 DCHECK(Smi::IsValid(value));
1295 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
1296 return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag);
1299 // Returns whether value can be represented in a Smi.
1300 static inline bool IsValid(intptr_t value) {
1301 bool result = Internals::IsValidSmi(value);
1302 DCHECK_EQ(result, value >= kMinValue && value <= kMaxValue);
1308 // Dispatched behavior.
1309 void SmiPrint(std::ostream& os) const; // NOLINT
1310 DECLARE_VERIFIER(Smi)
1312 static const int kMinValue =
1313 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
1314 static const int kMaxValue = -(kMinValue + 1);
1317 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1321 // Heap objects typically have a map pointer in their first word. However,
1322 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes
1323 // encoded in the first word. The class MapWord is an abstraction of the
1324 // value in a heap object's first word.
1325 class MapWord BASE_EMBEDDED {
1327 // Normal state: the map word contains a map pointer.
1329 // Create a map word from a map pointer.
1330 static inline MapWord FromMap(const Map* map);
1332 // View this map word as a map pointer.
1333 inline Map* ToMap();
1336 // Scavenge collection: the map word of live objects in the from space
1337 // contains a forwarding address (a heap object pointer in the to space).
1339 // True if this map word is a forwarding address for a scavenge
1340 // collection. Only valid during a scavenge collection (specifically,
1341 // when all map words are heap object pointers, i.e. not during a full GC).
1342 inline bool IsForwardingAddress();
1344 // Create a map word from a forwarding address.
1345 static inline MapWord FromForwardingAddress(HeapObject* object);
1347 // View this map word as a forwarding address.
1348 inline HeapObject* ToForwardingAddress();
1350 static inline MapWord FromRawValue(uintptr_t value) {
1351 return MapWord(value);
1354 inline uintptr_t ToRawValue() {
1359 // HeapObject calls the private constructor and directly reads the value.
1360 friend class HeapObject;
1362 explicit MapWord(uintptr_t value) : value_(value) {}
1368 // The content of an heap object (except for the map pointer). kTaggedValues
1369 // objects can contain both heap pointers and Smis, kMixedValues can contain
1370 // heap pointers, Smis, and raw values (e.g. doubles or strings), and kRawValues
1371 // objects can contain raw values and Smis.
1372 enum class HeapObjectContents { kTaggedValues, kMixedValues, kRawValues };
1375 // HeapObject is the superclass for all classes describing heap allocated
1377 class HeapObject: public Object {
1379 // [map]: Contains a map which contains the object's reflective
1381 inline Map* map() const;
1382 inline void set_map(Map* value);
1383 // The no-write-barrier version. This is OK if the object is white and in
1384 // new space, or if the value is an immortal immutable object, like the maps
1385 // of primitive (non-JS) objects like strings, heap numbers etc.
1386 inline void set_map_no_write_barrier(Map* value);
1388 // Get the map using acquire load.
1389 inline Map* synchronized_map();
1390 inline MapWord synchronized_map_word() const;
1392 // Set the map using release store
1393 inline void synchronized_set_map(Map* value);
1394 inline void synchronized_set_map_no_write_barrier(Map* value);
1395 inline void synchronized_set_map_word(MapWord map_word);
1397 // During garbage collection, the map word of a heap object does not
1398 // necessarily contain a map pointer.
1399 inline MapWord map_word() const;
1400 inline void set_map_word(MapWord map_word);
1402 // The Heap the object was allocated in. Used also to access Isolate.
1403 inline Heap* GetHeap() const;
1405 // Convenience method to get current isolate.
1406 inline Isolate* GetIsolate() const;
1408 // Converts an address to a HeapObject pointer.
1409 static inline HeapObject* FromAddress(Address address) {
1410 DCHECK_TAG_ALIGNED(address);
1411 return reinterpret_cast<HeapObject*>(address + kHeapObjectTag);
1414 // Returns the address of this HeapObject.
1415 inline Address address() {
1416 return reinterpret_cast<Address>(this) - kHeapObjectTag;
1419 // Iterates over pointers contained in the object (including the Map)
1420 void Iterate(ObjectVisitor* v);
1422 // Iterates over all pointers contained in the object except the
1423 // first map pointer. The object type is given in the first
1424 // parameter. This function does not access the map pointer in the
1425 // object, and so is safe to call while the map pointer is modified.
1426 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1428 // Returns the heap object's size in bytes
1431 // Indicates what type of values this heap object may contain.
1432 inline HeapObjectContents ContentType();
1434 // Given a heap object's map pointer, returns the heap size in bytes
1435 // Useful when the map pointer field is used for other purposes.
1437 inline int SizeFromMap(Map* map);
1439 // Returns the field at offset in obj, as a read/write Object* reference.
1440 // Does no checking, and is safe to use during GC, while maps are invalid.
1441 // Does not invoke write barrier, so should only be assigned to
1442 // during marking GC.
1443 static inline Object** RawField(HeapObject* obj, int offset);
1445 // Adds the |code| object related to |name| to the code cache of this map. If
1446 // this map is a dictionary map that is shared, the map copied and installed
1448 static void UpdateMapCodeCache(Handle<HeapObject> object,
1452 DECLARE_CAST(HeapObject)
1454 // Return the write barrier mode for this. Callers of this function
1455 // must be able to present a reference to an DisallowHeapAllocation
1456 // object as a sign that they are not going to use this function
1457 // from code that allocates and thus invalidates the returned write
1459 inline WriteBarrierMode GetWriteBarrierMode(
1460 const DisallowHeapAllocation& promise);
1462 // Dispatched behavior.
1463 void HeapObjectShortPrint(std::ostream& os); // NOLINT
1465 void PrintHeader(std::ostream& os, const char* id); // NOLINT
1467 DECLARE_PRINTER(HeapObject)
1468 DECLARE_VERIFIER(HeapObject)
1470 inline void VerifyObjectField(int offset);
1471 inline void VerifySmiField(int offset);
1473 // Verify a pointer is a valid HeapObject pointer that points to object
1474 // areas in the heap.
1475 static void VerifyHeapPointer(Object* p);
1478 inline AllocationAlignment RequiredAlignment();
1480 // Layout description.
1481 // First field in a heap object is map.
1482 static const int kMapOffset = Object::kHeaderSize;
1483 static const int kHeaderSize = kMapOffset + kPointerSize;
1485 STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset);
1488 // helpers for calling an ObjectVisitor to iterate over pointers in the
1489 // half-open range [start, end) specified as integer offsets
1490 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1491 // as above, for the single element at "offset"
1492 inline void IteratePointer(ObjectVisitor* v, int offset);
1493 // as above, for the next code link of a code object.
1494 inline void IterateNextCodeLink(ObjectVisitor* v, int offset);
1497 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1501 // This class describes a body of an object of a fixed size
1502 // in which all pointer fields are located in the [start_offset, end_offset)
1504 template<int start_offset, int end_offset, int size>
1505 class FixedBodyDescriptor {
1507 static const int kStartOffset = start_offset;
1508 static const int kEndOffset = end_offset;
1509 static const int kSize = size;
1511 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1513 template<typename StaticVisitor>
1514 static inline void IterateBody(HeapObject* obj) {
1515 StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1516 HeapObject::RawField(obj, end_offset));
1521 // This class describes a body of an object of a variable size
1522 // in which all pointer fields are located in the [start_offset, object_size)
1524 template<int start_offset>
1525 class FlexibleBodyDescriptor {
1527 static const int kStartOffset = start_offset;
1529 static inline void IterateBody(HeapObject* obj,
1533 template<typename StaticVisitor>
1534 static inline void IterateBody(HeapObject* obj, int object_size) {
1535 StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1536 HeapObject::RawField(obj, object_size));
1541 // The HeapNumber class describes heap allocated numbers that cannot be
1542 // represented in a Smi (small integer)
1543 class HeapNumber: public HeapObject {
1545 // [value]: number value.
1546 inline double value() const;
1547 inline void set_value(double value);
1549 DECLARE_CAST(HeapNumber)
1551 // Dispatched behavior.
1552 bool HeapNumberBooleanValue();
1554 void HeapNumberPrint(std::ostream& os); // NOLINT
1555 DECLARE_VERIFIER(HeapNumber)
1557 inline int get_exponent();
1558 inline int get_sign();
1560 // Layout description.
1561 static const int kValueOffset = HeapObject::kHeaderSize;
1562 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1563 // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
1564 // words within double numbers are endian dependent and they are set
1566 #if defined(V8_TARGET_LITTLE_ENDIAN)
1567 static const int kMantissaOffset = kValueOffset;
1568 static const int kExponentOffset = kValueOffset + 4;
1569 #elif defined(V8_TARGET_BIG_ENDIAN)
1570 static const int kMantissaOffset = kValueOffset + 4;
1571 static const int kExponentOffset = kValueOffset;
1573 #error Unknown byte ordering
1576 static const int kSize = kValueOffset + kDoubleSize;
1577 static const uint32_t kSignMask = 0x80000000u;
1578 static const uint32_t kExponentMask = 0x7ff00000u;
1579 static const uint32_t kMantissaMask = 0xfffffu;
1580 static const int kMantissaBits = 52;
1581 static const int kExponentBits = 11;
1582 static const int kExponentBias = 1023;
1583 static const int kExponentShift = 20;
1584 static const int kInfinityOrNanExponent =
1585 (kExponentMask >> kExponentShift) - kExponentBias;
1586 static const int kMantissaBitsInTopWord = 20;
1587 static const int kNonMantissaBitsInTopWord = 12;
1590 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1594 // The Simd128Value class describes heap allocated 128 bit SIMD values.
1595 class Simd128Value : public HeapObject {
1597 DECLARE_CAST(Simd128Value)
1599 DECLARE_PRINTER(Simd128Value)
1600 DECLARE_VERIFIER(Simd128Value)
1602 static Handle<String> ToString(Handle<Simd128Value> input);
1604 // Equality operations.
1605 inline bool Equals(Simd128Value* that);
1607 // Checks that another instance is bit-wise equal.
1608 bool BitwiseEquals(const Simd128Value* other) const;
1609 // Computes a hash from the 128 bit value, viewed as 4 32-bit integers.
1610 uint32_t Hash() const;
1611 // Copies the 16 bytes of SIMD data to the destination address.
1612 void CopyBits(void* destination) const;
1614 // Layout description.
1615 static const int kValueOffset = HeapObject::kHeaderSize;
1616 static const int kSize = kValueOffset + kSimd128Size;
1619 DISALLOW_IMPLICIT_CONSTRUCTORS(Simd128Value);
1623 // V has parameters (TYPE, Type, type, lane count, lane type)
1624 #define SIMD128_TYPES(V) \
1625 V(FLOAT32X4, Float32x4, float32x4, 4, float) \
1626 V(INT32X4, Int32x4, int32x4, 4, int32_t) \
1627 V(UINT32X4, Uint32x4, uint32x4, 4, uint32_t) \
1628 V(BOOL32X4, Bool32x4, bool32x4, 4, bool) \
1629 V(INT16X8, Int16x8, int16x8, 8, int16_t) \
1630 V(UINT16X8, Uint16x8, uint16x8, 8, uint16_t) \
1631 V(BOOL16X8, Bool16x8, bool16x8, 8, bool) \
1632 V(INT8X16, Int8x16, int8x16, 16, int8_t) \
1633 V(UINT8X16, Uint8x16, uint8x16, 16, uint8_t) \
1634 V(BOOL8X16, Bool8x16, bool8x16, 16, bool)
1636 #define SIMD128_VALUE_CLASS(TYPE, Type, type, lane_count, lane_type) \
1637 class Type final : public Simd128Value { \
1639 inline lane_type get_lane(int lane) const; \
1640 inline void set_lane(int lane, lane_type value); \
1642 DECLARE_CAST(Type) \
1644 DECLARE_PRINTER(Type) \
1646 static Handle<String> ToString(Handle<Type> input); \
1648 inline bool Equals(Type* that); \
1651 DISALLOW_IMPLICIT_CONSTRUCTORS(Type); \
1653 SIMD128_TYPES(SIMD128_VALUE_CLASS)
1654 #undef SIMD128_VALUE_CLASS
1657 enum EnsureElementsMode {
1658 DONT_ALLOW_DOUBLE_ELEMENTS,
1659 ALLOW_COPIED_DOUBLE_ELEMENTS,
1660 ALLOW_CONVERTED_DOUBLE_ELEMENTS
1664 // Indicator for one component of an AccessorPair.
1665 enum AccessorComponent {
1671 // JSReceiver includes types on which properties can be defined, i.e.,
1672 // JSObject and JSProxy.
1673 class JSReceiver: public HeapObject {
1675 DECLARE_CAST(JSReceiver)
1677 // ES6 section 7.1.1 ToPrimitive
1678 MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive(
1679 Handle<JSReceiver> receiver,
1680 ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
1681 MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive(
1682 Handle<JSReceiver> receiver, Handle<String> hint);
1684 // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
1685 MUST_USE_RESULT static inline Maybe<bool> HasProperty(
1686 Handle<JSReceiver> object, Handle<Name> name);
1687 MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>,
1689 MUST_USE_RESULT static inline Maybe<bool> HasElement(
1690 Handle<JSReceiver> object, uint32_t index);
1691 MUST_USE_RESULT static inline Maybe<bool> HasOwnElement(
1692 Handle<JSReceiver> object, uint32_t index);
1694 // Implementation of [[Delete]], ECMA-262 5th edition, section 8.12.7.
1695 MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyOrElement(
1696 Handle<JSReceiver> object, Handle<Name> name,
1697 LanguageMode language_mode = SLOPPY);
1698 MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
1699 Handle<JSReceiver> object, Handle<Name> name,
1700 LanguageMode language_mode = SLOPPY);
1701 MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
1702 LookupIterator* it, LanguageMode language_mode);
1703 MUST_USE_RESULT static MaybeHandle<Object> DeleteElement(
1704 Handle<JSReceiver> object, uint32_t index,
1705 LanguageMode language_mode = SLOPPY);
1707 // Tests for the fast common case for property enumeration.
1708 bool IsSimpleEnum();
1710 // Returns the class name ([[Class]] property in the specification).
1711 String* class_name();
1713 // Returns the constructor name (the name (possibly, inferred name) of the
1714 // function that was used to instantiate the object).
1715 String* constructor_name();
1717 MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes(
1718 Handle<JSReceiver> object, Handle<Name> name);
1719 MUST_USE_RESULT static inline Maybe<PropertyAttributes>
1720 GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
1722 MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes(
1723 Handle<JSReceiver> object, uint32_t index);
1724 MUST_USE_RESULT static inline Maybe<PropertyAttributes>
1725 GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index);
1727 MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
1728 LookupIterator* it);
1731 static Handle<Object> GetDataProperty(Handle<JSReceiver> object,
1733 static Handle<Object> GetDataProperty(LookupIterator* it);
1736 // Retrieves a permanent object identity hash code. The undefined value might
1737 // be returned in case no hash was created yet.
1738 inline Object* GetIdentityHash();
1740 // Retrieves a permanent object identity hash code. May create and store a
1741 // hash code if needed and none exists.
1742 inline static Handle<Smi> GetOrCreateIdentityHash(
1743 Handle<JSReceiver> object);
1745 enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS };
1747 // Computes the enumerable keys for a JSObject. Used for implementing
1748 // "for (n in object) { }".
1749 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys(
1750 Handle<JSReceiver> object,
1751 KeyCollectionType type);
1754 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1758 // The JSObject describes real heap allocated JavaScript objects with
1760 // Note that the map of JSObject changes during execution to enable inline
1762 class JSObject: public JSReceiver {
1764 // [properties]: Backing storage for properties.
1765 // properties is a FixedArray in the fast case and a Dictionary in the
1767 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1768 inline void initialize_properties();
1769 inline bool HasFastProperties();
1770 // Gets slow properties for non-global objects.
1771 inline NameDictionary* property_dictionary();
1772 // Gets global object properties.
1773 inline GlobalDictionary* global_dictionary();
1775 // [elements]: The elements (properties with names that are integers).
1777 // Elements can be in two general modes: fast and slow. Each mode
1778 // corrensponds to a set of object representations of elements that
1779 // have something in common.
1781 // In the fast mode elements is a FixedArray and so each element can
1782 // be quickly accessed. This fact is used in the generated code. The
1783 // elements array can have one of three maps in this mode:
1784 // fixed_array_map, sloppy_arguments_elements_map or
1785 // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1786 // the elements array may be shared by a few objects and so before
1787 // writing to any element the array must be copied. Use
1788 // EnsureWritableFastElements in this case.
1790 // In the slow mode the elements is either a NumberDictionary, a
1791 // FixedArray parameter map for a (sloppy) arguments object.
1792 DECL_ACCESSORS(elements, FixedArrayBase)
1793 inline void initialize_elements();
1794 static void ResetElements(Handle<JSObject> object);
1795 static inline void SetMapAndElements(Handle<JSObject> object,
1797 Handle<FixedArrayBase> elements);
1798 inline ElementsKind GetElementsKind();
1799 ElementsAccessor* GetElementsAccessor();
1800 // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
1801 inline bool HasFastSmiElements();
1802 // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
1803 inline bool HasFastObjectElements();
1804 // Returns true if an object has elements of FAST_ELEMENTS or
1805 // FAST_SMI_ONLY_ELEMENTS.
1806 inline bool HasFastSmiOrObjectElements();
1807 // Returns true if an object has any of the fast elements kinds.
1808 inline bool HasFastElements();
1809 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
1811 inline bool HasFastDoubleElements();
1812 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
1814 inline bool HasFastHoleyElements();
1815 inline bool HasSloppyArgumentsElements();
1816 inline bool HasDictionaryElements();
1818 inline bool HasFixedTypedArrayElements();
1820 inline bool HasFixedUint8ClampedElements();
1821 inline bool HasFixedArrayElements();
1822 inline bool HasFixedInt8Elements();
1823 inline bool HasFixedUint8Elements();
1824 inline bool HasFixedInt16Elements();
1825 inline bool HasFixedUint16Elements();
1826 inline bool HasFixedInt32Elements();
1827 inline bool HasFixedUint32Elements();
1828 inline bool HasFixedFloat32Elements();
1829 inline bool HasFixedFloat64Elements();
1831 inline bool HasFastArgumentsElements();
1832 inline bool HasSlowArgumentsElements();
1833 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
1835 // Requires: HasFastElements().
1836 static Handle<FixedArray> EnsureWritableFastElements(
1837 Handle<JSObject> object);
1839 // Collects elements starting at index 0.
1840 // Undefined values are placed after non-undefined values.
1841 // Returns the number of non-undefined values.
1842 static Handle<Object> PrepareElementsForSort(Handle<JSObject> object,
1844 // As PrepareElementsForSort, but only on objects where elements is
1845 // a dictionary, and it will stay a dictionary. Collates undefined and
1846 // unexisting elements below limit from position zero of the elements.
1847 static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object,
1850 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithInterceptor(
1851 LookupIterator* it, Handle<Object> value);
1853 // SetLocalPropertyIgnoreAttributes converts callbacks to fields. We need to
1854 // grant an exemption to ExecutableAccessor callbacks in some cases.
1855 enum ExecutableAccessorInfoHandling { DEFAULT_HANDLING, DONT_FORCE_FIELD };
1857 MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes(
1858 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
1859 ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
1861 MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes(
1862 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
1863 PropertyAttributes attributes,
1864 ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
1866 MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes(
1867 Handle<JSObject> object, uint32_t index, Handle<Object> value,
1868 PropertyAttributes attributes,
1869 ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
1871 // Equivalent to one of the above depending on whether |name| can be converted
1872 // to an array index.
1873 MUST_USE_RESULT static MaybeHandle<Object>
1874 DefinePropertyOrElementIgnoreAttributes(
1875 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
1876 PropertyAttributes attributes = NONE,
1877 ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
1879 // Adds or reconfigures a property to attributes NONE. It will fail when it
1881 MUST_USE_RESULT static Maybe<bool> CreateDataProperty(LookupIterator* it,
1882 Handle<Object> value);
1884 static void AddProperty(Handle<JSObject> object, Handle<Name> name,
1885 Handle<Object> value, PropertyAttributes attributes);
1887 MUST_USE_RESULT static MaybeHandle<Object> AddDataElement(
1888 Handle<JSObject> receiver, uint32_t index, Handle<Object> value,
1889 PropertyAttributes attributes);
1891 // Extend the receiver with a single fast property appeared first in the
1892 // passed map. This also extends the property backing store if necessary.
1893 static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map);
1895 // Migrates the given object to a map whose field representations are the
1896 // lowest upper bound of all known representations for that field.
1897 static void MigrateInstance(Handle<JSObject> instance);
1899 // Migrates the given object only if the target map is already available,
1900 // or returns false if such a map is not yet available.
1901 static bool TryMigrateInstance(Handle<JSObject> instance);
1903 // Sets the property value in a normalized object given (key, value, details).
1904 // Handles the special representation of JS global objects.
1905 static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name,
1906 Handle<Object> value,
1907 PropertyDetails details);
1908 static void SetDictionaryElement(Handle<JSObject> object, uint32_t index,
1909 Handle<Object> value,
1910 PropertyAttributes attributes);
1911 static void SetDictionaryArgumentsElement(Handle<JSObject> object,
1913 Handle<Object> value,
1914 PropertyAttributes attributes);
1916 static void OptimizeAsPrototype(Handle<JSObject> object,
1917 PrototypeOptimizationMode mode);
1918 static void ReoptimizeIfPrototype(Handle<JSObject> object);
1919 static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate);
1920 static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate);
1921 static void InvalidatePrototypeChains(Map* map);
1923 // Alternative implementation of WeakFixedArray::NullCallback.
1924 class PrototypeRegistryCompactionCallback {
1926 static void Callback(Object* value, int old_index, int new_index);
1929 // Retrieve interceptors.
1930 InterceptorInfo* GetNamedInterceptor();
1931 InterceptorInfo* GetIndexedInterceptor();
1933 // Used from JSReceiver.
1934 MUST_USE_RESULT static Maybe<PropertyAttributes>
1935 GetPropertyAttributesWithInterceptor(LookupIterator* it);
1936 MUST_USE_RESULT static Maybe<PropertyAttributes>
1937 GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
1939 // Retrieves an AccessorPair property from the given object. Might return
1940 // undefined if the property doesn't exist or is of a different kind.
1941 MUST_USE_RESULT static MaybeHandle<Object> GetAccessor(
1942 Handle<JSObject> object,
1944 AccessorComponent component);
1946 // Defines an AccessorPair property on the given object.
1947 // TODO(mstarzinger): Rename to SetAccessor().
1948 static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
1950 Handle<Object> getter,
1951 Handle<Object> setter,
1952 PropertyAttributes attributes);
1954 // Defines an AccessorInfo property on the given object.
1955 MUST_USE_RESULT static MaybeHandle<Object> SetAccessor(
1956 Handle<JSObject> object,
1957 Handle<AccessorInfo> info);
1959 // The result must be checked first for exceptions. If there's no exception,
1960 // the output parameter |done| indicates whether the interceptor has a result
1962 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
1963 LookupIterator* it, bool* done);
1965 // Accessors for hidden properties object.
1967 // Hidden properties are not own properties of the object itself.
1968 // Instead they are stored in an auxiliary structure kept as an own
1969 // property with a special name Heap::hidden_string(). But if the
1970 // receiver is a JSGlobalProxy then the auxiliary object is a property
1971 // of its prototype, and if it's a detached proxy, then you can't have
1972 // hidden properties.
1974 // Sets a hidden property on this object. Returns this object if successful,
1975 // undefined if called on a detached proxy.
1976 static Handle<Object> SetHiddenProperty(Handle<JSObject> object,
1978 Handle<Object> value);
1979 // Gets the value of a hidden property with the given key. Returns the hole
1980 // if the property doesn't exist (or if called on a detached proxy),
1981 // otherwise returns the value set for the key.
1982 Object* GetHiddenProperty(Handle<Name> key);
1983 // Deletes a hidden property. Deleting a non-existing property is
1984 // considered successful.
1985 static void DeleteHiddenProperty(Handle<JSObject> object,
1987 // Returns true if the object has a property with the hidden string as name.
1988 static bool HasHiddenProperties(Handle<JSObject> object);
1990 static void SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash);
1992 static void ValidateElements(Handle<JSObject> object);
1994 // Makes sure that this object can contain HeapObject as elements.
1995 static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj);
1997 // Makes sure that this object can contain the specified elements.
1998 static inline void EnsureCanContainElements(
1999 Handle<JSObject> object,
2002 EnsureElementsMode mode);
2003 static inline void EnsureCanContainElements(
2004 Handle<JSObject> object,
2005 Handle<FixedArrayBase> elements,
2007 EnsureElementsMode mode);
2008 static void EnsureCanContainElements(
2009 Handle<JSObject> object,
2010 Arguments* arguments,
2013 EnsureElementsMode mode);
2015 // Would we convert a fast elements array to dictionary mode given
2016 // an access at key?
2017 bool WouldConvertToSlowElements(uint32_t index);
2019 // Computes the new capacity when expanding the elements of a JSObject.
2020 static uint32_t NewElementsCapacity(uint32_t old_capacity) {
2021 // (old_capacity + 50%) + 16
2022 return old_capacity + (old_capacity >> 1) + 16;
2025 // These methods do not perform access checks!
2026 static void UpdateAllocationSite(Handle<JSObject> object,
2027 ElementsKind to_kind);
2029 // Lookup interceptors are used for handling properties controlled by host
2031 inline bool HasNamedInterceptor();
2032 inline bool HasIndexedInterceptor();
2034 // Computes the enumerable keys from interceptors. Used for debug mirrors and
2035 // by JSReceiver::GetKeys.
2036 MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForNamedInterceptor(
2037 Handle<JSObject> object,
2038 Handle<JSReceiver> receiver);
2039 MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForIndexedInterceptor(
2040 Handle<JSObject> object,
2041 Handle<JSReceiver> receiver);
2043 // Support functions for v8 api (needed for correct interceptor behavior).
2044 MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty(
2045 Handle<JSObject> object, Handle<Name> name);
2046 MUST_USE_RESULT static Maybe<bool> HasRealElementProperty(
2047 Handle<JSObject> object, uint32_t index);
2048 MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty(
2049 Handle<JSObject> object, Handle<Name> name);
2051 // Get the header size for a JSObject. Used to compute the index of
2052 // internal fields as well as the number of internal fields.
2053 inline int GetHeaderSize();
2055 inline int GetInternalFieldCount();
2056 inline int GetInternalFieldOffset(int index);
2057 inline Object* GetInternalField(int index);
2058 inline void SetInternalField(int index, Object* value);
2059 inline void SetInternalField(int index, Smi* value);
2061 // Returns the number of properties on this object filtering out properties
2062 // with the specified attributes (ignoring interceptors).
2063 int NumberOfOwnProperties(PropertyAttributes filter = NONE);
2064 // Fill in details for properties into storage starting at the specified
2065 // index. Returns the number of properties added.
2066 int GetOwnPropertyNames(FixedArray* storage, int index,
2067 PropertyAttributes filter = NONE);
2069 // Returns the number of properties on this object filtering out properties
2070 // with the specified attributes (ignoring interceptors).
2071 int NumberOfOwnElements(PropertyAttributes filter);
2072 // Returns the number of enumerable elements (ignoring interceptors).
2073 int NumberOfEnumElements();
2074 // Returns the number of elements on this object filtering out elements
2075 // with the specified attributes (ignoring interceptors).
2076 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter);
2077 // Count and fill in the enumerable elements into storage.
2078 // (storage->length() == NumberOfEnumElements()).
2079 // If storage is NULL, will count the elements without adding
2080 // them to any storage.
2081 // Returns the number of enumerable elements.
2082 int GetEnumElementKeys(FixedArray* storage);
2084 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
2087 // Returns a new map with all transitions dropped from the object's current
2088 // map and the ElementsKind set.
2089 static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
2090 ElementsKind to_kind);
2091 static void TransitionElementsKind(Handle<JSObject> object,
2092 ElementsKind to_kind);
2094 // Always use this to migrate an object to a new map.
2095 // |expected_additional_properties| is only used for fast-to-slow transitions
2096 // and ignored otherwise.
2097 static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map,
2098 int expected_additional_properties = 0);
2100 // Convert the object to use the canonical dictionary
2101 // representation. If the object is expected to have additional properties
2102 // added this number can be indicated to have the backing store allocated to
2103 // an initial capacity for holding these properties.
2104 static void NormalizeProperties(Handle<JSObject> object,
2105 PropertyNormalizationMode mode,
2106 int expected_additional_properties,
2107 const char* reason);
2109 // Convert and update the elements backing store to be a
2110 // SeededNumberDictionary dictionary. Returns the backing after conversion.
2111 static Handle<SeededNumberDictionary> NormalizeElements(
2112 Handle<JSObject> object);
2114 void RequireSlowElements(SeededNumberDictionary* dictionary);
2116 // Transform slow named properties to fast variants.
2117 static void MigrateSlowToFast(Handle<JSObject> object,
2118 int unused_property_fields, const char* reason);
2120 inline bool IsUnboxedDoubleField(FieldIndex index);
2122 // Access fast-case object properties at index.
2123 static Handle<Object> FastPropertyAt(Handle<JSObject> object,
2124 Representation representation,
2126 inline Object* RawFastPropertyAt(FieldIndex index);
2127 inline double RawFastDoublePropertyAt(FieldIndex index);
2129 inline void FastPropertyAtPut(FieldIndex index, Object* value);
2130 inline void RawFastPropertyAtPut(FieldIndex index, Object* value);
2131 inline void RawFastDoublePropertyAtPut(FieldIndex index, double value);
2132 inline void WriteToField(int descriptor, Object* value);
2134 // Access to in object properties.
2135 inline int GetInObjectPropertyOffset(int index);
2136 inline Object* InObjectPropertyAt(int index);
2137 inline Object* InObjectPropertyAtPut(int index,
2139 WriteBarrierMode mode
2140 = UPDATE_WRITE_BARRIER);
2142 // Set the object's prototype (only JSReceiver and null are allowed values).
2143 MUST_USE_RESULT static MaybeHandle<Object> SetPrototype(
2144 Handle<JSObject> object, Handle<Object> value, bool from_javascript);
2146 // Initializes the body after properties slot, properties slot is
2147 // initialized by set_properties. Fill the pre-allocated fields with
2148 // pre_allocated_value and the rest with filler_value.
2149 // Note: this call does not update write barrier, the caller is responsible
2150 // to ensure that |filler_value| can be collected without WB here.
2151 inline void InitializeBody(Map* map,
2152 Object* pre_allocated_value,
2153 Object* filler_value);
2155 // Check whether this object references another object
2156 bool ReferencesObject(Object* obj);
2158 // Disalow further properties to be added to the oject.
2159 MUST_USE_RESULT static MaybeHandle<Object> PreventExtensions(
2160 Handle<JSObject> object);
2162 bool IsExtensible();
2165 MUST_USE_RESULT static MaybeHandle<Object> Seal(Handle<JSObject> object);
2167 // ES5 Object.freeze
2168 MUST_USE_RESULT static MaybeHandle<Object> Freeze(Handle<JSObject> object);
2170 // Called the first time an object is observed with ES7 Object.observe.
2171 static void SetObserved(Handle<JSObject> object);
2174 enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
2176 MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy(
2177 Handle<JSObject> object,
2178 AllocationSiteUsageContext* site_context,
2179 DeepCopyHints hints = kNoHints);
2180 MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk(
2181 Handle<JSObject> object,
2182 AllocationSiteCreationContext* site_context);
2184 DECLARE_CAST(JSObject)
2186 // Dispatched behavior.
2187 void JSObjectShortPrint(StringStream* accumulator);
2188 DECLARE_PRINTER(JSObject)
2189 DECLARE_VERIFIER(JSObject)
2191 void PrintProperties(std::ostream& os); // NOLINT
2192 void PrintElements(std::ostream& os); // NOLINT
2194 #if defined(DEBUG) || defined(OBJECT_PRINT)
2195 void PrintTransitions(std::ostream& os); // NOLINT
2198 static void PrintElementsTransition(
2199 FILE* file, Handle<JSObject> object,
2200 ElementsKind from_kind, Handle<FixedArrayBase> from_elements,
2201 ElementsKind to_kind, Handle<FixedArrayBase> to_elements);
2203 void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map);
2206 // Structure for collecting spill information about JSObjects.
2207 class SpillInformation {
2211 int number_of_objects_;
2212 int number_of_objects_with_fast_properties_;
2213 int number_of_objects_with_fast_elements_;
2214 int number_of_fast_used_fields_;
2215 int number_of_fast_unused_fields_;
2216 int number_of_slow_used_properties_;
2217 int number_of_slow_unused_properties_;
2218 int number_of_fast_used_elements_;
2219 int number_of_fast_unused_elements_;
2220 int number_of_slow_used_elements_;
2221 int number_of_slow_unused_elements_;
2224 void IncrementSpillStatistics(SpillInformation* info);
2228 // If a GC was caused while constructing this object, the elements pointer
2229 // may point to a one pointer filler map. The object won't be rooted, but
2230 // our heap verification code could stumble across it.
2231 bool ElementsAreSafeToExamine();
2234 Object* SlowReverseLookup(Object* value);
2236 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2237 // Also maximal value of JSArray's length property.
2238 static const uint32_t kMaxElementCount = 0xffffffffu;
2240 // Constants for heuristics controlling conversion of fast elements
2241 // to slow elements.
2243 // Maximal gap that can be introduced by adding an element beyond
2244 // the current elements length.
2245 static const uint32_t kMaxGap = 1024;
2247 // Maximal length of fast elements array that won't be checked for
2248 // being dense enough on expansion.
2249 static const int kMaxUncheckedFastElementsLength = 5000;
2251 // Same as above but for old arrays. This limit is more strict. We
2252 // don't want to be wasteful with long lived objects.
2253 static const int kMaxUncheckedOldFastElementsLength = 500;
2255 // Note that Page::kMaxRegularHeapObjectSize puts a limit on
2256 // permissible values (see the DCHECK in heap.cc).
2257 static const int kInitialMaxFastElementArray = 100000;
2259 // This constant applies only to the initial map of "global.Object" and
2260 // not to arbitrary other JSObject maps.
2261 static const int kInitialGlobalObjectUnusedPropertiesCount = 4;
2263 static const int kMaxInstanceSize = 255 * kPointerSize;
2264 // When extending the backing storage for property values, we increase
2265 // its size by more than the 1 entry necessary, so sequentially adding fields
2266 // to the same object requires fewer allocations and copies.
2267 static const int kFieldsAdded = 3;
2269 // Layout description.
2270 static const int kPropertiesOffset = HeapObject::kHeaderSize;
2271 static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2272 static const int kHeaderSize = kElementsOffset + kPointerSize;
2274 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
2276 class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2278 static inline int SizeOf(Map* map, HeapObject* object);
2281 Context* GetCreationContext();
2283 // Enqueue change record for Object.observe. May cause GC.
2284 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord(
2285 Handle<JSObject> object, const char* type, Handle<Name> name,
2286 Handle<Object> old_value);
2288 // Gets the number of currently used elements.
2289 int GetFastElementsUsage();
2291 // Deletes an existing named property in a normalized object.
2292 static void DeleteNormalizedProperty(Handle<JSObject> object,
2293 Handle<Name> name, int entry);
2295 static bool AllCanRead(LookupIterator* it);
2296 static bool AllCanWrite(LookupIterator* it);
2299 friend class JSReceiver;
2300 friend class Object;
2302 static void MigrateFastToFast(Handle<JSObject> object, Handle<Map> new_map);
2303 static void MigrateFastToSlow(Handle<JSObject> object,
2304 Handle<Map> new_map,
2305 int expected_additional_properties);
2307 // Used from Object::GetProperty().
2308 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck(
2309 LookupIterator* it);
2311 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithFailedAccessCheck(
2312 LookupIterator* it, Handle<Object> value);
2314 // Add a property to a slow-case object.
2315 static void AddSlowProperty(Handle<JSObject> object,
2317 Handle<Object> value,
2318 PropertyAttributes attributes);
2320 MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithInterceptor(
2321 LookupIterator* it);
2323 bool ReferencesObjectFromElements(FixedArray* elements,
2327 // Return the hash table backing store or the inline stored identity hash,
2328 // whatever is found.
2329 MUST_USE_RESULT Object* GetHiddenPropertiesHashTable();
2331 // Return the hash table backing store for hidden properties. If there is no
2332 // backing store, allocate one.
2333 static Handle<ObjectHashTable> GetOrCreateHiddenPropertiesHashtable(
2334 Handle<JSObject> object);
2336 // Set the hidden property backing store to either a hash table or
2337 // the inline-stored identity hash.
2338 static Handle<Object> SetHiddenPropertiesHashTable(
2339 Handle<JSObject> object,
2340 Handle<Object> value);
2342 MUST_USE_RESULT Object* GetIdentityHash();
2344 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
2346 static Handle<SeededNumberDictionary> GetNormalizedElementDictionary(
2347 Handle<JSObject> object, Handle<FixedArrayBase> elements);
2349 // Helper for fast versions of preventExtensions, seal, and freeze.
2350 // attrs is one of NONE, SEALED, or FROZEN (depending on the operation).
2351 template <PropertyAttributes attrs>
2352 MUST_USE_RESULT static MaybeHandle<Object> PreventExtensionsWithTransition(
2353 Handle<JSObject> object);
2355 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2359 // Common superclass for FixedArrays that allow implementations to share
2360 // common accessors and some code paths.
2361 class FixedArrayBase: public HeapObject {
2363 // [length]: length of the array.
2364 inline int length() const;
2365 inline void set_length(int value);
2367 // Get and set the length using acquire loads and release stores.
2368 inline int synchronized_length() const;
2369 inline void synchronized_set_length(int value);
2371 DECLARE_CAST(FixedArrayBase)
2373 // Layout description.
2374 // Length is smi tagged when it is stored.
2375 static const int kLengthOffset = HeapObject::kHeaderSize;
2376 static const int kHeaderSize = kLengthOffset + kPointerSize;
2380 class FixedDoubleArray;
2381 class IncrementalMarking;
2384 // FixedArray describes fixed-sized arrays with element type Object*.
2385 class FixedArray: public FixedArrayBase {
2387 // Setter and getter for elements.
2388 inline Object* get(int index) const;
2389 void SetValue(uint32_t index, Object* value);
2390 static inline Handle<Object> get(Handle<FixedArray> array, int index);
2391 // Setter that uses write barrier.
2392 inline void set(int index, Object* value);
2393 inline bool is_the_hole(int index);
2395 // Setter that doesn't need write barrier.
2396 inline void set(int index, Smi* value);
2397 // Setter with explicit barrier mode.
2398 inline void set(int index, Object* value, WriteBarrierMode mode);
2400 // Setters for frequently used oddballs located in old space.
2401 inline void set_undefined(int index);
2402 inline void set_null(int index);
2403 inline void set_the_hole(int index);
2405 inline Object** GetFirstElementAddress();
2406 inline bool ContainsOnlySmisOrHoles();
2408 // Gives access to raw memory which stores the array's data.
2409 inline Object** data_start();
2411 inline void FillWithHoles(int from, int to);
2413 // Shrink length and insert filler objects.
2414 void Shrink(int length);
2416 enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS };
2418 // Add the elements of a JSArray to this FixedArray.
2419 MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromArrayLike(
2420 Handle<FixedArray> content, Handle<JSObject> array,
2421 KeyFilter filter = ALL_KEYS);
2423 // Computes the union of keys and return the result.
2424 // Used for implementing "for (n in object) { }"
2425 MUST_USE_RESULT static MaybeHandle<FixedArray> UnionOfKeys(
2426 Handle<FixedArray> first,
2427 Handle<FixedArray> second);
2429 // Copy a sub array from the receiver to dest.
2430 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2432 // Garbage collection support.
2433 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2435 // Code Generation support.
2436 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2438 // Garbage collection support.
2439 inline Object** RawFieldOfElementAt(int index);
2441 DECLARE_CAST(FixedArray)
2443 // Maximal allowed size, in bytes, of a single FixedArray.
2444 // Prevents overflowing size computations, as well as extreme memory
2446 static const int kMaxSize = 128 * MB * kPointerSize;
2447 // Maximally allowed length of a FixedArray.
2448 static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
2450 // Dispatched behavior.
2451 DECLARE_PRINTER(FixedArray)
2452 DECLARE_VERIFIER(FixedArray)
2454 // Checks if two FixedArrays have identical contents.
2455 bool IsEqualTo(FixedArray* other);
2458 // Swap two elements in a pair of arrays. If this array and the
2459 // numbers array are the same object, the elements are only swapped
2461 void SwapPairs(FixedArray* numbers, int i, int j);
2463 // Sort prefix of this array and the numbers array as pairs wrt. the
2464 // numbers. If the numbers array and the this array are the same
2465 // object, the prefix of this array is sorted.
2466 void SortPairs(FixedArray* numbers, uint32_t len);
2468 class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2470 static inline int SizeOf(Map* map, HeapObject* object);
2474 // Set operation on FixedArray without using write barriers. Can
2475 // only be used for storing old space objects or smis.
2476 static inline void NoWriteBarrierSet(FixedArray* array,
2480 // Set operation on FixedArray without incremental write barrier. Can
2481 // only be used if the object is guaranteed to be white (whiteness witness
2483 static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2488 STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize);
2490 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2494 // FixedDoubleArray describes fixed-sized arrays with element type double.
2495 class FixedDoubleArray: public FixedArrayBase {
2497 // Setter and getter for elements.
2498 inline double get_scalar(int index);
2499 inline uint64_t get_representation(int index);
2500 static inline Handle<Object> get(Handle<FixedDoubleArray> array, int index);
2501 // This accessor has to get a Number as |value|.
2502 void SetValue(uint32_t index, Object* value);
2503 inline void set(int index, double value);
2504 inline void set_the_hole(int index);
2506 // Checking for the hole.
2507 inline bool is_the_hole(int index);
2509 // Garbage collection support.
2510 inline static int SizeFor(int length) {
2511 return kHeaderSize + length * kDoubleSize;
2514 // Gives access to raw memory which stores the array's data.
2515 inline double* data_start();
2517 inline void FillWithHoles(int from, int to);
2519 // Code Generation support.
2520 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2522 DECLARE_CAST(FixedDoubleArray)
2524 // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2525 // Prevents overflowing size computations, as well as extreme memory
2527 static const int kMaxSize = 512 * MB;
2528 // Maximally allowed length of a FixedArray.
2529 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2531 // Dispatched behavior.
2532 DECLARE_PRINTER(FixedDoubleArray)
2533 DECLARE_VERIFIER(FixedDoubleArray)
2536 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2540 class WeakFixedArray : public FixedArray {
2542 // If |maybe_array| is not a WeakFixedArray, a fresh one will be allocated.
2543 // This function does not check if the value exists already, callers must
2544 // ensure this themselves if necessary.
2545 static Handle<WeakFixedArray> Add(Handle<Object> maybe_array,
2546 Handle<HeapObject> value,
2547 int* assigned_index = NULL);
2549 // Returns true if an entry was found and removed.
2550 bool Remove(Handle<HeapObject> value);
2552 class NullCallback {
2554 static void Callback(Object* value, int old_index, int new_index) {}
2557 template <class CompactionCallback>
2560 inline Object* Get(int index) const;
2561 inline void Clear(int index);
2562 inline int Length() const;
2564 inline bool IsEmptySlot(int index) const;
2565 static Object* Empty() { return Smi::FromInt(0); }
2569 explicit Iterator(Object* maybe_array) : list_(NULL) { Reset(maybe_array); }
2570 void Reset(Object* maybe_array);
2577 WeakFixedArray* list_;
2579 int last_used_index_;
2580 DisallowHeapAllocation no_gc_;
2582 DISALLOW_COPY_AND_ASSIGN(Iterator);
2585 DECLARE_CAST(WeakFixedArray)
2588 static const int kLastUsedIndexIndex = 0;
2589 static const int kFirstIndex = 1;
2591 static Handle<WeakFixedArray> Allocate(
2592 Isolate* isolate, int size, Handle<WeakFixedArray> initialize_from);
2594 static void Set(Handle<WeakFixedArray> array, int index,
2595 Handle<HeapObject> value);
2596 inline void clear(int index);
2598 inline int last_used_index() const;
2599 inline void set_last_used_index(int index);
2601 // Disallow inherited setters.
2602 void set(int index, Smi* value);
2603 void set(int index, Object* value);
2604 void set(int index, Object* value, WriteBarrierMode mode);
2605 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakFixedArray);
2609 // Generic array grows dynamically with O(1) amortized insertion.
2610 class ArrayList : public FixedArray {
2614 // Use this if GC can delete elements from the array.
2615 kReloadLengthAfterAllocation,
2617 static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj,
2618 AddMode mode = kNone);
2619 static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj1,
2620 Handle<Object> obj2, AddMode = kNone);
2621 inline int Length();
2622 inline void SetLength(int length);
2623 inline Object* Get(int index);
2624 inline Object** Slot(int index);
2625 inline void Set(int index, Object* obj);
2626 inline void Clear(int index, Object* undefined);
2627 DECLARE_CAST(ArrayList)
2630 static Handle<ArrayList> EnsureSpace(Handle<ArrayList> array, int length);
2631 static const int kLengthIndex = 0;
2632 static const int kFirstIndex = 1;
2633 DISALLOW_IMPLICIT_CONSTRUCTORS(ArrayList);
2637 // DescriptorArrays are fixed arrays used to hold instance descriptors.
2638 // The format of the these objects is:
2639 // [0]: Number of descriptors
2640 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array:
2641 // [0]: pointer to fixed array with enum cache
2642 // [1]: either Smi(0) or pointer to fixed array with indices
2644 // [2 + number of descriptors * kDescriptorSize]: start of slack
2645 class DescriptorArray: public FixedArray {
2647 // Returns true for both shared empty_descriptor_array and for smis, which the
2648 // map uses to encode additional bit fields when the descriptor array is not
2650 inline bool IsEmpty();
2652 // Returns the number of descriptors in the array.
2653 inline int number_of_descriptors();
2655 inline int number_of_descriptors_storage();
2657 inline int NumberOfSlackDescriptors();
2659 inline void SetNumberOfDescriptors(int number_of_descriptors);
2660 inline int number_of_entries();
2662 inline bool HasEnumCache();
2664 inline void CopyEnumCacheFrom(DescriptorArray* array);
2666 inline FixedArray* GetEnumCache();
2668 inline bool HasEnumIndicesCache();
2670 inline FixedArray* GetEnumIndicesCache();
2672 inline Object** GetEnumCacheSlot();
2674 void ClearEnumCache();
2676 // Initialize or change the enum cache,
2677 // using the supplied storage for the small "bridge".
2678 void SetEnumCache(FixedArray* bridge_storage,
2679 FixedArray* new_cache,
2680 Object* new_index_cache);
2682 bool CanHoldValue(int descriptor, Object* value);
2684 // Accessors for fetching instance descriptor at descriptor number.
2685 inline Name* GetKey(int descriptor_number);
2686 inline Object** GetKeySlot(int descriptor_number);
2687 inline Object* GetValue(int descriptor_number);
2688 inline void SetValue(int descriptor_number, Object* value);
2689 inline Object** GetValueSlot(int descriptor_number);
2690 static inline int GetValueOffset(int descriptor_number);
2691 inline Object** GetDescriptorStartSlot(int descriptor_number);
2692 inline Object** GetDescriptorEndSlot(int descriptor_number);
2693 inline PropertyDetails GetDetails(int descriptor_number);
2694 inline PropertyType GetType(int descriptor_number);
2695 inline int GetFieldIndex(int descriptor_number);
2696 inline HeapType* GetFieldType(int descriptor_number);
2697 inline Object* GetConstant(int descriptor_number);
2698 inline Object* GetCallbacksObject(int descriptor_number);
2699 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2701 inline Name* GetSortedKey(int descriptor_number);
2702 inline int GetSortedKeyIndex(int descriptor_number);
2703 inline void SetSortedKey(int pointer, int descriptor_number);
2704 inline void SetRepresentation(int descriptor_number,
2705 Representation representation);
2707 // Accessor for complete descriptor.
2708 inline void Get(int descriptor_number, Descriptor* desc);
2709 inline void Set(int descriptor_number, Descriptor* desc);
2710 void Replace(int descriptor_number, Descriptor* descriptor);
2712 // Append automatically sets the enumeration index. This should only be used
2713 // to add descriptors in bulk at the end, followed by sorting the descriptor
2715 inline void Append(Descriptor* desc);
2717 static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc,
2718 int enumeration_index,
2721 static Handle<DescriptorArray> CopyUpToAddAttributes(
2722 Handle<DescriptorArray> desc,
2723 int enumeration_index,
2724 PropertyAttributes attributes,
2727 // Sort the instance descriptors by the hash codes of their keys.
2730 // Search the instance descriptors for given name.
2731 INLINE(int Search(Name* name, int number_of_own_descriptors));
2733 // As the above, but uses DescriptorLookupCache and updates it when
2735 INLINE(int SearchWithCache(Name* name, Map* map));
2737 // Allocates a DescriptorArray, but returns the singleton
2738 // empty descriptor array object if number_of_descriptors is 0.
2739 static Handle<DescriptorArray> Allocate(Isolate* isolate,
2740 int number_of_descriptors,
2743 DECLARE_CAST(DescriptorArray)
2745 // Constant for denoting key was not found.
2746 static const int kNotFound = -1;
2748 static const int kDescriptorLengthIndex = 0;
2749 static const int kEnumCacheIndex = 1;
2750 static const int kFirstIndex = 2;
2752 // The length of the "bridge" to the enum cache.
2753 static const int kEnumCacheBridgeLength = 2;
2754 static const int kEnumCacheBridgeCacheIndex = 0;
2755 static const int kEnumCacheBridgeIndicesCacheIndex = 1;
2757 // Layout description.
2758 static const int kDescriptorLengthOffset = FixedArray::kHeaderSize;
2759 static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize;
2760 static const int kFirstOffset = kEnumCacheOffset + kPointerSize;
2762 // Layout description for the bridge array.
2763 static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
2765 // Layout of descriptor.
2766 static const int kDescriptorKey = 0;
2767 static const int kDescriptorDetails = 1;
2768 static const int kDescriptorValue = 2;
2769 static const int kDescriptorSize = 3;
2771 #if defined(DEBUG) || defined(OBJECT_PRINT)
2772 // For our gdb macros, we should perhaps change these in the future.
2775 // Print all the descriptors.
2776 void PrintDescriptors(std::ostream& os); // NOLINT
2780 // Is the descriptor array sorted and without duplicates?
2781 bool IsSortedNoDuplicates(int valid_descriptors = -1);
2783 // Is the descriptor array consistent with the back pointers in targets?
2784 bool IsConsistentWithBackPointers(Map* current_map);
2786 // Are two DescriptorArrays equal?
2787 bool IsEqualTo(DescriptorArray* other);
2790 // Returns the fixed array length required to hold number_of_descriptors
2792 static int LengthFor(int number_of_descriptors) {
2793 return ToKeyIndex(number_of_descriptors);
2797 // WhitenessWitness is used to prove that a descriptor array is white
2798 // (unmarked), so incremental write barriers can be skipped because the
2799 // marking invariant cannot be broken and slots pointing into evacuation
2800 // candidates will be discovered when the object is scanned. A witness is
2801 // always stack-allocated right after creating an array. By allocating a
2802 // witness, incremental marking is globally disabled. The witness is then
2803 // passed along wherever needed to statically prove that the array is known to
2805 class WhitenessWitness {
2807 inline explicit WhitenessWitness(DescriptorArray* array);
2808 inline ~WhitenessWitness();
2811 IncrementalMarking* marking_;
2814 // An entry in a DescriptorArray, represented as an (array, index) pair.
2817 inline explicit Entry(DescriptorArray* descs, int index) :
2818 descs_(descs), index_(index) { }
2820 inline PropertyType type();
2821 inline Object* GetCallbackObject();
2824 DescriptorArray* descs_;
2828 // Conversion from descriptor number to array indices.
2829 static int ToKeyIndex(int descriptor_number) {
2830 return kFirstIndex +
2831 (descriptor_number * kDescriptorSize) +
2835 static int ToDetailsIndex(int descriptor_number) {
2836 return kFirstIndex +
2837 (descriptor_number * kDescriptorSize) +
2841 static int ToValueIndex(int descriptor_number) {
2842 return kFirstIndex +
2843 (descriptor_number * kDescriptorSize) +
2847 // Transfer a complete descriptor from the src descriptor array to this
2848 // descriptor array.
2849 void CopyFrom(int index, DescriptorArray* src, const WhitenessWitness&);
2851 inline void Set(int descriptor_number,
2853 const WhitenessWitness&);
2855 // Swap first and second descriptor.
2856 inline void SwapSortedKeys(int first, int second);
2858 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2862 enum SearchMode { ALL_ENTRIES, VALID_ENTRIES };
2864 template <SearchMode search_mode, typename T>
2865 inline int Search(T* array, Name* name, int valid_entries = 0,
2866 int* out_insertion_index = NULL);
2869 // HashTable is a subclass of FixedArray that implements a hash table
2870 // that uses open addressing and quadratic probing.
2872 // In order for the quadratic probing to work, elements that have not
2873 // yet been used and elements that have been deleted are
2874 // distinguished. Probing continues when deleted elements are
2875 // encountered and stops when unused elements are encountered.
2877 // - Elements with key == undefined have not been used yet.
2878 // - Elements with key == the_hole have been deleted.
2880 // The hash table class is parameterized with a Shape and a Key.
2881 // Shape must be a class with the following interface:
2882 // class ExampleShape {
2884 // // Tells whether key matches other.
2885 // static bool IsMatch(Key key, Object* other);
2886 // // Returns the hash value for key.
2887 // static uint32_t Hash(Key key);
2888 // // Returns the hash value for object.
2889 // static uint32_t HashForObject(Key key, Object* object);
2890 // // Convert key to an object.
2891 // static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
2892 // // The prefix size indicates number of elements in the beginning
2893 // // of the backing storage.
2894 // static const int kPrefixSize = ..;
2895 // // The Element size indicates number of elements per entry.
2896 // static const int kEntrySize = ..;
2898 // The prefix size indicates an amount of memory in the
2899 // beginning of the backing storage that can be used for non-element
2900 // information by subclasses.
2902 template<typename Key>
2905 static const bool UsesSeed = false;
2906 static uint32_t Hash(Key key) { return 0; }
2907 static uint32_t SeededHash(Key key, uint32_t seed) {
2911 static uint32_t HashForObject(Key key, Object* object) { return 0; }
2912 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
2914 return HashForObject(key, object);
2919 class HashTableBase : public FixedArray {
2921 // Returns the number of elements in the hash table.
2922 inline int NumberOfElements();
2924 // Returns the number of deleted elements in the hash table.
2925 inline int NumberOfDeletedElements();
2927 // Returns the capacity of the hash table.
2928 inline int Capacity();
2930 // ElementAdded should be called whenever an element is added to a
2932 inline void ElementAdded();
2934 // ElementRemoved should be called whenever an element is removed from
2936 inline void ElementRemoved();
2937 inline void ElementsRemoved(int n);
2939 // Computes the required capacity for a table holding the given
2940 // number of elements. May be more than HashTable::kMaxCapacity.
2941 static inline int ComputeCapacity(int at_least_space_for);
2943 // Tells whether k is a real key. The hole and undefined are not allowed
2944 // as keys and can be used to indicate missing or deleted elements.
2945 inline bool IsKey(Object* k);
2947 // Compute the probe offset (quadratic probing).
2948 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2949 return (n + n * n) >> 1;
2952 static const int kNumberOfElementsIndex = 0;
2953 static const int kNumberOfDeletedElementsIndex = 1;
2954 static const int kCapacityIndex = 2;
2955 static const int kPrefixStartIndex = 3;
2957 // Constant used for denoting a absent entry.
2958 static const int kNotFound = -1;
2961 // Update the number of elements in the hash table.
2962 inline void SetNumberOfElements(int nof);
2964 // Update the number of deleted elements in the hash table.
2965 inline void SetNumberOfDeletedElements(int nod);
2967 // Returns probe entry.
2968 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2969 DCHECK(base::bits::IsPowerOfTwo32(size));
2970 return (hash + GetProbeOffset(number)) & (size - 1);
2973 inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2974 return hash & (size - 1);
2977 inline static uint32_t NextProbe(
2978 uint32_t last, uint32_t number, uint32_t size) {
2979 return (last + number) & (size - 1);
2984 template <typename Derived, typename Shape, typename Key>
2985 class HashTable : public HashTableBase {
2988 inline uint32_t Hash(Key key) {
2989 if (Shape::UsesSeed) {
2990 return Shape::SeededHash(key, GetHeap()->HashSeed());
2992 return Shape::Hash(key);
2996 inline uint32_t HashForObject(Key key, Object* object) {
2997 if (Shape::UsesSeed) {
2998 return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object);
3000 return Shape::HashForObject(key, object);
3004 // Returns a new HashTable object.
3005 MUST_USE_RESULT static Handle<Derived> New(
3006 Isolate* isolate, int at_least_space_for,
3007 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
3008 PretenureFlag pretenure = NOT_TENURED);
3010 DECLARE_CAST(HashTable)
3012 // Garbage collection support.
3013 void IteratePrefix(ObjectVisitor* visitor);
3014 void IterateElements(ObjectVisitor* visitor);
3016 // Find entry for key otherwise return kNotFound.
3017 inline int FindEntry(Key key);
3018 inline int FindEntry(Isolate* isolate, Key key, int32_t hash);
3019 int FindEntry(Isolate* isolate, Key key);
3021 // Rehashes the table in-place.
3022 void Rehash(Key key);
3024 // Returns the key at entry.
3025 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3027 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
3028 static const int kEntrySize = Shape::kEntrySize;
3029 static const int kElementsStartOffset =
3030 kHeaderSize + kElementsStartIndex * kPointerSize;
3031 static const int kCapacityOffset =
3032 kHeaderSize + kCapacityIndex * kPointerSize;
3034 // Returns the index for an entry (of the key)
3035 static inline int EntryToIndex(int entry) {
3036 return (entry * kEntrySize) + kElementsStartIndex;
3040 friend class ObjectHashTable;
3042 // Find the entry at which to insert element with the given key that
3043 // has the given hash value.
3044 uint32_t FindInsertionEntry(uint32_t hash);
3046 // Attempt to shrink hash table after removal of key.
3047 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key);
3049 // Ensure enough space for n additional elements.
3050 MUST_USE_RESULT static Handle<Derived> EnsureCapacity(
3051 Handle<Derived> table,
3054 PretenureFlag pretenure = NOT_TENURED);
3056 // Sets the capacity of the hash table.
3057 void SetCapacity(int capacity) {
3058 // To scale a computed hash code to fit within the hash table, we
3059 // use bit-wise AND with a mask, so the capacity must be positive
3061 DCHECK(capacity > 0);
3062 DCHECK(capacity <= kMaxCapacity);
3063 set(kCapacityIndex, Smi::FromInt(capacity));
3066 // Maximal capacity of HashTable. Based on maximal length of underlying
3067 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
3069 static const int kMaxCapacity =
3070 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
3073 // Returns _expected_ if one of entries given by the first _probe_ probes is
3074 // equal to _expected_. Otherwise, returns the entry given by the probe
3076 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
3078 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
3080 // Rehashes this hash-table into the new table.
3081 void Rehash(Handle<Derived> new_table, Key key);
3085 // HashTableKey is an abstract superclass for virtual key behavior.
3086 class HashTableKey {
3088 // Returns whether the other object matches this key.
3089 virtual bool IsMatch(Object* other) = 0;
3090 // Returns the hash value for this key.
3091 virtual uint32_t Hash() = 0;
3092 // Returns the hash value for object.
3093 virtual uint32_t HashForObject(Object* key) = 0;
3094 // Returns the key object for storing into the hash table.
3095 MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0;
3097 virtual ~HashTableKey() {}
3101 class StringTableShape : public BaseShape<HashTableKey*> {
3103 static inline bool IsMatch(HashTableKey* key, Object* value) {
3104 return key->IsMatch(value);
3107 static inline uint32_t Hash(HashTableKey* key) {
3111 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
3112 return key->HashForObject(object);
3115 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
3117 static const int kPrefixSize = 0;
3118 static const int kEntrySize = 1;
3121 class SeqOneByteString;
3125 // No special elements in the prefix and the element size is 1
3126 // because only the string itself (the key) needs to be stored.
3127 class StringTable: public HashTable<StringTable,
3131 // Find string in the string table. If it is not there yet, it is
3132 // added. The return value is the string found.
3133 static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
3134 static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
3135 static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key);
3137 // Tries to internalize given string and returns string handle on success
3138 // or an empty handle otherwise.
3139 MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
3141 Handle<String> string);
3143 // Looks up a string that is equal to the given string and returns
3144 // string handle if it is found, or an empty handle otherwise.
3145 MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
3147 Handle<String> str);
3148 MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
3153 static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
3155 DECLARE_CAST(StringTable)
3158 template <bool seq_one_byte>
3159 friend class JsonParser;
3161 DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable);
3165 template <typename Derived, typename Shape, typename Key>
3166 class Dictionary: public HashTable<Derived, Shape, Key> {
3167 typedef HashTable<Derived, Shape, Key> DerivedHashTable;
3170 // Returns the value at entry.
3171 Object* ValueAt(int entry) {
3172 return this->get(Derived::EntryToIndex(entry) + 1);
3175 // Set the value for entry.
3176 void ValueAtPut(int entry, Object* value) {
3177 this->set(Derived::EntryToIndex(entry) + 1, value);
3180 // Returns the property details for the property at entry.
3181 PropertyDetails DetailsAt(int entry) {
3182 return Shape::DetailsAt(static_cast<Derived*>(this), entry);
3185 // Set the details for entry.
3186 void DetailsAtPut(int entry, PropertyDetails value) {
3187 Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value);
3190 // Returns true if property at given entry is deleted.
3191 bool IsDeleted(int entry) {
3192 return Shape::IsDeleted(static_cast<Derived*>(this), entry);
3195 // Delete a property from the dictionary.
3196 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry);
3198 // Attempt to shrink the dictionary after deletion of key.
3199 MUST_USE_RESULT static inline Handle<Derived> Shrink(
3200 Handle<Derived> dictionary,
3202 return DerivedHashTable::Shrink(dictionary, key);
3206 // TODO(dcarney): templatize or move to SeededNumberDictionary
3207 void CopyValuesTo(FixedArray* elements);
3209 // Returns the number of elements in the dictionary filtering out properties
3210 // with the specified attributes.
3211 int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3213 // Returns the number of enumerable elements in the dictionary.
3214 int NumberOfEnumElements() {
3215 return NumberOfElementsFilterAttributes(
3216 static_cast<PropertyAttributes>(DONT_ENUM | SYMBOLIC));
3219 // Returns true if the dictionary contains any elements that are non-writable,
3220 // non-configurable, non-enumerable, or have getters/setters.
3221 bool HasComplexElements();
3223 enum SortMode { UNSORTED, SORTED };
3225 // Fill in details for properties into storage.
3226 // Returns the number of properties added.
3227 int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter,
3228 SortMode sort_mode);
3230 // Copies enumerable keys to preallocated fixed array.
3231 void CopyEnumKeysTo(FixedArray* storage);
3233 // Accessors for next enumeration index.
3234 void SetNextEnumerationIndex(int index) {
3236 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
3239 int NextEnumerationIndex() {
3240 return Smi::cast(this->get(kNextEnumerationIndexIndex))->value();
3243 // Creates a new dictionary.
3244 MUST_USE_RESULT static Handle<Derived> New(
3246 int at_least_space_for,
3247 PretenureFlag pretenure = NOT_TENURED);
3249 // Ensure enough space for n additional elements.
3250 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key);
3253 void Print(std::ostream& os); // NOLINT
3255 // Returns the key (slow).
3256 Object* SlowReverseLookup(Object* value);
3258 // Sets the entry to (key, value) pair.
3259 inline void SetEntry(int entry,
3261 Handle<Object> value);
3262 inline void SetEntry(int entry,
3264 Handle<Object> value,
3265 PropertyDetails details);
3267 MUST_USE_RESULT static Handle<Derived> Add(
3268 Handle<Derived> dictionary,
3270 Handle<Object> value,
3271 PropertyDetails details);
3273 // Returns iteration indices array for the |dictionary|.
3274 // Values are direct indices in the |HashTable| array.
3275 static Handle<FixedArray> BuildIterationIndicesArray(
3276 Handle<Derived> dictionary);
3279 // Generic at put operation.
3280 MUST_USE_RESULT static Handle<Derived> AtPut(
3281 Handle<Derived> dictionary,
3283 Handle<Object> value);
3285 // Add entry to dictionary.
3286 static void AddEntry(
3287 Handle<Derived> dictionary,
3289 Handle<Object> value,
3290 PropertyDetails details,
3293 // Generate new enumeration indices to avoid enumeration index overflow.
3294 // Returns iteration indices array for the |dictionary|.
3295 static Handle<FixedArray> GenerateNewEnumerationIndices(
3296 Handle<Derived> dictionary);
3297 static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
3298 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3302 template <typename Derived, typename Shape>
3303 class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > {
3304 typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary;
3307 // Find entry for key, otherwise return kNotFound. Optimized version of
3308 // HashTable::FindEntry.
3309 int FindEntry(Handle<Name> key);
3313 template <typename Key>
3314 class BaseDictionaryShape : public BaseShape<Key> {
3316 template <typename Dictionary>
3317 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) {
3318 STATIC_ASSERT(Dictionary::kEntrySize == 3);
3319 DCHECK(entry >= 0); // Not found is -1, which is not caught by get().
3320 return PropertyDetails(
3321 Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2)));
3324 template <typename Dictionary>
3325 static inline void DetailsAtPut(Dictionary* dict, int entry,
3326 PropertyDetails value) {
3327 STATIC_ASSERT(Dictionary::kEntrySize == 3);
3328 dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi());
3331 template <typename Dictionary>
3332 static bool IsDeleted(Dictionary* dict, int entry) {
3336 template <typename Dictionary>
3337 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
3338 Handle<Object> value, PropertyDetails details);
3342 class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > {
3344 static inline bool IsMatch(Handle<Name> key, Object* other);
3345 static inline uint32_t Hash(Handle<Name> key);
3346 static inline uint32_t HashForObject(Handle<Name> key, Object* object);
3347 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
3348 static const int kPrefixSize = 2;
3349 static const int kEntrySize = 3;
3350 static const bool kIsEnumerable = true;
3354 class NameDictionary
3355 : public NameDictionaryBase<NameDictionary, NameDictionaryShape> {
3356 typedef NameDictionaryBase<NameDictionary, NameDictionaryShape>
3360 DECLARE_CAST(NameDictionary)
3362 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices(
3363 Handle<NameDictionary> dictionary);
3367 class GlobalDictionaryShape : public NameDictionaryShape {
3369 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize
3371 template <typename Dictionary>
3372 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry);
3374 template <typename Dictionary>
3375 static inline void DetailsAtPut(Dictionary* dict, int entry,
3376 PropertyDetails value);
3378 template <typename Dictionary>
3379 static bool IsDeleted(Dictionary* dict, int entry);
3381 template <typename Dictionary>
3382 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
3383 Handle<Object> value, PropertyDetails details);
3387 class GlobalDictionary
3388 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> {
3390 DECLARE_CAST(GlobalDictionary)
3394 class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> {
3396 static inline bool IsMatch(uint32_t key, Object* other);
3397 static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key);
3398 static const int kEntrySize = 3;
3399 static const bool kIsEnumerable = false;
3403 class SeededNumberDictionaryShape : public NumberDictionaryShape {
3405 static const bool UsesSeed = true;
3406 static const int kPrefixSize = 2;
3408 static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3409 static inline uint32_t SeededHashForObject(uint32_t key,
3415 class UnseededNumberDictionaryShape : public NumberDictionaryShape {
3417 static const int kPrefixSize = 0;
3419 static inline uint32_t Hash(uint32_t key);
3420 static inline uint32_t HashForObject(uint32_t key, Object* object);
3424 class SeededNumberDictionary
3425 : public Dictionary<SeededNumberDictionary,
3426 SeededNumberDictionaryShape,
3429 DECLARE_CAST(SeededNumberDictionary)
3431 // Type specific at put (default NONE attributes is used when adding).
3432 MUST_USE_RESULT static Handle<SeededNumberDictionary> AtNumberPut(
3433 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3434 Handle<Object> value, bool used_as_prototype);
3435 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry(
3436 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3437 Handle<Object> value, PropertyDetails details, bool used_as_prototype);
3439 // Set an existing entry or add a new one if needed.
3440 // Return the updated dictionary.
3441 MUST_USE_RESULT static Handle<SeededNumberDictionary> Set(
3442 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3443 Handle<Object> value, PropertyDetails details, bool used_as_prototype);
3445 void UpdateMaxNumberKey(uint32_t key, bool used_as_prototype);
3447 // If slow elements are required we will never go back to fast-case
3448 // for the elements kept in this dictionary. We require slow
3449 // elements if an element has been added at an index larger than
3450 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3451 // when defining a getter or setter with a number key.
3452 inline bool requires_slow_elements();
3453 inline void set_requires_slow_elements();
3455 // Get the value of the max number key that has been added to this
3456 // dictionary. max_number_key can only be called if
3457 // requires_slow_elements returns false.
3458 inline uint32_t max_number_key();
3461 static const int kRequiresSlowElementsMask = 1;
3462 static const int kRequiresSlowElementsTagSize = 1;
3463 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
3467 class UnseededNumberDictionary
3468 : public Dictionary<UnseededNumberDictionary,
3469 UnseededNumberDictionaryShape,
3472 DECLARE_CAST(UnseededNumberDictionary)
3474 // Type specific at put (default NONE attributes is used when adding).
3475 MUST_USE_RESULT static Handle<UnseededNumberDictionary> AtNumberPut(
3476 Handle<UnseededNumberDictionary> dictionary,
3478 Handle<Object> value);
3479 MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry(
3480 Handle<UnseededNumberDictionary> dictionary,
3482 Handle<Object> value);
3484 // Set an existing entry or add a new one if needed.
3485 // Return the updated dictionary.
3486 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
3487 Handle<UnseededNumberDictionary> dictionary,
3489 Handle<Object> value);
3493 class ObjectHashTableShape : public BaseShape<Handle<Object> > {
3495 static inline bool IsMatch(Handle<Object> key, Object* other);
3496 static inline uint32_t Hash(Handle<Object> key);
3497 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
3498 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
3499 static const int kPrefixSize = 0;
3500 static const int kEntrySize = 2;
3504 // ObjectHashTable maps keys that are arbitrary objects to object values by
3505 // using the identity hash of the key for hashing purposes.
3506 class ObjectHashTable: public HashTable<ObjectHashTable,
3507 ObjectHashTableShape,
3510 ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable;
3512 DECLARE_CAST(ObjectHashTable)
3514 // Attempt to shrink hash table after removal of key.
3515 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink(
3516 Handle<ObjectHashTable> table,
3517 Handle<Object> key);
3519 // Looks up the value associated with the given key. The hole value is
3520 // returned in case the key is not present.
3521 Object* Lookup(Handle<Object> key);
3522 Object* Lookup(Handle<Object> key, int32_t hash);
3523 Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash);
3525 // Adds (or overwrites) the value associated with the given key.
3526 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
3528 Handle<Object> value);
3529 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
3530 Handle<Object> key, Handle<Object> value,
3533 // Returns an ObjectHashTable (possibly |table|) where |key| has been removed.
3534 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table,
3537 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table,
3538 Handle<Object> key, bool* was_present,
3542 friend class MarkCompactCollector;
3544 void AddEntry(int entry, Object* key, Object* value);
3545 void RemoveEntry(int entry);
3547 // Returns the index to the value of an entry.
3548 static inline int EntryToValueIndex(int entry) {
3549 return EntryToIndex(entry) + 1;
3554 // OrderedHashTable is a HashTable with Object keys that preserves
3555 // insertion order. There are Map and Set interfaces (OrderedHashMap
3556 // and OrderedHashTable, below). It is meant to be used by JSMap/JSSet.
3558 // Only Object* keys are supported, with Object::SameValueZero() used as the
3559 // equality operator and Object::GetHash() for the hash function.
3561 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at
3562 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables
3563 // Originally attributed to Tyler Close.
3566 // [0]: bucket count
3567 // [1]: element count
3568 // [2]: deleted element count
3569 // [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an
3570 // offset into the data table (see below) where the
3571 // first item in this bucket is stored.
3572 // [3 + NumberOfBuckets()..length]: "data table", an array of length
3573 // Capacity() * kEntrySize, where the first entrysize
3574 // items are handled by the derived class and the
3575 // item at kChainOffset is another entry into the
3576 // data table indicating the next entry in this hash
3579 // When we transition the table to a new version we obsolete it and reuse parts
3580 // of the memory to store information how to transition an iterator to the new
3583 // Memory layout for obsolete table:
3584 // [0]: bucket count
3585 // [1]: Next newer table
3586 // [2]: Number of removed holes or -1 when the table was cleared.
3587 // [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes.
3588 // [3 + NumberOfRemovedHoles()..length]: Not used
3590 template<class Derived, class Iterator, int entrysize>
3591 class OrderedHashTable: public FixedArray {
3593 // Returns an OrderedHashTable with a capacity of at least |capacity|.
3594 static Handle<Derived> Allocate(
3595 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED);
3597 // Returns an OrderedHashTable (possibly |table|) with enough space
3598 // to add at least one new element.
3599 static Handle<Derived> EnsureGrowable(Handle<Derived> table);
3601 // Returns an OrderedHashTable (possibly |table|) that's shrunken
3603 static Handle<Derived> Shrink(Handle<Derived> table);
3605 // Returns a new empty OrderedHashTable and records the clearing so that
3606 // exisiting iterators can be updated.
3607 static Handle<Derived> Clear(Handle<Derived> table);
3609 int NumberOfElements() {
3610 return Smi::cast(get(kNumberOfElementsIndex))->value();
3613 int NumberOfDeletedElements() {
3614 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
3617 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); }
3619 int NumberOfBuckets() {
3620 return Smi::cast(get(kNumberOfBucketsIndex))->value();
3623 // Returns an index into |this| for the given entry.
3624 int EntryToIndex(int entry) {
3625 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize);
3628 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3631 return !get(kNextTableIndex)->IsSmi();
3634 // The next newer table. This is only valid if the table is obsolete.
3635 Derived* NextTable() {
3636 return Derived::cast(get(kNextTableIndex));
3639 // When the table is obsolete we store the indexes of the removed holes.
3640 int RemovedIndexAt(int index) {
3641 return Smi::cast(get(kRemovedHolesIndex + index))->value();
3644 static const int kNotFound = -1;
3645 static const int kMinCapacity = 4;
3647 static const int kNumberOfBucketsIndex = 0;
3648 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1;
3649 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
3650 static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1;
3651 static const int kNextTableIndex = kNumberOfElementsIndex;
3653 static const int kNumberOfBucketsOffset =
3654 kHeaderSize + kNumberOfBucketsIndex * kPointerSize;
3655 static const int kNumberOfElementsOffset =
3656 kHeaderSize + kNumberOfElementsIndex * kPointerSize;
3657 static const int kNumberOfDeletedElementsOffset =
3658 kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize;
3659 static const int kHashTableStartOffset =
3660 kHeaderSize + kHashTableStartIndex * kPointerSize;
3661 static const int kNextTableOffset =
3662 kHeaderSize + kNextTableIndex * kPointerSize;
3664 static const int kEntrySize = entrysize + 1;
3665 static const int kChainOffset = entrysize;
3667 static const int kLoadFactor = 2;
3669 // NumberOfDeletedElements is set to kClearedTableSentinel when
3670 // the table is cleared, which allows iterator transitions to
3671 // optimize that case.
3672 static const int kClearedTableSentinel = -1;
3675 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity);
3677 void SetNumberOfBuckets(int num) {
3678 set(kNumberOfBucketsIndex, Smi::FromInt(num));
3681 void SetNumberOfElements(int num) {
3682 set(kNumberOfElementsIndex, Smi::FromInt(num));
3685 void SetNumberOfDeletedElements(int num) {
3686 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num));
3690 return NumberOfBuckets() * kLoadFactor;
3693 void SetNextTable(Derived* next_table) {
3694 set(kNextTableIndex, next_table);
3697 void SetRemovedIndexAt(int index, int removed_index) {
3698 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index));
3701 static const int kRemovedHolesIndex = kHashTableStartIndex;
3703 static const int kMaxCapacity =
3704 (FixedArray::kMaxLength - kHashTableStartIndex)
3705 / (1 + (kEntrySize * kLoadFactor));
3709 class JSSetIterator;
3712 class OrderedHashSet: public OrderedHashTable<
3713 OrderedHashSet, JSSetIterator, 1> {
3715 DECLARE_CAST(OrderedHashSet)
3719 class JSMapIterator;
3722 class OrderedHashMap
3723 : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> {
3725 DECLARE_CAST(OrderedHashMap)
3727 inline Object* ValueAt(int entry);
3729 static const int kValueOffset = 1;
3733 template <int entrysize>
3734 class WeakHashTableShape : public BaseShape<Handle<Object> > {
3736 static inline bool IsMatch(Handle<Object> key, Object* other);
3737 static inline uint32_t Hash(Handle<Object> key);
3738 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
3739 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
3740 static const int kPrefixSize = 0;
3741 static const int kEntrySize = entrysize;
3745 // WeakHashTable maps keys that are arbitrary heap objects to heap object
3746 // values. The table wraps the keys in weak cells and store values directly.
3747 // Thus it references keys weakly and values strongly.
3748 class WeakHashTable: public HashTable<WeakHashTable,
3749 WeakHashTableShape<2>,
3752 WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable;
3754 DECLARE_CAST(WeakHashTable)
3756 // Looks up the value associated with the given key. The hole value is
3757 // returned in case the key is not present.
3758 Object* Lookup(Handle<HeapObject> key);
3760 // Adds (or overwrites) the value associated with the given key. Mapping a
3761 // key to the hole value causes removal of the whole entry.
3762 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table,
3763 Handle<HeapObject> key,
3764 Handle<HeapObject> value);
3766 static Handle<FixedArray> GetValues(Handle<WeakHashTable> table);
3769 friend class MarkCompactCollector;
3771 void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value);
3773 // Returns the index to the value of an entry.
3774 static inline int EntryToValueIndex(int entry) {
3775 return EntryToIndex(entry) + 1;
3780 // ScopeInfo represents information about different scopes of a source
3781 // program and the allocation of the scope's variables. Scope information
3782 // is stored in a compressed form in ScopeInfo objects and is used
3783 // at runtime (stack dumps, deoptimization, etc.).
3785 // This object provides quick access to scope info details for runtime
3787 class ScopeInfo : public FixedArray {
3789 DECLARE_CAST(ScopeInfo)
3791 // Return the type of this scope.
3792 ScopeType scope_type();
3794 // Does this scope call eval?
3797 // Return the language mode of this scope.
3798 LanguageMode language_mode();
3800 // True if this scope is a (var) declaration scope.
3801 bool is_declaration_scope();
3803 // Does this scope make a sloppy eval call?
3804 bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); }
3806 // Return the total number of locals allocated on the stack and in the
3807 // context. This includes the parameters that are allocated in the context.
3810 // Return the number of stack slots for code. This number consists of two
3812 // 1. One stack slot per stack allocated local.
3813 // 2. One stack slot for the function name if it is stack allocated.
3814 int StackSlotCount();
3816 // Return the number of context slots for code if a context is allocated. This
3817 // number consists of three parts:
3818 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3819 // 2. One context slot per context allocated local.
3820 // 3. One context slot for the function name if it is context allocated.
3821 // Parameters allocated in the context count as context allocated locals. If
3822 // no contexts are allocated for this scope ContextLength returns 0.
3823 int ContextLength();
3825 // Does this scope declare a "this" binding?
3828 // Does this scope declare a "this" binding, and the "this" binding is stack-
3829 // or context-allocated?
3830 bool HasAllocatedReceiver();
3832 // Is this scope the scope of a named function expression?
3833 bool HasFunctionName();
3835 // Return if this has context allocated locals.
3836 bool HasHeapAllocatedLocals();
3838 // Return if contexts are allocated for this scope.
3841 // Return if this is a function scope with "use asm".
3842 inline bool IsAsmModule();
3844 // Return if this is a nested function within an asm module scope.
3845 inline bool IsAsmFunction();
3847 inline bool HasSimpleParameters();
3849 // Return the function_name if present.
3850 String* FunctionName();
3852 // Return the name of the given parameter.
3853 String* ParameterName(int var);
3855 // Return the name of the given local.
3856 String* LocalName(int var);
3858 // Return the name of the given stack local.
3859 String* StackLocalName(int var);
3861 // Return the name of the given stack local.
3862 int StackLocalIndex(int var);
3864 // Return the name of the given context local.
3865 String* ContextLocalName(int var);
3867 // Return the mode of the given context local.
3868 VariableMode ContextLocalMode(int var);
3870 // Return the initialization flag of the given context local.
3871 InitializationFlag ContextLocalInitFlag(int var);
3873 // Return the initialization flag of the given context local.
3874 MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var);
3876 // Return true if this local was introduced by the compiler, and should not be
3877 // exposed to the user in a debugger.
3878 bool LocalIsSynthetic(int var);
3880 String* StrongModeFreeVariableName(int var);
3881 int StrongModeFreeVariableStartPosition(int var);
3882 int StrongModeFreeVariableEndPosition(int var);
3884 // Lookup support for serialized scope info. Returns the
3885 // the stack slot index for a given slot name if the slot is
3886 // present; otherwise returns a value < 0. The name must be an internalized
3888 int StackSlotIndex(String* name);
3890 // Lookup support for serialized scope info. Returns the
3891 // context slot index for a given slot name if the slot is present; otherwise
3892 // returns a value < 0. The name must be an internalized string.
3893 // If the slot is present and mode != NULL, sets *mode to the corresponding
3894 // mode for that variable.
3895 static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name,
3896 VariableMode* mode, VariableLocation* location,
3897 InitializationFlag* init_flag,
3898 MaybeAssignedFlag* maybe_assigned_flag);
3900 // Lookup the name of a certain context slot by its index.
3901 String* ContextSlotName(int slot_index);
3903 // Lookup support for serialized scope info. Returns the
3904 // parameter index for a given parameter name if the parameter is present;
3905 // otherwise returns a value < 0. The name must be an internalized string.
3906 int ParameterIndex(String* name);
3908 // Lookup support for serialized scope info. Returns the function context
3909 // slot index if the function name is present and context-allocated (named
3910 // function expressions, only), otherwise returns a value < 0. The name
3911 // must be an internalized string.
3912 int FunctionContextSlotIndex(String* name, VariableMode* mode);
3914 // Lookup support for serialized scope info. Returns the receiver context
3915 // slot index if scope has a "this" binding, and the binding is
3916 // context-allocated. Otherwise returns a value < 0.
3917 int ReceiverContextSlotIndex();
3919 FunctionKind function_kind();
3921 static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope);
3922 static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate);
3924 // Serializes empty scope info.
3925 static ScopeInfo* Empty(Isolate* isolate);
3931 // The layout of the static part of a ScopeInfo is as follows. Each entry is
3932 // numeric and occupies one array slot.
3933 // 1. A set of properties of the scope
3934 // 2. The number of parameters. This only applies to function scopes. For
3935 // non-function scopes this is 0.
3936 // 3. The number of non-parameter variables allocated on the stack.
3937 // 4. The number of non-parameter and parameter variables allocated in the
3939 #define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \
3942 V(StackLocalCount) \
3943 V(ContextLocalCount) \
3944 V(ContextGlobalCount) \
3945 V(StrongModeFreeVariableCount)
3947 #define FIELD_ACCESSORS(name) \
3948 inline void Set##name(int value); \
3950 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS)
3951 #undef FIELD_ACCESSORS
3955 #define DECL_INDEX(name) k##name,
3956 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX)
3961 // The layout of the variable part of a ScopeInfo is as follows:
3962 // 1. ParameterEntries:
3963 // This part stores the names of the parameters for function scopes. One
3964 // slot is used per parameter, so in total this part occupies
3965 // ParameterCount() slots in the array. For other scopes than function
3966 // scopes ParameterCount() is 0.
3967 // 2. StackLocalFirstSlot:
3968 // Index of a first stack slot for stack local. Stack locals belonging to
3969 // this scope are located on a stack at slots starting from this index.
3970 // 3. StackLocalEntries:
3971 // Contains the names of local variables that are allocated on the stack,
3972 // in increasing order of the stack slot index. First local variable has
3973 // a stack slot index defined in StackLocalFirstSlot (point 2 above).
3974 // One slot is used per stack local, so in total this part occupies
3975 // StackLocalCount() slots in the array.
3976 // 4. ContextLocalNameEntries:
3977 // Contains the names of local variables and parameters that are allocated
3978 // in the context. They are stored in increasing order of the context slot
3979 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3980 // context local, so in total this part occupies ContextLocalCount() slots
3982 // 5. ContextLocalInfoEntries:
3983 // Contains the variable modes and initialization flags corresponding to
3984 // the context locals in ContextLocalNameEntries. One slot is used per
3985 // context local, so in total this part occupies ContextLocalCount()
3986 // slots in the array.
3987 // 6. StrongModeFreeVariableNameEntries:
3988 // Stores the names of strong mode free variables.
3989 // 7. StrongModeFreeVariablePositionEntries:
3990 // Stores the locations (start and end position) of strong mode free
3992 // 8. RecieverEntryIndex:
3993 // If the scope binds a "this" value, one slot is reserved to hold the
3994 // context or stack slot index for the variable.
3995 // 9. FunctionNameEntryIndex:
3996 // If the scope belongs to a named function expression this part contains
3997 // information about the function variable. It always occupies two array
3998 // slots: a. The name of the function variable.
3999 // b. The context or stack slot index for the variable.
4000 int ParameterEntriesIndex();
4001 int StackLocalFirstSlotIndex();
4002 int StackLocalEntriesIndex();
4003 int ContextLocalNameEntriesIndex();
4004 int ContextGlobalNameEntriesIndex();
4005 int ContextLocalInfoEntriesIndex();
4006 int ContextGlobalInfoEntriesIndex();
4007 int StrongModeFreeVariableNameEntriesIndex();
4008 int StrongModeFreeVariablePositionEntriesIndex();
4009 int ReceiverEntryIndex();
4010 int FunctionNameEntryIndex();
4012 int Lookup(Handle<String> name, int start, int end, VariableMode* mode,
4013 VariableLocation* location, InitializationFlag* init_flag,
4014 MaybeAssignedFlag* maybe_assigned_flag);
4016 // Used for the function name variable for named function expressions, and for
4018 enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED };
4020 // Properties of scopes.
4021 class ScopeTypeField : public BitField<ScopeType, 0, 4> {};
4022 class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {};
4023 STATIC_ASSERT(LANGUAGE_END == 3);
4024 class LanguageModeField
4025 : public BitField<LanguageMode, CallsEvalField::kNext, 2> {};
4026 class DeclarationScopeField
4027 : public BitField<bool, LanguageModeField::kNext, 1> {};
4028 class ReceiverVariableField
4029 : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext,
4031 class FunctionVariableField
4032 : public BitField<VariableAllocationInfo, ReceiverVariableField::kNext,
4034 class FunctionVariableMode
4035 : public BitField<VariableMode, FunctionVariableField::kNext, 3> {};
4036 class AsmModuleField : public BitField<bool, FunctionVariableMode::kNext, 1> {
4038 class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {};
4039 class HasSimpleParametersField
4040 : public BitField<bool, AsmFunctionField::kNext, 1> {};
4041 class FunctionKindField
4042 : public BitField<FunctionKind, HasSimpleParametersField::kNext, 8> {};
4044 // BitFields representing the encoded information for context locals in the
4045 // ContextLocalInfoEntries part.
4046 class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
4047 class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
4048 class ContextLocalMaybeAssignedFlag
4049 : public BitField<MaybeAssignedFlag, 4, 1> {};
4051 friend class ScopeIterator;
4055 // The cache for maps used by normalized (dictionary mode) objects.
4056 // Such maps do not have property descriptors, so a typical program
4057 // needs very limited number of distinct normalized maps.
4058 class NormalizedMapCache: public FixedArray {
4060 static Handle<NormalizedMapCache> New(Isolate* isolate);
4062 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map,
4063 PropertyNormalizationMode mode);
4064 void Set(Handle<Map> fast_map, Handle<Map> normalized_map);
4068 DECLARE_CAST(NormalizedMapCache)
4070 static inline bool IsNormalizedMapCache(const Object* obj);
4072 DECLARE_VERIFIER(NormalizedMapCache)
4074 static const int kEntries = 64;
4076 static inline int GetIndex(Handle<Map> map);
4078 // The following declarations hide base class methods.
4079 Object* get(int index);
4080 void set(int index, Object* value);
4084 // ByteArray represents fixed sized byte arrays. Used for the relocation info
4085 // that is attached to code objects.
4086 class ByteArray: public FixedArrayBase {
4090 // Setter and getter.
4091 inline byte get(int index);
4092 inline void set(int index, byte value);
4094 // Treat contents as an int array.
4095 inline int get_int(int index);
4097 static int SizeFor(int length) {
4098 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
4100 // We use byte arrays for free blocks in the heap. Given a desired size in
4101 // bytes that is a multiple of the word size and big enough to hold a byte
4102 // array, this function returns the number of elements a byte array should
4104 static int LengthFor(int size_in_bytes) {
4105 DCHECK(IsAligned(size_in_bytes, kPointerSize));
4106 DCHECK(size_in_bytes >= kHeaderSize);
4107 return size_in_bytes - kHeaderSize;
4110 // Returns data start address.
4111 inline Address GetDataStartAddress();
4113 // Returns a pointer to the ByteArray object for a given data start address.
4114 static inline ByteArray* FromDataStartAddress(Address address);
4116 DECLARE_CAST(ByteArray)
4118 // Dispatched behavior.
4119 inline int ByteArraySize();
4120 DECLARE_PRINTER(ByteArray)
4121 DECLARE_VERIFIER(ByteArray)
4123 // Layout description.
4124 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4126 // Maximal memory consumption for a single ByteArray.
4127 static const int kMaxSize = 512 * MB;
4128 // Maximal length of a single ByteArray.
4129 static const int kMaxLength = kMaxSize - kHeaderSize;
4132 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
4136 // BytecodeArray represents a sequence of interpreter bytecodes.
4137 class BytecodeArray : public FixedArrayBase {
4139 static int SizeFor(int length) {
4140 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
4143 // Setter and getter
4144 inline byte get(int index);
4145 inline void set(int index, byte value);
4147 // Returns data start address.
4148 inline Address GetFirstBytecodeAddress();
4150 // Accessors for frame size.
4151 inline int frame_size() const;
4152 inline void set_frame_size(int frame_size);
4154 // Accessors for parameter count (including implicit 'this' receiver).
4155 inline int parameter_count() const;
4156 inline void set_parameter_count(int number_of_parameters);
4158 // Accessors for the constant pool.
4159 DECL_ACCESSORS(constant_pool, FixedArray)
4161 DECLARE_CAST(BytecodeArray)
4163 // Dispatched behavior.
4164 inline int BytecodeArraySize();
4165 inline void BytecodeArrayIterateBody(ObjectVisitor* v);
4167 DECLARE_PRINTER(BytecodeArray)
4168 DECLARE_VERIFIER(BytecodeArray)
4170 void Disassemble(std::ostream& os);
4172 // Layout description.
4173 static const int kFrameSizeOffset = FixedArrayBase::kHeaderSize;
4174 static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize;
4175 static const int kConstantPoolOffset = kParameterSizeOffset + kIntSize;
4176 static const int kHeaderSize = kConstantPoolOffset + kPointerSize;
4178 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4180 // Maximal memory consumption for a single BytecodeArray.
4181 static const int kMaxSize = 512 * MB;
4182 // Maximal length of a single BytecodeArray.
4183 static const int kMaxLength = kMaxSize - kHeaderSize;
4186 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray);
4190 // FreeSpace are fixed-size free memory blocks used by the heap and GC.
4191 // They look like heap objects (are heap object tagged and have a map) so that
4192 // the heap remains iterable. They have a size and a next pointer.
4193 // The next pointer is the raw address of the next FreeSpace object (or NULL)
4194 // in the free list.
4195 class FreeSpace: public HeapObject {
4197 // [size]: size of the free space including the header.
4198 inline int size() const;
4199 inline void set_size(int value);
4201 inline int nobarrier_size() const;
4202 inline void nobarrier_set_size(int value);
4206 // Accessors for the next field.
4207 inline FreeSpace* next();
4208 inline FreeSpace** next_address();
4209 inline void set_next(FreeSpace* next);
4211 inline static FreeSpace* cast(HeapObject* obj);
4213 // Dispatched behavior.
4214 DECLARE_PRINTER(FreeSpace)
4215 DECLARE_VERIFIER(FreeSpace)
4217 // Layout description.
4218 // Size is smi tagged when it is stored.
4219 static const int kSizeOffset = HeapObject::kHeaderSize;
4220 static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize);
4223 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
4227 // V has parameters (Type, type, TYPE, C type, element_size)
4228 #define TYPED_ARRAYS(V) \
4229 V(Uint8, uint8, UINT8, uint8_t, 1) \
4230 V(Int8, int8, INT8, int8_t, 1) \
4231 V(Uint16, uint16, UINT16, uint16_t, 2) \
4232 V(Int16, int16, INT16, int16_t, 2) \
4233 V(Uint32, uint32, UINT32, uint32_t, 4) \
4234 V(Int32, int32, INT32, int32_t, 4) \
4235 V(Float32, float32, FLOAT32, float, 4) \
4236 V(Float64, float64, FLOAT64, double, 8) \
4237 V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1)
4240 class FixedTypedArrayBase: public FixedArrayBase {
4242 // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr.
4243 DECL_ACCESSORS(base_pointer, Object)
4245 // [external_pointer]: Contains the offset between base_pointer and the start
4246 // of the data. If the base_pointer is a nullptr, the external_pointer
4247 // therefore points to the actual backing store.
4248 DECL_ACCESSORS(external_pointer, void)
4250 // Dispatched behavior.
4251 inline void FixedTypedArrayBaseIterateBody(ObjectVisitor* v);
4253 template <typename StaticVisitor>
4254 inline void FixedTypedArrayBaseIterateBody();
4256 DECLARE_CAST(FixedTypedArrayBase)
4258 static const int kBasePointerOffset = FixedArrayBase::kHeaderSize;
4259 static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize;
4260 static const int kHeaderSize =
4261 DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize);
4263 static const int kDataOffset = kHeaderSize;
4267 static inline int TypedArraySize(InstanceType type, int length);
4268 inline int TypedArraySize(InstanceType type);
4270 // Use with care: returns raw pointer into heap.
4271 inline void* DataPtr();
4273 inline int DataSize();
4276 static inline int ElementSize(InstanceType type);
4278 inline int DataSize(InstanceType type);
4280 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase);
4284 template <class Traits>
4285 class FixedTypedArray: public FixedTypedArrayBase {
4287 typedef typename Traits::ElementType ElementType;
4288 static const InstanceType kInstanceType = Traits::kInstanceType;
4290 DECLARE_CAST(FixedTypedArray<Traits>)
4292 inline ElementType get_scalar(int index);
4293 static inline Handle<Object> get(Handle<FixedTypedArray> array, int index);
4294 inline void set(int index, ElementType value);
4296 static inline ElementType from_int(int value);
4297 static inline ElementType from_double(double value);
4299 // This accessor applies the correct conversion from Smi, HeapNumber
4301 void SetValue(uint32_t index, Object* value);
4303 DECLARE_PRINTER(FixedTypedArray)
4304 DECLARE_VERIFIER(FixedTypedArray)
4307 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray);
4310 #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \
4311 class Type##ArrayTraits { \
4312 public: /* NOLINT */ \
4313 typedef elementType ElementType; \
4314 static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \
4315 static const char* Designator() { return #type " array"; } \
4316 static inline Handle<Object> ToHandle(Isolate* isolate, \
4317 elementType scalar); \
4318 static inline elementType defaultValue(); \
4321 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array;
4323 TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS)
4325 #undef FIXED_TYPED_ARRAY_TRAITS
4328 // DeoptimizationInputData is a fixed array used to hold the deoptimization
4329 // data for code generated by the Hydrogen/Lithium compiler. It also
4330 // contains information about functions that were inlined. If N different
4331 // functions were inlined then first N elements of the literal array will
4332 // contain these functions.
4335 class DeoptimizationInputData: public FixedArray {
4337 // Layout description. Indices in the array.
4338 static const int kTranslationByteArrayIndex = 0;
4339 static const int kInlinedFunctionCountIndex = 1;
4340 static const int kLiteralArrayIndex = 2;
4341 static const int kOsrAstIdIndex = 3;
4342 static const int kOsrPcOffsetIndex = 4;
4343 static const int kOptimizationIdIndex = 5;
4344 static const int kSharedFunctionInfoIndex = 6;
4345 static const int kWeakCellCacheIndex = 7;
4346 static const int kFirstDeoptEntryIndex = 8;
4348 // Offsets of deopt entry elements relative to the start of the entry.
4349 static const int kAstIdRawOffset = 0;
4350 static const int kTranslationIndexOffset = 1;
4351 static const int kArgumentsStackHeightOffset = 2;
4352 static const int kPcOffset = 3;
4353 static const int kDeoptEntrySize = 4;
4355 // Simple element accessors.
4356 #define DECLARE_ELEMENT_ACCESSORS(name, type) \
4357 inline type* name(); \
4358 inline void Set##name(type* value);
4360 DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4361 DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4362 DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4363 DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4364 DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4365 DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi)
4366 DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object)
4367 DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object)
4369 #undef DECLARE_ELEMENT_ACCESSORS
4371 // Accessors for elements of the ith deoptimization entry.
4372 #define DECLARE_ENTRY_ACCESSORS(name, type) \
4373 inline type* name(int i); \
4374 inline void Set##name(int i, type* value);
4376 DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi)
4377 DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4378 DECLARE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
4379 DECLARE_ENTRY_ACCESSORS(Pc, Smi)
4381 #undef DECLARE_ENTRY_ACCESSORS
4383 inline BailoutId AstId(int i);
4385 inline void SetAstId(int i, BailoutId value);
4387 inline int DeoptCount();
4389 // Allocates a DeoptimizationInputData.
4390 static Handle<DeoptimizationInputData> New(Isolate* isolate,
4391 int deopt_entry_count,
4392 PretenureFlag pretenure);
4394 DECLARE_CAST(DeoptimizationInputData)
4396 #ifdef ENABLE_DISASSEMBLER
4397 void DeoptimizationInputDataPrint(std::ostream& os); // NOLINT
4401 static int IndexForEntry(int i) {
4402 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4406 static int LengthFor(int entry_count) { return IndexForEntry(entry_count); }
4410 // DeoptimizationOutputData is a fixed array used to hold the deoptimization
4411 // data for code generated by the full compiler.
4412 // The format of the these objects is
4413 // [i * 2]: Ast ID for ith deoptimization.
4414 // [i * 2 + 1]: PC and state of ith deoptimization
4415 class DeoptimizationOutputData: public FixedArray {
4417 inline int DeoptPoints();
4419 inline BailoutId AstId(int index);
4421 inline void SetAstId(int index, BailoutId id);
4423 inline Smi* PcAndState(int index);
4424 inline void SetPcAndState(int index, Smi* offset);
4426 static int LengthOfFixedArray(int deopt_points) {
4427 return deopt_points * 2;
4430 // Allocates a DeoptimizationOutputData.
4431 static Handle<DeoptimizationOutputData> New(Isolate* isolate,
4432 int number_of_deopt_points,
4433 PretenureFlag pretenure);
4435 DECLARE_CAST(DeoptimizationOutputData)
4437 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
4438 void DeoptimizationOutputDataPrint(std::ostream& os); // NOLINT
4443 // HandlerTable is a fixed array containing entries for exception handlers in
4444 // the code object it is associated with. The tables comes in two flavors:
4445 // 1) Based on ranges: Used for unoptimized code. Contains one entry per
4446 // exception handler and a range representing the try-block covered by that
4447 // handler. Layout looks as follows:
4448 // [ range-start , range-end , handler-offset , stack-depth ]
4449 // 2) Based on return addresses: Used for turbofanned code. Contains one entry
4450 // per call-site that could throw an exception. Layout looks as follows:
4451 // [ return-address-offset , handler-offset ]
4452 class HandlerTable : public FixedArray {
4454 // Conservative prediction whether a given handler will locally catch an
4455 // exception or cause a re-throw to outside the code boundary. Since this is
4456 // undecidable it is merely an approximation (e.g. useful for debugger).
4457 enum CatchPrediction { UNCAUGHT, CAUGHT };
4459 // Accessors for handler table based on ranges.
4460 inline void SetRangeStart(int index, int value);
4461 inline void SetRangeEnd(int index, int value);
4462 inline void SetRangeHandler(int index, int offset, CatchPrediction pred);
4463 inline void SetRangeDepth(int index, int value);
4465 // Accessors for handler table based on return addresses.
4466 inline void SetReturnOffset(int index, int value);
4467 inline void SetReturnHandler(int index, int offset, CatchPrediction pred);
4469 // Lookup handler in a table based on ranges.
4470 int LookupRange(int pc_offset, int* stack_depth, CatchPrediction* prediction);
4472 // Lookup handler in a table based on return addresses.
4473 int LookupReturn(int pc_offset, CatchPrediction* prediction);
4475 // Returns the required length of the underlying fixed array.
4476 static int LengthForRange(int entries) { return entries * kRangeEntrySize; }
4477 static int LengthForReturn(int entries) { return entries * kReturnEntrySize; }
4479 DECLARE_CAST(HandlerTable)
4481 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
4482 void HandlerTableRangePrint(std::ostream& os); // NOLINT
4483 void HandlerTableReturnPrint(std::ostream& os); // NOLINT
4487 // Layout description for handler table based on ranges.
4488 static const int kRangeStartIndex = 0;
4489 static const int kRangeEndIndex = 1;
4490 static const int kRangeHandlerIndex = 2;
4491 static const int kRangeDepthIndex = 3;
4492 static const int kRangeEntrySize = 4;
4494 // Layout description for handler table based on return addresses.
4495 static const int kReturnOffsetIndex = 0;
4496 static const int kReturnHandlerIndex = 1;
4497 static const int kReturnEntrySize = 2;
4499 // Encoding of the {handler} field.
4500 class HandlerPredictionField : public BitField<CatchPrediction, 0, 1> {};
4501 class HandlerOffsetField : public BitField<int, 1, 30> {};
4505 // Code describes objects with on-the-fly generated machine code.
4506 class Code: public HeapObject {
4508 // Opaque data type for encapsulating code flags like kind, inline
4509 // cache state, and arguments count.
4510 typedef uint32_t Flags;
4512 #define NON_IC_KIND_LIST(V) \
4514 V(OPTIMIZED_FUNCTION) \
4521 #define IC_KIND_LIST(V) \
4532 #define CODE_KIND_LIST(V) \
4533 NON_IC_KIND_LIST(V) \
4537 #define DEFINE_CODE_KIND_ENUM(name) name,
4538 CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM)
4539 #undef DEFINE_CODE_KIND_ENUM
4543 // No more than 16 kinds. The value is currently encoded in four bits in
4545 STATIC_ASSERT(NUMBER_OF_KINDS <= 16);
4547 static const char* Kind2String(Kind kind);
4555 static const int kPrologueOffsetNotSet = -1;
4557 #ifdef ENABLE_DISASSEMBLER
4559 static const char* ICState2String(InlineCacheState state);
4560 static const char* StubType2String(StubType type);
4561 static void PrintExtraICState(std::ostream& os, // NOLINT
4562 Kind kind, ExtraICState extra);
4563 void Disassemble(const char* name, std::ostream& os); // NOLINT
4564 #endif // ENABLE_DISASSEMBLER
4566 // [instruction_size]: Size of the native instructions
4567 inline int instruction_size() const;
4568 inline void set_instruction_size(int value);
4570 // [relocation_info]: Code relocation information
4571 DECL_ACCESSORS(relocation_info, ByteArray)
4572 void InvalidateRelocation();
4573 void InvalidateEmbeddedObjects();
4575 // [handler_table]: Fixed array containing offsets of exception handlers.
4576 DECL_ACCESSORS(handler_table, FixedArray)
4578 // [deoptimization_data]: Array containing data for deopt.
4579 DECL_ACCESSORS(deoptimization_data, FixedArray)
4581 // [raw_type_feedback_info]: This field stores various things, depending on
4582 // the kind of the code object.
4583 // FUNCTION => type feedback information.
4584 // STUB and ICs => major/minor key as Smi.
4585 DECL_ACCESSORS(raw_type_feedback_info, Object)
4586 inline Object* type_feedback_info();
4587 inline void set_type_feedback_info(
4588 Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4589 inline uint32_t stub_key();
4590 inline void set_stub_key(uint32_t key);
4592 // [next_code_link]: Link for lists of optimized or deoptimized code.
4593 // Note that storage for this field is overlapped with typefeedback_info.
4594 DECL_ACCESSORS(next_code_link, Object)
4596 // [gc_metadata]: Field used to hold GC related metadata. The contents of this
4597 // field does not have to be traced during garbage collection since
4598 // it is only used by the garbage collector itself.
4599 DECL_ACCESSORS(gc_metadata, Object)
4601 // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4602 // at the moment when this object was created.
4603 inline void set_ic_age(int count);
4604 inline int ic_age() const;
4606 // [prologue_offset]: Offset of the function prologue, used for aging
4607 // FUNCTIONs and OPTIMIZED_FUNCTIONs.
4608 inline int prologue_offset() const;
4609 inline void set_prologue_offset(int offset);
4611 // [constant_pool offset]: Offset of the constant pool.
4612 // Valid for FLAG_enable_embedded_constant_pool only
4613 inline int constant_pool_offset() const;
4614 inline void set_constant_pool_offset(int offset);
4616 // Unchecked accessors to be used during GC.
4617 inline ByteArray* unchecked_relocation_info();
4619 inline int relocation_size();
4621 // [flags]: Various code flags.
4622 inline Flags flags();
4623 inline void set_flags(Flags flags);
4625 // [flags]: Access to specific code flags.
4627 inline InlineCacheState ic_state(); // Only valid for IC stubs.
4628 inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
4630 inline StubType type(); // Only valid for monomorphic IC stubs.
4632 // Testers for IC stub kinds.
4633 inline bool is_inline_cache_stub();
4634 inline bool is_debug_stub();
4635 inline bool is_handler();
4636 inline bool is_load_stub();
4637 inline bool is_keyed_load_stub();
4638 inline bool is_store_stub();
4639 inline bool is_keyed_store_stub();
4640 inline bool is_call_stub();
4641 inline bool is_binary_op_stub();
4642 inline bool is_compare_ic_stub();
4643 inline bool is_compare_nil_ic_stub();
4644 inline bool is_to_boolean_ic_stub();
4645 inline bool is_keyed_stub();
4646 inline bool is_optimized_code();
4647 inline bool embeds_maps_weakly();
4649 inline bool IsCodeStubOrIC();
4650 inline bool IsJavaScriptCode();
4652 inline void set_raw_kind_specific_flags1(int value);
4653 inline void set_raw_kind_specific_flags2(int value);
4655 // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code
4656 // object was generated by either the hydrogen or the TurboFan optimizing
4657 // compiler (but it may not be an optimized function).
4658 inline bool is_crankshafted();
4659 inline bool is_hydrogen_stub(); // Crankshafted, but not a function.
4660 inline void set_is_crankshafted(bool value);
4662 // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the
4663 // code object was generated by the TurboFan optimizing compiler.
4664 inline bool is_turbofanned();
4665 inline void set_is_turbofanned(bool value);
4667 // [can_have_weak_objects]: For kind OPTIMIZED_FUNCTION, tells whether the
4668 // embedded objects in code should be treated weakly.
4669 inline bool can_have_weak_objects();
4670 inline void set_can_have_weak_objects(bool value);
4672 // [has_deoptimization_support]: For FUNCTION kind, tells if it has
4673 // deoptimization support.
4674 inline bool has_deoptimization_support();
4675 inline void set_has_deoptimization_support(bool value);
4677 // [has_debug_break_slots]: For FUNCTION kind, tells if it has
4678 // been compiled with debug break slots.
4679 inline bool has_debug_break_slots();
4680 inline void set_has_debug_break_slots(bool value);
4682 // [has_reloc_info_for_serialization]: For FUNCTION kind, tells if its
4683 // reloc info includes runtime and external references to support
4684 // serialization/deserialization.
4685 inline bool has_reloc_info_for_serialization();
4686 inline void set_has_reloc_info_for_serialization(bool value);
4688 // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
4689 // how long the function has been marked for OSR and therefore which
4690 // level of loop nesting we are willing to do on-stack replacement
4692 inline void set_allow_osr_at_loop_nesting_level(int level);
4693 inline int allow_osr_at_loop_nesting_level();
4695 // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
4696 // the code object was seen on the stack with no IC patching going on.
4697 inline int profiler_ticks();
4698 inline void set_profiler_ticks(int ticks);
4700 // [builtin_index]: For BUILTIN kind, tells which builtin index it has.
4701 // For builtins, tells which builtin index it has.
4702 // Note that builtins can have a code kind other than BUILTIN, which means
4703 // that for arbitrary code objects, this index value may be random garbage.
4704 // To verify in that case, compare the code object to the indexed builtin.
4705 inline int builtin_index();
4706 inline void set_builtin_index(int id);
4708 // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
4709 // reserved in the code prologue.
4710 inline unsigned stack_slots();
4711 inline void set_stack_slots(unsigned slots);
4713 // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in
4714 // the instruction stream where the safepoint table starts.
4715 inline unsigned safepoint_table_offset();
4716 inline void set_safepoint_table_offset(unsigned offset);
4718 // [back_edge_table_start]: For kind FUNCTION, the offset in the
4719 // instruction stream where the back edge table starts.
4720 inline unsigned back_edge_table_offset();
4721 inline void set_back_edge_table_offset(unsigned offset);
4723 inline bool back_edges_patched_for_osr();
4725 // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
4726 inline uint16_t to_boolean_state();
4728 // [has_function_cache]: For kind STUB tells whether there is a function
4729 // cache is passed to the stub.
4730 inline bool has_function_cache();
4731 inline void set_has_function_cache(bool flag);
4734 // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether
4735 // the code is going to be deoptimized because of dead embedded maps.
4736 inline bool marked_for_deoptimization();
4737 inline void set_marked_for_deoptimization(bool flag);
4739 // [constant_pool]: The constant pool for this function.
4740 inline Address constant_pool();
4742 // Get the safepoint entry for the given pc.
4743 SafepointEntry GetSafepointEntry(Address pc);
4745 // Find an object in a stub with a specified map
4746 Object* FindNthObject(int n, Map* match_map);
4748 // Find the first allocation site in an IC stub.
4749 AllocationSite* FindFirstAllocationSite();
4751 // Find the first map in an IC stub.
4752 Map* FindFirstMap();
4753 void FindAllMaps(MapHandleList* maps);
4755 // Find the first handler in an IC stub.
4756 Code* FindFirstHandler();
4758 // Find |length| handlers and put them into |code_list|. Returns false if not
4759 // enough handlers can be found.
4760 bool FindHandlers(CodeHandleList* code_list, int length = -1);
4762 // Find the handler for |map|.
4763 MaybeHandle<Code> FindHandlerForMap(Map* map);
4765 // Find the first name in an IC stub.
4766 Name* FindFirstName();
4768 class FindAndReplacePattern;
4769 // For each (map-to-find, object-to-replace) pair in the pattern, this
4770 // function replaces the corresponding placeholder in the code with the
4771 // object-to-replace. The function assumes that pairs in the pattern come in
4772 // the same order as the placeholders in the code.
4773 // If the placeholder is a weak cell, then the value of weak cell is matched
4774 // against the map-to-find.
4775 void FindAndReplace(const FindAndReplacePattern& pattern);
4777 // The entire code object including its header is copied verbatim to the
4778 // snapshot so that it can be written in one, fast, memcpy during
4779 // deserialization. The deserializer will overwrite some pointers, rather
4780 // like a runtime linker, but the random allocation addresses used in the
4781 // mksnapshot process would still be present in the unlinked snapshot data,
4782 // which would make snapshot production non-reproducible. This method wipes
4783 // out the to-be-overwritten header data for reproducible snapshots.
4784 inline void WipeOutHeader();
4786 // Flags operations.
4787 static inline Flags ComputeFlags(
4788 Kind kind, InlineCacheState ic_state = UNINITIALIZED,
4789 ExtraICState extra_ic_state = kNoExtraICState, StubType type = NORMAL,
4790 CacheHolderFlag holder = kCacheOnReceiver);
4792 static inline Flags ComputeMonomorphicFlags(
4793 Kind kind, ExtraICState extra_ic_state = kNoExtraICState,
4794 CacheHolderFlag holder = kCacheOnReceiver, StubType type = NORMAL);
4796 static inline Flags ComputeHandlerFlags(
4797 Kind handler_kind, StubType type = NORMAL,
4798 CacheHolderFlag holder = kCacheOnReceiver);
4800 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
4801 static inline StubType ExtractTypeFromFlags(Flags flags);
4802 static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
4803 static inline Kind ExtractKindFromFlags(Flags flags);
4804 static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
4806 static inline Flags RemoveTypeFromFlags(Flags flags);
4807 static inline Flags RemoveTypeAndHolderFromFlags(Flags flags);
4809 // Convert a target address into a code object.
4810 static inline Code* GetCodeFromTargetAddress(Address address);
4812 // Convert an entry address into an object.
4813 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
4815 // Returns the address of the first instruction.
4816 inline byte* instruction_start();
4818 // Returns the address right after the last instruction.
4819 inline byte* instruction_end();
4821 // Returns the size of the instructions, padding, and relocation information.
4822 inline int body_size();
4824 // Returns the address of the first relocation info (read backwards!).
4825 inline byte* relocation_start();
4827 // Code entry point.
4828 inline byte* entry();
4830 // Returns true if pc is inside this object's instructions.
4831 inline bool contains(byte* pc);
4833 // Relocate the code by delta bytes. Called to signal that this code
4834 // object has been moved by delta bytes.
4835 void Relocate(intptr_t delta);
4837 // Migrate code described by desc.
4838 void CopyFrom(const CodeDesc& desc);
4840 // Returns the object size for a given body (used for allocation).
4841 static int SizeFor(int body_size) {
4842 DCHECK_SIZE_TAG_ALIGNED(body_size);
4843 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
4846 // Calculate the size of the code object to report for log events. This takes
4847 // the layout of the code object into account.
4848 inline int ExecutableSize();
4850 // Locating source position.
4851 int SourcePosition(Address pc);
4852 int SourceStatementPosition(Address pc);
4856 // Dispatched behavior.
4857 inline int CodeSize();
4858 inline void CodeIterateBody(ObjectVisitor* v);
4860 template<typename StaticVisitor>
4861 inline void CodeIterateBody(Heap* heap);
4863 DECLARE_PRINTER(Code)
4864 DECLARE_VERIFIER(Code)
4866 void ClearInlineCaches();
4867 void ClearInlineCaches(Kind kind);
4869 BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset);
4870 uint32_t TranslateAstIdToPcOffset(BailoutId ast_id);
4872 #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge,
4874 kToBeExecutedOnceCodeAge = -3,
4875 kNotExecutedCodeAge = -2,
4876 kExecutedOnceCodeAge = -1,
4878 CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM)
4880 kFirstCodeAge = kToBeExecutedOnceCodeAge,
4881 kLastCodeAge = kAfterLastCodeAge - 1,
4882 kCodeAgeCount = kAfterLastCodeAge - kFirstCodeAge - 1,
4883 kIsOldCodeAge = kSexagenarianCodeAge,
4884 kPreAgedCodeAge = kIsOldCodeAge - 1
4886 #undef DECLARE_CODE_AGE_ENUM
4888 // Code aging. Indicates how many full GCs this code has survived without
4889 // being entered through the prologue. Used to determine when it is
4890 // relatively safe to flush this code object and replace it with the lazy
4891 // compilation stub.
4892 static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate);
4893 static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate);
4894 void MakeYoung(Isolate* isolate);
4895 void MarkToBeExecutedOnce(Isolate* isolate);
4896 void MakeOlder(MarkingParity);
4897 static bool IsYoungSequence(Isolate* isolate, byte* sequence);
4900 static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) {
4901 return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY);
4904 void PrintDeoptLocation(FILE* out, Address pc);
4905 bool CanDeoptAt(Address pc);
4908 void VerifyEmbeddedObjectsDependency();
4912 enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers };
4913 void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers);
4914 static void VerifyRecompiledCode(Code* old_code, Code* new_code);
4917 inline bool CanContainWeakObjects();
4919 inline bool IsWeakObject(Object* object);
4921 static inline bool IsWeakObjectInOptimizedCode(Object* object);
4923 static Handle<WeakCell> WeakCellFor(Handle<Code> code);
4924 WeakCell* CachedWeakCell();
4926 // Max loop nesting marker used to postpose OSR. We don't take loop
4927 // nesting that is deeper than 5 levels into account.
4928 static const int kMaxLoopNestingMarker = 6;
4930 static const int kConstantPoolSize =
4931 FLAG_enable_embedded_constant_pool ? kIntSize : 0;
4933 // Layout description.
4934 static const int kRelocationInfoOffset = HeapObject::kHeaderSize;
4935 static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
4936 static const int kDeoptimizationDataOffset =
4937 kHandlerTableOffset + kPointerSize;
4938 // For FUNCTION kind, we store the type feedback info here.
4939 static const int kTypeFeedbackInfoOffset =
4940 kDeoptimizationDataOffset + kPointerSize;
4941 static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize;
4942 static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize;
4943 static const int kInstructionSizeOffset = kGCMetadataOffset + kPointerSize;
4944 static const int kICAgeOffset = kInstructionSizeOffset + kIntSize;
4945 static const int kFlagsOffset = kICAgeOffset + kIntSize;
4946 static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize;
4947 static const int kKindSpecificFlags2Offset =
4948 kKindSpecificFlags1Offset + kIntSize;
4949 // Note: We might be able to squeeze this into the flags above.
4950 static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize;
4951 static const int kConstantPoolOffset = kPrologueOffset + kIntSize;
4952 static const int kHeaderPaddingStart =
4953 kConstantPoolOffset + kConstantPoolSize;
4955 // Add padding to align the instruction start following right after
4956 // the Code object header.
4957 static const int kHeaderSize =
4958 (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
4960 // Byte offsets within kKindSpecificFlags1Offset.
4961 static const int kFullCodeFlags = kKindSpecificFlags1Offset;
4962 class FullCodeFlagsHasDeoptimizationSupportField:
4963 public BitField<bool, 0, 1> {}; // NOLINT
4964 class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
4965 class FullCodeFlagsHasRelocInfoForSerialization
4966 : public BitField<bool, 2, 1> {};
4967 // Bit 3 in this bitfield is unused.
4968 class ProfilerTicksField : public BitField<int, 4, 28> {};
4970 // Flags layout. BitField<type, shift, size>.
4971 class ICStateField : public BitField<InlineCacheState, 0, 4> {};
4972 class TypeField : public BitField<StubType, 4, 1> {};
4973 class CacheHolderField : public BitField<CacheHolderFlag, 5, 2> {};
4974 class KindField : public BitField<Kind, 7, 4> {};
4975 class ExtraICStateField: public BitField<ExtraICState, 11,
4976 PlatformSmiTagging::kSmiValueSize - 11 + 1> {}; // NOLINT
4978 // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION)
4979 static const int kStackSlotsFirstBit = 0;
4980 static const int kStackSlotsBitCount = 24;
4981 static const int kHasFunctionCacheBit =
4982 kStackSlotsFirstBit + kStackSlotsBitCount;
4983 static const int kMarkedForDeoptimizationBit = kHasFunctionCacheBit + 1;
4984 static const int kIsTurbofannedBit = kMarkedForDeoptimizationBit + 1;
4985 static const int kCanHaveWeakObjects = kIsTurbofannedBit + 1;
4987 STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32);
4988 STATIC_ASSERT(kCanHaveWeakObjects + 1 <= 32);
4990 class StackSlotsField: public BitField<int,
4991 kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT
4992 class HasFunctionCacheField : public BitField<bool, kHasFunctionCacheBit, 1> {
4994 class MarkedForDeoptimizationField
4995 : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT
4996 class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> {
4998 class CanHaveWeakObjectsField
4999 : public BitField<bool, kCanHaveWeakObjects, 1> {}; // NOLINT
5001 // KindSpecificFlags2 layout (ALL)
5002 static const int kIsCrankshaftedBit = 0;
5003 class IsCrankshaftedField: public BitField<bool,
5004 kIsCrankshaftedBit, 1> {}; // NOLINT
5006 // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
5007 static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1;
5008 static const int kSafepointTableOffsetBitCount = 30;
5010 STATIC_ASSERT(kSafepointTableOffsetFirstBit +
5011 kSafepointTableOffsetBitCount <= 32);
5012 STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32);
5014 class SafepointTableOffsetField: public BitField<int,
5015 kSafepointTableOffsetFirstBit,
5016 kSafepointTableOffsetBitCount> {}; // NOLINT
5018 // KindSpecificFlags2 layout (FUNCTION)
5019 class BackEdgeTableOffsetField: public BitField<int,
5020 kIsCrankshaftedBit + 1, 27> {}; // NOLINT
5021 class AllowOSRAtLoopNestingLevelField: public BitField<int,
5022 kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT
5023 STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker);
5025 static const int kArgumentsBits = 16;
5026 static const int kMaxArguments = (1 << kArgumentsBits) - 1;
5028 // This constant should be encodable in an ARM instruction.
5029 static const int kFlagsNotUsedInLookup =
5030 TypeField::kMask | CacheHolderField::kMask;
5033 friend class RelocIterator;
5034 friend class Deoptimizer; // For FindCodeAgeSequence.
5036 void ClearInlineCaches(Kind* kind);
5039 byte* FindCodeAgeSequence();
5040 static void GetCodeAgeAndParity(Code* code, Age* age,
5041 MarkingParity* parity);
5042 static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age,
5043 MarkingParity* parity);
5044 static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity);
5046 // Code aging -- platform-specific
5047 static void PatchPlatformCodeAge(Isolate* isolate,
5048 byte* sequence, Age age,
5049 MarkingParity parity);
5051 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
5055 // This class describes the layout of dependent codes array of a map. The
5056 // array is partitioned into several groups of dependent codes. Each group
5057 // contains codes with the same dependency on the map. The array has the
5058 // following layout for n dependency groups:
5060 // +----+----+-----+----+---------+----------+-----+---------+-----------+
5061 // | C1 | C2 | ... | Cn | group 1 | group 2 | ... | group n | undefined |
5062 // +----+----+-----+----+---------+----------+-----+---------+-----------+
5064 // The first n elements are Smis, each of them specifies the number of codes
5065 // in the corresponding group. The subsequent elements contain grouped code
5066 // objects in weak cells. The suffix of the array can be filled with the
5067 // undefined value if the number of codes is less than the length of the
5068 // array. The order of the code objects within a group is not preserved.
5070 // All code indexes used in the class are counted starting from the first
5071 // code object of the first group. In other words, code index 0 corresponds
5072 // to array index n = kCodesStartIndex.
5074 class DependentCode: public FixedArray {
5076 enum DependencyGroup {
5077 // Group of code that weakly embed this map and depend on being
5078 // deoptimized when the map is garbage collected.
5080 // Group of code that embed a transition to this map, and depend on being
5081 // deoptimized when the transition is replaced by a new version.
5083 // Group of code that omit run-time prototype checks for prototypes
5084 // described by this map. The group is deoptimized whenever an object
5085 // described by this map changes shape (and transitions to a new map),
5086 // possibly invalidating the assumptions embedded in the code.
5087 kPrototypeCheckGroup,
5088 // Group of code that depends on global property values in property cells
5089 // not being changed.
5090 kPropertyCellChangedGroup,
5091 // Group of code that omit run-time type checks for the field(s) introduced
5094 // Group of code that omit run-time type checks for initial maps of
5096 kInitialMapChangedGroup,
5097 // Group of code that depends on tenuring information in AllocationSites
5098 // not being changed.
5099 kAllocationSiteTenuringChangedGroup,
5100 // Group of code that depends on element transition information in
5101 // AllocationSites not being changed.
5102 kAllocationSiteTransitionChangedGroup
5105 static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1;
5107 // Array for holding the index of the first code object of each group.
5108 // The last element stores the total number of code objects.
5109 class GroupStartIndexes {
5111 explicit GroupStartIndexes(DependentCode* entries);
5112 void Recompute(DependentCode* entries);
5113 int at(int i) { return start_indexes_[i]; }
5114 int number_of_entries() { return start_indexes_[kGroupCount]; }
5116 int start_indexes_[kGroupCount + 1];
5119 bool Contains(DependencyGroup group, WeakCell* code_cell);
5121 static Handle<DependentCode> InsertCompilationDependencies(
5122 Handle<DependentCode> entries, DependencyGroup group,
5123 Handle<Foreign> info);
5125 static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries,
5126 DependencyGroup group,
5127 Handle<WeakCell> code_cell);
5129 void UpdateToFinishedCode(DependencyGroup group, Foreign* info,
5130 WeakCell* code_cell);
5132 void RemoveCompilationDependencies(DependentCode::DependencyGroup group,
5135 void DeoptimizeDependentCodeGroup(Isolate* isolate,
5136 DependentCode::DependencyGroup group);
5138 bool MarkCodeForDeoptimization(Isolate* isolate,
5139 DependentCode::DependencyGroup group);
5141 // The following low-level accessors should only be used by this class
5142 // and the mark compact collector.
5143 inline int number_of_entries(DependencyGroup group);
5144 inline void set_number_of_entries(DependencyGroup group, int value);
5145 inline Object* object_at(int i);
5146 inline void set_object_at(int i, Object* object);
5147 inline void clear_at(int i);
5148 inline void copy(int from, int to);
5149 DECLARE_CAST(DependentCode)
5151 static const char* DependencyGroupName(DependencyGroup group);
5152 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group);
5155 static Handle<DependentCode> Insert(Handle<DependentCode> entries,
5156 DependencyGroup group,
5157 Handle<Object> object);
5158 static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries);
5159 // Make a room at the end of the given group by moving out the first
5160 // code objects of the subsequent groups.
5161 inline void ExtendGroup(DependencyGroup group);
5162 // Compact by removing cleared weak cells and return true if there was
5163 // any cleared weak cell.
5165 static int Grow(int number_of_entries) {
5166 if (number_of_entries < 5) return number_of_entries + 1;
5167 return number_of_entries * 5 / 4;
5169 static const int kCodesStartIndex = kGroupCount;
5173 class PrototypeInfo;
5176 // All heap objects have a Map that describes their structure.
5177 // A Map contains information about:
5178 // - Size information about the object
5179 // - How to iterate over an object (for garbage collection)
5180 class Map: public HeapObject {
5183 // Size in bytes or kVariableSizeSentinel if instances do not have
5185 inline int instance_size();
5186 inline void set_instance_size(int value);
5188 // Only to clear an unused byte, remove once byte is used.
5189 inline void clear_unused();
5191 // [inobject_properties_or_constructor_function_index]: Provides access
5192 // to the inobject properties in case of JSObject maps, or the constructor
5193 // function index in case of primitive maps.
5194 inline int inobject_properties_or_constructor_function_index();
5195 inline void set_inobject_properties_or_constructor_function_index(int value);
5196 // Count of properties allocated in the object (JSObject only).
5197 inline int GetInObjectProperties();
5198 inline void SetInObjectProperties(int value);
5199 // Index of the constructor function in the native context (primitives only),
5200 // or the special sentinel value to indicate that there is no object wrapper
5201 // for the primitive (i.e. in case of null or undefined).
5202 static const int kNoConstructorFunctionIndex = 0;
5203 inline int GetConstructorFunctionIndex();
5204 inline void SetConstructorFunctionIndex(int value);
5207 inline InstanceType instance_type();
5208 inline void set_instance_type(InstanceType value);
5210 // Tells how many unused property fields are available in the
5211 // instance (only used for JSObject in fast mode).
5212 inline int unused_property_fields();
5213 inline void set_unused_property_fields(int value);
5216 inline byte bit_field() const;
5217 inline void set_bit_field(byte value);
5220 inline byte bit_field2() const;
5221 inline void set_bit_field2(byte value);
5224 inline uint32_t bit_field3() const;
5225 inline void set_bit_field3(uint32_t bits);
5227 class EnumLengthBits: public BitField<int,
5228 0, kDescriptorIndexBitCount> {}; // NOLINT
5229 class NumberOfOwnDescriptorsBits: public BitField<int,
5230 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT
5231 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20);
5232 class DictionaryMap : public BitField<bool, 20, 1> {};
5233 class OwnsDescriptors : public BitField<bool, 21, 1> {};
5234 class HasInstanceCallHandler : public BitField<bool, 22, 1> {};
5235 class Deprecated : public BitField<bool, 23, 1> {};
5236 class IsUnstable : public BitField<bool, 24, 1> {};
5237 class IsMigrationTarget : public BitField<bool, 25, 1> {};
5238 class IsStrong : public BitField<bool, 26, 1> {};
5241 // Keep this bit field at the very end for better code in
5242 // Builtins::kJSConstructStubGeneric stub.
5243 // This counter is used for in-object slack tracking and for map aging.
5244 // The in-object slack tracking is considered enabled when the counter is
5245 // in the range [kSlackTrackingCounterStart, kSlackTrackingCounterEnd].
5246 class Counter : public BitField<int, 28, 4> {};
5247 static const int kSlackTrackingCounterStart = 14;
5248 static const int kSlackTrackingCounterEnd = 8;
5249 static const int kRetainingCounterStart = kSlackTrackingCounterEnd - 1;
5250 static const int kRetainingCounterEnd = 0;
5252 // Tells whether the object in the prototype property will be used
5253 // for instances created from this function. If the prototype
5254 // property is set to a value that is not a JSObject, the prototype
5255 // property will not be used to create instances of the function.
5256 // See ECMA-262, 13.2.2.
5257 inline void set_non_instance_prototype(bool value);
5258 inline bool has_non_instance_prototype();
5260 // Tells whether function has special prototype property. If not, prototype
5261 // property will not be created when accessed (will return undefined),
5262 // and construction from this function will not be allowed.
5263 inline void set_function_with_prototype(bool value);
5264 inline bool function_with_prototype();
5266 // Tells whether the instance with this map should be ignored by the
5267 // Object.getPrototypeOf() function and the __proto__ accessor.
5268 inline void set_is_hidden_prototype();
5269 inline bool is_hidden_prototype();
5271 // Records and queries whether the instance has a named interceptor.
5272 inline void set_has_named_interceptor();
5273 inline bool has_named_interceptor();
5275 // Records and queries whether the instance has an indexed interceptor.
5276 inline void set_has_indexed_interceptor();
5277 inline bool has_indexed_interceptor();
5279 // Tells whether the instance is undetectable.
5280 // An undetectable object is a special class of JSObject: 'typeof' operator
5281 // returns undefined, ToBoolean returns false. Otherwise it behaves like
5282 // a normal JS object. It is useful for implementing undetectable
5283 // document.all in Firefox & Safari.
5284 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
5285 inline void set_is_undetectable();
5286 inline bool is_undetectable();
5288 // Tells whether the instance has a call-as-function handler.
5289 inline void set_is_observed();
5290 inline bool is_observed();
5292 inline void set_is_strong();
5293 inline bool is_strong();
5294 inline void set_is_extensible(bool value);
5295 inline bool is_extensible();
5296 inline void set_is_prototype_map(bool value);
5297 inline bool is_prototype_map() const;
5299 inline void set_elements_kind(ElementsKind elements_kind);
5300 inline ElementsKind elements_kind();
5302 // Tells whether the instance has fast elements that are only Smis.
5303 inline bool has_fast_smi_elements();
5305 // Tells whether the instance has fast elements.
5306 inline bool has_fast_object_elements();
5307 inline bool has_fast_smi_or_object_elements();
5308 inline bool has_fast_double_elements();
5309 inline bool has_fast_elements();
5310 inline bool has_sloppy_arguments_elements();
5311 inline bool has_fixed_typed_array_elements();
5312 inline bool has_dictionary_elements();
5314 static bool IsValidElementsTransition(ElementsKind from_kind,
5315 ElementsKind to_kind);
5317 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a
5318 // map with DICTIONARY_ELEMENTS was found in the prototype chain.
5319 bool DictionaryElementsInPrototypeChainOnly();
5321 inline Map* ElementsTransitionMap();
5323 inline FixedArrayBase* GetInitialElements();
5325 // [raw_transitions]: Provides access to the transitions storage field.
5326 // Don't call set_raw_transitions() directly to overwrite transitions, use
5327 // the TransitionArray::ReplaceTransitions() wrapper instead!
5328 DECL_ACCESSORS(raw_transitions, Object)
5329 // [prototype_info]: Per-prototype metadata. Aliased with transitions
5330 // (which prototype maps don't have).
5331 DECL_ACCESSORS(prototype_info, Object)
5332 // PrototypeInfo is created lazily using this helper (which installs it on
5333 // the given prototype's map).
5334 static Handle<PrototypeInfo> GetOrCreatePrototypeInfo(
5335 Handle<JSObject> prototype, Isolate* isolate);
5336 static Handle<PrototypeInfo> GetOrCreatePrototypeInfo(
5337 Handle<Map> prototype_map, Isolate* isolate);
5339 // [prototype chain validity cell]: Associated with a prototype object,
5340 // stored in that object's map's PrototypeInfo, indicates that prototype
5341 // chains through this object are currently valid. The cell will be
5342 // invalidated and replaced when the prototype chain changes.
5343 static Handle<Cell> GetOrCreatePrototypeChainValidityCell(Handle<Map> map,
5345 static const int kPrototypeChainValid = 0;
5346 static const int kPrototypeChainInvalid = 1;
5349 Map* FindFieldOwner(int descriptor);
5351 inline int GetInObjectPropertyOffset(int index);
5353 int NumberOfFields();
5355 // TODO(ishell): candidate with JSObject::MigrateToMap().
5356 bool InstancesNeedRewriting(Map* target, int target_number_of_fields,
5357 int target_inobject, int target_unused,
5358 int* old_number_of_fields);
5359 // TODO(ishell): moveit!
5360 static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map);
5361 MUST_USE_RESULT static Handle<HeapType> GeneralizeFieldType(
5362 Handle<HeapType> type1,
5363 Handle<HeapType> type2,
5365 static void GeneralizeFieldType(Handle<Map> map, int modify_index,
5366 Representation new_representation,
5367 Handle<HeapType> new_field_type);
5368 static Handle<Map> ReconfigureProperty(Handle<Map> map, int modify_index,
5369 PropertyKind new_kind,
5370 PropertyAttributes new_attributes,
5371 Representation new_representation,
5372 Handle<HeapType> new_field_type,
5373 StoreMode store_mode);
5374 static Handle<Map> CopyGeneralizeAllRepresentations(
5375 Handle<Map> map, int modify_index, StoreMode store_mode,
5376 PropertyKind kind, PropertyAttributes attributes, const char* reason);
5378 static Handle<Map> PrepareForDataProperty(Handle<Map> old_map,
5379 int descriptor_number,
5380 Handle<Object> value);
5382 static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode,
5383 const char* reason);
5385 // Returns the constructor name (the name (possibly, inferred name) of the
5386 // function that was used to instantiate the object).
5387 String* constructor_name();
5389 // Tells whether the map is used for JSObjects in dictionary mode (ie
5390 // normalized objects, ie objects for which HasFastProperties returns false).
5391 // A map can never be used for both dictionary mode and fast mode JSObjects.
5392 // False by default and for HeapObjects that are not JSObjects.
5393 inline void set_dictionary_map(bool value);
5394 inline bool is_dictionary_map();
5396 // Tells whether the instance needs security checks when accessing its
5398 inline void set_is_access_check_needed(bool access_check_needed);
5399 inline bool is_access_check_needed();
5401 // Returns true if map has a non-empty stub code cache.
5402 inline bool has_code_cache();
5404 // [prototype]: implicit prototype object.
5405 DECL_ACCESSORS(prototype, Object)
5406 // TODO(jkummerow): make set_prototype private.
5407 static void SetPrototype(
5408 Handle<Map> map, Handle<Object> prototype,
5409 PrototypeOptimizationMode proto_mode = FAST_PROTOTYPE);
5411 // [constructor]: points back to the function responsible for this map.
5412 // The field overlaps with the back pointer. All maps in a transition tree
5413 // have the same constructor, so maps with back pointers can walk the
5414 // back pointer chain until they find the map holding their constructor.
5415 DECL_ACCESSORS(constructor_or_backpointer, Object)
5416 inline Object* GetConstructor() const;
5417 inline void SetConstructor(Object* constructor,
5418 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
5419 // [back pointer]: points back to the parent map from which a transition
5420 // leads to this map. The field overlaps with the constructor (see above).
5421 inline Object* GetBackPointer();
5422 inline void SetBackPointer(Object* value,
5423 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
5425 // [instance descriptors]: describes the object.
5426 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
5428 // [layout descriptor]: describes the object layout.
5429 DECL_ACCESSORS(layout_descriptor, LayoutDescriptor)
5430 // |layout descriptor| accessor which can be used from GC.
5431 inline LayoutDescriptor* layout_descriptor_gc_safe();
5432 inline bool HasFastPointerLayout() const;
5434 // |layout descriptor| accessor that is safe to call even when
5435 // FLAG_unbox_double_fields is disabled (in this case Map does not contain
5436 // |layout_descriptor| field at all).
5437 inline LayoutDescriptor* GetLayoutDescriptor();
5439 inline void UpdateDescriptors(DescriptorArray* descriptors,
5440 LayoutDescriptor* layout_descriptor);
5441 inline void InitializeDescriptors(DescriptorArray* descriptors,
5442 LayoutDescriptor* layout_descriptor);
5444 // [stub cache]: contains stubs compiled for this map.
5445 DECL_ACCESSORS(code_cache, Object)
5447 // [dependent code]: list of optimized codes that weakly embed this map.
5448 DECL_ACCESSORS(dependent_code, DependentCode)
5450 // [weak cell cache]: cache that stores a weak cell pointing to this map.
5451 DECL_ACCESSORS(weak_cell_cache, Object)
5453 inline PropertyDetails GetLastDescriptorDetails();
5455 inline int LastAdded();
5457 inline int NumberOfOwnDescriptors();
5458 inline void SetNumberOfOwnDescriptors(int number);
5460 inline Cell* RetrieveDescriptorsPointer();
5462 inline int EnumLength();
5463 inline void SetEnumLength(int length);
5465 inline bool owns_descriptors();
5466 inline void set_owns_descriptors(bool owns_descriptors);
5467 inline bool has_instance_call_handler();
5468 inline void set_has_instance_call_handler();
5469 inline void mark_unstable();
5470 inline bool is_stable();
5471 inline void set_migration_target(bool value);
5472 inline bool is_migration_target();
5473 inline void set_counter(int value);
5474 inline int counter();
5475 inline void deprecate();
5476 inline bool is_deprecated();
5477 inline bool CanBeDeprecated();
5478 // Returns a non-deprecated version of the input. If the input was not
5479 // deprecated, it is directly returned. Otherwise, the non-deprecated version
5480 // is found by re-transitioning from the root of the transition tree using the
5481 // descriptor array of the map. Returns MaybeHandle<Map>() if no updated map
5483 static MaybeHandle<Map> TryUpdate(Handle<Map> map) WARN_UNUSED_RESULT;
5485 // Returns a non-deprecated version of the input. This method may deprecate
5486 // existing maps along the way if encodings conflict. Not for use while
5487 // gathering type feedback. Use TryUpdate in those cases instead.
5488 static Handle<Map> Update(Handle<Map> map);
5490 static Handle<Map> CopyDropDescriptors(Handle<Map> map);
5491 static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
5492 Descriptor* descriptor,
5493 TransitionFlag flag);
5495 MUST_USE_RESULT static MaybeHandle<Map> CopyWithField(
5498 Handle<HeapType> type,
5499 PropertyAttributes attributes,
5500 Representation representation,
5501 TransitionFlag flag);
5503 MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant(
5506 Handle<Object> constant,
5507 PropertyAttributes attributes,
5508 TransitionFlag flag);
5510 // Returns a new map with all transitions dropped from the given map and
5511 // the ElementsKind set.
5512 static Handle<Map> TransitionElementsTo(Handle<Map> map,
5513 ElementsKind to_kind);
5515 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
5517 static Handle<Map> CopyAsElementsKind(Handle<Map> map,
5519 TransitionFlag flag);
5521 static Handle<Map> CopyForObserved(Handle<Map> map);
5523 static Handle<Map> CopyForPreventExtensions(Handle<Map> map,
5524 PropertyAttributes attrs_to_add,
5525 Handle<Symbol> transition_marker,
5526 const char* reason);
5528 static Handle<Map> FixProxy(Handle<Map> map, InstanceType type, int size);
5531 // Maximal number of fast properties. Used to restrict the number of map
5532 // transitions to avoid an explosion in the number of maps for objects used as
5534 inline bool TooManyFastProperties(StoreFromKeyed store_mode);
5535 static Handle<Map> TransitionToDataProperty(Handle<Map> map,
5537 Handle<Object> value,
5538 PropertyAttributes attributes,
5539 StoreFromKeyed store_mode);
5540 static Handle<Map> TransitionToAccessorProperty(
5541 Handle<Map> map, Handle<Name> name, AccessorComponent component,
5542 Handle<Object> accessor, PropertyAttributes attributes);
5543 static Handle<Map> ReconfigureExistingProperty(Handle<Map> map,
5546 PropertyAttributes attributes);
5548 inline void AppendDescriptor(Descriptor* desc);
5550 // Returns a copy of the map, prepared for inserting into the transition
5551 // tree (if the |map| owns descriptors then the new one will share
5552 // descriptors with |map|).
5553 static Handle<Map> CopyForTransition(Handle<Map> map, const char* reason);
5555 // Returns a copy of the map, with all transitions dropped from the
5556 // instance descriptors.
5557 static Handle<Map> Copy(Handle<Map> map, const char* reason);
5558 static Handle<Map> Create(Isolate* isolate, int inobject_properties);
5560 // Returns the next free property index (only valid for FAST MODE).
5561 int NextFreePropertyIndex();
5563 // Returns the number of properties described in instance_descriptors
5564 // filtering out properties with the specified attributes.
5565 int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
5566 PropertyAttributes filter = NONE);
5570 // Code cache operations.
5572 // Clears the code cache.
5573 inline void ClearCodeCache(Heap* heap);
5575 // Update code cache.
5576 static void UpdateCodeCache(Handle<Map> map,
5580 // Extend the descriptor array of the map with the list of descriptors.
5581 // In case of duplicates, the latest descriptor is used.
5582 static void AppendCallbackDescriptors(Handle<Map> map,
5583 Handle<Object> descriptors);
5585 static inline int SlackForArraySize(int old_size, int size_limit);
5587 static void EnsureDescriptorSlack(Handle<Map> map, int slack);
5589 // Returns the found code or undefined if absent.
5590 Object* FindInCodeCache(Name* name, Code::Flags flags);
5592 // Returns the non-negative index of the code object if it is in the
5593 // cache and -1 otherwise.
5594 int IndexInCodeCache(Object* name, Code* code);
5596 // Removes a code object from the code cache at the given index.
5597 void RemoveFromCodeCache(Name* name, Code* code, int index);
5599 // Computes a hash value for this map, to be used in HashTables and such.
5602 // Returns the map that this map transitions to if its elements_kind
5603 // is changed to |elements_kind|, or NULL if no such map is cached yet.
5604 // |safe_to_add_transitions| is set to false if adding transitions is not
5606 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
5608 // Returns the transitioned map for this map with the most generic
5609 // elements_kind that's found in |candidates|, or null handle if no match is
5611 static Handle<Map> FindTransitionedMap(Handle<Map> map,
5612 MapHandleList* candidates);
5614 inline bool CanTransition();
5616 inline bool IsPrimitiveMap();
5617 inline bool IsJSObjectMap();
5618 inline bool IsJSArrayMap();
5619 inline bool IsStringMap();
5620 inline bool IsJSProxyMap();
5621 inline bool IsJSGlobalProxyMap();
5622 inline bool IsJSGlobalObjectMap();
5623 inline bool IsGlobalObjectMap();
5625 inline bool CanOmitMapChecks();
5627 static void AddDependentCode(Handle<Map> map,
5628 DependentCode::DependencyGroup group,
5631 bool IsMapInArrayPrototypeChain();
5633 static Handle<WeakCell> WeakCellForMap(Handle<Map> map);
5635 // Dispatched behavior.
5636 DECLARE_PRINTER(Map)
5637 DECLARE_VERIFIER(Map)
5640 void DictionaryMapVerify();
5641 void VerifyOmittedMapChecks();
5644 inline int visitor_id();
5645 inline void set_visitor_id(int visitor_id);
5647 static Handle<Map> TransitionToPrototype(Handle<Map> map,
5648 Handle<Object> prototype,
5649 PrototypeOptimizationMode mode);
5651 static const int kMaxPreAllocatedPropertyFields = 255;
5653 // Layout description.
5654 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
5655 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
5656 static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize;
5657 static const int kPrototypeOffset = kBitField3Offset + kPointerSize;
5658 static const int kConstructorOrBackPointerOffset =
5659 kPrototypeOffset + kPointerSize;
5660 // When there is only one transition, it is stored directly in this field;
5661 // otherwise a transition array is used.
5662 // For prototype maps, this slot is used to store this map's PrototypeInfo
5664 static const int kTransitionsOrPrototypeInfoOffset =
5665 kConstructorOrBackPointerOffset + kPointerSize;
5666 static const int kDescriptorsOffset =
5667 kTransitionsOrPrototypeInfoOffset + kPointerSize;
5668 #if V8_DOUBLE_FIELDS_UNBOXING
5669 static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize;
5670 static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize;
5672 static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed.
5673 static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize;
5675 static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize;
5676 static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize;
5677 static const int kSize = kWeakCellCacheOffset + kPointerSize;
5679 // Layout of pointer fields. Heap iteration code relies on them
5680 // being continuously allocated.
5681 static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
5682 static const int kPointerFieldsEndOffset = kSize;
5684 // Byte offsets within kInstanceSizesOffset.
5685 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
5686 static const int kInObjectPropertiesOrConstructorFunctionIndexByte = 1;
5687 static const int kInObjectPropertiesOrConstructorFunctionIndexOffset =
5688 kInstanceSizesOffset + kInObjectPropertiesOrConstructorFunctionIndexByte;
5689 // Note there is one byte available for use here.
5690 static const int kUnusedByte = 2;
5691 static const int kUnusedOffset = kInstanceSizesOffset + kUnusedByte;
5692 static const int kVisitorIdByte = 3;
5693 static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
5695 // Byte offsets within kInstanceAttributesOffset attributes.
5696 #if V8_TARGET_LITTLE_ENDIAN
5697 // Order instance type and bit field together such that they can be loaded
5698 // together as a 16-bit word with instance type in the lower 8 bits regardless
5699 // of endianess. Also provide endian-independent offset to that 16-bit word.
5700 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
5701 static const int kBitFieldOffset = kInstanceAttributesOffset + 1;
5703 static const int kBitFieldOffset = kInstanceAttributesOffset + 0;
5704 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1;
5706 static const int kInstanceTypeAndBitFieldOffset =
5707 kInstanceAttributesOffset + 0;
5708 static const int kBitField2Offset = kInstanceAttributesOffset + 2;
5709 static const int kUnusedPropertyFieldsByte = 3;
5710 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3;
5712 STATIC_ASSERT(kInstanceTypeAndBitFieldOffset ==
5713 Internals::kMapInstanceTypeAndBitFieldOffset);
5715 // Bit positions for bit field.
5716 static const int kHasNonInstancePrototype = 0;
5717 static const int kIsHiddenPrototype = 1;
5718 static const int kHasNamedInterceptor = 2;
5719 static const int kHasIndexedInterceptor = 3;
5720 static const int kIsUndetectable = 4;
5721 static const int kIsObserved = 5;
5722 static const int kIsAccessCheckNeeded = 6;
5723 class FunctionWithPrototype: public BitField<bool, 7, 1> {};
5725 // Bit positions for bit field 2
5726 static const int kIsExtensible = 0;
5727 static const int kStringWrapperSafeForDefaultValueOf = 1;
5728 class IsPrototypeMapBits : public BitField<bool, 2, 1> {};
5729 class ElementsKindBits: public BitField<ElementsKind, 3, 5> {};
5731 // Derived values from bit field 2
5732 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
5733 (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1;
5734 static const int8_t kMaximumBitField2FastSmiElementValue =
5735 static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
5736 Map::ElementsKindBits::kShift) - 1;
5737 static const int8_t kMaximumBitField2FastHoleyElementValue =
5738 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
5739 Map::ElementsKindBits::kShift) - 1;
5740 static const int8_t kMaximumBitField2FastHoleySmiElementValue =
5741 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
5742 Map::ElementsKindBits::kShift) - 1;
5744 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
5745 kPointerFieldsEndOffset,
5746 kSize> BodyDescriptor;
5748 // Compares this map to another to see if they describe equivalent objects.
5749 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
5750 // it had exactly zero inobject properties.
5751 // The "shared" flags of both this map and |other| are ignored.
5752 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
5754 // Returns true if given field is unboxed double.
5755 inline bool IsUnboxedDoubleField(FieldIndex index);
5758 static void TraceTransition(const char* what, Map* from, Map* to, Name* name);
5759 static void TraceAllTransitions(Map* map);
5762 static inline Handle<Map> CopyInstallDescriptorsForTesting(
5763 Handle<Map> map, int new_descriptor, Handle<DescriptorArray> descriptors,
5764 Handle<LayoutDescriptor> layout_descriptor);
5767 static void ConnectTransition(Handle<Map> parent, Handle<Map> child,
5768 Handle<Name> name, SimpleTransitionFlag flag);
5770 bool EquivalentToForTransition(Map* other);
5771 static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
5772 static Handle<Map> ShareDescriptor(Handle<Map> map,
5773 Handle<DescriptorArray> descriptors,
5774 Descriptor* descriptor);
5775 static Handle<Map> CopyInstallDescriptors(
5776 Handle<Map> map, int new_descriptor, Handle<DescriptorArray> descriptors,
5777 Handle<LayoutDescriptor> layout_descriptor);
5778 static Handle<Map> CopyAddDescriptor(Handle<Map> map,
5779 Descriptor* descriptor,
5780 TransitionFlag flag);
5781 static Handle<Map> CopyReplaceDescriptors(
5782 Handle<Map> map, Handle<DescriptorArray> descriptors,
5783 Handle<LayoutDescriptor> layout_descriptor, TransitionFlag flag,
5784 MaybeHandle<Name> maybe_name, const char* reason,
5785 SimpleTransitionFlag simple_flag);
5787 static Handle<Map> CopyReplaceDescriptor(Handle<Map> map,
5788 Handle<DescriptorArray> descriptors,
5789 Descriptor* descriptor,
5791 TransitionFlag flag);
5792 static MUST_USE_RESULT MaybeHandle<Map> TryReconfigureExistingProperty(
5793 Handle<Map> map, int descriptor, PropertyKind kind,
5794 PropertyAttributes attributes, const char** reason);
5796 static Handle<Map> CopyNormalized(Handle<Map> map,
5797 PropertyNormalizationMode mode);
5799 // Fires when the layout of an object with a leaf map changes.
5800 // This includes adding transitions to the leaf map or changing
5801 // the descriptor array.
5802 inline void NotifyLeafMapLayoutChange();
5804 void DeprecateTransitionTree();
5805 bool DeprecateTarget(PropertyKind kind, Name* key,
5806 PropertyAttributes attributes,
5807 DescriptorArray* new_descriptors,
5808 LayoutDescriptor* new_layout_descriptor);
5810 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
5812 // Update field type of the given descriptor to new representation and new
5813 // type. The type must be prepared for storing in descriptor array:
5814 // it must be either a simple type or a map wrapped in a weak cell.
5815 void UpdateFieldType(int descriptor_number, Handle<Name> name,
5816 Representation new_representation,
5817 Handle<Object> new_wrapped_type);
5819 void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind,
5820 PropertyAttributes attributes);
5821 void PrintGeneralization(FILE* file,
5826 bool constant_to_field,
5827 Representation old_representation,
5828 Representation new_representation,
5829 HeapType* old_field_type,
5830 HeapType* new_field_type);
5832 static const int kFastPropertiesSoftLimit = 12;
5833 static const int kMaxFastProperties = 128;
5835 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
5839 // An abstract superclass, a marker class really, for simple structure classes.
5840 // It doesn't carry much functionality but allows struct classes to be
5841 // identified in the type system.
5842 class Struct: public HeapObject {
5844 inline void InitializeBody(int object_size);
5845 DECLARE_CAST(Struct)
5849 // A simple one-element struct, useful where smis need to be boxed.
5850 class Box : public Struct {
5852 // [value]: the boxed contents.
5853 DECL_ACCESSORS(value, Object)
5857 // Dispatched behavior.
5858 DECLARE_PRINTER(Box)
5859 DECLARE_VERIFIER(Box)
5861 static const int kValueOffset = HeapObject::kHeaderSize;
5862 static const int kSize = kValueOffset + kPointerSize;
5865 DISALLOW_IMPLICIT_CONSTRUCTORS(Box);
5869 // Container for metadata stored on each prototype map.
5870 class PrototypeInfo : public Struct {
5872 static const int UNREGISTERED = -1;
5874 // [prototype_users]: WeakFixedArray containing maps using this prototype,
5875 // or Smi(0) if uninitialized.
5876 DECL_ACCESSORS(prototype_users, Object)
5877 // [registry_slot]: Slot in prototype's user registry where this user
5878 // is stored. Returns UNREGISTERED if this prototype has not been registered.
5879 inline int registry_slot() const;
5880 inline void set_registry_slot(int slot);
5881 // [validity_cell]: Cell containing the validity bit for prototype chains
5882 // going through this object, or Smi(0) if uninitialized.
5883 DECL_ACCESSORS(validity_cell, Object)
5884 // [constructor_name]: User-friendly name of the original constructor.
5885 DECL_ACCESSORS(constructor_name, Object)
5887 DECLARE_CAST(PrototypeInfo)
5889 // Dispatched behavior.
5890 DECLARE_PRINTER(PrototypeInfo)
5891 DECLARE_VERIFIER(PrototypeInfo)
5893 static const int kPrototypeUsersOffset = HeapObject::kHeaderSize;
5894 static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize;
5895 static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize;
5896 static const int kConstructorNameOffset = kValidityCellOffset + kPointerSize;
5897 static const int kSize = kConstructorNameOffset + kPointerSize;
5900 DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo);
5904 // Pair used to store both a ScopeInfo and an extension object in the extension
5905 // slot of a block context. Needed in the rare case where a declaration block
5906 // scope (a "varblock" as used to desugar parameter destructuring) also contains
5907 // a sloppy direct eval. (In no other case both are needed at the same time.)
5908 class SloppyBlockWithEvalContextExtension : public Struct {
5910 // [scope_info]: Scope info.
5911 DECL_ACCESSORS(scope_info, ScopeInfo)
5912 // [extension]: Extension object.
5913 DECL_ACCESSORS(extension, JSObject)
5915 DECLARE_CAST(SloppyBlockWithEvalContextExtension)
5917 // Dispatched behavior.
5918 DECLARE_PRINTER(SloppyBlockWithEvalContextExtension)
5919 DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension)
5921 static const int kScopeInfoOffset = HeapObject::kHeaderSize;
5922 static const int kExtensionOffset = kScopeInfoOffset + kPointerSize;
5923 static const int kSize = kExtensionOffset + kPointerSize;
5926 DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension);
5930 // Script describes a script which has been added to the VM.
5931 class Script: public Struct {
5940 // Script compilation types.
5941 enum CompilationType {
5942 COMPILATION_TYPE_HOST = 0,
5943 COMPILATION_TYPE_EVAL = 1
5946 // Script compilation state.
5947 enum CompilationState {
5948 COMPILATION_STATE_INITIAL = 0,
5949 COMPILATION_STATE_COMPILED = 1
5952 // [source]: the script source.
5953 DECL_ACCESSORS(source, Object)
5955 // [name]: the script name.
5956 DECL_ACCESSORS(name, Object)
5958 // [id]: the script id.
5959 DECL_ACCESSORS(id, Smi)
5961 // [line_offset]: script line offset in resource from where it was extracted.
5962 DECL_ACCESSORS(line_offset, Smi)
5964 // [column_offset]: script column offset in resource from where it was
5966 DECL_ACCESSORS(column_offset, Smi)
5968 // [context_data]: context data for the context this script was compiled in.
5969 DECL_ACCESSORS(context_data, Object)
5971 // [wrapper]: the wrapper cache. This is either undefined or a WeakCell.
5972 DECL_ACCESSORS(wrapper, HeapObject)
5974 // [type]: the script type.
5975 DECL_ACCESSORS(type, Smi)
5977 // [line_ends]: FixedArray of line ends positions.
5978 DECL_ACCESSORS(line_ends, Object)
5980 // [eval_from_shared]: for eval scripts the shared funcion info for the
5981 // function from which eval was called.
5982 DECL_ACCESSORS(eval_from_shared, Object)
5984 // [eval_from_instructions_offset]: the instruction offset in the code for the
5985 // function from which eval was called where eval was called.
5986 DECL_ACCESSORS(eval_from_instructions_offset, Smi)
5988 // [shared_function_infos]: weak fixed array containing all shared
5989 // function infos created from this script.
5990 DECL_ACCESSORS(shared_function_infos, Object)
5992 // [flags]: Holds an exciting bitfield.
5993 DECL_ACCESSORS(flags, Smi)
5995 // [source_url]: sourceURL from magic comment
5996 DECL_ACCESSORS(source_url, Object)
5998 // [source_url]: sourceMappingURL magic comment
5999 DECL_ACCESSORS(source_mapping_url, Object)
6001 // [compilation_type]: how the the script was compiled. Encoded in the
6003 inline CompilationType compilation_type();
6004 inline void set_compilation_type(CompilationType type);
6006 // [compilation_state]: determines whether the script has already been
6007 // compiled. Encoded in the 'flags' field.
6008 inline CompilationState compilation_state();
6009 inline void set_compilation_state(CompilationState state);
6011 // [hide_source]: determines whether the script source can be exposed as
6012 // function source. Encoded in the 'flags' field.
6013 inline bool hide_source();
6014 inline void set_hide_source(bool value);
6016 // [origin_options]: optional attributes set by the embedder via ScriptOrigin,
6017 // and used by the embedder to make decisions about the script. V8 just passes
6018 // this through. Encoded in the 'flags' field.
6019 inline v8::ScriptOriginOptions origin_options();
6020 inline void set_origin_options(ScriptOriginOptions origin_options);
6022 DECLARE_CAST(Script)
6024 // If script source is an external string, check that the underlying
6025 // resource is accessible. Otherwise, always return true.
6026 inline bool HasValidSource();
6028 // Convert code position into column number.
6029 static int GetColumnNumber(Handle<Script> script, int code_pos);
6031 // Convert code position into (zero-based) line number.
6032 // The non-handlified version does not allocate, but may be much slower.
6033 static int GetLineNumber(Handle<Script> script, int code_pos);
6034 int GetLineNumber(int code_pos);
6036 static Handle<Object> GetNameOrSourceURL(Handle<Script> script);
6038 // Init line_ends array with code positions of line ends inside script source.
6039 static void InitLineEnds(Handle<Script> script);
6041 // Get the JS object wrapping the given script; create it if none exists.
6042 static Handle<JSObject> GetWrapper(Handle<Script> script);
6044 // Look through the list of existing shared function infos to find one
6045 // that matches the function literal. Return empty handle if not found.
6046 MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun);
6048 // Iterate over all script objects on the heap.
6051 explicit Iterator(Isolate* isolate);
6055 WeakFixedArray::Iterator iterator_;
6056 DISALLOW_COPY_AND_ASSIGN(Iterator);
6059 // Dispatched behavior.
6060 DECLARE_PRINTER(Script)
6061 DECLARE_VERIFIER(Script)
6063 static const int kSourceOffset = HeapObject::kHeaderSize;
6064 static const int kNameOffset = kSourceOffset + kPointerSize;
6065 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
6066 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
6067 static const int kContextOffset = kColumnOffsetOffset + kPointerSize;
6068 static const int kWrapperOffset = kContextOffset + kPointerSize;
6069 static const int kTypeOffset = kWrapperOffset + kPointerSize;
6070 static const int kLineEndsOffset = kTypeOffset + kPointerSize;
6071 static const int kIdOffset = kLineEndsOffset + kPointerSize;
6072 static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
6073 static const int kEvalFrominstructionsOffsetOffset =
6074 kEvalFromSharedOffset + kPointerSize;
6075 static const int kSharedFunctionInfosOffset =
6076 kEvalFrominstructionsOffsetOffset + kPointerSize;
6077 static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize;
6078 static const int kSourceUrlOffset = kFlagsOffset + kPointerSize;
6079 static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize;
6080 static const int kSize = kSourceMappingUrlOffset + kPointerSize;
6083 int GetLineNumberWithArray(int code_pos);
6085 // Bit positions in the flags field.
6086 static const int kCompilationTypeBit = 0;
6087 static const int kCompilationStateBit = 1;
6088 static const int kHideSourceBit = 2;
6089 static const int kOriginOptionsShift = 3;
6090 static const int kOriginOptionsSize = 3;
6091 static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1)
6092 << kOriginOptionsShift;
6094 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
6098 // List of builtin functions we want to identify to improve code
6101 // Each entry has a name of a global object property holding an object
6102 // optionally followed by ".prototype", a name of a builtin function
6103 // on the object (the one the id is set for), and a label.
6105 // Installation of ids for the selected builtin functions is handled
6106 // by the bootstrapper.
6107 #define FUNCTIONS_WITH_ID_LIST(V) \
6108 V(Array.prototype, indexOf, ArrayIndexOf) \
6109 V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \
6110 V(Array.prototype, push, ArrayPush) \
6111 V(Array.prototype, pop, ArrayPop) \
6112 V(Array.prototype, shift, ArrayShift) \
6113 V(Function.prototype, apply, FunctionApply) \
6114 V(Function.prototype, call, FunctionCall) \
6115 V(String.prototype, charCodeAt, StringCharCodeAt) \
6116 V(String.prototype, charAt, StringCharAt) \
6117 V(String, fromCharCode, StringFromCharCode) \
6118 V(Math, random, MathRandom) \
6119 V(Math, floor, MathFloor) \
6120 V(Math, round, MathRound) \
6121 V(Math, ceil, MathCeil) \
6122 V(Math, abs, MathAbs) \
6123 V(Math, log, MathLog) \
6124 V(Math, exp, MathExp) \
6125 V(Math, sqrt, MathSqrt) \
6126 V(Math, pow, MathPow) \
6127 V(Math, max, MathMax) \
6128 V(Math, min, MathMin) \
6129 V(Math, cos, MathCos) \
6130 V(Math, sin, MathSin) \
6131 V(Math, tan, MathTan) \
6132 V(Math, acos, MathAcos) \
6133 V(Math, asin, MathAsin) \
6134 V(Math, atan, MathAtan) \
6135 V(Math, atan2, MathAtan2) \
6136 V(Math, imul, MathImul) \
6137 V(Math, clz32, MathClz32) \
6138 V(Math, fround, MathFround)
6140 #define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \
6141 V(Atomics, load, AtomicsLoad) \
6142 V(Atomics, store, AtomicsStore)
6144 enum BuiltinFunctionId {
6146 #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
6148 FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
6149 ATOMIC_FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
6150 #undef DECLARE_FUNCTION_ID
6151 // Fake id for a special case of Math.pow. Note, it continues the
6152 // list of math functions.
6157 // Result of searching in an optimized code map of a SharedFunctionInfo. Note
6158 // that both {code} and {literals} can be NULL to pass search result status.
6159 struct CodeAndLiterals {
6160 Code* code; // Cached optimized code.
6161 FixedArray* literals; // Cached literals array.
6165 // SharedFunctionInfo describes the JSFunction information that can be
6166 // shared by multiple instances of the function.
6167 class SharedFunctionInfo: public HeapObject {
6169 // [name]: Function name.
6170 DECL_ACCESSORS(name, Object)
6172 // [code]: Function code.
6173 DECL_ACCESSORS(code, Code)
6174 inline void ReplaceCode(Code* code);
6176 // [optimized_code_map]: Map from native context to optimized code
6177 // and a shared literals array or Smi(0) if none.
6178 DECL_ACCESSORS(optimized_code_map, Object)
6180 // Returns entry from optimized code map for specified context and OSR entry.
6181 // Note that {code == nullptr} indicates no matching entry has been found,
6182 // whereas {literals == nullptr} indicates the code is context-independent.
6183 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context,
6184 BailoutId osr_ast_id);
6186 // Clear optimized code map.
6187 void ClearOptimizedCodeMap();
6189 // Removed a specific optimized code object from the optimized code map.
6190 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason);
6192 // Trims the optimized code map after entries have been removed.
6193 void TrimOptimizedCodeMap(int shrink_by);
6195 // Add a new entry to the optimized code map for context-independent code.
6196 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
6199 // Add a new entry to the optimized code map for context-dependent code.
6200 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
6201 Handle<Context> native_context,
6203 Handle<FixedArray> literals,
6204 BailoutId osr_ast_id);
6206 // Set up the link between shared function info and the script. The shared
6207 // function info is added to the list on the script.
6208 static void SetScript(Handle<SharedFunctionInfo> shared,
6209 Handle<Object> script_object);
6211 // Layout description of the optimized code map.
6212 static const int kNextMapIndex = 0;
6213 static const int kSharedCodeIndex = 1;
6214 static const int kEntriesStart = 2;
6215 static const int kContextOffset = 0;
6216 static const int kCachedCodeOffset = 1;
6217 static const int kLiteralsOffset = 2;
6218 static const int kOsrAstIdOffset = 3;
6219 static const int kEntryLength = 4;
6220 static const int kInitialLength = kEntriesStart + kEntryLength;
6222 // [scope_info]: Scope info.
6223 DECL_ACCESSORS(scope_info, ScopeInfo)
6225 // [construct stub]: Code stub for constructing instances of this function.
6226 DECL_ACCESSORS(construct_stub, Code)
6228 // Returns if this function has been compiled to native code yet.
6229 inline bool is_compiled();
6231 // [length]: The function length - usually the number of declared parameters.
6232 // Use up to 2^30 parameters.
6233 inline int length() const;
6234 inline void set_length(int value);
6236 // [internal formal parameter count]: The declared number of parameters.
6237 // For subclass constructors, also includes new.target.
6238 // The size of function's frame is internal_formal_parameter_count + 1.
6239 inline int internal_formal_parameter_count() const;
6240 inline void set_internal_formal_parameter_count(int value);
6242 // Set the formal parameter count so the function code will be
6243 // called without using argument adaptor frames.
6244 inline void DontAdaptArguments();
6246 // [expected_nof_properties]: Expected number of properties for the function.
6247 inline int expected_nof_properties() const;
6248 inline void set_expected_nof_properties(int value);
6250 // [feedback_vector] - accumulates ast node feedback from full-codegen and
6251 // (increasingly) from crankshafted code where sufficient feedback isn't
6253 DECL_ACCESSORS(feedback_vector, TypeFeedbackVector)
6255 // Unconditionally clear the type feedback vector (including vector ICs).
6256 void ClearTypeFeedbackInfo();
6258 // Clear the type feedback vector with a more subtle policy at GC time.
6259 void ClearTypeFeedbackInfoAtGCTime();
6262 // [unique_id] - For --trace-maps purposes, an identifier that's persistent
6263 // even if the GC moves this SharedFunctionInfo.
6264 inline int unique_id() const;
6265 inline void set_unique_id(int value);
6268 // [instance class name]: class name for instances.
6269 DECL_ACCESSORS(instance_class_name, Object)
6271 // [function data]: This field holds some additional data for function.
6272 // Currently it has one of:
6273 // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()].
6274 // - a Smi identifying a builtin function [HasBuiltinFunctionId()].
6275 // - a BytecodeArray for the interpreter [HasBytecodeArray()].
6276 // In the long run we don't want all functions to have this field but
6277 // we can fix that when we have a better model for storing hidden data
6279 DECL_ACCESSORS(function_data, Object)
6281 inline bool IsApiFunction();
6282 inline FunctionTemplateInfo* get_api_func_data();
6283 inline bool HasBuiltinFunctionId();
6284 inline BuiltinFunctionId builtin_function_id();
6285 inline bool HasBytecodeArray();
6286 inline BytecodeArray* bytecode_array();
6288 // [script info]: Script from which the function originates.
6289 DECL_ACCESSORS(script, Object)
6291 // [num_literals]: Number of literals used by this function.
6292 inline int num_literals() const;
6293 inline void set_num_literals(int value);
6295 // [start_position_and_type]: Field used to store both the source code
6296 // position, whether or not the function is a function expression,
6297 // and whether or not the function is a toplevel function. The two
6298 // least significants bit indicates whether the function is an
6299 // expression and the rest contains the source code position.
6300 inline int start_position_and_type() const;
6301 inline void set_start_position_and_type(int value);
6303 // The function is subject to debugging if a debug info is attached.
6304 inline bool HasDebugInfo();
6305 inline DebugInfo* GetDebugInfo();
6307 // A function has debug code if the compiled code has debug break slots.
6308 inline bool HasDebugCode();
6310 // [debug info]: Debug information.
6311 DECL_ACCESSORS(debug_info, Object)
6313 // [inferred name]: Name inferred from variable or property
6314 // assignment of this function. Used to facilitate debugging and
6315 // profiling of JavaScript code written in OO style, where almost
6316 // all functions are anonymous but are assigned to object
6318 DECL_ACCESSORS(inferred_name, String)
6320 // The function's name if it is non-empty, otherwise the inferred name.
6321 String* DebugName();
6323 // Position of the 'function' token in the script source.
6324 inline int function_token_position() const;
6325 inline void set_function_token_position(int function_token_position);
6327 // Position of this function in the script source.
6328 inline int start_position() const;
6329 inline void set_start_position(int start_position);
6331 // End position of this function in the script source.
6332 inline int end_position() const;
6333 inline void set_end_position(int end_position);
6335 // Is this function a function expression in the source code.
6336 DECL_BOOLEAN_ACCESSORS(is_expression)
6338 // Is this function a top-level function (scripts, evals).
6339 DECL_BOOLEAN_ACCESSORS(is_toplevel)
6341 // Bit field containing various information collected by the compiler to
6342 // drive optimization.
6343 inline int compiler_hints() const;
6344 inline void set_compiler_hints(int value);
6346 inline int ast_node_count() const;
6347 inline void set_ast_node_count(int count);
6349 inline int profiler_ticks() const;
6350 inline void set_profiler_ticks(int ticks);
6352 // Inline cache age is used to infer whether the function survived a context
6353 // disposal or not. In the former case we reset the opt_count.
6354 inline int ic_age();
6355 inline void set_ic_age(int age);
6357 // Indicates if this function can be lazy compiled.
6358 // This is used to determine if we can safely flush code from a function
6359 // when doing GC if we expect that the function will no longer be used.
6360 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
6362 // Indicates if this function can be lazy compiled without a context.
6363 // This is used to determine if we can force compilation without reaching
6364 // the function through program execution but through other means (e.g. heap
6365 // iteration by the debugger).
6366 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context)
6368 // Indicates whether optimizations have been disabled for this
6369 // shared function info. If a function is repeatedly optimized or if
6370 // we cannot optimize the function we disable optimization to avoid
6371 // spending time attempting to optimize it again.
6372 DECL_BOOLEAN_ACCESSORS(optimization_disabled)
6374 // Indicates the language mode.
6375 inline LanguageMode language_mode();
6376 inline void set_language_mode(LanguageMode language_mode);
6378 // False if the function definitely does not allocate an arguments object.
6379 DECL_BOOLEAN_ACCESSORS(uses_arguments)
6381 // Indicates that this function uses a super property (or an eval that may
6382 // use a super property).
6383 // This is needed to set up the [[HomeObject]] on the function instance.
6384 DECL_BOOLEAN_ACCESSORS(needs_home_object)
6386 // True if the function has any duplicated parameter names.
6387 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
6389 // Indicates whether the function is a native function.
6390 // These needs special treatment in .call and .apply since
6391 // null passed as the receiver should not be translated to the
6393 DECL_BOOLEAN_ACCESSORS(native)
6395 // Indicate that this function should always be inlined in optimized code.
6396 DECL_BOOLEAN_ACCESSORS(force_inline)
6398 // Indicates that the function was created by the Function function.
6399 // Though it's anonymous, toString should treat it as if it had the name
6400 // "anonymous". We don't set the name itself so that the system does not
6401 // see a binding for it.
6402 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
6404 // Indicates whether the function is a bound function created using
6405 // the bind function.
6406 DECL_BOOLEAN_ACCESSORS(bound)
6408 // Indicates that the function is anonymous (the name field can be set
6409 // through the API, which does not change this flag).
6410 DECL_BOOLEAN_ACCESSORS(is_anonymous)
6412 // Is this a function or top-level/eval code.
6413 DECL_BOOLEAN_ACCESSORS(is_function)
6415 // Indicates that code for this function cannot be compiled with Crankshaft.
6416 DECL_BOOLEAN_ACCESSORS(dont_crankshaft)
6418 // Indicates that code for this function cannot be flushed.
6419 DECL_BOOLEAN_ACCESSORS(dont_flush)
6421 // Indicates that this function is a generator.
6422 DECL_BOOLEAN_ACCESSORS(is_generator)
6424 // Indicates that this function is an arrow function.
6425 DECL_BOOLEAN_ACCESSORS(is_arrow)
6427 // Indicates that this function is a concise method.
6428 DECL_BOOLEAN_ACCESSORS(is_concise_method)
6430 // Indicates that this function is an accessor (getter or setter).
6431 DECL_BOOLEAN_ACCESSORS(is_accessor_function)
6433 // Indicates that this function is a default constructor.
6434 DECL_BOOLEAN_ACCESSORS(is_default_constructor)
6436 // Indicates that this function is an asm function.
6437 DECL_BOOLEAN_ACCESSORS(asm_function)
6439 // Indicates that the the shared function info is deserialized from cache.
6440 DECL_BOOLEAN_ACCESSORS(deserialized)
6442 // Indicates that the the shared function info has never been compiled before.
6443 DECL_BOOLEAN_ACCESSORS(never_compiled)
6445 inline FunctionKind kind();
6446 inline void set_kind(FunctionKind kind);
6448 // Indicates whether or not the code in the shared function support
6450 inline bool has_deoptimization_support();
6452 // Enable deoptimization support through recompiled code.
6453 void EnableDeoptimizationSupport(Code* recompiled);
6455 // Disable (further) attempted optimization of all functions sharing this
6456 // shared function info.
6457 void DisableOptimization(BailoutReason reason);
6459 inline BailoutReason disable_optimization_reason();
6461 // Lookup the bailout ID and DCHECK that it exists in the non-optimized
6462 // code, returns whether it asserted (i.e., always true if assertions are
6464 bool VerifyBailoutId(BailoutId id);
6466 // [source code]: Source code for the function.
6467 bool HasSourceCode() const;
6468 Handle<Object> GetSourceCode();
6470 // Number of times the function was optimized.
6471 inline int opt_count();
6472 inline void set_opt_count(int opt_count);
6474 // Number of times the function was deoptimized.
6475 inline void set_deopt_count(int value);
6476 inline int deopt_count();
6477 inline void increment_deopt_count();
6479 // Number of time we tried to re-enable optimization after it
6480 // was disabled due to high number of deoptimizations.
6481 inline void set_opt_reenable_tries(int value);
6482 inline int opt_reenable_tries();
6484 inline void TryReenableOptimization();
6486 // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
6487 inline void set_counters(int value);
6488 inline int counters() const;
6490 // Stores opt_count and bailout_reason as bit-fields.
6491 inline void set_opt_count_and_bailout_reason(int value);
6492 inline int opt_count_and_bailout_reason() const;
6494 inline void set_disable_optimization_reason(BailoutReason reason);
6496 // Tells whether this function should be subject to debugging.
6497 inline bool IsSubjectToDebugging();
6499 // Whether this function is defined in native code or extensions.
6500 inline bool IsBuiltin();
6502 // Check whether or not this function is inlineable.
6503 bool IsInlineable();
6505 // Source size of this function.
6508 // Calculate the instance size.
6509 int CalculateInstanceSize();
6511 // Calculate the number of in-object properties.
6512 int CalculateInObjectProperties();
6514 inline bool has_simple_parameters();
6516 // Initialize a SharedFunctionInfo from a parsed function literal.
6517 static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info,
6518 FunctionLiteral* lit);
6520 // Dispatched behavior.
6521 DECLARE_PRINTER(SharedFunctionInfo)
6522 DECLARE_VERIFIER(SharedFunctionInfo)
6524 void ResetForNewContext(int new_ic_age);
6526 // Iterate over all shared function infos that are created from a script.
6527 // That excludes shared function infos created for API functions and C++
6531 explicit Iterator(Isolate* isolate);
6532 SharedFunctionInfo* Next();
6537 Script::Iterator script_iterator_;
6538 WeakFixedArray::Iterator sfi_iterator_;
6539 DisallowHeapAllocation no_gc_;
6540 DISALLOW_COPY_AND_ASSIGN(Iterator);
6543 DECLARE_CAST(SharedFunctionInfo)
6546 static const int kDontAdaptArgumentsSentinel = -1;
6548 // Layout description.
6550 static const int kNameOffset = HeapObject::kHeaderSize;
6551 static const int kCodeOffset = kNameOffset + kPointerSize;
6552 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
6553 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
6554 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
6555 static const int kInstanceClassNameOffset =
6556 kConstructStubOffset + kPointerSize;
6557 static const int kFunctionDataOffset =
6558 kInstanceClassNameOffset + kPointerSize;
6559 static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
6560 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
6561 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
6562 static const int kFeedbackVectorOffset =
6563 kInferredNameOffset + kPointerSize;
6565 static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize;
6566 static const int kLastPointerFieldOffset = kUniqueIdOffset;
6568 // Just to not break the postmortrem support with conditional offsets
6569 static const int kUniqueIdOffset = kFeedbackVectorOffset;
6570 static const int kLastPointerFieldOffset = kFeedbackVectorOffset;
6573 #if V8_HOST_ARCH_32_BIT
6575 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize;
6576 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
6577 static const int kExpectedNofPropertiesOffset =
6578 kFormalParameterCountOffset + kPointerSize;
6579 static const int kNumLiteralsOffset =
6580 kExpectedNofPropertiesOffset + kPointerSize;
6581 static const int kStartPositionAndTypeOffset =
6582 kNumLiteralsOffset + kPointerSize;
6583 static const int kEndPositionOffset =
6584 kStartPositionAndTypeOffset + kPointerSize;
6585 static const int kFunctionTokenPositionOffset =
6586 kEndPositionOffset + kPointerSize;
6587 static const int kCompilerHintsOffset =
6588 kFunctionTokenPositionOffset + kPointerSize;
6589 static const int kOptCountAndBailoutReasonOffset =
6590 kCompilerHintsOffset + kPointerSize;
6591 static const int kCountersOffset =
6592 kOptCountAndBailoutReasonOffset + kPointerSize;
6593 static const int kAstNodeCountOffset =
6594 kCountersOffset + kPointerSize;
6595 static const int kProfilerTicksOffset =
6596 kAstNodeCountOffset + kPointerSize;
6599 static const int kSize = kProfilerTicksOffset + kPointerSize;
6601 // The only reason to use smi fields instead of int fields
6602 // is to allow iteration without maps decoding during
6603 // garbage collections.
6604 // To avoid wasting space on 64-bit architectures we use
6605 // the following trick: we group integer fields into pairs
6606 // The least significant integer in each pair is shifted left by 1.
6607 // By doing this we guarantee that LSB of each kPointerSize aligned
6608 // word is not set and thus this word cannot be treated as pointer
6609 // to HeapObject during old space traversal.
6610 #if V8_TARGET_LITTLE_ENDIAN
6611 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize;
6612 static const int kFormalParameterCountOffset =
6613 kLengthOffset + kIntSize;
6615 static const int kExpectedNofPropertiesOffset =
6616 kFormalParameterCountOffset + kIntSize;
6617 static const int kNumLiteralsOffset =
6618 kExpectedNofPropertiesOffset + kIntSize;
6620 static const int kEndPositionOffset =
6621 kNumLiteralsOffset + kIntSize;
6622 static const int kStartPositionAndTypeOffset =
6623 kEndPositionOffset + kIntSize;
6625 static const int kFunctionTokenPositionOffset =
6626 kStartPositionAndTypeOffset + kIntSize;
6627 static const int kCompilerHintsOffset =
6628 kFunctionTokenPositionOffset + kIntSize;
6630 static const int kOptCountAndBailoutReasonOffset =
6631 kCompilerHintsOffset + kIntSize;
6632 static const int kCountersOffset =
6633 kOptCountAndBailoutReasonOffset + kIntSize;
6635 static const int kAstNodeCountOffset =
6636 kCountersOffset + kIntSize;
6637 static const int kProfilerTicksOffset =
6638 kAstNodeCountOffset + kIntSize;
6641 static const int kSize = kProfilerTicksOffset + kIntSize;
6643 #elif V8_TARGET_BIG_ENDIAN
6644 static const int kFormalParameterCountOffset =
6645 kLastPointerFieldOffset + kPointerSize;
6646 static const int kLengthOffset = kFormalParameterCountOffset + kIntSize;
6648 static const int kNumLiteralsOffset = kLengthOffset + kIntSize;
6649 static const int kExpectedNofPropertiesOffset = kNumLiteralsOffset + kIntSize;
6651 static const int kStartPositionAndTypeOffset =
6652 kExpectedNofPropertiesOffset + kIntSize;
6653 static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize;
6655 static const int kCompilerHintsOffset = kEndPositionOffset + kIntSize;
6656 static const int kFunctionTokenPositionOffset =
6657 kCompilerHintsOffset + kIntSize;
6659 static const int kCountersOffset = kFunctionTokenPositionOffset + kIntSize;
6660 static const int kOptCountAndBailoutReasonOffset = kCountersOffset + kIntSize;
6662 static const int kProfilerTicksOffset =
6663 kOptCountAndBailoutReasonOffset + kIntSize;
6664 static const int kAstNodeCountOffset = kProfilerTicksOffset + kIntSize;
6667 static const int kSize = kAstNodeCountOffset + kIntSize;
6670 #error Unknown byte ordering
6671 #endif // Big endian
6675 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
6677 typedef FixedBodyDescriptor<kNameOffset,
6678 kLastPointerFieldOffset + kPointerSize,
6679 kSize> BodyDescriptor;
6681 // Bit positions in start_position_and_type.
6682 // The source code start position is in the 30 most significant bits of
6683 // the start_position_and_type field.
6684 static const int kIsExpressionBit = 0;
6685 static const int kIsTopLevelBit = 1;
6686 static const int kStartPositionShift = 2;
6687 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
6689 // Bit positions in compiler_hints.
6690 enum CompilerHints {
6691 kAllowLazyCompilation,
6692 kAllowLazyCompilationWithoutContext,
6693 kOptimizationDisabled,
6694 kStrictModeFunction,
6695 kStrongModeFunction,
6698 kHasDuplicateParameters,
6703 kNameShouldPrintAsAnonymous,
6710 kIsAccessorFunction,
6711 kIsDefaultConstructor,
6712 kIsSubclassConstructor,
6718 kCompilerHintsCount // Pseudo entry
6720 // Add hints for other modes when they're added.
6721 STATIC_ASSERT(LANGUAGE_END == 3);
6723 class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 8> {};
6725 class DeoptCountBits : public BitField<int, 0, 4> {};
6726 class OptReenableTriesBits : public BitField<int, 4, 18> {};
6727 class ICAgeBits : public BitField<int, 22, 8> {};
6729 class OptCountBits : public BitField<int, 0, 22> {};
6730 class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {};
6733 #if V8_HOST_ARCH_32_BIT
6734 // On 32 bit platforms, compiler hints is a smi.
6735 static const int kCompilerHintsSmiTagSize = kSmiTagSize;
6736 static const int kCompilerHintsSize = kPointerSize;
6738 // On 64 bit platforms, compiler hints is not a smi, see comment above.
6739 static const int kCompilerHintsSmiTagSize = 0;
6740 static const int kCompilerHintsSize = kIntSize;
6743 STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
6744 SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
6747 // Constants for optimizing codegen for strict mode function and
6749 // Allows to use byte-width instructions.
6750 static const int kStrictModeBitWithinByte =
6751 (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
6752 static const int kStrongModeBitWithinByte =
6753 (kStrongModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
6755 static const int kNativeBitWithinByte =
6756 (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
6758 static const int kBoundBitWithinByte =
6759 (kBoundFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
6761 #if defined(V8_TARGET_LITTLE_ENDIAN)
6762 static const int kStrictModeByteOffset = kCompilerHintsOffset +
6763 (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
6764 static const int kStrongModeByteOffset =
6765 kCompilerHintsOffset +
6766 (kStrongModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
6767 static const int kNativeByteOffset = kCompilerHintsOffset +
6768 (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
6769 static const int kBoundByteOffset =
6770 kCompilerHintsOffset +
6771 (kBoundFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
6772 #elif defined(V8_TARGET_BIG_ENDIAN)
6773 static const int kStrictModeByteOffset = kCompilerHintsOffset +
6774 (kCompilerHintsSize - 1) -
6775 ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
6776 static const int kStrongModeByteOffset =
6777 kCompilerHintsOffset + (kCompilerHintsSize - 1) -
6778 ((kStrongModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
6779 static const int kNativeByteOffset = kCompilerHintsOffset +
6780 (kCompilerHintsSize - 1) -
6781 ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
6782 static const int kBoundByteOffset =
6783 kCompilerHintsOffset + (kCompilerHintsSize - 1) -
6784 ((kBoundFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
6786 #error Unknown byte ordering
6790 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
6794 // Printing support.
6795 struct SourceCodeOf {
6796 explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1)
6797 : value(v), max_length(max) {}
6798 const SharedFunctionInfo* value;
6803 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v);
6806 class JSGeneratorObject: public JSObject {
6808 // [function]: The function corresponding to this generator object.
6809 DECL_ACCESSORS(function, JSFunction)
6811 // [context]: The context of the suspended computation.
6812 DECL_ACCESSORS(context, Context)
6814 // [receiver]: The receiver of the suspended computation.
6815 DECL_ACCESSORS(receiver, Object)
6817 // [continuation]: Offset into code of continuation.
6819 // A positive offset indicates a suspended generator. The special
6820 // kGeneratorExecuting and kGeneratorClosed values indicate that a generator
6821 // cannot be resumed.
6822 inline int continuation() const;
6823 inline void set_continuation(int continuation);
6824 inline bool is_closed();
6825 inline bool is_executing();
6826 inline bool is_suspended();
6828 // [operand_stack]: Saved operand stack.
6829 DECL_ACCESSORS(operand_stack, FixedArray)
6831 DECLARE_CAST(JSGeneratorObject)
6833 // Dispatched behavior.
6834 DECLARE_PRINTER(JSGeneratorObject)
6835 DECLARE_VERIFIER(JSGeneratorObject)
6837 // Magic sentinel values for the continuation.
6838 static const int kGeneratorExecuting = -1;
6839 static const int kGeneratorClosed = 0;
6841 // Layout description.
6842 static const int kFunctionOffset = JSObject::kHeaderSize;
6843 static const int kContextOffset = kFunctionOffset + kPointerSize;
6844 static const int kReceiverOffset = kContextOffset + kPointerSize;
6845 static const int kContinuationOffset = kReceiverOffset + kPointerSize;
6846 static const int kOperandStackOffset = kContinuationOffset + kPointerSize;
6847 static const int kSize = kOperandStackOffset + kPointerSize;
6849 // Resume mode, for use by runtime functions.
6850 enum ResumeMode { NEXT, THROW };
6852 // Yielding from a generator returns an object with the following inobject
6853 // properties. See Context::iterator_result_map() for the map.
6854 static const int kResultValuePropertyIndex = 0;
6855 static const int kResultDonePropertyIndex = 1;
6856 static const int kResultPropertyCount = 2;
6858 static const int kResultValuePropertyOffset = JSObject::kHeaderSize;
6859 static const int kResultDonePropertyOffset =
6860 kResultValuePropertyOffset + kPointerSize;
6861 static const int kResultSize = kResultDonePropertyOffset + kPointerSize;
6864 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject);
6868 // Representation for module instance objects.
6869 class JSModule: public JSObject {
6871 // [context]: the context holding the module's locals, or undefined if none.
6872 DECL_ACCESSORS(context, Object)
6874 // [scope_info]: Scope info.
6875 DECL_ACCESSORS(scope_info, ScopeInfo)
6877 DECLARE_CAST(JSModule)
6879 // Dispatched behavior.
6880 DECLARE_PRINTER(JSModule)
6881 DECLARE_VERIFIER(JSModule)
6883 // Layout description.
6884 static const int kContextOffset = JSObject::kHeaderSize;
6885 static const int kScopeInfoOffset = kContextOffset + kPointerSize;
6886 static const int kSize = kScopeInfoOffset + kPointerSize;
6889 DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule);
6893 // JSFunction describes JavaScript functions.
6894 class JSFunction: public JSObject {
6896 // [prototype_or_initial_map]:
6897 DECL_ACCESSORS(prototype_or_initial_map, Object)
6899 // [shared]: The information about the function that
6900 // can be shared by instances.
6901 DECL_ACCESSORS(shared, SharedFunctionInfo)
6903 // [context]: The context for this function.
6904 inline Context* context();
6905 inline void set_context(Object* context);
6906 inline JSObject* global_proxy();
6908 // [code]: The generated code object for this function. Executed
6909 // when the function is invoked, e.g. foo() or new foo(). See
6910 // [[Call]] and [[Construct]] description in ECMA-262, section
6912 inline Code* code();
6913 inline void set_code(Code* code);
6914 inline void set_code_no_write_barrier(Code* code);
6915 inline void ReplaceCode(Code* code);
6917 // Tells whether this function is builtin.
6918 inline bool IsBuiltin();
6920 // Tells whether this function inlines the given shared function info.
6921 bool Inlines(SharedFunctionInfo* candidate);
6923 // Tells whether this function should be subject to debugging.
6924 inline bool IsSubjectToDebugging();
6926 // Tells whether or not the function needs arguments adaption.
6927 inline bool NeedsArgumentsAdaption();
6929 // Tells whether or not this function has been optimized.
6930 inline bool IsOptimized();
6932 // Mark this function for lazy recompilation. The function will be
6933 // recompiled the next time it is executed.
6934 void MarkForOptimization();
6935 void AttemptConcurrentOptimization();
6937 // Tells whether or not the function is already marked for lazy
6939 inline bool IsMarkedForOptimization();
6940 inline bool IsMarkedForConcurrentOptimization();
6942 // Tells whether or not the function is on the concurrent recompilation queue.
6943 inline bool IsInOptimizationQueue();
6945 // Inobject slack tracking is the way to reclaim unused inobject space.
6947 // The instance size is initially determined by adding some slack to
6948 // expected_nof_properties (to allow for a few extra properties added
6949 // after the constructor). There is no guarantee that the extra space
6950 // will not be wasted.
6952 // Here is the algorithm to reclaim the unused inobject space:
6953 // - Detect the first constructor call for this JSFunction.
6954 // When it happens enter the "in progress" state: initialize construction
6955 // counter in the initial_map.
6956 // - While the tracking is in progress create objects filled with
6957 // one_pointer_filler_map instead of undefined_value. This way they can be
6958 // resized quickly and safely.
6959 // - Once enough objects have been created compute the 'slack'
6960 // (traverse the map transition tree starting from the
6961 // initial_map and find the lowest value of unused_property_fields).
6962 // - Traverse the transition tree again and decrease the instance size
6963 // of every map. Existing objects will resize automatically (they are
6964 // filled with one_pointer_filler_map). All further allocations will
6965 // use the adjusted instance size.
6966 // - SharedFunctionInfo's expected_nof_properties left unmodified since
6967 // allocations made using different closures could actually create different
6968 // kind of objects (see prototype inheritance pattern).
6970 // Important: inobject slack tracking is not attempted during the snapshot
6973 // True if the initial_map is set and the object constructions countdown
6974 // counter is not zero.
6975 static const int kGenerousAllocationCount =
6976 Map::kSlackTrackingCounterStart - Map::kSlackTrackingCounterEnd + 1;
6977 inline bool IsInobjectSlackTrackingInProgress();
6979 // Starts the tracking.
6980 // Initializes object constructions countdown counter in the initial map.
6981 void StartInobjectSlackTracking();
6983 // Completes the tracking.
6984 void CompleteInobjectSlackTracking();
6986 // [literals_or_bindings]: Fixed array holding either
6987 // the materialized literals or the bindings of a bound function.
6989 // If the function contains object, regexp or array literals, the
6990 // literals array prefix contains the object, regexp, and array
6991 // function to be used when creating these literals. This is
6992 // necessary so that we do not dynamically lookup the object, regexp
6993 // or array functions. Performing a dynamic lookup, we might end up
6994 // using the functions from a new context that we should not have
6997 // On bound functions, the array is a (copy-on-write) fixed-array containing
6998 // the function that was bound, bound this-value and any bound
6999 // arguments. Bound functions never contain literals.
7000 DECL_ACCESSORS(literals_or_bindings, FixedArray)
7002 inline FixedArray* literals();
7003 inline void set_literals(FixedArray* literals);
7005 inline FixedArray* function_bindings();
7006 inline void set_function_bindings(FixedArray* bindings);
7008 // The initial map for an object created by this constructor.
7009 inline Map* initial_map();
7010 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
7011 Handle<Object> prototype);
7012 inline bool has_initial_map();
7013 static void EnsureHasInitialMap(Handle<JSFunction> function);
7015 // Get and set the prototype property on a JSFunction. If the
7016 // function has an initial map the prototype is set on the initial
7017 // map. Otherwise, the prototype is put in the initial map field
7018 // until an initial map is needed.
7019 inline bool has_prototype();
7020 inline bool has_instance_prototype();
7021 inline Object* prototype();
7022 inline Object* instance_prototype();
7023 static void SetPrototype(Handle<JSFunction> function,
7024 Handle<Object> value);
7025 static void SetInstancePrototype(Handle<JSFunction> function,
7026 Handle<Object> value);
7028 // Creates a new closure for the fucntion with the same bindings,
7029 // bound values, and prototype. An equivalent of spec operations
7030 // ``CloneMethod`` and ``CloneBoundFunction``.
7031 static Handle<JSFunction> CloneClosure(Handle<JSFunction> function);
7033 // After prototype is removed, it will not be created when accessed, and
7034 // [[Construct]] from this function will not be allowed.
7035 bool RemovePrototype();
7036 inline bool should_have_prototype();
7038 // Accessor for this function's initial map's [[class]]
7039 // property. This is primarily used by ECMA native functions. This
7040 // method sets the class_name field of this function's initial map
7041 // to a given value. It creates an initial map if this function does
7042 // not have one. Note that this method does not copy the initial map
7043 // if it has one already, but simply replaces it with the new value.
7044 // Instances created afterwards will have a map whose [[class]] is
7045 // set to 'value', but there is no guarantees on instances created
7047 void SetInstanceClassName(String* name);
7049 // Returns if this function has been compiled to native code yet.
7050 inline bool is_compiled();
7052 // Returns `false` if formal parameters include rest parameters, optional
7053 // parameters, or destructuring parameters.
7054 // TODO(caitp): make this a flag set during parsing
7055 inline bool has_simple_parameters();
7057 // [next_function_link]: Links functions into various lists, e.g. the list
7058 // of optimized functions hanging off the native_context. The CodeFlusher
7059 // uses this link to chain together flushing candidates. Treated weakly
7060 // by the garbage collector.
7061 DECL_ACCESSORS(next_function_link, Object)
7063 // Prints the name of the function using PrintF.
7064 void PrintName(FILE* out = stdout);
7066 DECLARE_CAST(JSFunction)
7068 // Iterates the objects, including code objects indirectly referenced
7069 // through pointers to the first instruction in the code object.
7070 void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
7072 // Dispatched behavior.
7073 DECLARE_PRINTER(JSFunction)
7074 DECLARE_VERIFIER(JSFunction)
7076 // Returns the number of allocated literals.
7077 inline int NumberOfLiterals();
7079 // Used for flags such as --hydrogen-filter.
7080 bool PassesFilter(const char* raw_filter);
7082 // The function's name if it is configured, otherwise shared function info
7084 static Handle<String> GetDebugName(Handle<JSFunction> function);
7086 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
7087 // kSize) is weak and has special handling during garbage collection.
7088 static const int kCodeEntryOffset = JSObject::kHeaderSize;
7089 static const int kPrototypeOrInitialMapOffset =
7090 kCodeEntryOffset + kPointerSize;
7091 static const int kSharedFunctionInfoOffset =
7092 kPrototypeOrInitialMapOffset + kPointerSize;
7093 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
7094 static const int kLiteralsOffset = kContextOffset + kPointerSize;
7095 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
7096 static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
7097 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
7099 // Layout of the bound-function binding array.
7100 static const int kBoundFunctionIndex = 0;
7101 static const int kBoundThisIndex = 1;
7102 static const int kBoundArgumentsStartIndex = 2;
7105 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
7109 // JSGlobalProxy's prototype must be a JSGlobalObject or null,
7110 // and the prototype is hidden. JSGlobalProxy always delegates
7111 // property accesses to its prototype if the prototype is not null.
7113 // A JSGlobalProxy can be reinitialized which will preserve its identity.
7115 // Accessing a JSGlobalProxy requires security check.
7117 class JSGlobalProxy : public JSObject {
7119 // [native_context]: the owner native context of this global proxy object.
7120 // It is null value if this object is not used by any context.
7121 DECL_ACCESSORS(native_context, Object)
7123 // [hash]: The hash code property (undefined if not initialized yet).
7124 DECL_ACCESSORS(hash, Object)
7126 DECLARE_CAST(JSGlobalProxy)
7128 inline bool IsDetachedFrom(GlobalObject* global) const;
7130 // Dispatched behavior.
7131 DECLARE_PRINTER(JSGlobalProxy)
7132 DECLARE_VERIFIER(JSGlobalProxy)
7134 // Layout description.
7135 static const int kNativeContextOffset = JSObject::kHeaderSize;
7136 static const int kHashOffset = kNativeContextOffset + kPointerSize;
7137 static const int kSize = kHashOffset + kPointerSize;
7140 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
7144 // Common super class for JavaScript global objects and the special
7145 // builtins global objects.
7146 class GlobalObject: public JSObject {
7148 // [builtins]: the object holding the runtime routines written in JS.
7149 DECL_ACCESSORS(builtins, JSBuiltinsObject)
7151 // [native context]: the natives corresponding to this global object.
7152 DECL_ACCESSORS(native_context, Context)
7154 // [global proxy]: the global proxy object of the context
7155 DECL_ACCESSORS(global_proxy, JSObject)
7157 DECLARE_CAST(GlobalObject)
7159 static void InvalidatePropertyCell(Handle<GlobalObject> object,
7161 // Ensure that the global object has a cell for the given property name.
7162 static Handle<PropertyCell> EnsurePropertyCell(Handle<GlobalObject> global,
7165 // Layout description.
7166 static const int kBuiltinsOffset = JSObject::kHeaderSize;
7167 static const int kNativeContextOffset = kBuiltinsOffset + kPointerSize;
7168 static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize;
7169 static const int kHeaderSize = kGlobalProxyOffset + kPointerSize;
7172 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
7176 // JavaScript global object.
7177 class JSGlobalObject: public GlobalObject {
7179 DECLARE_CAST(JSGlobalObject)
7181 inline bool IsDetached();
7183 // Dispatched behavior.
7184 DECLARE_PRINTER(JSGlobalObject)
7185 DECLARE_VERIFIER(JSGlobalObject)
7187 // Layout description.
7188 static const int kSize = GlobalObject::kHeaderSize;
7191 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
7195 // Builtins global object which holds the runtime routines written in
7197 class JSBuiltinsObject: public GlobalObject {
7199 DECLARE_CAST(JSBuiltinsObject)
7201 // Dispatched behavior.
7202 DECLARE_PRINTER(JSBuiltinsObject)
7203 DECLARE_VERIFIER(JSBuiltinsObject)
7205 // Layout description.
7206 static const int kSize = GlobalObject::kHeaderSize;
7209 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
7213 // Representation for JS Wrapper objects, String, Number, Boolean, etc.
7214 class JSValue: public JSObject {
7216 // [value]: the object being wrapped.
7217 DECL_ACCESSORS(value, Object)
7219 DECLARE_CAST(JSValue)
7221 // Dispatched behavior.
7222 DECLARE_PRINTER(JSValue)
7223 DECLARE_VERIFIER(JSValue)
7225 // Layout description.
7226 static const int kValueOffset = JSObject::kHeaderSize;
7227 static const int kSize = kValueOffset + kPointerSize;
7230 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
7236 // Representation for JS date objects.
7237 class JSDate: public JSObject {
7239 // If one component is NaN, all of them are, indicating a NaN time value.
7240 // [value]: the time value.
7241 DECL_ACCESSORS(value, Object)
7242 // [year]: caches year. Either undefined, smi, or NaN.
7243 DECL_ACCESSORS(year, Object)
7244 // [month]: caches month. Either undefined, smi, or NaN.
7245 DECL_ACCESSORS(month, Object)
7246 // [day]: caches day. Either undefined, smi, or NaN.
7247 DECL_ACCESSORS(day, Object)
7248 // [weekday]: caches day of week. Either undefined, smi, or NaN.
7249 DECL_ACCESSORS(weekday, Object)
7250 // [hour]: caches hours. Either undefined, smi, or NaN.
7251 DECL_ACCESSORS(hour, Object)
7252 // [min]: caches minutes. Either undefined, smi, or NaN.
7253 DECL_ACCESSORS(min, Object)
7254 // [sec]: caches seconds. Either undefined, smi, or NaN.
7255 DECL_ACCESSORS(sec, Object)
7256 // [cache stamp]: sample of the date cache stamp at the
7257 // moment when chached fields were cached.
7258 DECL_ACCESSORS(cache_stamp, Object)
7260 DECLARE_CAST(JSDate)
7262 // Returns the date field with the specified index.
7263 // See FieldIndex for the list of date fields.
7264 static Object* GetField(Object* date, Smi* index);
7266 void SetValue(Object* value, bool is_value_nan);
7269 // Dispatched behavior.
7270 DECLARE_PRINTER(JSDate)
7271 DECLARE_VERIFIER(JSDate)
7273 // The order is important. It must be kept in sync with date macros
7284 kFirstUncachedField,
7285 kMillisecond = kFirstUncachedField,
7289 kYearUTC = kFirstUTCField,
7302 // Layout description.
7303 static const int kValueOffset = JSObject::kHeaderSize;
7304 static const int kYearOffset = kValueOffset + kPointerSize;
7305 static const int kMonthOffset = kYearOffset + kPointerSize;
7306 static const int kDayOffset = kMonthOffset + kPointerSize;
7307 static const int kWeekdayOffset = kDayOffset + kPointerSize;
7308 static const int kHourOffset = kWeekdayOffset + kPointerSize;
7309 static const int kMinOffset = kHourOffset + kPointerSize;
7310 static const int kSecOffset = kMinOffset + kPointerSize;
7311 static const int kCacheStampOffset = kSecOffset + kPointerSize;
7312 static const int kSize = kCacheStampOffset + kPointerSize;
7315 inline Object* DoGetField(FieldIndex index);
7317 Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
7319 // Computes and caches the cacheable fields of the date.
7320 inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache);
7323 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
7327 // Representation of message objects used for error reporting through
7328 // the API. The messages are formatted in JavaScript so this object is
7329 // a real JavaScript object. The information used for formatting the
7330 // error messages are not directly accessible from JavaScript to
7331 // prevent leaking information to user code called during error
7333 class JSMessageObject: public JSObject {
7335 // [type]: the type of error message.
7336 inline int type() const;
7337 inline void set_type(int value);
7339 // [arguments]: the arguments for formatting the error message.
7340 DECL_ACCESSORS(argument, Object)
7342 // [script]: the script from which the error message originated.
7343 DECL_ACCESSORS(script, Object)
7345 // [stack_frames]: an array of stack frames for this error object.
7346 DECL_ACCESSORS(stack_frames, Object)
7348 // [start_position]: the start position in the script for the error message.
7349 inline int start_position() const;
7350 inline void set_start_position(int value);
7352 // [end_position]: the end position in the script for the error message.
7353 inline int end_position() const;
7354 inline void set_end_position(int value);
7356 DECLARE_CAST(JSMessageObject)
7358 // Dispatched behavior.
7359 DECLARE_PRINTER(JSMessageObject)
7360 DECLARE_VERIFIER(JSMessageObject)
7362 // Layout description.
7363 static const int kTypeOffset = JSObject::kHeaderSize;
7364 static const int kArgumentsOffset = kTypeOffset + kPointerSize;
7365 static const int kScriptOffset = kArgumentsOffset + kPointerSize;
7366 static const int kStackFramesOffset = kScriptOffset + kPointerSize;
7367 static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
7368 static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
7369 static const int kSize = kEndPositionOffset + kPointerSize;
7371 typedef FixedBodyDescriptor<HeapObject::kMapOffset,
7372 kStackFramesOffset + kPointerSize,
7373 kSize> BodyDescriptor;
7377 // Regular expressions
7378 // The regular expression holds a single reference to a FixedArray in
7379 // the kDataOffset field.
7380 // The FixedArray contains the following data:
7381 // - tag : type of regexp implementation (not compiled yet, atom or irregexp)
7382 // - reference to the original source string
7383 // - reference to the original flag string
7384 // If it is an atom regexp
7385 // - a reference to a literal string to search for
7386 // If it is an irregexp regexp:
7387 // - a reference to code for Latin1 inputs (bytecode or compiled), or a smi
7388 // used for tracking the last usage (used for code flushing).
7389 // - a reference to code for UC16 inputs (bytecode or compiled), or a smi
7390 // used for tracking the last usage (used for code flushing)..
7391 // - max number of registers used by irregexp implementations.
7392 // - number of capture registers (output values) of the regexp.
7393 class JSRegExp: public JSObject {
7396 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
7397 // ATOM: A simple string to match against using an indexOf operation.
7398 // IRREGEXP: Compiled with Irregexp.
7399 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
7400 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
7407 UNICODE_ESCAPES = 16
7412 explicit Flags(uint32_t value) : value_(value) { }
7413 bool is_global() { return (value_ & GLOBAL) != 0; }
7414 bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
7415 bool is_multiline() { return (value_ & MULTILINE) != 0; }
7416 bool is_sticky() { return (value_ & STICKY) != 0; }
7417 bool is_unicode() { return (value_ & UNICODE_ESCAPES) != 0; }
7418 uint32_t value() { return value_; }
7423 DECL_ACCESSORS(data, Object)
7425 inline Type TypeTag();
7426 inline int CaptureCount();
7427 inline Flags GetFlags();
7428 inline String* Pattern();
7429 inline Object* DataAt(int index);
7430 // Set implementation data after the object has been prepared.
7431 inline void SetDataAt(int index, Object* value);
7433 static int code_index(bool is_latin1) {
7435 return kIrregexpLatin1CodeIndex;
7437 return kIrregexpUC16CodeIndex;
7441 static int saved_code_index(bool is_latin1) {
7443 return kIrregexpLatin1CodeSavedIndex;
7445 return kIrregexpUC16CodeSavedIndex;
7449 DECLARE_CAST(JSRegExp)
7451 // Dispatched behavior.
7452 DECLARE_VERIFIER(JSRegExp)
7454 static const int kDataOffset = JSObject::kHeaderSize;
7455 static const int kSize = kDataOffset + kPointerSize;
7457 // Indices in the data array.
7458 static const int kTagIndex = 0;
7459 static const int kSourceIndex = kTagIndex + 1;
7460 static const int kFlagsIndex = kSourceIndex + 1;
7461 static const int kDataIndex = kFlagsIndex + 1;
7462 // The data fields are used in different ways depending on the
7463 // value of the tag.
7464 // Atom regexps (literal strings).
7465 static const int kAtomPatternIndex = kDataIndex;
7467 static const int kAtomDataSize = kAtomPatternIndex + 1;
7469 // Irregexp compiled code or bytecode for Latin1. If compilation
7470 // fails, this fields hold an exception object that should be
7471 // thrown if the regexp is used again.
7472 static const int kIrregexpLatin1CodeIndex = kDataIndex;
7473 // Irregexp compiled code or bytecode for UC16. If compilation
7474 // fails, this fields hold an exception object that should be
7475 // thrown if the regexp is used again.
7476 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
7478 // Saved instance of Irregexp compiled code or bytecode for Latin1 that
7479 // is a potential candidate for flushing.
7480 static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2;
7481 // Saved instance of Irregexp compiled code or bytecode for UC16 that is
7482 // a potential candidate for flushing.
7483 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
7485 // Maximal number of registers used by either Latin1 or UC16.
7486 // Only used to check that there is enough stack space
7487 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
7488 // Number of captures in the compiled regexp.
7489 static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
7491 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
7493 // Offsets directly into the data fixed array.
7494 static const int kDataTagOffset =
7495 FixedArray::kHeaderSize + kTagIndex * kPointerSize;
7496 static const int kDataOneByteCodeOffset =
7497 FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize;
7498 static const int kDataUC16CodeOffset =
7499 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
7500 static const int kIrregexpCaptureCountOffset =
7501 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
7503 // In-object fields.
7504 static const int kSourceFieldIndex = 0;
7505 static const int kGlobalFieldIndex = 1;
7506 static const int kIgnoreCaseFieldIndex = 2;
7507 static const int kMultilineFieldIndex = 3;
7508 static const int kLastIndexFieldIndex = 4;
7509 static const int kInObjectFieldCount = 5;
7511 // The uninitialized value for a regexp code object.
7512 static const int kUninitializedValue = -1;
7514 // The compilation error value for the regexp code object. The real error
7515 // object is in the saved code field.
7516 static const int kCompilationErrorValue = -2;
7518 // When we store the sweep generation at which we moved the code from the
7519 // code index to the saved code index we mask it of to be in the [0:255]
7521 static const int kCodeAgeMask = 0xff;
7525 class CompilationCacheShape : public BaseShape<HashTableKey*> {
7527 static inline bool IsMatch(HashTableKey* key, Object* value) {
7528 return key->IsMatch(value);
7531 static inline uint32_t Hash(HashTableKey* key) {
7535 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
7536 return key->HashForObject(object);
7539 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
7541 static const int kPrefixSize = 0;
7542 static const int kEntrySize = 2;
7546 // This cache is used in two different variants. For regexp caching, it simply
7547 // maps identifying info of the regexp to the cached regexp object. Scripts and
7548 // eval code only gets cached after a second probe for the code object. To do
7549 // so, on first "put" only a hash identifying the source is entered into the
7550 // cache, mapping it to a lifetime count of the hash. On each call to Age all
7551 // such lifetimes get reduced, and removed once they reach zero. If a second put
7552 // is called while such a hash is live in the cache, the hash gets replaced by
7553 // an actual cache entry. Age also removes stale live entries from the cache.
7554 // Such entries are identified by SharedFunctionInfos pointing to either the
7555 // recompilation stub, or to "old" code. This avoids memory leaks due to
7556 // premature caching of scripts and eval strings that are never needed later.
7557 class CompilationCacheTable: public HashTable<CompilationCacheTable,
7558 CompilationCacheShape,
7561 // Find cached value for a string key, otherwise return null.
7562 Handle<Object> Lookup(
7563 Handle<String> src, Handle<Context> context, LanguageMode language_mode);
7564 Handle<Object> LookupEval(
7565 Handle<String> src, Handle<SharedFunctionInfo> shared,
7566 LanguageMode language_mode, int scope_position);
7567 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
7568 static Handle<CompilationCacheTable> Put(
7569 Handle<CompilationCacheTable> cache, Handle<String> src,
7570 Handle<Context> context, LanguageMode language_mode,
7571 Handle<Object> value);
7572 static Handle<CompilationCacheTable> PutEval(
7573 Handle<CompilationCacheTable> cache, Handle<String> src,
7574 Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value,
7575 int scope_position);
7576 static Handle<CompilationCacheTable> PutRegExp(
7577 Handle<CompilationCacheTable> cache, Handle<String> src,
7578 JSRegExp::Flags flags, Handle<FixedArray> value);
7579 void Remove(Object* value);
7581 static const int kHashGenerations = 10;
7583 DECLARE_CAST(CompilationCacheTable)
7586 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
7590 class CodeCache: public Struct {
7592 DECL_ACCESSORS(default_cache, FixedArray)
7593 DECL_ACCESSORS(normal_type_cache, Object)
7595 // Add the code object to the cache.
7597 Handle<CodeCache> cache, Handle<Name> name, Handle<Code> code);
7599 // Lookup code object in the cache. Returns code object if found and undefined
7601 Object* Lookup(Name* name, Code::Flags flags);
7603 // Get the internal index of a code object in the cache. Returns -1 if the
7604 // code object is not in that cache. This index can be used to later call
7605 // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
7607 int GetIndex(Object* name, Code* code);
7609 // Remove an object from the cache with the provided internal index.
7610 void RemoveByIndex(Object* name, Code* code, int index);
7612 DECLARE_CAST(CodeCache)
7614 // Dispatched behavior.
7615 DECLARE_PRINTER(CodeCache)
7616 DECLARE_VERIFIER(CodeCache)
7618 static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
7619 static const int kNormalTypeCacheOffset =
7620 kDefaultCacheOffset + kPointerSize;
7621 static const int kSize = kNormalTypeCacheOffset + kPointerSize;
7624 static void UpdateDefaultCache(
7625 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
7626 static void UpdateNormalTypeCache(
7627 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
7628 Object* LookupDefaultCache(Name* name, Code::Flags flags);
7629 Object* LookupNormalTypeCache(Name* name, Code::Flags flags);
7631 // Code cache layout of the default cache. Elements are alternating name and
7632 // code objects for non normal load/store/call IC's.
7633 static const int kCodeCacheEntrySize = 2;
7634 static const int kCodeCacheEntryNameOffset = 0;
7635 static const int kCodeCacheEntryCodeOffset = 1;
7637 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
7641 class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
7643 static inline bool IsMatch(HashTableKey* key, Object* value) {
7644 return key->IsMatch(value);
7647 static inline uint32_t Hash(HashTableKey* key) {
7651 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
7652 return key->HashForObject(object);
7655 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
7657 static const int kPrefixSize = 0;
7658 static const int kEntrySize = 2;
7662 class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
7663 CodeCacheHashTableShape,
7666 Object* Lookup(Name* name, Code::Flags flags);
7667 static Handle<CodeCacheHashTable> Put(
7668 Handle<CodeCacheHashTable> table,
7672 int GetIndex(Name* name, Code::Flags flags);
7673 void RemoveByIndex(int index);
7675 DECLARE_CAST(CodeCacheHashTable)
7677 // Initial size of the fixed array backing the hash table.
7678 static const int kInitialSize = 64;
7681 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
7685 class PolymorphicCodeCache: public Struct {
7687 DECL_ACCESSORS(cache, Object)
7689 static void Update(Handle<PolymorphicCodeCache> cache,
7690 MapHandleList* maps,
7695 // Returns an undefined value if the entry is not found.
7696 Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
7698 DECLARE_CAST(PolymorphicCodeCache)
7700 // Dispatched behavior.
7701 DECLARE_PRINTER(PolymorphicCodeCache)
7702 DECLARE_VERIFIER(PolymorphicCodeCache)
7704 static const int kCacheOffset = HeapObject::kHeaderSize;
7705 static const int kSize = kCacheOffset + kPointerSize;
7708 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
7712 class PolymorphicCodeCacheHashTable
7713 : public HashTable<PolymorphicCodeCacheHashTable,
7714 CodeCacheHashTableShape,
7717 Object* Lookup(MapHandleList* maps, int code_kind);
7719 static Handle<PolymorphicCodeCacheHashTable> Put(
7720 Handle<PolymorphicCodeCacheHashTable> hash_table,
7721 MapHandleList* maps,
7725 DECLARE_CAST(PolymorphicCodeCacheHashTable)
7727 static const int kInitialSize = 64;
7729 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
7733 class TypeFeedbackInfo: public Struct {
7735 inline int ic_total_count();
7736 inline void set_ic_total_count(int count);
7738 inline int ic_with_type_info_count();
7739 inline void change_ic_with_type_info_count(int delta);
7741 inline int ic_generic_count();
7742 inline void change_ic_generic_count(int delta);
7744 inline void initialize_storage();
7746 inline void change_own_type_change_checksum();
7747 inline int own_type_change_checksum();
7749 inline void set_inlined_type_change_checksum(int checksum);
7750 inline bool matches_inlined_type_change_checksum(int checksum);
7752 DECLARE_CAST(TypeFeedbackInfo)
7754 // Dispatched behavior.
7755 DECLARE_PRINTER(TypeFeedbackInfo)
7756 DECLARE_VERIFIER(TypeFeedbackInfo)
7758 static const int kStorage1Offset = HeapObject::kHeaderSize;
7759 static const int kStorage2Offset = kStorage1Offset + kPointerSize;
7760 static const int kStorage3Offset = kStorage2Offset + kPointerSize;
7761 static const int kSize = kStorage3Offset + kPointerSize;
7764 static const int kTypeChangeChecksumBits = 7;
7766 class ICTotalCountField: public BitField<int, 0,
7767 kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
7768 class OwnTypeChangeChecksum: public BitField<int,
7769 kSmiValueSize - kTypeChangeChecksumBits,
7770 kTypeChangeChecksumBits> {}; // NOLINT
7771 class ICsWithTypeInfoCountField: public BitField<int, 0,
7772 kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
7773 class InlinedTypeChangeChecksum: public BitField<int,
7774 kSmiValueSize - kTypeChangeChecksumBits,
7775 kTypeChangeChecksumBits> {}; // NOLINT
7777 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
7781 enum AllocationSiteMode {
7782 DONT_TRACK_ALLOCATION_SITE,
7783 TRACK_ALLOCATION_SITE,
7784 LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE
7788 class AllocationSite: public Struct {
7790 static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024;
7791 static const double kPretenureRatio;
7792 static const int kPretenureMinimumCreated = 100;
7794 // Values for pretenure decision field.
7795 enum PretenureDecision {
7801 kLastPretenureDecisionValue = kZombie
7804 const char* PretenureDecisionName(PretenureDecision decision);
7806 DECL_ACCESSORS(transition_info, Object)
7807 // nested_site threads a list of sites that represent nested literals
7808 // walked in a particular order. So [[1, 2], 1, 2] will have one
7809 // nested_site, but [[1, 2], 3, [4]] will have a list of two.
7810 DECL_ACCESSORS(nested_site, Object)
7811 DECL_ACCESSORS(pretenure_data, Smi)
7812 DECL_ACCESSORS(pretenure_create_count, Smi)
7813 DECL_ACCESSORS(dependent_code, DependentCode)
7814 DECL_ACCESSORS(weak_next, Object)
7816 inline void Initialize();
7818 // This method is expensive, it should only be called for reporting.
7819 bool IsNestedSite();
7821 // transition_info bitfields, for constructed array transition info.
7822 class ElementsKindBits: public BitField<ElementsKind, 0, 15> {};
7823 class UnusedBits: public BitField<int, 15, 14> {};
7824 class DoNotInlineBit: public BitField<bool, 29, 1> {};
7826 // Bitfields for pretenure_data
7827 class MementoFoundCountBits: public BitField<int, 0, 26> {};
7828 class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {};
7829 class DeoptDependentCodeBit: public BitField<bool, 29, 1> {};
7830 STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
7832 // Increments the mementos found counter and returns true when the first
7833 // memento was found for a given allocation site.
7834 inline bool IncrementMementoFoundCount();
7836 inline void IncrementMementoCreateCount();
7838 PretenureFlag GetPretenureMode();
7840 void ResetPretenureDecision();
7842 inline PretenureDecision pretenure_decision();
7843 inline void set_pretenure_decision(PretenureDecision decision);
7845 inline bool deopt_dependent_code();
7846 inline void set_deopt_dependent_code(bool deopt);
7848 inline int memento_found_count();
7849 inline void set_memento_found_count(int count);
7851 inline int memento_create_count();
7852 inline void set_memento_create_count(int count);
7854 // The pretenuring decision is made during gc, and the zombie state allows
7855 // us to recognize when an allocation site is just being kept alive because
7856 // a later traversal of new space may discover AllocationMementos that point
7857 // to this AllocationSite.
7858 inline bool IsZombie();
7860 inline bool IsMaybeTenure();
7862 inline void MarkZombie();
7864 inline bool MakePretenureDecision(PretenureDecision current_decision,
7866 bool maximum_size_scavenge);
7868 inline bool DigestPretenuringFeedback(bool maximum_size_scavenge);
7870 inline ElementsKind GetElementsKind();
7871 inline void SetElementsKind(ElementsKind kind);
7873 inline bool CanInlineCall();
7874 inline void SetDoNotInlineCall();
7876 inline bool SitePointsToLiteral();
7878 static void DigestTransitionFeedback(Handle<AllocationSite> site,
7879 ElementsKind to_kind);
7881 DECLARE_PRINTER(AllocationSite)
7882 DECLARE_VERIFIER(AllocationSite)
7884 DECLARE_CAST(AllocationSite)
7885 static inline AllocationSiteMode GetMode(
7886 ElementsKind boilerplate_elements_kind);
7887 static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to);
7888 static inline bool CanTrack(InstanceType type);
7890 static const int kTransitionInfoOffset = HeapObject::kHeaderSize;
7891 static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize;
7892 static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize;
7893 static const int kPretenureCreateCountOffset =
7894 kPretenureDataOffset + kPointerSize;
7895 static const int kDependentCodeOffset =
7896 kPretenureCreateCountOffset + kPointerSize;
7897 static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize;
7898 static const int kSize = kWeakNextOffset + kPointerSize;
7900 // During mark compact we need to take special care for the dependent code
7902 static const int kPointerFieldsBeginOffset = kTransitionInfoOffset;
7903 static const int kPointerFieldsEndOffset = kWeakNextOffset;
7905 // For other visitors, use the fixed body descriptor below.
7906 typedef FixedBodyDescriptor<HeapObject::kHeaderSize,
7907 kDependentCodeOffset + kPointerSize,
7908 kSize> BodyDescriptor;
7911 inline bool PretenuringDecisionMade();
7913 DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite);
7917 class AllocationMemento: public Struct {
7919 static const int kAllocationSiteOffset = HeapObject::kHeaderSize;
7920 static const int kSize = kAllocationSiteOffset + kPointerSize;
7922 DECL_ACCESSORS(allocation_site, Object)
7924 inline bool IsValid();
7925 inline AllocationSite* GetAllocationSite();
7927 DECLARE_PRINTER(AllocationMemento)
7928 DECLARE_VERIFIER(AllocationMemento)
7930 DECLARE_CAST(AllocationMemento)
7933 DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento);
7937 // Representation of a slow alias as part of a sloppy arguments objects.
7938 // For fast aliases (if HasSloppyArgumentsElements()):
7939 // - the parameter map contains an index into the context
7940 // - all attributes of the element have default values
7941 // For slow aliases (if HasDictionaryArgumentsElements()):
7942 // - the parameter map contains no fast alias mapping (i.e. the hole)
7943 // - this struct (in the slow backing store) contains an index into the context
7944 // - all attributes are available as part if the property details
7945 class AliasedArgumentsEntry: public Struct {
7947 inline int aliased_context_slot() const;
7948 inline void set_aliased_context_slot(int count);
7950 DECLARE_CAST(AliasedArgumentsEntry)
7952 // Dispatched behavior.
7953 DECLARE_PRINTER(AliasedArgumentsEntry)
7954 DECLARE_VERIFIER(AliasedArgumentsEntry)
7956 static const int kAliasedContextSlot = HeapObject::kHeaderSize;
7957 static const int kSize = kAliasedContextSlot + kPointerSize;
7960 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
7964 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
7965 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
7968 class StringHasher {
7970 explicit inline StringHasher(int length, uint32_t seed);
7972 template <typename schar>
7973 static inline uint32_t HashSequentialString(const schar* chars,
7977 // Reads all the data, even for long strings and computes the utf16 length.
7978 static uint32_t ComputeUtf8Hash(Vector<const char> chars,
7980 int* utf16_length_out);
7982 // Calculated hash value for a string consisting of 1 to
7983 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
7984 // value is represented decimal value.
7985 static uint32_t MakeArrayIndexHash(uint32_t value, int length);
7987 // No string is allowed to have a hash of zero. That value is reserved
7988 // for internal properties. If the hash calculation yields zero then we
7990 static const int kZeroHash = 27;
7992 // Reusable parts of the hashing algorithm.
7993 INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c));
7994 INLINE(static uint32_t GetHashCore(uint32_t running_hash));
7995 INLINE(static uint32_t ComputeRunningHash(uint32_t running_hash,
7996 const uc16* chars, int length));
7997 INLINE(static uint32_t ComputeRunningHashOneByte(uint32_t running_hash,
8002 // Returns the value to store in the hash field of a string with
8003 // the given length and contents.
8004 uint32_t GetHashField();
8005 // Returns true if the hash of this string can be computed without
8006 // looking at the contents.
8007 inline bool has_trivial_hash();
8008 // Adds a block of characters to the hash.
8009 template<typename Char>
8010 inline void AddCharacters(const Char* chars, int len);
8013 // Add a character to the hash.
8014 inline void AddCharacter(uint16_t c);
8015 // Update index. Returns true if string is still an index.
8016 inline bool UpdateIndex(uint16_t c);
8019 uint32_t raw_running_hash_;
8020 uint32_t array_index_;
8021 bool is_array_index_;
8022 bool is_first_char_;
8023 DISALLOW_COPY_AND_ASSIGN(StringHasher);
8027 class IteratingStringHasher : public StringHasher {
8029 static inline uint32_t Hash(String* string, uint32_t seed);
8030 inline void VisitOneByteString(const uint8_t* chars, int length);
8031 inline void VisitTwoByteString(const uint16_t* chars, int length);
8034 inline IteratingStringHasher(int len, uint32_t seed);
8035 void VisitConsString(ConsString* cons_string);
8036 DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher);
8040 // The characteristics of a string are stored in its map. Retrieving these
8041 // few bits of information is moderately expensive, involving two memory
8042 // loads where the second is dependent on the first. To improve efficiency
8043 // the shape of the string is given its own class so that it can be retrieved
8044 // once and used for several string operations. A StringShape is small enough
8045 // to be passed by value and is immutable, but be aware that flattening a
8046 // string can potentially alter its shape. Also be aware that a GC caused by
8047 // something else can alter the shape of a string due to ConsString
8048 // shortcutting. Keeping these restrictions in mind has proven to be error-
8049 // prone and so we no longer put StringShapes in variables unless there is a
8050 // concrete performance benefit at that particular point in the code.
8051 class StringShape BASE_EMBEDDED {
8053 inline explicit StringShape(const String* s);
8054 inline explicit StringShape(Map* s);
8055 inline explicit StringShape(InstanceType t);
8056 inline bool IsSequential();
8057 inline bool IsExternal();
8058 inline bool IsCons();
8059 inline bool IsSliced();
8060 inline bool IsIndirect();
8061 inline bool IsExternalOneByte();
8062 inline bool IsExternalTwoByte();
8063 inline bool IsSequentialOneByte();
8064 inline bool IsSequentialTwoByte();
8065 inline bool IsInternalized();
8066 inline StringRepresentationTag representation_tag();
8067 inline uint32_t encoding_tag();
8068 inline uint32_t full_representation_tag();
8069 inline uint32_t size_tag();
8071 inline uint32_t type() { return type_; }
8072 inline void invalidate() { valid_ = false; }
8073 inline bool valid() { return valid_; }
8075 inline void invalidate() { }
8081 inline void set_valid() { valid_ = true; }
8084 inline void set_valid() { }
8089 // The Name abstract class captures anything that can be used as a property
8090 // name, i.e., strings and symbols. All names store a hash value.
8091 class Name: public HeapObject {
8093 // Get and set the hash field of the name.
8094 inline uint32_t hash_field();
8095 inline void set_hash_field(uint32_t value);
8097 // Tells whether the hash code has been computed.
8098 inline bool HasHashCode();
8100 // Returns a hash value used for the property table
8101 inline uint32_t Hash();
8103 // Equality operations.
8104 inline bool Equals(Name* other);
8105 inline static bool Equals(Handle<Name> one, Handle<Name> two);
8108 inline bool AsArrayIndex(uint32_t* index);
8110 // If the name is private, it can only name own properties.
8111 inline bool IsPrivate();
8113 // If the name is a non-flat string, this method returns a flat version of the
8114 // string. Otherwise it'll just return the input.
8115 static inline Handle<Name> Flatten(Handle<Name> name,
8116 PretenureFlag pretenure = NOT_TENURED);
8120 DECLARE_PRINTER(Name)
8122 void NameShortPrint();
8123 int NameShortPrint(Vector<char> str);
8126 // Layout description.
8127 static const int kHashFieldSlot = HeapObject::kHeaderSize;
8128 #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
8129 static const int kHashFieldOffset = kHashFieldSlot;
8131 static const int kHashFieldOffset = kHashFieldSlot + kIntSize;
8133 static const int kSize = kHashFieldSlot + kPointerSize;
8135 // Mask constant for checking if a name has a computed hash code
8136 // and if it is a string that is an array index. The least significant bit
8137 // indicates whether a hash code has been computed. If the hash code has
8138 // been computed the 2nd bit tells whether the string can be used as an
8140 static const int kHashNotComputedMask = 1;
8141 static const int kIsNotArrayIndexMask = 1 << 1;
8142 static const int kNofHashBitFields = 2;
8144 // Shift constant retrieving hash code from hash field.
8145 static const int kHashShift = kNofHashBitFields;
8147 // Only these bits are relevant in the hash, since the top two are shifted
8149 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
8151 // Array index strings this short can keep their index in the hash field.
8152 static const int kMaxCachedArrayIndexLength = 7;
8154 // For strings which are array indexes the hash value has the string length
8155 // mixed into the hash, mainly to avoid a hash value of zero which would be
8156 // the case for the string '0'. 24 bits are used for the array index value.
8157 static const int kArrayIndexValueBits = 24;
8158 static const int kArrayIndexLengthBits =
8159 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8161 STATIC_ASSERT((kArrayIndexLengthBits > 0));
8163 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8164 kArrayIndexValueBits> {}; // NOLINT
8165 class ArrayIndexLengthBits : public BitField<unsigned int,
8166 kNofHashBitFields + kArrayIndexValueBits,
8167 kArrayIndexLengthBits> {}; // NOLINT
8169 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8170 // could use a mask to test if the length of string is less than or equal to
8171 // kMaxCachedArrayIndexLength.
8172 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8174 static const unsigned int kContainsCachedArrayIndexMask =
8175 (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8176 << ArrayIndexLengthBits::kShift) |
8177 kIsNotArrayIndexMask;
8179 // Value of empty hash field indicating that the hash is not computed.
8180 static const int kEmptyHashField =
8181 kIsNotArrayIndexMask | kHashNotComputedMask;
8184 static inline bool IsHashFieldComputed(uint32_t field);
8187 DISALLOW_IMPLICIT_CONSTRUCTORS(Name);
8192 class Symbol: public Name {
8194 // [name]: The print name of a symbol, or undefined if none.
8195 DECL_ACCESSORS(name, Object)
8197 DECL_ACCESSORS(flags, Smi)
8199 // [is_private]: Whether this is a private symbol. Private symbols can only
8200 // be used to designate own properties of objects.
8201 DECL_BOOLEAN_ACCESSORS(is_private)
8203 DECLARE_CAST(Symbol)
8205 // Dispatched behavior.
8206 DECLARE_PRINTER(Symbol)
8207 DECLARE_VERIFIER(Symbol)
8209 // Layout description.
8210 static const int kNameOffset = Name::kSize;
8211 static const int kFlagsOffset = kNameOffset + kPointerSize;
8212 static const int kSize = kFlagsOffset + kPointerSize;
8214 typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor;
8216 void SymbolShortPrint(std::ostream& os);
8219 static const int kPrivateBit = 0;
8221 const char* PrivateSymbolToName() const;
8224 friend class Name; // For PrivateSymbolToName.
8227 DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol);
8233 // The String abstract class captures JavaScript string values:
8236 // 4.3.16 String Value
8237 // A string value is a member of the type String and is a finite
8238 // ordered sequence of zero or more 16-bit unsigned integer values.
8240 // All string values have a length field.
8241 class String: public Name {
8243 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING };
8245 // Array index strings this short can keep their index in the hash field.
8246 static const int kMaxCachedArrayIndexLength = 7;
8248 // For strings which are array indexes the hash value has the string length
8249 // mixed into the hash, mainly to avoid a hash value of zero which would be
8250 // the case for the string '0'. 24 bits are used for the array index value.
8251 static const int kArrayIndexValueBits = 24;
8252 static const int kArrayIndexLengthBits =
8253 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8255 STATIC_ASSERT((kArrayIndexLengthBits > 0));
8257 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8258 kArrayIndexValueBits> {}; // NOLINT
8259 class ArrayIndexLengthBits : public BitField<unsigned int,
8260 kNofHashBitFields + kArrayIndexValueBits,
8261 kArrayIndexLengthBits> {}; // NOLINT
8263 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8264 // could use a mask to test if the length of string is less than or equal to
8265 // kMaxCachedArrayIndexLength.
8266 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8268 static const unsigned int kContainsCachedArrayIndexMask =
8269 (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8270 << ArrayIndexLengthBits::kShift) |
8271 kIsNotArrayIndexMask;
8273 class SubStringRange {
8275 explicit inline SubStringRange(String* string, int first = 0,
8278 inline iterator begin();
8279 inline iterator end();
8287 // Representation of the flat content of a String.
8288 // A non-flat string doesn't have flat content.
8289 // A flat string has content that's encoded as a sequence of either
8290 // one-byte chars or two-byte UC16.
8291 // Returned by String::GetFlatContent().
8294 // Returns true if the string is flat and this structure contains content.
8295 bool IsFlat() { return state_ != NON_FLAT; }
8296 // Returns true if the structure contains one-byte content.
8297 bool IsOneByte() { return state_ == ONE_BYTE; }
8298 // Returns true if the structure contains two-byte content.
8299 bool IsTwoByte() { return state_ == TWO_BYTE; }
8301 // Return the one byte content of the string. Only use if IsOneByte()
8303 Vector<const uint8_t> ToOneByteVector() {
8304 DCHECK_EQ(ONE_BYTE, state_);
8305 return Vector<const uint8_t>(onebyte_start, length_);
8307 // Return the two-byte content of the string. Only use if IsTwoByte()
8309 Vector<const uc16> ToUC16Vector() {
8310 DCHECK_EQ(TWO_BYTE, state_);
8311 return Vector<const uc16>(twobyte_start, length_);
8315 DCHECK(i < length_);
8316 DCHECK(state_ != NON_FLAT);
8317 if (state_ == ONE_BYTE) return onebyte_start[i];
8318 return twobyte_start[i];
8321 bool UsesSameString(const FlatContent& other) const {
8322 return onebyte_start == other.onebyte_start;
8326 enum State { NON_FLAT, ONE_BYTE, TWO_BYTE };
8328 // Constructors only used by String::GetFlatContent().
8329 explicit FlatContent(const uint8_t* start, int length)
8330 : onebyte_start(start), length_(length), state_(ONE_BYTE) {}
8331 explicit FlatContent(const uc16* start, int length)
8332 : twobyte_start(start), length_(length), state_(TWO_BYTE) { }
8333 FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { }
8336 const uint8_t* onebyte_start;
8337 const uc16* twobyte_start;
8342 friend class String;
8343 friend class IterableSubString;
8346 template <typename Char>
8347 INLINE(Vector<const Char> GetCharVector());
8349 // Get and set the length of the string.
8350 inline int length() const;
8351 inline void set_length(int value);
8353 // Get and set the length of the string using acquire loads and release
8355 inline int synchronized_length() const;
8356 inline void synchronized_set_length(int value);
8358 // Returns whether this string has only one-byte chars, i.e. all of them can
8359 // be one-byte encoded. This might be the case even if the string is
8360 // two-byte. Such strings may appear when the embedder prefers
8361 // two-byte external representations even for one-byte data.
8362 inline bool IsOneByteRepresentation() const;
8363 inline bool IsTwoByteRepresentation() const;
8365 // Cons and slices have an encoding flag that may not represent the actual
8366 // encoding of the underlying string. This is taken into account here.
8367 // Requires: this->IsFlat()
8368 inline bool IsOneByteRepresentationUnderneath();
8369 inline bool IsTwoByteRepresentationUnderneath();
8371 // NOTE: this should be considered only a hint. False negatives are
8373 inline bool HasOnlyOneByteChars();
8375 // Get and set individual two byte chars in the string.
8376 inline void Set(int index, uint16_t value);
8377 // Get individual two byte char in the string. Repeated calls
8378 // to this method are not efficient unless the string is flat.
8379 INLINE(uint16_t Get(int index));
8381 // ES6 section 7.1.3.1 ToNumber Applied to the String Type
8382 static Handle<Object> ToNumber(Handle<String> subject);
8384 // Flattens the string. Checks first inline to see if it is
8385 // necessary. Does nothing if the string is not a cons string.
8386 // Flattening allocates a sequential string with the same data as
8387 // the given string and mutates the cons string to a degenerate
8388 // form, where the first component is the new sequential string and
8389 // the second component is the empty string. If allocation fails,
8390 // this function returns a failure. If flattening succeeds, this
8391 // function returns the sequential string that is now the first
8392 // component of the cons string.
8394 // Degenerate cons strings are handled specially by the garbage
8395 // collector (see IsShortcutCandidate).
8397 static inline Handle<String> Flatten(Handle<String> string,
8398 PretenureFlag pretenure = NOT_TENURED);
8400 // Tries to return the content of a flat string as a structure holding either
8401 // a flat vector of char or of uc16.
8402 // If the string isn't flat, and therefore doesn't have flat content, the
8403 // returned structure will report so, and can't provide a vector of either
8405 FlatContent GetFlatContent();
8407 // Returns the parent of a sliced string or first part of a flat cons string.
8408 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
8409 inline String* GetUnderlying();
8411 // String equality operations.
8412 inline bool Equals(String* other);
8413 inline static bool Equals(Handle<String> one, Handle<String> two);
8414 bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false);
8415 bool IsOneByteEqualTo(Vector<const uint8_t> str);
8416 bool IsTwoByteEqualTo(Vector<const uc16> str);
8418 // Return a UTF8 representation of the string. The string is null
8419 // terminated but may optionally contain nulls. Length is returned
8420 // in length_output if length_output is not a null pointer The string
8421 // should be nearly flat, otherwise the performance of this method may
8422 // be very slow (quadratic in the length). Setting robustness_flag to
8423 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8424 // handles unexpected data without causing assert failures and it does not
8425 // do any heap allocations. This is useful when printing stack traces.
8426 base::SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
8427 RobustnessFlag robustness_flag,
8428 int offset, int length,
8429 int* length_output = 0);
8430 base::SmartArrayPointer<char> ToCString(
8431 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
8432 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
8433 int* length_output = 0);
8435 // Return a 16 bit Unicode representation of the string.
8436 // The string should be nearly flat, otherwise the performance of
8437 // of this method may be very bad. Setting robustness_flag to
8438 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8439 // handles unexpected data without causing assert failures and it does not
8440 // do any heap allocations. This is useful when printing stack traces.
8441 base::SmartArrayPointer<uc16> ToWideCString(
8442 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
8444 bool ComputeArrayIndex(uint32_t* index);
8447 bool MakeExternal(v8::String::ExternalStringResource* resource);
8448 bool MakeExternal(v8::String::ExternalOneByteStringResource* resource);
8451 inline bool AsArrayIndex(uint32_t* index);
8453 DECLARE_CAST(String)
8455 void PrintOn(FILE* out);
8457 // For use during stack traces. Performs rudimentary sanity check.
8460 // Dispatched behavior.
8461 void StringShortPrint(StringStream* accumulator);
8462 void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT
8463 #if defined(DEBUG) || defined(OBJECT_PRINT)
8464 char* ToAsciiArray();
8466 DECLARE_PRINTER(String)
8467 DECLARE_VERIFIER(String)
8469 inline bool IsFlat();
8471 // Layout description.
8472 static const int kLengthOffset = Name::kSize;
8473 static const int kSize = kLengthOffset + kPointerSize;
8475 // Maximum number of characters to consider when trying to convert a string
8476 // value into an array index.
8477 static const int kMaxArrayIndexSize = 10;
8478 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
8481 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
8482 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
8483 static const int kMaxUtf16CodeUnit = 0xffff;
8484 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit;
8486 // Value of hash field containing computed hash equal to zero.
8487 static const int kEmptyStringHash = kIsNotArrayIndexMask;
8489 // Maximal string length.
8490 static const int kMaxLength = (1 << 28) - 16;
8492 // Max length for computing hash. For strings longer than this limit the
8493 // string length is used as the hash value.
8494 static const int kMaxHashCalcLength = 16383;
8496 // Limit for truncation in short printing.
8497 static const int kMaxShortPrintLength = 1024;
8499 // Support for regular expressions.
8500 const uc16* GetTwoByteData(unsigned start);
8502 // Helper function for flattening strings.
8503 template <typename sinkchar>
8504 static void WriteToFlat(String* source,
8509 // The return value may point to the first aligned word containing the first
8510 // non-one-byte character, rather than directly to the non-one-byte character.
8511 // If the return value is >= the passed length, the entire string was
8513 static inline int NonAsciiStart(const char* chars, int length) {
8514 const char* start = chars;
8515 const char* limit = chars + length;
8517 if (length >= kIntptrSize) {
8518 // Check unaligned bytes.
8519 while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) {
8520 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8521 return static_cast<int>(chars - start);
8525 // Check aligned words.
8526 DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F);
8527 const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80;
8528 while (chars + sizeof(uintptr_t) <= limit) {
8529 if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) {
8530 return static_cast<int>(chars - start);
8532 chars += sizeof(uintptr_t);
8535 // Check remaining unaligned bytes.
8536 while (chars < limit) {
8537 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8538 return static_cast<int>(chars - start);
8543 return static_cast<int>(chars - start);
8546 static inline bool IsAscii(const char* chars, int length) {
8547 return NonAsciiStart(chars, length) >= length;
8550 static inline bool IsAscii(const uint8_t* chars, int length) {
8552 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length;
8555 static inline int NonOneByteStart(const uc16* chars, int length) {
8556 const uc16* limit = chars + length;
8557 const uc16* start = chars;
8558 while (chars < limit) {
8559 if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
8562 return static_cast<int>(chars - start);
8565 static inline bool IsOneByte(const uc16* chars, int length) {
8566 return NonOneByteStart(chars, length) >= length;
8569 template<class Visitor>
8570 static inline ConsString* VisitFlat(Visitor* visitor,
8574 static Handle<FixedArray> CalculateLineEnds(Handle<String> string,
8575 bool include_ending_line);
8577 // Use the hash field to forward to the canonical internalized string
8578 // when deserializing an internalized string.
8579 inline void SetForwardedInternalizedString(String* string);
8580 inline String* GetForwardedInternalizedString();
8584 friend class StringTableInsertionKey;
8586 static Handle<String> SlowFlatten(Handle<ConsString> cons,
8587 PretenureFlag tenure);
8589 // Slow case of String::Equals. This implementation works on any strings
8590 // but it is most efficient on strings that are almost flat.
8591 bool SlowEquals(String* other);
8593 static bool SlowEquals(Handle<String> one, Handle<String> two);
8595 // Slow case of AsArrayIndex.
8596 bool SlowAsArrayIndex(uint32_t* index);
8598 // Compute and set the hash code.
8599 uint32_t ComputeAndSetHash();
8601 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
8605 // The SeqString abstract class captures sequential string values.
8606 class SeqString: public String {
8608 DECLARE_CAST(SeqString)
8610 // Layout description.
8611 static const int kHeaderSize = String::kSize;
8613 // Truncate the string in-place if possible and return the result.
8614 // In case of new_length == 0, the empty string is returned without
8615 // truncating the original string.
8616 MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string,
8619 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
8623 // The OneByteString class captures sequential one-byte string objects.
8624 // Each character in the OneByteString is an one-byte character.
8625 class SeqOneByteString: public SeqString {
8627 static const bool kHasOneByteEncoding = true;
8629 // Dispatched behavior.
8630 inline uint16_t SeqOneByteStringGet(int index);
8631 inline void SeqOneByteStringSet(int index, uint16_t value);
8633 // Get the address of the characters in this string.
8634 inline Address GetCharsAddress();
8636 inline uint8_t* GetChars();
8638 DECLARE_CAST(SeqOneByteString)
8640 // Garbage collection support. This method is called by the
8641 // garbage collector to compute the actual size of an OneByteString
8643 inline int SeqOneByteStringSize(InstanceType instance_type);
8645 // Computes the size for an OneByteString instance of a given length.
8646 static int SizeFor(int length) {
8647 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
8650 // Maximal memory usage for a single sequential one-byte string.
8651 static const int kMaxSize = 512 * MB - 1;
8652 STATIC_ASSERT((kMaxSize - kHeaderSize) >= String::kMaxLength);
8655 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString);
8659 // The TwoByteString class captures sequential unicode string objects.
8660 // Each character in the TwoByteString is a two-byte uint16_t.
8661 class SeqTwoByteString: public SeqString {
8663 static const bool kHasOneByteEncoding = false;
8665 // Dispatched behavior.
8666 inline uint16_t SeqTwoByteStringGet(int index);
8667 inline void SeqTwoByteStringSet(int index, uint16_t value);
8669 // Get the address of the characters in this string.
8670 inline Address GetCharsAddress();
8672 inline uc16* GetChars();
8675 const uint16_t* SeqTwoByteStringGetData(unsigned start);
8677 DECLARE_CAST(SeqTwoByteString)
8679 // Garbage collection support. This method is called by the
8680 // garbage collector to compute the actual size of a TwoByteString
8682 inline int SeqTwoByteStringSize(InstanceType instance_type);
8684 // Computes the size for a TwoByteString instance of a given length.
8685 static int SizeFor(int length) {
8686 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
8689 // Maximal memory usage for a single sequential two-byte string.
8690 static const int kMaxSize = 512 * MB - 1;
8691 STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >=
8692 String::kMaxLength);
8695 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
8699 // The ConsString class describes string values built by using the
8700 // addition operator on strings. A ConsString is a pair where the
8701 // first and second components are pointers to other string values.
8702 // One or both components of a ConsString can be pointers to other
8703 // ConsStrings, creating a binary tree of ConsStrings where the leaves
8704 // are non-ConsString string values. The string value represented by
8705 // a ConsString can be obtained by concatenating the leaf string
8706 // values in a left-to-right depth-first traversal of the tree.
8707 class ConsString: public String {
8709 // First string of the cons cell.
8710 inline String* first();
8711 // Doesn't check that the result is a string, even in debug mode. This is
8712 // useful during GC where the mark bits confuse the checks.
8713 inline Object* unchecked_first();
8714 inline void set_first(String* first,
8715 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
8717 // Second string of the cons cell.
8718 inline String* second();
8719 // Doesn't check that the result is a string, even in debug mode. This is
8720 // useful during GC where the mark bits confuse the checks.
8721 inline Object* unchecked_second();
8722 inline void set_second(String* second,
8723 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
8725 // Dispatched behavior.
8726 uint16_t ConsStringGet(int index);
8728 DECLARE_CAST(ConsString)
8730 // Layout description.
8731 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
8732 static const int kSecondOffset = kFirstOffset + kPointerSize;
8733 static const int kSize = kSecondOffset + kPointerSize;
8735 // Minimum length for a cons string.
8736 static const int kMinLength = 13;
8738 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
8741 DECLARE_VERIFIER(ConsString)
8744 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
8748 // The Sliced String class describes strings that are substrings of another
8749 // sequential string. The motivation is to save time and memory when creating
8750 // a substring. A Sliced String is described as a pointer to the parent,
8751 // the offset from the start of the parent string and the length. Using
8752 // a Sliced String therefore requires unpacking of the parent string and
8753 // adding the offset to the start address. A substring of a Sliced String
8754 // are not nested since the double indirection is simplified when creating
8755 // such a substring.
8756 // Currently missing features are:
8757 // - handling externalized parent strings
8758 // - external strings as parent
8759 // - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
8760 class SlicedString: public String {
8762 inline String* parent();
8763 inline void set_parent(String* parent,
8764 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
8765 inline int offset() const;
8766 inline void set_offset(int offset);
8768 // Dispatched behavior.
8769 uint16_t SlicedStringGet(int index);
8771 DECLARE_CAST(SlicedString)
8773 // Layout description.
8774 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
8775 static const int kOffsetOffset = kParentOffset + kPointerSize;
8776 static const int kSize = kOffsetOffset + kPointerSize;
8778 // Minimum length for a sliced string.
8779 static const int kMinLength = 13;
8781 typedef FixedBodyDescriptor<kParentOffset,
8782 kOffsetOffset + kPointerSize, kSize>
8785 DECLARE_VERIFIER(SlicedString)
8788 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
8792 // The ExternalString class describes string values that are backed by
8793 // a string resource that lies outside the V8 heap. ExternalStrings
8794 // consist of the length field common to all strings, a pointer to the
8795 // external resource. It is important to ensure (externally) that the
8796 // resource is not deallocated while the ExternalString is live in the
8799 // The API expects that all ExternalStrings are created through the
8800 // API. Therefore, ExternalStrings should not be used internally.
8801 class ExternalString: public String {
8803 DECLARE_CAST(ExternalString)
8805 // Layout description.
8806 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
8807 static const int kShortSize = kResourceOffset + kPointerSize;
8808 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
8809 static const int kSize = kResourceDataOffset + kPointerSize;
8811 static const int kMaxShortLength =
8812 (kShortSize - SeqString::kHeaderSize) / kCharSize;
8814 // Return whether external string is short (data pointer is not cached).
8815 inline bool is_short();
8817 STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset);
8820 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
8824 // The ExternalOneByteString class is an external string backed by an
8826 class ExternalOneByteString : public ExternalString {
8828 static const bool kHasOneByteEncoding = true;
8830 typedef v8::String::ExternalOneByteStringResource Resource;
8832 // The underlying resource.
8833 inline const Resource* resource();
8834 inline void set_resource(const Resource* buffer);
8836 // Update the pointer cache to the external character array.
8837 // The cached pointer is always valid, as the external character array does =
8838 // not move during lifetime. Deserialization is the only exception, after
8839 // which the pointer cache has to be refreshed.
8840 inline void update_data_cache();
8842 inline const uint8_t* GetChars();
8844 // Dispatched behavior.
8845 inline uint16_t ExternalOneByteStringGet(int index);
8847 DECLARE_CAST(ExternalOneByteString)
8849 // Garbage collection support.
8850 inline void ExternalOneByteStringIterateBody(ObjectVisitor* v);
8852 template <typename StaticVisitor>
8853 inline void ExternalOneByteStringIterateBody();
8856 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString);
8860 // The ExternalTwoByteString class is an external string backed by a UTF-16
8862 class ExternalTwoByteString: public ExternalString {
8864 static const bool kHasOneByteEncoding = false;
8866 typedef v8::String::ExternalStringResource Resource;
8868 // The underlying string resource.
8869 inline const Resource* resource();
8870 inline void set_resource(const Resource* buffer);
8872 // Update the pointer cache to the external character array.
8873 // The cached pointer is always valid, as the external character array does =
8874 // not move during lifetime. Deserialization is the only exception, after
8875 // which the pointer cache has to be refreshed.
8876 inline void update_data_cache();
8878 inline const uint16_t* GetChars();
8880 // Dispatched behavior.
8881 inline uint16_t ExternalTwoByteStringGet(int index);
8884 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
8886 DECLARE_CAST(ExternalTwoByteString)
8888 // Garbage collection support.
8889 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
8891 template<typename StaticVisitor>
8892 inline void ExternalTwoByteStringIterateBody();
8895 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
8899 // Utility superclass for stack-allocated objects that must be updated
8900 // on gc. It provides two ways for the gc to update instances, either
8901 // iterating or updating after gc.
8902 class Relocatable BASE_EMBEDDED {
8904 explicit inline Relocatable(Isolate* isolate);
8905 inline virtual ~Relocatable();
8906 virtual void IterateInstance(ObjectVisitor* v) { }
8907 virtual void PostGarbageCollection() { }
8909 static void PostGarbageCollectionProcessing(Isolate* isolate);
8910 static int ArchiveSpacePerThread();
8911 static char* ArchiveState(Isolate* isolate, char* to);
8912 static char* RestoreState(Isolate* isolate, char* from);
8913 static void Iterate(Isolate* isolate, ObjectVisitor* v);
8914 static void Iterate(ObjectVisitor* v, Relocatable* top);
8915 static char* Iterate(ObjectVisitor* v, char* t);
8923 // A flat string reader provides random access to the contents of a
8924 // string independent of the character width of the string. The handle
8925 // must be valid as long as the reader is being used.
8926 class FlatStringReader : public Relocatable {
8928 FlatStringReader(Isolate* isolate, Handle<String> str);
8929 FlatStringReader(Isolate* isolate, Vector<const char> input);
8930 void PostGarbageCollection();
8931 inline uc32 Get(int index);
8932 template <typename Char>
8933 inline Char Get(int index);
8934 int length() { return length_; }
8943 // This maintains an off-stack representation of the stack frames required
8944 // to traverse a ConsString, allowing an entirely iterative and restartable
8945 // traversal of the entire string
8946 class ConsStringIterator {
8948 inline ConsStringIterator() {}
8949 inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) {
8950 Reset(cons_string, offset);
8952 inline void Reset(ConsString* cons_string, int offset = 0) {
8954 // Next will always return NULL.
8955 if (cons_string == NULL) return;
8956 Initialize(cons_string, offset);
8958 // Returns NULL when complete.
8959 inline String* Next(int* offset_out) {
8961 if (depth_ == 0) return NULL;
8962 return Continue(offset_out);
8966 static const int kStackSize = 32;
8967 // Use a mask instead of doing modulo operations for stack wrapping.
8968 static const int kDepthMask = kStackSize-1;
8969 STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize));
8970 static inline int OffsetForDepth(int depth);
8972 inline void PushLeft(ConsString* string);
8973 inline void PushRight(ConsString* string);
8974 inline void AdjustMaximumDepth();
8976 inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; }
8977 void Initialize(ConsString* cons_string, int offset);
8978 String* Continue(int* offset_out);
8979 String* NextLeaf(bool* blew_stack);
8980 String* Search(int* offset_out);
8982 // Stack must always contain only frames for which right traversal
8983 // has not yet been performed.
8984 ConsString* frames_[kStackSize];
8989 DISALLOW_COPY_AND_ASSIGN(ConsStringIterator);
8993 class StringCharacterStream {
8995 inline StringCharacterStream(String* string,
8997 inline uint16_t GetNext();
8998 inline bool HasMore();
8999 inline void Reset(String* string, int offset = 0);
9000 inline void VisitOneByteString(const uint8_t* chars, int length);
9001 inline void VisitTwoByteString(const uint16_t* chars, int length);
9004 ConsStringIterator iter_;
9007 const uint8_t* buffer8_;
9008 const uint16_t* buffer16_;
9010 const uint8_t* end_;
9011 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream);
9015 template <typename T>
9016 class VectorIterator {
9018 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
9019 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
9020 T GetNext() { return data_[index_++]; }
9021 bool has_more() { return index_ < data_.length(); }
9023 Vector<const T> data_;
9028 // The Oddball describes objects null, undefined, true, and false.
9029 class Oddball: public HeapObject {
9031 // [to_string]: Cached to_string computed at startup.
9032 DECL_ACCESSORS(to_string, String)
9034 // [to_number]: Cached to_number computed at startup.
9035 DECL_ACCESSORS(to_number, Object)
9037 // [typeof]: Cached type_of computed at startup.
9038 DECL_ACCESSORS(type_of, String)
9040 inline byte kind() const;
9041 inline void set_kind(byte kind);
9043 DECLARE_CAST(Oddball)
9045 // Dispatched behavior.
9046 DECLARE_VERIFIER(Oddball)
9048 // Initialize the fields.
9049 static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
9050 const char* to_string, Handle<Object> to_number,
9051 const char* type_of, byte kind);
9053 // Layout description.
9054 static const int kToStringOffset = HeapObject::kHeaderSize;
9055 static const int kToNumberOffset = kToStringOffset + kPointerSize;
9056 static const int kTypeOfOffset = kToNumberOffset + kPointerSize;
9057 static const int kKindOffset = kTypeOfOffset + kPointerSize;
9058 static const int kSize = kKindOffset + kPointerSize;
9060 static const byte kFalse = 0;
9061 static const byte kTrue = 1;
9062 static const byte kNotBooleanMask = ~1;
9063 static const byte kTheHole = 2;
9064 static const byte kNull = 3;
9065 static const byte kArgumentMarker = 4;
9066 static const byte kUndefined = 5;
9067 static const byte kUninitialized = 6;
9068 static const byte kOther = 7;
9069 static const byte kException = 8;
9071 typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize,
9072 kSize> BodyDescriptor;
9074 STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
9075 STATIC_ASSERT(kNull == Internals::kNullOddballKind);
9076 STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);
9079 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
9083 class Cell: public HeapObject {
9085 // [value]: value of the cell.
9086 DECL_ACCESSORS(value, Object)
9090 static inline Cell* FromValueAddress(Address value) {
9091 Object* result = FromAddress(value - kValueOffset);
9092 return static_cast<Cell*>(result);
9095 inline Address ValueAddress() {
9096 return address() + kValueOffset;
9099 // Dispatched behavior.
9100 DECLARE_PRINTER(Cell)
9101 DECLARE_VERIFIER(Cell)
9103 // Layout description.
9104 static const int kValueOffset = HeapObject::kHeaderSize;
9105 static const int kSize = kValueOffset + kPointerSize;
9107 typedef FixedBodyDescriptor<kValueOffset,
9108 kValueOffset + kPointerSize,
9109 kSize> BodyDescriptor;
9112 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell);
9116 class PropertyCell : public HeapObject {
9118 // [property_details]: details of the global property.
9119 DECL_ACCESSORS(property_details_raw, Object)
9120 // [value]: value of the global property.
9121 DECL_ACCESSORS(value, Object)
9122 // [dependent_code]: dependent code that depends on the type of the global
9124 DECL_ACCESSORS(dependent_code, DependentCode)
9126 inline PropertyDetails property_details();
9127 inline void set_property_details(PropertyDetails details);
9129 PropertyCellConstantType GetConstantType();
9131 // Computes the new type of the cell's contents for the given value, but
9132 // without actually modifying the details.
9133 static PropertyCellType UpdatedType(Handle<PropertyCell> cell,
9134 Handle<Object> value,
9135 PropertyDetails details);
9136 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry,
9137 Handle<Object> value, PropertyDetails details);
9139 static Handle<PropertyCell> InvalidateEntry(
9140 Handle<GlobalDictionary> dictionary, int entry);
9142 static void SetValueWithInvalidation(Handle<PropertyCell> cell,
9143 Handle<Object> new_value);
9145 DECLARE_CAST(PropertyCell)
9147 // Dispatched behavior.
9148 DECLARE_PRINTER(PropertyCell)
9149 DECLARE_VERIFIER(PropertyCell)
9151 // Layout description.
9152 static const int kDetailsOffset = HeapObject::kHeaderSize;
9153 static const int kValueOffset = kDetailsOffset + kPointerSize;
9154 static const int kDependentCodeOffset = kValueOffset + kPointerSize;
9155 static const int kSize = kDependentCodeOffset + kPointerSize;
9157 static const int kPointerFieldsBeginOffset = kValueOffset;
9158 static const int kPointerFieldsEndOffset = kSize;
9160 typedef FixedBodyDescriptor<kValueOffset,
9162 kSize> BodyDescriptor;
9165 DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell);
9169 class WeakCell : public HeapObject {
9171 inline Object* value() const;
9173 // This should not be called by anyone except GC.
9174 inline void clear();
9176 // This should not be called by anyone except allocator.
9177 inline void initialize(HeapObject* value);
9179 inline bool cleared() const;
9181 DECL_ACCESSORS(next, Object)
9183 inline void clear_next(Heap* heap);
9185 inline bool next_cleared();
9187 DECLARE_CAST(WeakCell)
9189 DECLARE_PRINTER(WeakCell)
9190 DECLARE_VERIFIER(WeakCell)
9192 // Layout description.
9193 static const int kValueOffset = HeapObject::kHeaderSize;
9194 static const int kNextOffset = kValueOffset + kPointerSize;
9195 static const int kSize = kNextOffset + kPointerSize;
9197 typedef FixedBodyDescriptor<kValueOffset, kSize, kSize> BodyDescriptor;
9200 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakCell);
9204 // The JSProxy describes EcmaScript Harmony proxies
9205 class JSProxy: public JSReceiver {
9207 // [handler]: The handler property.
9208 DECL_ACCESSORS(handler, Object)
9210 // [hash]: The hash code property (undefined if not initialized yet).
9211 DECL_ACCESSORS(hash, Object)
9213 DECLARE_CAST(JSProxy)
9215 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithHandler(
9216 Handle<JSProxy> proxy,
9217 Handle<Object> receiver,
9220 // If the handler defines an accessor property with a setter, invoke it.
9221 // If it defines an accessor property without a setter, or a data property
9222 // that is read-only, throw. In all these cases set '*done' to true,
9223 // otherwise set it to false.
9225 static MaybeHandle<Object> SetPropertyViaPrototypesWithHandler(
9226 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
9227 Handle<Object> value, LanguageMode language_mode, bool* done);
9229 MUST_USE_RESULT static Maybe<PropertyAttributes>
9230 GetPropertyAttributesWithHandler(Handle<JSProxy> proxy,
9231 Handle<Object> receiver,
9233 MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler(
9234 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
9235 Handle<Object> value, LanguageMode language_mode);
9237 // Turn the proxy into an (empty) JSObject.
9238 static void Fix(Handle<JSProxy> proxy);
9240 // Initializes the body after the handler slot.
9241 inline void InitializeBody(int object_size, Object* value);
9243 // Invoke a trap by name. If the trap does not exist on this's handler,
9244 // but derived_trap is non-NULL, invoke that instead. May cause GC.
9245 MUST_USE_RESULT static MaybeHandle<Object> CallTrap(
9246 Handle<JSProxy> proxy,
9248 Handle<Object> derived_trap,
9250 Handle<Object> args[]);
9252 // Dispatched behavior.
9253 DECLARE_PRINTER(JSProxy)
9254 DECLARE_VERIFIER(JSProxy)
9256 // Layout description. We add padding so that a proxy has the same
9257 // size as a virgin JSObject. This is essential for becoming a JSObject
9259 static const int kHandlerOffset = HeapObject::kHeaderSize;
9260 static const int kHashOffset = kHandlerOffset + kPointerSize;
9261 static const int kPaddingOffset = kHashOffset + kPointerSize;
9262 static const int kSize = JSObject::kHeaderSize;
9263 static const int kHeaderSize = kPaddingOffset;
9264 static const int kPaddingSize = kSize - kPaddingOffset;
9266 STATIC_ASSERT(kPaddingSize >= 0);
9268 typedef FixedBodyDescriptor<kHandlerOffset,
9270 kSize> BodyDescriptor;
9273 friend class JSReceiver;
9275 MUST_USE_RESULT static Maybe<bool> HasPropertyWithHandler(
9276 Handle<JSProxy> proxy, Handle<Name> name);
9278 MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithHandler(
9279 Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode);
9281 MUST_USE_RESULT Object* GetIdentityHash();
9283 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
9285 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
9289 class JSFunctionProxy: public JSProxy {
9291 // [call_trap]: The call trap.
9292 DECL_ACCESSORS(call_trap, Object)
9294 // [construct_trap]: The construct trap.
9295 DECL_ACCESSORS(construct_trap, Object)
9297 DECLARE_CAST(JSFunctionProxy)
9299 // Dispatched behavior.
9300 DECLARE_PRINTER(JSFunctionProxy)
9301 DECLARE_VERIFIER(JSFunctionProxy)
9303 // Layout description.
9304 static const int kCallTrapOffset = JSProxy::kPaddingOffset;
9305 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
9306 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
9307 static const int kSize = JSFunction::kSize;
9308 static const int kPaddingSize = kSize - kPaddingOffset;
9310 STATIC_ASSERT(kPaddingSize >= 0);
9312 typedef FixedBodyDescriptor<kHandlerOffset,
9313 kConstructTrapOffset + kPointerSize,
9314 kSize> BodyDescriptor;
9317 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
9321 class JSCollection : public JSObject {
9323 // [table]: the backing hash table
9324 DECL_ACCESSORS(table, Object)
9326 static const int kTableOffset = JSObject::kHeaderSize;
9327 static const int kSize = kTableOffset + kPointerSize;
9330 DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection);
9334 // The JSSet describes EcmaScript Harmony sets
9335 class JSSet : public JSCollection {
9339 static void Initialize(Handle<JSSet> set, Isolate* isolate);
9340 static void Clear(Handle<JSSet> set);
9342 // Dispatched behavior.
9343 DECLARE_PRINTER(JSSet)
9344 DECLARE_VERIFIER(JSSet)
9347 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
9351 // The JSMap describes EcmaScript Harmony maps
9352 class JSMap : public JSCollection {
9356 static void Initialize(Handle<JSMap> map, Isolate* isolate);
9357 static void Clear(Handle<JSMap> map);
9359 // Dispatched behavior.
9360 DECLARE_PRINTER(JSMap)
9361 DECLARE_VERIFIER(JSMap)
9364 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
9368 // OrderedHashTableIterator is an iterator that iterates over the keys and
9369 // values of an OrderedHashTable.
9371 // The iterator has a reference to the underlying OrderedHashTable data,
9372 // [table], as well as the current [index] the iterator is at.
9374 // When the OrderedHashTable is rehashed it adds a reference from the old table
9375 // to the new table as well as storing enough data about the changes so that the
9376 // iterator [index] can be adjusted accordingly.
9378 // When the [Next] result from the iterator is requested, the iterator checks if
9379 // there is a newer table that it needs to transition to.
9380 template<class Derived, class TableType>
9381 class OrderedHashTableIterator: public JSObject {
9383 // [table]: the backing hash table mapping keys to values.
9384 DECL_ACCESSORS(table, Object)
9386 // [index]: The index into the data table.
9387 DECL_ACCESSORS(index, Object)
9389 // [kind]: The kind of iteration this is. One of the [Kind] enum values.
9390 DECL_ACCESSORS(kind, Object)
9393 void OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT
9396 static const int kTableOffset = JSObject::kHeaderSize;
9397 static const int kIndexOffset = kTableOffset + kPointerSize;
9398 static const int kKindOffset = kIndexOffset + kPointerSize;
9399 static const int kSize = kKindOffset + kPointerSize;
9407 // Whether the iterator has more elements. This needs to be called before
9408 // calling |CurrentKey| and/or |CurrentValue|.
9411 // Move the index forward one.
9413 set_index(Smi::FromInt(Smi::cast(index())->value() + 1));
9416 // Populates the array with the next key and value and then moves the iterator
9418 // This returns the |kind| or 0 if the iterator is already at the end.
9419 Smi* Next(JSArray* value_array);
9421 // Returns the current key of the iterator. This should only be called when
9422 // |HasMore| returns true.
9423 inline Object* CurrentKey();
9426 // Transitions the iterator to the non obsolete backing store. This is a NOP
9427 // if the [table] is not obsolete.
9430 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator);
9434 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator,
9437 // Dispatched behavior.
9438 DECLARE_PRINTER(JSSetIterator)
9439 DECLARE_VERIFIER(JSSetIterator)
9441 DECLARE_CAST(JSSetIterator)
9443 // Called by |Next| to populate the array. This allows the subclasses to
9444 // populate the array differently.
9445 inline void PopulateValueArray(FixedArray* array);
9448 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator);
9452 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
9455 // Dispatched behavior.
9456 DECLARE_PRINTER(JSMapIterator)
9457 DECLARE_VERIFIER(JSMapIterator)
9459 DECLARE_CAST(JSMapIterator)
9461 // Called by |Next| to populate the array. This allows the subclasses to
9462 // populate the array differently.
9463 inline void PopulateValueArray(FixedArray* array);
9466 // Returns the current value of the iterator. This should only be called when
9467 // |HasMore| returns true.
9468 inline Object* CurrentValue();
9470 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator);
9474 // Base class for both JSWeakMap and JSWeakSet
9475 class JSWeakCollection: public JSObject {
9477 // [table]: the backing hash table mapping keys to values.
9478 DECL_ACCESSORS(table, Object)
9480 // [next]: linked list of encountered weak maps during GC.
9481 DECL_ACCESSORS(next, Object)
9483 static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
9484 static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
9485 Handle<Object> value, int32_t hash);
9486 static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
9489 static const int kTableOffset = JSObject::kHeaderSize;
9490 static const int kNextOffset = kTableOffset + kPointerSize;
9491 static const int kSize = kNextOffset + kPointerSize;
9494 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection);
9498 // The JSWeakMap describes EcmaScript Harmony weak maps
9499 class JSWeakMap: public JSWeakCollection {
9501 DECLARE_CAST(JSWeakMap)
9503 // Dispatched behavior.
9504 DECLARE_PRINTER(JSWeakMap)
9505 DECLARE_VERIFIER(JSWeakMap)
9508 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
9512 // The JSWeakSet describes EcmaScript Harmony weak sets
9513 class JSWeakSet: public JSWeakCollection {
9515 DECLARE_CAST(JSWeakSet)
9517 // Dispatched behavior.
9518 DECLARE_PRINTER(JSWeakSet)
9519 DECLARE_VERIFIER(JSWeakSet)
9522 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet);
9526 // Whether a JSArrayBuffer is a SharedArrayBuffer or not.
9527 enum class SharedFlag { kNotShared, kShared };
9530 class JSArrayBuffer: public JSObject {
9532 // [backing_store]: backing memory for this array
9533 DECL_ACCESSORS(backing_store, void)
9535 // [byte_length]: length in bytes
9536 DECL_ACCESSORS(byte_length, Object)
9538 inline uint32_t bit_field() const;
9539 inline void set_bit_field(uint32_t bits);
9541 inline bool is_external();
9542 inline void set_is_external(bool value);
9544 inline bool is_neuterable();
9545 inline void set_is_neuterable(bool value);
9547 inline bool was_neutered();
9548 inline void set_was_neutered(bool value);
9550 inline bool is_shared();
9551 inline void set_is_shared(bool value);
9553 DECLARE_CAST(JSArrayBuffer)
9557 static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
9558 bool is_external, void* data, size_t allocated_length,
9559 SharedFlag shared = SharedFlag::kNotShared);
9561 static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
9562 Isolate* isolate, size_t allocated_length,
9563 bool initialize = true,
9564 SharedFlag shared = SharedFlag::kNotShared);
9566 // Dispatched behavior.
9567 DECLARE_PRINTER(JSArrayBuffer)
9568 DECLARE_VERIFIER(JSArrayBuffer)
9570 static const int kBackingStoreOffset = JSObject::kHeaderSize;
9571 static const int kByteLengthOffset = kBackingStoreOffset + kPointerSize;
9572 static const int kBitFieldSlot = kByteLengthOffset + kPointerSize;
9573 #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
9574 static const int kBitFieldOffset = kBitFieldSlot;
9576 static const int kBitFieldOffset = kBitFieldSlot + kIntSize;
9578 static const int kSize = kBitFieldSlot + kPointerSize;
9580 static const int kSizeWithInternalFields =
9581 kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize;
9583 class IsExternal : public BitField<bool, 1, 1> {};
9584 class IsNeuterable : public BitField<bool, 2, 1> {};
9585 class WasNeutered : public BitField<bool, 3, 1> {};
9586 class IsShared : public BitField<bool, 4, 1> {};
9589 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer);
9593 class JSArrayBufferView: public JSObject {
9595 // [buffer]: ArrayBuffer that this typed array views.
9596 DECL_ACCESSORS(buffer, Object)
9598 // [byte_offset]: offset of typed array in bytes.
9599 DECL_ACCESSORS(byte_offset, Object)
9601 // [byte_length]: length of typed array in bytes.
9602 DECL_ACCESSORS(byte_length, Object)
9604 DECLARE_CAST(JSArrayBufferView)
9606 DECLARE_VERIFIER(JSArrayBufferView)
9608 inline bool WasNeutered() const;
9610 static const int kBufferOffset = JSObject::kHeaderSize;
9611 static const int kByteOffsetOffset = kBufferOffset + kPointerSize;
9612 static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize;
9613 static const int kViewSize = kByteLengthOffset + kPointerSize;
9617 DECL_ACCESSORS(raw_byte_offset, Object)
9618 DECL_ACCESSORS(raw_byte_length, Object)
9621 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView);
9625 class JSTypedArray: public JSArrayBufferView {
9627 // [length]: length of typed array in elements.
9628 DECL_ACCESSORS(length, Object)
9629 inline uint32_t length_value() const;
9631 DECLARE_CAST(JSTypedArray)
9633 ExternalArrayType type();
9634 size_t element_size();
9636 Handle<JSArrayBuffer> GetBuffer();
9638 // Dispatched behavior.
9639 DECLARE_PRINTER(JSTypedArray)
9640 DECLARE_VERIFIER(JSTypedArray)
9642 static const int kLengthOffset = kViewSize + kPointerSize;
9643 static const int kSize = kLengthOffset + kPointerSize;
9645 static const int kSizeWithInternalFields =
9646 kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
9649 static Handle<JSArrayBuffer> MaterializeArrayBuffer(
9650 Handle<JSTypedArray> typed_array);
9652 DECL_ACCESSORS(raw_length, Object)
9655 DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray);
9659 class JSDataView: public JSArrayBufferView {
9661 DECLARE_CAST(JSDataView)
9663 // Dispatched behavior.
9664 DECLARE_PRINTER(JSDataView)
9665 DECLARE_VERIFIER(JSDataView)
9667 static const int kSize = kViewSize;
9669 static const int kSizeWithInternalFields =
9670 kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
9673 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView);
9677 // Foreign describes objects pointing from JavaScript to C structures.
9678 class Foreign: public HeapObject {
9680 // [address]: field containing the address.
9681 inline Address foreign_address();
9682 inline void set_foreign_address(Address value);
9684 DECLARE_CAST(Foreign)
9686 // Dispatched behavior.
9687 inline void ForeignIterateBody(ObjectVisitor* v);
9689 template<typename StaticVisitor>
9690 inline void ForeignIterateBody();
9692 // Dispatched behavior.
9693 DECLARE_PRINTER(Foreign)
9694 DECLARE_VERIFIER(Foreign)
9696 // Layout description.
9698 static const int kForeignAddressOffset = HeapObject::kHeaderSize;
9699 static const int kSize = kForeignAddressOffset + kPointerSize;
9701 STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset);
9704 DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
9708 // The JSArray describes JavaScript Arrays
9709 // Such an array can be in one of two modes:
9710 // - fast, backing storage is a FixedArray and length <= elements.length();
9711 // Please note: push and pop can be used to grow and shrink the array.
9712 // - slow, backing storage is a HashTable with numbers as keys.
9713 class JSArray: public JSObject {
9715 // [length]: The length property.
9716 DECL_ACCESSORS(length, Object)
9718 // Overload the length setter to skip write barrier when the length
9719 // is set to a smi. This matches the set function on FixedArray.
9720 inline void set_length(Smi* length);
9722 static bool HasReadOnlyLength(Handle<JSArray> array);
9723 static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index);
9724 static MaybeHandle<Object> ReadOnlyLengthError(Handle<JSArray> array);
9726 // Initialize the array with the given capacity. The function may
9727 // fail due to out-of-memory situations, but only if the requested
9728 // capacity is non-zero.
9729 static void Initialize(Handle<JSArray> array, int capacity, int length = 0);
9731 // If the JSArray has fast elements, and new_length would result in
9732 // normalization, returns true.
9733 bool SetLengthWouldNormalize(uint32_t new_length);
9734 static inline bool SetLengthWouldNormalize(Heap* heap, uint32_t new_length);
9736 // Initializes the array to a certain length.
9737 inline bool AllowsSetLength();
9739 static void SetLength(Handle<JSArray> array, uint32_t length);
9740 // Same as above but will also queue splice records if |array| is observed.
9741 static MaybeHandle<Object> ObservableSetLength(Handle<JSArray> array,
9744 // Set the content of the array to the content of storage.
9745 static inline void SetContent(Handle<JSArray> array,
9746 Handle<FixedArrayBase> storage);
9748 DECLARE_CAST(JSArray)
9750 // Dispatched behavior.
9751 DECLARE_PRINTER(JSArray)
9752 DECLARE_VERIFIER(JSArray)
9754 // Number of element slots to pre-allocate for an empty array.
9755 static const int kPreallocatedArrayElements = 4;
9757 // Layout description.
9758 static const int kLengthOffset = JSObject::kHeaderSize;
9759 static const int kSize = kLengthOffset + kPointerSize;
9762 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
9766 Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context,
9767 Handle<Map> initial_map);
9770 // JSRegExpResult is just a JSArray with a specific initial map.
9771 // This initial map adds in-object properties for "index" and "input"
9772 // properties, as assigned by RegExp.prototype.exec, which allows
9773 // faster creation of RegExp exec results.
9774 // This class just holds constants used when creating the result.
9775 // After creation the result must be treated as a JSArray in all regards.
9776 class JSRegExpResult: public JSArray {
9778 // Offsets of object fields.
9779 static const int kIndexOffset = JSArray::kSize;
9780 static const int kInputOffset = kIndexOffset + kPointerSize;
9781 static const int kSize = kInputOffset + kPointerSize;
9782 // Indices of in-object properties.
9783 static const int kIndexIndex = 0;
9784 static const int kInputIndex = 1;
9786 DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
9790 class AccessorInfo: public Struct {
9792 DECL_ACCESSORS(name, Object)
9793 DECL_ACCESSORS(flag, Smi)
9794 DECL_ACCESSORS(expected_receiver_type, Object)
9796 inline bool all_can_read();
9797 inline void set_all_can_read(bool value);
9799 inline bool all_can_write();
9800 inline void set_all_can_write(bool value);
9802 inline bool is_special_data_property();
9803 inline void set_is_special_data_property(bool value);
9805 inline PropertyAttributes property_attributes();
9806 inline void set_property_attributes(PropertyAttributes attributes);
9808 // Checks whether the given receiver is compatible with this accessor.
9809 static bool IsCompatibleReceiverMap(Isolate* isolate,
9810 Handle<AccessorInfo> info,
9812 inline bool IsCompatibleReceiver(Object* receiver);
9814 DECLARE_CAST(AccessorInfo)
9816 // Dispatched behavior.
9817 DECLARE_VERIFIER(AccessorInfo)
9819 // Append all descriptors to the array that are not already there.
9820 // Return number added.
9821 static int AppendUnique(Handle<Object> descriptors,
9822 Handle<FixedArray> array,
9823 int valid_descriptors);
9825 static const int kNameOffset = HeapObject::kHeaderSize;
9826 static const int kFlagOffset = kNameOffset + kPointerSize;
9827 static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
9828 static const int kSize = kExpectedReceiverTypeOffset + kPointerSize;
9831 inline bool HasExpectedReceiverType();
9833 // Bit positions in flag.
9834 static const int kAllCanReadBit = 0;
9835 static const int kAllCanWriteBit = 1;
9836 static const int kSpecialDataProperty = 2;
9837 class AttributesField : public BitField<PropertyAttributes, 3, 3> {};
9839 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
9843 // An accessor must have a getter, but can have no setter.
9845 // When setting a property, V8 searches accessors in prototypes.
9846 // If an accessor was found and it does not have a setter,
9847 // the request is ignored.
9849 // If the accessor in the prototype has the READ_ONLY property attribute, then
9850 // a new value is added to the derived object when the property is set.
9851 // This shadows the accessor in the prototype.
9852 class ExecutableAccessorInfo: public AccessorInfo {
9854 DECL_ACCESSORS(getter, Object)
9855 DECL_ACCESSORS(setter, Object)
9856 DECL_ACCESSORS(data, Object)
9858 DECLARE_CAST(ExecutableAccessorInfo)
9860 // Dispatched behavior.
9861 DECLARE_PRINTER(ExecutableAccessorInfo)
9862 DECLARE_VERIFIER(ExecutableAccessorInfo)
9864 static const int kGetterOffset = AccessorInfo::kSize;
9865 static const int kSetterOffset = kGetterOffset + kPointerSize;
9866 static const int kDataOffset = kSetterOffset + kPointerSize;
9867 static const int kSize = kDataOffset + kPointerSize;
9869 static void ClearSetter(Handle<ExecutableAccessorInfo> info);
9872 DISALLOW_IMPLICIT_CONSTRUCTORS(ExecutableAccessorInfo);
9876 // Support for JavaScript accessors: A pair of a getter and a setter. Each
9877 // accessor can either be
9878 // * a pointer to a JavaScript function or proxy: a real accessor
9879 // * undefined: considered an accessor by the spec, too, strangely enough
9880 // * the hole: an accessor which has not been set
9881 // * a pointer to a map: a transition used to ensure map sharing
9882 class AccessorPair: public Struct {
9884 DECL_ACCESSORS(getter, Object)
9885 DECL_ACCESSORS(setter, Object)
9887 DECLARE_CAST(AccessorPair)
9889 static Handle<AccessorPair> Copy(Handle<AccessorPair> pair);
9891 inline Object* get(AccessorComponent component);
9892 inline void set(AccessorComponent component, Object* value);
9894 // Note: Returns undefined instead in case of a hole.
9895 Object* GetComponent(AccessorComponent component);
9897 // Set both components, skipping arguments which are a JavaScript null.
9898 inline void SetComponents(Object* getter, Object* setter);
9900 inline bool Equals(AccessorPair* pair);
9901 inline bool Equals(Object* getter_value, Object* setter_value);
9903 inline bool ContainsAccessor();
9905 // Dispatched behavior.
9906 DECLARE_PRINTER(AccessorPair)
9907 DECLARE_VERIFIER(AccessorPair)
9909 static const int kGetterOffset = HeapObject::kHeaderSize;
9910 static const int kSetterOffset = kGetterOffset + kPointerSize;
9911 static const int kSize = kSetterOffset + kPointerSize;
9914 // Strangely enough, in addition to functions and harmony proxies, the spec
9915 // requires us to consider undefined as a kind of accessor, too:
9917 // Object.defineProperty(obj, "foo", {get: undefined});
9918 // assertTrue("foo" in obj);
9919 inline bool IsJSAccessor(Object* obj);
9921 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
9925 class AccessCheckInfo: public Struct {
9927 DECL_ACCESSORS(named_callback, Object)
9928 DECL_ACCESSORS(indexed_callback, Object)
9929 DECL_ACCESSORS(data, Object)
9931 DECLARE_CAST(AccessCheckInfo)
9933 // Dispatched behavior.
9934 DECLARE_PRINTER(AccessCheckInfo)
9935 DECLARE_VERIFIER(AccessCheckInfo)
9937 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
9938 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
9939 static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
9940 static const int kSize = kDataOffset + kPointerSize;
9943 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
9947 class InterceptorInfo: public Struct {
9949 DECL_ACCESSORS(getter, Object)
9950 DECL_ACCESSORS(setter, Object)
9951 DECL_ACCESSORS(query, Object)
9952 DECL_ACCESSORS(deleter, Object)
9953 DECL_ACCESSORS(enumerator, Object)
9954 DECL_ACCESSORS(data, Object)
9955 DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
9956 DECL_BOOLEAN_ACCESSORS(all_can_read)
9957 DECL_BOOLEAN_ACCESSORS(non_masking)
9959 inline int flags() const;
9960 inline void set_flags(int flags);
9962 DECLARE_CAST(InterceptorInfo)
9964 // Dispatched behavior.
9965 DECLARE_PRINTER(InterceptorInfo)
9966 DECLARE_VERIFIER(InterceptorInfo)
9968 static const int kGetterOffset = HeapObject::kHeaderSize;
9969 static const int kSetterOffset = kGetterOffset + kPointerSize;
9970 static const int kQueryOffset = kSetterOffset + kPointerSize;
9971 static const int kDeleterOffset = kQueryOffset + kPointerSize;
9972 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
9973 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
9974 static const int kFlagsOffset = kDataOffset + kPointerSize;
9975 static const int kSize = kFlagsOffset + kPointerSize;
9977 static const int kCanInterceptSymbolsBit = 0;
9978 static const int kAllCanReadBit = 1;
9979 static const int kNonMasking = 2;
9982 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
9986 class CallHandlerInfo: public Struct {
9988 DECL_ACCESSORS(callback, Object)
9989 DECL_ACCESSORS(data, Object)
9991 DECLARE_CAST(CallHandlerInfo)
9993 // Dispatched behavior.
9994 DECLARE_PRINTER(CallHandlerInfo)
9995 DECLARE_VERIFIER(CallHandlerInfo)
9997 static const int kCallbackOffset = HeapObject::kHeaderSize;
9998 static const int kDataOffset = kCallbackOffset + kPointerSize;
9999 static const int kSize = kDataOffset + kPointerSize;
10002 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
10006 class TemplateInfo: public Struct {
10008 DECL_ACCESSORS(tag, Object)
10009 inline int number_of_properties() const;
10010 inline void set_number_of_properties(int value);
10011 DECL_ACCESSORS(property_list, Object)
10012 DECL_ACCESSORS(property_accessors, Object)
10014 DECLARE_VERIFIER(TemplateInfo)
10016 static const int kTagOffset = HeapObject::kHeaderSize;
10017 static const int kNumberOfProperties = kTagOffset + kPointerSize;
10018 static const int kPropertyListOffset = kNumberOfProperties + kPointerSize;
10019 static const int kPropertyAccessorsOffset =
10020 kPropertyListOffset + kPointerSize;
10021 static const int kHeaderSize = kPropertyAccessorsOffset + kPointerSize;
10024 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
10028 class FunctionTemplateInfo: public TemplateInfo {
10030 DECL_ACCESSORS(serial_number, Object)
10031 DECL_ACCESSORS(call_code, Object)
10032 DECL_ACCESSORS(prototype_template, Object)
10033 DECL_ACCESSORS(parent_template, Object)
10034 DECL_ACCESSORS(named_property_handler, Object)
10035 DECL_ACCESSORS(indexed_property_handler, Object)
10036 DECL_ACCESSORS(instance_template, Object)
10037 DECL_ACCESSORS(class_name, Object)
10038 DECL_ACCESSORS(signature, Object)
10039 DECL_ACCESSORS(instance_call_handler, Object)
10040 DECL_ACCESSORS(access_check_info, Object)
10041 DECL_ACCESSORS(flag, Smi)
10043 inline int length() const;
10044 inline void set_length(int value);
10046 // Following properties use flag bits.
10047 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
10048 DECL_BOOLEAN_ACCESSORS(undetectable)
10049 // If the bit is set, object instances created by this function
10050 // requires access check.
10051 DECL_BOOLEAN_ACCESSORS(needs_access_check)
10052 DECL_BOOLEAN_ACCESSORS(read_only_prototype)
10053 DECL_BOOLEAN_ACCESSORS(remove_prototype)
10054 DECL_BOOLEAN_ACCESSORS(do_not_cache)
10055 DECL_BOOLEAN_ACCESSORS(instantiated)
10056 DECL_BOOLEAN_ACCESSORS(accept_any_receiver)
10058 DECLARE_CAST(FunctionTemplateInfo)
10060 // Dispatched behavior.
10061 DECLARE_PRINTER(FunctionTemplateInfo)
10062 DECLARE_VERIFIER(FunctionTemplateInfo)
10064 static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
10065 static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
10066 static const int kPrototypeTemplateOffset =
10067 kCallCodeOffset + kPointerSize;
10068 static const int kParentTemplateOffset =
10069 kPrototypeTemplateOffset + kPointerSize;
10070 static const int kNamedPropertyHandlerOffset =
10071 kParentTemplateOffset + kPointerSize;
10072 static const int kIndexedPropertyHandlerOffset =
10073 kNamedPropertyHandlerOffset + kPointerSize;
10074 static const int kInstanceTemplateOffset =
10075 kIndexedPropertyHandlerOffset + kPointerSize;
10076 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
10077 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
10078 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
10079 static const int kAccessCheckInfoOffset =
10080 kInstanceCallHandlerOffset + kPointerSize;
10081 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
10082 static const int kLengthOffset = kFlagOffset + kPointerSize;
10083 static const int kSize = kLengthOffset + kPointerSize;
10085 // Returns true if |object| is an instance of this function template.
10086 bool IsTemplateFor(Object* object);
10087 bool IsTemplateFor(Map* map);
10089 // Returns the holder JSObject if the function can legally be called with this
10090 // receiver. Returns Heap::null_value() if the call is illegal.
10091 Object* GetCompatibleReceiver(Isolate* isolate, Object* receiver);
10094 // Bit position in the flag, from least significant bit position.
10095 static const int kHiddenPrototypeBit = 0;
10096 static const int kUndetectableBit = 1;
10097 static const int kNeedsAccessCheckBit = 2;
10098 static const int kReadOnlyPrototypeBit = 3;
10099 static const int kRemovePrototypeBit = 4;
10100 static const int kDoNotCacheBit = 5;
10101 static const int kInstantiatedBit = 6;
10102 static const int kAcceptAnyReceiver = 7;
10104 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
10108 class ObjectTemplateInfo: public TemplateInfo {
10110 DECL_ACCESSORS(constructor, Object)
10111 DECL_ACCESSORS(internal_field_count, Object)
10113 DECLARE_CAST(ObjectTemplateInfo)
10115 // Dispatched behavior.
10116 DECLARE_PRINTER(ObjectTemplateInfo)
10117 DECLARE_VERIFIER(ObjectTemplateInfo)
10119 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
10120 static const int kInternalFieldCountOffset =
10121 kConstructorOffset + kPointerSize;
10122 static const int kSize = kInternalFieldCountOffset + kPointerSize;
10126 class TypeSwitchInfo: public Struct {
10128 DECL_ACCESSORS(types, Object)
10130 DECLARE_CAST(TypeSwitchInfo)
10132 // Dispatched behavior.
10133 DECLARE_PRINTER(TypeSwitchInfo)
10134 DECLARE_VERIFIER(TypeSwitchInfo)
10136 static const int kTypesOffset = Struct::kHeaderSize;
10137 static const int kSize = kTypesOffset + kPointerSize;
10141 // The DebugInfo class holds additional information for a function being
10143 class DebugInfo: public Struct {
10145 // The shared function info for the source being debugged.
10146 DECL_ACCESSORS(shared, SharedFunctionInfo)
10147 // Code object for the patched code. This code object is the code object
10148 // currently active for the function.
10149 DECL_ACCESSORS(code, Code)
10150 // Fixed array holding status information for each active break point.
10151 DECL_ACCESSORS(break_points, FixedArray)
10153 // Check if there is a break point at a code position.
10154 bool HasBreakPoint(int code_position);
10155 // Get the break point info object for a code position.
10156 Object* GetBreakPointInfo(int code_position);
10157 // Clear a break point.
10158 static void ClearBreakPoint(Handle<DebugInfo> debug_info,
10160 Handle<Object> break_point_object);
10161 // Set a break point.
10162 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
10163 int source_position, int statement_position,
10164 Handle<Object> break_point_object);
10165 // Get the break point objects for a code position.
10166 Handle<Object> GetBreakPointObjects(int code_position);
10167 // Find the break point info holding this break point object.
10168 static Handle<Object> FindBreakPointInfo(Handle<DebugInfo> debug_info,
10169 Handle<Object> break_point_object);
10170 // Get the number of break points for this function.
10171 int GetBreakPointCount();
10173 DECLARE_CAST(DebugInfo)
10175 // Dispatched behavior.
10176 DECLARE_PRINTER(DebugInfo)
10177 DECLARE_VERIFIER(DebugInfo)
10179 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
10180 static const int kCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
10181 static const int kBreakPointsStateIndex = kCodeIndex + kPointerSize;
10182 static const int kSize = kBreakPointsStateIndex + kPointerSize;
10184 static const int kEstimatedNofBreakPointsInFunction = 16;
10187 static const int kNoBreakPointInfo = -1;
10189 // Lookup the index in the break_points array for a code position.
10190 int GetBreakPointInfoIndex(int code_position);
10192 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
10196 // The BreakPointInfo class holds information for break points set in a
10197 // function. The DebugInfo object holds a BreakPointInfo object for each code
10198 // position with one or more break points.
10199 class BreakPointInfo: public Struct {
10201 // The position in the code for the break point.
10202 DECL_ACCESSORS(code_position, Smi)
10203 // The position in the source for the break position.
10204 DECL_ACCESSORS(source_position, Smi)
10205 // The position in the source for the last statement before this break
10207 DECL_ACCESSORS(statement_position, Smi)
10208 // List of related JavaScript break points.
10209 DECL_ACCESSORS(break_point_objects, Object)
10211 // Removes a break point.
10212 static void ClearBreakPoint(Handle<BreakPointInfo> info,
10213 Handle<Object> break_point_object);
10214 // Set a break point.
10215 static void SetBreakPoint(Handle<BreakPointInfo> info,
10216 Handle<Object> break_point_object);
10217 // Check if break point info has this break point object.
10218 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
10219 Handle<Object> break_point_object);
10220 // Get the number of break points for this code position.
10221 int GetBreakPointCount();
10223 DECLARE_CAST(BreakPointInfo)
10225 // Dispatched behavior.
10226 DECLARE_PRINTER(BreakPointInfo)
10227 DECLARE_VERIFIER(BreakPointInfo)
10229 static const int kCodePositionIndex = Struct::kHeaderSize;
10230 static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
10231 static const int kStatementPositionIndex =
10232 kSourcePositionIndex + kPointerSize;
10233 static const int kBreakPointObjectsIndex =
10234 kStatementPositionIndex + kPointerSize;
10235 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
10238 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
10242 #undef DECL_BOOLEAN_ACCESSORS
10243 #undef DECL_ACCESSORS
10244 #undef DECLARE_CAST
10245 #undef DECLARE_VERIFIER
10247 #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
10248 V(kStringTable, "string_table", "(Internalized strings)") \
10249 V(kExternalStringsTable, "external_strings_table", "(External strings)") \
10250 V(kStrongRootList, "strong_root_list", "(Strong roots)") \
10251 V(kSmiRootList, "smi_root_list", "(Smi roots)") \
10252 V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
10253 V(kTop, "top", "(Isolate)") \
10254 V(kRelocatable, "relocatable", "(Relocatable)") \
10255 V(kDebug, "debug", "(Debugger)") \
10256 V(kCompilationCache, "compilationcache", "(Compilation cache)") \
10257 V(kHandleScope, "handlescope", "(Handle scope)") \
10258 V(kBuiltins, "builtins", "(Builtins)") \
10259 V(kGlobalHandles, "globalhandles", "(Global handles)") \
10260 V(kEternalHandles, "eternalhandles", "(Eternal handles)") \
10261 V(kThreadManager, "threadmanager", "(Thread manager)") \
10262 V(kStrongRoots, "strong roots", "(Strong roots)") \
10263 V(kExtensions, "Extensions", "(Extensions)")
10265 class VisitorSynchronization : public AllStatic {
10267 #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
10269 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM)
10272 #undef DECLARE_ENUM
10274 static const char* const kTags[kNumberOfSyncTags];
10275 static const char* const kTagNames[kNumberOfSyncTags];
10278 // Abstract base class for visiting, and optionally modifying, the
10279 // pointers contained in Objects. Used in GC and serialization/deserialization.
10280 class ObjectVisitor BASE_EMBEDDED {
10282 virtual ~ObjectVisitor() {}
10284 // Visits a contiguous arrays of pointers in the half-open range
10285 // [start, end). Any or all of the values may be modified on return.
10286 virtual void VisitPointers(Object** start, Object** end) = 0;
10288 // Handy shorthand for visiting a single pointer.
10289 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
10291 // Visit weak next_code_link in Code object.
10292 virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); }
10294 // To allow lazy clearing of inline caches the visitor has
10295 // a rich interface for iterating over Code objects..
10297 // Visits a code target in the instruction stream.
10298 virtual void VisitCodeTarget(RelocInfo* rinfo);
10300 // Visits a code entry in a JS function.
10301 virtual void VisitCodeEntry(Address entry_address);
10303 // Visits a global property cell reference in the instruction stream.
10304 virtual void VisitCell(RelocInfo* rinfo);
10306 // Visits a runtime entry in the instruction stream.
10307 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
10309 // Visits the resource of an one-byte or two-byte string.
10310 virtual void VisitExternalOneByteString(
10311 v8::String::ExternalOneByteStringResource** resource) {}
10312 virtual void VisitExternalTwoByteString(
10313 v8::String::ExternalStringResource** resource) {}
10315 // Visits a debug call target in the instruction stream.
10316 virtual void VisitDebugTarget(RelocInfo* rinfo);
10318 // Visits the byte sequence in a function's prologue that contains information
10319 // about the code's age.
10320 virtual void VisitCodeAgeSequence(RelocInfo* rinfo);
10322 // Visit pointer embedded into a code object.
10323 virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
10325 // Visits an external reference embedded into a code object.
10326 virtual void VisitExternalReference(RelocInfo* rinfo);
10328 // Visits an external reference.
10329 virtual void VisitExternalReference(Address* p) {}
10331 // Visits an (encoded) internal reference.
10332 virtual void VisitInternalReference(RelocInfo* rinfo) {}
10334 // Visits a handle that has an embedder-assigned class ID.
10335 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
10337 // Intended for serialization/deserialization checking: insert, or
10338 // check for the presence of, a tag at this position in the stream.
10339 // Also used for marking up GC roots in heap snapshots.
10340 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
10344 class StructBodyDescriptor : public
10345 FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
10347 static inline int SizeOf(Map* map, HeapObject* object);
10351 // BooleanBit is a helper class for setting and getting a bit in an
10353 class BooleanBit : public AllStatic {
10355 static inline bool get(Smi* smi, int bit_position) {
10356 return get(smi->value(), bit_position);
10359 static inline bool get(int value, int bit_position) {
10360 return (value & (1 << bit_position)) != 0;
10363 static inline Smi* set(Smi* smi, int bit_position, bool v) {
10364 return Smi::FromInt(set(smi->value(), bit_position, v));
10367 static inline int set(int value, int bit_position, bool v) {
10369 value |= (1 << bit_position);
10371 value &= ~(1 << bit_position);
10377 } } // namespace v8::internal
10379 #endif // V8_OBJECTS_H_