V8 Project
objects.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_
7 
8 #include "src/allocation.h"
9 #include "src/assert-scope.h"
10 #include "src/bailout-reason.h"
11 #include "src/base/bits.h"
12 #include "src/builtins.h"
13 #include "src/checks.h"
14 #include "src/elements-kind.h"
15 #include "src/field-index.h"
16 #include "src/flags.h"
17 #include "src/list.h"
18 #include "src/property-details.h"
19 #include "src/smart-pointers.h"
20 #include "src/unicode-inl.h"
21 #include "src/zone.h"
22 
23 #if V8_TARGET_ARCH_ARM
24 #include "src/arm/constants-arm.h" // NOLINT
25 #elif V8_TARGET_ARCH_ARM64
26 #include "src/arm64/constants-arm64.h" // NOLINT
27 #elif V8_TARGET_ARCH_MIPS
28 #include "src/mips/constants-mips.h" // NOLINT
29 #elif V8_TARGET_ARCH_MIPS64
30 #include "src/mips64/constants-mips64.h" // NOLINT
31 #endif
32 
33 
34 //
35 // Most object types in the V8 JavaScript are described in this file.
36 //
37 // Inheritance hierarchy:
38 // - Object
39 // - Smi (immediate small integer)
40 // - HeapObject (superclass for everything allocated in the heap)
41 // - JSReceiver (suitable for property access)
42 // - JSObject
43 // - JSArray
44 // - JSArrayBuffer
45 // - JSArrayBufferView
46 // - JSTypedArray
47 // - JSDataView
48 // - JSCollection
49 // - JSSet
50 // - JSMap
51 // - JSSetIterator
52 // - JSMapIterator
53 // - JSWeakCollection
54 // - JSWeakMap
55 // - JSWeakSet
56 // - JSRegExp
57 // - JSFunction
58 // - JSGeneratorObject
59 // - JSModule
60 // - GlobalObject
61 // - JSGlobalObject
62 // - JSBuiltinsObject
63 // - JSGlobalProxy
64 // - JSValue
65 // - JSDate
66 // - JSMessageObject
67 // - JSProxy
68 // - JSFunctionProxy
69 // - FixedArrayBase
70 // - ByteArray
71 // - FixedArray
72 // - DescriptorArray
73 // - HashTable
74 // - Dictionary
75 // - StringTable
76 // - CompilationCacheTable
77 // - CodeCacheHashTable
78 // - MapCache
79 // - OrderedHashTable
80 // - OrderedHashSet
81 // - OrderedHashMap
82 // - Context
83 // - TypeFeedbackVector
84 // - JSFunctionResultCache
85 // - ScopeInfo
86 // - TransitionArray
87 // - FixedDoubleArray
88 // - ExternalArray
89 // - ExternalUint8ClampedArray
90 // - ExternalInt8Array
91 // - ExternalUint8Array
92 // - ExternalInt16Array
93 // - ExternalUint16Array
94 // - ExternalInt32Array
95 // - ExternalUint32Array
96 // - ExternalFloat32Array
97 // - Name
98 // - String
99 // - SeqString
100 // - SeqOneByteString
101 // - SeqTwoByteString
102 // - SlicedString
103 // - ConsString
104 // - ExternalString
105 // - ExternalOneByteString
106 // - ExternalTwoByteString
107 // - InternalizedString
108 // - SeqInternalizedString
109 // - SeqOneByteInternalizedString
110 // - SeqTwoByteInternalizedString
111 // - ConsInternalizedString
112 // - ExternalInternalizedString
113 // - ExternalOneByteInternalizedString
114 // - ExternalTwoByteInternalizedString
115 // - Symbol
116 // - HeapNumber
117 // - Cell
118 // - PropertyCell
119 // - Code
120 // - Map
121 // - Oddball
122 // - Foreign
123 // - SharedFunctionInfo
124 // - Struct
125 // - Box
126 // - DeclaredAccessorDescriptor
127 // - AccessorInfo
128 // - DeclaredAccessorInfo
129 // - ExecutableAccessorInfo
130 // - AccessorPair
131 // - AccessCheckInfo
132 // - InterceptorInfo
133 // - CallHandlerInfo
134 // - TemplateInfo
135 // - FunctionTemplateInfo
136 // - ObjectTemplateInfo
137 // - Script
138 // - SignatureInfo
139 // - TypeSwitchInfo
140 // - DebugInfo
141 // - BreakPointInfo
142 // - CodeCache
143 //
144 // Formats of Object*:
145 // Smi: [31 bit signed int] 0
146 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
147 
148 namespace v8 {
149 namespace internal {
150 
151 class OStream;
152 
170 };
171 
172 
175  CONTEXTUAL
176 };
177 
178 
181  IMMUTABLE
182 };
183 
184 
197 
198 
200  KeyedAccessStoreMode store_mode) {
201  if (store_mode < STORE_AND_GROW_NO_TRANSITION) {
202  store_mode = static_cast<KeyedAccessStoreMode>(
203  static_cast<int>(store_mode) + kGrowICDelta);
204  }
205  return store_mode;
206 }
207 
208 
209 static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) {
210  return store_mode > STANDARD_STORE &&
212  store_mode != STORE_AND_GROW_NO_TRANSITION;
213 }
214 
215 
217  KeyedAccessStoreMode store_mode) {
218  if (store_mode >= STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) {
219  return store_mode;
220  }
221  if (store_mode >= STORE_AND_GROW_NO_TRANSITION) {
223  }
224  return STANDARD_STORE;
225 }
226 
227 
228 static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) {
229  return store_mode >= STORE_AND_GROW_NO_TRANSITION &&
231 }
232 
233 
234 // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
236 
237 
238 // Indicates whether a value can be loaded as a constant.
239 enum StoreMode {
242 };
243 
244 
245 // PropertyNormalizationMode is used to specify whether to keep
246 // inobject properties when normalizing properties of a JSObject.
250 };
251 
252 
253 // Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE
254 // will give the fastest result by tailoring the map to the prototype, but that
255 // will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used
256 // (at least for now) when dynamically modifying the prototype chain of an
257 // object using __proto__ or Object.setPrototypeOf.
259 
260 
261 // Indicates whether transitions can be added to a source map or not.
265 };
266 
267 
271 };
272 
273 
274 // Indicates whether the transition is simple: the target map of the transition
275 // either extends the current map with a new property, or it modifies the
276 // property that was added last to the current map.
280 };
281 
282 
283 // Indicates whether we are only interested in the descriptors of a particular
284 // map, or in all descriptors in the descriptor array.
288 };
289 
290 // The GC maintains a bit of information, the MarkingParity, which toggles
291 // from odd to even and back every time marking is completed. Incremental
292 // marking can visit an object twice during a marking phase, so algorithms that
293 // that piggy-back on marking can use the parity to ensure that they only
294 // perform an operation on an object once per marking phase: they record the
295 // MarkingParity when they visit an object, and only re-visit the object when it
296 // is marked again and the MarkingParity changes.
301 };
302 
303 // ICs store extra state in a Code object. The default extra state is
304 // kNoExtraICState.
305 typedef int ExtraICState;
306 static const ExtraICState kNoExtraICState = 0;
307 
308 // Instance size sentinel for objects of variable size.
309 const int kVariableSizeSentinel = 0;
310 
311 // We may store the unsigned bit field as signed Smi value and do not
312 // use the sign bit.
313 const int kStubMajorKeyBits = 7;
315 
316 // All Maps have a field instance_type containing a InstanceType.
317 // It describes the type of the instances.
318 //
319 // As an example, a JavaScript object is a heap object and its map
320 // instance_type is JS_OBJECT_TYPE.
321 //
322 // The names of the string instance types are intended to systematically
323 // mirror their encoding in the instance_type field of the map. The default
324 // encoding is considered TWO_BYTE. It is not mentioned in the name. ONE_BYTE
325 // encoding is mentioned explicitly in the name. Likewise, the default
326 // representation is considered sequential. It is not mentioned in the
327 // name. The other representations (e.g. CONS, EXTERNAL) are explicitly
328 // mentioned. Finally, the string is either a STRING_TYPE (if it is a normal
329 // string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string).
330 //
331 // NOTE: The following things are some that depend on the string types having
332 // instance_types that are less than those of all other types:
333 // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
334 // Object::IsString.
335 //
336 // NOTE: Everything following JS_VALUE_TYPE is considered a
337 // JSObject for GC purposes. The first four entries here have typeof
338 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
339 #define INSTANCE_TYPE_LIST(V) \
340  V(STRING_TYPE) \
341  V(ONE_BYTE_STRING_TYPE) \
342  V(CONS_STRING_TYPE) \
343  V(CONS_ONE_BYTE_STRING_TYPE) \
344  V(SLICED_STRING_TYPE) \
345  V(SLICED_ONE_BYTE_STRING_TYPE) \
346  V(EXTERNAL_STRING_TYPE) \
347  V(EXTERNAL_ONE_BYTE_STRING_TYPE) \
348  V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
349  V(SHORT_EXTERNAL_STRING_TYPE) \
350  V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \
351  V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
352  \
353  V(INTERNALIZED_STRING_TYPE) \
354  V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \
355  V(EXTERNAL_INTERNALIZED_STRING_TYPE) \
356  V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
357  V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
358  V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \
359  V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
360  V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
361  \
362  V(SYMBOL_TYPE) \
363  \
364  V(MAP_TYPE) \
365  V(CODE_TYPE) \
366  V(ODDBALL_TYPE) \
367  V(CELL_TYPE) \
368  V(PROPERTY_CELL_TYPE) \
369  \
370  V(HEAP_NUMBER_TYPE) \
371  V(MUTABLE_HEAP_NUMBER_TYPE) \
372  V(FOREIGN_TYPE) \
373  V(BYTE_ARRAY_TYPE) \
374  V(FREE_SPACE_TYPE) \
375  /* Note: the order of these external array */ \
376  /* types is relied upon in */ \
377  /* Object::IsExternalArray(). */ \
378  V(EXTERNAL_INT8_ARRAY_TYPE) \
379  V(EXTERNAL_UINT8_ARRAY_TYPE) \
380  V(EXTERNAL_INT16_ARRAY_TYPE) \
381  V(EXTERNAL_UINT16_ARRAY_TYPE) \
382  V(EXTERNAL_INT32_ARRAY_TYPE) \
383  V(EXTERNAL_UINT32_ARRAY_TYPE) \
384  V(EXTERNAL_FLOAT32_ARRAY_TYPE) \
385  V(EXTERNAL_FLOAT64_ARRAY_TYPE) \
386  V(EXTERNAL_UINT8_CLAMPED_ARRAY_TYPE) \
387  \
388  V(FIXED_INT8_ARRAY_TYPE) \
389  V(FIXED_UINT8_ARRAY_TYPE) \
390  V(FIXED_INT16_ARRAY_TYPE) \
391  V(FIXED_UINT16_ARRAY_TYPE) \
392  V(FIXED_INT32_ARRAY_TYPE) \
393  V(FIXED_UINT32_ARRAY_TYPE) \
394  V(FIXED_FLOAT32_ARRAY_TYPE) \
395  V(FIXED_FLOAT64_ARRAY_TYPE) \
396  V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \
397  \
398  V(FILLER_TYPE) \
399  \
400  V(DECLARED_ACCESSOR_DESCRIPTOR_TYPE) \
401  V(DECLARED_ACCESSOR_INFO_TYPE) \
402  V(EXECUTABLE_ACCESSOR_INFO_TYPE) \
403  V(ACCESSOR_PAIR_TYPE) \
404  V(ACCESS_CHECK_INFO_TYPE) \
405  V(INTERCEPTOR_INFO_TYPE) \
406  V(CALL_HANDLER_INFO_TYPE) \
407  V(FUNCTION_TEMPLATE_INFO_TYPE) \
408  V(OBJECT_TEMPLATE_INFO_TYPE) \
409  V(SIGNATURE_INFO_TYPE) \
410  V(TYPE_SWITCH_INFO_TYPE) \
411  V(ALLOCATION_MEMENTO_TYPE) \
412  V(ALLOCATION_SITE_TYPE) \
413  V(SCRIPT_TYPE) \
414  V(CODE_CACHE_TYPE) \
415  V(POLYMORPHIC_CODE_CACHE_TYPE) \
416  V(TYPE_FEEDBACK_INFO_TYPE) \
417  V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
418  V(BOX_TYPE) \
419  \
420  V(FIXED_ARRAY_TYPE) \
421  V(FIXED_DOUBLE_ARRAY_TYPE) \
422  V(CONSTANT_POOL_ARRAY_TYPE) \
423  V(SHARED_FUNCTION_INFO_TYPE) \
424  \
425  V(JS_MESSAGE_OBJECT_TYPE) \
426  \
427  V(JS_VALUE_TYPE) \
428  V(JS_DATE_TYPE) \
429  V(JS_OBJECT_TYPE) \
430  V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
431  V(JS_GENERATOR_OBJECT_TYPE) \
432  V(JS_MODULE_TYPE) \
433  V(JS_GLOBAL_OBJECT_TYPE) \
434  V(JS_BUILTINS_OBJECT_TYPE) \
435  V(JS_GLOBAL_PROXY_TYPE) \
436  V(JS_ARRAY_TYPE) \
437  V(JS_ARRAY_BUFFER_TYPE) \
438  V(JS_TYPED_ARRAY_TYPE) \
439  V(JS_DATA_VIEW_TYPE) \
440  V(JS_PROXY_TYPE) \
441  V(JS_SET_TYPE) \
442  V(JS_MAP_TYPE) \
443  V(JS_SET_ITERATOR_TYPE) \
444  V(JS_MAP_ITERATOR_TYPE) \
445  V(JS_WEAK_MAP_TYPE) \
446  V(JS_WEAK_SET_TYPE) \
447  V(JS_REGEXP_TYPE) \
448  \
449  V(JS_FUNCTION_TYPE) \
450  V(JS_FUNCTION_PROXY_TYPE) \
451  V(DEBUG_INFO_TYPE) \
452  V(BREAK_POINT_INFO_TYPE)
453 
454 
455 // Since string types are not consecutive, this macro is used to
456 // iterate over them.
457 #define STRING_TYPE_LIST(V) \
458  V(STRING_TYPE, kVariableSizeSentinel, string, String) \
459  V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \
460  OneByteString) \
461  V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \
462  V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \
463  ConsOneByteString) \
464  V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \
465  V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \
466  SlicedOneByteString) \
467  V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \
468  ExternalString) \
469  V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \
470  external_one_byte_string, ExternalOneByteString) \
471  V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \
472  external_string_with_one_byte_data, ExternalStringWithOneByteData) \
473  V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \
474  short_external_string, ShortExternalString) \
475  V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \
476  short_external_one_byte_string, ShortExternalOneByteString) \
477  V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \
478  ExternalTwoByteString::kShortSize, \
479  short_external_string_with_one_byte_data, \
480  ShortExternalStringWithOneByteData) \
481  \
482  V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \
483  InternalizedString) \
484  V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \
485  one_byte_internalized_string, OneByteInternalizedString) \
486  V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \
487  external_internalized_string, ExternalInternalizedString) \
488  V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \
489  external_one_byte_internalized_string, ExternalOneByteInternalizedString) \
490  V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
491  ExternalTwoByteString::kSize, \
492  external_internalized_string_with_one_byte_data, \
493  ExternalInternalizedStringWithOneByteData) \
494  V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \
495  ExternalTwoByteString::kShortSize, short_external_internalized_string, \
496  ShortExternalInternalizedString) \
497  V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \
498  ExternalOneByteString::kShortSize, \
499  short_external_one_byte_internalized_string, \
500  ShortExternalOneByteInternalizedString) \
501  V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
502  ExternalTwoByteString::kShortSize, \
503  short_external_internalized_string_with_one_byte_data, \
504  ShortExternalInternalizedStringWithOneByteData)
505 
506 // A struct is a simple object a set of object-valued fields. Including an
507 // object type in this causes the compiler to generate most of the boilerplate
508 // code for the class including allocation and garbage collection routines,
509 // casts and predicates. All you need to define is the class, methods and
510 // object verification routines. Easy, no?
511 //
512 // Note that for subtle reasons related to the ordering or numerical values of
513 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
514 // manually.
515 #define STRUCT_LIST(V) \
516  V(BOX, Box, box) \
517  V(DECLARED_ACCESSOR_DESCRIPTOR, \
518  DeclaredAccessorDescriptor, \
519  declared_accessor_descriptor) \
520  V(DECLARED_ACCESSOR_INFO, DeclaredAccessorInfo, declared_accessor_info) \
521  V(EXECUTABLE_ACCESSOR_INFO, ExecutableAccessorInfo, executable_accessor_info)\
522  V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
523  V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
524  V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
525  V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
526  V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
527  V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
528  V(SIGNATURE_INFO, SignatureInfo, signature_info) \
529  V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
530  V(SCRIPT, Script, script) \
531  V(ALLOCATION_SITE, AllocationSite, allocation_site) \
532  V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \
533  V(CODE_CACHE, CodeCache, code_cache) \
534  V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
535  V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
536  V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \
537  V(DEBUG_INFO, DebugInfo, debug_info) \
538  V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
539 
540 // We use the full 8 bits of the instance_type field to encode heap object
541 // instance types. The high-order bit (bit 7) is set if the object is not a
542 // string, and cleared if it is a string.
544 const uint32_t kStringTag = 0x0;
545 const uint32_t kNotStringTag = 0x80;
546 
547 // Bit 6 indicates that the object is an internalized string (if set) or not.
548 // Bit 7 has to be clear as well.
552 
553 // If bit 7 is clear then bit 2 indicates whether the string consists of
554 // two-byte characters or one-byte characters.
558 
559 // If bit 7 is clear, the low-order 2 bits indicate the representation
560 // of the string.
566  kSlicedStringTag = 0x3
567 };
576 
577 // Use this mask to distinguish between cons and slice only after making
578 // sure that the string is one of the two (an indirect string).
581 
582 // If bit 7 is clear, then bit 3 indicates whether this two-byte
583 // string actually contains one byte data.
586 
587 // If bit 7 is clear and string representation indicates an external string,
588 // then bit 4 indicates whether the data pointer is cached.
591 
592 
593 // A ConsString with an empty string as the right side is a candidate
594 // for being shortcut by the garbage collector. We don't allocate any
595 // non-flat internalized strings, so we do not shortcut them thereby
596 // avoiding turning internalized strings into strings. The bit-masks
597 // below contain the internalized bit as additional safety.
598 // See heap.cc, mark-compact.cc and objects-visiting.cc.
604 
605 static inline bool IsShortcutCandidate(int type) {
606  return ((type & kShortcutTypeMask) == kShortcutTypeTag);
607 }
608 
609 
611  // String types.
656 
657  // Non-string names
658  SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE
659 
660  // Objects allocated in their own spaces (never in new space).
666 
667  // "Data", objects that cannot contain non-map-word pointers to heap
668  // objects.
674  EXTERNAL_INT8_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
682  EXTERNAL_UINT8_CLAMPED_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
683  FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE
691  FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE
693  FILLER_TYPE, // LAST_DATA_TYPE
694 
695  // Structs.
720 
721  // All the following types are subtypes of JSReceiver, which corresponds to
722  // objects in the JS sense. The first and the last type in this range are
723  // the two forms of function. This organization enables using the same
724  // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
725  // NONCALLABLE_JS_OBJECT range.
726  JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
727  JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
728  JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
749  JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
750 
751  // Pseudo-types
752  FIRST_TYPE = 0x0,
759  // Boundaries for testing for an external array.
762  // Boundaries for testing for a fixed typed array.
765  // Boundary for promotion to old data space/old pointer space.
767  // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
768  // Note that there is no range for JSObject or JSProxy, since their subtypes
769  // are not continuous in this enum! The enum ranges instead reflect the
770  // external class names, where proxies are treated as either ordinary objects,
771  // or functions.
774  // Boundaries for testing the types represented as JSObject
777  // Boundaries for testing the types represented as JSProxy
780  // Boundaries for testing whether the type is a JavaScript object.
783  // Boundaries for testing the types for which typeof is "object".
786  // Note that the types for which typeof is "function" are not continuous.
787  // Define this so that we can put assertions on discrete checks.
789 };
790 
793 
798 
799 
800 #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \
801  V(FAST_ELEMENTS_SUB_TYPE) \
802  V(DICTIONARY_ELEMENTS_SUB_TYPE) \
803  V(FAST_PROPERTIES_SUB_TYPE) \
804  V(DICTIONARY_PROPERTIES_SUB_TYPE) \
805  V(MAP_CODE_CACHE_SUB_TYPE) \
806  V(SCOPE_INFO_SUB_TYPE) \
807  V(STRING_TABLE_SUB_TYPE) \
808  V(DESCRIPTOR_ARRAY_SUB_TYPE) \
809  V(TRANSITION_ARRAY_SUB_TYPE)
810 
812 #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name,
814 #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE
815  LAST_FIXED_ARRAY_SUB_TYPE = TRANSITION_ARRAY_SUB_TYPE
816 };
817 
818 
820  LESS = -1,
821  EQUAL = 0,
822  GREATER = 1,
823 
825 };
826 
827 
828 #define DECL_BOOLEAN_ACCESSORS(name) \
829  inline bool name() const; \
830  inline void set_##name(bool value); \
831 
832 
833 #define DECL_ACCESSORS(name, type) \
834  inline type* name() const; \
835  inline void set_##name(type* value, \
836  WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
837 
838 
839 #define DECLARE_CAST(type) \
840  INLINE(static type* cast(Object* object)); \
841  INLINE(static const type* cast(const Object* object));
842 
843 
844 class AccessorPair;
845 class AllocationSite;
846 class AllocationSiteCreationContext;
847 class AllocationSiteUsageContext;
848 class DictionaryElementsAccessor;
849 class ElementsAccessor;
850 class FixedArrayBase;
851 class GlobalObject;
852 class ObjectVisitor;
853 class LookupIterator;
854 class StringStream;
855 class TypeFeedbackVector;
856 // We cannot just say "class HeapType;" if it is created from a template... =8-?
857 template<class> class TypeImpl;
858 struct HeapTypeConfig;
859 typedef TypeImpl<HeapTypeConfig> HeapType;
860 
861 
862 // A template-ized version of the IsXXX functions.
863 template <class C> inline bool Is(Object* obj);
864 
865 #ifdef VERIFY_HEAP
866 #define DECLARE_VERIFIER(Name) void Name##Verify();
867 #else
868 #define DECLARE_VERIFIER(Name)
869 #endif
870 
871 #ifdef OBJECT_PRINT
872 #define DECLARE_PRINTER(Name) void Name##Print(OStream& os); // NOLINT
873 #else
874 #define DECLARE_PRINTER(Name)
875 #endif
876 
877 
878 #define OBJECT_TYPE_LIST(V) \
879  V(Smi) \
880  V(HeapObject) \
881  V(Number)
882 
883 #define HEAP_OBJECT_TYPE_LIST(V) \
884  V(HeapNumber) \
885  V(MutableHeapNumber) \
886  V(Name) \
887  V(UniqueName) \
888  V(String) \
889  V(SeqString) \
890  V(ExternalString) \
891  V(ConsString) \
892  V(SlicedString) \
893  V(ExternalTwoByteString) \
894  V(ExternalOneByteString) \
895  V(SeqTwoByteString) \
896  V(SeqOneByteString) \
897  V(InternalizedString) \
898  V(Symbol) \
899  \
900  V(ExternalArray) \
901  V(ExternalInt8Array) \
902  V(ExternalUint8Array) \
903  V(ExternalInt16Array) \
904  V(ExternalUint16Array) \
905  V(ExternalInt32Array) \
906  V(ExternalUint32Array) \
907  V(ExternalFloat32Array) \
908  V(ExternalFloat64Array) \
909  V(ExternalUint8ClampedArray) \
910  V(FixedTypedArrayBase) \
911  V(FixedUint8Array) \
912  V(FixedInt8Array) \
913  V(FixedUint16Array) \
914  V(FixedInt16Array) \
915  V(FixedUint32Array) \
916  V(FixedInt32Array) \
917  V(FixedFloat32Array) \
918  V(FixedFloat64Array) \
919  V(FixedUint8ClampedArray) \
920  V(ByteArray) \
921  V(FreeSpace) \
922  V(JSReceiver) \
923  V(JSObject) \
924  V(JSContextExtensionObject) \
925  V(JSGeneratorObject) \
926  V(JSModule) \
927  V(Map) \
928  V(DescriptorArray) \
929  V(TransitionArray) \
930  V(TypeFeedbackVector) \
931  V(DeoptimizationInputData) \
932  V(DeoptimizationOutputData) \
933  V(DependentCode) \
934  V(FixedArray) \
935  V(FixedDoubleArray) \
936  V(ConstantPoolArray) \
937  V(Context) \
938  V(NativeContext) \
939  V(ScopeInfo) \
940  V(JSFunction) \
941  V(Code) \
942  V(Oddball) \
943  V(SharedFunctionInfo) \
944  V(JSValue) \
945  V(JSDate) \
946  V(JSMessageObject) \
947  V(StringWrapper) \
948  V(Foreign) \
949  V(Boolean) \
950  V(JSArray) \
951  V(JSArrayBuffer) \
952  V(JSArrayBufferView) \
953  V(JSTypedArray) \
954  V(JSDataView) \
955  V(JSProxy) \
956  V(JSFunctionProxy) \
957  V(JSSet) \
958  V(JSMap) \
959  V(JSSetIterator) \
960  V(JSMapIterator) \
961  V(JSWeakCollection) \
962  V(JSWeakMap) \
963  V(JSWeakSet) \
964  V(JSRegExp) \
965  V(HashTable) \
966  V(Dictionary) \
967  V(StringTable) \
968  V(JSFunctionResultCache) \
969  V(NormalizedMapCache) \
970  V(CompilationCacheTable) \
971  V(CodeCacheHashTable) \
972  V(PolymorphicCodeCacheHashTable) \
973  V(MapCache) \
974  V(Primitive) \
975  V(GlobalObject) \
976  V(JSGlobalObject) \
977  V(JSBuiltinsObject) \
978  V(JSGlobalProxy) \
979  V(UndetectableObject) \
980  V(AccessCheckNeeded) \
981  V(Cell) \
982  V(PropertyCell) \
983  V(ObjectHashTable) \
984  V(WeakHashTable) \
985  V(OrderedHashTable)
986 
987 // Object is the abstract superclass for all classes in the
988 // object hierarchy.
989 // Object does not use any virtual functions to avoid the
990 // allocation of the C++ vtable.
991 // Since both Smi and HeapObject are subclasses of Object no
992 // data members can be present in Object.
993 class Object {
994  public:
995  // Type testing.
996  bool IsObject() const { return true; }
997 
998 #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const);
1001 #undef IS_TYPE_FUNCTION_DECL
1002 
1003  // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
1004  // a keyed store is of the form a[expression] = foo.
1008  };
1009 
1011 
1012  INLINE(bool IsFixedArrayBase() const);
1013  INLINE(bool IsExternal() const);
1014  INLINE(bool IsAccessorInfo() const);
1015 
1016  INLINE(bool IsStruct() const);
1017 #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \
1018  INLINE(bool Is##Name() const);
1020 #undef DECLARE_STRUCT_PREDICATE
1021 
1022  INLINE(bool IsSpecObject()) const;
1023  INLINE(bool IsSpecFunction()) const;
1024  INLINE(bool IsTemplateInfo()) const;
1025  INLINE(bool IsNameDictionary() const);
1026  INLINE(bool IsSeededNumberDictionary() const);
1027  INLINE(bool IsUnseededNumberDictionary() const);
1028  INLINE(bool IsOrderedHashSet() const);
1029  INLINE(bool IsOrderedHashMap() const);
1030  bool IsCallable() const;
1031 
1032  // Oddball testing.
1033  INLINE(bool IsUndefined() const);
1034  INLINE(bool IsNull() const);
1035  INLINE(bool IsTheHole() const);
1036  INLINE(bool IsException() const);
1037  INLINE(bool IsUninitialized() const);
1038  INLINE(bool IsTrue() const);
1039  INLINE(bool IsFalse() const);
1040  INLINE(bool IsArgumentsMarker() const);
1041 
1042  // Filler objects (fillers and free space objects).
1043  INLINE(bool IsFiller() const);
1044 
1045  // Extract the number.
1046  inline double Number();
1047  INLINE(bool IsNaN() const);
1048  INLINE(bool IsMinusZero() const);
1049  bool ToInt32(int32_t* value);
1050  bool ToUint32(uint32_t* value);
1051 
1053  if (!FLAG_track_fields) return Representation::Tagged();
1054  if (IsSmi()) {
1055  return Representation::Smi();
1056  } else if (FLAG_track_double_fields && IsHeapNumber()) {
1057  return Representation::Double();
1058  } else if (FLAG_track_computed_fields && IsUninitialized()) {
1059  return Representation::None();
1060  } else if (FLAG_track_heap_object_fields) {
1061  DCHECK(IsHeapObject());
1062  return Representation::HeapObject();
1063  } else {
1064  return Representation::Tagged();
1065  }
1066  }
1067 
1068  inline bool FitsRepresentation(Representation representation) {
1069  if (FLAG_track_fields && representation.IsNone()) {
1070  return false;
1071  } else if (FLAG_track_fields && representation.IsSmi()) {
1072  return IsSmi();
1073  } else if (FLAG_track_double_fields && representation.IsDouble()) {
1074  return IsMutableHeapNumber() || IsNumber();
1075  } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
1076  return IsHeapObject();
1077  }
1078  return true;
1079  }
1080 
1081  Handle<HeapType> OptimalType(Isolate* isolate, Representation representation);
1082 
1083  inline static Handle<Object> NewStorageFor(Isolate* isolate,
1084  Handle<Object> object,
1085  Representation representation);
1086 
1087  inline static Handle<Object> WrapForRead(Isolate* isolate,
1088  Handle<Object> object,
1089  Representation representation);
1090 
1091  // Returns true if the object is of the correct type to be used as a
1092  // implementation of a JSObject's elements.
1093  inline bool HasValidElements();
1094 
1095  inline bool HasSpecificClassOf(String* name);
1096 
1097  bool BooleanValue(); // ECMA-262 9.2.
1098 
1099  // Convert to a JSObject if needed.
1100  // native_context is used when creating wrapper object.
1101  static inline MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
1102  Handle<Object> object);
1103  static MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
1104  Handle<Object> object,
1105  Handle<Context> context);
1106 
1107  // Converts this to a Smi if possible.
1108  static MUST_USE_RESULT inline MaybeHandle<Smi> ToSmi(Isolate* isolate,
1109  Handle<Object> object);
1110 
1112 
1113  // Implementation of [[Put]], ECMA-262 5th edition, section 8.12.5.
1115  Handle<Object> object, Handle<Name> key, Handle<Object> value,
1116  StrictMode strict_mode,
1118 
1120  LookupIterator* it, Handle<Object> value, StrictMode strict_mode,
1121  StoreFromKeyed store_mode,
1122  StorePropertyMode data_store_mode = NORMAL_PROPERTY);
1124  LookupIterator* it, Handle<Object> value, StrictMode strict_mode);
1126  Handle<Object> value);
1128  LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
1129  StrictMode strict_mode, StoreFromKeyed store_mode);
1131  Handle<Object> object,
1132  Handle<Name> key);
1134  Isolate* isolate,
1135  Handle<Object> object,
1136  const char* key);
1138  Handle<Object> object,
1139  Handle<Name> key);
1140 
1142  Handle<Object> receiver,
1144  Handle<JSObject> holder,
1145  Handle<Object> structure);
1148  Handle<JSObject> holder, Handle<Object> structure,
1149  StrictMode strict_mode);
1150 
1152  Handle<Object> receiver,
1153  Handle<JSReceiver> getter);
1155  Handle<Object> receiver,
1156  Handle<JSReceiver> setter,
1157  Handle<Object> value);
1158 
1160  Isolate* isolate,
1161  Handle<Object> object,
1162  uint32_t index);
1163 
1165  Isolate* isolate,
1166  Handle<Object> object,
1167  Handle<Object> receiver,
1168  uint32_t index);
1169 
1170  // Returns the permanent hash code associated with this object. May return
1171  // undefined if not yet created.
1172  Object* GetHash();
1173 
1174  // Returns the permanent hash code associated with this object depending on
1175  // the actual object type. May create and store a hash code if needed and none
1176  // exists.
1177  static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object);
1178 
1179  // Checks whether this object has the same value as the given one. This
1180  // function is implemented according to ES5, section 9.12 and can be used
1181  // to implement the Harmony "egal" function.
1182  bool SameValue(Object* other);
1183 
1184  // Checks whether this object has the same value as the given one.
1185  // +0 and -0 are treated equal. Everything else is the same as SameValue.
1186  // This function is implemented according to ES6, section 7.2.4 and is used
1187  // by ES6 Map and Set.
1188  bool SameValueZero(Object* other);
1189 
1190  // Tries to convert an object to an array index. Returns true and sets
1191  // the output parameter if it succeeds.
1192  inline bool ToArrayIndex(uint32_t* index);
1193 
1194  // Returns true if this is a JSValue containing a string and the index is
1195  // < the length of the string. Used to implement [] on strings.
1196  inline bool IsStringObjectWithCharacterAt(uint32_t index);
1197 
1199 #ifdef VERIFY_HEAP
1200  // Verify a pointer is a valid object pointer.
1201  static void VerifyPointer(Object* p);
1202 #endif
1203 
1204  inline void VerifyApiCallResultType();
1205 
1206  // Prints this object without details.
1207  void ShortPrint(FILE* out = stdout);
1208 
1209  // Prints this object without details to a message accumulator.
1210  void ShortPrint(StringStream* accumulator);
1211 
1213 
1214  // Layout description.
1215  static const int kHeaderSize = 0; // Object does not take up any space.
1216 
1217 #ifdef OBJECT_PRINT
1218  // For our gdb macros, we should perhaps change these in the future.
1219  void Print();
1220 
1221  // Prints this object with details.
1222  void Print(OStream& os); // NOLINT
1223 #endif
1224 
1225  private:
1226  friend class LookupIterator;
1227  friend class PrototypeIterator;
1228 
1229  // Return the map of the root of object's prototype chain.
1230  Map* GetRootMap(Isolate* isolate);
1231 
1233 };
1234 
1235 
1236 struct Brief {
1237  explicit Brief(const Object* const v) : value(v) {}
1238  const Object* value;
1239 };
1240 
1241 
1242 OStream& operator<<(OStream& os, const Brief& v);
1243 
1244 
1245 // Smi represents integer Numbers that can be stored in 31 bits.
1246 // Smis are immediate which means they are NOT allocated in the heap.
1247 // The this pointer has the following format: [31 bit signed int] 0
1248 // For long smis it has the following format:
1249 // [32 bit signed int] [31 bits zero padding] 0
1250 // Smi stands for small integer.
1251 class Smi: public Object {
1252  public:
1253  // Returns the integer value.
1254  inline int value() const;
1255 
1256  // Convert a value to a Smi object.
1257  static inline Smi* FromInt(int value);
1258 
1259  static inline Smi* FromIntptr(intptr_t value);
1260 
1261  // Returns whether value can be represented in a Smi.
1262  static inline bool IsValid(intptr_t value);
1263 
1264  DECLARE_CAST(Smi)
1265 
1266  // Dispatched behavior.
1267  void SmiPrint(OStream& os) const; // NOLINT
1269 
1270  static const int kMinValue =
1271  (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
1272  static const int kMaxValue = -(kMinValue + 1);
1273 
1274  private:
1276 };
1277 
1278 
1279 // Heap objects typically have a map pointer in their first word. However,
1280 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes
1281 // encoded in the first word. The class MapWord is an abstraction of the
1282 // value in a heap object's first word.
1283 class MapWord BASE_EMBEDDED {
1284  public:
1285  // Normal state: the map word contains a map pointer.
1286 
1287  // Create a map word from a map pointer.
1288  static inline MapWord FromMap(const Map* map);
1289 
1290  // View this map word as a map pointer.
1291  inline Map* ToMap();
1292 
1293 
1294  // Scavenge collection: the map word of live objects in the from space
1295  // contains a forwarding address (a heap object pointer in the to space).
1296 
1297  // True if this map word is a forwarding address for a scavenge
1298  // collection. Only valid during a scavenge collection (specifically,
1299  // when all map words are heap object pointers, i.e. not during a full GC).
1300  inline bool IsForwardingAddress();
1301 
1302  // Create a map word from a forwarding address.
1303  static inline MapWord FromForwardingAddress(HeapObject* object);
1304 
1305  // View this map word as a forwarding address.
1307 
1308  static inline MapWord FromRawValue(uintptr_t value) {
1309  return MapWord(value);
1310  }
1311 
1313  return value_;
1314  }
1315 
1316  private:
1317  // HeapObject calls the private constructor and directly reads the value.
1318  friend class HeapObject;
1319 
1320  explicit MapWord(uintptr_t value) : value_(value) {}
1321 
1323 };
1324 
1325 
1326 // HeapObject is the superclass for all classes describing heap allocated
1327 // objects.
1328 class HeapObject: public Object {
1329  public:
1330  // [map]: Contains a map which contains the object's reflective
1331  // information.
1332  inline Map* map() const;
1333  inline void set_map(Map* value);
1334  // The no-write-barrier version. This is OK if the object is white and in
1335  // new space, or if the value is an immortal immutable object, like the maps
1336  // of primitive (non-JS) objects like strings, heap numbers etc.
1337  inline void set_map_no_write_barrier(Map* value);
1338 
1339  // Get the map using acquire load.
1340  inline Map* synchronized_map();
1341  inline MapWord synchronized_map_word() const;
1342 
1343  // Set the map using release store
1344  inline void synchronized_set_map(Map* value);
1345  inline void synchronized_set_map_no_write_barrier(Map* value);
1346  inline void synchronized_set_map_word(MapWord map_word);
1347 
1348  // During garbage collection, the map word of a heap object does not
1349  // necessarily contain a map pointer.
1350  inline MapWord map_word() const;
1351  inline void set_map_word(MapWord map_word);
1352 
1353  // The Heap the object was allocated in. Used also to access Isolate.
1354  inline Heap* GetHeap() const;
1355 
1356  // Convenience method to get current isolate.
1357  inline Isolate* GetIsolate() const;
1358 
1359  // Converts an address to a HeapObject pointer.
1360  static inline HeapObject* FromAddress(Address address);
1361 
1362  // Returns the address of this HeapObject.
1363  inline Address address();
1364 
1365  // Iterates over pointers contained in the object (including the Map)
1366  void Iterate(ObjectVisitor* v);
1367 
1368  // Iterates over all pointers contained in the object except the
1369  // first map pointer. The object type is given in the first
1370  // parameter. This function does not access the map pointer in the
1371  // object, and so is safe to call while the map pointer is modified.
1372  void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1373 
1374  // Returns the heap object's size in bytes
1375  inline int Size();
1376 
1377  // Returns true if this heap object may contain raw values, i.e., values that
1378  // look like pointers to heap objects.
1379  inline bool MayContainRawValues();
1380 
1381  // Given a heap object's map pointer, returns the heap size in bytes
1382  // Useful when the map pointer field is used for other purposes.
1383  // GC internal.
1384  inline int SizeFromMap(Map* map);
1385 
1386  // Returns the field at offset in obj, as a read/write Object* reference.
1387  // Does no checking, and is safe to use during GC, while maps are invalid.
1388  // Does not invoke write barrier, so should only be assigned to
1389  // during marking GC.
1390  static inline Object** RawField(HeapObject* obj, int offset);
1391 
1392  // Adds the |code| object related to |name| to the code cache of this map. If
1393  // this map is a dictionary map that is shared, the map copied and installed
1394  // onto the object.
1395  static void UpdateMapCodeCache(Handle<HeapObject> object,
1397  Handle<Code> code);
1398 
1400 
1401  // Return the write barrier mode for this. Callers of this function
1402  // must be able to present a reference to an DisallowHeapAllocation
1403  // object as a sign that they are not going to use this function
1404  // from code that allocates and thus invalidates the returned write
1405  // barrier mode.
1406  inline WriteBarrierMode GetWriteBarrierMode(
1407  const DisallowHeapAllocation& promise);
1408 
1409  // Dispatched behavior.
1410  void HeapObjectShortPrint(OStream& os); // NOLINT
1411 #ifdef OBJECT_PRINT
1412  void PrintHeader(OStream& os, const char* id); // NOLINT
1413 #endif
1416 #ifdef VERIFY_HEAP
1417  inline void VerifyObjectField(int offset);
1418  inline void VerifySmiField(int offset);
1419 
1420  // Verify a pointer is a valid HeapObject pointer that points to object
1421  // areas in the heap.
1422  static void VerifyHeapPointer(Object* p);
1423 #endif
1424 
1425  // Layout description.
1426  // First field in a heap object is map.
1427  static const int kMapOffset = Object::kHeaderSize;
1428  static const int kHeaderSize = kMapOffset + kPointerSize;
1429 
1431 
1432  protected:
1433  // helpers for calling an ObjectVisitor to iterate over pointers in the
1434  // half-open range [start, end) specified as integer offsets
1435  inline void IteratePointers(ObjectVisitor* v, int start, int end);
1436  // as above, for the single element at "offset"
1437  inline void IteratePointer(ObjectVisitor* v, int offset);
1438  // as above, for the next code link of a code object.
1439  inline void IterateNextCodeLink(ObjectVisitor* v, int offset);
1440 
1441  private:
1443 };
1444 
1445 
1446 // This class describes a body of an object of a fixed size
1447 // in which all pointer fields are located in the [start_offset, end_offset)
1448 // interval.
1449 template<int start_offset, int end_offset, int size>
1451  public:
1452  static const int kStartOffset = start_offset;
1453  static const int kEndOffset = end_offset;
1454  static const int kSize = size;
1455 
1456  static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1457 
1458  template<typename StaticVisitor>
1459  static inline void IterateBody(HeapObject* obj) {
1460  StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1461  HeapObject::RawField(obj, end_offset));
1462  }
1463 };
1464 
1465 
1466 // This class describes a body of an object of a variable size
1467 // in which all pointer fields are located in the [start_offset, object_size)
1468 // interval.
1469 template<int start_offset>
1471  public:
1472  static const int kStartOffset = start_offset;
1473 
1474  static inline void IterateBody(HeapObject* obj,
1475  int object_size,
1476  ObjectVisitor* v);
1477 
1478  template<typename StaticVisitor>
1479  static inline void IterateBody(HeapObject* obj, int object_size) {
1480  StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1481  HeapObject::RawField(obj, object_size));
1482  }
1483 };
1484 
1485 
1486 // The HeapNumber class describes heap allocated numbers that cannot be
1487 // represented in a Smi (small integer)
1488 class HeapNumber: public HeapObject {
1489  public:
1490  // [value]: number value.
1491  inline double value() const;
1492  inline void set_value(double value);
1493 
1495 
1496  // Dispatched behavior.
1497  bool HeapNumberBooleanValue();
1498 
1499  void HeapNumberPrint(OStream& os); // NOLINT
1501 
1502  inline int get_exponent();
1503  inline int get_sign();
1504 
1505  // Layout description.
1506  static const int kValueOffset = HeapObject::kHeaderSize;
1507  // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1508  // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
1509  // words within double numbers are endian dependent and they are set
1510  // accordingly.
1511 #if defined(V8_TARGET_LITTLE_ENDIAN)
1512  static const int kMantissaOffset = kValueOffset;
1513  static const int kExponentOffset = kValueOffset + 4;
1514 #elif defined(V8_TARGET_BIG_ENDIAN)
1515  static const int kMantissaOffset = kValueOffset + 4;
1516  static const int kExponentOffset = kValueOffset;
1517 #else
1518 #error Unknown byte ordering
1519 #endif
1520 
1521  static const int kSize = kValueOffset + kDoubleSize;
1522  static const uint32_t kSignMask = 0x80000000u;
1523  static const uint32_t kExponentMask = 0x7ff00000u;
1524  static const uint32_t kMantissaMask = 0xfffffu;
1525  static const int kMantissaBits = 52;
1526  static const int kExponentBits = 11;
1527  static const int kExponentBias = 1023;
1528  static const int kExponentShift = 20;
1529  static const int kInfinityOrNanExponent =
1530  (kExponentMask >> kExponentShift) - kExponentBias;
1531  static const int kMantissaBitsInTopWord = 20;
1532  static const int kNonMantissaBitsInTopWord = 12;
1533 
1534  private:
1536 };
1537 
1538 
1543 };
1544 
1545 
1546 // Indicates whether a property should be set or (re)defined. Setting of a
1547 // property causes attributes to remain unchanged, writability to be checked
1548 // and callbacks to be called. Defining of a property causes attributes to
1549 // be updated and callbacks to be overridden.
1553 };
1554 
1555 
1556 // Indicator for one component of an AccessorPair.
1560 };
1561 
1562 
1563 // JSReceiver includes types on which properties can be defined, i.e.,
1564 // JSObject and JSProxy.
1565 class JSReceiver: public HeapObject {
1566  public:
1567  enum DeleteMode {
1570  FORCE_DELETION
1571  };
1572 
1574 
1575  MUST_USE_RESULT static MaybeHandle<Object> SetElement(
1576  Handle<JSReceiver> object,
1577  uint32_t index,
1579  PropertyAttributes attributes,
1580  StrictMode strict_mode);
1581 
1582  // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
1583  MUST_USE_RESULT static inline Maybe<bool> HasProperty(
1585  MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>,
1586  Handle<Name> name);
1587  MUST_USE_RESULT static inline Maybe<bool> HasElement(
1588  Handle<JSReceiver> object, uint32_t index);
1589  MUST_USE_RESULT static inline Maybe<bool> HasOwnElement(
1590  Handle<JSReceiver> object, uint32_t index);
1591 
1592  // Implementation of [[Delete]], ECMA-262 5th edition, section 8.12.7.
1593  MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
1594  Handle<JSReceiver> object,
1596  DeleteMode mode = NORMAL_DELETION);
1597  MUST_USE_RESULT static MaybeHandle<Object> DeleteElement(
1598  Handle<JSReceiver> object,
1599  uint32_t index,
1600  DeleteMode mode = NORMAL_DELETION);
1601 
1602  // Tests for the fast common case for property enumeration.
1603  bool IsSimpleEnum();
1604 
1605  // Returns the class name ([[Class]] property in the specification).
1606  String* class_name();
1607 
1608  // Returns the constructor name (the name (possibly, inferred name) of the
1609  // function that was used to instantiate the object).
1610  String* constructor_name();
1611 
1612  MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes(
1614  MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
1615  LookupIterator* it);
1616  MUST_USE_RESULT static Maybe<PropertyAttributes> GetOwnPropertyAttributes(
1618 
1619  MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttribute(
1620  Handle<JSReceiver> object, uint32_t index);
1622  GetOwnElementAttribute(Handle<JSReceiver> object, uint32_t index);
1623 
1624  // Return the constructor function (may be Heap::null_value()).
1625  inline Object* GetConstructor();
1626 
1627  // Retrieves a permanent object identity hash code. The undefined value might
1628  // be returned in case no hash was created yet.
1629  inline Object* GetIdentityHash();
1630 
1631  // Retrieves a permanent object identity hash code. May create and store a
1632  // hash code if needed and none exists.
1633  inline static Handle<Smi> GetOrCreateIdentityHash(
1634  Handle<JSReceiver> object);
1635 
1636  enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS };
1637 
1638  // Computes the enumerable keys for a JSObject. Used for implementing
1639  // "for (n in object) { }".
1641  Handle<JSReceiver> object,
1642  KeyCollectionType type);
1643 
1644  private:
1646 };
1647 
1648 // Forward declaration for JSObject::GetOrCreateHiddenPropertiesHashTable.
1649 class ObjectHashTable;
1650 
1651 // Forward declaration for JSObject::Copy.
1652 class AllocationSite;
1653 
1654 
1655 // The JSObject describes real heap allocated JavaScript objects with
1656 // properties.
1657 // Note that the map of JSObject changes during execution to enable inline
1658 // caching.
1659 class JSObject: public JSReceiver {
1660  public:
1661  // [properties]: Backing storage for properties.
1662  // properties is a FixedArray in the fast case and a Dictionary in the
1663  // slow case.
1664  DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1665  inline void initialize_properties();
1666  inline bool HasFastProperties();
1667  inline NameDictionary* property_dictionary(); // Gets slow properties.
1668 
1669  // [elements]: The elements (properties with names that are integers).
1670  //
1671  // Elements can be in two general modes: fast and slow. Each mode
1672  // corrensponds to a set of object representations of elements that
1673  // have something in common.
1674  //
1675  // In the fast mode elements is a FixedArray and so each element can
1676  // be quickly accessed. This fact is used in the generated code. The
1677  // elements array can have one of three maps in this mode:
1678  // fixed_array_map, sloppy_arguments_elements_map or
1679  // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1680  // the elements array may be shared by a few objects and so before
1681  // writing to any element the array must be copied. Use
1682  // EnsureWritableFastElements in this case.
1683  //
1684  // In the slow mode the elements is either a NumberDictionary, an
1685  // ExternalArray, or a FixedArray parameter map for a (sloppy)
1686  // arguments object.
1687  DECL_ACCESSORS(elements, FixedArrayBase)
1688  inline void initialize_elements();
1689  static void ResetElements(Handle<JSObject> object);
1690  static inline void SetMapAndElements(Handle<JSObject> object,
1691  Handle<Map> map,
1692  Handle<FixedArrayBase> elements);
1693  inline ElementsKind GetElementsKind();
1694  inline ElementsAccessor* GetElementsAccessor();
1695  // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
1696  inline bool HasFastSmiElements();
1697  // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
1698  inline bool HasFastObjectElements();
1699  // Returns true if an object has elements of FAST_ELEMENTS or
1700  // FAST_SMI_ONLY_ELEMENTS.
1701  inline bool HasFastSmiOrObjectElements();
1702  // Returns true if an object has any of the fast elements kinds.
1703  inline bool HasFastElements();
1704  // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
1705  // ElementsKind.
1706  inline bool HasFastDoubleElements();
1707  // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
1708  // ElementsKind.
1709  inline bool HasFastHoleyElements();
1710  inline bool HasSloppyArgumentsElements();
1711  inline bool HasDictionaryElements();
1712 
1714  inline bool HasExternalArrayElements();
1723 
1724  inline bool HasFixedTypedArrayElements();
1725 
1727  inline bool HasFixedArrayElements();
1728  inline bool HasFixedInt8Elements();
1729  inline bool HasFixedUint8Elements();
1730  inline bool HasFixedInt16Elements();
1731  inline bool HasFixedUint16Elements();
1732  inline bool HasFixedInt32Elements();
1733  inline bool HasFixedUint32Elements();
1736 
1737  bool HasFastArgumentsElements();
1738  bool HasDictionaryArgumentsElements();
1739  inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
1740 
1741  // Requires: HasFastElements().
1742  static Handle<FixedArray> EnsureWritableFastElements(
1743  Handle<JSObject> object);
1744 
1745  // Collects elements starting at index 0.
1746  // Undefined values are placed after non-undefined values.
1747  // Returns the number of non-undefined values.
1748  static Handle<Object> PrepareElementsForSort(Handle<JSObject> object,
1749  uint32_t limit);
1750  // As PrepareElementsForSort, but only on objects where elements is
1751  // a dictionary, and it will stay a dictionary. Collates undefined and
1752  // unexisting elements below limit from position zero of the elements.
1753  static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object,
1754  uint32_t limit);
1755 
1756  MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithInterceptor(
1758 
1759  // SetLocalPropertyIgnoreAttributes converts callbacks to fields. We need to
1760  // grant an exemption to ExecutableAccessor callbacks in some cases.
1763  DONT_FORCE_FIELD
1764  };
1765 
1766  MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes(
1767  Handle<JSObject> object,
1768  Handle<Name> key,
1770  PropertyAttributes attributes,
1771  ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
1772 
1773  static void AddProperty(Handle<JSObject> object, Handle<Name> key,
1775 
1776  // Extend the receiver with a single fast property appeared first in the
1777  // passed map. This also extends the property backing store if necessary.
1778  static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map);
1779 
1780  // Migrates the given object to a map whose field representations are the
1781  // lowest upper bound of all known representations for that field.
1782  static void MigrateInstance(Handle<JSObject> instance);
1783 
1784  // Migrates the given object only if the target map is already available,
1785  // or returns false if such a map is not yet available.
1786  static bool TryMigrateInstance(Handle<JSObject> instance);
1787 
1788  // Sets the property value in a normalized object given (key, value, details).
1789  // Handles the special representation of JS global objects.
1790  static void SetNormalizedProperty(Handle<JSObject> object,
1791  Handle<Name> key,
1793  PropertyDetails details);
1794 
1795  static void OptimizeAsPrototype(Handle<JSObject> object,
1797  static void ReoptimizeIfPrototype(Handle<JSObject> object);
1798 
1799  // Retrieve interceptors.
1800  InterceptorInfo* GetNamedInterceptor();
1801  InterceptorInfo* GetIndexedInterceptor();
1802 
1803  // Used from JSReceiver.
1805  GetPropertyAttributesWithInterceptor(Handle<JSObject> holder,
1806  Handle<Object> receiver,
1807  Handle<Name> name);
1809  GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
1811  GetElementAttributeWithReceiver(Handle<JSObject> object,
1812  Handle<JSReceiver> receiver,
1813  uint32_t index, bool check_prototype);
1814 
1815  // Retrieves an AccessorPair property from the given object. Might return
1816  // undefined if the property doesn't exist or is of a different kind.
1817  MUST_USE_RESULT static MaybeHandle<Object> GetAccessor(
1818  Handle<JSObject> object,
1820  AccessorComponent component);
1821 
1822  // Defines an AccessorPair property on the given object.
1823  // TODO(mstarzinger): Rename to SetAccessor().
1824  static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
1826  Handle<Object> getter,
1827  Handle<Object> setter,
1828  PropertyAttributes attributes);
1829 
1830  // Defines an AccessorInfo property on the given object.
1831  MUST_USE_RESULT static MaybeHandle<Object> SetAccessor(
1832  Handle<JSObject> object,
1833  Handle<AccessorInfo> info);
1834 
1835  MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
1836  Handle<JSObject> object,
1837  Handle<Object> receiver,
1838  Handle<Name> name);
1839 
1840  // Returns true if this is an instance of an api function and has
1841  // been modified since it was created. May give false positives.
1842  bool IsDirty();
1843 
1844  // Accessors for hidden properties object.
1845  //
1846  // Hidden properties are not own properties of the object itself.
1847  // Instead they are stored in an auxiliary structure kept as an own
1848  // property with a special name Heap::hidden_string(). But if the
1849  // receiver is a JSGlobalProxy then the auxiliary object is a property
1850  // of its prototype, and if it's a detached proxy, then you can't have
1851  // hidden properties.
1852 
1853  // Sets a hidden property on this object. Returns this object if successful,
1854  // undefined if called on a detached proxy.
1855  static Handle<Object> SetHiddenProperty(Handle<JSObject> object,
1856  Handle<Name> key,
1858  // Gets the value of a hidden property with the given key. Returns the hole
1859  // if the property doesn't exist (or if called on a detached proxy),
1860  // otherwise returns the value set for the key.
1861  Object* GetHiddenProperty(Handle<Name> key);
1862  // Deletes a hidden property. Deleting a non-existing property is
1863  // considered successful.
1864  static void DeleteHiddenProperty(Handle<JSObject> object,
1865  Handle<Name> key);
1866  // Returns true if the object has a property with the hidden string as name.
1867  static bool HasHiddenProperties(Handle<JSObject> object);
1868 
1869  static void SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash);
1870 
1871  static inline void ValidateElements(Handle<JSObject> object);
1872 
1873  // Makes sure that this object can contain HeapObject as elements.
1874  static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj);
1875 
1876  // Makes sure that this object can contain the specified elements.
1877  static inline void EnsureCanContainElements(
1878  Handle<JSObject> object,
1879  Object** elements,
1880  uint32_t count,
1882  static inline void EnsureCanContainElements(
1883  Handle<JSObject> object,
1884  Handle<FixedArrayBase> elements,
1885  uint32_t length,
1887  static void EnsureCanContainElements(
1888  Handle<JSObject> object,
1889  Arguments* arguments,
1890  uint32_t first_arg,
1891  uint32_t arg_count,
1893 
1894  // Would we convert a fast elements array to dictionary mode given
1895  // an access at key?
1896  bool WouldConvertToSlowElements(Handle<Object> key);
1897  // Do we want to keep the elements in fast case when increasing the
1898  // capacity?
1899  bool ShouldConvertToSlowElements(int new_capacity);
1900  // Returns true if the backing storage for the slow-case elements of
1901  // this object takes up nearly as much space as a fast-case backing
1902  // storage would. In that case the JSObject should have fast
1903  // elements.
1904  bool ShouldConvertToFastElements();
1905  // Returns true if the elements of JSObject contains only values that can be
1906  // represented in a FixedDoubleArray and has at least one value that can only
1907  // be represented as a double and not a Smi.
1908  bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements);
1909 
1910  // Computes the new capacity when expanding the elements of a JSObject.
1911  static int NewElementsCapacity(int old_capacity) {
1912  // (old_capacity + 50%) + 16
1913  return old_capacity + (old_capacity >> 1) + 16;
1914  }
1915 
1916  // These methods do not perform access checks!
1917  MUST_USE_RESULT static MaybeHandle<AccessorPair> GetOwnElementAccessorPair(
1918  Handle<JSObject> object,
1919  uint32_t index);
1920 
1921  MUST_USE_RESULT static MaybeHandle<Object> SetFastElement(
1922  Handle<JSObject> object,
1923  uint32_t index,
1925  StrictMode strict_mode,
1926  bool check_prototype);
1927 
1928  MUST_USE_RESULT static MaybeHandle<Object> SetOwnElement(
1929  Handle<JSObject> object,
1930  uint32_t index,
1932  StrictMode strict_mode);
1933 
1934  // Empty handle is returned if the element cannot be set to the given value.
1935  MUST_USE_RESULT static MaybeHandle<Object> SetElement(
1936  Handle<JSObject> object,
1937  uint32_t index,
1939  PropertyAttributes attributes,
1940  StrictMode strict_mode,
1941  bool check_prototype = true,
1942  SetPropertyMode set_mode = SET_PROPERTY);
1943 
1944  // Returns the index'th element.
1945  // The undefined object if index is out of bounds.
1946  MUST_USE_RESULT static MaybeHandle<Object> GetElementWithInterceptor(
1947  Handle<JSObject> object,
1948  Handle<Object> receiver,
1949  uint32_t index);
1950 
1954  kDontAllowSmiElements
1955  };
1956 
1957  // Replace the elements' backing store with fast elements of the given
1958  // capacity. Update the length for JSArrays. Returns the new backing
1959  // store.
1960  static Handle<FixedArray> SetFastElementsCapacityAndLength(
1961  Handle<JSObject> object,
1962  int capacity,
1963  int length,
1964  SetFastElementsCapacitySmiMode smi_mode);
1965  static void SetFastDoubleElementsCapacityAndLength(
1966  Handle<JSObject> object,
1967  int capacity,
1968  int length);
1969 
1970  // Lookup interceptors are used for handling properties controlled by host
1971  // objects.
1972  inline bool HasNamedInterceptor();
1973  inline bool HasIndexedInterceptor();
1974 
1975  // Computes the enumerable keys from interceptors. Used for debug mirrors and
1976  // by JSReceiver::GetKeys.
1977  MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForNamedInterceptor(
1978  Handle<JSObject> object,
1979  Handle<JSReceiver> receiver);
1980  MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForIndexedInterceptor(
1981  Handle<JSObject> object,
1982  Handle<JSReceiver> receiver);
1983 
1984  // Support functions for v8 api (needed for correct interceptor behavior).
1985  MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty(
1986  Handle<JSObject> object, Handle<Name> key);
1987  MUST_USE_RESULT static Maybe<bool> HasRealElementProperty(
1988  Handle<JSObject> object, uint32_t index);
1989  MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty(
1990  Handle<JSObject> object, Handle<Name> key);
1991 
1992  // Get the header size for a JSObject. Used to compute the index of
1993  // internal fields as well as the number of internal fields.
1994  inline int GetHeaderSize();
1995 
1996  inline int GetInternalFieldCount();
1997  inline int GetInternalFieldOffset(int index);
1998  inline Object* GetInternalField(int index);
1999  inline void SetInternalField(int index, Object* value);
2000  inline void SetInternalField(int index, Smi* value);
2001 
2002  // Returns the number of properties on this object filtering out properties
2003  // with the specified attributes (ignoring interceptors).
2004  int NumberOfOwnProperties(PropertyAttributes filter = NONE);
2005  // Fill in details for properties into storage starting at the specified
2006  // index.
2007  void GetOwnPropertyNames(
2008  FixedArray* storage, int index, PropertyAttributes filter = NONE);
2009 
2010  // Returns the number of properties on this object filtering out properties
2011  // with the specified attributes (ignoring interceptors).
2012  int NumberOfOwnElements(PropertyAttributes filter);
2013  // Returns the number of enumerable elements (ignoring interceptors).
2014  int NumberOfEnumElements();
2015  // Returns the number of elements on this object filtering out elements
2016  // with the specified attributes (ignoring interceptors).
2017  int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter);
2018  // Count and fill in the enumerable elements into storage.
2019  // (storage->length() == NumberOfEnumElements()).
2020  // If storage is NULL, will count the elements without adding
2021  // them to any storage.
2022  // Returns the number of enumerable elements.
2023  int GetEnumElementKeys(FixedArray* storage);
2024 
2025  // Returns a new map with all transitions dropped from the object's current
2026  // map and the ElementsKind set.
2027  static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
2028  ElementsKind to_kind);
2029  static void TransitionElementsKind(Handle<JSObject> object,
2030  ElementsKind to_kind);
2031 
2032  static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map);
2033 
2034  // Convert the object to use the canonical dictionary
2035  // representation. If the object is expected to have additional properties
2036  // added this number can be indicated to have the backing store allocated to
2037  // an initial capacity for holding these properties.
2038  static void NormalizeProperties(Handle<JSObject> object,
2040  int expected_additional_properties);
2041 
2042  // Convert and update the elements backing store to be a
2043  // SeededNumberDictionary dictionary. Returns the backing after conversion.
2044  static Handle<SeededNumberDictionary> NormalizeElements(
2045  Handle<JSObject> object);
2046 
2047  // Transform slow named properties to fast variants.
2048  static void MigrateSlowToFast(Handle<JSObject> object,
2049  int unused_property_fields);
2050 
2051  // Access fast-case object properties at index.
2052  static Handle<Object> FastPropertyAt(Handle<JSObject> object,
2053  Representation representation,
2054  FieldIndex index);
2055  inline Object* RawFastPropertyAt(FieldIndex index);
2056  inline void FastPropertyAtPut(FieldIndex index, Object* value);
2057  void WriteToField(int descriptor, Object* value);
2058 
2059  // Access to in object properties.
2060  inline int GetInObjectPropertyOffset(int index);
2061  inline Object* InObjectPropertyAt(int index);
2062  inline Object* InObjectPropertyAtPut(int index,
2063  Object* value,
2066 
2067  // Set the object's prototype (only JSReceiver and null are allowed values).
2068  MUST_USE_RESULT static MaybeHandle<Object> SetPrototype(
2069  Handle<JSObject> object, Handle<Object> value, bool from_javascript);
2070 
2071  // Initializes the body after properties slot, properties slot is
2072  // initialized by set_properties. Fill the pre-allocated fields with
2073  // pre_allocated_value and the rest with filler_value.
2074  // Note: this call does not update write barrier, the caller is responsible
2075  // to ensure that |filler_value| can be collected without WB here.
2076  inline void InitializeBody(Map* map,
2077  Object* pre_allocated_value,
2078  Object* filler_value);
2079 
2080  // Check whether this object references another object
2081  bool ReferencesObject(Object* obj);
2082 
2083  // Disalow further properties to be added to the object.
2084  MUST_USE_RESULT static MaybeHandle<Object> PreventExtensions(
2085  Handle<JSObject> object);
2086 
2087  // ES5 Object.freeze
2089 
2090  // Called the first time an object is observed with ES7 Object.observe.
2091  static void SetObserved(Handle<JSObject> object);
2092 
2093  // Copy object.
2094  enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
2095 
2097  MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy(
2098  Handle<JSObject> object,
2099  AllocationSiteUsageContext* site_context,
2100  DeepCopyHints hints = kNoHints);
2101  MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk(
2102  Handle<JSObject> object,
2103  AllocationSiteCreationContext* site_context);
2104 
2105  static Handle<Object> GetDataProperty(Handle<JSObject> object,
2106  Handle<Name> key);
2107  static Handle<Object> GetDataProperty(LookupIterator* it);
2108 
2110 
2111  // Dispatched behavior.
2112  void JSObjectShortPrint(StringStream* accumulator);
2115 #ifdef OBJECT_PRINT
2116  void PrintProperties(OStream& os); // NOLINT
2117  void PrintElements(OStream& os); // NOLINT
2118  void PrintTransitions(OStream& os); // NOLINT
2119 #endif
2120 
2121  static void PrintElementsTransition(
2122  FILE* file, Handle<JSObject> object,
2123  ElementsKind from_kind, Handle<FixedArrayBase> from_elements,
2124  ElementsKind to_kind, Handle<FixedArrayBase> to_elements);
2125 
2126  void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map);
2127 
2128 #ifdef DEBUG
2129  // Structure for collecting spill information about JSObjects.
2130  class SpillInformation {
2131  public:
2132  void Clear();
2133  void Print();
2134  int number_of_objects_;
2135  int number_of_objects_with_fast_properties_;
2136  int number_of_objects_with_fast_elements_;
2137  int number_of_fast_used_fields_;
2138  int number_of_fast_unused_fields_;
2139  int number_of_slow_used_properties_;
2140  int number_of_slow_unused_properties_;
2141  int number_of_fast_used_elements_;
2142  int number_of_fast_unused_elements_;
2143  int number_of_slow_used_elements_;
2144  int number_of_slow_unused_elements_;
2145  };
2146 
2147  void IncrementSpillStatistics(SpillInformation* info);
2148 #endif
2149 
2150 #ifdef VERIFY_HEAP
2151  // If a GC was caused while constructing this object, the elements pointer
2152  // may point to a one pointer filler map. The object won't be rooted, but
2153  // our heap verification code could stumble across it.
2154  bool ElementsAreSafeToExamine();
2155 #endif
2156 
2157  Object* SlowReverseLookup(Object* value);
2158 
2159  // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2160  // Also maximal value of JSArray's length property.
2161  static const uint32_t kMaxElementCount = 0xffffffffu;
2162 
2163  // Constants for heuristics controlling conversion of fast elements
2164  // to slow elements.
2165 
2166  // Maximal gap that can be introduced by adding an element beyond
2167  // the current elements length.
2168  static const uint32_t kMaxGap = 1024;
2169 
2170  // Maximal length of fast elements array that won't be checked for
2171  // being dense enough on expansion.
2172  static const int kMaxUncheckedFastElementsLength = 5000;
2173 
2174  // Same as above but for old arrays. This limit is more strict. We
2175  // don't want to be wasteful with long lived objects.
2176  static const int kMaxUncheckedOldFastElementsLength = 500;
2177 
2178  // Note that Page::kMaxRegularHeapObjectSize puts a limit on
2179  // permissible values (see the DCHECK in heap.cc).
2180  static const int kInitialMaxFastElementArray = 100000;
2181 
2182  // This constant applies only to the initial map of "$Object" aka
2183  // "global.Object" and not to arbitrary other JSObject maps.
2184  static const int kInitialGlobalObjectUnusedPropertiesCount = 4;
2185 
2186  static const int kMaxInstanceSize = 255 * kPointerSize;
2187  // When extending the backing storage for property values, we increase
2188  // its size by more than the 1 entry necessary, so sequentially adding fields
2189  // to the same object requires fewer allocations and copies.
2190  static const int kFieldsAdded = 3;
2191 
2192  // Layout description.
2193  static const int kPropertiesOffset = HeapObject::kHeaderSize;
2194  static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2195  static const int kHeaderSize = kElementsOffset + kPointerSize;
2196 
2198 
2199  class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2200  public:
2201  static inline int SizeOf(Map* map, HeapObject* object);
2202  };
2203 
2204  Context* GetCreationContext();
2205 
2206  // Enqueue change record for Object.observe. May cause GC.
2207  static void EnqueueChangeRecord(Handle<JSObject> object,
2208  const char* type,
2210  Handle<Object> old_value);
2211 
2212  static void MigrateToNewProperty(Handle<JSObject> object,
2213  Handle<Map> transition,
2215 
2216  private:
2218  friend class JSReceiver;
2219  friend class Object;
2220 
2221  static void MigrateFastToFast(Handle<JSObject> object, Handle<Map> new_map);
2222  static void MigrateFastToSlow(Handle<JSObject> object,
2223  Handle<Map> new_map,
2224  int expected_additional_properties);
2225 
2226  static void GeneralizeFieldRepresentation(Handle<JSObject> object,
2227  int modify_index,
2228  Representation new_representation,
2229  Handle<HeapType> new_field_type);
2230 
2231  static void UpdateAllocationSite(Handle<JSObject> object,
2232  ElementsKind to_kind);
2233 
2234  // Used from Object::GetProperty().
2235  MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck(
2236  LookupIterator* it);
2237 
2238  MUST_USE_RESULT static MaybeHandle<Object> GetElementWithCallback(
2239  Handle<JSObject> object,
2240  Handle<Object> receiver,
2241  Handle<Object> structure,
2242  uint32_t index,
2243  Handle<Object> holder);
2244 
2246  GetElementAttributeWithInterceptor(Handle<JSObject> object,
2247  Handle<JSReceiver> receiver,
2248  uint32_t index, bool continue_search);
2250  GetElementAttributeWithoutInterceptor(Handle<JSObject> object,
2251  Handle<JSReceiver> receiver,
2252  uint32_t index,
2253  bool continue_search);
2254  MUST_USE_RESULT static MaybeHandle<Object> SetElementWithCallback(
2255  Handle<JSObject> object,
2256  Handle<Object> structure,
2257  uint32_t index,
2259  Handle<JSObject> holder,
2260  StrictMode strict_mode);
2261  MUST_USE_RESULT static MaybeHandle<Object> SetElementWithInterceptor(
2262  Handle<JSObject> object,
2263  uint32_t index,
2265  PropertyAttributes attributes,
2266  StrictMode strict_mode,
2267  bool check_prototype,
2268  SetPropertyMode set_mode);
2269  MUST_USE_RESULT static MaybeHandle<Object> SetElementWithoutInterceptor(
2270  Handle<JSObject> object,
2271  uint32_t index,
2273  PropertyAttributes attributes,
2274  StrictMode strict_mode,
2275  bool check_prototype,
2276  SetPropertyMode set_mode);
2278  static MaybeHandle<Object> SetElementWithCallbackSetterInPrototypes(
2279  Handle<JSObject> object,
2280  uint32_t index,
2282  bool* found,
2283  StrictMode strict_mode);
2284  MUST_USE_RESULT static MaybeHandle<Object> SetDictionaryElement(
2285  Handle<JSObject> object,
2286  uint32_t index,
2288  PropertyAttributes attributes,
2289  StrictMode strict_mode,
2290  bool check_prototype,
2291  SetPropertyMode set_mode = SET_PROPERTY);
2292  MUST_USE_RESULT static MaybeHandle<Object> SetFastDoubleElement(
2293  Handle<JSObject> object,
2294  uint32_t index,
2296  StrictMode strict_mode,
2297  bool check_prototype = true);
2298 
2299  MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithFailedAccessCheck(
2300  LookupIterator* it, Handle<Object> value, StrictMode strict_mode);
2301 
2302  // Add a property to a slow-case object.
2303  static void AddSlowProperty(Handle<JSObject> object,
2306  PropertyAttributes attributes);
2307 
2308  MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
2309  Handle<JSObject> object,
2311  DeleteMode mode);
2312  MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithInterceptor(
2314 
2315  // Deletes the named property in a normalized object.
2316  static Handle<Object> DeleteNormalizedProperty(Handle<JSObject> object,
2318  DeleteMode mode);
2319 
2320  MUST_USE_RESULT static MaybeHandle<Object> DeleteElement(
2321  Handle<JSObject> object,
2322  uint32_t index,
2323  DeleteMode mode);
2324  MUST_USE_RESULT static MaybeHandle<Object> DeleteElementWithInterceptor(
2325  Handle<JSObject> object,
2326  uint32_t index);
2327 
2328  bool ReferencesObjectFromElements(FixedArray* elements,
2329  ElementsKind kind,
2330  Object* object);
2331 
2332  // Returns true if most of the elements backing storage is used.
2333  bool HasDenseElements();
2334 
2335  // Gets the current elements capacity and the number of used elements.
2336  void GetElementsCapacityAndUsage(int* capacity, int* used);
2337 
2339  static void SetElementCallback(Handle<JSObject> object,
2340  uint32_t index,
2341  Handle<Object> structure,
2342  PropertyAttributes attributes);
2343  static void SetPropertyCallback(Handle<JSObject> object,
2345  Handle<Object> structure,
2346  PropertyAttributes attributes);
2347  static void DefineElementAccessor(Handle<JSObject> object,
2348  uint32_t index,
2349  Handle<Object> getter,
2350  Handle<Object> setter,
2351  PropertyAttributes attributes);
2352 
2353  // Return the hash table backing store or the inline stored identity hash,
2354  // whatever is found.
2355  MUST_USE_RESULT Object* GetHiddenPropertiesHashTable();
2356 
2357  // Return the hash table backing store for hidden properties. If there is no
2358  // backing store, allocate one.
2359  static Handle<ObjectHashTable> GetOrCreateHiddenPropertiesHashtable(
2360  Handle<JSObject> object);
2361 
2362  // Set the hidden property backing store to either a hash table or
2363  // the inline-stored identity hash.
2364  static Handle<Object> SetHiddenPropertiesHashTable(
2365  Handle<JSObject> object,
2367 
2368  MUST_USE_RESULT Object* GetIdentityHash();
2369 
2370  static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
2371 
2373 };
2374 
2375 
2376 // Common superclass for FixedArrays that allow implementations to share
2377 // common accessors and some code paths.
2379  public:
2380  // [length]: length of the array.
2381  inline int length() const;
2382  inline void set_length(int value);
2383 
2384  // Get and set the length using acquire loads and release stores.
2385  inline int synchronized_length() const;
2386  inline void synchronized_set_length(int value);
2387 
2389 
2390  // Layout description.
2391  // Length is smi tagged when it is stored.
2392  static const int kLengthOffset = HeapObject::kHeaderSize;
2393  static const int kHeaderSize = kLengthOffset + kPointerSize;
2394 };
2395 
2396 
2397 class FixedDoubleArray;
2398 class IncrementalMarking;
2399 
2400 
2401 // FixedArray describes fixed-sized arrays with element type Object*.
2403  public:
2404  // Setter and getter for elements.
2405  inline Object* get(int index);
2406  static inline Handle<Object> get(Handle<FixedArray> array, int index);
2407  // Setter that uses write barrier.
2408  inline void set(int index, Object* value);
2409  inline bool is_the_hole(int index);
2410 
2411  // Setter that doesn't need write barrier.
2412  inline void set(int index, Smi* value);
2413  // Setter with explicit barrier mode.
2414  inline void set(int index, Object* value, WriteBarrierMode mode);
2415 
2416  // Setters for frequently used oddballs located in old space.
2417  inline void set_undefined(int index);
2418  inline void set_null(int index);
2419  inline void set_the_hole(int index);
2420 
2421  inline Object** GetFirstElementAddress();
2422  inline bool ContainsOnlySmisOrHoles();
2423 
2424  // Gives access to raw memory which stores the array's data.
2425  inline Object** data_start();
2426 
2427  inline void FillWithHoles(int from, int to);
2428 
2429  // Shrink length and insert filler objects.
2430  void Shrink(int length);
2431 
2432  // Copy operation.
2433  static Handle<FixedArray> CopySize(Handle<FixedArray> array,
2434  int new_length,
2435  PretenureFlag pretenure = NOT_TENURED);
2436 
2437  // Add the elements of a JSArray to this FixedArray.
2438  MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromArrayLike(
2439  Handle<FixedArray> content,
2440  Handle<JSObject> array);
2441 
2442  // Computes the union of keys and return the result.
2443  // Used for implementing "for (n in object) { }"
2444  MUST_USE_RESULT static MaybeHandle<FixedArray> UnionOfKeys(
2445  Handle<FixedArray> first,
2446  Handle<FixedArray> second);
2447 
2448  // Copy a sub array from the receiver to dest.
2449  void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2450 
2451  // Garbage collection support.
2452  static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2453 
2454  // Code Generation support.
2455  static int OffsetOfElementAt(int index) { return SizeFor(index); }
2456 
2457  // Garbage collection support.
2459  return HeapObject::RawField(this, OffsetOfElementAt(index));
2460  }
2461 
2463 
2464  // Maximal allowed size, in bytes, of a single FixedArray.
2465  // Prevents overflowing size computations, as well as extreme memory
2466  // consumption.
2467  static const int kMaxSize = 128 * MB * kPointerSize;
2468  // Maximally allowed length of a FixedArray.
2469  static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
2470 
2471  // Dispatched behavior.
2474 #ifdef DEBUG
2475  // Checks if two FixedArrays have identical contents.
2476  bool IsEqualTo(FixedArray* other);
2477 #endif
2478 
2479  // Swap two elements in a pair of arrays. If this array and the
2480  // numbers array are the same object, the elements are only swapped
2481  // once.
2482  void SwapPairs(FixedArray* numbers, int i, int j);
2483 
2484  // Sort prefix of this array and the numbers array as pairs wrt. the
2485  // numbers. If the numbers array and the this array are the same
2486  // object, the prefix of this array is sorted.
2487  void SortPairs(FixedArray* numbers, uint32_t len);
2488 
2489  class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2490  public:
2491  static inline int SizeOf(Map* map, HeapObject* object) {
2492  return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2493  }
2494  };
2495 
2496  protected:
2497  // Set operation on FixedArray without using write barriers. Can
2498  // only be used for storing old space objects or smis.
2499  static inline void NoWriteBarrierSet(FixedArray* array,
2500  int index,
2501  Object* value);
2502 
2503  // Set operation on FixedArray without incremental write barrier. Can
2504  // only be used if the object is guaranteed to be white (whiteness witness
2505  // is present).
2506  static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2507  int index,
2508  Object* value);
2509 
2510  private:
2512 
2514 };
2515 
2516 
2517 // FixedDoubleArray describes fixed-sized arrays with element type double.
2519  public:
2520  // Setter and getter for elements.
2521  inline double get_scalar(int index);
2522  inline int64_t get_representation(int index);
2523  static inline Handle<Object> get(Handle<FixedDoubleArray> array, int index);
2524  inline void set(int index, double value);
2525  inline void set_the_hole(int index);
2526 
2527  // Checking for the hole.
2528  inline bool is_the_hole(int index);
2529 
2530  // Garbage collection support.
2531  inline static int SizeFor(int length) {
2532  return kHeaderSize + length * kDoubleSize;
2533  }
2534 
2535  // Gives access to raw memory which stores the array's data.
2536  inline double* data_start();
2537 
2538  inline void FillWithHoles(int from, int to);
2539 
2540  // Code Generation support.
2541  static int OffsetOfElementAt(int index) { return SizeFor(index); }
2542 
2543  inline static bool is_the_hole_nan(double value);
2544  inline static double hole_nan_as_double();
2545  inline static double canonical_not_the_hole_nan_as_double();
2546 
2548 
2549  // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2550  // Prevents overflowing size computations, as well as extreme memory
2551  // consumption.
2552  static const int kMaxSize = 512 * MB;
2553  // Maximally allowed length of a FixedArray.
2554  static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2555 
2556  // Dispatched behavior.
2559 
2560  private:
2562 };
2563 
2564 
2565 // ConstantPoolArray describes a fixed-sized array containing constant pool
2566 // entries.
2567 //
2568 // A ConstantPoolArray can be structured in two different ways depending upon
2569 // whether it is extended or small. The is_extended_layout() method can be used
2570 // to discover which layout the constant pool has.
2571 //
2572 // The format of a small constant pool is:
2573 // [kSmallLayout1Offset] : Small section layout bitmap 1
2574 // [kSmallLayout2Offset] : Small section layout bitmap 2
2575 // [first_index(INT64, SMALL_SECTION)] : 64 bit entries
2576 // ... : ...
2577 // [first_index(CODE_PTR, SMALL_SECTION)] : code pointer entries
2578 // ... : ...
2579 // [first_index(HEAP_PTR, SMALL_SECTION)] : heap pointer entries
2580 // ... : ...
2581 // [first_index(INT32, SMALL_SECTION)] : 32 bit entries
2582 // ... : ...
2583 //
2584 // If the constant pool has an extended layout, the extended section constant
2585 // pool also contains an extended section, which has the following format at
2586 // location get_extended_section_header_offset():
2587 // [kExtendedInt64CountOffset] : count of extended 64 bit entries
2588 // [kExtendedCodePtrCountOffset] : count of extended code pointers
2589 // [kExtendedHeapPtrCountOffset] : count of extended heap pointers
2590 // [kExtendedInt32CountOffset] : count of extended 32 bit entries
2591 // [first_index(INT64, EXTENDED_SECTION)] : 64 bit entries
2592 // ... : ...
2593 // [first_index(CODE_PTR, EXTENDED_SECTION)]: code pointer entries
2594 // ... : ...
2595 // [first_index(HEAP_PTR, EXTENDED_SECTION)]: heap pointer entries
2596 // ... : ...
2597 // [first_index(INT32, EXTENDED_SECTION)] : 32 bit entries
2598 // ... : ...
2599 //
2601  public:
2605  WEAK_OBJECTS_IN_IC
2606  };
2607 
2608  enum Type {
2609  INT64 = 0,
2613  // Number of types stored by the ConstantPoolArrays.
2615  FIRST_TYPE = INT64,
2616  LAST_TYPE = INT32
2617  };
2618 
2620  SMALL_SECTION = 0,
2622  NUMBER_OF_LAYOUT_SECTIONS
2623  };
2624 
2625  class NumberOfEntries BASE_EMBEDDED {
2626  public:
2627  inline NumberOfEntries() {
2628  for (int i = 0; i < NUMBER_OF_TYPES; i++) {
2629  element_counts_[i] = 0;
2630  }
2631  }
2632 
2633  inline NumberOfEntries(int int64_count, int code_ptr_count,
2634  int heap_ptr_count, int int32_count) {
2635  element_counts_[INT64] = int64_count;
2636  element_counts_[CODE_PTR] = code_ptr_count;
2637  element_counts_[HEAP_PTR] = heap_ptr_count;
2638  element_counts_[INT32] = int32_count;
2639  }
2640 
2642  element_counts_[INT64] = array->number_of_entries(INT64, section);
2643  element_counts_[CODE_PTR] = array->number_of_entries(CODE_PTR, section);
2644  element_counts_[HEAP_PTR] = array->number_of_entries(HEAP_PTR, section);
2645  element_counts_[INT32] = array->number_of_entries(INT32, section);
2646  }
2647 
2648  inline void increment(Type type);
2649  inline int equals(const NumberOfEntries& other) const;
2650  inline bool is_empty() const;
2651  inline int count_of(Type type) const;
2652  inline int base_of(Type type) const;
2653  inline int total_count() const;
2654  inline int are_in_range(int min, int max) const;
2655 
2656  private:
2657  int element_counts_[NUMBER_OF_TYPES];
2658  };
2659 
2660  class Iterator BASE_EMBEDDED {
2661  public:
2662  inline Iterator(ConstantPoolArray* array, Type type)
2663  : array_(array),
2664  type_(type),
2665  final_section_(array->final_section()),
2666  current_section_(SMALL_SECTION),
2667  next_index_(array->first_index(type, SMALL_SECTION)) {
2668  update_section();
2669  }
2670 
2671  inline Iterator(ConstantPoolArray* array, Type type, LayoutSection section)
2672  : array_(array),
2673  type_(type),
2674  final_section_(section),
2675  current_section_(section),
2676  next_index_(array->first_index(type, section)) {
2677  update_section();
2678  }
2679 
2680  inline int next_index();
2681  inline bool is_finished();
2682 
2683  private:
2684  inline void update_section();
2686  const Type type_;
2688 
2691  };
2692 
2693  // Getters for the first index, the last index and the count of entries of
2694  // a given type for a given layout section.
2695  inline int first_index(Type type, LayoutSection layout_section);
2696  inline int last_index(Type type, LayoutSection layout_section);
2697  inline int number_of_entries(Type type, LayoutSection layout_section);
2698 
2699  // Returns the type of the entry at the given index.
2700  inline Type get_type(int index);
2701  inline bool offset_is_type(int offset, Type type);
2702 
2703  // Setter and getter for pool elements.
2704  inline Address get_code_ptr_entry(int index);
2705  inline Object* get_heap_ptr_entry(int index);
2706  inline int64_t get_int64_entry(int index);
2707  inline int32_t get_int32_entry(int index);
2708  inline double get_int64_entry_as_double(int index);
2709 
2710  inline void set(int index, Address value);
2711  inline void set(int index, Object* value);
2712  inline void set(int index, int64_t value);
2713  inline void set(int index, double value);
2714  inline void set(int index, int32_t value);
2715 
2716  // Setters which take a raw offset rather than an index (for code generation).
2717  inline void set_at_offset(int offset, int32_t value);
2718  inline void set_at_offset(int offset, int64_t value);
2719  inline void set_at_offset(int offset, double value);
2720  inline void set_at_offset(int offset, Address value);
2721  inline void set_at_offset(int offset, Object* value);
2722 
2723  // Setter and getter for weak objects state
2724  inline void set_weak_object_state(WeakObjectState state);
2725  inline WeakObjectState get_weak_object_state();
2726 
2727  // Returns true if the constant pool has an extended layout, false if it has
2728  // only the small layout.
2729  inline bool is_extended_layout();
2730 
2731  // Returns the last LayoutSection in this constant pool array.
2732  inline LayoutSection final_section();
2733 
2734  // Set up initial state for a small layout constant pool array.
2735  inline void Init(const NumberOfEntries& small);
2736 
2737  // Set up initial state for an extended layout constant pool array.
2738  inline void InitExtended(const NumberOfEntries& small,
2739  const NumberOfEntries& extended);
2740 
2741  // Clears the pointer entries with GC safe values.
2742  void ClearPtrEntries(Isolate* isolate);
2743 
2744  // returns the total number of entries in the constant pool array.
2745  inline int length();
2746 
2747  // Garbage collection support.
2748  inline int size();
2749 
2750 
2751  inline static int MaxInt64Offset(int number_of_int64) {
2752  return kFirstEntryOffset + (number_of_int64 * kInt64Size);
2753  }
2754 
2755  inline static int SizeFor(const NumberOfEntries& small) {
2756  int size = kFirstEntryOffset +
2757  (small.count_of(INT64) * kInt64Size) +
2758  (small.count_of(CODE_PTR) * kPointerSize) +
2759  (small.count_of(HEAP_PTR) * kPointerSize) +
2760  (small.count_of(INT32) * kInt32Size);
2761  return RoundUp(size, kPointerSize);
2762  }
2763 
2764  inline static int SizeForExtended(const NumberOfEntries& small,
2765  const NumberOfEntries& extended) {
2766  int size = SizeFor(small);
2767  size = RoundUp(size, kInt64Size); // Align extended header to 64 bits.
2768  size += kExtendedFirstOffset +
2769  (extended.count_of(INT64) * kInt64Size) +
2770  (extended.count_of(CODE_PTR) * kPointerSize) +
2771  (extended.count_of(HEAP_PTR) * kPointerSize) +
2772  (extended.count_of(INT32) * kInt32Size);
2773  return RoundUp(size, kPointerSize);
2774  }
2775 
2776  inline static int entry_size(Type type) {
2777  switch (type) {
2778  case INT32:
2779  return kInt32Size;
2780  case INT64:
2781  return kInt64Size;
2782  case CODE_PTR:
2783  case HEAP_PTR:
2784  return kPointerSize;
2785  default:
2786  UNREACHABLE();
2787  return 0;
2788  }
2789  }
2790 
2791  // Code Generation support.
2792  inline int OffsetOfElementAt(int index) {
2793  int offset;
2794  LayoutSection section;
2795  if (is_extended_layout() && index >= first_extended_section_index()) {
2796  section = EXTENDED_SECTION;
2797  offset = get_extended_section_header_offset() + kExtendedFirstOffset;
2798  } else {
2799  section = SMALL_SECTION;
2800  offset = kFirstEntryOffset;
2801  }
2802 
2803  // Add offsets for the preceding type sections.
2804  DCHECK(index <= last_index(LAST_TYPE, section));
2805  for (Type type = FIRST_TYPE; index > last_index(type, section);
2806  type = next_type(type)) {
2807  offset += entry_size(type) * number_of_entries(type, section);
2808  }
2809 
2810  // Add offset for the index in it's type.
2811  Type type = get_type(index);
2812  offset += entry_size(type) * (index - first_index(type, section));
2813  return offset;
2814  }
2815 
2817 
2818  // Garbage collection support.
2819  Object** RawFieldOfElementAt(int index) {
2820  return HeapObject::RawField(this, OffsetOfElementAt(index));
2821  }
2822 
2823  // Small Layout description.
2824  static const int kSmallLayout1Offset = HeapObject::kHeaderSize;
2825  static const int kSmallLayout2Offset = kSmallLayout1Offset + kInt32Size;
2826  static const int kHeaderSize = kSmallLayout2Offset + kInt32Size;
2827  static const int kFirstEntryOffset = ROUND_UP(kHeaderSize, kInt64Size);
2828 
2829  static const int kSmallLayoutCountBits = 10;
2830  static const int kMaxSmallEntriesPerType = (1 << kSmallLayoutCountBits) - 1;
2831 
2832  // Fields in kSmallLayout1Offset.
2833  class Int64CountField: public BitField<int, 1, kSmallLayoutCountBits> {};
2834  class CodePtrCountField: public BitField<int, 11, kSmallLayoutCountBits> {};
2835  class HeapPtrCountField: public BitField<int, 21, kSmallLayoutCountBits> {};
2836  class IsExtendedField: public BitField<bool, 31, 1> {};
2837 
2838  // Fields in kSmallLayout2Offset.
2839  class Int32CountField: public BitField<int, 1, kSmallLayoutCountBits> {};
2840  class TotalCountField: public BitField<int, 11, 12> {};
2841  class WeakObjectStateField: public BitField<WeakObjectState, 23, 2> {};
2842 
2843  // Extended layout description, which starts at
2844  // get_extended_section_header_offset().
2845  static const int kExtendedInt64CountOffset = 0;
2846  static const int kExtendedCodePtrCountOffset =
2847  kExtendedInt64CountOffset + kPointerSize;
2848  static const int kExtendedHeapPtrCountOffset =
2849  kExtendedCodePtrCountOffset + kPointerSize;
2850  static const int kExtendedInt32CountOffset =
2851  kExtendedHeapPtrCountOffset + kPointerSize;
2852  static const int kExtendedFirstOffset =
2853  kExtendedInt32CountOffset + kPointerSize;
2854 
2855  // Dispatched behavior.
2856  void ConstantPoolIterateBody(ObjectVisitor* v);
2857 
2860 
2861  private:
2862  inline int first_extended_section_index();
2863  inline int get_extended_section_header_offset();
2864 
2865  inline static Type next_type(Type type) {
2866  DCHECK(type >= FIRST_TYPE && type < NUMBER_OF_TYPES);
2867  int type_int = static_cast<int>(type);
2868  return static_cast<Type>(++type_int);
2869  }
2870 
2872 };
2873 
2874 
2875 // DescriptorArrays are fixed arrays used to hold instance descriptors.
2876 // The format of the these objects is:
2877 // [0]: Number of descriptors
2878 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array:
2879 // [0]: pointer to fixed array with enum cache
2880 // [1]: either Smi(0) or pointer to fixed array with indices
2881 // [2]: first key
2882 // [2 + number of descriptors * kDescriptorSize]: start of slack
2884  public:
2885  // Returns true for both shared empty_descriptor_array and for smis, which the
2886  // map uses to encode additional bit fields when the descriptor array is not
2887  // yet used.
2888  inline bool IsEmpty();
2889 
2890  // Returns the number of descriptors in the array.
2892  DCHECK(length() >= kFirstIndex || IsEmpty());
2893  int len = length();
2894  return len == 0 ? 0 : Smi::cast(get(kDescriptorLengthIndex))->value();
2895  }
2896 
2898  int len = length();
2899  return len == 0 ? 0 : (len - kFirstIndex) / kDescriptorSize;
2900  }
2901 
2903  return number_of_descriptors_storage() - number_of_descriptors();
2904  }
2905 
2906  inline void SetNumberOfDescriptors(int number_of_descriptors);
2907  inline int number_of_entries() { return number_of_descriptors(); }
2908 
2909  bool HasEnumCache() {
2910  return !IsEmpty() && !get(kEnumCacheIndex)->IsSmi();
2911  }
2912 
2914  set(kEnumCacheIndex, array->get(kEnumCacheIndex));
2915  }
2916 
2918  DCHECK(HasEnumCache());
2919  FixedArray* bridge = FixedArray::cast(get(kEnumCacheIndex));
2920  return FixedArray::cast(bridge->get(kEnumCacheBridgeCacheIndex));
2921  }
2922 
2924  if (IsEmpty()) return false;
2925  Object* object = get(kEnumCacheIndex);
2926  if (object->IsSmi()) return false;
2927  FixedArray* bridge = FixedArray::cast(object);
2928  return !bridge->get(kEnumCacheBridgeIndicesCacheIndex)->IsSmi();
2929  }
2930 
2932  DCHECK(HasEnumIndicesCache());
2933  FixedArray* bridge = FixedArray::cast(get(kEnumCacheIndex));
2934  return FixedArray::cast(bridge->get(kEnumCacheBridgeIndicesCacheIndex));
2935  }
2936 
2938  DCHECK(HasEnumCache());
2939  return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2940  kEnumCacheOffset);
2941  }
2942 
2943  void ClearEnumCache();
2944 
2945  // Initialize or change the enum cache,
2946  // using the supplied storage for the small "bridge".
2947  void SetEnumCache(FixedArray* bridge_storage,
2948  FixedArray* new_cache,
2949  Object* new_index_cache);
2950 
2951  bool CanHoldValue(int descriptor, Object* value);
2952 
2953  // Accessors for fetching instance descriptor at descriptor number.
2954  inline Name* GetKey(int descriptor_number);
2955  inline Object** GetKeySlot(int descriptor_number);
2956  inline Object* GetValue(int descriptor_number);
2957  inline void SetValue(int descriptor_number, Object* value);
2958  inline Object** GetValueSlot(int descriptor_number);
2959  static inline int GetValueOffset(int descriptor_number);
2960  inline Object** GetDescriptorStartSlot(int descriptor_number);
2961  inline Object** GetDescriptorEndSlot(int descriptor_number);
2962  inline PropertyDetails GetDetails(int descriptor_number);
2963  inline PropertyType GetType(int descriptor_number);
2964  inline int GetFieldIndex(int descriptor_number);
2965  inline HeapType* GetFieldType(int descriptor_number);
2966  inline Object* GetConstant(int descriptor_number);
2967  inline Object* GetCallbacksObject(int descriptor_number);
2968  inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2969 
2970  inline Name* GetSortedKey(int descriptor_number);
2971  inline int GetSortedKeyIndex(int descriptor_number);
2972  inline void SetSortedKey(int pointer, int descriptor_number);
2973  inline void SetRepresentation(int descriptor_number,
2974  Representation representation);
2975 
2976  // Accessor for complete descriptor.
2977  inline void Get(int descriptor_number, Descriptor* desc);
2978  inline void Set(int descriptor_number, Descriptor* desc);
2979  void Replace(int descriptor_number, Descriptor* descriptor);
2980 
2981  // Append automatically sets the enumeration index. This should only be used
2982  // to add descriptors in bulk at the end, followed by sorting the descriptor
2983  // array.
2984  inline void Append(Descriptor* desc);
2985 
2986  static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc,
2987  int enumeration_index,
2988  int slack = 0);
2989 
2990  static Handle<DescriptorArray> CopyUpToAddAttributes(
2992  int enumeration_index,
2993  PropertyAttributes attributes,
2994  int slack = 0);
2995 
2996  // Sort the instance descriptors by the hash codes of their keys.
2997  void Sort();
2998 
2999  // Search the instance descriptors for given name.
3000  INLINE(int Search(Name* name, int number_of_own_descriptors));
3001 
3002  // As the above, but uses DescriptorLookupCache and updates it when
3003  // necessary.
3004  INLINE(int SearchWithCache(Name* name, Map* map));
3005 
3006  // Allocates a DescriptorArray, but returns the singleton
3007  // empty descriptor array object if number_of_descriptors is 0.
3008  static Handle<DescriptorArray> Allocate(Isolate* isolate,
3009  int number_of_descriptors,
3010  int slack = 0);
3011 
3013 
3014  // Constant for denoting key was not found.
3015  static const int kNotFound = -1;
3016 
3017  static const int kDescriptorLengthIndex = 0;
3018  static const int kEnumCacheIndex = 1;
3019  static const int kFirstIndex = 2;
3020 
3021  // The length of the "bridge" to the enum cache.
3022  static const int kEnumCacheBridgeLength = 2;
3023  static const int kEnumCacheBridgeCacheIndex = 0;
3024  static const int kEnumCacheBridgeIndicesCacheIndex = 1;
3025 
3026  // Layout description.
3027  static const int kDescriptorLengthOffset = FixedArray::kHeaderSize;
3028  static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize;
3029  static const int kFirstOffset = kEnumCacheOffset + kPointerSize;
3030 
3031  // Layout description for the bridge array.
3032  static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
3033 
3034  // Layout of descriptor.
3035  static const int kDescriptorKey = 0;
3036  static const int kDescriptorDetails = 1;
3037  static const int kDescriptorValue = 2;
3038  static const int kDescriptorSize = 3;
3039 
3040 #ifdef OBJECT_PRINT
3041  // Print all the descriptors.
3042  void PrintDescriptors(OStream& os); // NOLINT
3043 #endif
3044 
3045 #ifdef DEBUG
3046  // Is the descriptor array sorted and without duplicates?
3047  bool IsSortedNoDuplicates(int valid_descriptors = -1);
3048 
3049  // Is the descriptor array consistent with the back pointers in targets?
3050  bool IsConsistentWithBackPointers(Map* current_map);
3051 
3052  // Are two DescriptorArrays equal?
3053  bool IsEqualTo(DescriptorArray* other);
3054 #endif
3055 
3056  // Returns the fixed array length required to hold number_of_descriptors
3057  // descriptors.
3058  static int LengthFor(int number_of_descriptors) {
3059  return ToKeyIndex(number_of_descriptors);
3060  }
3061 
3062  private:
3063  // WhitenessWitness is used to prove that a descriptor array is white
3064  // (unmarked), so incremental write barriers can be skipped because the
3065  // marking invariant cannot be broken and slots pointing into evacuation
3066  // candidates will be discovered when the object is scanned. A witness is
3067  // always stack-allocated right after creating an array. By allocating a
3068  // witness, incremental marking is globally disabled. The witness is then
3069  // passed along wherever needed to statically prove that the array is known to
3070  // be white.
3072  public:
3073  inline explicit WhitenessWitness(DescriptorArray* array);
3074  inline ~WhitenessWitness();
3075 
3076  private:
3078  };
3079 
3080  // An entry in a DescriptorArray, represented as an (array, index) pair.
3081  class Entry {
3082  public:
3083  inline explicit Entry(DescriptorArray* descs, int index) :
3084  descs_(descs), index_(index) { }
3085 
3086  inline PropertyType type() { return descs_->GetType(index_); }
3087  inline Object* GetCallbackObject() { return descs_->GetValue(index_); }
3088 
3089  private:
3091  int index_;
3092  };
3093 
3094  // Conversion from descriptor number to array indices.
3095  static int ToKeyIndex(int descriptor_number) {
3096  return kFirstIndex +
3097  (descriptor_number * kDescriptorSize) +
3098  kDescriptorKey;
3099  }
3100 
3101  static int ToDetailsIndex(int descriptor_number) {
3102  return kFirstIndex +
3103  (descriptor_number * kDescriptorSize) +
3104  kDescriptorDetails;
3105  }
3106 
3107  static int ToValueIndex(int descriptor_number) {
3108  return kFirstIndex +
3109  (descriptor_number * kDescriptorSize) +
3110  kDescriptorValue;
3111  }
3112 
3113  // Transfer a complete descriptor from the src descriptor array to this
3114  // descriptor array.
3115  void CopyFrom(int index,
3116  DescriptorArray* src,
3117  const WhitenessWitness&);
3118 
3119  inline void Set(int descriptor_number,
3120  Descriptor* desc,
3121  const WhitenessWitness&);
3122 
3123  // Swap first and second descriptor.
3124  inline void SwapSortedKeys(int first, int second);
3125 
3127 };
3128 
3129 
3131 
3132 template<SearchMode search_mode, typename T>
3133 inline int LinearSearch(T* array, Name* name, int len, int valid_entries);
3134 
3135 
3136 template<SearchMode search_mode, typename T>
3137 inline int Search(T* array, Name* name, int valid_entries = 0);
3138 
3139 
3140 // HashTable is a subclass of FixedArray that implements a hash table
3141 // that uses open addressing and quadratic probing.
3142 //
3143 // In order for the quadratic probing to work, elements that have not
3144 // yet been used and elements that have been deleted are
3145 // distinguished. Probing continues when deleted elements are
3146 // encountered and stops when unused elements are encountered.
3147 //
3148 // - Elements with key == undefined have not been used yet.
3149 // - Elements with key == the_hole have been deleted.
3150 //
3151 // The hash table class is parameterized with a Shape and a Key.
3152 // Shape must be a class with the following interface:
3153 // class ExampleShape {
3154 // public:
3155 // // Tells whether key matches other.
3156 // static bool IsMatch(Key key, Object* other);
3157 // // Returns the hash value for key.
3158 // static uint32_t Hash(Key key);
3159 // // Returns the hash value for object.
3160 // static uint32_t HashForObject(Key key, Object* object);
3161 // // Convert key to an object.
3162 // static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
3163 // // The prefix size indicates number of elements in the beginning
3164 // // of the backing storage.
3165 // static const int kPrefixSize = ..;
3166 // // The Element size indicates number of elements per entry.
3167 // static const int kEntrySize = ..;
3168 // };
3169 // The prefix size indicates an amount of memory in the
3170 // beginning of the backing storage that can be used for non-element
3171 // information by subclasses.
3172 
3173 template<typename Key>
3174 class BaseShape {
3175  public:
3176  static const bool UsesSeed = false;
3177  static uint32_t Hash(Key key) { return 0; }
3178  static uint32_t SeededHash(Key key, uint32_t seed) {
3179  DCHECK(UsesSeed);
3180  return Hash(key);
3181  }
3182  static uint32_t HashForObject(Key key, Object* object) { return 0; }
3183  static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
3184  DCHECK(UsesSeed);
3185  return HashForObject(key, object);
3186  }
3187 };
3188 
3189 template<typename Derived, typename Shape, typename Key>
3190 class HashTable: public FixedArray {
3191  public:
3192  // Wrapper methods
3193  inline uint32_t Hash(Key key) {
3194  if (Shape::UsesSeed) {
3195  return Shape::SeededHash(key, GetHeap()->HashSeed());
3196  } else {
3197  return Shape::Hash(key);
3198  }
3199  }
3200 
3201  inline uint32_t HashForObject(Key key, Object* object) {
3202  if (Shape::UsesSeed) {
3203  return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object);
3204  } else {
3205  return Shape::HashForObject(key, object);
3206  }
3207  }
3208 
3209  // Returns the number of elements in the hash table.
3211  return Smi::cast(get(kNumberOfElementsIndex))->value();
3212  }
3213 
3214  // Returns the number of deleted elements in the hash table.
3216  return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
3217  }
3218 
3219  // Returns the capacity of the hash table.
3220  int Capacity() {
3221  return Smi::cast(get(kCapacityIndex))->value();
3222  }
3223 
3224  // ElementAdded should be called whenever an element is added to a
3225  // hash table.
3226  void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
3227 
3228  // ElementRemoved should be called whenever an element is removed from
3229  // a hash table.
3231  SetNumberOfElements(NumberOfElements() - 1);
3232  SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
3233  }
3234  void ElementsRemoved(int n) {
3235  SetNumberOfElements(NumberOfElements() - n);
3236  SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
3237  }
3238 
3239  // Returns a new HashTable object.
3240  MUST_USE_RESULT static Handle<Derived> New(
3241  Isolate* isolate,
3242  int at_least_space_for,
3244  PretenureFlag pretenure = NOT_TENURED);
3245 
3246  // Computes the required capacity for a table holding the given
3247  // number of elements. May be more than HashTable::kMaxCapacity.
3248  static int ComputeCapacity(int at_least_space_for);
3249 
3250  // Returns the key at entry.
3251  Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3252 
3253  // Tells whether k is a real key. The hole and undefined are not allowed
3254  // as keys and can be used to indicate missing or deleted elements.
3255  bool IsKey(Object* k) {
3256  return !k->IsTheHole() && !k->IsUndefined();
3257  }
3258 
3259  // Garbage collection support.
3260  void IteratePrefix(ObjectVisitor* visitor);
3261  void IterateElements(ObjectVisitor* visitor);
3262 
3264 
3265  // Compute the probe offset (quadratic probing).
3266  INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
3267  return (n + n * n) >> 1;
3268  }
3269 
3270  static const int kNumberOfElementsIndex = 0;
3271  static const int kNumberOfDeletedElementsIndex = 1;
3272  static const int kCapacityIndex = 2;
3273  static const int kPrefixStartIndex = 3;
3274  static const int kElementsStartIndex =
3275  kPrefixStartIndex + Shape::kPrefixSize;
3276  static const int kEntrySize = Shape::kEntrySize;
3277  static const int kElementsStartOffset =
3278  kHeaderSize + kElementsStartIndex * kPointerSize;
3279  static const int kCapacityOffset =
3280  kHeaderSize + kCapacityIndex * kPointerSize;
3281 
3282  // Constant used for denoting a absent entry.
3283  static const int kNotFound = -1;
3284 
3285  // Maximal capacity of HashTable. Based on maximal length of underlying
3286  // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
3287  // cannot overflow.
3288  static const int kMaxCapacity =
3289  (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
3290 
3291  // Find entry for key otherwise return kNotFound.
3292  inline int FindEntry(Key key);
3293  int FindEntry(Isolate* isolate, Key key);
3294 
3295  // Rehashes the table in-place.
3296  void Rehash(Key key);
3297 
3298  protected:
3299  friend class ObjectHashTable;
3300 
3301  // Find the entry at which to insert element with the given key that
3302  // has the given hash value.
3303  uint32_t FindInsertionEntry(uint32_t hash);
3304 
3305  // Returns the index for an entry (of the key)
3306  static inline int EntryToIndex(int entry) {
3307  return (entry * kEntrySize) + kElementsStartIndex;
3308  }
3309 
3310  // Update the number of elements in the hash table.
3311  void SetNumberOfElements(int nof) {
3312  set(kNumberOfElementsIndex, Smi::FromInt(nof));
3313  }
3314 
3315  // Update the number of deleted elements in the hash table.
3317  set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
3318  }
3319 
3320  // Sets the capacity of the hash table.
3321  void SetCapacity(int capacity) {
3322  // To scale a computed hash code to fit within the hash table, we
3323  // use bit-wise AND with a mask, so the capacity must be positive
3324  // and non-zero.
3325  DCHECK(capacity > 0);
3326  DCHECK(capacity <= kMaxCapacity);
3327  set(kCapacityIndex, Smi::FromInt(capacity));
3328  }
3329 
3330 
3331  // Returns probe entry.
3334  return (hash + GetProbeOffset(number)) & (size - 1);
3335  }
3336 
3337  inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
3338  return hash & (size - 1);
3339  }
3340 
3341  inline static uint32_t NextProbe(
3342  uint32_t last, uint32_t number, uint32_t size) {
3343  return (last + number) & (size - 1);
3344  }
3345 
3346  // Attempt to shrink hash table after removal of key.
3347  MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key);
3348 
3349  // Ensure enough space for n additional elements.
3350  MUST_USE_RESULT static Handle<Derived> EnsureCapacity(
3351  Handle<Derived> table,
3352  int n,
3353  Key key,
3354  PretenureFlag pretenure = NOT_TENURED);
3355 
3356  private:
3357  // Returns _expected_ if one of entries given by the first _probe_ probes is
3358  // equal to _expected_. Otherwise, returns the entry given by the probe
3359  // number _probe_.
3360  uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
3361 
3362  void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
3363 
3364  // Rehashes this hash-table into the new table.
3365  void Rehash(Handle<Derived> new_table, Key key);
3366 };
3367 
3368 
3369 // HashTableKey is an abstract superclass for virtual key behavior.
3371  public:
3372  // Returns whether the other object matches this key.
3373  virtual bool IsMatch(Object* other) = 0;
3374  // Returns the hash value for this key.
3375  virtual uint32_t Hash() = 0;
3376  // Returns the hash value for object.
3377  virtual uint32_t HashForObject(Object* key) = 0;
3378  // Returns the key object for storing into the hash table.
3380  // Required.
3381  virtual ~HashTableKey() {}
3382 };
3383 
3384 
3385 class StringTableShape : public BaseShape<HashTableKey*> {
3386  public:
3387  static inline bool IsMatch(HashTableKey* key, Object* value) {
3388  return key->IsMatch(value);
3389  }
3390 
3391  static inline uint32_t Hash(HashTableKey* key) {
3392  return key->Hash();
3393  }
3394 
3395  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
3396  return key->HashForObject(object);
3397  }
3398 
3399  static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
3400 
3401  static const int kPrefixSize = 0;
3402  static const int kEntrySize = 1;
3403 };
3404 
3405 class SeqOneByteString;
3406 
3407 // StringTable.
3408 //
3409 // No special elements in the prefix and the element size is 1
3410 // because only the string itself (the key) needs to be stored.
3411 class StringTable: public HashTable<StringTable,
3412  StringTableShape,
3413  HashTableKey*> {
3414  public:
3415  // Find string in the string table. If it is not there yet, it is
3416  // added. The return value is the string found.
3417  static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
3418  static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
3419 
3420  // Tries to internalize given string and returns string handle on success
3421  // or an empty handle otherwise.
3422  MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
3423  Isolate* isolate,
3424  Handle<String> string);
3425 
3426  // Looks up a string that is equal to the given string and returns
3427  // string handle if it is found, or an empty handle otherwise.
3428  MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
3429  Isolate* isolate,
3430  Handle<String> str);
3431  MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
3432  Isolate* isolate,
3433  uint16_t c1,
3434  uint16_t c2);
3435 
3437 
3438  private:
3439  template <bool seq_one_byte>
3440  friend class JsonParser;
3441 
3443 };
3444 
3445 
3446 class MapCacheShape : public BaseShape<HashTableKey*> {
3447  public:
3448  static inline bool IsMatch(HashTableKey* key, Object* value) {
3449  return key->IsMatch(value);
3450  }
3451 
3452  static inline uint32_t Hash(HashTableKey* key) {
3453  return key->Hash();
3454  }
3455 
3456  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
3457  return key->HashForObject(object);
3458  }
3459 
3460  static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
3461 
3462  static const int kPrefixSize = 0;
3463  static const int kEntrySize = 2;
3464 };
3465 
3466 
3467 // MapCache.
3468 //
3469 // Maps keys that are a fixed array of unique names to a map.
3470 // Used for canonicalize maps for object literals.
3471 class MapCache: public HashTable<MapCache, MapCacheShape, HashTableKey*> {
3472  public:
3473  // Find cached value for a name key, otherwise return null.
3474  Object* Lookup(FixedArray* key);
3475  static Handle<MapCache> Put(
3478 
3479  private:
3481 };
3482 
3483 
3484 template <typename Derived, typename Shape, typename Key>
3485 class Dictionary: public HashTable<Derived, Shape, Key> {
3486  protected:
3488 
3489  public:
3490  // Returns the value at entry.
3491  Object* ValueAt(int entry) {
3492  return this->get(DerivedHashTable::EntryToIndex(entry) + 1);
3493  }
3494 
3495  // Set the value for entry.
3496  void ValueAtPut(int entry, Object* value) {
3497  this->set(DerivedHashTable::EntryToIndex(entry) + 1, value);
3498  }
3499 
3500  // Returns the property details for the property at entry.
3501  PropertyDetails DetailsAt(int entry) {
3502  DCHECK(entry >= 0); // Not found is -1, which is not caught by get().
3503  return PropertyDetails(
3504  Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2)));
3505  }
3506 
3507  // Set the details for entry.
3508  void DetailsAtPut(int entry, PropertyDetails value) {
3509  this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi());
3510  }
3511 
3512  // Sorting support
3513  void CopyValuesTo(FixedArray* elements);
3514 
3515  // Delete a property from the dictionary.
3516  static Handle<Object> DeleteProperty(
3517  Handle<Derived> dictionary,
3518  int entry,
3520 
3521  // Attempt to shrink the dictionary after deletion of key.
3523  Handle<Derived> dictionary,
3524  Key key) {
3525  return DerivedHashTable::Shrink(dictionary, key);
3526  }
3527 
3528  // Returns the number of elements in the dictionary filtering out properties
3529  // with the specified attributes.
3530  int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3531 
3532  // Returns the number of enumerable elements in the dictionary.
3533  int NumberOfEnumElements();
3534 
3535  enum SortMode { UNSORTED, SORTED };
3536  // Copies keys to preallocated fixed array.
3537  void CopyKeysTo(FixedArray* storage,
3538  PropertyAttributes filter,
3539  SortMode sort_mode);
3540  // Fill in details for properties into storage.
3541  void CopyKeysTo(FixedArray* storage,
3542  int index,
3543  PropertyAttributes filter,
3544  SortMode sort_mode);
3545 
3546  // Accessors for next enumeration index.
3547  void SetNextEnumerationIndex(int index) {
3548  DCHECK(index != 0);
3549  this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
3550  }
3551 
3553  return Smi::cast(this->get(kNextEnumerationIndexIndex))->value();
3554  }
3555 
3556  // Creates a new dictionary.
3557  MUST_USE_RESULT static Handle<Derived> New(
3558  Isolate* isolate,
3559  int at_least_space_for,
3560  PretenureFlag pretenure = NOT_TENURED);
3561 
3562  // Ensure enough space for n additional elements.
3563  static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key);
3564 
3565 #ifdef OBJECT_PRINT
3566  void Print(OStream& os); // NOLINT
3567 #endif
3568  // Returns the key (slow).
3569  Object* SlowReverseLookup(Object* value);
3570 
3571  // Sets the entry to (key, value) pair.
3572  inline void SetEntry(int entry,
3573  Handle<Object> key,
3575  inline void SetEntry(int entry,
3576  Handle<Object> key,
3578  PropertyDetails details);
3579 
3580  MUST_USE_RESULT static Handle<Derived> Add(
3581  Handle<Derived> dictionary,
3582  Key key,
3584  PropertyDetails details);
3585 
3586  protected:
3587  // Generic at put operation.
3588  MUST_USE_RESULT static Handle<Derived> AtPut(
3589  Handle<Derived> dictionary,
3590  Key key,
3592 
3593  // Add entry to dictionary.
3594  static void AddEntry(
3595  Handle<Derived> dictionary,
3596  Key key,
3598  PropertyDetails details,
3599  uint32_t hash);
3600 
3601  // Generate new enumeration indices to avoid enumeration index overflow.
3602  static void GenerateNewEnumerationIndices(Handle<Derived> dictionary);
3603  static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
3604  static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3605 };
3606 
3607 
3608 class NameDictionaryShape : public BaseShape<Handle<Name> > {
3609  public:
3610  static inline bool IsMatch(Handle<Name> key, Object* other);
3611  static inline uint32_t Hash(Handle<Name> key);
3612  static inline uint32_t HashForObject(Handle<Name> key, Object* object);
3613  static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
3614  static const int kPrefixSize = 2;
3615  static const int kEntrySize = 3;
3616  static const bool kIsEnumerable = true;
3617 };
3618 
3619 
3620 class NameDictionary: public Dictionary<NameDictionary,
3621  NameDictionaryShape,
3622  Handle<Name> > {
3623  typedef Dictionary<
3625 
3626  public:
3628 
3629  // Copies enumerable keys to preallocated fixed array.
3630  void CopyEnumKeysTo(FixedArray* storage);
3631  inline static void DoGenerateNewEnumerationIndices(
3632  Handle<NameDictionary> dictionary);
3633 
3634  // Find entry for key, otherwise return kNotFound. Optimized version of
3635  // HashTable::FindEntry.
3636  int FindEntry(Handle<Name> key);
3637 };
3638 
3639 
3640 class NumberDictionaryShape : public BaseShape<uint32_t> {
3641  public:
3642  static inline bool IsMatch(uint32_t key, Object* other);
3643  static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key);
3644  static const int kEntrySize = 3;
3645  static const bool kIsEnumerable = false;
3646 };
3647 
3648 
3650  public:
3651  static const bool UsesSeed = true;
3652  static const int kPrefixSize = 2;
3653 
3654  static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3655  static inline uint32_t SeededHashForObject(uint32_t key,
3656  uint32_t seed,
3657  Object* object);
3658 };
3659 
3660 
3662  public:
3663  static const int kPrefixSize = 0;
3664 
3665  static inline uint32_t Hash(uint32_t key);
3666  static inline uint32_t HashForObject(uint32_t key, Object* object);
3667 };
3668 
3669 
3671  : public Dictionary<SeededNumberDictionary,
3672  SeededNumberDictionaryShape,
3673  uint32_t> {
3674  public:
3676 
3677  // Type specific at put (default NONE attributes is used when adding).
3679  Handle<SeededNumberDictionary> dictionary,
3680  uint32_t key,
3682  MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry(
3683  Handle<SeededNumberDictionary> dictionary,
3684  uint32_t key,
3686  PropertyDetails details);
3687 
3688  // Set an existing entry or add a new one if needed.
3689  // Return the updated dictionary.
3691  Handle<SeededNumberDictionary> dictionary,
3692  uint32_t key,
3694  PropertyDetails details);
3695 
3696  void UpdateMaxNumberKey(uint32_t key);
3697 
3698  // If slow elements are required we will never go back to fast-case
3699  // for the elements kept in this dictionary. We require slow
3700  // elements if an element has been added at an index larger than
3701  // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3702  // when defining a getter or setter with a number key.
3703  inline bool requires_slow_elements();
3704  inline void set_requires_slow_elements();
3705 
3706  // Get the value of the max number key that has been added to this
3707  // dictionary. max_number_key can only be called if
3708  // requires_slow_elements returns false.
3709  inline uint32_t max_number_key();
3710 
3711  // Bit masks.
3712  static const int kRequiresSlowElementsMask = 1;
3713  static const int kRequiresSlowElementsTagSize = 1;
3714  static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
3715 };
3716 
3717 
3719  : public Dictionary<UnseededNumberDictionary,
3720  UnseededNumberDictionaryShape,
3721  uint32_t> {
3722  public:
3724 
3725  // Type specific at put (default NONE attributes is used when adding).
3728  uint32_t key,
3730  MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry(
3732  uint32_t key,
3734 
3735  // Set an existing entry or add a new one if needed.
3736  // Return the updated dictionary.
3739  uint32_t key,
3741 };
3742 
3743 
3744 class ObjectHashTableShape : public BaseShape<Handle<Object> > {
3745  public:
3746  static inline bool IsMatch(Handle<Object> key, Object* other);
3747  static inline uint32_t Hash(Handle<Object> key);
3748  static inline uint32_t HashForObject(Handle<Object> key, Object* object);
3749  static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
3750  static const int kPrefixSize = 0;
3751  static const int kEntrySize = 2;
3752 };
3753 
3754 
3755 // ObjectHashTable maps keys that are arbitrary objects to object values by
3756 // using the identity hash of the key for hashing purposes.
3757 class ObjectHashTable: public HashTable<ObjectHashTable,
3758  ObjectHashTableShape,
3759  Handle<Object> > {
3760  typedef HashTable<
3762  public:
3764 
3765  // Attempt to shrink hash table after removal of key.
3766  MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink(
3768  Handle<Object> key);
3769 
3770  // Looks up the value associated with the given key. The hole value is
3771  // returned in case the key is not present.
3772  Object* Lookup(Handle<Object> key);
3773 
3774  // Adds (or overwrites) the value associated with the given key.
3776  Handle<Object> key,
3778 
3779  // Returns an ObjectHashTable (possibly |table|) where |key| has been removed.
3781  Handle<Object> key,
3782  bool* was_present);
3783 
3784  private:
3785  friend class MarkCompactCollector;
3786 
3787  void AddEntry(int entry, Object* key, Object* value);
3788  void RemoveEntry(int entry);
3789 
3790  // Returns the index to the value of an entry.
3791  static inline int EntryToValueIndex(int entry) {
3792  return EntryToIndex(entry) + 1;
3793  }
3794 };
3795 
3796 
3797 // OrderedHashTable is a HashTable with Object keys that preserves
3798 // insertion order. There are Map and Set interfaces (OrderedHashMap
3799 // and OrderedHashTable, below). It is meant to be used by JSMap/JSSet.
3800 //
3801 // Only Object* keys are supported, with Object::SameValueZero() used as the
3802 // equality operator and Object::GetHash() for the hash function.
3803 //
3804 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at
3805 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables
3806 // Originally attributed to Tyler Close.
3807 //
3808 // Memory layout:
3809 // [0]: bucket count
3810 // [1]: element count
3811 // [2]: deleted element count
3812 // [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an
3813 // offset into the data table (see below) where the
3814 // first item in this bucket is stored.
3815 // [3 + NumberOfBuckets()..length]: "data table", an array of length
3816 // Capacity() * kEntrySize, where the first entrysize
3817 // items are handled by the derived class and the
3818 // item at kChainOffset is another entry into the
3819 // data table indicating the next entry in this hash
3820 // bucket.
3821 //
3822 // When we transition the table to a new version we obsolete it and reuse parts
3823 // of the memory to store information how to transition an iterator to the new
3824 // table:
3825 //
3826 // Memory layout for obsolete table:
3827 // [0]: bucket count
3828 // [1]: Next newer table
3829 // [2]: Number of removed holes or -1 when the table was cleared.
3830 // [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes.
3831 // [3 + NumberOfRemovedHoles()..length]: Not used
3832 //
3833 template<class Derived, class Iterator, int entrysize>
3835  public:
3836  // Returns an OrderedHashTable with a capacity of at least |capacity|.
3837  static Handle<Derived> Allocate(
3838  Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED);
3839 
3840  // Returns an OrderedHashTable (possibly |table|) with enough space
3841  // to add at least one new element.
3842  static Handle<Derived> EnsureGrowable(Handle<Derived> table);
3843 
3844  // Returns an OrderedHashTable (possibly |table|) that's shrunken
3845  // if possible.
3846  static Handle<Derived> Shrink(Handle<Derived> table);
3847 
3848  // Returns a new empty OrderedHashTable and records the clearing so that
3849  // exisiting iterators can be updated.
3850  static Handle<Derived> Clear(Handle<Derived> table);
3851 
3852  // Returns an OrderedHashTable (possibly |table|) where |key| has been
3853  // removed.
3854  static Handle<Derived> Remove(Handle<Derived> table, Handle<Object> key,
3855  bool* was_present);
3856 
3857  // Returns kNotFound if the key isn't present.
3858  int FindEntry(Handle<Object> key, int hash);
3859 
3860  // Like the above, but doesn't require the caller to provide a hash.
3861  int FindEntry(Handle<Object> key);
3862 
3864  return Smi::cast(get(kNumberOfElementsIndex))->value();
3865  }
3866 
3868  return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
3869  }
3870 
3871  int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); }
3872 
3874  return Smi::cast(get(kNumberOfBucketsIndex))->value();
3875  }
3876 
3877  // Returns the index into the data table where the new entry
3878  // should be placed. The table is assumed to have enough space
3879  // for a new entry.
3880  int AddEntry(int hash);
3881 
3882  // Removes the entry, and puts the_hole in entrysize pointers
3883  // (leaving the hash table chain intact).
3884  void RemoveEntry(int entry);
3885 
3886  // Returns an index into |this| for the given entry.
3887  int EntryToIndex(int entry) {
3888  return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize);
3889  }
3890 
3891  Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3892 
3893  bool IsObsolete() {
3894  return !get(kNextTableIndex)->IsSmi();
3895  }
3896 
3897  // The next newer table. This is only valid if the table is obsolete.
3898  Derived* NextTable() {
3899  return Derived::cast(get(kNextTableIndex));
3900  }
3901 
3902  // When the table is obsolete we store the indexes of the removed holes.
3903  int RemovedIndexAt(int index) {
3904  return Smi::cast(get(kRemovedHolesIndex + index))->value();
3905  }
3906 
3907  static const int kNotFound = -1;
3908  static const int kMinCapacity = 4;
3909 
3910  private:
3911  static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity);
3912 
3913  void SetNumberOfBuckets(int num) {
3914  set(kNumberOfBucketsIndex, Smi::FromInt(num));
3915  }
3916 
3917  void SetNumberOfElements(int num) {
3918  set(kNumberOfElementsIndex, Smi::FromInt(num));
3919  }
3920 
3922  set(kNumberOfDeletedElementsIndex, Smi::FromInt(num));
3923  }
3924 
3925  int Capacity() {
3926  return NumberOfBuckets() * kLoadFactor;
3927  }
3928 
3929  // Returns the next entry for the given entry.
3930  int ChainAt(int entry) {
3931  return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value();
3932  }
3933 
3934  int HashToBucket(int hash) {
3935  return hash & (NumberOfBuckets() - 1);
3936  }
3937 
3938  int HashToEntry(int hash) {
3939  int bucket = HashToBucket(hash);
3940  return Smi::cast(get(kHashTableStartIndex + bucket))->value();
3941  }
3942 
3943  void SetNextTable(Derived* next_table) {
3944  set(kNextTableIndex, next_table);
3945  }
3946 
3947  void SetRemovedIndexAt(int index, int removed_index) {
3948  return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index));
3949  }
3950 
3951  static const int kNumberOfBucketsIndex = 0;
3952  static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1;
3953  static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
3954  static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1;
3955 
3956  static const int kNextTableIndex = kNumberOfElementsIndex;
3957  static const int kRemovedHolesIndex = kHashTableStartIndex;
3958 
3959  static const int kEntrySize = entrysize + 1;
3960  static const int kChainOffset = entrysize;
3961 
3962  static const int kLoadFactor = 2;
3963  static const int kMaxCapacity =
3964  (FixedArray::kMaxLength - kHashTableStartIndex)
3965  / (1 + (kEntrySize * kLoadFactor));
3966 };
3967 
3968 
3969 class JSSetIterator;
3970 
3971 
3973  OrderedHashSet, JSSetIterator, 1> {
3974  public:
3976 
3977  bool Contains(Handle<Object> key);
3978  static Handle<OrderedHashSet> Add(
3980 };
3981 
3982 
3983 class JSMapIterator;
3984 
3985 
3987  OrderedHashMap, JSMapIterator, 2> {
3988  public:
3990 
3991  Object* Lookup(Handle<Object> key);
3992  static Handle<OrderedHashMap> Put(
3993  Handle<OrderedHashMap> table,
3994  Handle<Object> key,
3996 
3997  Object* ValueAt(int entry) {
3998  return get(EntryToIndex(entry) + kValueOffset);
3999  }
4000 
4001  private:
4002  static const int kValueOffset = 1;
4003 };
4004 
4005 
4006 template <int entrysize>
4007 class WeakHashTableShape : public BaseShape<Handle<Object> > {
4008  public:
4009  static inline bool IsMatch(Handle<Object> key, Object* other);
4010  static inline uint32_t Hash(Handle<Object> key);
4011  static inline uint32_t HashForObject(Handle<Object> key, Object* object);
4012  static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
4013  static const int kPrefixSize = 0;
4014  static const int kEntrySize = entrysize;
4015 };
4016 
4017 
4018 // WeakHashTable maps keys that are arbitrary objects to object values.
4019 // It is used for the global weak hash table that maps objects
4020 // embedded in optimized code to dependent code lists.
4021 class WeakHashTable: public HashTable<WeakHashTable,
4022  WeakHashTableShape<2>,
4023  Handle<Object> > {
4024  typedef HashTable<
4026  public:
4028 
4029  // Looks up the value associated with the given key. The hole value is
4030  // returned in case the key is not present.
4031  Object* Lookup(Handle<Object> key);
4032 
4033  // Adds (or overwrites) the value associated with the given key. Mapping a
4034  // key to the hole value causes removal of the whole entry.
4036  Handle<Object> key,
4038 
4039  // This function is called when heap verification is turned on.
4040  void Zap(Object* value) {
4041  int capacity = Capacity();
4042  for (int i = 0; i < capacity; i++) {
4043  set(EntryToIndex(i), value);
4044  set(EntryToValueIndex(i), value);
4045  }
4046  }
4047 
4048  private:
4049  friend class MarkCompactCollector;
4050 
4051  void AddEntry(int entry, Handle<Object> key, Handle<Object> value);
4052 
4053  // Returns the index to the value of an entry.
4054  static inline int EntryToValueIndex(int entry) {
4055  return EntryToIndex(entry) + 1;
4056  }
4057 };
4058 
4059 
4060 // JSFunctionResultCache caches results of some JSFunction invocation.
4061 // It is a fixed array with fixed structure:
4062 // [0]: factory function
4063 // [1]: finger index
4064 // [2]: current cache size
4065 // [3]: dummy field.
4066 // The rest of array are key/value pairs.
4068  public:
4069  static const int kFactoryIndex = 0;
4070  static const int kFingerIndex = kFactoryIndex + 1;
4071  static const int kCacheSizeIndex = kFingerIndex + 1;
4072  static const int kDummyIndex = kCacheSizeIndex + 1;
4073  static const int kEntriesIndex = kDummyIndex + 1;
4074 
4075  static const int kEntrySize = 2; // key + value
4076 
4077  static const int kFactoryOffset = kHeaderSize;
4078  static const int kFingerOffset = kFactoryOffset + kPointerSize;
4079  static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
4080 
4081  inline void MakeZeroSize();
4082  inline void Clear();
4083 
4084  inline int size();
4085  inline void set_size(int size);
4086  inline int finger_index();
4087  inline void set_finger_index(int finger_index);
4088 
4090 
4092 };
4093 
4094 
4095 // ScopeInfo represents information about different scopes of a source
4096 // program and the allocation of the scope's variables. Scope information
4097 // is stored in a compressed form in ScopeInfo objects and is used
4098 // at runtime (stack dumps, deoptimization, etc.).
4099 
4100 // This object provides quick access to scope info details for runtime
4101 // routines.
4102 class ScopeInfo : public FixedArray {
4103  public:
4105 
4106  // Return the type of this scope.
4107  ScopeType scope_type();
4108 
4109  // Does this scope call eval?
4110  bool CallsEval();
4111 
4112  // Return the strict mode of this scope.
4113  StrictMode strict_mode();
4114 
4115  // Does this scope make a sloppy eval call?
4116  bool CallsSloppyEval() { return CallsEval() && strict_mode() == SLOPPY; }
4117 
4118  // Return the total number of locals allocated on the stack and in the
4119  // context. This includes the parameters that are allocated in the context.
4120  int LocalCount();
4121 
4122  // Return the number of stack slots for code. This number consists of two
4123  // parts:
4124  // 1. One stack slot per stack allocated local.
4125  // 2. One stack slot for the function name if it is stack allocated.
4126  int StackSlotCount();
4127 
4128  // Return the number of context slots for code if a context is allocated. This
4129  // number consists of three parts:
4130  // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
4131  // 2. One context slot per context allocated local.
4132  // 3. One context slot for the function name if it is context allocated.
4133  // Parameters allocated in the context count as context allocated locals. If
4134  // no contexts are allocated for this scope ContextLength returns 0.
4135  int ContextLength();
4136 
4137  // Is this scope the scope of a named function expression?
4138  bool HasFunctionName();
4139 
4140  // Return if this has context allocated locals.
4141  bool HasHeapAllocatedLocals();
4142 
4143  // Return if contexts are allocated for this scope.
4144  bool HasContext();
4145 
4146  // Return if this is a function scope with "use asm".
4147  bool IsAsmModule() { return AsmModuleField::decode(Flags()); }
4148 
4149  // Return if this is a nested function within an asm module scope.
4150  bool IsAsmFunction() { return AsmFunctionField::decode(Flags()); }
4151 
4152  // Return the function_name if present.
4153  String* FunctionName();
4154 
4155  // Return the name of the given parameter.
4156  String* ParameterName(int var);
4157 
4158  // Return the name of the given local.
4159  String* LocalName(int var);
4160 
4161  // Return the name of the given stack local.
4162  String* StackLocalName(int var);
4163 
4164  // Return the name of the given context local.
4165  String* ContextLocalName(int var);
4166 
4167  // Return the mode of the given context local.
4168  VariableMode ContextLocalMode(int var);
4169 
4170  // Return the initialization flag of the given context local.
4171  InitializationFlag ContextLocalInitFlag(int var);
4172 
4173  // Return the initialization flag of the given context local.
4174  MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var);
4175 
4176  // Return true if this local was introduced by the compiler, and should not be
4177  // exposed to the user in a debugger.
4178  bool LocalIsSynthetic(int var);
4179 
4180  // Lookup support for serialized scope info. Returns the
4181  // the stack slot index for a given slot name if the slot is
4182  // present; otherwise returns a value < 0. The name must be an internalized
4183  // string.
4184  int StackSlotIndex(String* name);
4185 
4186  // Lookup support for serialized scope info. Returns the
4187  // context slot index for a given slot name if the slot is present; otherwise
4188  // returns a value < 0. The name must be an internalized string.
4189  // If the slot is present and mode != NULL, sets *mode to the corresponding
4190  // mode for that variable.
4191  static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name,
4192  VariableMode* mode, InitializationFlag* init_flag,
4193  MaybeAssignedFlag* maybe_assigned_flag);
4194 
4195  // Lookup support for serialized scope info. Returns the
4196  // parameter index for a given parameter name if the parameter is present;
4197  // otherwise returns a value < 0. The name must be an internalized string.
4198  int ParameterIndex(String* name);
4199 
4200  // Lookup support for serialized scope info. Returns the function context
4201  // slot index if the function name is present and context-allocated (named
4202  // function expressions, only), otherwise returns a value < 0. The name
4203  // must be an internalized string.
4204  int FunctionContextSlotIndex(String* name, VariableMode* mode);
4205 
4206 
4207  // Copies all the context locals into an object used to materialize a scope.
4208  static bool CopyContextLocalsToScopeObject(Handle<ScopeInfo> scope_info,
4209  Handle<Context> context,
4210  Handle<JSObject> scope_object);
4211 
4212 
4213  static Handle<ScopeInfo> Create(Scope* scope, Zone* zone);
4214 
4215  // Serializes empty scope info.
4216  static ScopeInfo* Empty(Isolate* isolate);
4217 
4218 #ifdef DEBUG
4219  void Print();
4220 #endif
4221 
4222  // The layout of the static part of a ScopeInfo is as follows. Each entry is
4223  // numeric and occupies one array slot.
4224  // 1. A set of properties of the scope
4225  // 2. The number of parameters. This only applies to function scopes. For
4226  // non-function scopes this is 0.
4227  // 3. The number of non-parameter variables allocated on the stack.
4228  // 4. The number of non-parameter and parameter variables allocated in the
4229  // context.
4230 #define FOR_EACH_NUMERIC_FIELD(V) \
4231  V(Flags) \
4232  V(ParameterCount) \
4233  V(StackLocalCount) \
4234  V(ContextLocalCount)
4235 
4236 #define FIELD_ACCESSORS(name) \
4237  void Set##name(int value) { \
4238  set(k##name, Smi::FromInt(value)); \
4239  } \
4240  int name() { \
4241  if (length() > 0) { \
4242  return Smi::cast(get(k##name))->value(); \
4243  } else { \
4244  return 0; \
4245  } \
4246  }
4248 #undef FIELD_ACCESSORS
4249 
4250  private:
4251  enum {
4252 #define DECL_INDEX(name) k##name,
4254 #undef DECL_INDEX
4255 #undef FOR_EACH_NUMERIC_FIELD
4256  kVariablePartIndex
4257  };
4258 
4259  // The layout of the variable part of a ScopeInfo is as follows:
4260  // 1. ParameterEntries:
4261  // This part stores the names of the parameters for function scopes. One
4262  // slot is used per parameter, so in total this part occupies
4263  // ParameterCount() slots in the array. For other scopes than function
4264  // scopes ParameterCount() is 0.
4265  // 2. StackLocalEntries:
4266  // Contains the names of local variables that are allocated on the stack,
4267  // in increasing order of the stack slot index. One slot is used per stack
4268  // local, so in total this part occupies StackLocalCount() slots in the
4269  // array.
4270  // 3. ContextLocalNameEntries:
4271  // Contains the names of local variables and parameters that are allocated
4272  // in the context. They are stored in increasing order of the context slot
4273  // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
4274  // context local, so in total this part occupies ContextLocalCount() slots
4275  // in the array.
4276  // 4. ContextLocalInfoEntries:
4277  // Contains the variable modes and initialization flags corresponding to
4278  // the context locals in ContextLocalNameEntries. One slot is used per
4279  // context local, so in total this part occupies ContextLocalCount()
4280  // slots in the array.
4281  // 5. FunctionNameEntryIndex:
4282  // If the scope belongs to a named function expression this part contains
4283  // information about the function variable. It always occupies two array
4284  // slots: a. The name of the function variable.
4285  // b. The context or stack slot index for the variable.
4286  int ParameterEntriesIndex();
4287  int StackLocalEntriesIndex();
4288  int ContextLocalNameEntriesIndex();
4289  int ContextLocalInfoEntriesIndex();
4290  int FunctionNameEntryIndex();
4291 
4292  // Location of the function variable for named function expressions.
4294  NONE, // No function name present.
4295  STACK, // Function
4297  UNUSED
4298  };
4299 
4300  // Properties of scopes.
4301  class ScopeTypeField: public BitField<ScopeType, 0, 3> {};
4302  class CallsEvalField: public BitField<bool, 3, 1> {};
4303  class StrictModeField: public BitField<StrictMode, 4, 1> {};
4304  class FunctionVariableField: public BitField<FunctionVariableInfo, 5, 2> {};
4305  class FunctionVariableMode: public BitField<VariableMode, 7, 3> {};
4306  class AsmModuleField : public BitField<bool, 10, 1> {};
4307  class AsmFunctionField : public BitField<bool, 11, 1> {};
4308 
4309  // BitFields representing the encoded information for context locals in the
4310  // ContextLocalInfoEntries part.
4311  class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
4312  class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
4314  : public BitField<MaybeAssignedFlag, 4, 1> {};
4315 };
4316 
4317 
4318 // The cache for maps used by normalized (dictionary mode) objects.
4319 // Such maps do not have property descriptors, so a typical program
4320 // needs very limited number of distinct normalized maps.
4322  public:
4323  static Handle<NormalizedMapCache> New(Isolate* isolate);
4324 
4327  void Set(Handle<Map> fast_map, Handle<Map> normalized_map);
4328 
4329  void Clear();
4330 
4332 
4333  static inline bool IsNormalizedMapCache(const Object* obj);
4334 
4336  private:
4337  static const int kEntries = 64;
4338 
4339  static inline int GetIndex(Handle<Map> map);
4340 
4341  // The following declarations hide base class methods.
4342  Object* get(int index);
4343  void set(int index, Object* value);
4344 };
4345 
4346 
4347 // ByteArray represents fixed sized byte arrays. Used for the relocation info
4348 // that is attached to code objects.
4349 class ByteArray: public FixedArrayBase {
4350  public:
4351  inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
4352 
4353  // Setter and getter.
4354  inline byte get(int index);
4355  inline void set(int index, byte value);
4356 
4357  // Treat contents as an int array.
4358  inline int get_int(int index);
4359 
4360  static int SizeFor(int length) {
4361  return OBJECT_POINTER_ALIGN(kHeaderSize + length);
4362  }
4363  // We use byte arrays for free blocks in the heap. Given a desired size in
4364  // bytes that is a multiple of the word size and big enough to hold a byte
4365  // array, this function returns the number of elements a byte array should
4366  // have.
4367  static int LengthFor(int size_in_bytes) {
4368  DCHECK(IsAligned(size_in_bytes, kPointerSize));
4369  DCHECK(size_in_bytes >= kHeaderSize);
4370  return size_in_bytes - kHeaderSize;
4371  }
4372 
4373  // Returns data start address.
4374  inline Address GetDataStartAddress();
4375 
4376  // Returns a pointer to the ByteArray object for a given data start address.
4377  static inline ByteArray* FromDataStartAddress(Address address);
4378 
4380 
4381  // Dispatched behavior.
4382  inline int ByteArraySize() {
4383  return SizeFor(this->length());
4384  }
4387 
4388  // Layout description.
4389  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4390 
4391  // Maximal memory consumption for a single ByteArray.
4392  static const int kMaxSize = 512 * MB;
4393  // Maximal length of a single ByteArray.
4394  static const int kMaxLength = kMaxSize - kHeaderSize;
4395 
4396  private:
4398 };
4399 
4400 
4401 // FreeSpace represents fixed sized areas of the heap that are not currently in
4402 // use. Used by the heap and GC.
4403 class FreeSpace: public HeapObject {
4404  public:
4405  // [size]: size of the free space including the header.
4406  inline int size() const;
4407  inline void set_size(int value);
4408 
4409  inline int nobarrier_size() const;
4410  inline void nobarrier_set_size(int value);
4411 
4412  inline int Size() { return size(); }
4413 
4415 
4416  // Dispatched behavior.
4419 
4420  // Layout description.
4421  // Size is smi tagged when it is stored.
4422  static const int kSizeOffset = HeapObject::kHeaderSize;
4423  static const int kHeaderSize = kSizeOffset + kPointerSize;
4424 
4425  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4426 
4427  private:
4429 };
4430 
4431 
4432 // V has parameters (Type, type, TYPE, C type, element_size)
4433 #define TYPED_ARRAYS(V) \
4434  V(Uint8, uint8, UINT8, uint8_t, 1) \
4435  V(Int8, int8, INT8, int8_t, 1) \
4436  V(Uint16, uint16, UINT16, uint16_t, 2) \
4437  V(Int16, int16, INT16, int16_t, 2) \
4438  V(Uint32, uint32, UINT32, uint32_t, 4) \
4439  V(Int32, int32, INT32, int32_t, 4) \
4440  V(Float32, float32, FLOAT32, float, 4) \
4441  V(Float64, float64, FLOAT64, double, 8) \
4442  V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1)
4443 
4444 
4445 
4446 // An ExternalArray represents a fixed-size array of primitive values
4447 // which live outside the JavaScript heap. Its subclasses are used to
4448 // implement the CanvasArray types being defined in the WebGL
4449 // specification. As of this writing the first public draft is not yet
4450 // available, but Khronos members can access the draft at:
4451 // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
4452 //
4453 // The semantics of these arrays differ from CanvasPixelArray.
4454 // Out-of-range values passed to the setter are converted via a C
4455 // cast, not clamping. Out-of-range indices cause exceptions to be
4456 // raised rather than being silently ignored.
4458  public:
4459  inline bool is_the_hole(int index) { return false; }
4460 
4461  // [external_pointer]: The pointer to the external memory area backing this
4462  // external array.
4463  DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
4464 
4466 
4467  // Maximal acceptable length for an external array.
4468  static const int kMaxLength = 0x3fffffff;
4469 
4470  // ExternalArray headers are not quadword aligned.
4471  static const int kExternalPointerOffset =
4473  static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
4474  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4475 
4476  private:
4478 };
4479 
4480 
4481 // A ExternalUint8ClampedArray represents a fixed-size byte array with special
4482 // semantics used for implementing the CanvasPixelArray object. Please see the
4483 // specification at:
4484 
4485 // http://www.whatwg.org/specs/web-apps/current-work/
4486 // multipage/the-canvas-element.html#canvaspixelarray
4487 // In particular, write access clamps the value written to 0 or 255 if the
4488 // value written is outside this range.
4490  public:
4491  inline uint8_t* external_uint8_clamped_pointer();
4492 
4493  // Setter and getter.
4494  inline uint8_t get_scalar(int index);
4495  static inline Handle<Object> get(Handle<ExternalUint8ClampedArray> array,
4496  int index);
4497  inline void set(int index, uint8_t value);
4498 
4499  // This accessor applies the correct conversion from Smi, HeapNumber
4500  // and undefined and clamps the converted value between 0 and 255.
4501  static Handle<Object> SetValue(Handle<ExternalUint8ClampedArray> array,
4502  uint32_t index,
4504 
4506 
4507  // Dispatched behavior.
4510 
4511  private:
4513 };
4514 
4515 
4517  public:
4518  // Setter and getter.
4519  inline int8_t get_scalar(int index);
4520  static inline Handle<Object> get(Handle<ExternalInt8Array> array, int index);
4521  inline void set(int index, int8_t value);
4522 
4523  // This accessor applies the correct conversion from Smi, HeapNumber
4524  // and undefined.
4525  static Handle<Object> SetValue(Handle<ExternalInt8Array> array,
4526  uint32_t index,
4528 
4530 
4531  // Dispatched behavior.
4534 
4535  private:
4537 };
4538 
4539 
4541  public:
4542  // Setter and getter.
4543  inline uint8_t get_scalar(int index);
4544  static inline Handle<Object> get(Handle<ExternalUint8Array> array, int index);
4545  inline void set(int index, uint8_t value);
4546 
4547  // This accessor applies the correct conversion from Smi, HeapNumber
4548  // and undefined.
4549  static Handle<Object> SetValue(Handle<ExternalUint8Array> array,
4550  uint32_t index,
4552 
4554 
4555  // Dispatched behavior.
4558 
4559  private:
4561 };
4562 
4563 
4565  public:
4566  // Setter and getter.
4567  inline int16_t get_scalar(int index);
4568  static inline Handle<Object> get(Handle<ExternalInt16Array> array, int index);
4569  inline void set(int index, int16_t value);
4570 
4571  // This accessor applies the correct conversion from Smi, HeapNumber
4572  // and undefined.
4573  static Handle<Object> SetValue(Handle<ExternalInt16Array> array,
4574  uint32_t index,
4576 
4578 
4579  // Dispatched behavior.
4582 
4583  private:
4585 };
4586 
4587 
4589  public:
4590  // Setter and getter.
4591  inline uint16_t get_scalar(int index);
4592  static inline Handle<Object> get(Handle<ExternalUint16Array> array,
4593  int index);
4594  inline void set(int index, uint16_t value);
4595 
4596  // This accessor applies the correct conversion from Smi, HeapNumber
4597  // and undefined.
4598  static Handle<Object> SetValue(Handle<ExternalUint16Array> array,
4599  uint32_t index,
4601 
4603 
4604  // Dispatched behavior.
4607 
4608  private:
4610 };
4611 
4612 
4614  public:
4615  // Setter and getter.
4616  inline int32_t get_scalar(int index);
4617  static inline Handle<Object> get(Handle<ExternalInt32Array> array, int index);
4618  inline void set(int index, int32_t value);
4619 
4620  // This accessor applies the correct conversion from Smi, HeapNumber
4621  // and undefined.
4622  static Handle<Object> SetValue(Handle<ExternalInt32Array> array,
4623  uint32_t index,
4625 
4627 
4628  // Dispatched behavior.
4631 
4632  private:
4634 };
4635 
4636 
4638  public:
4639  // Setter and getter.
4640  inline uint32_t get_scalar(int index);
4641  static inline Handle<Object> get(Handle<ExternalUint32Array> array,
4642  int index);
4643  inline void set(int index, uint32_t value);
4644 
4645  // This accessor applies the correct conversion from Smi, HeapNumber
4646  // and undefined.
4647  static Handle<Object> SetValue(Handle<ExternalUint32Array> array,
4648  uint32_t index,
4650 
4652 
4653  // Dispatched behavior.
4656 
4657  private:
4659 };
4660 
4661 
4663  public:
4664  // Setter and getter.
4665  inline float get_scalar(int index);
4666  static inline Handle<Object> get(Handle<ExternalFloat32Array> array,
4667  int index);
4668  inline void set(int index, float value);
4669 
4670  // This accessor applies the correct conversion from Smi, HeapNumber
4671  // and undefined.
4672  static Handle<Object> SetValue(Handle<ExternalFloat32Array> array,
4673  uint32_t index,
4675 
4677 
4678  // Dispatched behavior.
4681 
4682  private:
4684 };
4685 
4686 
4688  public:
4689  // Setter and getter.
4690  inline double get_scalar(int index);
4691  static inline Handle<Object> get(Handle<ExternalFloat64Array> array,
4692  int index);
4693  inline void set(int index, double value);
4694 
4695  // This accessor applies the correct conversion from Smi, HeapNumber
4696  // and undefined.
4697  static Handle<Object> SetValue(Handle<ExternalFloat64Array> array,
4698  uint32_t index,
4700 
4702 
4703  // Dispatched behavior.
4706 
4707  private:
4709 };
4710 
4711 
4713  public:
4715 
4716  static const int kDataOffset = kHeaderSize;
4717 
4718  inline int size();
4719 
4720  inline int TypedArraySize(InstanceType type);
4721 
4722  // Use with care: returns raw pointer into heap.
4723  inline void* DataPtr();
4724 
4725  inline int DataSize();
4726 
4727  private:
4728  inline int DataSize(InstanceType type);
4729 
4731 };
4732 
4733 
4734 template <class Traits>
4736  public:
4737  typedef typename Traits::ElementType ElementType;
4738  static const InstanceType kInstanceType = Traits::kInstanceType;
4739 
4741 
4742  static inline int ElementOffset(int index) {
4743  return kDataOffset + index * sizeof(ElementType);
4744  }
4745 
4746  static inline int SizeFor(int length) {
4747  return ElementOffset(length);
4748  }
4749 
4750  inline ElementType get_scalar(int index);
4751  static inline Handle<Object> get(Handle<FixedTypedArray> array, int index);
4752  inline void set(int index, ElementType value);
4753 
4754  static inline ElementType from_int(int value);
4755  static inline ElementType from_double(double value);
4756 
4757  // This accessor applies the correct conversion from Smi, HeapNumber
4758  // and undefined.
4759  static Handle<Object> SetValue(Handle<FixedTypedArray<Traits> > array,
4760  uint32_t index,
4762 
4765 
4766  private:
4768 };
4769 
4770 #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \
4771  class Type##ArrayTraits { \
4772  public: /* NOLINT */ \
4773  typedef elementType ElementType; \
4774  static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \
4775  static const char* Designator() { return #type " array"; } \
4776  static inline Handle<Object> ToHandle(Isolate* isolate, \
4777  elementType scalar); \
4778  static inline elementType defaultValue(); \
4779  }; \
4780  \
4781  typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array;
4782 
4784 
4785 #undef FIXED_TYPED_ARRAY_TRAITS
4786 
4787 // DeoptimizationInputData is a fixed array used to hold the deoptimization
4788 // data for code generated by the Hydrogen/Lithium compiler. It also
4789 // contains information about functions that were inlined. If N different
4790 // functions were inlined then first N elements of the literal array will
4791 // contain these functions.
4792 //
4793 // It can be empty.
4795  public:
4796  // Layout description. Indices in the array.
4797  static const int kTranslationByteArrayIndex = 0;
4798  static const int kInlinedFunctionCountIndex = 1;
4799  static const int kLiteralArrayIndex = 2;
4800  static const int kOsrAstIdIndex = 3;
4801  static const int kOsrPcOffsetIndex = 4;
4802  static const int kOptimizationIdIndex = 5;
4803  static const int kSharedFunctionInfoIndex = 6;
4804  static const int kFirstDeoptEntryIndex = 7;
4805 
4806  // Offsets of deopt entry elements relative to the start of the entry.
4807  static const int kAstIdRawOffset = 0;
4808  static const int kTranslationIndexOffset = 1;
4809  static const int kArgumentsStackHeightOffset = 2;
4810  static const int kPcOffset = 3;
4811  static const int kDeoptEntrySize = 4;
4812 
4813  // Simple element accessors.
4814 #define DEFINE_ELEMENT_ACCESSORS(name, type) \
4815  type* name() { \
4816  return type::cast(get(k##name##Index)); \
4817  } \
4818  void Set##name(type* value) { \
4819  set(k##name##Index, value); \
4820  }
4821 
4822  DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4823  DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4824  DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4825  DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4826  DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4827  DEFINE_ELEMENT_ACCESSORS(OptimizationId, Smi)
4828  DEFINE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object)
4829 
4830 #undef DEFINE_ELEMENT_ACCESSORS
4831 
4832  // Accessors for elements of the ith deoptimization entry.
4833 #define DEFINE_ENTRY_ACCESSORS(name, type) \
4834  type* name(int i) { \
4835  return type::cast(get(IndexForEntry(i) + k##name##Offset)); \
4836  } \
4837  void Set##name(int i, type* value) { \
4838  set(IndexForEntry(i) + k##name##Offset, value); \
4839  }
4840 
4841  DEFINE_ENTRY_ACCESSORS(AstIdRaw, Smi)
4842  DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4843  DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
4844  DEFINE_ENTRY_ACCESSORS(Pc, Smi)
4845 
4846 #undef DEFINE_DEOPT_ENTRY_ACCESSORS
4847 
4849  return BailoutId(AstIdRaw(i)->value());
4850  }
4851 
4852  void SetAstId(int i, BailoutId value) {
4853  SetAstIdRaw(i, Smi::FromInt(value.ToInt()));
4854  }
4855 
4856  int DeoptCount() {
4857  return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
4858  }
4859 
4860  // Allocates a DeoptimizationInputData.
4861  static Handle<DeoptimizationInputData> New(Isolate* isolate,
4862  int deopt_entry_count,
4863  PretenureFlag pretenure);
4864 
4866 
4867 #ifdef ENABLE_DISASSEMBLER
4868  void DeoptimizationInputDataPrint(OStream& os); // NOLINT
4869 #endif
4870 
4871  private:
4872  static int IndexForEntry(int i) {
4873  return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4874  }
4875 
4876 
4877  static int LengthFor(int entry_count) { return IndexForEntry(entry_count); }
4878 };
4879 
4880 
4881 // DeoptimizationOutputData is a fixed array used to hold the deoptimization
4882 // data for code generated by the full compiler.
4883 // The format of the these objects is
4884 // [i * 2]: Ast ID for ith deoptimization.
4885 // [i * 2 + 1]: PC and state of ith deoptimization
4887  public:
4888  int DeoptPoints() { return length() / 2; }
4889 
4890  BailoutId AstId(int index) {
4891  return BailoutId(Smi::cast(get(index * 2))->value());
4892  }
4893 
4894  void SetAstId(int index, BailoutId id) {
4895  set(index * 2, Smi::FromInt(id.ToInt()));
4896  }
4897 
4898  Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
4899  void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
4900 
4901  static int LengthOfFixedArray(int deopt_points) {
4902  return deopt_points * 2;
4903  }
4904 
4905  // Allocates a DeoptimizationOutputData.
4906  static Handle<DeoptimizationOutputData> New(Isolate* isolate,
4907  int number_of_deopt_points,
4908  PretenureFlag pretenure);
4909 
4911 
4912 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
4913  void DeoptimizationOutputDataPrint(OStream& os); // NOLINT
4914 #endif
4915 };
4916 
4917 
4918 // Forward declaration.
4919 class Cell;
4920 class PropertyCell;
4921 class SafepointEntry;
4922 class TypeFeedbackInfo;
4923 
4924 // Code describes objects with on-the-fly generated machine code.
4925 class Code: public HeapObject {
4926  public:
4927  // Opaque data type for encapsulating code flags like kind, inline
4928  // cache state, and arguments count.
4929  typedef uint32_t Flags;
4930 
4931 #define NON_IC_KIND_LIST(V) \
4932  V(FUNCTION) \
4933  V(OPTIMIZED_FUNCTION) \
4934  V(STUB) \
4935  V(HANDLER) \
4936  V(BUILTIN) \
4937  V(REGEXP)
4938 
4939 #define IC_KIND_LIST(V) \
4940  V(LOAD_IC) \
4941  V(KEYED_LOAD_IC) \
4942  V(CALL_IC) \
4943  V(STORE_IC) \
4944  V(KEYED_STORE_IC) \
4945  V(BINARY_OP_IC) \
4946  V(COMPARE_IC) \
4947  V(COMPARE_NIL_IC) \
4948  V(TO_BOOLEAN_IC)
4949 
4950 #define CODE_KIND_LIST(V) \
4951  NON_IC_KIND_LIST(V) \
4952  IC_KIND_LIST(V)
4953 
4954  enum Kind {
4955 #define DEFINE_CODE_KIND_ENUM(name) name,
4957 #undef DEFINE_CODE_KIND_ENUM
4958  NUMBER_OF_KINDS
4959  };
4960 
4961  // No more than 16 kinds. The value is currently encoded in four bits in
4962  // Flags.
4963  STATIC_ASSERT(NUMBER_OF_KINDS <= 16);
4964 
4965  static const char* Kind2String(Kind kind);
4966 
4967  // Types of stubs.
4968  enum StubType {
4970  FAST
4971  };
4972 
4973  static const int kPrologueOffsetNotSet = -1;
4974 
4975 #ifdef ENABLE_DISASSEMBLER
4976  // Printing
4977  static const char* ICState2String(InlineCacheState state);
4978  static const char* StubType2String(StubType type);
4979  static void PrintExtraICState(OStream& os, // NOLINT
4980  Kind kind, ExtraICState extra);
4981  void Disassemble(const char* name, OStream& os); // NOLINT
4982 #endif // ENABLE_DISASSEMBLER
4983 
4984  // [instruction_size]: Size of the native instructions
4985  inline int instruction_size() const;
4986  inline void set_instruction_size(int value);
4987 
4988  // [relocation_info]: Code relocation information
4989  DECL_ACCESSORS(relocation_info, ByteArray)
4990  void InvalidateRelocation();
4991  void InvalidateEmbeddedObjects();
4992 
4993  // [handler_table]: Fixed array containing offsets of exception handlers.
4994  DECL_ACCESSORS(handler_table, FixedArray)
4995 
4996  // [deoptimization_data]: Array containing data for deopt.
4997  DECL_ACCESSORS(deoptimization_data, FixedArray)
4998 
4999  // [raw_type_feedback_info]: This field stores various things, depending on
5000  // the kind of the code object.
5001  // FUNCTION => type feedback information.
5002  // STUB and ICs => major/minor key as Smi.
5003  DECL_ACCESSORS(raw_type_feedback_info, Object)
5004  inline Object* type_feedback_info();
5005  inline void set_type_feedback_info(
5007  inline uint32_t stub_key();
5008  inline void set_stub_key(uint32_t key);
5009 
5010  // [next_code_link]: Link for lists of optimized or deoptimized code.
5011  // Note that storage for this field is overlapped with typefeedback_info.
5012  DECL_ACCESSORS(next_code_link, Object)
5013 
5014  // [gc_metadata]: Field used to hold GC related metadata. The contents of this
5015  // field does not have to be traced during garbage collection since
5016  // it is only used by the garbage collector itself.
5017  DECL_ACCESSORS(gc_metadata, Object)
5018 
5019  // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
5020  // at the moment when this object was created.
5021  inline void set_ic_age(int count);
5022  inline int ic_age() const;
5023 
5024  // [prologue_offset]: Offset of the function prologue, used for aging
5025  // FUNCTIONs and OPTIMIZED_FUNCTIONs.
5026  inline int prologue_offset() const;
5027  inline void set_prologue_offset(int offset);
5028 
5029  // Unchecked accessors to be used during GC.
5030  inline ByteArray* unchecked_relocation_info();
5031 
5032  inline int relocation_size();
5033 
5034  // [flags]: Various code flags.
5035  inline Flags flags();
5036  inline void set_flags(Flags flags);
5037 
5038  // [flags]: Access to specific code flags.
5039  inline Kind kind();
5040  inline InlineCacheState ic_state(); // Only valid for IC stubs.
5041  inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
5042 
5043  inline StubType type(); // Only valid for monomorphic IC stubs.
5044 
5045  // Testers for IC stub kinds.
5046  inline bool is_inline_cache_stub();
5047  inline bool is_debug_stub();
5048  inline bool is_handler() { return kind() == HANDLER; }
5049  inline bool is_load_stub() { return kind() == LOAD_IC; }
5050  inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
5051  inline bool is_store_stub() { return kind() == STORE_IC; }
5052  inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
5053  inline bool is_call_stub() { return kind() == CALL_IC; }
5054  inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; }
5055  inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
5056  inline bool is_compare_nil_ic_stub() { return kind() == COMPARE_NIL_IC; }
5057  inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; }
5058  inline bool is_keyed_stub();
5059  inline bool is_optimized_code() { return kind() == OPTIMIZED_FUNCTION; }
5060  inline bool is_weak_stub();
5061  inline void mark_as_weak_stub();
5062  inline bool is_invalidated_weak_stub();
5063  inline void mark_as_invalidated_weak_stub();
5064 
5065  inline bool CanBeWeakStub() {
5066  Kind k = kind();
5067  return (k == LOAD_IC || k == STORE_IC || k == KEYED_LOAD_IC ||
5068  k == KEYED_STORE_IC || k == COMPARE_NIL_IC) &&
5069  ic_state() == MONOMORPHIC;
5070  }
5071 
5072  inline bool IsCodeStubOrIC();
5073 
5074  inline void set_raw_kind_specific_flags1(int value);
5075  inline void set_raw_kind_specific_flags2(int value);
5076 
5077  // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code
5078  // object was generated by either the hydrogen or the TurboFan optimizing
5079  // compiler (but it may not be an optimized function).
5080  inline bool is_crankshafted();
5081  inline bool is_hydrogen_stub(); // Crankshafted, but not a function.
5082  inline void set_is_crankshafted(bool value);
5083 
5084  // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the
5085  // code object was generated by the TurboFan optimizing compiler.
5086  inline bool is_turbofanned();
5087  inline void set_is_turbofanned(bool value);
5088 
5089  // [optimizable]: For FUNCTION kind, tells if it is optimizable.
5090  inline bool optimizable();
5091  inline void set_optimizable(bool value);
5092 
5093  // [has_deoptimization_support]: For FUNCTION kind, tells if it has
5094  // deoptimization support.
5095  inline bool has_deoptimization_support();
5096  inline void set_has_deoptimization_support(bool value);
5097 
5098  // [has_debug_break_slots]: For FUNCTION kind, tells if it has
5099  // been compiled with debug break slots.
5100  inline bool has_debug_break_slots();
5101  inline void set_has_debug_break_slots(bool value);
5102 
5103  // [compiled_with_optimizing]: For FUNCTION kind, tells if it has
5104  // been compiled with IsOptimizing set to true.
5105  inline bool is_compiled_optimizable();
5106  inline void set_compiled_optimizable(bool value);
5107 
5108  // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
5109  // how long the function has been marked for OSR and therefore which
5110  // level of loop nesting we are willing to do on-stack replacement
5111  // for.
5112  inline void set_allow_osr_at_loop_nesting_level(int level);
5113  inline int allow_osr_at_loop_nesting_level();
5114 
5115  // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
5116  // the code object was seen on the stack with no IC patching going on.
5117  inline int profiler_ticks();
5118  inline void set_profiler_ticks(int ticks);
5119 
5120  // [builtin_index]: For BUILTIN kind, tells which builtin index it has.
5121  inline int builtin_index();
5122  inline void set_builtin_index(int id);
5123 
5124  // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
5125  // reserved in the code prologue.
5126  inline unsigned stack_slots();
5127  inline void set_stack_slots(unsigned slots);
5128 
5129  // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in
5130  // the instruction stream where the safepoint table starts.
5131  inline unsigned safepoint_table_offset();
5132  inline void set_safepoint_table_offset(unsigned offset);
5133 
5134  // [back_edge_table_start]: For kind FUNCTION, the offset in the
5135  // instruction stream where the back edge table starts.
5136  inline unsigned back_edge_table_offset();
5137  inline void set_back_edge_table_offset(unsigned offset);
5138 
5139  inline bool back_edges_patched_for_osr();
5140 
5141  // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
5142  inline byte to_boolean_state();
5143 
5144  // [has_function_cache]: For kind STUB tells whether there is a function
5145  // cache is passed to the stub.
5146  inline bool has_function_cache();
5147  inline void set_has_function_cache(bool flag);
5148 
5149 
5150  // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether
5151  // the code is going to be deoptimized because of dead embedded maps.
5152  inline bool marked_for_deoptimization();
5153  inline void set_marked_for_deoptimization(bool flag);
5154 
5155  // [constant_pool]: The constant pool for this function.
5156  inline ConstantPoolArray* constant_pool();
5157  inline void set_constant_pool(Object* constant_pool);
5158 
5159  // Get the safepoint entry for the given pc.
5160  SafepointEntry GetSafepointEntry(Address pc);
5161 
5162  // Find an object in a stub with a specified map
5163  Object* FindNthObject(int n, Map* match_map);
5164 
5165  // Find the first allocation site in an IC stub.
5166  AllocationSite* FindFirstAllocationSite();
5167 
5168  // Find the first map in an IC stub.
5169  Map* FindFirstMap();
5170  void FindAllMaps(MapHandleList* maps);
5171 
5172  // Find the first handler in an IC stub.
5173  Code* FindFirstHandler();
5174 
5175  // Find |length| handlers and put them into |code_list|. Returns false if not
5176  // enough handlers can be found.
5177  bool FindHandlers(CodeHandleList* code_list, int length = -1);
5178 
5179  // Find the handler for |map|.
5180  MaybeHandle<Code> FindHandlerForMap(Map* map);
5181 
5182  // Find the first name in an IC stub.
5183  Name* FindFirstName();
5184 
5185  class FindAndReplacePattern;
5186  // For each (map-to-find, object-to-replace) pair in the pattern, this
5187  // function replaces the corresponding placeholder in the code with the
5188  // object-to-replace. The function assumes that pairs in the pattern come in
5189  // the same order as the placeholders in the code.
5190  void FindAndReplace(const FindAndReplacePattern& pattern);
5191 
5192  // The entire code object including its header is copied verbatim to the
5193  // snapshot so that it can be written in one, fast, memcpy during
5194  // deserialization. The deserializer will overwrite some pointers, rather
5195  // like a runtime linker, but the random allocation addresses used in the
5196  // mksnapshot process would still be present in the unlinked snapshot data,
5197  // which would make snapshot production non-reproducible. This method wipes
5198  // out the to-be-overwritten header data for reproducible snapshots.
5199  inline void WipeOutHeader();
5200 
5201  // Flags operations.
5202  static inline Flags ComputeFlags(
5203  Kind kind, InlineCacheState ic_state = UNINITIALIZED,
5204  ExtraICState extra_ic_state = kNoExtraICState, StubType type = NORMAL,
5206 
5207  static inline Flags ComputeMonomorphicFlags(
5208  Kind kind, ExtraICState extra_ic_state = kNoExtraICState,
5209  CacheHolderFlag holder = kCacheOnReceiver, StubType type = NORMAL);
5210 
5211  static inline Flags ComputeHandlerFlags(
5212  Kind handler_kind, StubType type = NORMAL,
5214 
5215  static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
5216  static inline StubType ExtractTypeFromFlags(Flags flags);
5217  static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
5218  static inline Kind ExtractKindFromFlags(Flags flags);
5219  static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
5220 
5221  static inline Flags RemoveTypeFromFlags(Flags flags);
5222  static inline Flags RemoveTypeAndHolderFromFlags(Flags flags);
5223 
5224  // Convert a target address into a code object.
5225  static inline Code* GetCodeFromTargetAddress(Address address);
5226 
5227  // Convert an entry address into an object.
5228  static inline Object* GetObjectFromEntryAddress(Address location_of_address);
5229 
5230  // Returns the address of the first instruction.
5231  inline byte* instruction_start();
5232 
5233  // Returns the address right after the last instruction.
5234  inline byte* instruction_end();
5235 
5236  // Returns the size of the instructions, padding, and relocation information.
5237  inline int body_size();
5238 
5239  // Returns the address of the first relocation info (read backwards!).
5240  inline byte* relocation_start();
5241 
5242  // Code entry point.
5243  inline byte* entry();
5244 
5245  // Returns true if pc is inside this object's instructions.
5246  inline bool contains(byte* pc);
5247 
5248  // Relocate the code by delta bytes. Called to signal that this code
5249  // object has been moved by delta bytes.
5250  void Relocate(intptr_t delta);
5251 
5252  // Migrate code described by desc.
5253  void CopyFrom(const CodeDesc& desc);
5254 
5255  // Returns the object size for a given body (used for allocation).
5256  static int SizeFor(int body_size) {
5257  DCHECK_SIZE_TAG_ALIGNED(body_size);
5258  return RoundUp(kHeaderSize + body_size, kCodeAlignment);
5259  }
5260 
5261  // Calculate the size of the code object to report for log events. This takes
5262  // the layout of the code object into account.
5264  // Check that the assumptions about the layout of the code object holds.
5265  DCHECK_EQ(static_cast<int>(instruction_start() - address()),
5267  return instruction_size() + Code::kHeaderSize;
5268  }
5269 
5270  // Locating source position.
5271  int SourcePosition(Address pc);
5272  int SourceStatementPosition(Address pc);
5273 
5275 
5276  // Dispatched behavior.
5277  int CodeSize() { return SizeFor(body_size()); }
5278  inline void CodeIterateBody(ObjectVisitor* v);
5279 
5280  template<typename StaticVisitor>
5281  inline void CodeIterateBody(Heap* heap);
5282 
5285 
5286  void ClearInlineCaches();
5287  void ClearInlineCaches(Kind kind);
5288 
5289  BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset);
5290  uint32_t TranslateAstIdToPcOffset(BailoutId ast_id);
5291 
5292 #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge,
5293  enum Age {
5294  kNotExecutedCodeAge = -2,
5295  kExecutedOnceCodeAge = -1,
5296  kNoAgeCodeAge = 0,
5298  kAfterLastCodeAge,
5299  kFirstCodeAge = kNotExecutedCodeAge,
5300  kLastCodeAge = kAfterLastCodeAge - 1,
5301  kCodeAgeCount = kAfterLastCodeAge - kNotExecutedCodeAge - 1,
5302  kIsOldCodeAge = kSexagenarianCodeAge,
5303  kPreAgedCodeAge = kIsOldCodeAge - 1
5304  };
5305 #undef DECLARE_CODE_AGE_ENUM
5306 
5307  // Code aging. Indicates how many full GCs this code has survived without
5308  // being entered through the prologue. Used to determine when it is
5309  // relatively safe to flush this code object and replace it with the lazy
5310  // compilation stub.
5311  static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate);
5312  static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate);
5313  void MakeOlder(MarkingParity);
5314  static bool IsYoungSequence(Isolate* isolate, byte* sequence);
5315  bool IsOld();
5316  Age GetAge();
5317  // Gets the raw code age, including psuedo code-age values such as
5318  // kNotExecutedCodeAge and kExecutedOnceCodeAge.
5319  Age GetRawAge();
5320  static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) {
5321  return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY);
5322  }
5323 
5324  void PrintDeoptLocation(FILE* out, int bailout_id);
5325  bool CanDeoptAt(Address pc);
5326 
5327 #ifdef VERIFY_HEAP
5328  void VerifyEmbeddedObjectsDependency();
5329 #endif
5330 
5331  inline bool CanContainWeakObjects() {
5332  return is_optimized_code() || is_weak_stub();
5333  }
5334 
5335  inline bool IsWeakObject(Object* object) {
5336  return (is_optimized_code() && !is_turbofanned() &&
5337  IsWeakObjectInOptimizedCode(object)) ||
5338  (is_weak_stub() && IsWeakObjectInIC(object));
5339  }
5340 
5341  static inline bool IsWeakObjectInOptimizedCode(Object* object);
5342  static inline bool IsWeakObjectInIC(Object* object);
5343 
5344  // Max loop nesting marker used to postpose OSR. We don't take loop
5345  // nesting that is deeper than 5 levels into account.
5346  static const int kMaxLoopNestingMarker = 6;
5347 
5348  // Layout description.
5349  static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
5350  static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
5351  static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
5352  static const int kDeoptimizationDataOffset =
5353  kHandlerTableOffset + kPointerSize;
5354  // For FUNCTION kind, we store the type feedback info here.
5355  static const int kTypeFeedbackInfoOffset =
5356  kDeoptimizationDataOffset + kPointerSize;
5357  static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize;
5358  static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize;
5359  static const int kICAgeOffset =
5360  kGCMetadataOffset + kPointerSize;
5361  static const int kFlagsOffset = kICAgeOffset + kIntSize;
5362  static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize;
5363  static const int kKindSpecificFlags2Offset =
5364  kKindSpecificFlags1Offset + kIntSize;
5365  // Note: We might be able to squeeze this into the flags above.
5366  static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize;
5367  static const int kConstantPoolOffset = kPrologueOffset + kPointerSize;
5368 
5369  static const int kHeaderPaddingStart = kConstantPoolOffset + kIntSize;
5370 
5371  // Add padding to align the instruction start following right after
5372  // the Code object header.
5373  static const int kHeaderSize =
5374  (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
5375 
5376  // Byte offsets within kKindSpecificFlags1Offset.
5377  static const int kOptimizableOffset = kKindSpecificFlags1Offset;
5378 
5379  static const int kFullCodeFlags = kOptimizableOffset + 1;
5381  public BitField<bool, 0, 1> {}; // NOLINT
5382  class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
5383  class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {};
5384 
5385  static const int kProfilerTicksOffset = kFullCodeFlags + 1;
5386 
5387  // Flags layout. BitField<type, shift, size>.
5388  class ICStateField : public BitField<InlineCacheState, 0, 4> {};
5389  class TypeField : public BitField<StubType, 4, 1> {};
5390  class CacheHolderField : public BitField<CacheHolderFlag, 5, 2> {};
5391  class KindField : public BitField<Kind, 7, 4> {};
5392  class ExtraICStateField: public BitField<ExtraICState, 11,
5393  PlatformSmiTagging::kSmiValueSize - 11 + 1> {}; // NOLINT
5394 
5395  // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION)
5396  static const int kStackSlotsFirstBit = 0;
5397  static const int kStackSlotsBitCount = 24;
5398  static const int kHasFunctionCacheBit =
5399  kStackSlotsFirstBit + kStackSlotsBitCount;
5400  static const int kMarkedForDeoptimizationBit = kHasFunctionCacheBit + 1;
5401  static const int kWeakStubBit = kMarkedForDeoptimizationBit + 1;
5402  static const int kInvalidatedWeakStubBit = kWeakStubBit + 1;
5403  static const int kIsTurbofannedBit = kInvalidatedWeakStubBit + 1;
5404 
5405  STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32);
5406  STATIC_ASSERT(kIsTurbofannedBit + 1 <= 32);
5407 
5408  class StackSlotsField: public BitField<int,
5409  kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT
5410  class HasFunctionCacheField : public BitField<bool, kHasFunctionCacheBit, 1> {
5411  }; // NOLINT
5413  : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT
5414  class WeakStubField : public BitField<bool, kWeakStubBit, 1> {}; // NOLINT
5416  : public BitField<bool, kInvalidatedWeakStubBit, 1> {}; // NOLINT
5417  class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> {
5418  }; // NOLINT
5419 
5420  // KindSpecificFlags2 layout (ALL)
5421  static const int kIsCrankshaftedBit = 0;
5422  class IsCrankshaftedField: public BitField<bool,
5423  kIsCrankshaftedBit, 1> {}; // NOLINT
5424 
5425  // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
5426  static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1;
5427  static const int kSafepointTableOffsetBitCount = 24;
5428 
5429  STATIC_ASSERT(kSafepointTableOffsetFirstBit +
5430  kSafepointTableOffsetBitCount <= 32);
5431  STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32);
5432 
5434  kSafepointTableOffsetFirstBit,
5435  kSafepointTableOffsetBitCount> {}; // NOLINT
5436 
5437  // KindSpecificFlags2 layout (FUNCTION)
5439  kIsCrankshaftedBit + 1, 27> {}; // NOLINT
5441  kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT
5442  STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker);
5443 
5444  static const int kArgumentsBits = 16;
5445  static const int kMaxArguments = (1 << kArgumentsBits) - 1;
5446 
5447  // This constant should be encodable in an ARM instruction.
5448  static const int kFlagsNotUsedInLookup =
5449  TypeField::kMask | CacheHolderField::kMask;
5450 
5451  private:
5452  friend class RelocIterator;
5453  friend class Deoptimizer; // For FindCodeAgeSequence.
5454 
5455  void ClearInlineCaches(Kind* kind);
5456 
5457  // Code aging
5458  byte* FindCodeAgeSequence();
5459  static void GetCodeAgeAndParity(Code* code, Age* age,
5460  MarkingParity* parity);
5461  static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age,
5462  MarkingParity* parity);
5463  static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity);
5464 
5465  // Code aging -- platform-specific
5466  static void PatchPlatformCodeAge(Isolate* isolate,
5467  byte* sequence, Age age,
5468  MarkingParity parity);
5469 
5471 };
5472 
5473 
5474 class CompilationInfo;
5475 
5476 // This class describes the layout of dependent codes array of a map. The
5477 // array is partitioned into several groups of dependent codes. Each group
5478 // contains codes with the same dependency on the map. The array has the
5479 // following layout for n dependency groups:
5480 //
5481 // +----+----+-----+----+---------+----------+-----+---------+-----------+
5482 // | C1 | C2 | ... | Cn | group 1 | group 2 | ... | group n | undefined |
5483 // +----+----+-----+----+---------+----------+-----+---------+-----------+
5484 //
5485 // The first n elements are Smis, each of them specifies the number of codes
5486 // in the corresponding group. The subsequent elements contain grouped code
5487 // objects. The suffix of the array can be filled with the undefined value if
5488 // the number of codes is less than the length of the array. The order of the
5489 // code objects within a group is not preserved.
5490 //
5491 // All code indexes used in the class are counted starting from the first
5492 // code object of the first group. In other words, code index 0 corresponds
5493 // to array index n = kCodesStartIndex.
5494 
5495 class DependentCode: public FixedArray {
5496  public:
5498  // Group of IC stubs that weakly embed this map and depend on being
5499  // invalidated when the map is garbage collected. Dependent IC stubs form
5500  // a linked list. This group stores only the head of the list. This means
5501  // that the number_of_entries(kWeakICGroup) is 0 or 1.
5503  // Group of code that weakly embed this map and depend on being
5504  // deoptimized when the map is garbage collected.
5506  // Group of code that embed a transition to this map, and depend on being
5507  // deoptimized when the transition is replaced by a new version.
5509  // Group of code that omit run-time prototype checks for prototypes
5510  // described by this map. The group is deoptimized whenever an object
5511  // described by this map changes shape (and transitions to a new map),
5512  // possibly invalidating the assumptions embedded in the code.
5514  // Group of code that depends on elements not being added to objects with
5515  // this map.
5517  // Group of code that depends on global property values in property cells
5518  // not being changed.
5520  // Group of code that omit run-time type checks for the field(s) introduced
5521  // by this map.
5523  // Group of code that omit run-time type checks for initial maps of
5524  // constructors.
5526  // Group of code that depends on tenuring information in AllocationSites
5527  // not being changed.
5529  // Group of code that depends on element transition information in
5530  // AllocationSites not being changed.
5531  kAllocationSiteTransitionChangedGroup
5532  };
5533 
5534  static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1;
5535 
5536  // Array for holding the index of the first code object of each group.
5537  // The last element stores the total number of code objects.
5539  public:
5540  explicit GroupStartIndexes(DependentCode* entries);
5541  void Recompute(DependentCode* entries);
5542  int at(int i) { return start_indexes_[i]; }
5543  int number_of_entries() { return start_indexes_[kGroupCount]; }
5544  private:
5545  int start_indexes_[kGroupCount + 1];
5546  };
5547 
5548  bool Contains(DependencyGroup group, Code* code);
5549  static Handle<DependentCode> Insert(Handle<DependentCode> entries,
5550  DependencyGroup group,
5551  Handle<Object> object);
5552  void UpdateToFinishedCode(DependencyGroup group,
5553  CompilationInfo* info,
5554  Code* code);
5555  void RemoveCompilationInfo(DependentCode::DependencyGroup group,
5556  CompilationInfo* info);
5557 
5558  void DeoptimizeDependentCodeGroup(Isolate* isolate,
5560 
5561  bool MarkCodeForDeoptimization(Isolate* isolate,
5563  void AddToDependentICList(Handle<Code> stub);
5564 
5565  // The following low-level accessors should only be used by this class
5566  // and the mark compact collector.
5567  inline int number_of_entries(DependencyGroup group);
5568  inline void set_number_of_entries(DependencyGroup group, int value);
5569  inline bool is_code_at(int i);
5570  inline Code* code_at(int i);
5571  inline CompilationInfo* compilation_info_at(int i);
5572  inline void set_object_at(int i, Object* object);
5573  inline Object** slot_at(int i);
5574  inline Object* object_at(int i);
5575  inline void clear_at(int i);
5576  inline void copy(int from, int to);
5578 
5579  static DependentCode* ForObject(Handle<HeapObject> object,
5580  DependencyGroup group);
5581 
5582  static const char* DependencyGroupName(DependencyGroup group);
5583  static void SetMarkedForDeoptimization(Code* code, DependencyGroup group);
5584 
5585  private:
5586  // Make a room at the end of the given group by moving out the first
5587  // code objects of the subsequent groups.
5588  inline void ExtendGroup(DependencyGroup group);
5589  static const int kCodesStartIndex = kGroupCount;
5590 };
5591 
5592 
5593 // All heap objects have a Map that describes their structure.
5594 // A Map contains information about:
5595 // - Size information about the object
5596 // - How to iterate over an object (for garbage collection)
5597 class Map: public HeapObject {
5598  public:
5599  // Instance size.
5600  // Size in bytes or kVariableSizeSentinel if instances do not have
5601  // a fixed size.
5602  inline int instance_size();
5603  inline void set_instance_size(int value);
5604 
5605  // Count of properties allocated in the object.
5606  inline int inobject_properties();
5607  inline void set_inobject_properties(int value);
5608 
5609  // Count of property fields pre-allocated in the object when first allocated.
5610  inline int pre_allocated_property_fields();
5611  inline void set_pre_allocated_property_fields(int value);
5612 
5613  // Instance type.
5614  inline InstanceType instance_type();
5615  inline void set_instance_type(InstanceType value);
5616 
5617  // Tells how many unused property fields are available in the
5618  // instance (only used for JSObject in fast mode).
5619  inline int unused_property_fields();
5620  inline void set_unused_property_fields(int value);
5621 
5622  // Bit field.
5623  inline byte bit_field();
5624  inline void set_bit_field(byte value);
5625 
5626  // Bit field 2.
5627  inline byte bit_field2();
5628  inline void set_bit_field2(byte value);
5629 
5630  // Bit field 3.
5631  inline uint32_t bit_field3();
5632  inline void set_bit_field3(uint32_t bits);
5633 
5634  class EnumLengthBits: public BitField<int,
5635  0, kDescriptorIndexBitCount> {}; // NOLINT
5637  kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT
5639  class DictionaryMap : public BitField<bool, 20, 1> {};
5640  class OwnsDescriptors : public BitField<bool, 21, 1> {};
5641  class HasInstanceCallHandler : public BitField<bool, 22, 1> {};
5642  class Deprecated : public BitField<bool, 23, 1> {};
5643  class IsFrozen : public BitField<bool, 24, 1> {};
5644  class IsUnstable : public BitField<bool, 25, 1> {};
5645  class IsMigrationTarget : public BitField<bool, 26, 1> {};
5646  class DoneInobjectSlackTracking : public BitField<bool, 27, 1> {};
5647  // Bit 28 is free.
5648 
5649  // Keep this bit field at the very end for better code in
5650  // Builtins::kJSConstructStubGeneric stub.
5651  class ConstructionCount: public BitField<int, 29, 3> {};
5652 
5653  // Tells whether the object in the prototype property will be used
5654  // for instances created from this function. If the prototype
5655  // property is set to a value that is not a JSObject, the prototype
5656  // property will not be used to create instances of the function.
5657  // See ECMA-262, 13.2.2.
5658  inline void set_non_instance_prototype(bool value);
5659  inline bool has_non_instance_prototype();
5660 
5661  // Tells whether function has special prototype property. If not, prototype
5662  // property will not be created when accessed (will return undefined),
5663  // and construction from this function will not be allowed.
5664  inline void set_function_with_prototype(bool value);
5665  inline bool function_with_prototype();
5666 
5667  // Tells whether the instance with this map should be ignored by the
5668  // Object.getPrototypeOf() function and the __proto__ accessor.
5669  inline void set_is_hidden_prototype() {
5670  set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
5671  }
5672 
5673  inline bool is_hidden_prototype() {
5674  return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
5675  }
5676 
5677  // Records and queries whether the instance has a named interceptor.
5679  set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
5680  }
5681 
5682  inline bool has_named_interceptor() {
5683  return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
5684  }
5685 
5686  // Records and queries whether the instance has an indexed interceptor.
5688  set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
5689  }
5690 
5691  inline bool has_indexed_interceptor() {
5692  return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
5693  }
5694 
5695  // Tells whether the instance is undetectable.
5696  // An undetectable object is a special class of JSObject: 'typeof' operator
5697  // returns undefined, ToBoolean returns false. Otherwise it behaves like
5698  // a normal JS object. It is useful for implementing undetectable
5699  // document.all in Firefox & Safari.
5700  // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
5701  inline void set_is_undetectable() {
5702  set_bit_field(bit_field() | (1 << kIsUndetectable));
5703  }
5704 
5705  inline bool is_undetectable() {
5706  return ((1 << kIsUndetectable) & bit_field()) != 0;
5707  }
5708 
5709  // Tells whether the instance has a call-as-function handler.
5710  inline void set_is_observed() {
5711  set_bit_field(bit_field() | (1 << kIsObserved));
5712  }
5713 
5714  inline bool is_observed() {
5715  return ((1 << kIsObserved) & bit_field()) != 0;
5716  }
5717 
5718  inline void set_is_extensible(bool value);
5719  inline bool is_extensible();
5720  inline void set_is_prototype_map(bool value);
5721  inline bool is_prototype_map();
5722 
5723  inline void set_elements_kind(ElementsKind elements_kind) {
5724  DCHECK(elements_kind < kElementsKindCount);
5726  set_bit_field2(Map::ElementsKindBits::update(bit_field2(), elements_kind));
5727  DCHECK(this->elements_kind() == elements_kind);
5728  }
5729 
5731  return Map::ElementsKindBits::decode(bit_field2());
5732  }
5733 
5734  // Tells whether the instance has fast elements that are only Smis.
5735  inline bool has_fast_smi_elements() {
5736  return IsFastSmiElementsKind(elements_kind());
5737  }
5738 
5739  // Tells whether the instance has fast elements.
5741  return IsFastObjectElementsKind(elements_kind());
5742  }
5743 
5745  return IsFastSmiOrObjectElementsKind(elements_kind());
5746  }
5747 
5749  return IsFastDoubleElementsKind(elements_kind());
5750  }
5751 
5752  inline bool has_fast_elements() {
5753  return IsFastElementsKind(elements_kind());
5754  }
5755 
5757  return elements_kind() == SLOPPY_ARGUMENTS_ELEMENTS;
5758  }
5759 
5761  return IsExternalArrayElementsKind(elements_kind());
5762  }
5763 
5765  return IsFixedTypedArrayElementsKind(elements_kind());
5766  }
5767 
5768  inline bool has_dictionary_elements() {
5769  return IsDictionaryElementsKind(elements_kind());
5770  }
5771 
5772  inline bool has_slow_elements_kind() {
5773  return elements_kind() == DICTIONARY_ELEMENTS
5774  || elements_kind() == SLOPPY_ARGUMENTS_ELEMENTS;
5775  }
5776 
5777  static bool IsValidElementsTransition(ElementsKind from_kind,
5778  ElementsKind to_kind);
5779 
5780  // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a
5781  // map with DICTIONARY_ELEMENTS was found in the prototype chain.
5782  bool DictionaryElementsInPrototypeChainOnly();
5783 
5784  inline bool HasTransitionArray() const;
5785  inline bool HasElementsTransition();
5786  inline Map* elements_transition_map();
5787 
5788  inline Map* GetTransition(int transition_index);
5789  inline int SearchTransition(Name* name);
5790  inline FixedArrayBase* GetInitialElements();
5791 
5792  DECL_ACCESSORS(transitions, TransitionArray)
5793 
5794  static inline Handle<String> ExpectedTransitionKey(Handle<Map> map);
5795  static inline Handle<Map> ExpectedTransitionTarget(Handle<Map> map);
5796 
5797  // Try to follow an existing transition to a field with attributes NONE. The
5798  // return value indicates whether the transition was successful.
5799  static inline Handle<Map> FindTransitionToField(Handle<Map> map,
5800  Handle<Name> key);
5801 
5802  Map* FindRootMap();
5803  Map* FindFieldOwner(int descriptor);
5804 
5805  inline int GetInObjectPropertyOffset(int index);
5806 
5807  int NumberOfFields();
5808 
5809  // TODO(ishell): candidate with JSObject::MigrateToMap().
5810  bool InstancesNeedRewriting(Map* target, int target_number_of_fields,
5811  int target_inobject, int target_unused,
5812  int* old_number_of_fields);
5813  // TODO(ishell): moveit!
5814  static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map);
5815  MUST_USE_RESULT static Handle<HeapType> GeneralizeFieldType(
5816  Handle<HeapType> type1,
5817  Handle<HeapType> type2,
5818  Isolate* isolate);
5819  static void GeneralizeFieldType(Handle<Map> map,
5820  int modify_index,
5821  Handle<HeapType> new_field_type);
5822  static Handle<Map> GeneralizeRepresentation(
5823  Handle<Map> map,
5824  int modify_index,
5825  Representation new_representation,
5826  Handle<HeapType> new_field_type,
5827  StoreMode store_mode);
5828  static Handle<Map> CopyGeneralizeAllRepresentations(
5829  Handle<Map> map,
5830  int modify_index,
5831  StoreMode store_mode,
5832  PropertyAttributes attributes,
5833  const char* reason);
5834  static Handle<Map> CopyGeneralizeAllRepresentations(
5835  Handle<Map> map,
5836  int modify_index,
5837  StoreMode store_mode,
5838  const char* reason);
5839 
5840  static Handle<Map> PrepareForDataProperty(Handle<Map> old_map,
5841  int descriptor_number,
5843 
5845 
5846  // Returns the constructor name (the name (possibly, inferred name) of the
5847  // function that was used to instantiate the object).
5848  String* constructor_name();
5849 
5850  // Tells whether the map is used for JSObjects in dictionary mode (ie
5851  // normalized objects, ie objects for which HasFastProperties returns false).
5852  // A map can never be used for both dictionary mode and fast mode JSObjects.
5853  // False by default and for HeapObjects that are not JSObjects.
5854  inline void set_dictionary_map(bool value);
5855  inline bool is_dictionary_map();
5856 
5857  // Tells whether the instance needs security checks when accessing its
5858  // properties.
5859  inline void set_is_access_check_needed(bool access_check_needed);
5860  inline bool is_access_check_needed();
5861 
5862  // Returns true if map has a non-empty stub code cache.
5863  inline bool has_code_cache();
5864 
5865  // [prototype]: implicit prototype object.
5866  DECL_ACCESSORS(prototype, Object)
5867 
5868  // [constructor]: points back to the function responsible for this map.
5869  DECL_ACCESSORS(constructor, Object)
5870 
5871  // [instance descriptors]: describes the object.
5872  DECL_ACCESSORS(instance_descriptors, DescriptorArray)
5873  inline void InitializeDescriptors(DescriptorArray* descriptors);
5874 
5875  // [stub cache]: contains stubs compiled for this map.
5876  DECL_ACCESSORS(code_cache, Object)
5877 
5878  // [dependent code]: list of optimized codes that weakly embed this map.
5880 
5881  // [back pointer]: points back to the parent map from which a transition
5882  // leads to this map. The field overlaps with prototype transitions and the
5883  // back pointer will be moved into the prototype transitions array if
5884  // required.
5885  inline Object* GetBackPointer();
5886  inline void SetBackPointer(Object* value,
5888  inline void init_back_pointer(Object* undefined);
5889 
5890  // [prototype transitions]: cache of prototype transitions.
5891  // Prototype transition is a transition that happens
5892  // when we change object's prototype to a new one.
5893  // Cache format:
5894  // 0: finger - index of the first free cell in the cache
5895  // 1: back pointer that overlaps with prototype transitions field.
5896  // 2 + 2 * i: prototype
5897  // 3 + 2 * i: target map
5898  inline FixedArray* GetPrototypeTransitions();
5899  inline bool HasPrototypeTransitions();
5900 
5901  static const int kProtoTransitionHeaderSize = 1;
5902  static const int kProtoTransitionNumberOfEntriesOffset = 0;
5903  static const int kProtoTransitionElementsPerEntry = 2;
5904  static const int kProtoTransitionPrototypeOffset = 0;
5905  static const int kProtoTransitionMapOffset = 1;
5906 
5908  FixedArray* cache = GetPrototypeTransitions();
5909  if (cache->length() == 0) return 0;
5910  return
5911  Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value();
5912  }
5913 
5915  FixedArray* cache = GetPrototypeTransitions();
5916  DCHECK(cache->length() != 0);
5917  cache->set(kProtoTransitionNumberOfEntriesOffset, Smi::FromInt(value));
5918  }
5919 
5920  // Lookup in the map's instance descriptors and fill out the result
5921  // with the given holder if the name is found. The holder may be
5922  // NULL when this function is used from the compiler.
5923  inline void LookupDescriptor(JSObject* holder,
5924  Name* name,
5925  LookupResult* result);
5926 
5927  inline void LookupTransition(JSObject* holder,
5928  Name* name,
5929  LookupResult* result);
5930 
5931  inline PropertyDetails GetLastDescriptorDetails();
5932 
5933  // The size of transition arrays are limited so they do not end up in large
5934  // object space. Otherwise ClearNonLiveTransitions would leak memory while
5935  // applying in-place right trimming.
5936  inline bool CanHaveMoreTransitions();
5937 
5938  int LastAdded() {
5939  int number_of_own_descriptors = NumberOfOwnDescriptors();
5940  DCHECK(number_of_own_descriptors > 0);
5941  return number_of_own_descriptors - 1;
5942  }
5943 
5945  return NumberOfOwnDescriptorsBits::decode(bit_field3());
5946  }
5947 
5948  void SetNumberOfOwnDescriptors(int number) {
5949  DCHECK(number <= instance_descriptors()->number_of_descriptors());
5950  set_bit_field3(NumberOfOwnDescriptorsBits::update(bit_field3(), number));
5951  }
5952 
5954 
5955  int EnumLength() {
5956  return EnumLengthBits::decode(bit_field3());
5957  }
5958 
5959  void SetEnumLength(int length) {
5960  if (length != kInvalidEnumCacheSentinel) {
5961  DCHECK(length >= 0);
5962  DCHECK(length == 0 || instance_descriptors()->HasEnumCache());
5963  DCHECK(length <= NumberOfOwnDescriptors());
5964  }
5965  set_bit_field3(EnumLengthBits::update(bit_field3(), length));
5966  }
5967 
5968  inline bool owns_descriptors();
5969  inline void set_owns_descriptors(bool owns_descriptors);
5970  inline bool has_instance_call_handler();
5971  inline void set_has_instance_call_handler();
5972  inline void freeze();
5973  inline bool is_frozen();
5974  inline void mark_unstable();
5975  inline bool is_stable();
5976  inline void set_migration_target(bool value);
5977  inline bool is_migration_target();
5978  inline void set_done_inobject_slack_tracking(bool value);
5979  inline bool done_inobject_slack_tracking();
5980  inline void set_construction_count(int value);
5981  inline int construction_count();
5982  inline void deprecate();
5983  inline bool is_deprecated();
5984  inline bool CanBeDeprecated();
5985  // Returns a non-deprecated version of the input. If the input was not
5986  // deprecated, it is directly returned. Otherwise, the non-deprecated version
5987  // is found by re-transitioning from the root of the transition tree using the
5988  // descriptor array of the map. Returns NULL if no updated map is found.
5989  // This method also applies any pending migrations along the prototype chain.
5991  // Same as above, but does not touch the prototype chain.
5992  static MaybeHandle<Map> TryUpdateInternal(Handle<Map> map)
5994 
5995  // Returns a non-deprecated version of the input. This method may deprecate
5996  // existing maps along the way if encodings conflict. Not for use while
5997  // gathering type feedback. Use TryUpdate in those cases instead.
5998  static Handle<Map> Update(Handle<Map> map);
5999 
6000  static Handle<Map> CopyDropDescriptors(Handle<Map> map);
6001  static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
6002  Descriptor* descriptor,
6004 
6005  MUST_USE_RESULT static MaybeHandle<Map> CopyWithField(
6006  Handle<Map> map,
6008  Handle<HeapType> type,
6009  PropertyAttributes attributes,
6010  Representation representation,
6012 
6013  MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant(
6014  Handle<Map> map,
6016  Handle<Object> constant,
6017  PropertyAttributes attributes,
6019 
6020  // Returns a new map with all transitions dropped from the given map and
6021  // the ElementsKind set.
6022  static Handle<Map> TransitionElementsTo(Handle<Map> map,
6023  ElementsKind to_kind);
6024 
6025  static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
6026 
6027  static Handle<Map> CopyAsElementsKind(Handle<Map> map,
6028  ElementsKind kind,
6030 
6031  static Handle<Map> CopyForObserved(Handle<Map> map);
6032 
6033  static Handle<Map> CopyForFreeze(Handle<Map> map);
6034  // Maximal number of fast properties. Used to restrict the number of map
6035  // transitions to avoid an explosion in the number of maps for objects used as
6036  // dictionaries.
6037  inline bool TooManyFastProperties(StoreFromKeyed store_mode);
6038  static Handle<Map> TransitionToDataProperty(Handle<Map> map,
6041  PropertyAttributes attributes,
6042  StoreFromKeyed store_mode);
6043  static Handle<Map> TransitionToAccessorProperty(
6045  Handle<Object> accessor, PropertyAttributes attributes);
6046  static Handle<Map> ReconfigureDataProperty(Handle<Map> map, int descriptor,
6047  PropertyAttributes attributes);
6048 
6049  inline void AppendDescriptor(Descriptor* desc);
6050 
6051  // Returns a copy of the map, with all transitions dropped from the
6052  // instance descriptors.
6053  static Handle<Map> Copy(Handle<Map> map);
6054  static Handle<Map> Create(Isolate* isolate, int inobject_properties);
6055 
6056  // Returns the next free property index (only valid for FAST MODE).
6057  int NextFreePropertyIndex();
6058 
6059  // Returns the number of properties described in instance_descriptors
6060  // filtering out properties with the specified attributes.
6061  int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
6062  PropertyAttributes filter = NONE);
6063 
6064  // Returns the number of slots allocated for the initial properties
6065  // backing storage for instances of this map.
6067  return pre_allocated_property_fields() + unused_property_fields() -
6068  inobject_properties();
6069  }
6070 
6071  DECLARE_CAST(Map)
6072 
6073  // Code cache operations.
6074 
6075  // Clears the code cache.
6076  inline void ClearCodeCache(Heap* heap);
6077 
6078  // Update code cache.
6079  static void UpdateCodeCache(Handle<Map> map,
6081  Handle<Code> code);
6082 
6083  // Extend the descriptor array of the map with the list of descriptors.
6084  // In case of duplicates, the latest descriptor is used.
6085  static void AppendCallbackDescriptors(Handle<Map> map,
6086  Handle<Object> descriptors);
6087 
6088  static void EnsureDescriptorSlack(Handle<Map> map, int slack);
6089 
6090  // Returns the found code or undefined if absent.
6091  Object* FindInCodeCache(Name* name, Code::Flags flags);
6092 
6093  // Returns the non-negative index of the code object if it is in the
6094  // cache and -1 otherwise.
6095  int IndexInCodeCache(Object* name, Code* code);
6096 
6097  // Removes a code object from the code cache at the given index.
6098  void RemoveFromCodeCache(Name* name, Code* code, int index);
6099 
6100  // Set all map transitions from this map to dead maps to null. Also clear
6101  // back pointers in transition targets so that we do not process this map
6102  // again while following back pointers.
6104 
6105  // Computes a hash value for this map, to be used in HashTables and such.
6106  int Hash();
6107 
6108  // Returns the map that this map transitions to if its elements_kind
6109  // is changed to |elements_kind|, or NULL if no such map is cached yet.
6110  // |safe_to_add_transitions| is set to false if adding transitions is not
6111  // allowed.
6112  Map* LookupElementsTransitionMap(ElementsKind elements_kind);
6113 
6114  // Returns the transitioned map for this map with the most generic
6115  // elements_kind that's found in |candidates|, or null handle if no match is
6116  // found at all.
6117  Handle<Map> FindTransitionedMap(MapHandleList* candidates);
6118 
6119  bool CanTransition() {
6120  // Only JSObject and subtypes have map transitions and back pointers.
6122  return instance_type() >= FIRST_JS_OBJECT_TYPE;
6123  }
6124 
6125  bool IsJSObjectMap() {
6126  return instance_type() >= FIRST_JS_OBJECT_TYPE;
6127  }
6128  bool IsJSProxyMap() {
6129  InstanceType type = instance_type();
6130  return FIRST_JS_PROXY_TYPE <= type && type <= LAST_JS_PROXY_TYPE;
6131  }
6133  return instance_type() == JS_GLOBAL_PROXY_TYPE;
6134  }
6136  return instance_type() == JS_GLOBAL_OBJECT_TYPE;
6137  }
6139  const InstanceType type = instance_type();
6140  return type == JS_GLOBAL_OBJECT_TYPE || type == JS_BUILTINS_OBJECT_TYPE;
6141  }
6142 
6143  inline bool CanOmitMapChecks();
6144 
6145  static void AddDependentCompilationInfo(Handle<Map> map,
6147  CompilationInfo* info);
6148 
6149  static void AddDependentCode(Handle<Map> map,
6151  Handle<Code> code);
6152  static void AddDependentIC(Handle<Map> map,
6153  Handle<Code> stub);
6154 
6155  bool IsMapInArrayPrototypeChain();
6156 
6157  // Dispatched behavior.
6160 
6161 #ifdef VERIFY_HEAP
6162  void DictionaryMapVerify();
6163  void VerifyOmittedMapChecks();
6164 #endif
6165 
6166  inline int visitor_id();
6167  inline void set_visitor_id(int visitor_id);
6168 
6169  typedef void (*TraverseCallback)(Map* map, void* data);
6170 
6171  void TraverseTransitionTree(TraverseCallback callback, void* data);
6172 
6173  // When you set the prototype of an object using the __proto__ accessor you
6174  // need a new map for the object (the prototype is stored in the map). In
6175  // order not to multiply maps unnecessarily we store these as transitions in
6176  // the original map. That way we can transition to the same map if the same
6177  // prototype is set, rather than creating a new map every time. The
6178  // transitions are in the form of a map where the keys are prototype objects
6179  // and the values are the maps the are transitioned to.
6180  static const int kMaxCachedPrototypeTransitions = 256;
6181  static Handle<Map> TransitionToPrototype(Handle<Map> map,
6182  Handle<Object> prototype);
6183 
6184  static const int kMaxPreAllocatedPropertyFields = 255;
6185 
6186  // Layout description.
6187  static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
6188  static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
6189  static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize;
6190  static const int kPrototypeOffset = kBitField3Offset + kPointerSize;
6191  static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
6192  // Storage for the transition array is overloaded to directly contain a back
6193  // pointer if unused. When the map has transitions, the back pointer is
6194  // transferred to the transition array and accessed through an extra
6195  // indirection.
6196  static const int kTransitionsOrBackPointerOffset =
6197  kConstructorOffset + kPointerSize;
6198  static const int kDescriptorsOffset =
6199  kTransitionsOrBackPointerOffset + kPointerSize;
6200  static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize;
6201  static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize;
6202  static const int kSize = kDependentCodeOffset + kPointerSize;
6203 
6204  // Layout of pointer fields. Heap iteration code relies on them
6205  // being continuously allocated.
6206  static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
6207  static const int kPointerFieldsEndOffset = kSize;
6208 
6209  // Byte offsets within kInstanceSizesOffset.
6210  static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
6211  static const int kInObjectPropertiesByte = 1;
6212  static const int kInObjectPropertiesOffset =
6213  kInstanceSizesOffset + kInObjectPropertiesByte;
6214  static const int kPreAllocatedPropertyFieldsByte = 2;
6215  static const int kPreAllocatedPropertyFieldsOffset =
6216  kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
6217  static const int kVisitorIdByte = 3;
6218  static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
6219 
6220  // Byte offsets within kInstanceAttributesOffset attributes.
6221 #if V8_TARGET_LITTLE_ENDIAN
6222  // Order instance type and bit field together such that they can be loaded
6223  // together as a 16-bit word with instance type in the lower 8 bits regardless
6224  // of endianess. Also provide endian-independent offset to that 16-bit word.
6225  static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
6226  static const int kBitFieldOffset = kInstanceAttributesOffset + 1;
6227 #else
6228  static const int kBitFieldOffset = kInstanceAttributesOffset + 0;
6229  static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1;
6230 #endif
6231  static const int kInstanceTypeAndBitFieldOffset =
6232  kInstanceAttributesOffset + 0;
6233  static const int kBitField2Offset = kInstanceAttributesOffset + 2;
6234  static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3;
6235 
6236  STATIC_ASSERT(kInstanceTypeAndBitFieldOffset ==
6238 
6239  // Bit positions for bit field.
6240  static const int kHasNonInstancePrototype = 0;
6241  static const int kIsHiddenPrototype = 1;
6242  static const int kHasNamedInterceptor = 2;
6243  static const int kHasIndexedInterceptor = 3;
6244  static const int kIsUndetectable = 4;
6245  static const int kIsObserved = 5;
6246  static const int kIsAccessCheckNeeded = 6;
6247  class FunctionWithPrototype: public BitField<bool, 7, 1> {};
6248 
6249  // Bit positions for bit field 2
6250  static const int kIsExtensible = 0;
6251  static const int kStringWrapperSafeForDefaultValueOf = 1;
6252  class IsPrototypeMapBits : public BitField<bool, 2, 1> {};
6253  class ElementsKindBits: public BitField<ElementsKind, 3, 5> {};
6254 
6255  // Derived values from bit field 2
6256  static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
6258  static const int8_t kMaximumBitField2FastSmiElementValue =
6259  static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
6261  static const int8_t kMaximumBitField2FastHoleyElementValue =
6262  static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
6264  static const int8_t kMaximumBitField2FastHoleySmiElementValue =
6265  static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
6267 
6268  typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
6269  kPointerFieldsEndOffset,
6271 
6272  // Compares this map to another to see if they describe equivalent objects.
6273  // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
6274  // it had exactly zero inobject properties.
6275  // The "shared" flags of both this map and |other| are ignored.
6276  bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
6277 
6278  private:
6279  static void ConnectElementsTransition(Handle<Map> parent, Handle<Map> child);
6280  static void ConnectTransition(Handle<Map> parent, Handle<Map> child,
6282 
6283  bool EquivalentToForTransition(Map* other);
6284  static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
6285  static Handle<Map> ShareDescriptor(Handle<Map> map,
6286  Handle<DescriptorArray> descriptors,
6287  Descriptor* descriptor);
6288  static Handle<Map> CopyInstallDescriptors(
6289  Handle<Map> map,
6290  int new_descriptor,
6291  Handle<DescriptorArray> descriptors);
6292  static Handle<Map> CopyAddDescriptor(Handle<Map> map,
6293  Descriptor* descriptor,
6295  static Handle<Map> CopyReplaceDescriptors(
6296  Handle<Map> map,
6297  Handle<DescriptorArray> descriptors,
6299  MaybeHandle<Name> maybe_name,
6300  SimpleTransitionFlag simple_flag = FULL_TRANSITION);
6301  static Handle<Map> CopyReplaceDescriptor(Handle<Map> map,
6302  Handle<DescriptorArray> descriptors,
6303  Descriptor* descriptor,
6304  int index,
6306 
6307  static Handle<Map> CopyNormalized(Handle<Map> map,
6309 
6310  // Fires when the layout of an object with a leaf map changes.
6311  // This includes adding transitions to the leaf map or changing
6312  // the descriptor array.
6313  inline void NotifyLeafMapLayoutChange();
6314 
6315  static Handle<Map> TransitionElementsToSlow(Handle<Map> object,
6316  ElementsKind to_kind);
6317 
6318  // Zaps the contents of backing data structures. Note that the
6319  // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
6320  // holding weak references when incremental marking is used, because it also
6321  // iterates over objects that are otherwise unreachable.
6322  // In general we only want to call these functions in release mode when
6323  // heap verification is turned on.
6324  void ZapPrototypeTransitions();
6325  void ZapTransitions();
6326 
6327  void DeprecateTransitionTree();
6328  void DeprecateTarget(Name* key, DescriptorArray* new_descriptors);
6329 
6330  Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
6331 
6332  void UpdateFieldType(int descriptor_number, Handle<Name> name,
6333  Handle<HeapType> new_type);
6334 
6335  void PrintGeneralization(FILE* file,
6336  const char* reason,
6337  int modify_index,
6338  int split,
6339  int descriptors,
6340  bool constant_to_field,
6341  Representation old_representation,
6342  Representation new_representation,
6343  HeapType* old_field_type,
6344  HeapType* new_field_type);
6345 
6346  static inline void SetPrototypeTransitions(
6347  Handle<Map> map,
6348  Handle<FixedArray> prototype_transitions);
6349 
6350  static Handle<Map> GetPrototypeTransition(Handle<Map> map,
6351  Handle<Object> prototype);
6352  static Handle<Map> PutPrototypeTransition(Handle<Map> map,
6353  Handle<Object> prototype,
6354  Handle<Map> target_map);
6355 
6356  static const int kFastPropertiesSoftLimit = 12;
6357  static const int kMaxFastProperties = 128;
6358 
6360 };
6361 
6362 
6363 // An abstract superclass, a marker class really, for simple structure classes.
6364 // It doesn't carry much functionality but allows struct classes to be
6365 // identified in the type system.
6366 class Struct: public HeapObject {
6367  public:
6368  inline void InitializeBody(int object_size);
6370 };
6371 
6372 
6373 // A simple one-element struct, useful where smis need to be boxed.
6374 class Box : public Struct {
6375  public:
6376  // [value]: the boxed contents.
6378 
6379  DECLARE_CAST(Box)
6380 
6381  // Dispatched behavior.
6384 
6385  static const int kValueOffset = HeapObject::kHeaderSize;
6386  static const int kSize = kValueOffset + kPointerSize;
6387 
6388  private:
6390 };
6391 
6392 
6393 // Script describes a script which has been added to the VM.
6394 class Script: public Struct {
6395  public:
6396  // Script types.
6397  enum Type {
6398  TYPE_NATIVE = 0,
6399  TYPE_EXTENSION = 1,
6400  TYPE_NORMAL = 2
6401  };
6402 
6403  // Script compilation types.
6405  COMPILATION_TYPE_HOST = 0,
6406  COMPILATION_TYPE_EVAL = 1
6407  };
6408 
6409  // Script compilation state.
6411  COMPILATION_STATE_INITIAL = 0,
6412  COMPILATION_STATE_COMPILED = 1
6413  };
6414 
6415  // [source]: the script source.
6416  DECL_ACCESSORS(source, Object)
6417 
6418  // [name]: the script name.
6420 
6421  // [id]: the script id.
6422  DECL_ACCESSORS(id, Smi)
6423 
6424  // [line_offset]: script line offset in resource from where it was extracted.
6425  DECL_ACCESSORS(line_offset, Smi)
6426 
6427  // [column_offset]: script column offset in resource from where it was
6428  // extracted.
6429  DECL_ACCESSORS(column_offset, Smi)
6430 
6431  // [context_data]: context data for the context this script was compiled in.
6432  DECL_ACCESSORS(context_data, Object)
6433 
6434  // [wrapper]: the wrapper cache.
6435  DECL_ACCESSORS(wrapper, Foreign)
6436 
6437  // [type]: the script type.
6438  DECL_ACCESSORS(type, Smi)
6439 
6440  // [line_ends]: FixedArray of line ends positions.
6441  DECL_ACCESSORS(line_ends, Object)
6442 
6443  // [eval_from_shared]: for eval scripts the shared funcion info for the
6444  // function from which eval was called.
6445  DECL_ACCESSORS(eval_from_shared, Object)
6446 
6447  // [eval_from_instructions_offset]: the instruction offset in the code for the
6448  // function from which eval was called where eval was called.
6449  DECL_ACCESSORS(eval_from_instructions_offset, Smi)
6450 
6451  // [flags]: Holds an exciting bitfield.
6453 
6454  // [source_url]: sourceURL from magic comment
6455  DECL_ACCESSORS(source_url, Object)
6456 
6457  // [source_url]: sourceMappingURL magic comment
6458  DECL_ACCESSORS(source_mapping_url, Object)
6459 
6460  // [compilation_type]: how the the script was compiled. Encoded in the
6461  // 'flags' field.
6462  inline CompilationType compilation_type();
6463  inline void set_compilation_type(CompilationType type);
6464 
6465  // [compilation_state]: determines whether the script has already been
6466  // compiled. Encoded in the 'flags' field.
6467  inline CompilationState compilation_state();
6468  inline void set_compilation_state(CompilationState state);
6469 
6470  // [is_shared_cross_origin]: An opaque boolean set by the embedder via
6471  // ScriptOrigin, and used by the embedder to make decisions about the
6472  // script's level of privilege. V8 just passes this through. Encoded in
6473  // the 'flags' field.
6474  DECL_BOOLEAN_ACCESSORS(is_shared_cross_origin)
6475 
6477 
6478  // If script source is an external string, check that the underlying
6479  // resource is accessible. Otherwise, always return true.
6480  inline bool HasValidSource();
6481 
6482  // Convert code position into column number.
6483  static int GetColumnNumber(Handle<Script> script, int code_pos);
6484 
6485  // Convert code position into (zero-based) line number.
6486  // The non-handlified version does not allocate, but may be much slower.
6487  static int GetLineNumber(Handle<Script> script, int code_pos);
6488  int GetLineNumber(int code_pos);
6489 
6490  static Handle<Object> GetNameOrSourceURL(Handle<Script> script);
6491 
6492  // Init line_ends array with code positions of line ends inside script source.
6493  static void InitLineEnds(Handle<Script> script);
6494 
6495  // Get the JS object wrapping the given script; create it if none exists.
6496  static Handle<JSObject> GetWrapper(Handle<Script> script);
6497  void ClearWrapperCache();
6498 
6499  // Dispatched behavior.
6502 
6503  static const int kSourceOffset = HeapObject::kHeaderSize;
6504  static const int kNameOffset = kSourceOffset + kPointerSize;
6505  static const int kLineOffsetOffset = kNameOffset + kPointerSize;
6506  static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
6507  static const int kContextOffset = kColumnOffsetOffset + kPointerSize;
6508  static const int kWrapperOffset = kContextOffset + kPointerSize;
6509  static const int kTypeOffset = kWrapperOffset + kPointerSize;
6510  static const int kLineEndsOffset = kTypeOffset + kPointerSize;
6511  static const int kIdOffset = kLineEndsOffset + kPointerSize;
6512  static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
6513  static const int kEvalFrominstructionsOffsetOffset =
6514  kEvalFromSharedOffset + kPointerSize;
6515  static const int kFlagsOffset =
6516  kEvalFrominstructionsOffsetOffset + kPointerSize;
6517  static const int kSourceUrlOffset = kFlagsOffset + kPointerSize;
6518  static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize;
6519  static const int kSize = kSourceMappingUrlOffset + kPointerSize;
6520 
6521  private:
6522  int GetLineNumberWithArray(int code_pos);
6523 
6524  // Bit positions in the flags field.
6525  static const int kCompilationTypeBit = 0;
6526  static const int kCompilationStateBit = 1;
6527  static const int kIsSharedCrossOriginBit = 2;
6528 
6530 };
6531 
6532 
6533 // List of builtin functions we want to identify to improve code
6534 // generation.
6535 //
6536 // Each entry has a name of a global object property holding an object
6537 // optionally followed by ".prototype", a name of a builtin function
6538 // on the object (the one the id is set for), and a label.
6539 //
6540 // Installation of ids for the selected builtin functions is handled
6541 // by the bootstrapper.
6542 #define FUNCTIONS_WITH_ID_LIST(V) \
6543  V(Array.prototype, indexOf, ArrayIndexOf) \
6544  V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \
6545  V(Array.prototype, push, ArrayPush) \
6546  V(Array.prototype, pop, ArrayPop) \
6547  V(Array.prototype, shift, ArrayShift) \
6548  V(Function.prototype, apply, FunctionApply) \
6549  V(String.prototype, charCodeAt, StringCharCodeAt) \
6550  V(String.prototype, charAt, StringCharAt) \
6551  V(String, fromCharCode, StringFromCharCode) \
6552  V(Math, floor, MathFloor) \
6553  V(Math, round, MathRound) \
6554  V(Math, ceil, MathCeil) \
6555  V(Math, abs, MathAbs) \
6556  V(Math, log, MathLog) \
6557  V(Math, exp, MathExp) \
6558  V(Math, sqrt, MathSqrt) \
6559  V(Math, pow, MathPow) \
6560  V(Math, max, MathMax) \
6561  V(Math, min, MathMin) \
6562  V(Math, imul, MathImul) \
6563  V(Math, clz32, MathClz32) \
6564  V(Math, fround, MathFround)
6565 
6568 #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
6569  k##name,
6571 #undef DECLARE_FUNCTION_ID
6572  // Fake id for a special case of Math.pow. Note, it continues the
6573  // list of math functions.
6574  kMathPowHalf
6575 };
6576 
6577 
6578 // SharedFunctionInfo describes the JSFunction information that can be
6579 // shared by multiple instances of the function.
6581  public:
6582  // [name]: Function name.
6584 
6585  // [code]: Function code.
6586  DECL_ACCESSORS(code, Code)
6587  inline void ReplaceCode(Code* code);
6588 
6589  // [optimized_code_map]: Map from native context to optimized code
6590  // and a shared literals array or Smi(0) if none.
6591  DECL_ACCESSORS(optimized_code_map, Object)
6592 
6593  // Returns index i of the entry with the specified context and OSR entry.
6594  // At position i - 1 is the context, position i the code, and i + 1 the
6595  // literals array. Returns -1 when no matching entry is found.
6596  int SearchOptimizedCodeMap(Context* native_context, BailoutId osr_ast_id);
6597 
6598  // Installs optimized code from the code map on the given closure. The
6599  // index has to be consistent with a search result as defined above.
6600  FixedArray* GetLiteralsFromOptimizedCodeMap(int index);
6601 
6602  Code* GetCodeFromOptimizedCodeMap(int index);
6603 
6604  // Clear optimized code map.
6605  void ClearOptimizedCodeMap();
6606 
6607  // Removed a specific optimized code object from the optimized code map.
6608  void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason);
6609 
6610  void ClearTypeFeedbackInfo();
6611 
6612  // Trims the optimized code map after entries have been removed.
6613  void TrimOptimizedCodeMap(int shrink_by);
6614 
6615  // Add a new entry to the optimized code map.
6616  static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
6617  Handle<Context> native_context,
6618  Handle<Code> code,
6620  BailoutId osr_ast_id);
6621 
6622  // Layout description of the optimized code map.
6623  static const int kNextMapIndex = 0;
6624  static const int kEntriesStart = 1;
6625  static const int kContextOffset = 0;
6626  static const int kCachedCodeOffset = 1;
6627  static const int kLiteralsOffset = 2;
6628  static const int kOsrAstIdOffset = 3;
6629  static const int kEntryLength = 4;
6630  static const int kInitialLength = kEntriesStart + kEntryLength;
6631 
6632  // [scope_info]: Scope info.
6633  DECL_ACCESSORS(scope_info, ScopeInfo)
6634 
6635  // [construct stub]: Code stub for constructing instances of this function.
6636  DECL_ACCESSORS(construct_stub, Code)
6637 
6638  // Returns if this function has been compiled to native code yet.
6639  inline bool is_compiled();
6640 
6641  // [length]: The function length - usually the number of declared parameters.
6642  // Use up to 2^30 parameters.
6643  inline int length() const;
6644  inline void set_length(int value);
6645 
6646  // [formal parameter count]: The declared number of parameters.
6647  inline int formal_parameter_count() const;
6649 
6650  // Set the formal parameter count so the function code will be
6651  // called without using argument adaptor frames.
6652  inline void DontAdaptArguments();
6653 
6654  // [expected_nof_properties]: Expected number of properties for the function.
6655  inline int expected_nof_properties() const;
6657 
6658  // [feedback_vector] - accumulates ast node feedback from full-codegen and
6659  // (increasingly) from crankshafted code where sufficient feedback isn't
6660  // available.
6662 
6663  // [instance class name]: class name for instances.
6664  DECL_ACCESSORS(instance_class_name, Object)
6665 
6666  // [function data]: This field holds some additional data for function.
6667  // Currently it either has FunctionTemplateInfo to make benefit the API
6668  // or Smi identifying a builtin function.
6669  // In the long run we don't want all functions to have this field but
6670  // we can fix that when we have a better model for storing hidden data
6671  // on objects.
6672  DECL_ACCESSORS(function_data, Object)
6673 
6674  inline bool IsApiFunction();
6675  inline FunctionTemplateInfo* get_api_func_data();
6676  inline bool HasBuiltinFunctionId();
6677  inline BuiltinFunctionId builtin_function_id();
6678 
6679  // [script info]: Script from which the function originates.
6680  DECL_ACCESSORS(script, Object)
6681 
6682  // [num_literals]: Number of literals used by this function.
6683  inline int num_literals() const;
6684  inline void set_num_literals(int value);
6685 
6686  // [start_position_and_type]: Field used to store both the source code
6687  // position, whether or not the function is a function expression,
6688  // and whether or not the function is a toplevel function. The two
6689  // least significants bit indicates whether the function is an
6690  // expression and the rest contains the source code position.
6691  inline int start_position_and_type() const;
6692  inline void set_start_position_and_type(int value);
6693 
6694  // [debug info]: Debug information.
6695  DECL_ACCESSORS(debug_info, Object)
6696 
6697  // [inferred name]: Name inferred from variable or property
6698  // assignment of this function. Used to facilitate debugging and
6699  // profiling of JavaScript code written in OO style, where almost
6700  // all functions are anonymous but are assigned to object
6701  // properties.
6702  DECL_ACCESSORS(inferred_name, String)
6703 
6704  // The function's name if it is non-empty, otherwise the inferred name.
6705  String* DebugName();
6706 
6707  // Position of the 'function' token in the script source.
6708  inline int function_token_position() const;
6709  inline void set_function_token_position(int function_token_position);
6710 
6711  // Position of this function in the script source.
6712  inline int start_position() const;
6713  inline void set_start_position(int start_position);
6714 
6715  // End position of this function in the script source.
6716  inline int end_position() const;
6717  inline void set_end_position(int end_position);
6718 
6719  // Is this function a function expression in the source code.
6720  DECL_BOOLEAN_ACCESSORS(is_expression)
6721 
6722  // Is this function a top-level function (scripts, evals).
6724 
6725  // Bit field containing various information collected by the compiler to
6726  // drive optimization.
6727  inline int compiler_hints() const;
6728  inline void set_compiler_hints(int value);
6729 
6730  inline int ast_node_count() const;
6731  inline void set_ast_node_count(int count);
6732 
6733  inline int profiler_ticks() const;
6734  inline void set_profiler_ticks(int ticks);
6735 
6736  // Inline cache age is used to infer whether the function survived a context
6737  // disposal or not. In the former case we reset the opt_count.
6738  inline int ic_age();
6739  inline void set_ic_age(int age);
6740 
6741  // Indicates if this function can be lazy compiled.
6742  // This is used to determine if we can safely flush code from a function
6743  // when doing GC if we expect that the function will no longer be used.
6744  DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
6745 
6746  // Indicates if this function can be lazy compiled without a context.
6747  // This is used to determine if we can force compilation without reaching
6748  // the function through program execution but through other means (e.g. heap
6749  // iteration by the debugger).
6751 
6752  // Indicates whether optimizations have been disabled for this
6753  // shared function info. If a function is repeatedly optimized or if
6754  // we cannot optimize the function we disable optimization to avoid
6755  // spending time attempting to optimize it again.
6756  DECL_BOOLEAN_ACCESSORS(optimization_disabled)
6757 
6758  // Indicates the language mode.
6759  inline StrictMode strict_mode();
6760  inline void set_strict_mode(StrictMode strict_mode);
6761 
6762  // False if the function definitely does not allocate an arguments object.
6763  DECL_BOOLEAN_ACCESSORS(uses_arguments)
6764 
6765  // True if the function has any duplicated parameter names.
6767 
6768  // Indicates whether the function is a native function.
6769  // These needs special treatment in .call and .apply since
6770  // null passed as the receiver should not be translated to the
6771  // global object.
6772  DECL_BOOLEAN_ACCESSORS(native)
6773 
6774  // Indicate that this builtin needs to be inlined in crankshaft.
6775  DECL_BOOLEAN_ACCESSORS(inline_builtin)
6776 
6777  // Indicates that the function was created by the Function function.
6778  // Though it's anonymous, toString should treat it as if it had the name
6779  // "anonymous". We don't set the name itself so that the system does not
6780  // see a binding for it.
6782 
6783  // Indicates whether the function is a bound function created using
6784  // the bind function.
6785  DECL_BOOLEAN_ACCESSORS(bound)
6786 
6787  // Indicates that the function is anonymous (the name field can be set
6788  // through the API, which does not change this flag).
6789  DECL_BOOLEAN_ACCESSORS(is_anonymous)
6790 
6791  // Is this a function or top-level/eval code.
6792  DECL_BOOLEAN_ACCESSORS(is_function)
6793 
6794  // Indicates that code for this function cannot be cached.
6795  DECL_BOOLEAN_ACCESSORS(dont_cache)
6796 
6797  // Indicates that code for this function cannot be flushed.
6798  DECL_BOOLEAN_ACCESSORS(dont_flush)
6799 
6800  // Indicates that this function is a generator.
6801  DECL_BOOLEAN_ACCESSORS(is_generator)
6802 
6803  // Indicates that this function is an arrow function.
6804  DECL_BOOLEAN_ACCESSORS(is_arrow)
6805 
6806  // Indicates that this function is a concise method.
6807  DECL_BOOLEAN_ACCESSORS(is_concise_method)
6808 
6809  // Indicates that this function is an asm function.
6810  DECL_BOOLEAN_ACCESSORS(asm_function)
6811 
6812  inline FunctionKind kind();
6813  inline void set_kind(FunctionKind kind);
6814 
6815  // Indicates whether or not the code in the shared function support
6816  // deoptimization.
6817  inline bool has_deoptimization_support();
6818 
6819  // Enable deoptimization support through recompiled code.
6820  void EnableDeoptimizationSupport(Code* recompiled);
6821 
6822  // Disable (further) attempted optimization of all functions sharing this
6823  // shared function info.
6824  void DisableOptimization(BailoutReason reason);
6825 
6826  inline BailoutReason DisableOptimizationReason();
6827 
6828  // Lookup the bailout ID and DCHECK that it exists in the non-optimized
6829  // code, returns whether it asserted (i.e., always true if assertions are
6830  // disabled).
6831  bool VerifyBailoutId(BailoutId id);
6832 
6833  // [source code]: Source code for the function.
6834  bool HasSourceCode() const;
6835  Handle<Object> GetSourceCode();
6836 
6837  // Number of times the function was optimized.
6838  inline int opt_count();
6839  inline void set_opt_count(int opt_count);
6840 
6841  // Number of times the function was deoptimized.
6842  inline void set_deopt_count(int value);
6843  inline int deopt_count();
6844  inline void increment_deopt_count();
6845 
6846  // Number of time we tried to re-enable optimization after it
6847  // was disabled due to high number of deoptimizations.
6848  inline void set_opt_reenable_tries(int value);
6849  inline int opt_reenable_tries();
6850 
6851  inline void TryReenableOptimization();
6852 
6853  // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
6854  inline void set_counters(int value);
6855  inline int counters() const;
6856 
6857  // Stores opt_count and bailout_reason as bit-fields.
6858  inline void set_opt_count_and_bailout_reason(int value);
6859  inline int opt_count_and_bailout_reason() const;
6860 
6861  void set_bailout_reason(BailoutReason reason) {
6862  set_opt_count_and_bailout_reason(
6863  DisabledOptimizationReasonBits::update(opt_count_and_bailout_reason(),
6864  reason));
6865  }
6866 
6867  // Check whether or not this function is inlineable.
6868  bool IsInlineable();
6869 
6870  // Source size of this function.
6871  int SourceSize();
6872 
6873  // Calculate the instance size.
6874  int CalculateInstanceSize();
6875 
6876  // Calculate the number of in-object properties.
6877  int CalculateInObjectProperties();
6878 
6879  // Dispatched behavior.
6882 
6883  void ResetForNewContext(int new_ic_age);
6884 
6886 
6887  // Constants.
6888  static const int kDontAdaptArgumentsSentinel = -1;
6889 
6890  // Layout description.
6891  // Pointer fields.
6892  static const int kNameOffset = HeapObject::kHeaderSize;
6893  static const int kCodeOffset = kNameOffset + kPointerSize;
6894  static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
6895  static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
6896  static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
6897  static const int kInstanceClassNameOffset =
6898  kConstructStubOffset + kPointerSize;
6899  static const int kFunctionDataOffset =
6900  kInstanceClassNameOffset + kPointerSize;
6901  static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
6902  static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
6903  static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
6904  static const int kFeedbackVectorOffset =
6905  kInferredNameOffset + kPointerSize;
6906 #if V8_HOST_ARCH_32_BIT
6907  // Smi fields.
6908  static const int kLengthOffset =
6909  kFeedbackVectorOffset + kPointerSize;
6910  static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
6911  static const int kExpectedNofPropertiesOffset =
6912  kFormalParameterCountOffset + kPointerSize;
6913  static const int kNumLiteralsOffset =
6914  kExpectedNofPropertiesOffset + kPointerSize;
6915  static const int kStartPositionAndTypeOffset =
6916  kNumLiteralsOffset + kPointerSize;
6917  static const int kEndPositionOffset =
6918  kStartPositionAndTypeOffset + kPointerSize;
6919  static const int kFunctionTokenPositionOffset =
6920  kEndPositionOffset + kPointerSize;
6921  static const int kCompilerHintsOffset =
6922  kFunctionTokenPositionOffset + kPointerSize;
6923  static const int kOptCountAndBailoutReasonOffset =
6924  kCompilerHintsOffset + kPointerSize;
6925  static const int kCountersOffset =
6926  kOptCountAndBailoutReasonOffset + kPointerSize;
6927  static const int kAstNodeCountOffset =
6928  kCountersOffset + kPointerSize;
6929  static const int kProfilerTicksOffset =
6930  kAstNodeCountOffset + kPointerSize;
6931 
6932  // Total size.
6933  static const int kSize = kProfilerTicksOffset + kPointerSize;
6934 #else
6935  // The only reason to use smi fields instead of int fields
6936  // is to allow iteration without maps decoding during
6937  // garbage collections.
6938  // To avoid wasting space on 64-bit architectures we use
6939  // the following trick: we group integer fields into pairs
6940  // First integer in each pair is shifted left by 1.
6941  // By doing this we guarantee that LSB of each kPointerSize aligned
6942  // word is not set and thus this word cannot be treated as pointer
6943  // to HeapObject during old space traversal.
6944  static const int kLengthOffset =
6945  kFeedbackVectorOffset + kPointerSize;
6946  static const int kFormalParameterCountOffset =
6947  kLengthOffset + kIntSize;
6948 
6949  static const int kExpectedNofPropertiesOffset =
6950  kFormalParameterCountOffset + kIntSize;
6951  static const int kNumLiteralsOffset =
6952  kExpectedNofPropertiesOffset + kIntSize;
6953 
6954  static const int kEndPositionOffset =
6955  kNumLiteralsOffset + kIntSize;
6956  static const int kStartPositionAndTypeOffset =
6957  kEndPositionOffset + kIntSize;
6958 
6959  static const int kFunctionTokenPositionOffset =
6960  kStartPositionAndTypeOffset + kIntSize;
6961  static const int kCompilerHintsOffset =
6962  kFunctionTokenPositionOffset + kIntSize;
6963 
6964  static const int kOptCountAndBailoutReasonOffset =
6965  kCompilerHintsOffset + kIntSize;
6966  static const int kCountersOffset =
6967  kOptCountAndBailoutReasonOffset + kIntSize;
6968 
6969  static const int kAstNodeCountOffset =
6970  kCountersOffset + kIntSize;
6971  static const int kProfilerTicksOffset =
6972  kAstNodeCountOffset + kIntSize;
6973 
6974  // Total size.
6975  static const int kSize = kProfilerTicksOffset + kIntSize;
6976 
6977 #endif
6978 
6979  static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
6980 
6981  typedef FixedBodyDescriptor<kNameOffset,
6982  kFeedbackVectorOffset + kPointerSize,
6984 
6985  // Bit positions in start_position_and_type.
6986  // The source code start position is in the 30 most significant bits of
6987  // the start_position_and_type field.
6988  static const int kIsExpressionBit = 0;
6989  static const int kIsTopLevelBit = 1;
6990  static const int kStartPositionShift = 2;
6991  static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
6992 
6993  // Bit positions in compiler_hints.
7013  kCompilerHintsCount // Pseudo entry
7014  };
7015 
7016  class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 3> {};
7017 
7018  class DeoptCountBits : public BitField<int, 0, 4> {};
7019  class OptReenableTriesBits : public BitField<int, 4, 18> {};
7020  class ICAgeBits : public BitField<int, 22, 8> {};
7021 
7022  class OptCountBits : public BitField<int, 0, 22> {};
7023  class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {};
7024 
7025  private:
7026 #if V8_HOST_ARCH_32_BIT
7027  // On 32 bit platforms, compiler hints is a smi.
7028  static const int kCompilerHintsSmiTagSize = kSmiTagSize;
7029  static const int kCompilerHintsSize = kPointerSize;
7030 #else
7031  // On 64 bit platforms, compiler hints is not a smi, see comment above.
7032  static const int kCompilerHintsSmiTagSize = 0;
7033  static const int kCompilerHintsSize = kIntSize;
7034 #endif
7035 
7038 
7039  public:
7040  // Constants for optimizing codegen for strict mode function and
7041  // native tests.
7042  // Allows to use byte-width instructions.
7043  static const int kStrictModeBitWithinByte =
7044  (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
7045 
7046  static const int kNativeBitWithinByte =
7047  (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
7048 
7049 #if defined(V8_TARGET_LITTLE_ENDIAN)
7050  static const int kStrictModeByteOffset = kCompilerHintsOffset +
7051  (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
7052  static const int kNativeByteOffset = kCompilerHintsOffset +
7053  (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
7054 #elif defined(V8_TARGET_BIG_ENDIAN)
7055  static const int kStrictModeByteOffset = kCompilerHintsOffset +
7056  (kCompilerHintsSize - 1) -
7057  ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
7058  static const int kNativeByteOffset = kCompilerHintsOffset +
7059  (kCompilerHintsSize - 1) -
7060  ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
7061 #else
7062 #error Unknown byte ordering
7063 #endif
7064 
7065  private:
7067 };
7068 
7069 
7070 // Printing support.
7072  explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1)
7073  : value(v), max_length(max) {}
7076 };
7077 
7078 
7079 OStream& operator<<(OStream& os, const SourceCodeOf& v);
7080 
7081 
7083  public:
7084  // [function]: The function corresponding to this generator object.
7085  DECL_ACCESSORS(function, JSFunction)
7086 
7087  // [context]: The context of the suspended computation.
7088  DECL_ACCESSORS(context, Context)
7089 
7090  // [receiver]: The receiver of the suspended computation.
7091  DECL_ACCESSORS(receiver, Object)
7092 
7093  // [continuation]: Offset into code of continuation.
7094  //
7095  // A positive offset indicates a suspended generator. The special
7096  // kGeneratorExecuting and kGeneratorClosed values indicate that a generator
7097  // cannot be resumed.
7098  inline int continuation() const;
7099  inline void set_continuation(int continuation);
7100  inline bool is_closed();
7101  inline bool is_executing();
7102  inline bool is_suspended();
7103 
7104  // [operand_stack]: Saved operand stack.
7105  DECL_ACCESSORS(operand_stack, FixedArray)
7106 
7107  // [stack_handler_index]: Index of first stack handler in operand_stack, or -1
7108  // if the captured activation had no stack handler.
7109  inline int stack_handler_index() const;
7110  inline void set_stack_handler_index(int stack_handler_index);
7111 
7113 
7114  // Dispatched behavior.
7117 
7118  // Magic sentinel values for the continuation.
7119  static const int kGeneratorExecuting = -1;
7120  static const int kGeneratorClosed = 0;
7121 
7122  // Layout description.
7123  static const int kFunctionOffset = JSObject::kHeaderSize;
7124  static const int kContextOffset = kFunctionOffset + kPointerSize;
7125  static const int kReceiverOffset = kContextOffset + kPointerSize;
7126  static const int kContinuationOffset = kReceiverOffset + kPointerSize;
7127  static const int kOperandStackOffset = kContinuationOffset + kPointerSize;
7128  static const int kStackHandlerIndexOffset =
7129  kOperandStackOffset + kPointerSize;
7130  static const int kSize = kStackHandlerIndexOffset + kPointerSize;
7131 
7132  // Resume mode, for use by runtime functions.
7133  enum ResumeMode { NEXT, THROW };
7134 
7135  // Yielding from a generator returns an object with the following inobject
7136  // properties. See Context::iterator_result_map() for the map.
7137  static const int kResultValuePropertyIndex = 0;
7138  static const int kResultDonePropertyIndex = 1;
7139  static const int kResultPropertyCount = 2;
7140 
7141  static const int kResultValuePropertyOffset = JSObject::kHeaderSize;
7142  static const int kResultDonePropertyOffset =
7143  kResultValuePropertyOffset + kPointerSize;
7144  static const int kResultSize = kResultDonePropertyOffset + kPointerSize;
7145 
7146  private:
7148 };
7149 
7150 
7151 // Representation for module instance objects.
7152 class JSModule: public JSObject {
7153  public:
7154  // [context]: the context holding the module's locals, or undefined if none.
7155  DECL_ACCESSORS(context, Object)
7156 
7157  // [scope_info]: Scope info.
7158  DECL_ACCESSORS(scope_info, ScopeInfo)
7159 
7161 
7162  // Dispatched behavior.
7165 
7166  // Layout description.
7167  static const int kContextOffset = JSObject::kHeaderSize;
7168  static const int kScopeInfoOffset = kContextOffset + kPointerSize;
7169  static const int kSize = kScopeInfoOffset + kPointerSize;
7170 
7171  private:
7173 };
7174 
7175 
7176 // JSFunction describes JavaScript functions.
7177 class JSFunction: public JSObject {
7178  public:
7179  // [prototype_or_initial_map]:
7180  DECL_ACCESSORS(prototype_or_initial_map, Object)
7181 
7182  // [shared]: The information about the function that
7183  // can be shared by instances.
7185 
7186  // [context]: The context for this function.
7187  inline Context* context();
7188  inline void set_context(Object* context);
7189  inline JSObject* global_proxy();
7190 
7191  // [code]: The generated code object for this function. Executed
7192  // when the function is invoked, e.g. foo() or new foo(). See
7193  // [[Call]] and [[Construct]] description in ECMA-262, section
7194  // 8.6.2, page 27.
7195  inline Code* code();
7196  inline void set_code(Code* code);
7197  inline void set_code_no_write_barrier(Code* code);
7198  inline void ReplaceCode(Code* code);
7199 
7200  // Tells whether this function is builtin.
7201  inline bool IsBuiltin();
7202 
7203  // Tells whether this function is defined in a native script.
7204  inline bool IsFromNativeScript();
7205 
7206  // Tells whether this function is defined in an extension script.
7207  inline bool IsFromExtensionScript();
7208 
7209  // Tells whether or not the function needs arguments adaption.
7210  inline bool NeedsArgumentsAdaption();
7211 
7212  // Tells whether or not this function has been optimized.
7213  inline bool IsOptimized();
7214 
7215  // Tells whether or not this function can be optimized.
7216  inline bool IsOptimizable();
7217 
7218  // Mark this function for lazy recompilation. The function will be
7219  // recompiled the next time it is executed.
7220  void MarkForOptimization();
7221  void MarkForConcurrentOptimization();
7222  void MarkInOptimizationQueue();
7223 
7224  // Tells whether or not the function is already marked for lazy
7225  // recompilation.
7226  inline bool IsMarkedForOptimization();
7227  inline bool IsMarkedForConcurrentOptimization();
7228 
7229  // Tells whether or not the function is on the concurrent recompilation queue.
7230  inline bool IsInOptimizationQueue();
7231 
7232  // Inobject slack tracking is the way to reclaim unused inobject space.
7233  //
7234  // The instance size is initially determined by adding some slack to
7235  // expected_nof_properties (to allow for a few extra properties added
7236  // after the constructor). There is no guarantee that the extra space
7237  // will not be wasted.
7238  //
7239  // Here is the algorithm to reclaim the unused inobject space:
7240  // - Detect the first constructor call for this JSFunction.
7241  // When it happens enter the "in progress" state: initialize construction
7242  // counter in the initial_map and set the |done_inobject_slack_tracking|
7243  // flag.
7244  // - While the tracking is in progress create objects filled with
7245  // one_pointer_filler_map instead of undefined_value. This way they can be
7246  // resized quickly and safely.
7247  // - Once enough (kGenerousAllocationCount) objects have been created
7248  // compute the 'slack' (traverse the map transition tree starting from the
7249  // initial_map and find the lowest value of unused_property_fields).
7250  // - Traverse the transition tree again and decrease the instance size
7251  // of every map. Existing objects will resize automatically (they are
7252  // filled with one_pointer_filler_map). All further allocations will
7253  // use the adjusted instance size.
7254  // - SharedFunctionInfo's expected_nof_properties left unmodified since
7255  // allocations made using different closures could actually create different
7256  // kind of objects (see prototype inheritance pattern).
7257  //
7258  // Important: inobject slack tracking is not attempted during the snapshot
7259  // creation.
7260 
7261  static const int kGenerousAllocationCount = Map::ConstructionCount::kMax;
7262  static const int kFinishSlackTracking = 1;
7263  static const int kNoSlackTracking = 0;
7264 
7265  // True if the initial_map is set and the object constructions countdown
7266  // counter is not zero.
7267  inline bool IsInobjectSlackTrackingInProgress();
7268 
7269  // Starts the tracking.
7270  // Initializes object constructions countdown counter in the initial map.
7271  // IsInobjectSlackTrackingInProgress is normally true after this call,
7272  // except when tracking have not been started (e.g. the map has no unused
7273  // properties or the snapshot is being built).
7274  void StartInobjectSlackTracking();
7275 
7276  // Completes the tracking.
7277  // IsInobjectSlackTrackingInProgress is false after this call.
7278  void CompleteInobjectSlackTracking();
7279 
7280  // [literals_or_bindings]: Fixed array holding either
7281  // the materialized literals or the bindings of a bound function.
7282  //
7283  // If the function contains object, regexp or array literals, the
7284  // literals array prefix contains the object, regexp, and array
7285  // function to be used when creating these literals. This is
7286  // necessary so that we do not dynamically lookup the object, regexp
7287  // or array functions. Performing a dynamic lookup, we might end up
7288  // using the functions from a new context that we should not have
7289  // access to.
7290  //
7291  // On bound functions, the array is a (copy-on-write) fixed-array containing
7292  // the function that was bound, bound this-value and any bound
7293  // arguments. Bound functions never contain literals.
7294  DECL_ACCESSORS(literals_or_bindings, FixedArray)
7295 
7296  inline FixedArray* literals();
7297  inline void set_literals(FixedArray* literals);
7298 
7299  inline FixedArray* function_bindings();
7300  inline void set_function_bindings(FixedArray* bindings);
7301 
7302  // The initial map for an object created by this constructor.
7303  inline Map* initial_map();
7304  static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
7305  Handle<Object> prototype);
7306  inline bool has_initial_map();
7307  static void EnsureHasInitialMap(Handle<JSFunction> function);
7308 
7309  // Get and set the prototype property on a JSFunction. If the
7310  // function has an initial map the prototype is set on the initial
7311  // map. Otherwise, the prototype is put in the initial map field
7312  // until an initial map is needed.
7313  inline bool has_prototype();
7314  inline bool has_instance_prototype();
7315  inline Object* prototype();
7316  inline Object* instance_prototype();
7317  static void SetPrototype(Handle<JSFunction> function,
7319  static void SetInstancePrototype(Handle<JSFunction> function,
7321 
7322  // Creates a new closure for the fucntion with the same bindings,
7323  // bound values, and prototype. An equivalent of spec operations
7324  // ``CloneMethod`` and ``CloneBoundFunction``.
7325  static Handle<JSFunction> CloneClosure(Handle<JSFunction> function);
7326 
7327  // After prototype is removed, it will not be created when accessed, and
7328  // [[Construct]] from this function will not be allowed.
7329  bool RemovePrototype();
7330  inline bool should_have_prototype();
7331 
7332  // Accessor for this function's initial map's [[class]]
7333  // property. This is primarily used by ECMA native functions. This
7334  // method sets the class_name field of this function's initial map
7335  // to a given value. It creates an initial map if this function does
7336  // not have one. Note that this method does not copy the initial map
7337  // if it has one already, but simply replaces it with the new value.
7338  // Instances created afterwards will have a map whose [[class]] is
7339  // set to 'value', but there is no guarantees on instances created
7340  // before.
7341  void SetInstanceClassName(String* name);
7342 
7343  // Returns if this function has been compiled to native code yet.
7344  inline bool is_compiled();
7345 
7346  // [next_function_link]: Links functions into various lists, e.g. the list
7347  // of optimized functions hanging off the native_context. The CodeFlusher
7348  // uses this link to chain together flushing candidates. Treated weakly
7349  // by the garbage collector.
7350  DECL_ACCESSORS(next_function_link, Object)
7351 
7352  // Prints the name of the function using PrintF.
7353  void PrintName(FILE* out = stdout);
7354 
7356 
7357  // Iterates the objects, including code objects indirectly referenced
7358  // through pointers to the first instruction in the code object.
7359  void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
7360 
7361  // Dispatched behavior.
7364 
7365  // Returns the number of allocated literals.
7366  inline int NumberOfLiterals();
7367 
7368  // Retrieve the native context from a function's literal array.
7369  static Context* NativeContextFromLiterals(FixedArray* literals);
7370 
7371  // Used for flags such as --hydrogen-filter.
7372  bool PassesFilter(const char* raw_filter);
7373 
7374  // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
7375  // kSize) is weak and has special handling during garbage collection.
7376  static const int kCodeEntryOffset = JSObject::kHeaderSize;
7377  static const int kPrototypeOrInitialMapOffset =
7378  kCodeEntryOffset + kPointerSize;
7379  static const int kSharedFunctionInfoOffset =
7380  kPrototypeOrInitialMapOffset + kPointerSize;
7381  static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
7382  static const int kLiteralsOffset = kContextOffset + kPointerSize;
7383  static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
7384  static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
7385  static const int kSize = kNextFunctionLinkOffset + kPointerSize;
7386 
7387  // Layout of the literals array.
7388  static const int kLiteralsPrefixSize = 1;
7389  static const int kLiteralNativeContextIndex = 0;
7390 
7391  // Layout of the bound-function binding array.
7392  static const int kBoundFunctionIndex = 0;
7393  static const int kBoundThisIndex = 1;
7394  static const int kBoundArgumentsStartIndex = 2;
7395 
7396  private:
7398 };
7399 
7400 
7401 // JSGlobalProxy's prototype must be a JSGlobalObject or null,
7402 // and the prototype is hidden. JSGlobalProxy always delegates
7403 // property accesses to its prototype if the prototype is not null.
7404 //
7405 // A JSGlobalProxy can be reinitialized which will preserve its identity.
7406 //
7407 // Accessing a JSGlobalProxy requires security check.
7408 
7409 class JSGlobalProxy : public JSObject {
7410  public:
7411  // [native_context]: the owner native context of this global proxy object.
7412  // It is null value if this object is not used by any context.
7413  DECL_ACCESSORS(native_context, Object)
7414 
7415  // [hash]: The hash code property (undefined if not initialized yet).
7416  DECL_ACCESSORS(hash, Object)
7417 
7419 
7420  inline bool IsDetachedFrom(GlobalObject* global) const;
7421 
7422  // Dispatched behavior.
7425 
7426  // Layout description.
7427  static const int kNativeContextOffset = JSObject::kHeaderSize;
7428  static const int kHashOffset = kNativeContextOffset + kPointerSize;
7429  static const int kSize = kHashOffset + kPointerSize;
7430 
7431  private:
7433 };
7434 
7435 
7436 // Forward declaration.
7437 class JSBuiltinsObject;
7438 
7439 // Common super class for JavaScript global objects and the special
7440 // builtins global objects.
7441 class GlobalObject: public JSObject {
7442  public:
7443  // [builtins]: the object holding the runtime routines written in JS.
7444  DECL_ACCESSORS(builtins, JSBuiltinsObject)
7445 
7446  // [native context]: the natives corresponding to this global object.
7447  DECL_ACCESSORS(native_context, Context)
7448 
7449  // [global context]: the most recent (i.e. innermost) global context.
7450  DECL_ACCESSORS(global_context, Context)
7451 
7452  // [global proxy]: the global proxy object of the context
7453  DECL_ACCESSORS(global_proxy, JSObject)
7454 
7456 
7457  // Layout description.
7458  static const int kBuiltinsOffset = JSObject::kHeaderSize;
7459  static const int kNativeContextOffset = kBuiltinsOffset + kPointerSize;
7460  static const int kGlobalContextOffset = kNativeContextOffset + kPointerSize;
7461  static const int kGlobalProxyOffset = kGlobalContextOffset + kPointerSize;
7462  static const int kHeaderSize = kGlobalProxyOffset + kPointerSize;
7463 
7464  private:
7466 };
7467 
7468 
7469 // JavaScript global object.
7471  public:
7473 
7474  // Ensure that the global object has a cell for the given property name.
7475  static Handle<PropertyCell> EnsurePropertyCell(Handle<JSGlobalObject> global,
7476  Handle<Name> name);
7477 
7478  inline bool IsDetached();
7479 
7480  // Dispatched behavior.
7483 
7484  // Layout description.
7485  static const int kSize = GlobalObject::kHeaderSize;
7486 
7487  private:
7489 };
7490 
7491 
7492 // Builtins global object which holds the runtime routines written in
7493 // JavaScript.
7495  public:
7496  // Accessors for the runtime routines written in JavaScript.
7497  inline Object* javascript_builtin(Builtins::JavaScript id);
7498  inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
7499 
7500  // Accessors for code of the runtime routines written in JavaScript.
7501  inline Code* javascript_builtin_code(Builtins::JavaScript id);
7502  inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
7503 
7505 
7506  // Dispatched behavior.
7509 
7510  // Layout description. The size of the builtins object includes
7511  // room for two pointers per runtime routine written in javascript
7512  // (function and code object).
7513  static const int kJSBuiltinsCount = Builtins::id_count;
7514  static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
7515  static const int kJSBuiltinsCodeOffset =
7516  GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
7517  static const int kSize =
7518  kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
7519 
7520  static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
7521  return kJSBuiltinsOffset + id * kPointerSize;
7522  }
7523 
7525  return kJSBuiltinsCodeOffset + id * kPointerSize;
7526  }
7527 
7528  private:
7530 };
7531 
7532 
7533 // Representation for JS Wrapper objects, String, Number, Boolean, etc.
7534 class JSValue: public JSObject {
7535  public:
7536  // [value]: the object being wrapped.
7538 
7540 
7541  // Dispatched behavior.
7544 
7545  // Layout description.
7546  static const int kValueOffset = JSObject::kHeaderSize;
7547  static const int kSize = kValueOffset + kPointerSize;
7548 
7549  private:
7551 };
7552 
7553 
7554 class DateCache;
7555 
7556 // Representation for JS date objects.
7557 class JSDate: public JSObject {
7558  public:
7559  // If one component is NaN, all of them are, indicating a NaN time value.
7560  // [value]: the time value.
7562  // [year]: caches year. Either undefined, smi, or NaN.
7563  DECL_ACCESSORS(year, Object)
7564  // [month]: caches month. Either undefined, smi, or NaN.
7565  DECL_ACCESSORS(month, Object)
7566  // [day]: caches day. Either undefined, smi, or NaN.
7567  DECL_ACCESSORS(day, Object)
7568  // [weekday]: caches day of week. Either undefined, smi, or NaN.
7569  DECL_ACCESSORS(weekday, Object)
7570  // [hour]: caches hours. Either undefined, smi, or NaN.
7571  DECL_ACCESSORS(hour, Object)
7572  // [min]: caches minutes. Either undefined, smi, or NaN.
7574  // [sec]: caches seconds. Either undefined, smi, or NaN.
7575  DECL_ACCESSORS(sec, Object)
7576  // [cache stamp]: sample of the date cache stamp at the
7577  // moment when chached fields were cached.
7578  DECL_ACCESSORS(cache_stamp, Object)
7579 
7581 
7582  // Returns the date field with the specified index.
7583  // See FieldIndex for the list of date fields.
7584  static Object* GetField(Object* date, Smi* index);
7585 
7586  void SetValue(Object* value, bool is_value_nan);
7587 
7588 
7589  // Dispatched behavior.
7592 
7593  // The order is important. It must be kept in sync with date macros
7594  // in macros.py.
7595  enum FieldIndex {
7605  kMillisecond = kFirstUncachedField,
7609  kYearUTC = kFirstUTCField,
7619  kTimezoneOffset
7620  };
7621 
7622  // Layout description.
7623  static const int kValueOffset = JSObject::kHeaderSize;
7624  static const int kYearOffset = kValueOffset + kPointerSize;
7625  static const int kMonthOffset = kYearOffset + kPointerSize;
7626  static const int kDayOffset = kMonthOffset + kPointerSize;
7627  static const int kWeekdayOffset = kDayOffset + kPointerSize;
7628  static const int kHourOffset = kWeekdayOffset + kPointerSize;
7629  static const int kMinOffset = kHourOffset + kPointerSize;
7630  static const int kSecOffset = kMinOffset + kPointerSize;
7631  static const int kCacheStampOffset = kSecOffset + kPointerSize;
7632  static const int kSize = kCacheStampOffset + kPointerSize;
7633 
7634  private:
7635  inline Object* DoGetField(FieldIndex index);
7636 
7637  Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
7638 
7639  // Computes and caches the cacheable fields of the date.
7640  inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache);
7641 
7642 
7644 };
7645 
7646 
7647 // Representation of message objects used for error reporting through
7648 // the API. The messages are formatted in JavaScript so this object is
7649 // a real JavaScript object. The information used for formatting the
7650 // error messages are not directly accessible from JavaScript to
7651 // prevent leaking information to user code called during error
7652 // formatting.
7653 class JSMessageObject: public JSObject {
7654  public:
7655  // [type]: the type of error message.
7656  DECL_ACCESSORS(type, String)
7657 
7658  // [arguments]: the arguments for formatting the error message.
7659  DECL_ACCESSORS(arguments, JSArray)
7660 
7661  // [script]: the script from which the error message originated.
7662  DECL_ACCESSORS(script, Object)
7663 
7664  // [stack_frames]: an array of stack frames for this error object.
7665  DECL_ACCESSORS(stack_frames, Object)
7666 
7667  // [start_position]: the start position in the script for the error message.
7668  inline int start_position() const;
7669  inline void set_start_position(int value);
7670 
7671  // [end_position]: the end position in the script for the error message.
7672  inline int end_position() const;
7673  inline void set_end_position(int value);
7674 
7676 
7677  // Dispatched behavior.
7680 
7681  // Layout description.
7682  static const int kTypeOffset = JSObject::kHeaderSize;
7683  static const int kArgumentsOffset = kTypeOffset + kPointerSize;
7684  static const int kScriptOffset = kArgumentsOffset + kPointerSize;
7685  static const int kStackFramesOffset = kScriptOffset + kPointerSize;
7686  static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
7687  static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
7688  static const int kSize = kEndPositionOffset + kPointerSize;
7689 
7690  typedef FixedBodyDescriptor<HeapObject::kMapOffset,
7691  kStackFramesOffset + kPointerSize,
7693 };
7694 
7695 
7696 // Regular expressions
7697 // The regular expression holds a single reference to a FixedArray in
7698 // the kDataOffset field.
7699 // The FixedArray contains the following data:
7700 // - tag : type of regexp implementation (not compiled yet, atom or irregexp)
7701 // - reference to the original source string
7702 // - reference to the original flag string
7703 // If it is an atom regexp
7704 // - a reference to a literal string to search for
7705 // If it is an irregexp regexp:
7706 // - a reference to code for Latin1 inputs (bytecode or compiled), or a smi
7707 // used for tracking the last usage (used for code flushing).
7708 // - a reference to code for UC16 inputs (bytecode or compiled), or a smi
7709 // used for tracking the last usage (used for code flushing)..
7710 // - max number of registers used by irregexp implementations.
7711 // - number of capture registers (output values) of the regexp.
7712 class JSRegExp: public JSObject {
7713  public:
7714  // Meaning of Type:
7715  // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
7716  // ATOM: A simple string to match against using an indexOf operation.
7717  // IRREGEXP: Compiled with Irregexp.
7718  // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
7719  enum Type { NOT_COMPILED, ATOM, IRREGEXP };
7720  enum Flag {
7721  NONE = 0,
7722  GLOBAL = 1,
7723  IGNORE_CASE = 2,
7724  MULTILINE = 4,
7725  STICKY = 8
7726  };
7727 
7728  class Flags {
7729  public:
7730  explicit Flags(uint32_t value) : value_(value) { }
7731  bool is_global() { return (value_ & GLOBAL) != 0; }
7732  bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
7733  bool is_multiline() { return (value_ & MULTILINE) != 0; }
7734  bool is_sticky() { return (value_ & STICKY) != 0; }
7735  uint32_t value() { return value_; }
7736  private:
7738  };
7739 
7740  DECL_ACCESSORS(data, Object)
7741 
7742  inline Type TypeTag();
7743  inline int CaptureCount();
7744  inline Flags GetFlags();
7745  inline String* Pattern();
7746  inline Object* DataAt(int index);
7747  // Set implementation data after the object has been prepared.
7748  inline void SetDataAt(int index, Object* value);
7749 
7750  static int code_index(bool is_latin1) {
7751  if (is_latin1) {
7752  return kIrregexpLatin1CodeIndex;
7753  } else {
7754  return kIrregexpUC16CodeIndex;
7755  }
7756  }
7757 
7758  static int saved_code_index(bool is_latin1) {
7759  if (is_latin1) {
7760  return kIrregexpLatin1CodeSavedIndex;
7761  } else {
7762  return kIrregexpUC16CodeSavedIndex;
7763  }
7764  }
7765 
7767 
7768  // Dispatched behavior.
7770 
7771  static const int kDataOffset = JSObject::kHeaderSize;
7772  static const int kSize = kDataOffset + kPointerSize;
7773 
7774  // Indices in the data array.
7775  static const int kTagIndex = 0;
7776  static const int kSourceIndex = kTagIndex + 1;
7777  static const int kFlagsIndex = kSourceIndex + 1;
7778  static const int kDataIndex = kFlagsIndex + 1;
7779  // The data fields are used in different ways depending on the
7780  // value of the tag.
7781  // Atom regexps (literal strings).
7782  static const int kAtomPatternIndex = kDataIndex;
7783 
7784  static const int kAtomDataSize = kAtomPatternIndex + 1;
7785 
7786  // Irregexp compiled code or bytecode for Latin1. If compilation
7787  // fails, this fields hold an exception object that should be
7788  // thrown if the regexp is used again.
7789  static const int kIrregexpLatin1CodeIndex = kDataIndex;
7790  // Irregexp compiled code or bytecode for UC16. If compilation
7791  // fails, this fields hold an exception object that should be
7792  // thrown if the regexp is used again.
7793  static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
7794 
7795  // Saved instance of Irregexp compiled code or bytecode for Latin1 that
7796  // is a potential candidate for flushing.
7797  static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2;
7798  // Saved instance of Irregexp compiled code or bytecode for UC16 that is
7799  // a potential candidate for flushing.
7800  static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
7801 
7802  // Maximal number of registers used by either Latin1 or UC16.
7803  // Only used to check that there is enough stack space
7804  static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
7805  // Number of captures in the compiled regexp.
7806  static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
7807 
7808  static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
7809 
7810  // Offsets directly into the data fixed array.
7811  static const int kDataTagOffset =
7812  FixedArray::kHeaderSize + kTagIndex * kPointerSize;
7813  static const int kDataOneByteCodeOffset =
7814  FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize;
7815  static const int kDataUC16CodeOffset =
7816  FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
7817  static const int kIrregexpCaptureCountOffset =
7818  FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
7819 
7820  // In-object fields.
7821  static const int kSourceFieldIndex = 0;
7822  static const int kGlobalFieldIndex = 1;
7823  static const int kIgnoreCaseFieldIndex = 2;
7824  static const int kMultilineFieldIndex = 3;
7825  static const int kLastIndexFieldIndex = 4;
7826  static const int kInObjectFieldCount = 5;
7827 
7828  // The uninitialized value for a regexp code object.
7829  static const int kUninitializedValue = -1;
7830 
7831  // The compilation error value for the regexp code object. The real error
7832  // object is in the saved code field.
7833  static const int kCompilationErrorValue = -2;
7834 
7835  // When we store the sweep generation at which we moved the code from the
7836  // code index to the saved code index we mask it of to be in the [0:255]
7837  // range.
7838  static const int kCodeAgeMask = 0xff;
7839 };
7840 
7841 
7843  public:
7844  static inline bool IsMatch(HashTableKey* key, Object* value) {
7845  return key->IsMatch(value);
7846  }
7847 
7848  static inline uint32_t Hash(HashTableKey* key) {
7849  return key->Hash();
7850  }
7851 
7852  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
7853  return key->HashForObject(object);
7854  }
7855 
7856  static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
7857 
7858  static const int kPrefixSize = 0;
7859  static const int kEntrySize = 2;
7860 };
7861 
7862 
7863 class CompilationCacheTable: public HashTable<CompilationCacheTable,
7864  CompilationCacheShape,
7865  HashTableKey*> {
7866  public:
7867  // Find cached value for a string key, otherwise return null.
7868  Handle<Object> Lookup(Handle<String> src, Handle<Context> context);
7869  Handle<Object> LookupEval(Handle<String> src, Handle<Context> context,
7870  StrictMode strict_mode, int scope_position);
7871  Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
7872  static Handle<CompilationCacheTable> Put(
7875  static Handle<CompilationCacheTable> PutEval(
7878  int scope_position);
7879  static Handle<CompilationCacheTable> PutRegExp(
7882  void Remove(Object* value);
7883 
7885 
7886  private:
7888 };
7889 
7890 
7891 class CodeCache: public Struct {
7892  public:
7893  DECL_ACCESSORS(default_cache, FixedArray)
7894  DECL_ACCESSORS(normal_type_cache, Object)
7895 
7896  // Add the code object to the cache.
7897  static void Update(
7899 
7900  // Lookup code object in the cache. Returns code object if found and undefined
7901  // if not.
7902  Object* Lookup(Name* name, Code::Flags flags);
7903 
7904  // Get the internal index of a code object in the cache. Returns -1 if the
7905  // code object is not in that cache. This index can be used to later call
7906  // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
7907  // RemoveByIndex.
7908  int GetIndex(Object* name, Code* code);
7909 
7910  // Remove an object from the cache with the provided internal index.
7911  void RemoveByIndex(Object* name, Code* code, int index);
7912 
7914 
7915  // Dispatched behavior.
7918 
7919  static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
7920  static const int kNormalTypeCacheOffset =
7921  kDefaultCacheOffset + kPointerSize;
7922  static const int kSize = kNormalTypeCacheOffset + kPointerSize;
7923 
7924  private:
7925  static void UpdateDefaultCache(
7926  Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
7927  static void UpdateNormalTypeCache(
7928  Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
7929  Object* LookupDefaultCache(Name* name, Code::Flags flags);
7930  Object* LookupNormalTypeCache(Name* name, Code::Flags flags);
7931 
7932  // Code cache layout of the default cache. Elements are alternating name and
7933  // code objects for non normal load/store/call IC's.
7934  static const int kCodeCacheEntrySize = 2;
7935  static const int kCodeCacheEntryNameOffset = 0;
7936  static const int kCodeCacheEntryCodeOffset = 1;
7937 
7939 };
7940 
7941 
7943  public:
7944  static inline bool IsMatch(HashTableKey* key, Object* value) {
7945  return key->IsMatch(value);
7946  }
7947 
7948  static inline uint32_t Hash(HashTableKey* key) {
7949  return key->Hash();
7950  }
7951 
7952  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
7953  return key->HashForObject(object);
7954  }
7955 
7956  static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
7957 
7958  static const int kPrefixSize = 0;
7959  static const int kEntrySize = 2;
7960 };
7961 
7962 
7963 class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
7964  CodeCacheHashTableShape,
7965  HashTableKey*> {
7966  public:
7967  Object* Lookup(Name* name, Code::Flags flags);
7968  static Handle<CodeCacheHashTable> Put(
7971  Handle<Code> code);
7972 
7973  int GetIndex(Name* name, Code::Flags flags);
7974  void RemoveByIndex(int index);
7975 
7977 
7978  // Initial size of the fixed array backing the hash table.
7979  static const int kInitialSize = 64;
7980 
7981  private:
7983 };
7984 
7985 
7987  public:
7988  DECL_ACCESSORS(cache, Object)
7989 
7990  static void Update(Handle<PolymorphicCodeCache> cache,
7991  MapHandleList* maps,
7993  Handle<Code> code);
7994 
7995 
7996  // Returns an undefined value if the entry is not found.
7998 
8000 
8001  // Dispatched behavior.
8004 
8005  static const int kCacheOffset = HeapObject::kHeaderSize;
8006  static const int kSize = kCacheOffset + kPointerSize;
8007 
8008  private:
8010 };
8011 
8012 
8016  HashTableKey*> {
8017  public:
8018  Object* Lookup(MapHandleList* maps, int code_kind);
8019 
8022  MapHandleList* maps,
8023  int code_kind,
8024  Handle<Code> code);
8025 
8027 
8028  static const int kInitialSize = 64;
8029  private:
8031 };
8032 
8033 
8034 class TypeFeedbackInfo: public Struct {
8035  public:
8036  inline int ic_total_count();
8037  inline void set_ic_total_count(int count);
8038 
8039  inline int ic_with_type_info_count();
8040  inline void change_ic_with_type_info_count(int delta);
8041 
8042  inline int ic_generic_count();
8043  inline void change_ic_generic_count(int delta);
8044 
8045  inline void initialize_storage();
8046 
8047  inline void change_own_type_change_checksum();
8048  inline int own_type_change_checksum();
8049 
8050  inline void set_inlined_type_change_checksum(int checksum);
8051  inline bool matches_inlined_type_change_checksum(int checksum);
8052 
8053 
8055 
8056  // Dispatched behavior.
8059 
8060  static const int kStorage1Offset = HeapObject::kHeaderSize;
8061  static const int kStorage2Offset = kStorage1Offset + kPointerSize;
8062  static const int kStorage3Offset = kStorage2Offset + kPointerSize;
8063  static const int kSize = kStorage3Offset + kPointerSize;
8064 
8065  private:
8066  static const int kTypeChangeChecksumBits = 7;
8067 
8068  class ICTotalCountField: public BitField<int, 0,
8069  kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
8070  class OwnTypeChangeChecksum: public BitField<int,
8071  kSmiValueSize - kTypeChangeChecksumBits,
8072  kTypeChangeChecksumBits> {}; // NOLINT
8073  class ICsWithTypeInfoCountField: public BitField<int, 0,
8074  kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
8076  kSmiValueSize - kTypeChangeChecksumBits,
8077  kTypeChangeChecksumBits> {}; // NOLINT
8078 
8080 };
8081 
8082 
8087 };
8088 
8089 
8090 class AllocationSite: public Struct {
8091  public:
8092  static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024;
8093  static const double kPretenureRatio;
8094  static const int kPretenureMinimumCreated = 100;
8095 
8096  // Values for pretenure decision field.
8098  kUndecided = 0,
8099  kDontTenure = 1,
8100  kMaybeTenure = 2,
8101  kTenure = 3,
8102  kZombie = 4,
8103  kLastPretenureDecisionValue = kZombie
8104  };
8105 
8106  const char* PretenureDecisionName(PretenureDecision decision);
8107 
8108  DECL_ACCESSORS(transition_info, Object)
8109  // nested_site threads a list of sites that represent nested literals
8110  // walked in a particular order. So [[1, 2], 1, 2] will have one
8111  // nested_site, but [[1, 2], 3, [4]] will have a list of two.
8112  DECL_ACCESSORS(nested_site, Object)
8113  DECL_ACCESSORS(pretenure_data, Smi)
8114  DECL_ACCESSORS(pretenure_create_count, Smi)
8116  DECL_ACCESSORS(weak_next, Object)
8117 
8118  inline void Initialize();
8119 
8120  // This method is expensive, it should only be called for reporting.
8121  bool IsNestedSite();
8122 
8123  // transition_info bitfields, for constructed array transition info.
8124  class ElementsKindBits: public BitField<ElementsKind, 0, 15> {};
8125  class UnusedBits: public BitField<int, 15, 14> {};
8126  class DoNotInlineBit: public BitField<bool, 29, 1> {};
8127 
8128  // Bitfields for pretenure_data
8129  class MementoFoundCountBits: public BitField<int, 0, 26> {};
8130  class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {};
8131  class DeoptDependentCodeBit: public BitField<bool, 29, 1> {};
8132  STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
8133 
8134  // Increments the mementos found counter and returns true when the first
8135  // memento was found for a given allocation site.
8136  inline bool IncrementMementoFoundCount();
8137 
8138  inline void IncrementMementoCreateCount();
8139 
8140  PretenureFlag GetPretenureMode();
8141 
8142  void ResetPretenureDecision();
8143 
8145  int value = pretenure_data()->value();
8146  return PretenureDecisionBits::decode(value);
8147  }
8148 
8150  int value = pretenure_data()->value();
8151  set_pretenure_data(
8152  Smi::FromInt(PretenureDecisionBits::update(value, decision)),
8154  }
8155 
8157  int value = pretenure_data()->value();
8158  return DeoptDependentCodeBit::decode(value);
8159  }
8160 
8161  void set_deopt_dependent_code(bool deopt) {
8162  int value = pretenure_data()->value();
8163  set_pretenure_data(
8164  Smi::FromInt(DeoptDependentCodeBit::update(value, deopt)),
8166  }
8167 
8169  int value = pretenure_data()->value();
8170  return MementoFoundCountBits::decode(value);
8171  }
8172 
8173  inline void set_memento_found_count(int count);
8174 
8176  return pretenure_create_count()->value();
8177  }
8178 
8179  void set_memento_create_count(int count) {
8180  set_pretenure_create_count(Smi::FromInt(count), SKIP_WRITE_BARRIER);
8181  }
8182 
8183  // The pretenuring decision is made during gc, and the zombie state allows
8184  // us to recognize when an allocation site is just being kept alive because
8185  // a later traversal of new space may discover AllocationMementos that point
8186  // to this AllocationSite.
8187  bool IsZombie() {
8188  return pretenure_decision() == kZombie;
8189  }
8190 
8191  bool IsMaybeTenure() {
8192  return pretenure_decision() == kMaybeTenure;
8193  }
8194 
8195  inline void MarkZombie();
8196 
8197  inline bool MakePretenureDecision(PretenureDecision current_decision,
8198  double ratio,
8199  bool maximum_size_scavenge);
8200 
8201  inline bool DigestPretenuringFeedback(bool maximum_size_scavenge);
8202 
8204  DCHECK(!SitePointsToLiteral());
8205  int value = Smi::cast(transition_info())->value();
8206  return ElementsKindBits::decode(value);
8207  }
8208 
8210  int value = Smi::cast(transition_info())->value();
8211  set_transition_info(Smi::FromInt(ElementsKindBits::update(value, kind)),
8213  }
8214 
8215  bool CanInlineCall() {
8216  int value = Smi::cast(transition_info())->value();
8217  return DoNotInlineBit::decode(value) == 0;
8218  }
8219 
8221  int value = Smi::cast(transition_info())->value();
8222  set_transition_info(Smi::FromInt(DoNotInlineBit::update(value, true)),
8224  }
8225 
8227  // If transition_info is a smi, then it represents an ElementsKind
8228  // for a constructed array. Otherwise, it must be a boilerplate
8229  // for an object or array literal.
8230  return transition_info()->IsJSArray() || transition_info()->IsJSObject();
8231  }
8232 
8233  static void DigestTransitionFeedback(Handle<AllocationSite> site,
8234  ElementsKind to_kind);
8235 
8236  enum Reason {
8238  TRANSITIONS
8239  };
8240 
8241  static void AddDependentCompilationInfo(Handle<AllocationSite> site,
8242  Reason reason,
8243  CompilationInfo* info);
8244 
8247 
8249  static inline AllocationSiteMode GetMode(
8250  ElementsKind boilerplate_elements_kind);
8251  static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to);
8252  static inline bool CanTrack(InstanceType type);
8253 
8254  static const int kTransitionInfoOffset = HeapObject::kHeaderSize;
8255  static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize;
8256  static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize;
8257  static const int kPretenureCreateCountOffset =
8258  kPretenureDataOffset + kPointerSize;
8259  static const int kDependentCodeOffset =
8260  kPretenureCreateCountOffset + kPointerSize;
8261  static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize;
8262  static const int kSize = kWeakNextOffset + kPointerSize;
8263 
8264  // During mark compact we need to take special care for the dependent code
8265  // field.
8266  static const int kPointerFieldsBeginOffset = kTransitionInfoOffset;
8267  static const int kPointerFieldsEndOffset = kDependentCodeOffset;
8268 
8269  // For other visitors, use the fixed body descriptor below.
8271  kDependentCodeOffset + kPointerSize,
8273 
8274  private:
8275  inline DependentCode::DependencyGroup ToDependencyGroup(Reason reason);
8277  return pretenure_decision() != kUndecided;
8278  }
8279 
8281 };
8282 
8283 
8284 class AllocationMemento: public Struct {
8285  public:
8286  static const int kAllocationSiteOffset = HeapObject::kHeaderSize;
8287  static const int kSize = kAllocationSiteOffset + kPointerSize;
8288 
8289  DECL_ACCESSORS(allocation_site, Object)
8290 
8292  return allocation_site()->IsAllocationSite() &&
8293  !AllocationSite::cast(allocation_site())->IsZombie();
8294  }
8296  DCHECK(IsValid());
8297  return AllocationSite::cast(allocation_site());
8298  }
8299 
8302 
8304 
8305  private:
8307 };
8308 
8309 
8310 // Representation of a slow alias as part of a sloppy arguments objects.
8311 // For fast aliases (if HasSloppyArgumentsElements()):
8312 // - the parameter map contains an index into the context
8313 // - all attributes of the element have default values
8314 // For slow aliases (if HasDictionaryArgumentsElements()):
8315 // - the parameter map contains no fast alias mapping (i.e. the hole)
8316 // - this struct (in the slow backing store) contains an index into the context
8317 // - all attributes are available as part if the property details
8319  public:
8320  inline int aliased_context_slot() const;
8321  inline void set_aliased_context_slot(int count);
8322 
8324 
8325  // Dispatched behavior.
8328 
8329  static const int kAliasedContextSlot = HeapObject::kHeaderSize;
8330  static const int kSize = kAliasedContextSlot + kPointerSize;
8331 
8332  private:
8334 };
8335 
8336 
8339 
8340 
8342  public:
8343  explicit inline StringHasher(int length, uint32_t seed);
8344 
8345  template <typename schar>
8346  static inline uint32_t HashSequentialString(const schar* chars,
8347  int length,
8348  uint32_t seed);
8349 
8350  // Reads all the data, even for long strings and computes the utf16 length.
8351  static uint32_t ComputeUtf8Hash(Vector<const char> chars,
8352  uint32_t seed,
8353  int* utf16_length_out);
8354 
8355  // Calculated hash value for a string consisting of 1 to
8356  // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
8357  // value is represented decimal value.
8358  static uint32_t MakeArrayIndexHash(uint32_t value, int length);
8359 
8360  // No string is allowed to have a hash of zero. That value is reserved
8361  // for internal properties. If the hash calculation yields zero then we
8362  // use 27 instead.
8363  static const int kZeroHash = 27;
8364 
8365  // Reusable parts of the hashing algorithm.
8366  INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c));
8367  INLINE(static uint32_t GetHashCore(uint32_t running_hash));
8368 
8369  protected:
8370  // Returns the value to store in the hash field of a string with
8371  // the given length and contents.
8372  uint32_t GetHashField();
8373  // Returns true if the hash of this string can be computed without
8374  // looking at the contents.
8375  inline bool has_trivial_hash();
8376  // Adds a block of characters to the hash.
8377  template<typename Char>
8378  inline void AddCharacters(const Char* chars, int len);
8379 
8380  private:
8381  // Add a character to the hash.
8382  inline void AddCharacter(uint16_t c);
8383  // Update index. Returns true if string is still an index.
8384  inline bool UpdateIndex(uint16_t c);
8385 
8386  int length_;
8392 };
8393 
8394 
8396  public:
8397  static inline uint32_t Hash(String* string, uint32_t seed);
8398  inline void VisitOneByteString(const uint8_t* chars, int length);
8399  inline void VisitTwoByteString(const uint16_t* chars, int length);
8400 
8401  private:
8402  inline IteratingStringHasher(int len, uint32_t seed)
8403  : StringHasher(len, seed) {}
8405 };
8406 
8407 
8408 // The characteristics of a string are stored in its map. Retrieving these
8409 // few bits of information is moderately expensive, involving two memory
8410 // loads where the second is dependent on the first. To improve efficiency
8411 // the shape of the string is given its own class so that it can be retrieved
8412 // once and used for several string operations. A StringShape is small enough
8413 // to be passed by value and is immutable, but be aware that flattening a
8414 // string can potentially alter its shape. Also be aware that a GC caused by
8415 // something else can alter the shape of a string due to ConsString
8416 // shortcutting. Keeping these restrictions in mind has proven to be error-
8417 // prone and so we no longer put StringShapes in variables unless there is a
8418 // concrete performance benefit at that particular point in the code.
8419 class StringShape BASE_EMBEDDED {
8420  public:
8421  inline explicit StringShape(const String* s);
8422  inline explicit StringShape(Map* s);
8423  inline explicit StringShape(InstanceType t);
8424  inline bool IsSequential();
8425  inline bool IsExternal();
8426  inline bool IsCons();
8427  inline bool IsSliced();
8428  inline bool IsIndirect();
8429  inline bool IsExternalOneByte();
8430  inline bool IsExternalTwoByte();
8431  inline bool IsSequentialOneByte();
8432  inline bool IsSequentialTwoByte();
8433  inline bool IsInternalized();
8437  inline uint32_t size_tag();
8438 #ifdef DEBUG
8439  inline uint32_t type() { return type_; }
8440  inline void invalidate() { valid_ = false; }
8441  inline bool valid() { return valid_; }
8442 #else
8443  inline void invalidate() { }
8444 #endif
8445 
8446  private:
8448 #ifdef DEBUG
8449  inline void set_valid() { valid_ = true; }
8450  bool valid_;
8451 #else
8452  inline void set_valid() { }
8453 #endif
8454 };
8455 
8456 
8457 // The Name abstract class captures anything that can be used as a property
8458 // name, i.e., strings and symbols. All names store a hash value.
8459 class Name: public HeapObject {
8460  public:
8461  // Get and set the hash field of the name.
8462  inline uint32_t hash_field();
8463  inline void set_hash_field(uint32_t value);
8464 
8465  // Tells whether the hash code has been computed.
8466  inline bool HasHashCode();
8467 
8468  // Returns a hash value used for the property table
8469  inline uint32_t Hash();
8470 
8471  // Equality operations.
8472  inline bool Equals(Name* other);
8473  inline static bool Equals(Handle<Name> one, Handle<Name> two);
8474 
8475  // Conversion.
8476  inline bool AsArrayIndex(uint32_t* index);
8477 
8478  // Whether name can only name own properties.
8479  inline bool IsOwn();
8480 
8482 
8484 
8485  // Layout description.
8486  static const int kHashFieldOffset = HeapObject::kHeaderSize;
8487  static const int kSize = kHashFieldOffset + kPointerSize;
8488 
8489  // Mask constant for checking if a name has a computed hash code
8490  // and if it is a string that is an array index. The least significant bit
8491  // indicates whether a hash code has been computed. If the hash code has
8492  // been computed the 2nd bit tells whether the string can be used as an
8493  // array index.
8494  static const int kHashNotComputedMask = 1;
8495  static const int kIsNotArrayIndexMask = 1 << 1;
8496  static const int kNofHashBitFields = 2;
8497 
8498  // Shift constant retrieving hash code from hash field.
8499  static const int kHashShift = kNofHashBitFields;
8500 
8501  // Only these bits are relevant in the hash, since the top two are shifted
8502  // out.
8503  static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
8504 
8505  // Array index strings this short can keep their index in the hash field.
8506  static const int kMaxCachedArrayIndexLength = 7;
8507 
8508  // For strings which are array indexes the hash value has the string length
8509  // mixed into the hash, mainly to avoid a hash value of zero which would be
8510  // the case for the string '0'. 24 bits are used for the array index value.
8511  static const int kArrayIndexValueBits = 24;
8512  static const int kArrayIndexLengthBits =
8513  kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8514 
8515  STATIC_ASSERT((kArrayIndexLengthBits > 0));
8516 
8517  class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8518  kArrayIndexValueBits> {}; // NOLINT
8519  class ArrayIndexLengthBits : public BitField<unsigned int,
8520  kNofHashBitFields + kArrayIndexValueBits,
8521  kArrayIndexLengthBits> {}; // NOLINT
8522 
8523  // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8524  // could use a mask to test if the length of string is less than or equal to
8525  // kMaxCachedArrayIndexLength.
8526  STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8527 
8528  static const unsigned int kContainsCachedArrayIndexMask =
8529  (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8530  << ArrayIndexLengthBits::kShift) |
8531  kIsNotArrayIndexMask;
8532 
8533  // Value of empty hash field indicating that the hash is not computed.
8534  static const int kEmptyHashField =
8535  kIsNotArrayIndexMask | kHashNotComputedMask;
8536 
8537  protected:
8538  static inline bool IsHashFieldComputed(uint32_t field);
8539 
8540  private:
8542 };
8543 
8544 
8545 // ES6 symbols.
8546 class Symbol: public Name {
8547  public:
8548  // [name]: the print name of a symbol, or undefined if none.
8550 
8552 
8553  // [is_private]: whether this is a private symbol.
8554  DECL_BOOLEAN_ACCESSORS(is_private)
8555 
8556  // [is_own]: whether this is an own symbol, that is, only used to designate
8557  // own properties of objects.
8558  DECL_BOOLEAN_ACCESSORS(is_own)
8559 
8561 
8562  // Dispatched behavior.
8565 
8566  // Layout description.
8567  static const int kNameOffset = Name::kSize;
8568  static const int kFlagsOffset = kNameOffset + kPointerSize;
8569  static const int kSize = kFlagsOffset + kPointerSize;
8570 
8571  typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor;
8572 
8573  private:
8574  static const int kPrivateBit = 0;
8575  static const int kOwnBit = 1;
8576 
8578 };
8579 
8580 
8581 class ConsString;
8582 
8583 // The String abstract class captures JavaScript string values:
8584 //
8585 // Ecma-262:
8586 // 4.3.16 String Value
8587 // A string value is a member of the type String and is a finite
8588 // ordered sequence of zero or more 16-bit unsigned integer values.
8589 //
8590 // All string values have a length field.
8591 class String: public Name {
8592  public:
8593  enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING };
8594 
8595  // Array index strings this short can keep their index in the hash field.
8596  static const int kMaxCachedArrayIndexLength = 7;
8597 
8598  // For strings which are array indexes the hash value has the string length
8599  // mixed into the hash, mainly to avoid a hash value of zero which would be
8600  // the case for the string '0'. 24 bits are used for the array index value.
8601  static const int kArrayIndexValueBits = 24;
8602  static const int kArrayIndexLengthBits =
8603  kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8604 
8605  STATIC_ASSERT((kArrayIndexLengthBits > 0));
8606 
8607  class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8608  kArrayIndexValueBits> {}; // NOLINT
8609  class ArrayIndexLengthBits : public BitField<unsigned int,
8610  kNofHashBitFields + kArrayIndexValueBits,
8611  kArrayIndexLengthBits> {}; // NOLINT
8612 
8613  // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8614  // could use a mask to test if the length of string is less than or equal to
8615  // kMaxCachedArrayIndexLength.
8616  STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8617 
8618  static const unsigned int kContainsCachedArrayIndexMask =
8619  (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8620  << ArrayIndexLengthBits::kShift) |
8621  kIsNotArrayIndexMask;
8622 
8623  // Representation of the flat content of a String.
8624  // A non-flat string doesn't have flat content.
8625  // A flat string has content that's encoded as a sequence of either
8626  // one-byte chars or two-byte UC16.
8627  // Returned by String::GetFlatContent().
8628  class FlatContent {
8629  public:
8630  // Returns true if the string is flat and this structure contains content.
8631  bool IsFlat() { return state_ != NON_FLAT; }
8632  // Returns true if the structure contains one-byte content.
8633  bool IsOneByte() { return state_ == ONE_BYTE; }
8634  // Returns true if the structure contains two-byte content.
8635  bool IsTwoByte() { return state_ == TWO_BYTE; }
8636 
8637  // Return the one byte content of the string. Only use if IsOneByte()
8638  // returns true.
8640  DCHECK_EQ(ONE_BYTE, state_);
8641  return Vector<const uint8_t>(onebyte_start, length_);
8642  }
8643  // Return the two-byte content of the string. Only use if IsTwoByte()
8644  // returns true.
8646  DCHECK_EQ(TWO_BYTE, state_);
8647  return Vector<const uc16>(twobyte_start, length_);
8648  }
8649 
8650  uc16 Get(int i) {
8651  DCHECK(i < length_);
8652  DCHECK(state_ != NON_FLAT);
8653  if (state_ == ONE_BYTE) return onebyte_start[i];
8654  return twobyte_start[i];
8655  }
8656 
8657  private:
8658  enum State { NON_FLAT, ONE_BYTE, TWO_BYTE };
8659 
8660  // Constructors only used by String::GetFlatContent().
8661  explicit FlatContent(const uint8_t* start, int length)
8662  : onebyte_start(start), length_(length), state_(ONE_BYTE) {}
8663  explicit FlatContent(const uc16* start, int length)
8664  : twobyte_start(start), length_(length), state_(TWO_BYTE) { }
8665  FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { }
8666 
8667  union {
8668  const uint8_t* onebyte_start;
8670  };
8671  int length_;
8673 
8674  friend class String;
8675  };
8676 
8677  // Get and set the length of the string.
8678  inline int length() const;
8679  inline void set_length(int value);
8680 
8681  // Get and set the length of the string using acquire loads and release
8682  // stores.
8683  inline int synchronized_length() const;
8684  inline void synchronized_set_length(int value);
8685 
8686  // Returns whether this string has only one-byte chars, i.e. all of them can
8687  // be one-byte encoded. This might be the case even if the string is
8688  // two-byte. Such strings may appear when the embedder prefers
8689  // two-byte external representations even for one-byte data.
8690  inline bool IsOneByteRepresentation() const;
8691  inline bool IsTwoByteRepresentation() const;
8692 
8693  // Cons and slices have an encoding flag that may not represent the actual
8694  // encoding of the underlying string. This is taken into account here.
8695  // Requires: this->IsFlat()
8696  inline bool IsOneByteRepresentationUnderneath();
8697  inline bool IsTwoByteRepresentationUnderneath();
8698 
8699  // NOTE: this should be considered only a hint. False negatives are
8700  // possible.
8701  inline bool HasOnlyOneByteChars();
8702 
8703  // Get and set individual two byte chars in the string.
8704  inline void Set(int index, uint16_t value);
8705  // Get individual two byte char in the string. Repeated calls
8706  // to this method are not efficient unless the string is flat.
8707  INLINE(uint16_t Get(int index));
8708 
8709  // Flattens the string. Checks first inline to see if it is
8710  // necessary. Does nothing if the string is not a cons string.
8711  // Flattening allocates a sequential string with the same data as
8712  // the given string and mutates the cons string to a degenerate
8713  // form, where the first component is the new sequential string and
8714  // the second component is the empty string. If allocation fails,
8715  // this function returns a failure. If flattening succeeds, this
8716  // function returns the sequential string that is now the first
8717  // component of the cons string.
8718  //
8719  // Degenerate cons strings are handled specially by the garbage
8720  // collector (see IsShortcutCandidate).
8721 
8722  static inline Handle<String> Flatten(Handle<String> string,
8723  PretenureFlag pretenure = NOT_TENURED);
8724 
8725  // Tries to return the content of a flat string as a structure holding either
8726  // a flat vector of char or of uc16.
8727  // If the string isn't flat, and therefore doesn't have flat content, the
8728  // returned structure will report so, and can't provide a vector of either
8729  // kind.
8730  FlatContent GetFlatContent();
8731 
8732  // Returns the parent of a sliced string or first part of a flat cons string.
8733  // Requires: StringShape(this).IsIndirect() && this->IsFlat()
8734  inline String* GetUnderlying();
8735 
8736  // Mark the string as an undetectable object. It only applies to
8737  // one-byte and two-byte string types.
8738  bool MarkAsUndetectable();
8739 
8740  // String equality operations.
8741  inline bool Equals(String* other);
8742  inline static bool Equals(Handle<String> one, Handle<String> two);
8743  bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false);
8744  bool IsOneByteEqualTo(Vector<const uint8_t> str);
8745  bool IsTwoByteEqualTo(Vector<const uc16> str);
8746 
8747  // Return a UTF8 representation of the string. The string is null
8748  // terminated but may optionally contain nulls. Length is returned
8749  // in length_output if length_output is not a null pointer The string
8750  // should be nearly flat, otherwise the performance of this method may
8751  // be very slow (quadratic in the length). Setting robustness_flag to
8752  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8753  // handles unexpected data without causing assert failures and it does not
8754  // do any heap allocations. This is useful when printing stack traces.
8755  SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
8756  RobustnessFlag robustness_flag,
8757  int offset,
8758  int length,
8759  int* length_output = 0);
8760  SmartArrayPointer<char> ToCString(
8761  AllowNullsFlag allow_nulls = DISALLOW_NULLS,
8762  RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
8763  int* length_output = 0);
8764 
8765  // Return a 16 bit Unicode representation of the string.
8766  // The string should be nearly flat, otherwise the performance of
8767  // of this method may be very bad. Setting robustness_flag to
8768  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8769  // handles unexpected data without causing assert failures and it does not
8770  // do any heap allocations. This is useful when printing stack traces.
8771  SmartArrayPointer<uc16> ToWideCString(
8772  RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
8773 
8774  bool ComputeArrayIndex(uint32_t* index);
8775 
8776  // Externalization.
8777  bool MakeExternal(v8::String::ExternalStringResource* resource);
8778  bool MakeExternal(v8::String::ExternalOneByteStringResource* resource);
8779 
8780  // Conversion.
8781  inline bool AsArrayIndex(uint32_t* index);
8782 
8784 
8785  void PrintOn(FILE* out);
8786 
8787  // For use during stack traces. Performs rudimentary sanity check.
8788  bool LooksValid();
8789 
8790  // Dispatched behavior.
8791  void StringShortPrint(StringStream* accumulator);
8792  void PrintUC16(OStream& os, int start = 0, int end = -1); // NOLINT
8793 #ifdef OBJECT_PRINT
8794  char* ToAsciiArray();
8795 #endif
8798 
8799  inline bool IsFlat();
8800 
8801  // Layout description.
8802  static const int kLengthOffset = Name::kSize;
8803  static const int kSize = kLengthOffset + kPointerSize;
8804 
8805  // Maximum number of characters to consider when trying to convert a string
8806  // value into an array index.
8807  static const int kMaxArrayIndexSize = 10;
8808  STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
8809 
8810  // Max char codes.
8811  static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
8812  static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
8813  static const int kMaxUtf16CodeUnit = 0xffff;
8814  static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit;
8815 
8816  // Value of hash field containing computed hash equal to zero.
8817  static const int kEmptyStringHash = kIsNotArrayIndexMask;
8818 
8819  // Maximal string length.
8820  static const int kMaxLength = (1 << 28) - 16;
8821 
8822  // Max length for computing hash. For strings longer than this limit the
8823  // string length is used as the hash value.
8824  static const int kMaxHashCalcLength = 16383;
8825 
8826  // Limit for truncation in short printing.
8827  static const int kMaxShortPrintLength = 1024;
8828 
8829  // Support for regular expressions.
8830  const uc16* GetTwoByteData(unsigned start);
8831 
8832  // Helper function for flattening strings.
8833  template <typename sinkchar>
8834  static void WriteToFlat(String* source,
8835  sinkchar* sink,
8836  int from,
8837  int to);
8838 
8839  // The return value may point to the first aligned word containing the first
8840  // non-one-byte character, rather than directly to the non-one-byte character.
8841  // If the return value is >= the passed length, the entire string was
8842  // one-byte.
8843  static inline int NonAsciiStart(const char* chars, int length) {
8844  const char* start = chars;
8845  const char* limit = chars + length;
8846 
8847  if (length >= kIntptrSize) {
8848  // Check unaligned bytes.
8849  while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) {
8850  if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8851  return static_cast<int>(chars - start);
8852  }
8853  ++chars;
8854  }
8855  // Check aligned words.
8857  const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80;
8858  while (chars + sizeof(uintptr_t) <= limit) {
8859  if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) {
8860  return static_cast<int>(chars - start);
8861  }
8862  chars += sizeof(uintptr_t);
8863  }
8864  }
8865  // Check remaining unaligned bytes.
8866  while (chars < limit) {
8867  if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8868  return static_cast<int>(chars - start);
8869  }
8870  ++chars;
8871  }
8872 
8873  return static_cast<int>(chars - start);
8874  }
8875 
8876  static inline bool IsAscii(const char* chars, int length) {
8877  return NonAsciiStart(chars, length) >= length;
8878  }
8879 
8880  static inline bool IsAscii(const uint8_t* chars, int length) {
8881  return
8882  NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length;
8883  }
8884 
8885  static inline int NonOneByteStart(const uc16* chars, int length) {
8886  const uc16* limit = chars + length;
8887  const uc16* start = chars;
8888  while (chars < limit) {
8889  if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
8890  ++chars;
8891  }
8892  return static_cast<int>(chars - start);
8893  }
8894 
8895  static inline bool IsOneByte(const uc16* chars, int length) {
8896  return NonOneByteStart(chars, length) >= length;
8897  }
8898 
8899  template<class Visitor>
8900  static inline ConsString* VisitFlat(Visitor* visitor,
8901  String* string,
8902  int offset = 0);
8903 
8904  static Handle<FixedArray> CalculateLineEnds(Handle<String> string,
8905  bool include_ending_line);
8906 
8907  // Use the hash field to forward to the canonical internalized string
8908  // when deserializing an internalized string.
8909  inline void SetForwardedInternalizedString(String* string);
8910  inline String* GetForwardedInternalizedString();
8911 
8912  private:
8913  friend class Name;
8915 
8916  static Handle<String> SlowFlatten(Handle<ConsString> cons,
8917  PretenureFlag tenure);
8918 
8919  // Slow case of String::Equals. This implementation works on any strings
8920  // but it is most efficient on strings that are almost flat.
8921  bool SlowEquals(String* other);
8922 
8923  static bool SlowEquals(Handle<String> one, Handle<String> two);
8924 
8925  // Slow case of AsArrayIndex.
8926  bool SlowAsArrayIndex(uint32_t* index);
8927 
8928  // Compute and set the hash code.
8929  uint32_t ComputeAndSetHash();
8930 
8932 };
8933 
8934 
8935 // The SeqString abstract class captures sequential string values.
8936 class SeqString: public String {
8937  public:
8939 
8940  // Layout description.
8941  static const int kHeaderSize = String::kSize;
8942 
8943  // Truncate the string in-place if possible and return the result.
8944  // In case of new_length == 0, the empty string is returned without
8945  // truncating the original string.
8946  MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string,
8947  int new_length);
8948  private:
8950 };
8951 
8952 
8953 // The OneByteString class captures sequential one-byte string objects.
8954 // Each character in the OneByteString is an one-byte character.
8956  public:
8957  static const bool kHasOneByteEncoding = true;
8958 
8959  // Dispatched behavior.
8960  inline uint16_t SeqOneByteStringGet(int index);
8961  inline void SeqOneByteStringSet(int index, uint16_t value);
8962 
8963  // Get the address of the characters in this string.
8964  inline Address GetCharsAddress();
8965 
8966  inline uint8_t* GetChars();
8967 
8969 
8970  // Garbage collection support. This method is called by the
8971  // garbage collector to compute the actual size of an OneByteString
8972  // instance.
8973  inline int SeqOneByteStringSize(InstanceType instance_type);
8974 
8975  // Computes the size for an OneByteString instance of a given length.
8976  static int SizeFor(int length) {
8977  return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
8978  }
8979 
8980  // Maximal memory usage for a single sequential one-byte string.
8981  static const int kMaxSize = 512 * MB - 1;
8983 
8984  private:
8986 };
8987 
8988 
8989 // The TwoByteString class captures sequential unicode string objects.
8990 // Each character in the TwoByteString is a two-byte uint16_t.
8992  public:
8993  static const bool kHasOneByteEncoding = false;
8994 
8995  // Dispatched behavior.
8996  inline uint16_t SeqTwoByteStringGet(int index);
8997  inline void SeqTwoByteStringSet(int index, uint16_t value);
8998 
8999  // Get the address of the characters in this string.
9000  inline Address GetCharsAddress();
9001 
9002  inline uc16* GetChars();
9003 
9004  // For regexp code.
9005  const uint16_t* SeqTwoByteStringGetData(unsigned start);
9006 
9008 
9009  // Garbage collection support. This method is called by the
9010  // garbage collector to compute the actual size of a TwoByteString
9011  // instance.
9012  inline int SeqTwoByteStringSize(InstanceType instance_type);
9013 
9014  // Computes the size for a TwoByteString instance of a given length.
9015  static int SizeFor(int length) {
9016  return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
9017  }
9018 
9019  // Maximal memory usage for a single sequential two-byte string.
9020  static const int kMaxSize = 512 * MB - 1;
9021  STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >=
9023 
9024  private:
9026 };
9027 
9028 
9029 // The ConsString class describes string values built by using the
9030 // addition operator on strings. A ConsString is a pair where the
9031 // first and second components are pointers to other string values.
9032 // One or both components of a ConsString can be pointers to other
9033 // ConsStrings, creating a binary tree of ConsStrings where the leaves
9034 // are non-ConsString string values. The string value represented by
9035 // a ConsString can be obtained by concatenating the leaf string
9036 // values in a left-to-right depth-first traversal of the tree.
9037 class ConsString: public String {
9038  public:
9039  // First string of the cons cell.
9040  inline String* first();
9041  // Doesn't check that the result is a string, even in debug mode. This is
9042  // useful during GC where the mark bits confuse the checks.
9043  inline Object* unchecked_first();
9044  inline void set_first(String* first,
9046 
9047  // Second string of the cons cell.
9048  inline String* second();
9049  // Doesn't check that the result is a string, even in debug mode. This is
9050  // useful during GC where the mark bits confuse the checks.
9051  inline Object* unchecked_second();
9052  inline void set_second(String* second,
9054 
9055  // Dispatched behavior.
9056  uint16_t ConsStringGet(int index);
9057 
9059 
9060  // Layout description.
9061  static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
9062  static const int kSecondOffset = kFirstOffset + kPointerSize;
9063  static const int kSize = kSecondOffset + kPointerSize;
9064 
9065  // Minimum length for a cons string.
9066  static const int kMinLength = 13;
9067 
9068  typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
9070 
9072 
9073  private:
9075 };
9076 
9077 
9078 // The Sliced String class describes strings that are substrings of another
9079 // sequential string. The motivation is to save time and memory when creating
9080 // a substring. A Sliced String is described as a pointer to the parent,
9081 // the offset from the start of the parent string and the length. Using
9082 // a Sliced String therefore requires unpacking of the parent string and
9083 // adding the offset to the start address. A substring of a Sliced String
9084 // are not nested since the double indirection is simplified when creating
9085 // such a substring.
9086 // Currently missing features are:
9087 // - handling externalized parent strings
9088 // - external strings as parent
9089 // - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
9090 class SlicedString: public String {
9091  public:
9092  inline String* parent();
9093  inline void set_parent(String* parent,
9095  inline int offset() const;
9096  inline void set_offset(int offset);
9097 
9098  // Dispatched behavior.
9099  uint16_t SlicedStringGet(int index);
9100 
9102 
9103  // Layout description.
9104  static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
9105  static const int kOffsetOffset = kParentOffset + kPointerSize;
9106  static const int kSize = kOffsetOffset + kPointerSize;
9107 
9108  // Minimum length for a sliced string.
9109  static const int kMinLength = 13;
9110 
9111  typedef FixedBodyDescriptor<kParentOffset,
9112  kOffsetOffset + kPointerSize, kSize>
9114 
9116 
9117  private:
9119 };
9120 
9121 
9122 // The ExternalString class describes string values that are backed by
9123 // a string resource that lies outside the V8 heap. ExternalStrings
9124 // consist of the length field common to all strings, a pointer to the
9125 // external resource. It is important to ensure (externally) that the
9126 // resource is not deallocated while the ExternalString is live in the
9127 // V8 heap.
9128 //
9129 // The API expects that all ExternalStrings are created through the
9130 // API. Therefore, ExternalStrings should not be used internally.
9131 class ExternalString: public String {
9132  public:
9134 
9135  // Layout description.
9136  static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
9137  static const int kShortSize = kResourceOffset + kPointerSize;
9138  static const int kResourceDataOffset = kResourceOffset + kPointerSize;
9139  static const int kSize = kResourceDataOffset + kPointerSize;
9140 
9141  static const int kMaxShortLength =
9143 
9144  // Return whether external string is short (data pointer is not cached).
9145  inline bool is_short();
9146 
9147  STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset);
9148 
9149  private:
9151 };
9152 
9153 
9154 // The ExternalOneByteString class is an external string backed by an
9155 // one-byte string.
9157  public:
9158  static const bool kHasOneByteEncoding = true;
9159 
9161 
9162  // The underlying resource.
9163  inline const Resource* resource();
9164  inline void set_resource(const Resource* buffer);
9165 
9166  // Update the pointer cache to the external character array.
9167  // The cached pointer is always valid, as the external character array does =
9168  // not move during lifetime. Deserialization is the only exception, after
9169  // which the pointer cache has to be refreshed.
9170  inline void update_data_cache();
9171 
9172  inline const uint8_t* GetChars();
9173 
9174  // Dispatched behavior.
9175  inline uint16_t ExternalOneByteStringGet(int index);
9176 
9178 
9179  // Garbage collection support.
9180  inline void ExternalOneByteStringIterateBody(ObjectVisitor* v);
9181 
9182  template <typename StaticVisitor>
9183  inline void ExternalOneByteStringIterateBody();
9184 
9185  private:
9187 };
9188 
9189 
9190 // The ExternalTwoByteString class is an external string backed by a UTF-16
9191 // encoded string.
9193  public:
9194  static const bool kHasOneByteEncoding = false;
9195 
9197 
9198  // The underlying string resource.
9199  inline const Resource* resource();
9200  inline void set_resource(const Resource* buffer);
9201 
9202  // Update the pointer cache to the external character array.
9203  // The cached pointer is always valid, as the external character array does =
9204  // not move during lifetime. Deserialization is the only exception, after
9205  // which the pointer cache has to be refreshed.
9206  inline void update_data_cache();
9207 
9208  inline const uint16_t* GetChars();
9209 
9210  // Dispatched behavior.
9211  inline uint16_t ExternalTwoByteStringGet(int index);
9212 
9213  // For regexp code.
9214  inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
9215 
9217 
9218  // Garbage collection support.
9219  inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
9220 
9221  template<typename StaticVisitor>
9222  inline void ExternalTwoByteStringIterateBody();
9223 
9224  private:
9226 };
9227 
9228 
9229 // Utility superclass for stack-allocated objects that must be updated
9230 // on gc. It provides two ways for the gc to update instances, either
9231 // iterating or updating after gc.
9232 class Relocatable BASE_EMBEDDED {
9233  public:
9234  explicit inline Relocatable(Isolate* isolate);
9235  inline virtual ~Relocatable();
9236  virtual void IterateInstance(ObjectVisitor* v) { }
9237  virtual void PostGarbageCollection() { }
9238 
9241  static char* ArchiveState(Isolate* isolate, char* to);
9242  static char* RestoreState(Isolate* isolate, char* from);
9243  static void Iterate(Isolate* isolate, ObjectVisitor* v);
9244  static void Iterate(ObjectVisitor* v, Relocatable* top);
9245  static char* Iterate(ObjectVisitor* v, char* t);
9246 
9247  private:
9248  Isolate* isolate_;
9249  Relocatable* prev_;
9250 };
9251 
9252 
9253 // A flat string reader provides random access to the contents of a
9254 // string independent of the character width of the string. The handle
9255 // must be valid as long as the reader is being used.
9256 class FlatStringReader : public Relocatable {
9257  public:
9258  FlatStringReader(Isolate* isolate, Handle<String> str);
9259  FlatStringReader(Isolate* isolate, Vector<const char> input);
9260  void PostGarbageCollection();
9261  inline uc32 Get(int index);
9262  int length() { return length_; }
9263  private:
9266  int length_;
9267  const void* start_;
9268 };
9269 
9270 
9271 // A ConsStringOp that returns null.
9272 // Useful when the operation to apply on a ConsString
9273 // requires an expensive data structure.
9275  public:
9276  inline ConsStringNullOp() {}
9277  static inline String* Operate(String*, unsigned*, int32_t*, unsigned*);
9278  private:
9280 };
9281 
9282 
9283 // This maintains an off-stack representation of the stack frames required
9284 // to traverse a ConsString, allowing an entirely iterative and restartable
9285 // traversal of the entire string
9287  public:
9289  inline explicit ConsStringIteratorOp(ConsString* cons_string,
9290  int offset = 0) {
9291  Reset(cons_string, offset);
9292  }
9293  inline void Reset(ConsString* cons_string, int offset = 0) {
9294  depth_ = 0;
9295  // Next will always return NULL.
9296  if (cons_string == NULL) return;
9297  Initialize(cons_string, offset);
9298  }
9299  // Returns NULL when complete.
9300  inline String* Next(int* offset_out) {
9301  *offset_out = 0;
9302  if (depth_ == 0) return NULL;
9303  return Continue(offset_out);
9304  }
9305 
9306  private:
9307  static const int kStackSize = 32;
9308  // Use a mask instead of doing modulo operations for stack wrapping.
9309  static const int kDepthMask = kStackSize-1;
9311  static inline int OffsetForDepth(int depth);
9312 
9313  inline void PushLeft(ConsString* string);
9314  inline void PushRight(ConsString* string);
9315  inline void AdjustMaximumDepth();
9316  inline void Pop();
9317  inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; }
9318  void Initialize(ConsString* cons_string, int offset);
9319  String* Continue(int* offset_out);
9320  String* NextLeaf(bool* blew_stack);
9321  String* Search(int* offset_out);
9322 
9323  // Stack must always contain only frames for which right traversal
9324  // has not yet been performed.
9325  ConsString* frames_[kStackSize];
9327  int depth_;
9331 };
9332 
9333 
9335  public:
9336  inline StringCharacterStream(String* string,
9338  int offset = 0);
9339  inline uint16_t GetNext();
9340  inline bool HasMore();
9341  inline void Reset(String* string, int offset = 0);
9342  inline void VisitOneByteString(const uint8_t* chars, int length);
9343  inline void VisitTwoByteString(const uint16_t* chars, int length);
9344 
9345  private:
9347  union {
9348  const uint8_t* buffer8_;
9350  };
9351  const uint8_t* end_;
9354 };
9355 
9356 
9357 template <typename T>
9359  public:
9360  VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
9361  explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
9362  T GetNext() { return data_[index_++]; }
9363  bool has_more() { return index_ < data_.length(); }
9364  private:
9366  int index_;
9367 };
9368 
9369 
9370 // The Oddball describes objects null, undefined, true, and false.
9371 class Oddball: public HeapObject {
9372  public:
9373  // [to_string]: Cached to_string computed at startup.
9374  DECL_ACCESSORS(to_string, String)
9375 
9376  // [to_number]: Cached to_number computed at startup.
9377  DECL_ACCESSORS(to_number, Object)
9378 
9379  inline byte kind() const;
9380  inline void set_kind(byte kind);
9381 
9383 
9384  // Dispatched behavior.
9386 
9387  // Initialize the fields.
9388  static void Initialize(Isolate* isolate,
9389  Handle<Oddball> oddball,
9390  const char* to_string,
9391  Handle<Object> to_number,
9392  byte kind);
9393 
9394  // Layout description.
9395  static const int kToStringOffset = HeapObject::kHeaderSize;
9396  static const int kToNumberOffset = kToStringOffset + kPointerSize;
9397  static const int kKindOffset = kToNumberOffset + kPointerSize;
9398  static const int kSize = kKindOffset + kPointerSize;
9399 
9400  static const byte kFalse = 0;
9401  static const byte kTrue = 1;
9402  static const byte kNotBooleanMask = ~1;
9403  static const byte kTheHole = 2;
9404  static const byte kNull = 3;
9405  static const byte kArgumentMarker = 4;
9406  static const byte kUndefined = 5;
9407  static const byte kUninitialized = 6;
9408  static const byte kOther = 7;
9409  static const byte kException = 8;
9410 
9411  typedef FixedBodyDescriptor<kToStringOffset,
9412  kToNumberOffset + kPointerSize,
9414 
9418 
9419  private:
9421 };
9422 
9423 
9424 class Cell: public HeapObject {
9425  public:
9426  // [value]: value of the global property.
9428 
9430 
9431  static inline Cell* FromValueAddress(Address value) {
9432  Object* result = FromAddress(value - kValueOffset);
9433  DCHECK(result->IsCell() || result->IsPropertyCell());
9434  return static_cast<Cell*>(result);
9435  }
9436 
9438  return address() + kValueOffset;
9439  }
9440 
9441  // Dispatched behavior.
9444 
9445  // Layout description.
9446  static const int kValueOffset = HeapObject::kHeaderSize;
9447  static const int kSize = kValueOffset + kPointerSize;
9448 
9449  typedef FixedBodyDescriptor<kValueOffset,
9450  kValueOffset + kPointerSize,
9452 
9453  private:
9455 };
9456 
9457 
9458 class PropertyCell: public Cell {
9459  public:
9460  // [type]: type of the global property.
9461  HeapType* type();
9463 
9464  // [dependent_code]: dependent code that depends on the type of the global
9465  // property.
9467 
9468  // Sets the value of the cell and updates the type field to be the union
9469  // of the cell's current type and the value's type. If the change causes
9470  // a change of the type of the cell's contents, code dependent on the cell
9471  // will be deoptimized.
9472  static void SetValueInferType(Handle<PropertyCell> cell,
9474 
9475  // Computes the new type of the cell's contents for the given value, but
9476  // without actually modifying the 'type' field.
9477  static Handle<HeapType> UpdatedType(Handle<PropertyCell> cell,
9479 
9480  static void AddDependentCompilationInfo(Handle<PropertyCell> cell,
9481  CompilationInfo* info);
9482 
9484 
9485  inline Address TypeAddress() {
9486  return address() + kTypeOffset;
9487  }
9488 
9489  // Dispatched behavior.
9492 
9493  // Layout description.
9494  static const int kTypeOffset = kValueOffset + kPointerSize;
9495  static const int kDependentCodeOffset = kTypeOffset + kPointerSize;
9496  static const int kSize = kDependentCodeOffset + kPointerSize;
9497 
9498  static const int kPointerFieldsBeginOffset = kValueOffset;
9499  static const int kPointerFieldsEndOffset = kDependentCodeOffset;
9500 
9501  typedef FixedBodyDescriptor<kValueOffset,
9502  kSize,
9504 
9505  private:
9506  DECL_ACCESSORS(type_raw, Object)
9508 };
9509 
9510 
9511 // The JSProxy describes EcmaScript Harmony proxies
9512 class JSProxy: public JSReceiver {
9513  public:
9514  // [handler]: The handler property.
9515  DECL_ACCESSORS(handler, Object)
9516 
9517  // [hash]: The hash code property (undefined if not initialized yet).
9518  DECL_ACCESSORS(hash, Object)
9519 
9521 
9522  MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithHandler(
9523  Handle<JSProxy> proxy,
9524  Handle<Object> receiver,
9525  Handle<Name> name);
9526  MUST_USE_RESULT static inline MaybeHandle<Object> GetElementWithHandler(
9527  Handle<JSProxy> proxy,
9528  Handle<Object> receiver,
9529  uint32_t index);
9530 
9531  // If the handler defines an accessor property with a setter, invoke it.
9532  // If it defines an accessor property without a setter, or a data property
9533  // that is read-only, throw. In all these cases set '*done' to true,
9534  // otherwise set it to false.
9536  static MaybeHandle<Object> SetPropertyViaPrototypesWithHandler(
9538  Handle<Object> value, StrictMode strict_mode, bool* done);
9539 
9541  GetPropertyAttributesWithHandler(Handle<JSProxy> proxy,
9542  Handle<Object> receiver,
9543  Handle<Name> name);
9545  GetElementAttributeWithHandler(Handle<JSProxy> proxy,
9546  Handle<JSReceiver> receiver,
9547  uint32_t index);
9548  MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler(
9550  Handle<Object> value, StrictMode strict_mode);
9551 
9552  // Turn the proxy into an (empty) JSObject.
9553  static void Fix(Handle<JSProxy> proxy);
9554 
9555  // Initializes the body after the handler slot.
9556  inline void InitializeBody(int object_size, Object* value);
9557 
9558  // Invoke a trap by name. If the trap does not exist on this's handler,
9559  // but derived_trap is non-NULL, invoke that instead. May cause GC.
9560  MUST_USE_RESULT static MaybeHandle<Object> CallTrap(
9561  Handle<JSProxy> proxy,
9562  const char* name,
9563  Handle<Object> derived_trap,
9564  int argc,
9565  Handle<Object> args[]);
9566 
9567  // Dispatched behavior.
9570 
9571  // Layout description. We add padding so that a proxy has the same
9572  // size as a virgin JSObject. This is essential for becoming a JSObject
9573  // upon freeze.
9574  static const int kHandlerOffset = HeapObject::kHeaderSize;
9575  static const int kHashOffset = kHandlerOffset + kPointerSize;
9576  static const int kPaddingOffset = kHashOffset + kPointerSize;
9577  static const int kSize = JSObject::kHeaderSize;
9578  static const int kHeaderSize = kPaddingOffset;
9579  static const int kPaddingSize = kSize - kPaddingOffset;
9580 
9581  STATIC_ASSERT(kPaddingSize >= 0);
9582 
9583  typedef FixedBodyDescriptor<kHandlerOffset,
9584  kPaddingOffset,
9586 
9587  private:
9588  friend class JSReceiver;
9589 
9590  MUST_USE_RESULT static inline MaybeHandle<Object> SetElementWithHandler(
9591  Handle<JSProxy> proxy,
9592  Handle<JSReceiver> receiver,
9593  uint32_t index,
9594  Handle<Object> value,
9595  StrictMode strict_mode);
9596 
9597  MUST_USE_RESULT static Maybe<bool> HasPropertyWithHandler(
9598  Handle<JSProxy> proxy, Handle<Name> name);
9599  MUST_USE_RESULT static inline Maybe<bool> HasElementWithHandler(
9600  Handle<JSProxy> proxy, uint32_t index);
9601 
9602  MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithHandler(
9603  Handle<JSProxy> proxy,
9604  Handle<Name> name,
9605  DeleteMode mode);
9606  MUST_USE_RESULT static MaybeHandle<Object> DeleteElementWithHandler(
9607  Handle<JSProxy> proxy,
9608  uint32_t index,
9609  DeleteMode mode);
9610 
9611  MUST_USE_RESULT Object* GetIdentityHash();
9612 
9613  static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
9614 
9616 };
9617 
9618 
9619 class JSFunctionProxy: public JSProxy {
9620  public:
9621  // [call_trap]: The call trap.
9622  DECL_ACCESSORS(call_trap, Object)
9623 
9624  // [construct_trap]: The construct trap.
9625  DECL_ACCESSORS(construct_trap, Object)
9626 
9628 
9629  // Dispatched behavior.
9632 
9633  // Layout description.
9634  static const int kCallTrapOffset = JSProxy::kPaddingOffset;
9635  static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
9636  static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
9637  static const int kSize = JSFunction::kSize;
9638  static const int kPaddingSize = kSize - kPaddingOffset;
9639 
9640  STATIC_ASSERT(kPaddingSize >= 0);
9641 
9642  typedef FixedBodyDescriptor<kHandlerOffset,
9643  kConstructTrapOffset + kPointerSize,
9645 
9646  private:
9648 };
9649 
9650 
9651 class JSCollection : public JSObject {
9652  public:
9653  // [table]: the backing hash table
9654  DECL_ACCESSORS(table, Object)
9655 
9656  static const int kTableOffset = JSObject::kHeaderSize;
9657  static const int kSize = kTableOffset + kPointerSize;
9658 
9659  private:
9661 };
9662 
9663 
9664 // The JSSet describes EcmaScript Harmony sets
9665 class JSSet : public JSCollection {
9666  public:
9668 
9669  // Dispatched behavior.
9672 
9673  private:
9675 };
9676 
9677 
9678 // The JSMap describes EcmaScript Harmony maps
9679 class JSMap : public JSCollection {
9680  public:
9682 
9683  // Dispatched behavior.
9686 
9687  private:
9689 };
9690 
9691 
9692 // OrderedHashTableIterator is an iterator that iterates over the keys and
9693 // values of an OrderedHashTable.
9694 //
9695 // The iterator has a reference to the underlying OrderedHashTable data,
9696 // [table], as well as the current [index] the iterator is at.
9697 //
9698 // When the OrderedHashTable is rehashed it adds a reference from the old table
9699 // to the new table as well as storing enough data about the changes so that the
9700 // iterator [index] can be adjusted accordingly.
9701 //
9702 // When the [Next] result from the iterator is requested, the iterator checks if
9703 // there is a newer table that it needs to transition to.
9704 template<class Derived, class TableType>
9706  public:
9707  // [table]: the backing hash table mapping keys to values.
9708  DECL_ACCESSORS(table, Object)
9709 
9710  // [index]: The index into the data table.
9711  DECL_ACCESSORS(index, Object)
9712 
9713  // [kind]: The kind of iteration this is. One of the [Kind] enum values.
9714  DECL_ACCESSORS(kind, Object)
9715 
9716 #ifdef OBJECT_PRINT
9717  void OrderedHashTableIteratorPrint(OStream& os); // NOLINT
9718 #endif
9719 
9720  static const int kTableOffset = JSObject::kHeaderSize;
9721  static const int kIndexOffset = kTableOffset + kPointerSize;
9722  static const int kKindOffset = kIndexOffset + kPointerSize;
9723  static const int kSize = kKindOffset + kPointerSize;
9724 
9725  enum Kind {
9726  kKindKeys = 1,
9727  kKindValues = 2,
9728  kKindEntries = 3
9729  };
9730 
9731  // Whether the iterator has more elements. This needs to be called before
9732  // calling |CurrentKey| and/or |CurrentValue|.
9733  bool HasMore();
9734 
9735  // Move the index forward one.
9736  void MoveNext() {
9737  set_index(Smi::FromInt(Smi::cast(index())->value() + 1));
9738  }
9739 
9740  // Populates the array with the next key and value and then moves the iterator
9741  // forward.
9742  // This returns the |kind| or 0 if the iterator is already at the end.
9743  Smi* Next(JSArray* value_array);
9744 
9745  // Returns the current key of the iterator. This should only be called when
9746  // |HasMore| returns true.
9747  inline Object* CurrentKey();
9748 
9749  private:
9750  // Transitions the iterator to the non obsolete backing store. This is a NOP
9751  // if the [table] is not obsolete.
9752  void Transition();
9753 
9755 };
9756 
9757 
9758 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator,
9759  OrderedHashSet> {
9760  public:
9761  // Dispatched behavior.
9764 
9766 
9767  // Called by |Next| to populate the array. This allows the subclasses to
9768  // populate the array differently.
9769  inline void PopulateValueArray(FixedArray* array);
9770 
9771  private:
9773 };
9774 
9775 
9776 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
9777  OrderedHashMap> {
9778  public:
9779  // Dispatched behavior.
9782 
9784 
9785  // Called by |Next| to populate the array. This allows the subclasses to
9786  // populate the array differently.
9787  inline void PopulateValueArray(FixedArray* array);
9788 
9789  private:
9790  // Returns the current value of the iterator. This should only be called when
9791  // |HasMore| returns true.
9792  inline Object* CurrentValue();
9793 
9795 };
9796 
9797 
9798 // Base class for both JSWeakMap and JSWeakSet
9800  public:
9801  // [table]: the backing hash table mapping keys to values.
9802  DECL_ACCESSORS(table, Object)
9803 
9804  // [next]: linked list of encountered weak maps during GC.
9805  DECL_ACCESSORS(next, Object)
9806 
9807  static const int kTableOffset = JSObject::kHeaderSize;
9808  static const int kNextOffset = kTableOffset + kPointerSize;
9809  static const int kSize = kNextOffset + kPointerSize;
9810 
9811  private:
9813 };
9814 
9815 
9816 // The JSWeakMap describes EcmaScript Harmony weak maps
9818  public:
9820 
9821  // Dispatched behavior.
9824 
9825  private:
9827 };
9828 
9829 
9830 // The JSWeakSet describes EcmaScript Harmony weak sets
9832  public:
9834 
9835  // Dispatched behavior.
9838 
9839  private:
9841 };
9842 
9843 
9844 class JSArrayBuffer: public JSObject {
9845  public:
9846  // [backing_store]: backing memory for this array
9847  DECL_ACCESSORS(backing_store, void)
9848 
9849  // [byte_length]: length in bytes
9850  DECL_ACCESSORS(byte_length, Object)
9851 
9852  // [flags]
9854 
9855  inline bool is_external();
9856  inline void set_is_external(bool value);
9857 
9858  inline bool should_be_freed();
9859  inline void set_should_be_freed(bool value);
9860 
9861  // [weak_next]: linked list of array buffers.
9862  DECL_ACCESSORS(weak_next, Object)
9863 
9864  // [weak_first_array]: weak linked list of views.
9865  DECL_ACCESSORS(weak_first_view, Object)
9866 
9868 
9869  // Neutering. Only neuters the buffer, not associated typed arrays.
9870  void Neuter();
9871 
9872  // Dispatched behavior.
9875 
9876  static const int kBackingStoreOffset = JSObject::kHeaderSize;
9877  static const int kByteLengthOffset = kBackingStoreOffset + kPointerSize;
9878  static const int kFlagOffset = kByteLengthOffset + kPointerSize;
9879  static const int kWeakNextOffset = kFlagOffset + kPointerSize;
9880  static const int kWeakFirstViewOffset = kWeakNextOffset + kPointerSize;
9881  static const int kSize = kWeakFirstViewOffset + kPointerSize;
9882 
9883  static const int kSizeWithInternalFields =
9884  kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize;
9885 
9886  private:
9887  // Bit position in a flag
9888  static const int kIsExternalBit = 0;
9889  static const int kShouldBeFreed = 1;
9890 
9892 };
9893 
9894 
9896  public:
9897  // [buffer]: ArrayBuffer that this typed array views.
9898  DECL_ACCESSORS(buffer, Object)
9899 
9900  // [byte_length]: offset of typed array in bytes.
9901  DECL_ACCESSORS(byte_offset, Object)
9902 
9903  // [byte_length]: length of typed array in bytes.
9904  DECL_ACCESSORS(byte_length, Object)
9905 
9906  // [weak_next]: linked list of typed arrays over the same array buffer.
9907  DECL_ACCESSORS(weak_next, Object)
9908 
9910 
9912 
9913  static const int kBufferOffset = JSObject::kHeaderSize;
9914  static const int kByteOffsetOffset = kBufferOffset + kPointerSize;
9915  static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize;
9916  static const int kWeakNextOffset = kByteLengthOffset + kPointerSize;
9917  static const int kViewSize = kWeakNextOffset + kPointerSize;
9918 
9919  protected:
9920  void NeuterView();
9921 
9922  private:
9924 };
9925 
9926 
9928  public:
9929  // [length]: length of typed array in elements.
9930  DECL_ACCESSORS(length, Object)
9931 
9932  // Neutering. Only neuters this typed array.
9933  void Neuter();
9934 
9936 
9937  ExternalArrayType type();
9938  size_t element_size();
9939 
9940  Handle<JSArrayBuffer> GetBuffer();
9941 
9942  // Dispatched behavior.
9945 
9946  static const int kLengthOffset = kViewSize + kPointerSize;
9947  static const int kSize = kLengthOffset + kPointerSize;
9948 
9949  static const int kSizeWithInternalFields =
9950  kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
9951 
9952  private:
9953  static Handle<JSArrayBuffer> MaterializeArrayBuffer(
9954  Handle<JSTypedArray> typed_array);
9955 
9957 };
9958 
9959 
9961  public:
9962  // Only neuters this DataView
9963  void Neuter();
9964 
9966 
9967  // Dispatched behavior.
9970 
9971  static const int kSize = kViewSize;
9972 
9973  static const int kSizeWithInternalFields =
9974  kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
9975 
9976  private:
9978 };
9979 
9980 
9981 // Foreign describes objects pointing from JavaScript to C structures.
9982 // Since they cannot contain references to JS HeapObjects they can be
9983 // placed in old_data_space.
9984 class Foreign: public HeapObject {
9985  public:
9986  // [address]: field containing the address.
9987  inline Address foreign_address();
9988  inline void set_foreign_address(Address value);
9989 
9991 
9992  // Dispatched behavior.
9993  inline void ForeignIterateBody(ObjectVisitor* v);
9994 
9995  template<typename StaticVisitor>
9996  inline void ForeignIterateBody();
9997 
9998  // Dispatched behavior.
10001 
10002  // Layout description.
10003 
10004  static const int kForeignAddressOffset = HeapObject::kHeaderSize;
10005  static const int kSize = kForeignAddressOffset + kPointerSize;
10006 
10007  STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset);
10008 
10009  private:
10011 };
10012 
10013 
10014 // The JSArray describes JavaScript Arrays
10015 // Such an array can be in one of two modes:
10016 // - fast, backing storage is a FixedArray and length <= elements.length();
10017 // Please note: push and pop can be used to grow and shrink the array.
10018 // - slow, backing storage is a HashTable with numbers as keys.
10019 class JSArray: public JSObject {
10020  public:
10021  // [length]: The length property.
10022  DECL_ACCESSORS(length, Object)
10023 
10024  // Overload the length setter to skip write barrier when the length
10025  // is set to a smi. This matches the set function on FixedArray.
10026  inline void set_length(Smi* length);
10027 
10028  static void JSArrayUpdateLengthFromIndex(Handle<JSArray> array,
10029  uint32_t index,
10031 
10032  static bool IsReadOnlyLengthDescriptor(Handle<Map> jsarray_map);
10033  static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index);
10034  static MaybeHandle<Object> ReadOnlyLengthError(Handle<JSArray> array);
10035 
10036  // Initialize the array with the given capacity. The function may
10037  // fail due to out-of-memory situations, but only if the requested
10038  // capacity is non-zero.
10039  static void Initialize(Handle<JSArray> array, int capacity, int length = 0);
10040 
10041  // Initializes the array to a certain length.
10042  inline bool AllowsSetElementsLength();
10043  // Can cause GC.
10044  MUST_USE_RESULT static MaybeHandle<Object> SetElementsLength(
10045  Handle<JSArray> array,
10046  Handle<Object> length);
10047 
10048  // Set the content of the array to the content of storage.
10049  static inline void SetContent(Handle<JSArray> array,
10050  Handle<FixedArrayBase> storage);
10051 
10053 
10054  // Ensures that the fixed array backing the JSArray has at
10055  // least the stated size.
10056  static inline void EnsureSize(Handle<JSArray> array,
10057  int minimum_size_of_backing_fixed_array);
10058 
10059  // Expand the fixed array backing of a fast-case JSArray to at least
10060  // the requested size.
10061  static void Expand(Handle<JSArray> array,
10062  int minimum_size_of_backing_fixed_array);
10063 
10064  // Dispatched behavior.
10067 
10068  // Number of element slots to pre-allocate for an empty array.
10069  static const int kPreallocatedArrayElements = 4;
10070 
10071  // Layout description.
10072  static const int kLengthOffset = JSObject::kHeaderSize;
10073  static const int kSize = kLengthOffset + kPointerSize;
10074 
10075  private:
10077 };
10078 
10079 
10081  Handle<Map> initial_map);
10082 
10083 
10084 // JSRegExpResult is just a JSArray with a specific initial map.
10085 // This initial map adds in-object properties for "index" and "input"
10086 // properties, as assigned by RegExp.prototype.exec, which allows
10087 // faster creation of RegExp exec results.
10088 // This class just holds constants used when creating the result.
10089 // After creation the result must be treated as a JSArray in all regards.
10090 class JSRegExpResult: public JSArray {
10091  public:
10092  // Offsets of object fields.
10093  static const int kIndexOffset = JSArray::kSize;
10094  static const int kInputOffset = kIndexOffset + kPointerSize;
10095  static const int kSize = kInputOffset + kPointerSize;
10096  // Indices of in-object properties.
10097  static const int kIndexIndex = 0;
10098  static const int kInputIndex = 1;
10099  private:
10101 };
10102 
10103 
10104 class AccessorInfo: public Struct {
10105  public:
10108  DECL_ACCESSORS(expected_receiver_type, Object)
10109 
10110  inline bool all_can_read();
10111  inline void set_all_can_read(bool value);
10112 
10113  inline bool all_can_write();
10114  inline void set_all_can_write(bool value);
10115 
10116  inline PropertyAttributes property_attributes();
10117  inline void set_property_attributes(PropertyAttributes attributes);
10118 
10119  // Checks whether the given receiver is compatible with this accessor.
10120  static bool IsCompatibleReceiverType(Isolate* isolate,
10121  Handle<AccessorInfo> info,
10122  Handle<HeapType> type);
10123  inline bool IsCompatibleReceiver(Object* receiver);
10124 
10126 
10127  // Dispatched behavior.
10129 
10130  // Append all descriptors to the array that are not already there.
10131  // Return number added.
10132  static int AppendUnique(Handle<Object> descriptors,
10133  Handle<FixedArray> array,
10134  int valid_descriptors);
10135 
10136  static const int kNameOffset = HeapObject::kHeaderSize;
10137  static const int kFlagOffset = kNameOffset + kPointerSize;
10138  static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
10139  static const int kSize = kExpectedReceiverTypeOffset + kPointerSize;
10140 
10141  private:
10142  inline bool HasExpectedReceiverType() {
10143  return expected_receiver_type()->IsFunctionTemplateInfo();
10144  }
10145  // Bit positions in flag.
10146  static const int kAllCanReadBit = 0;
10147  static const int kAllCanWriteBit = 1;
10148  class AttributesField: public BitField<PropertyAttributes, 2, 3> {};
10149 
10151 };
10152 
10153 
10162 };
10163 
10164 
10168  uint8_t size; // Must be in {1,2,4}.
10169 };
10170 
10171 
10174 };
10175 
10176 
10179  uint8_t bool_offset; // Must be in [0,7], used for kDescriptorBoolType.
10180 };
10181 
10182 
10185 };
10186 
10187 
10190 };
10191 
10192 
10195  union {
10196  struct BitmaskCompareDescriptor bitmask_compare_descriptor;
10197  struct PointerCompareDescriptor pointer_compare_descriptor;
10198  struct PrimitiveValueDescriptor primitive_value_descriptor;
10199  struct ObjectDerefenceDescriptor object_dereference_descriptor;
10200  struct PointerShiftDescriptor pointer_shift_descriptor;
10201  };
10202 };
10203 
10204 
10206 
10207 
10209  public:
10211  DeclaredAccessorDescriptor* descriptor);
10212  const DeclaredAccessorDescriptorData* Next();
10213  bool Complete() const { return length_ == offset_; }
10214  private:
10215  uint8_t* array_;
10216  const int length_;
10217  int offset_;
10219 };
10220 
10221 
10223  public:
10225 
10227 
10228  static Handle<DeclaredAccessorDescriptor> Create(
10229  Isolate* isolate,
10230  const DeclaredAccessorDescriptorData& data,
10232 
10233  // Dispatched behavior.
10236 
10237  static const int kSerializedDataOffset = HeapObject::kHeaderSize;
10238  static const int kSize = kSerializedDataOffset + kPointerSize;
10239 
10240  private:
10242 };
10243 
10244 
10246  public:
10248 
10250 
10251  // Dispatched behavior.
10254 
10255  static const int kDescriptorOffset = AccessorInfo::kSize;
10256  static const int kSize = kDescriptorOffset + kPointerSize;
10257 
10258  private:
10260 };
10261 
10262 
10263 // An accessor must have a getter, but can have no setter.
10264 //
10265 // When setting a property, V8 searches accessors in prototypes.
10266 // If an accessor was found and it does not have a setter,
10267 // the request is ignored.
10268 //
10269 // If the accessor in the prototype has the READ_ONLY property attribute, then
10270 // a new value is added to the derived object when the property is set.
10271 // This shadows the accessor in the prototype.
10273  public:
10274  DECL_ACCESSORS(getter, Object)
10275  DECL_ACCESSORS(setter, Object)
10276  DECL_ACCESSORS(data, Object)
10277 
10279 
10280  // Dispatched behavior.
10283 
10284  static const int kGetterOffset = AccessorInfo::kSize;
10285  static const int kSetterOffset = kGetterOffset + kPointerSize;
10286  static const int kDataOffset = kSetterOffset + kPointerSize;
10287  static const int kSize = kDataOffset + kPointerSize;
10288 
10289  inline void clear_setter();
10290 
10291  private:
10293 };
10294 
10295 
10296 // Support for JavaScript accessors: A pair of a getter and a setter. Each
10297 // accessor can either be
10298 // * a pointer to a JavaScript function or proxy: a real accessor
10299 // * undefined: considered an accessor by the spec, too, strangely enough
10300 // * the hole: an accessor which has not been set
10301 // * a pointer to a map: a transition used to ensure map sharing
10302 class AccessorPair: public Struct {
10303  public:
10304  DECL_ACCESSORS(getter, Object)
10305  DECL_ACCESSORS(setter, Object)
10306 
10308 
10309  static Handle<AccessorPair> Copy(Handle<AccessorPair> pair);
10310 
10312  return component == ACCESSOR_GETTER ? getter() : setter();
10313  }
10314 
10315  void set(AccessorComponent component, Object* value) {
10316  if (component == ACCESSOR_GETTER) {
10317  set_getter(value);
10318  } else {
10319  set_setter(value);
10320  }
10321  }
10322 
10323  // Note: Returns undefined instead in case of a hole.
10324  Object* GetComponent(AccessorComponent component);
10325 
10326  // Set both components, skipping arguments which are a JavaScript null.
10327  void SetComponents(Object* getter, Object* setter) {
10328  if (!getter->IsNull()) set_getter(getter);
10329  if (!setter->IsNull()) set_setter(setter);
10330  }
10331 
10333  return IsJSAccessor(getter()) || IsJSAccessor(setter());
10334  }
10335 
10336  // Dispatched behavior.
10339 
10340  static const int kGetterOffset = HeapObject::kHeaderSize;
10341  static const int kSetterOffset = kGetterOffset + kPointerSize;
10342  static const int kSize = kSetterOffset + kPointerSize;
10343 
10344  private:
10345  // Strangely enough, in addition to functions and harmony proxies, the spec
10346  // requires us to consider undefined as a kind of accessor, too:
10347  // var obj = {};
10348  // Object.defineProperty(obj, "foo", {get: undefined});
10349  // assertTrue("foo" in obj);
10350  bool IsJSAccessor(Object* obj) {
10351  return obj->IsSpecFunction() || obj->IsUndefined();
10352  }
10353 
10355 };
10356 
10357 
10358 class AccessCheckInfo: public Struct {
10359  public:
10360  DECL_ACCESSORS(named_callback, Object)
10361  DECL_ACCESSORS(indexed_callback, Object)
10362  DECL_ACCESSORS(data, Object)
10363 
10365 
10366  // Dispatched behavior.
10369 
10370  static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
10371  static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
10372  static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
10373  static const int kSize = kDataOffset + kPointerSize;
10374 
10375  private:
10377 };
10378 
10379 
10380 class InterceptorInfo: public Struct {
10381  public:
10382  DECL_ACCESSORS(getter, Object)
10383  DECL_ACCESSORS(setter, Object)
10384  DECL_ACCESSORS(query, Object)
10385  DECL_ACCESSORS(deleter, Object)
10386  DECL_ACCESSORS(enumerator, Object)
10387  DECL_ACCESSORS(data, Object)
10388 
10390 
10391  // Dispatched behavior.
10394 
10395  static const int kGetterOffset = HeapObject::kHeaderSize;
10396  static const int kSetterOffset = kGetterOffset + kPointerSize;
10397  static const int kQueryOffset = kSetterOffset + kPointerSize;
10398  static const int kDeleterOffset = kQueryOffset + kPointerSize;
10399  static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
10400  static const int kDataOffset = kEnumeratorOffset + kPointerSize;
10401  static const int kSize = kDataOffset + kPointerSize;
10402 
10403  private:
10405 };
10406 
10407 
10408 class CallHandlerInfo: public Struct {
10409  public:
10410  DECL_ACCESSORS(callback, Object)
10411  DECL_ACCESSORS(data, Object)
10412 
10414 
10415  // Dispatched behavior.
10418 
10419  static const int kCallbackOffset = HeapObject::kHeaderSize;
10420  static const int kDataOffset = kCallbackOffset + kPointerSize;
10421  static const int kSize = kDataOffset + kPointerSize;
10422 
10423  private:
10425 };
10426 
10427 
10428 class TemplateInfo: public Struct {
10429  public:
10430  DECL_ACCESSORS(tag, Object)
10431  DECL_ACCESSORS(property_list, Object)
10432  DECL_ACCESSORS(property_accessors, Object)
10433 
10435 
10436  static const int kTagOffset = HeapObject::kHeaderSize;
10437  static const int kPropertyListOffset = kTagOffset + kPointerSize;
10438  static const int kPropertyAccessorsOffset =
10439  kPropertyListOffset + kPointerSize;
10440  static const int kHeaderSize = kPropertyAccessorsOffset + kPointerSize;
10441 
10442  private:
10444 };
10445 
10446 
10448  public:
10449  DECL_ACCESSORS(serial_number, Object)
10450  DECL_ACCESSORS(call_code, Object)
10452  DECL_ACCESSORS(parent_template, Object)
10453  DECL_ACCESSORS(named_property_handler, Object)
10455  DECL_ACCESSORS(instance_template, Object)
10456  DECL_ACCESSORS(class_name, Object)
10457  DECL_ACCESSORS(signature, Object)
10459  DECL_ACCESSORS(access_check_info, Object)
10461 
10462  inline int length() const;
10463  inline void set_length(int value);
10464 
10465  // Following properties use flag bits.
10467  DECL_BOOLEAN_ACCESSORS(undetectable)
10468  // If the bit is set, object instances created by this function
10469  // requires access check.
10470  DECL_BOOLEAN_ACCESSORS(needs_access_check)
10472  DECL_BOOLEAN_ACCESSORS(remove_prototype)
10474 
10476 
10477  // Dispatched behavior.
10480 
10481  static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
10482  static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
10483  static const int kPrototypeTemplateOffset =
10484  kCallCodeOffset + kPointerSize;
10485  static const int kParentTemplateOffset =
10486  kPrototypeTemplateOffset + kPointerSize;
10487  static const int kNamedPropertyHandlerOffset =
10488  kParentTemplateOffset + kPointerSize;
10489  static const int kIndexedPropertyHandlerOffset =
10490  kNamedPropertyHandlerOffset + kPointerSize;
10491  static const int kInstanceTemplateOffset =
10492  kIndexedPropertyHandlerOffset + kPointerSize;
10493  static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
10494  static const int kSignatureOffset = kClassNameOffset + kPointerSize;
10495  static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
10496  static const int kAccessCheckInfoOffset =
10497  kInstanceCallHandlerOffset + kPointerSize;
10498  static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
10499  static const int kLengthOffset = kFlagOffset + kPointerSize;
10500  static const int kSize = kLengthOffset + kPointerSize;
10501 
10502  // Returns true if |object| is an instance of this function template.
10503  bool IsTemplateFor(Object* object);
10504  bool IsTemplateFor(Map* map);
10505 
10506  private:
10507  // Bit position in the flag, from least significant bit position.
10508  static const int kHiddenPrototypeBit = 0;
10509  static const int kUndetectableBit = 1;
10510  static const int kNeedsAccessCheckBit = 2;
10511  static const int kReadOnlyPrototypeBit = 3;
10512  static const int kRemovePrototypeBit = 4;
10513  static const int kDoNotCacheBit = 5;
10514 
10516 };
10517 
10518 
10520  public:
10521  DECL_ACCESSORS(constructor, Object)
10523 
10525 
10526  // Dispatched behavior.
10529 
10530  static const int kConstructorOffset = TemplateInfo::kHeaderSize;
10531  static const int kInternalFieldCountOffset =
10532  kConstructorOffset + kPointerSize;
10533  static const int kSize = kInternalFieldCountOffset + kPointerSize;
10534 };
10535 
10536 
10537 class SignatureInfo: public Struct {
10538  public:
10539  DECL_ACCESSORS(receiver, Object)
10540  DECL_ACCESSORS(args, Object)
10541 
10543 
10544  // Dispatched behavior.
10547 
10548  static const int kReceiverOffset = Struct::kHeaderSize;
10549  static const int kArgsOffset = kReceiverOffset + kPointerSize;
10550  static const int kSize = kArgsOffset + kPointerSize;
10551 
10552  private:
10554 };
10555 
10556 
10557 class TypeSwitchInfo: public Struct {
10558  public:
10559  DECL_ACCESSORS(types, Object)
10560 
10562 
10563  // Dispatched behavior.
10566 
10567  static const int kTypesOffset = Struct::kHeaderSize;
10568  static const int kSize = kTypesOffset + kPointerSize;
10569 };
10570 
10571 
10572 // The DebugInfo class holds additional information for a function being
10573 // debugged.
10574 class DebugInfo: public Struct {
10575  public:
10576  // The shared function info for the source being debugged.
10578  // Code object for the original code.
10579  DECL_ACCESSORS(original_code, Code)
10580  // Code object for the patched code. This code object is the code object
10581  // currently active for the function.
10582  DECL_ACCESSORS(code, Code)
10583  // Fixed array holding status information for each active break point.
10584  DECL_ACCESSORS(break_points, FixedArray)
10585 
10586  // Check if there is a break point at a code position.
10587  bool HasBreakPoint(int code_position);
10588  // Get the break point info object for a code position.
10589  Object* GetBreakPointInfo(int code_position);
10590  // Clear a break point.
10591  static void ClearBreakPoint(Handle<DebugInfo> debug_info,
10592  int code_position,
10593  Handle<Object> break_point_object);
10594  // Set a break point.
10595  static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
10596  int source_position, int statement_position,
10597  Handle<Object> break_point_object);
10598  // Get the break point objects for a code position.
10599  Object* GetBreakPointObjects(int code_position);
10600  // Find the break point info holding this break point object.
10601  static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
10602  Handle<Object> break_point_object);
10603  // Get the number of break points for this function.
10604  int GetBreakPointCount();
10605 
10607 
10608  // Dispatched behavior.
10611 
10612  static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
10613  static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
10614  static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
10615  static const int kActiveBreakPointsCountIndex =
10616  kPatchedCodeIndex + kPointerSize;
10617  static const int kBreakPointsStateIndex =
10618  kActiveBreakPointsCountIndex + kPointerSize;
10619  static const int kSize = kBreakPointsStateIndex + kPointerSize;
10620 
10621  static const int kEstimatedNofBreakPointsInFunction = 16;
10622 
10623  private:
10624  static const int kNoBreakPointInfo = -1;
10625 
10626  // Lookup the index in the break_points array for a code position.
10627  int GetBreakPointInfoIndex(int code_position);
10628 
10630 };
10631 
10632 
10633 // The BreakPointInfo class holds information for break points set in a
10634 // function. The DebugInfo object holds a BreakPointInfo object for each code
10635 // position with one or more break points.
10636 class BreakPointInfo: public Struct {
10637  public:
10638  // The position in the code for the break point.
10639  DECL_ACCESSORS(code_position, Smi)
10640  // The position in the source for the break position.
10641  DECL_ACCESSORS(source_position, Smi)
10642  // The position in the source for the last statement before this break
10643  // position.
10644  DECL_ACCESSORS(statement_position, Smi)
10645  // List of related JavaScript break points.
10646  DECL_ACCESSORS(break_point_objects, Object)
10647 
10648  // Removes a break point.
10649  static void ClearBreakPoint(Handle<BreakPointInfo> info,
10650  Handle<Object> break_point_object);
10651  // Set a break point.
10652  static void SetBreakPoint(Handle<BreakPointInfo> info,
10653  Handle<Object> break_point_object);
10654  // Check if break point info has this break point object.
10655  static bool HasBreakPointObject(Handle<BreakPointInfo> info,
10656  Handle<Object> break_point_object);
10657  // Get the number of break points for this code position.
10658  int GetBreakPointCount();
10659 
10661 
10662  // Dispatched behavior.
10665 
10666  static const int kCodePositionIndex = Struct::kHeaderSize;
10667  static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
10668  static const int kStatementPositionIndex =
10669  kSourcePositionIndex + kPointerSize;
10670  static const int kBreakPointObjectsIndex =
10671  kStatementPositionIndex + kPointerSize;
10672  static const int kSize = kBreakPointObjectsIndex + kPointerSize;
10673 
10674  private:
10676 };
10677 
10678 
10679 #undef DECL_BOOLEAN_ACCESSORS
10680 #undef DECL_ACCESSORS
10681 #undef DECLARE_CAST
10682 #undef DECLARE_VERIFIER
10683 
10684 #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
10685  V(kStringTable, "string_table", "(Internalized strings)") \
10686  V(kExternalStringsTable, "external_strings_table", "(External strings)") \
10687  V(kStrongRootList, "strong_root_list", "(Strong roots)") \
10688  V(kSmiRootList, "smi_root_list", "(Smi roots)") \
10689  V(kInternalizedString, "internalized_string", "(Internal string)") \
10690  V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
10691  V(kTop, "top", "(Isolate)") \
10692  V(kRelocatable, "relocatable", "(Relocatable)") \
10693  V(kDebug, "debug", "(Debugger)") \
10694  V(kCompilationCache, "compilationcache", "(Compilation cache)") \
10695  V(kHandleScope, "handlescope", "(Handle scope)") \
10696  V(kBuiltins, "builtins", "(Builtins)") \
10697  V(kGlobalHandles, "globalhandles", "(Global handles)") \
10698  V(kEternalHandles, "eternalhandles", "(Eternal handles)") \
10699  V(kThreadManager, "threadmanager", "(Thread manager)") \
10700  V(kExtensions, "Extensions", "(Extensions)")
10701 
10703  public:
10704 #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
10705  enum SyncTag {
10707  kNumberOfSyncTags
10708  };
10709 #undef DECLARE_ENUM
10710 
10711  static const char* const kTags[kNumberOfSyncTags];
10712  static const char* const kTagNames[kNumberOfSyncTags];
10713 };
10714 
10715 // Abstract base class for visiting, and optionally modifying, the
10716 // pointers contained in Objects. Used in GC and serialization/deserialization.
10718  public:
10719  virtual ~ObjectVisitor() {}
10720 
10721  // Visits a contiguous arrays of pointers in the half-open range
10722  // [start, end). Any or all of the values may be modified on return.
10723  virtual void VisitPointers(Object** start, Object** end) = 0;
10724 
10725  // Handy shorthand for visiting a single pointer.
10726  virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
10727 
10728  // Visit weak next_code_link in Code object.
10729  virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); }
10730 
10731  // To allow lazy clearing of inline caches the visitor has
10732  // a rich interface for iterating over Code objects..
10733 
10734  // Visits a code target in the instruction stream.
10735  virtual void VisitCodeTarget(RelocInfo* rinfo);
10736 
10737  // Visits a code entry in a JS function.
10738  virtual void VisitCodeEntry(Address entry_address);
10739 
10740  // Visits a global property cell reference in the instruction stream.
10741  virtual void VisitCell(RelocInfo* rinfo);
10742 
10743  // Visits a runtime entry in the instruction stream.
10744  virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
10745 
10746  // Visits the resource of an one-byte or two-byte string.
10750  v8::String::ExternalStringResource** resource) {}
10751 
10752  // Visits a debug call target in the instruction stream.
10753  virtual void VisitDebugTarget(RelocInfo* rinfo);
10754 
10755  // Visits the byte sequence in a function's prologue that contains information
10756  // about the code's age.
10757  virtual void VisitCodeAgeSequence(RelocInfo* rinfo);
10758 
10759  // Visit pointer embedded into a code object.
10760  virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
10761 
10762  // Visits an external reference embedded into a code object.
10763  virtual void VisitExternalReference(RelocInfo* rinfo);
10764 
10765  // Visits an external reference. The value may be modified on return.
10766  virtual void VisitExternalReference(Address* p) {}
10767 
10768  // Visits a handle that has an embedder-assigned class ID.
10769  virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
10770 
10771  // Intended for serialization/deserialization checking: insert, or
10772  // check for the presence of, a tag at this position in the stream.
10773  // Also used for marking up GC roots in heap snapshots.
10775 };
10776 
10777 
10778 class StructBodyDescriptor : public
10779  FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
10780  public:
10781  static inline int SizeOf(Map* map, HeapObject* object) {
10782  return map->instance_size();
10783  }
10784 };
10785 
10786 
10787 // BooleanBit is a helper class for setting and getting a bit in an
10788 // integer or Smi.
10789 class BooleanBit : public AllStatic {
10790  public:
10791  static inline bool get(Smi* smi, int bit_position) {
10792  return get(smi->value(), bit_position);
10793  }
10794 
10795  static inline bool get(int value, int bit_position) {
10796  return (value & (1 << bit_position)) != 0;
10797  }
10798 
10799  static inline Smi* set(Smi* smi, int bit_position, bool v) {
10800  return Smi::FromInt(set(smi->value(), bit_position, v));
10801  }
10802 
10803  static inline int set(int value, int bit_position, bool v) {
10804  if (v) {
10805  value |= (1 << bit_position);
10806  } else {
10807  value &= ~(1 << bit_position);
10808  }
10809  return value;
10810  }
10811 };
10812 
10813 } } // namespace v8::internal
10814 
10815 #endif // V8_OBJECTS_H_
#define CODE_AGE_LIST(V)
Definition: builtins.h:27
#define DCHECK_SIZE_TAG_ALIGNED(size)
Definition: checks.h:60
static const unsigned kMaxChar
Definition: unicode.h:118
static const unsigned kMaxOneByteChar
Definition: unicode.h:141
A base class for an instance of one of "views" over ArrayBuffer, including TypedArrays and DataView (...
Definition: v8.h:2975
An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
Definition: v8.h:2850
A superclass for symbols and strings.
Definition: v8.h:1741
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V...
Definition: v8.h:1918
An ExternalStringResource is a wrapper around a two-byte string buffer that resides outside V8's heap...
Definition: v8.h:1885
DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo)
void SetComponents(Object *getter, Object *setter)
Definition: objects.h:10327
Object * get(AccessorComponent component)
Definition: objects.h:10311
void set(AccessorComponent component, Object *value)
Definition: objects.h:10315
DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair)
AllocationSite * GetAllocationSite()
Definition: objects.h:8295
DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento)
FixedBodyDescriptor< HeapObject::kHeaderSize, kDependentCodeOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:8272
void set_pretenure_decision(PretenureDecision decision)
Definition: objects.h:8149
static const double kPretenureRatio
Definition: objects.h:8093
void set_deopt_dependent_code(bool deopt)
Definition: objects.h:8161
PretenureDecision pretenure_decision()
Definition: objects.h:8144
DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite)
void set_memento_create_count(int count)
Definition: objects.h:8179
STATIC_ASSERT(PretenureDecisionBits::kMax >=kLastPretenureDecisionValue)
ElementsKind GetElementsKind()
Definition: objects.h:8203
void SetElementsKind(ElementsKind kind)
Definition: objects.h:8209
virtual void IterateInstance(ObjectVisitor *v)
Definition: objects.h:9236
virtual void VisitEmbedderReference(Object **p, uint16_t class_id)
Definition: objects.h:10769
virtual void VisitExternalReference(Address *p)
Definition: objects.h:10766
static MapWord FromRawValue(uintptr_t value)
Definition: objects.h:1308
virtual void PostGarbageCollection()
Definition: objects.h:9237
virtual void VisitCodeEntry(Address entry_address)
static void Iterate(Isolate *isolate, ObjectVisitor *v)
static char * RestoreState(Isolate *isolate, char *from)
StringRepresentationTag representation_tag()
static void PostGarbageCollectionProcessing(Isolate *isolate)
virtual void VisitExternalTwoByteString(v8::String::ExternalStringResource **resource)
Definition: objects.h:10749
static MapWord FromForwardingAddress(HeapObject *object)
StringShape(InstanceType t)
virtual void VisitPointer(Object **p)
Definition: objects.h:10726
virtual void VisitRuntimeEntry(RelocInfo *rinfo)
Definition: objects.h:10744
virtual void VisitCodeAgeSequence(RelocInfo *rinfo)
virtual void VisitCodeTarget(RelocInfo *rinfo)
virtual void Synchronize(VisitorSynchronization::SyncTag tag)
Definition: objects.h:10774
virtual void VisitExternalOneByteString(v8::String::ExternalOneByteStringResource **resource)
Definition: objects.h:10747
HeapObject * ToForwardingAddress()
virtual void VisitNextCodeLink(Object **p)
Definition: objects.h:10729
static char * ArchiveState(Isolate *isolate, char *to)
StringShape(const String *s)
static char * Iterate(ObjectVisitor *v, char *t)
static MapWord FromMap(const Map *map)
virtual void VisitDebugTarget(RelocInfo *rinfo)
static int ArchiveSpacePerThread()
virtual void VisitPointers(Object **start, Object **end)=0
static void Iterate(ObjectVisitor *v, Relocatable *top)
Relocatable(Isolate *isolate)
MapWord(uintptr_t value)
Definition: objects.h:1320
virtual void VisitCell(RelocInfo *rinfo)
virtual void VisitExternalReference(RelocInfo *rinfo)
virtual void VisitEmbeddedPointer(RelocInfo *rinfo)
static uint32_t SeededHash(Key key, uint32_t seed)
Definition: objects.h:3178
static uint32_t Hash(Key key)
Definition: objects.h:3177
static uint32_t HashForObject(Key key, Object *object)
Definition: objects.h:3182
static uint32_t SeededHashForObject(Key key, uint32_t seed, Object *object)
Definition: objects.h:3183
static const U kShift
Definition: utils.h:204
static U update(U previous, T value)
Definition: utils.h:223
static const U kSize
Definition: utils.h:205
static const T kMax
Definition: utils.h:209
static T decode(U value)
Definition: utils.h:228
static bool get(int value, int bit_position)
Definition: objects.h:10795
static bool get(Smi *smi, int bit_position)
Definition: objects.h:10791
static Smi * set(Smi *smi, int bit_position, bool v)
Definition: objects.h:10799
static int set(int value, int bit_position, bool v)
Definition: objects.h:10803
static int SizeFor(int length)
Definition: objects.h:4360
static int LengthFor(int size_in_bytes)
Definition: objects.h:4367
Address ValueAddress()
Definition: objects.h:9437
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:7944
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:7948
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:7952
bool CanContainWeakObjects()
Definition: objects.h:5331
bool is_store_stub()
Definition: objects.h:5051
bool is_compare_ic_stub()
Definition: objects.h:5055
static void PatchPlatformCodeAge(Isolate *isolate, byte *sequence, Age age, MarkingParity parity)
static bool IsYoungSequence(Isolate *isolate, byte *sequence)
int ExecutableSize()
Definition: objects.h:5263
STATIC_ASSERT(kStackSlotsFirstBit+kStackSlotsBitCount<=32)
bool is_load_stub()
Definition: objects.h:5049
bool is_call_stub()
Definition: objects.h:5053
static void GetCodeAgeAndParity(Isolate *isolate, byte *sequence, Age *age, MarkingParity *parity)
STATIC_ASSERT(NUMBER_OF_KINDS<=16)
int instruction_size() const
bool is_keyed_store_stub()
Definition: objects.h:5052
STATIC_ASSERT(kSafepointTableOffsetFirstBit+kSafepointTableOffsetBitCount<=32)
bool is_keyed_load_stub()
Definition: objects.h:5050
bool is_binary_op_stub()
Definition: objects.h:5054
bool IsWeakObject(Object *object)
Definition: objects.h:5335
bool is_optimized_code()
Definition: objects.h:5059
DISALLOW_IMPLICIT_CONSTRUCTORS(Code)
STATIC_ASSERT(kIsTurbofannedBit+1<=32)
static const int kHeaderSize
Definition: objects.h:5373
bool is_to_boolean_ic_stub()
Definition: objects.h:5057
static int SizeFor(int body_size)
Definition: objects.h:5256
STATIC_ASSERT(1+kSafepointTableOffsetBitCount<=32)
uint32_t Flags
Definition: objects.h:4929
static Code * GetPreAgedCodeAgeStub(Isolate *isolate)
Definition: objects.h:5320
void set_instruction_size(int value)
bool CanBeWeakStub()
Definition: objects.h:5065
STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >=kMaxLoopNestingMarker)
bool is_compare_nil_ic_stub()
Definition: objects.h:5056
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:7844
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:7852
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:7848
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable)
DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp)
void Reset(ConsString *cons_string, int offset=0)
Definition: objects.h:9293
STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize))
String * Next(int *offset_out)
Definition: objects.h:9300
ConsStringIteratorOp(ConsString *cons_string, int offset=0)
Definition: objects.h:9289
static String * Operate(String *, unsigned *, int32_t *, unsigned *)
DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp)
NumberOfEntries(int int64_count, int code_ptr_count, int heap_ptr_count, int int32_count)
Definition: objects.h:2633
Iterator(ConstantPoolArray *array, Type type)
Definition: objects.h:2662
NumberOfEntries(ConstantPoolArray *array, LayoutSection section)
Definition: objects.h:2641
int are_in_range(int min, int max) const
Iterator(ConstantPoolArray *array, Type type, LayoutSection section)
Definition: objects.h:2671
int equals(const NumberOfEntries &other) const
static Type next_type(Type type)
Definition: objects.h:2865
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolArray)
static int MaxInt64Offset(int number_of_int64)
Definition: objects.h:2751
int OffsetOfElementAt(int index)
Definition: objects.h:2792
static int SizeFor(const NumberOfEntries &small)
Definition: objects.h:2755
int number_of_entries(Type type, LayoutSection layout_section)
Definition: objects-inl.h:2415
static int entry_size(Type type)
Definition: objects.h:2776
static int SizeForExtended(const NumberOfEntries &small, const NumberOfEntries &extended)
Definition: objects.h:2764
DISALLOW_IMPLICIT_CONSTRUCTORS(DeclaredAccessorDescriptorIterator)
static int LengthFor(int entry_count)
Definition: objects.h:4877
void SetAstId(int i, BailoutId value)
Definition: objects.h:4852
void SetAstId(int index, BailoutId id)
Definition: objects.h:4894
static int LengthOfFixedArray(int deopt_points)
Definition: objects.h:4901
void SetPcAndState(int index, Smi *offset)
Definition: objects.h:4899
Entry(DescriptorArray *descs, int index)
Definition: objects.h:3083
void CopyEnumCacheFrom(DescriptorArray *array)
Definition: objects.h:2913
static int LengthFor(int number_of_descriptors)
Definition: objects.h:3058
INLINE(int Search(Name *name, int number_of_own_descriptors))
static int ToValueIndex(int descriptor_number)
Definition: objects.h:3107
DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray)
FixedArray * GetEnumCache()
Definition: objects.h:2917
INLINE(int SearchWithCache(Name *name, Map *map))
static int ToDetailsIndex(int descriptor_number)
Definition: objects.h:3101
static int ToKeyIndex(int descriptor_number)
Definition: objects.h:3095
FixedArray * GetEnumIndicesCache()
Definition: objects.h:2931
void CopyKeysTo(FixedArray *storage, int index, PropertyAttributes filter, SortMode sort_mode)
void CopyKeysTo(FixedArray *storage, PropertyAttributes filter, SortMode sort_mode)
Object * ValueAt(int entry)
Definition: objects.h:3491
void SetNextEnumerationIndex(int index)
Definition: objects.h:3547
HashTable< Derived, Shape, Key > DerivedHashTable
Definition: objects.h:3487
static MUST_USE_RESULT Handle< Derived > Shrink(Handle< Derived > dictionary, Key key)
Definition: objects.h:3522
PropertyDetails DetailsAt(int entry)
Definition: objects.h:3501
void ValueAtPut(int entry, Object *value)
Definition: objects.h:3496
void DetailsAtPut(int entry, PropertyDetails value)
Definition: objects.h:3508
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray)
bool is_the_hole(int index)
Definition: objects.h:4459
DECL_ACCESSORS(external_pointer, void) static const int kMaxLength=0x3fffffff
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloat32Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloat64Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalInt16Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalInt32Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalInt8Array)
v8::String::ExternalOneByteStringResource Resource
Definition: objects.h:9160
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString)
v8::String::ExternalStringResource Resource
Definition: objects.h:9196
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUint16Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUint32Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUint8Array)
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUint8ClampedArray)
static const int kLengthOffset
Definition: objects.h:2392
void synchronized_set_length(int value)
static int SizeOf(Map *map, HeapObject *object)
Definition: objects.h:2491
Object ** RawFieldOfElementAt(int index)
Definition: objects.h:2458
static int OffsetOfElementAt(int index)
Definition: objects.h:2455
Object * get(int index)
Definition: objects-inl.h:2165
DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray)
static int SizeFor(int length)
Definition: objects.h:2452
void set(int index, Object *value)
Definition: objects-inl.h:2190
STATIC_ASSERT(kHeaderSize==Internals::kFixedArrayHeaderSize)
static const int kMaxLength
Definition: objects.h:2469
static void IterateBody(HeapObject *obj)
Definition: objects.h:1459
static int SizeFor(int length)
Definition: objects.h:2531
static int OffsetOfElementAt(int index)
Definition: objects.h:2541
DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray)
static int SizeFor(int length)
Definition: objects.h:4746
Traits::ElementType ElementType
Definition: objects.h:4737
static void IterateBody(HeapObject *obj, int object_size)
Definition: objects.h:1479
void nobarrier_set_size(int value)
int nobarrier_size() const
void set_size(int value)
virtual uint32_t Hash()=0
virtual bool IsMatch(Object *other)=0
virtual MUST_USE_RESULT Handle< Object > AsHandle(Isolate *isolate)=0
virtual uint32_t HashForObject(Object *key)=0
void SetNumberOfElements(int nof)
Definition: objects.h:3311
bool IsKey(Object *k)
Definition: objects.h:3255
static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size)
Definition: objects.h:3341
Object * KeyAt(int entry)
Definition: objects.h:3251
static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size)
Definition: objects.h:3332
void SetNumberOfDeletedElements(int nod)
Definition: objects.h:3316
uint32_t Hash(Key key)
Definition: objects.h:3193
uint32_t HashForObject(Key key, Object *object)
Definition: objects.h:3201
static int EntryToIndex(int entry)
Definition: objects.h:3306
static uint32_t FirstProbe(uint32_t hash, uint32_t size)
Definition: objects.h:3337
void ElementsRemoved(int n)
Definition: objects.h:3234
void SetCapacity(int capacity)
Definition: objects.h:3321
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber)
STATIC_ASSERT(kMapOffset==Internals::kHeapObjectMapOffset)
static Object ** RawField(HeapObject *obj, int offset)
Definition: objects-inl.h:1311
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject)
static const int kHeaderSize
Definition: objects.h:1428
This class exports constants and functionality from within v8 that is necessary to implement inline f...
Definition: v8.h:5815
static const int kHeapObjectMapOffset
Definition: v8.h:5819
static const int kOddballType
Definition: v8.h:5864
static const int kForeignType
Definition: v8.h:5865
static const int kUndefinedOddballKind
Definition: v8.h:5867
static const int kJSObjectType
Definition: v8.h:5862
static const int kFirstNonstringType
Definition: v8.h:5863
static const int kFixedArrayHeaderSize
Definition: v8.h:5827
static const int kNullOddballKind
Definition: v8.h:5868
static const int kOddballKindOffset
Definition: v8.h:5824
static const int kMapInstanceTypeAndBitFieldOffset
Definition: v8.h:5820
static const int kJSObjectHeaderSize
Definition: v8.h:5826
DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher)
IteratingStringHasher(int len, uint32_t seed)
Definition: objects.h:8402
static const int kSize
Definition: objects.h:10073
DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject)
static int OffsetOfCodeWithId(Builtins::JavaScript id)
Definition: objects.h:7524
DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap)
static Handle< JSObject > Copy(Handle< JSObject > object)
bool HasFixedUint8ClampedElements()
DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject)
DECL_ACCESSORS(properties, FixedArray) inline void initialize_properties()
static const int kHeaderSize
Definition: objects.h:2195
STATIC_ASSERT(kHeaderSize==Internals::kJSObjectHeaderSize)
static int NewElementsCapacity(int old_capacity)
Definition: objects.h:1911
static bool CanSetCallback(Handle< JSObject > object, Handle< Name > name)
bool HasExternalUint8ClampedElements()
DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult)
static int saved_code_index(bool is_latin1)
Definition: objects.h:7758
static int code_index(bool is_latin1)
Definition: objects.h:7750
DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap)
DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet)
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:3456
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:3452
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:3448
DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache)
bool has_external_array_elements()
Definition: objects.h:5760
ElementsKind elements_kind()
Definition: objects.h:5730
void SetEnumLength(int length)
Definition: objects.h:5959
int NumberOfOwnDescriptors()
Definition: objects.h:5944
Cell * RetrieveDescriptorsPointer()
bool IsJSGlobalProxyMap()
Definition: objects.h:6132
void set_is_hidden_prototype()
Definition: objects.h:5669
void set_is_undetectable()
Definition: objects.h:5701
STATIC_ASSERT(kDescriptorIndexBitCount+kDescriptorIndexBitCount==20)
bool has_fast_smi_or_object_elements()
Definition: objects.h:5744
FixedBodyDescriptor< kPointerFieldsBeginOffset, kPointerFieldsEndOffset, kSize > BodyDescriptor
Definition: objects.h:6270
bool has_fast_elements()
Definition: objects.h:5752
void SetNumberOfProtoTransitions(int value)
Definition: objects.h:5914
bool has_named_interceptor()
Definition: objects.h:5682
bool is_hidden_prototype()
Definition: objects.h:5673
bool has_dictionary_elements()
Definition: objects.h:5768
bool CanTransition()
Definition: objects.h:6119
bool IsJSProxyMap()
Definition: objects.h:6128
void SetNumberOfOwnDescriptors(int number)
Definition: objects.h:5948
bool IsJSGlobalObjectMap()
Definition: objects.h:6135
bool has_fixed_typed_array_elements()
Definition: objects.h:5764
bool IsJSObjectMap()
Definition: objects.h:6125
void ClearNonLiveTransitions(Heap *heap)
void set_elements_kind(ElementsKind elements_kind)
Definition: objects.h:5723
void set_has_named_interceptor()
Definition: objects.h:5678
bool is_undetectable()
Definition: objects.h:5705
bool IsGlobalObjectMap()
Definition: objects.h:6138
bool has_fast_double_elements()
Definition: objects.h:5748
DISALLOW_IMPLICIT_CONSTRUCTORS(Map)
int InitialPropertiesLength()
Definition: objects.h:6066
bool has_sloppy_arguments_elements()
Definition: objects.h:5756
bool has_fast_smi_elements()
Definition: objects.h:5735
bool has_fast_object_elements()
Definition: objects.h:5740
bool is_observed()
Definition: objects.h:5714
int NumberOfProtoTransitions()
Definition: objects.h:5907
STATIC_ASSERT(kInstanceTypeAndBitFieldOffset==Internals::kMapInstanceTypeAndBitFieldOffset)
bool has_indexed_interceptor()
Definition: objects.h:5691
static const int kPrototypeOffset
Definition: objects.h:6190
void set_is_observed()
Definition: objects.h:5710
void set_has_indexed_interceptor()
Definition: objects.h:5687
bool has_slow_elements_kind()
Definition: objects.h:5772
Dictionary< NameDictionary, NameDictionaryShape, Handle< Name > > DerivedDictionary
Definition: objects.h:3624
STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength+1))
DISALLOW_IMPLICIT_CONSTRUCTORS(Name)
static const int kSize
Definition: objects.h:8487
void set(int index, Object *value)
static int EntryToValueIndex(int entry)
Definition: objects.h:3791
HashTable< ObjectHashTable, ObjectHashTableShape, Handle< Object > > DerivedHashTable
Definition: objects.h:3761
INLINE(bool IsNameDictionary() const)
INLINE(bool IsException() const)
INLINE(bool IsTrue() const)
Handle< HeapType > OptimalType(Isolate *isolate, Representation representation)
Definition: objects.cc:47
static MUST_USE_RESULT MaybeHandle< Object > AddDataProperty(LookupIterator *it, Handle< Object > value, PropertyAttributes attributes, StrictMode strict_mode, StoreFromKeyed store_mode)
Definition: objects.cc:2968
static MUST_USE_RESULT MaybeHandle< Object > GetPropertyOrElement(Handle< Object > object, Handle< Name > key)
Definition: objects-inl.h:1124
Object * GetHash()
Definition: objects.cc:835
static MUST_USE_RESULT MaybeHandle< Object > SetPropertyWithDefinedSetter(Handle< Object > receiver, Handle< JSReceiver > setter, Handle< Object > value)
Definition: objects.cc:552
bool IsObject() const
Definition: objects.h:996
INLINE(bool IsArgumentsMarker() const)
INLINE(bool IsOrderedHashMap() const)
static MUST_USE_RESULT MaybeHandle< Object > SetPropertyWithAccessor(Handle< Object > receiver, Handle< Name > name, Handle< Object > value, Handle< JSObject > holder, Handle< Object > structure, StrictMode strict_mode)
Definition: objects.cc:478
INLINE(bool IsExternal() const)
bool ToUint32(uint32_t *value)
Definition: objects.cc:191
INLINE(bool IsUndefined() const)
static MaybeHandle< JSReceiver > ToObject(Isolate *isolate, Handle< Object > object)
Definition: objects-inl.h:1094
static MUST_USE_RESULT MaybeHandle< Object > GetElement(Isolate *isolate, Handle< Object > object, uint32_t index)
Definition: objects-inl.h:1113
INLINE(bool IsFixedArrayBase() const)
INLINE(bool IsFalse() const)
INLINE(bool IsSeededNumberDictionary() const)
bool SameValue(Object *other)
Definition: objects.cc:865
friend class LookupIterator
Definition: objects.h:1226
static MUST_USE_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it)
Definition: objects.cc:109
@ CERTAINLY_NOT_STORE_FROM_KEYED
Definition: objects.h:1007
Map * GetRootMap(Isolate *isolate)
Definition: objects.cc:803
bool SameValueZero(Object *other)
Definition: objects.cc:886
static Handle< Object > NewStorageFor(Isolate *isolate, Handle< Object > object, Representation representation)
Definition: objects-inl.h:277
INLINE(bool IsSpecFunction()) const
bool IsCallable() const
Definition: objects.cc:98
INLINE(bool IsUninitialized() const)
static MUST_USE_RESULT MaybeHandle< Object > WriteToReadOnlyProperty(LookupIterator *it, Handle< Object > value, StrictMode strict_mode)
Definition: objects.cc:2920
void ShortPrint(FILE *out=stdout)
Definition: objects.cc:905
static MUST_USE_RESULT MaybeHandle< Object > GetPropertyWithDefinedGetter(Handle< Object > receiver, Handle< JSReceiver > getter)
Definition: objects.cc:536
INLINE(bool IsUnseededNumberDictionary() const)
static MUST_USE_RESULT MaybeHandle< Smi > ToSmi(Isolate *isolate, Handle< Object > object)
Definition: objects-inl.h:1081
INLINE(bool IsFiller() const)
bool FitsRepresentation(Representation representation)
Definition: objects.h:1068
void VerifyApiCallResultType()
Definition: objects-inl.h:2148
static Handle< Object > SetDataProperty(LookupIterator *it, Handle< Object > value)
Definition: objects.cc:2933
INLINE(bool IsAccessorInfo() const)
bool IsStringObjectWithCharacterAt(uint32_t index)
Definition: objects-inl.h:2135
INLINE(bool IsSpecObject()) const
INLINE(bool IsStruct() const)
bool ToInt32(int32_t *value)
Definition: objects.cc:175
Representation OptimalRepresentation()
Definition: objects.h:1052
INLINE(bool IsNaN() const)
bool ToArrayIndex(uint32_t *index)
Definition: objects-inl.h:2116
INLINE(bool IsOrderedHashSet() const)
INLINE(bool IsTemplateInfo()) const
INLINE(bool IsMinusZero() const)
static Handle< Smi > GetOrCreateHash(Isolate *isolate, Handle< Object > object)
Definition: objects.cc:856
INLINE(bool IsNull() const)
INLINE(bool IsTheHole() const)
static Handle< Object > WrapForRead(Isolate *isolate, Handle< Object > object, Representation representation)
Definition: objects-inl.h:296
static const int kHeaderSize
Definition: objects.h:1215
static MUST_USE_RESULT MaybeHandle< Object > GetElementWithReceiver(Isolate *isolate, Handle< Object > object, Handle< Object > receiver, uint32_t index)
Definition: objects.cc:747
static MUST_USE_RESULT MaybeHandle< Object > GetPropertyWithAccessor(Handle< Object > receiver, Handle< Name > name, Handle< JSObject > holder, Handle< Object > structure)
Definition: objects.cc:411
bool HasSpecificClassOf(String *name)
Definition: objects-inl.h:1101
DISALLOW_IMPLICIT_CONSTRUCTORS(Object)
static MUST_USE_RESULT MaybeHandle< Object > SetProperty(Handle< Object > object, Handle< Name > key, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode=MAY_BE_STORE_FROM_KEYED)
Definition: objects.cc:2798
STATIC_ASSERT(kNull==Internals::kNullOddballKind)
STATIC_ASSERT(kUndefined==Internals::kUndefinedOddballKind)
DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball)
FixedBodyDescriptor< kToStringOffset, kToNumberOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:9413
STATIC_ASSERT(kKindOffset==Internals::kOddballKindOffset)
Object * ValueAt(int entry)
Definition: objects.h:3997
DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator)
void SetNextTable(Derived *next_table)
Definition: objects.h:3943
int RemovedIndexAt(int index)
Definition: objects.h:3903
void SetRemovedIndexAt(int index, int removed_index)
Definition: objects.h:3947
int EntryToIndex(int entry)
Definition: objects.h:3887
void SetNumberOfBuckets(int num)
Definition: objects.h:3913
void SetNumberOfElements(int num)
Definition: objects.h:3917
void SetNumberOfDeletedElements(int num)
Definition: objects.h:3921
Object * KeyAt(int entry)
Definition: objects.h:3891
A class to uniformly access the prototype of any Object and walk its prototype chain.
Definition: prototype.h:25
static Representation Double()
static Representation Smi()
static Representation HeapObject()
static Representation Tagged()
static Representation None()
DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString)
static int SizeFor(int length)
Definition: objects.h:8976
STATIC_ASSERT((kMaxSize - kHeaderSize) >=String::kMaxLength)
static int SizeFor(int length)
Definition: objects.h:9015
STATIC_ASSERT(static_cast< int >((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >=String::kMaxLength)
DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString)
FixedBodyDescriptor< kNameOffset, kFeedbackVectorOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:6983
void set_expected_nof_properties(int value)
static const int kCompilerHintsSize
Definition: objects.h:7033
void set_formal_parameter_count(int value)
DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo)
STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount<=SharedFunctionInfo::kCompilerHintsSize *kBitsPerByte)
void set_offset(int offset)
void SmiPrint(OStream &os) const
Definition: objects.cc:930
DISALLOW_IMPLICIT_CONSTRUCTORS(Smi)
static const int kMaxValue
Definition: objects.h:1272
int value() const
Definition: objects-inl.h:1316
static const int kMinValue
Definition: objects.h:1270
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static Smi * FromIntptr(intptr_t value)
Definition: objects-inl.h:1327
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1334
ConsStringIteratorOp * op_
Definition: objects.h:9352
DISALLOW_COPY_AND_ASSIGN(StringCharacterStream)
INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c))
DISALLOW_COPY_AND_ASSIGN(StringHasher)
INLINE(static uint32_t GetHashCore(uint32_t running_hash))
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:3387
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:3391
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:3395
DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable)
FlatContent(const uc16 *start, int length)
Definition: objects.h:8663
FlatContent(const uint8_t *start, int length)
Definition: objects.h:8661
Vector< const uint8_t > ToOneByteVector()
Definition: objects.h:8639
Vector< const uc16 > ToUC16Vector()
Definition: objects.h:8645
static int NonAsciiStart(const char *chars, int length)
Definition: objects.h:8843
STATIC_ASSERT((kArrayIndexLengthBits > 0))
int synchronized_length() const
static bool IsAscii(const uint8_t *chars, int length)
Definition: objects.h:8880
static const int kMaxLength
Definition: objects.h:8820
STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength+1))
void synchronized_set_length(int value)
static int NonOneByteStart(const uc16 *chars, int length)
Definition: objects.h:8885
STATIC_ASSERT(kMaxArrayIndexSize<(1<< kArrayIndexLengthBits))
INLINE(uint16_t Get(int index))
DISALLOW_IMPLICIT_CONSTRUCTORS(String)
static bool IsOneByte(const uc16 *chars, int length)
Definition: objects.h:8895
void set_length(int value)
static bool IsAscii(const char *chars, int length)
Definition: objects.h:8876
static int SizeOf(Map *map, HeapObject *object)
Definition: objects.h:10781
DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo)
VectorIterator(Vector< const T > data)
Definition: objects.h:9361
Vector< const T > data_
Definition: objects.h:9365
VectorIterator(T *d, int l)
Definition: objects.h:9360
HashTable< WeakHashTable, WeakHashTableShape< 2 >, Handle< Object > > DerivedHashTable
Definition: objects.h:4025
static int EntryToValueIndex(int entry)
Definition: objects.h:4054
void Zap(Object *value)
Definition: objects.h:4040
#define WARN_UNUSED_RESULT
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric literals(0o77, 0b11)") DEFINE_BOOL(harmony_object_literals
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob file(mksnapshot only)") DEFINE_BOOL(profile_hydrogen_code_stub_compilation
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define ROUND_UP(n, sz)
Definition: globals.h:191
#define POINTER_SIZE_ALIGN(value)
Definition: globals.h:582
#define OBJECT_POINTER_ALIGN(value)
Definition: globals.h:578
#define GLOBAL
#define UNREACHABLE()
Definition: logging.h:30
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
#define IS_POWER_OF_TWO(x)
Definition: macros.h:325
#define MUST_USE_RESULT
Definition: macros.h:266
unsigned short uint16_t
Definition: unicode.cc:23
signed short int16_t
Definition: unicode.cc:22
int int32_t
Definition: unicode.cc:24
bool IsPowerOfTwo32(uint32_t value)
Definition: bits.h:77
const int kPointerSize
Definition: globals.h:129
@ DONT_ALLOW_DOUBLE_ELEMENTS
Definition: objects.h:1540
@ ALLOW_CONVERTED_DOUBLE_ELEMENTS
Definition: objects.h:1542
@ ALLOW_COPIED_DOUBLE_ELEMENTS
Definition: objects.h:1541
const uint32_t kStringEncodingMask
Definition: objects.h:555
static bool IterateElements(Isolate *isolate, Handle< JSArray > receiver, ArrayConcatVisitor *visitor)
A helper function that visits elements of a JSArray in numerical order.
Definition: runtime.cc:4946
bool Is(Object *obj)
const int kBitsPerInt
Definition: globals.h:165
kSerializedDataOffset kPrototypeTemplateOffset kIndexedPropertyHandlerOffset kInstanceCallHandlerOffset internal_field_count
Definition: objects-inl.h:5340
InitializationFlag
Definition: globals.h:751
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kDoNotCacheBit is_toplevel
Definition: objects-inl.h:5431
@ LAST_ALLOCATION_SITE_MODE
Definition: objects.h:8086
@ TRACK_ALLOCATION_SITE
Definition: objects.h:8085
@ DONT_TRACK_ALLOCATION_SITE
Definition: objects.h:8084
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kDoNotCacheBit kIsTopLevelBit kAllowLazyCompilationWithoutContext has_duplicate_parameters
Definition: objects-inl.h:5448
kExpectedNofPropertiesOffset kFunctionTokenPositionOffset kOptCountAndBailoutReasonOffset profiler_ticks
Definition: objects-inl.h:5528
StringRepresentationTag
Definition: objects.h:562
@ kSeqStringTag
Definition: objects.h:563
@ kConsStringTag
Definition: objects.h:564
@ kSlicedStringTag
Definition: objects.h:566
@ kExternalStringTag
Definition: objects.h:565
const uintptr_t kUintptrAllBitsSet
Definition: globals.h:149
bool IsExternalArrayElementsKind(ElementsKind kind)
Definition: elements-kind.h:95
@ SKIP_WRITE_BARRIER
Definition: objects.h:235
@ UPDATE_WRITE_BARRIER
Definition: objects.h:235
kSerializedDataOffset kPrototypeTemplateOffset indexed_property_handler
Definition: objects-inl.h:5327
FixedArraySubInstanceType
Definition: objects.h:811
@ LAST_FIXED_ARRAY_SUB_TYPE
Definition: objects.h:815
PrototypeOptimizationMode
Definition: objects.h:258
@ FAST_PROTOTYPE
Definition: objects.h:258
@ REGULAR_PROTOTYPE
Definition: objects.h:258
static int min(int a, int b)
Definition: liveedit.cc:273
@ DEFINE_PROPERTY
Definition: objects.h:1552
const intptr_t kCodeAlignment
Definition: globals.h:240
bool IsFastSmiOrObjectElementsKind(ElementsKind kind)
static MUST_USE_RESULT MaybeHandle< Code > GetCodeFromOptimizedCodeMap(Handle< JSFunction > function, BailoutId osr_ast_id)
Definition: compiler.cc:682
const uint32_t kTwoByteStringTag
Definition: objects.h:556
const uint32_t kShortExternalStringTag
Definition: objects.h:590
kExpectedNofPropertiesOffset function_token_position
Definition: objects-inl.h:5513
Handle< Object > CacheInitialJSArrayMaps(Handle< Context > native_context, Handle< Map > initial_map)
Definition: objects.cc:9355
const uint32_t kShortcutTypeMask
Definition: objects.h:599
const int kSmiTagSize
Definition: v8.h:5743
@ INSERT_TRANSITION
Definition: objects.h:263
@ OMIT_TRANSITION
Definition: objects.h:264
static const ExtraICState kNoExtraICState
Definition: objects.h:306
name_should_print_as_anonymous
Definition: objects-inl.h:5584
@ ALLOW_AS_CONSTANT
Definition: objects.h:240
@ USE_DEFAULT_MINIMUM_CAPACITY
Definition: globals.h:385
const int kDoubleSize
Definition: globals.h:127
const uint32_t kNotStringTag
Definition: objects.h:545
@ DISALLOW_NULLS
Definition: objects.h:8337
SimpleTransitionFlag
Definition: objects.h:277
@ FULL_TRANSITION
Definition: objects.h:279
@ SIMPLE_TRANSITION
Definition: objects.h:278
static KeyedAccessStoreMode GetNonTransitioningStoreMode(KeyedAccessStoreMode store_mode)
Definition: objects.h:216
static const int kGrowICDelta
Definition: objects.h:185
KeyedAccessStoreMode
Definition: objects.h:153
@ STORE_AND_GROW_TRANSITION_HOLEY_DOUBLE_TO_OBJECT
Definition: objects.h:167
@ STORE_TRANSITION_HOLEY_SMI_TO_OBJECT
Definition: objects.h:158
@ STORE_TRANSITION_DOUBLE_TO_OBJECT
Definition: objects.h:157
@ STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_DOUBLE
Definition: objects.h:166
@ STORE_AND_GROW_NO_TRANSITION
Definition: objects.h:161
@ STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE
Definition: objects.h:163
@ STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT
Definition: objects.h:164
@ STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS
Definition: objects.h:168
@ STORE_NO_TRANSITION_HANDLE_COW
Definition: objects.h:169
@ STORE_TRANSITION_HOLEY_SMI_TO_DOUBLE
Definition: objects.h:159
@ STORE_TRANSITION_HOLEY_DOUBLE_TO_OBJECT
Definition: objects.h:160
@ STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT
Definition: objects.h:162
@ STORE_TRANSITION_SMI_TO_DOUBLE
Definition: objects.h:156
@ STORE_TRANSITION_SMI_TO_OBJECT
Definition: objects.h:155
@ STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_OBJECT
Definition: objects.h:165
@ STANDARD_STORE
Definition: objects.h:154
static bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode)
Definition: objects.h:209
const int kIntptrSize
Definition: globals.h:128
int ExtraICState
Definition: objects.h:305
const int kElementsKindCount
Definition: elements-kind.h:66
kSerializedDataOffset Object
Definition: objects-inl.h:5322
const uint32_t kNotInternalizedTag
Definition: objects.h:550
kSerializedDataOffset kPrototypeTemplateOffset kIndexedPropertyHandlerOffset instance_call_handler
Definition: objects-inl.h:5333
const uint32_t kStringTag
Definition: objects.h:544
TypeImpl< HeapTypeConfig > HeapType
Definition: list.h:191
@ OBJECT_TEMPLATE_INFO_TYPE
Definition: objects.h:704
@ INTERCEPTOR_INFO_TYPE
Definition: objects.h:701
@ FIRST_FIXED_TYPED_ARRAY_TYPE
Definition: objects.h:763
@ EXTERNAL_STRING_TYPE
Definition: objects.h:642
@ LAST_NONCALLABLE_SPEC_OBJECT_TYPE
Definition: objects.h:785
@ JS_REGEXP_TYPE
Definition: objects.h:748
@ SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE
Definition: objects.h:623
@ SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE
Definition: objects.h:626
@ NUM_OF_CALLABLE_SPEC_OBJECT_TYPES
Definition: objects.h:788
@ FIXED_UINT8_ARRAY_TYPE
Definition: objects.h:684
@ SLICED_STRING_TYPE
Definition: objects.h:638
@ JS_VALUE_TYPE
Definition: objects.h:728
@ JS_DATE_TYPE
Definition: objects.h:730
@ JS_GLOBAL_PROXY_TYPE
Definition: objects.h:737
@ FIRST_UNIQUE_NAME_TYPE
Definition: objects.h:756
@ DECLARED_ACCESSOR_INFO_TYPE
Definition: objects.h:697
@ FIRST_NONCALLABLE_SPEC_OBJECT_TYPE
Definition: objects.h:784
@ FIRST_JS_PROXY_TYPE
Definition: objects.h:778
@ FIXED_DOUBLE_ARRAY_TYPE
Definition: objects.h:692
@ JS_ARRAY_TYPE
Definition: objects.h:738
@ DECLARED_ACCESSOR_DESCRIPTOR_TYPE
Definition: objects.h:696
@ FIXED_ARRAY_TYPE
Definition: objects.h:717
@ JS_MODULE_TYPE
Definition: objects.h:734
@ JS_OBJECT_TYPE
Definition: objects.h:731
@ JS_TYPED_ARRAY_TYPE
Definition: objects.h:740
@ CONS_ONE_BYTE_STRING_TYPE
Definition: objects.h:636
@ FIRST_NONSTRING_TYPE
Definition: objects.h:758
@ JS_DATA_VIEW_TYPE
Definition: objects.h:741
@ FIXED_INT8_ARRAY_TYPE
Definition: objects.h:683
@ LAST_NAME_TYPE
Definition: objects.h:755
@ PROPERTY_CELL_TYPE
Definition: objects.h:665
@ TYPE_SWITCH_INFO_TYPE
Definition: objects.h:706
@ FREE_SPACE_TYPE
Definition: objects.h:673
@ JS_GENERATOR_OBJECT_TYPE
Definition: objects.h:733
@ EXTERNAL_FLOAT32_ARRAY_TYPE
Definition: objects.h:680
@ EXTERNAL_UINT32_ARRAY_TYPE
Definition: objects.h:679
@ EXTERNAL_FLOAT64_ARRAY_TYPE
Definition: objects.h:681
@ BYTE_ARRAY_TYPE
Definition: objects.h:672
@ FIXED_INT32_ARRAY_TYPE
Definition: objects.h:687
@ EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:646
@ EXTERNAL_UINT8_ARRAY_TYPE
Definition: objects.h:675
@ FIXED_UINT16_ARRAY_TYPE
Definition: objects.h:686
@ JS_WEAK_SET_TYPE
Definition: objects.h:747
@ ODDBALL_TYPE
Definition: objects.h:663
@ ALLOCATION_MEMENTO_TYPE
Definition: objects.h:708
@ FIRST_SPEC_OBJECT_TYPE
Definition: objects.h:781
@ LAST_SPEC_OBJECT_TYPE
Definition: objects.h:782
@ SLICED_ONE_BYTE_STRING_TYPE
Definition: objects.h:640
@ LAST_JS_RECEIVER_TYPE
Definition: objects.h:773
@ SIGNATURE_INFO_TYPE
Definition: objects.h:705
@ ALLOCATION_SITE_TYPE
Definition: objects.h:707
@ JS_CONTEXT_EXTENSION_OBJECT_TYPE
Definition: objects.h:732
@ FIRST_JS_RECEIVER_TYPE
Definition: objects.h:772
@ MUTABLE_HEAP_NUMBER_TYPE
Definition: objects.h:670
@ LAST_UNIQUE_NAME_TYPE
Definition: objects.h:757
@ FIRST_JS_OBJECT_TYPE
Definition: objects.h:775
@ LAST_JS_OBJECT_TYPE
Definition: objects.h:776
@ LAST_DATA_TYPE
Definition: objects.h:766
@ ONE_BYTE_STRING_TYPE
Definition: objects.h:633
@ HEAP_NUMBER_TYPE
Definition: objects.h:669
@ DEBUG_INFO_TYPE
Definition: objects.h:715
@ EXTERNAL_UINT8_CLAMPED_ARRAY_TYPE
Definition: objects.h:682
@ JS_MAP_ITERATOR_TYPE
Definition: objects.h:745
@ JS_MESSAGE_OBJECT_TYPE
Definition: objects.h:729
@ EXECUTABLE_ACCESSOR_INFO_TYPE
Definition: objects.h:698
@ JS_FUNCTION_TYPE
Definition: objects.h:749
@ JS_FUNCTION_PROXY_TYPE
Definition: objects.h:726
@ FIRST_EXTERNAL_ARRAY_TYPE
Definition: objects.h:760
@ SHARED_FUNCTION_INFO_TYPE
Definition: objects.h:719
@ JS_SET_ITERATOR_TYPE
Definition: objects.h:744
@ EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:620
@ EXTERNAL_INT32_ARRAY_TYPE
Definition: objects.h:678
@ INTERNALIZED_STRING_TYPE
Definition: objects.h:612
@ FIRST_NAME_TYPE
Definition: objects.h:754
@ ACCESSOR_PAIR_TYPE
Definition: objects.h:699
@ FUNCTION_TEMPLATE_INFO_TYPE
Definition: objects.h:703
@ ALIASED_ARGUMENTS_ENTRY_TYPE
Definition: objects.h:713
@ JS_GLOBAL_OBJECT_TYPE
Definition: objects.h:735
@ CALL_HANDLER_INFO_TYPE
Definition: objects.h:702
@ FIXED_FLOAT32_ARRAY_TYPE
Definition: objects.h:689
@ SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:653
@ EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE
Definition: objects.h:618
@ SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:629
@ LAST_FIXED_TYPED_ARRAY_TYPE
Definition: objects.h:764
@ EXTERNAL_INTERNALIZED_STRING_TYPE
Definition: objects.h:616
@ EXTERNAL_INT8_ARRAY_TYPE
Definition: objects.h:674
@ CONS_STRING_TYPE
Definition: objects.h:635
@ CODE_CACHE_TYPE
Definition: objects.h:710
@ JS_ARRAY_BUFFER_TYPE
Definition: objects.h:739
@ JS_PROXY_TYPE
Definition: objects.h:727
@ FIXED_UINT32_ARRAY_TYPE
Definition: objects.h:688
@ EXTERNAL_ONE_BYTE_STRING_TYPE
Definition: objects.h:644
@ SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE
Definition: objects.h:651
@ ACCESS_CHECK_INFO_TYPE
Definition: objects.h:700
@ FIXED_UINT8_CLAMPED_ARRAY_TYPE
Definition: objects.h:691
@ JS_BUILTINS_OBJECT_TYPE
Definition: objects.h:736
@ BREAK_POINT_INFO_TYPE
Definition: objects.h:716
@ CONSTANT_POOL_ARRAY_TYPE
Definition: objects.h:718
@ ONE_BYTE_INTERNALIZED_STRING_TYPE
Definition: objects.h:614
@ FIXED_FLOAT64_ARRAY_TYPE
Definition: objects.h:690
@ POLYMORPHIC_CODE_CACHE_TYPE
Definition: objects.h:711
@ LAST_JS_PROXY_TYPE
Definition: objects.h:779
@ FIXED_INT16_ARRAY_TYPE
Definition: objects.h:685
@ FOREIGN_TYPE
Definition: objects.h:671
@ EXTERNAL_INT16_ARRAY_TYPE
Definition: objects.h:676
@ EXTERNAL_UINT16_ARRAY_TYPE
Definition: objects.h:677
@ SHORT_EXTERNAL_STRING_TYPE
Definition: objects.h:649
@ TYPE_FEEDBACK_INFO_TYPE
Definition: objects.h:712
@ JS_WEAK_MAP_TYPE
Definition: objects.h:746
@ LAST_EXTERNAL_ARRAY_TYPE
Definition: objects.h:761
@ SLOPPY_ARGUMENTS_ELEMENTS
Definition: elements-kind.h:31
@ FAST_HOLEY_SMI_ELEMENTS
Definition: elements-kind.h:17
bool IsFastDoubleElementsKind(ElementsKind kind)
@ kCacheOnReceiver
Definition: globals.h:488
int LinearSearch(T *array, Name *name, int len, int valid_entries)
Definition: objects-inl.h:2799
const uint32_t kOneByteStringTag
Definition: objects.h:557
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kDoNotCacheBit start_position_and_type
Definition: objects-inl.h:5431
const int kVariableSizeSentinel
Definition: objects.h:309
@ FAST_STRING_TRAVERSAL
Definition: objects.h:8338
@ ROBUST_STRING_TRAVERSAL
Definition: objects.h:8338
static bool IsGrowStoreMode(KeyedAccessStoreMode store_mode)
Definition: objects.h:228
const int kShortSize
Definition: globals.h:123
@ ODD_MARKING_PARITY
Definition: objects.h:299
@ EVEN_MARKING_PARITY
Definition: objects.h:300
@ NO_MARKING_PARITY
Definition: objects.h:298
kFeedbackVectorOffset kHiddenPrototypeBit read_only_prototype
Definition: objects-inl.h:5423
const int kStubMinorKeyBits
Definition: objects.h:314
const int kInt64Size
Definition: globals.h:126
const Register pc
const uint32_t kShortExternalStringMask
Definition: objects.h:589
OStream & operator<<(OStream &os, const BasicBlockProfiler &p)
static bool IsShortcutCandidate(int type)
Definition: objects.h:605
static OStream & PrintUC16(OStream &os, uint16_t c, bool(*pred)(uint16_t))
Definition: ostreams.cc:173
static const int kInvalidEnumCacheSentinel
const int kInt32Size
Definition: globals.h:125
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kDoNotCacheBit kIsTopLevelBit allows_lazy_compilation_without_context
Definition: objects-inl.h:5440
const int kSignMask
const uint32_t kStringRepresentationMask
Definition: objects.h:561
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kDoNotCacheBit kIsTopLevelBit compiler_hints
Definition: objects-inl.h:5439
byte * Address
Definition: globals.h:101
bool IsFastElementsKind(ElementsKind kind)
const intptr_t kCodeAlignmentMask
Definition: globals.h:241
const uint32_t kSlicedNotConsMask
Definition: objects.h:579
kSerializedDataOffset kPrototypeTemplateOffset kIndexedPropertyHandlerOffset kInstanceCallHandlerOffset kInternalFieldCountOffset dependent_code
Definition: objects-inl.h:5353
static uint32_t Hash(RegisteredExtension *extension)
@ NOT_CONTEXTUAL
Definition: objects.h:174
static bool HasSourceCode(Heap *heap, SharedFunctionInfo *info)
const uint32_t kShortcutTypeTag
Definition: objects.h:603
kFeedbackVectorOffset hidden_prototype
Definition: objects-inl.h:5418
const int kIntSize
Definition: globals.h:124
bool IsDictionaryElementsKind(ElementsKind kind)
Definition: elements-kind.h:85
const uint32_t kOneByteDataHintMask
Definition: objects.h:584
const int kSmiValueSize
Definition: v8.h:5806
kExpectedNofPropertiesOffset kFunctionTokenPositionOffset opt_count_and_bailout_reason
Definition: objects-inl.h:5520
@ DEBUG_PREPARE_STEP_IN
Definition: objects.h:270
const uint32_t kIsIndirectStringTag
Definition: objects.h:569
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit do_not_cache
Definition: objects-inl.h:5427
const uint32_t kInternalizedTag
Definition: objects.h:551
const int kStubMajorKeyBits
Definition: objects.h:313
static void RoundUp(Vector< char > buffer, int *length, int *decimal_point)
Definition: fixed-dtoa.cc:171
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
const int kBitsPerByte
Definition: globals.h:162
AccessorDescriptorType
Definition: objects.h:10154
@ kDescriptorBitmaskCompare
Definition: objects.h:10155
@ kDescriptorPointerDereference
Definition: objects.h:10159
@ kDescriptorPointerShift
Definition: objects.h:10160
@ kDescriptorObjectDereference
Definition: objects.h:10158
@ kDescriptorPrimitiveValue
Definition: objects.h:10157
@ kDescriptorReturnObject
Definition: objects.h:10161
@ kDescriptorPointerCompare
Definition: objects.h:10156
static const int kDescriptorIndexBitCount
const uint32_t kIsNotInternalizedMask
Definition: objects.h:549
const uint32_t kOneByteDataHintTag
Definition: objects.h:585
bool IsFixedTypedArrayElementsKind(ElementsKind kind)
kSerializedDataOffset prototype_template
Definition: objects-inl.h:5322
static bool IsMinusZero(double value)
Definition: conversions.h:154
uint16_t uc16
Definition: globals.h:184
const int MB
Definition: globals.h:107
bool IsFastSmiElementsKind(ElementsKind kind)
const uint32_t kIsNotStringMask
Definition: objects.h:543
static KeyedAccessStoreMode GetGrowStoreMode(KeyedAccessStoreMode store_mode)
Definition: objects.h:199
const int kExternalArrayTypeCount
Definition: objects.h:791
int32_t uc32
Definition: globals.h:185
int Search(T *array, Name *name, int valid_entries)
Definition: objects-inl.h:2822
bool IsAligned(T value, U alignment)
Definition: utils.h:123
@ ACCESSOR_GETTER
Definition: objects.h:1558
@ ACCESSOR_SETTER
Definition: objects.h:1559
const int kCharSize
Definition: globals.h:122
@ OWN_DESCRIPTORS
Definition: objects.h:287
@ ALL_DESCRIPTORS
Definition: objects.h:286
@ UNINITIALIZED
Definition: globals.h:446
const uint32_t kIsIndirectStringMask
Definition: objects.h:568
bool IsFastObjectElementsKind(ElementsKind kind)
PropertyNormalizationMode
Definition: objects.h:247
@ KEEP_INOBJECT_PROPERTIES
Definition: objects.h:249
@ CLEAR_INOBJECT_PROPERTIES
Definition: objects.h:248
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
DeclaredAccessorDescriptorDataType
Definition: v8.h:3937
ExternalArrayType
Definition: v8.h:2217
#define DECL_INDEX(name)
Definition: objects.h:4252
#define DECLARE_FUNCTION_ID(ignored1, ignore2, name)
Definition: objects.h:6568
#define DECLARE_CODE_AGE_ENUM(X)
Definition: objects.h:5292
#define FOR_EACH_NUMERIC_FIELD(V)
Definition: objects.h:4230
#define HEAP_OBJECT_TYPE_LIST(V)
Definition: objects.h:883
#define DEFINE_CODE_KIND_ENUM(name)
Definition: objects.h:4955
#define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name)
Definition: objects.h:812
#define STRUCT_LIST(V)
Definition: objects.h:515
#define DECLARE_STRUCT_PREDICATE(NAME, Name, name)
Definition: objects.h:1017
#define DECL_BOOLEAN_ACCESSORS(name)
Definition: objects.h:828
#define DECLARE_CAST(type)
Definition: objects.h:839
#define DECLARE_PRINTER(Name)
Definition: objects.h:874
#define CODE_KIND_LIST(V)
Definition: objects.h:4950
#define DEFINE_ELEMENT_ACCESSORS(name, type)
Definition: objects.h:4814
#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)
Definition: objects.h:800
#define DEFINE_ENTRY_ACCESSORS(name, type)
Definition: objects.h:4833
#define TYPED_ARRAYS(V)
Definition: objects.h:4433
#define FUNCTIONS_WITH_ID_LIST(V)
Definition: objects.h:6542
#define OBJECT_TYPE_LIST(V)
Definition: objects.h:878
#define DECLARE_VERIFIER(Name)
Definition: objects.h:868
#define IS_TYPE_FUNCTION_DECL(type_)
Definition: objects.h:998
#define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size)
Definition: objects.h:4770
#define FIELD_ACCESSORS(name)
Definition: objects.h:4236
#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V)
Definition: objects.h:10684
#define DECLARE_ENUM(enum_item, ignore1, ignore2)
Definition: objects.h:10704
#define DECL_ACCESSORS(name, type)
Definition: objects.h:833
PropertyAttributes
@ NONE
A simple Maybe type, representing an object which may or may not have a value.
Definition: v8.h:890
const Object * value
Definition: objects.h:1238
Brief(const Object *const v)
Definition: objects.h:1237
v8::DeclaredAccessorDescriptorDataType data_type
Definition: objects.h:10178
SourceCodeOf(SharedFunctionInfo *v, int max=-1)
Definition: objects.h:7072
const SharedFunctionInfo * value
Definition: objects.h:7074
#define T(name, string, precedence)
Definition: token.cc:25