v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
objects.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_OBJECTS_H_
29 #define V8_OBJECTS_H_
30 
31 #include "allocation.h"
32 #include "builtins.h"
33 #include "elements-kind.h"
34 #include "list.h"
35 #include "property-details.h"
36 #include "smart-pointers.h"
37 #include "unicode-inl.h"
38 #if V8_TARGET_ARCH_ARM
39 #include "arm/constants-arm.h"
40 #elif V8_TARGET_ARCH_MIPS
41 #include "mips/constants-mips.h"
42 #endif
43 #include "v8checks.h"
44 #include "zone.h"
45 
46 
47 //
48 // Most object types in the V8 JavaScript are described in this file.
49 //
50 // Inheritance hierarchy:
51 // - MaybeObject (an object or a failure)
52 // - Failure (immediate for marking failed operation)
53 // - Object
54 // - Smi (immediate small integer)
55 // - HeapObject (superclass for everything allocated in the heap)
56 // - JSReceiver (suitable for property access)
57 // - JSObject
58 // - JSArray
59 // - JSSet
60 // - JSMap
61 // - JSWeakMap
62 // - JSRegExp
63 // - JSFunction
64 // - JSModule
65 // - GlobalObject
66 // - JSGlobalObject
67 // - JSBuiltinsObject
68 // - JSGlobalProxy
69 // - JSValue
70 // - JSDate
71 // - JSMessageObject
72 // - JSProxy
73 // - JSFunctionProxy
74 // - FixedArrayBase
75 // - ByteArray
76 // - FixedArray
77 // - DescriptorArray
78 // - HashTable
79 // - Dictionary
80 // - SymbolTable
81 // - CompilationCacheTable
82 // - CodeCacheHashTable
83 // - MapCache
84 // - Context
85 // - JSFunctionResultCache
86 // - ScopeInfo
87 // - TransitionArray
88 // - FixedDoubleArray
89 // - ExternalArray
90 // - ExternalPixelArray
91 // - ExternalByteArray
92 // - ExternalUnsignedByteArray
93 // - ExternalShortArray
94 // - ExternalUnsignedShortArray
95 // - ExternalIntArray
96 // - ExternalUnsignedIntArray
97 // - ExternalFloatArray
98 // - String
99 // - SeqString
100 // - SeqAsciiString
101 // - SeqTwoByteString
102 // - SlicedString
103 // - ConsString
104 // - ExternalString
105 // - ExternalAsciiString
106 // - ExternalTwoByteString
107 // - HeapNumber
108 // - Code
109 // - Map
110 // - Oddball
111 // - Foreign
112 // - SharedFunctionInfo
113 // - Struct
114 // - AccessorInfo
115 // - AccessorPair
116 // - AccessCheckInfo
117 // - InterceptorInfo
118 // - CallHandlerInfo
119 // - TemplateInfo
120 // - FunctionTemplateInfo
121 // - ObjectTemplateInfo
122 // - Script
123 // - SignatureInfo
124 // - TypeSwitchInfo
125 // - DebugInfo
126 // - BreakPointInfo
127 // - CodeCache
128 //
129 // Formats of Object*:
130 // Smi: [31 bit signed int] 0
131 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
132 // Failure: [30 bit signed int] 11
133 
134 namespace v8 {
135 namespace internal {
136 
140 };
141 
145 };
146 
147 // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
149 
150 
151 // PropertyNormalizationMode is used to specify whether to keep
152 // inobject properties when normalizing properties of a JSObject.
156 };
157 
158 
159 // NormalizedMapSharingMode is used to specify whether a map may be shared
160 // by different objects with normalized properties.
164 };
165 
166 
167 // Indicates whether a get method should implicitly create the object looked up.
171 };
172 
173 
174 // Indicates whether transitions can be added to a source map or not.
178 };
179 
180 
181 // Indicates whether the transition is simple: the target map of the transition
182 // either extends the current map with a new property, or it modifies the
183 // property that was added last to the current map.
187 };
188 
189 
190 // Indicates whether we are only interested in the descriptors of a particular
191 // map, or in all descriptors in the descriptor array.
195 };
196 
197 
198 // Instance size sentinel for objects of variable size.
199 const int kVariableSizeSentinel = 0;
200 
201 const int kStubMajorKeyBits = 6;
203 
204 // All Maps have a field instance_type containing a InstanceType.
205 // It describes the type of the instances.
206 //
207 // As an example, a JavaScript object is a heap object and its map
208 // instance_type is JS_OBJECT_TYPE.
209 //
210 // The names of the string instance types are intended to systematically
211 // mirror their encoding in the instance_type field of the map. The default
212 // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII
213 // encoding is mentioned explicitly in the name. Likewise, the default
214 // representation is considered sequential. It is not mentioned in the
215 // name. The other representations (e.g. CONS, EXTERNAL) are explicitly
216 // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a
217 // symbol) or a STRING_TYPE (if it is not a symbol).
218 //
219 // NOTE: The following things are some that depend on the string types having
220 // instance_types that are less than those of all other types:
221 // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
222 // Object::IsString.
223 //
224 // NOTE: Everything following JS_VALUE_TYPE is considered a
225 // JSObject for GC purposes. The first four entries here have typeof
226 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
227 #define INSTANCE_TYPE_LIST_ALL(V) \
228  V(SYMBOL_TYPE) \
229  V(ASCII_SYMBOL_TYPE) \
230  V(CONS_SYMBOL_TYPE) \
231  V(CONS_ASCII_SYMBOL_TYPE) \
232  V(EXTERNAL_SYMBOL_TYPE) \
233  V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
234  V(EXTERNAL_ASCII_SYMBOL_TYPE) \
235  V(SHORT_EXTERNAL_SYMBOL_TYPE) \
236  V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
237  V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
238  V(STRING_TYPE) \
239  V(ASCII_STRING_TYPE) \
240  V(CONS_STRING_TYPE) \
241  V(CONS_ASCII_STRING_TYPE) \
242  V(SLICED_STRING_TYPE) \
243  V(EXTERNAL_STRING_TYPE) \
244  V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
245  V(EXTERNAL_ASCII_STRING_TYPE) \
246  V(SHORT_EXTERNAL_STRING_TYPE) \
247  V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
248  V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
249  V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
250  \
251  V(MAP_TYPE) \
252  V(CODE_TYPE) \
253  V(ODDBALL_TYPE) \
254  V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
255  \
256  V(HEAP_NUMBER_TYPE) \
257  V(FOREIGN_TYPE) \
258  V(BYTE_ARRAY_TYPE) \
259  V(FREE_SPACE_TYPE) \
260  /* Note: the order of these external array */ \
261  /* types is relied upon in */ \
262  /* Object::IsExternalArray(). */ \
263  V(EXTERNAL_BYTE_ARRAY_TYPE) \
264  V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
265  V(EXTERNAL_SHORT_ARRAY_TYPE) \
266  V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
267  V(EXTERNAL_INT_ARRAY_TYPE) \
268  V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
269  V(EXTERNAL_FLOAT_ARRAY_TYPE) \
270  V(EXTERNAL_PIXEL_ARRAY_TYPE) \
271  V(FILLER_TYPE) \
272  \
273  V(ACCESSOR_INFO_TYPE) \
274  V(ACCESSOR_PAIR_TYPE) \
275  V(ACCESS_CHECK_INFO_TYPE) \
276  V(INTERCEPTOR_INFO_TYPE) \
277  V(CALL_HANDLER_INFO_TYPE) \
278  V(FUNCTION_TEMPLATE_INFO_TYPE) \
279  V(OBJECT_TEMPLATE_INFO_TYPE) \
280  V(SIGNATURE_INFO_TYPE) \
281  V(TYPE_SWITCH_INFO_TYPE) \
282  V(SCRIPT_TYPE) \
283  V(CODE_CACHE_TYPE) \
284  V(POLYMORPHIC_CODE_CACHE_TYPE) \
285  V(TYPE_FEEDBACK_INFO_TYPE) \
286  V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
287  \
288  V(FIXED_ARRAY_TYPE) \
289  V(FIXED_DOUBLE_ARRAY_TYPE) \
290  V(SHARED_FUNCTION_INFO_TYPE) \
291  \
292  V(JS_MESSAGE_OBJECT_TYPE) \
293  \
294  V(JS_VALUE_TYPE) \
295  V(JS_DATE_TYPE) \
296  V(JS_OBJECT_TYPE) \
297  V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
298  V(JS_MODULE_TYPE) \
299  V(JS_GLOBAL_OBJECT_TYPE) \
300  V(JS_BUILTINS_OBJECT_TYPE) \
301  V(JS_GLOBAL_PROXY_TYPE) \
302  V(JS_ARRAY_TYPE) \
303  V(JS_PROXY_TYPE) \
304  V(JS_WEAK_MAP_TYPE) \
305  V(JS_REGEXP_TYPE) \
306  \
307  V(JS_FUNCTION_TYPE) \
308  V(JS_FUNCTION_PROXY_TYPE) \
309 
310 #ifdef ENABLE_DEBUGGER_SUPPORT
311 #define INSTANCE_TYPE_LIST_DEBUGGER(V) \
312  V(DEBUG_INFO_TYPE) \
313  V(BREAK_POINT_INFO_TYPE)
314 #else
315 #define INSTANCE_TYPE_LIST_DEBUGGER(V)
316 #endif
317 
318 #define INSTANCE_TYPE_LIST(V) \
319  INSTANCE_TYPE_LIST_ALL(V) \
320  INSTANCE_TYPE_LIST_DEBUGGER(V)
321 
322 
323 // Since string types are not consecutive, this macro is used to
324 // iterate over them.
325 #define STRING_TYPE_LIST(V) \
326  V(SYMBOL_TYPE, \
327  kVariableSizeSentinel, \
328  symbol, \
329  Symbol) \
330  V(ASCII_SYMBOL_TYPE, \
331  kVariableSizeSentinel, \
332  ascii_symbol, \
333  AsciiSymbol) \
334  V(CONS_SYMBOL_TYPE, \
335  ConsString::kSize, \
336  cons_symbol, \
337  ConsSymbol) \
338  V(CONS_ASCII_SYMBOL_TYPE, \
339  ConsString::kSize, \
340  cons_ascii_symbol, \
341  ConsAsciiSymbol) \
342  V(EXTERNAL_SYMBOL_TYPE, \
343  ExternalTwoByteString::kSize, \
344  external_symbol, \
345  ExternalSymbol) \
346  V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
347  ExternalTwoByteString::kSize, \
348  external_symbol_with_ascii_data, \
349  ExternalSymbolWithAsciiData) \
350  V(EXTERNAL_ASCII_SYMBOL_TYPE, \
351  ExternalAsciiString::kSize, \
352  external_ascii_symbol, \
353  ExternalAsciiSymbol) \
354  V(SHORT_EXTERNAL_SYMBOL_TYPE, \
355  ExternalTwoByteString::kShortSize, \
356  short_external_symbol, \
357  ShortExternalSymbol) \
358  V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
359  ExternalTwoByteString::kShortSize, \
360  short_external_symbol_with_ascii_data, \
361  ShortExternalSymbolWithAsciiData) \
362  V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
363  ExternalAsciiString::kShortSize, \
364  short_external_ascii_symbol, \
365  ShortExternalAsciiSymbol) \
366  V(STRING_TYPE, \
367  kVariableSizeSentinel, \
368  string, \
369  String) \
370  V(ASCII_STRING_TYPE, \
371  kVariableSizeSentinel, \
372  ascii_string, \
373  AsciiString) \
374  V(CONS_STRING_TYPE, \
375  ConsString::kSize, \
376  cons_string, \
377  ConsString) \
378  V(CONS_ASCII_STRING_TYPE, \
379  ConsString::kSize, \
380  cons_ascii_string, \
381  ConsAsciiString) \
382  V(SLICED_STRING_TYPE, \
383  SlicedString::kSize, \
384  sliced_string, \
385  SlicedString) \
386  V(SLICED_ASCII_STRING_TYPE, \
387  SlicedString::kSize, \
388  sliced_ascii_string, \
389  SlicedAsciiString) \
390  V(EXTERNAL_STRING_TYPE, \
391  ExternalTwoByteString::kSize, \
392  external_string, \
393  ExternalString) \
394  V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
395  ExternalTwoByteString::kSize, \
396  external_string_with_ascii_data, \
397  ExternalStringWithAsciiData) \
398  V(EXTERNAL_ASCII_STRING_TYPE, \
399  ExternalAsciiString::kSize, \
400  external_ascii_string, \
401  ExternalAsciiString) \
402  V(SHORT_EXTERNAL_STRING_TYPE, \
403  ExternalTwoByteString::kShortSize, \
404  short_external_string, \
405  ShortExternalString) \
406  V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
407  ExternalTwoByteString::kShortSize, \
408  short_external_string_with_ascii_data, \
409  ShortExternalStringWithAsciiData) \
410  V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
411  ExternalAsciiString::kShortSize, \
412  short_external_ascii_string, \
413  ShortExternalAsciiString)
414 
415 // A struct is a simple object a set of object-valued fields. Including an
416 // object type in this causes the compiler to generate most of the boilerplate
417 // code for the class including allocation and garbage collection routines,
418 // casts and predicates. All you need to define is the class, methods and
419 // object verification routines. Easy, no?
420 //
421 // Note that for subtle reasons related to the ordering or numerical values of
422 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
423 // manually.
424 #define STRUCT_LIST_ALL(V) \
425  V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
426  V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
427  V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
428  V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
429  V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
430  V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
431  V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
432  V(SIGNATURE_INFO, SignatureInfo, signature_info) \
433  V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
434  V(SCRIPT, Script, script) \
435  V(CODE_CACHE, CodeCache, code_cache) \
436  V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
437  V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
438  V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry)
439 
440 #ifdef ENABLE_DEBUGGER_SUPPORT
441 #define STRUCT_LIST_DEBUGGER(V) \
442  V(DEBUG_INFO, DebugInfo, debug_info) \
443  V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
444 #else
445 #define STRUCT_LIST_DEBUGGER(V)
446 #endif
447 
448 #define STRUCT_LIST(V) \
449  STRUCT_LIST_ALL(V) \
450  STRUCT_LIST_DEBUGGER(V)
451 
452 // We use the full 8 bits of the instance_type field to encode heap object
453 // instance types. The high-order bit (bit 7) is set if the object is not a
454 // string, and cleared if it is a string.
455 const uint32_t kIsNotStringMask = 0x80;
456 const uint32_t kStringTag = 0x0;
457 const uint32_t kNotStringTag = 0x80;
458 
459 // Bit 6 indicates that the object is a symbol (if set) or not (if cleared).
460 // There are not enough types that the non-string types (with bit 7 set) can
461 // have bit 6 set too.
462 const uint32_t kIsSymbolMask = 0x40;
463 const uint32_t kNotSymbolTag = 0x0;
464 const uint32_t kSymbolTag = 0x40;
465 
466 // If bit 7 is clear then bit 2 indicates whether the string consists of
467 // two-byte characters or one-byte characters.
468 const uint32_t kStringEncodingMask = 0x4;
469 const uint32_t kTwoByteStringTag = 0x0;
470 const uint32_t kAsciiStringTag = 0x4;
471 
472 // If bit 7 is clear, the low-order 2 bits indicate the representation
473 // of the string.
474 const uint32_t kStringRepresentationMask = 0x03;
480 };
481 const uint32_t kIsIndirectStringMask = 0x1;
482 const uint32_t kIsIndirectStringTag = 0x1;
489 
490 // Use this mask to distinguish between cons and slice only after making
491 // sure that the string is one of the two (an indirect string).
494 
495 // If bit 7 is clear, then bit 3 indicates whether this two-byte
496 // string actually contains ASCII data.
497 const uint32_t kAsciiDataHintMask = 0x08;
498 const uint32_t kAsciiDataHintTag = 0x08;
499 
500 // If bit 7 is clear and string representation indicates an external string,
501 // then bit 4 indicates whether the data pointer is cached.
502 const uint32_t kShortExternalStringMask = 0x10;
503 const uint32_t kShortExternalStringTag = 0x10;
504 
505 
506 // A ConsString with an empty string as the right side is a candidate
507 // for being shortcut by the garbage collector unless it is a
508 // symbol. It's not common to have non-flat symbols, so we do not
509 // shortcut them thereby avoiding turning symbols into strings. See
510 // heap.cc and mark-compact.cc.
511 const uint32_t kShortcutTypeMask =
513  kIsSymbolMask |
516 
517 
519  // String types.
552  // LAST_STRING_TYPE
555 
556  // Objects allocated in their own spaces (never in new space).
557  MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
561 
562  // "Data", objects that cannot contain non-map-word pointers to heap
563  // objects.
568  EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
576  EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
578  FILLER_TYPE, // LAST_DATA_TYPE
579 
580  // Structs.
595  // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT
596  // is defined. However as include/v8.h contain some of the instance type
597  // constants always having them avoids them getting different numbers
598  // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not.
601 
604 
606 
607  // All the following types are subtypes of JSReceiver, which corresponds to
608  // objects in the JS sense. The first and the last type in this range are
609  // the two forms of function. This organization enables using the same
610  // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
611  // NONCALLABLE_JS_OBJECT range.
612  JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
613  JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
614 
615  JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
627 
629 
630  JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
631 
632  // Pseudo-types
633  FIRST_TYPE = 0x0,
637  // Boundaries for testing for an external array.
640  // Boundary for promotion to old data space/old pointer space.
642  // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
643  // Note that there is no range for JSObject or JSProxy, since their subtypes
644  // are not continuous in this enum! The enum ranges instead reflect the
645  // external class names, where proxies are treated as either ordinary objects,
646  // or functions.
649  // Boundaries for testing the types represented as JSObject
652  // Boundaries for testing the types represented as JSProxy
655  // Boundaries for testing whether the type is a JavaScript object.
658  // Boundaries for testing the types for which typeof is "object".
661  // Note that the types for which typeof is "function" are not continuous.
662  // Define this so that we can put assertions on discrete checks.
664 };
665 
668 
673 
674 
675 #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \
676  V(FAST_ELEMENTS_SUB_TYPE) \
677  V(DICTIONARY_ELEMENTS_SUB_TYPE) \
678  V(FAST_PROPERTIES_SUB_TYPE) \
679  V(DICTIONARY_PROPERTIES_SUB_TYPE) \
680  V(MAP_CODE_CACHE_SUB_TYPE) \
681  V(SCOPE_INFO_SUB_TYPE) \
682  V(SYMBOL_TABLE_SUB_TYPE) \
683  V(DESCRIPTOR_ARRAY_SUB_TYPE) \
684  V(TRANSITION_ARRAY_SUB_TYPE)
685 
687 #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name,
689 #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE
690  LAST_FIXED_ARRAY_SUB_TYPE = TRANSITION_ARRAY_SUB_TYPE
691 };
692 
693 
695  LESS = -1,
696  EQUAL = 0,
697  GREATER = 1,
698 
700 };
701 
702 
703 #define DECL_BOOLEAN_ACCESSORS(name) \
704  inline bool name(); \
705  inline void set_##name(bool value); \
706 
707 
708 #define DECL_ACCESSORS(name, type) \
709  inline type* name(); \
710  inline void set_##name(type* value, \
711  WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
712 
713 
714 class AccessorPair;
715 class DictionaryElementsAccessor;
716 class ElementsAccessor;
717 class Failure;
718 class FixedArrayBase;
719 class ObjectVisitor;
720 class StringStream;
721 
722 struct ValueInfo : public Malloced {
726  const char* str;
727  double number;
728 };
729 
730 
731 // A template-ized version of the IsXXX functions.
732 template <class C> static inline bool Is(Object* obj);
733 
734 #ifdef VERIFY_HEAP
735 #define DECLARE_VERIFIER(Name) void Name##Verify();
736 #else
737 #define DECLARE_VERIFIER(Name)
738 #endif
739 
740 class MaybeObject BASE_EMBEDDED {
741  public:
742  inline bool IsFailure();
743  inline bool IsRetryAfterGC();
744  inline bool IsOutOfMemory();
745  inline bool IsException();
746  INLINE(bool IsTheHole());
747  inline bool ToObject(Object** obj) {
748  if (IsFailure()) return false;
749  *obj = reinterpret_cast<Object*>(this);
750  return true;
751  }
753  ASSERT(IsFailure());
754  return reinterpret_cast<Failure*>(this);
755  }
757  ASSERT(!IsFailure());
758  return reinterpret_cast<Object*>(this);
759  }
761  CHECK(!IsFailure());
762  return reinterpret_cast<Object*>(this);
763  }
764 
765  template<typename T>
766  inline bool To(T** obj) {
767  if (IsFailure()) return false;
768  *obj = T::cast(reinterpret_cast<Object*>(this));
769  return true;
770  }
771 
772 #ifdef OBJECT_PRINT
773  // Prints this object with details.
774  inline void Print() {
775  Print(stdout);
776  }
777  inline void PrintLn() {
778  PrintLn(stdout);
779  }
780  void Print(FILE* out);
781  void PrintLn(FILE* out);
782 #endif
783 #ifdef VERIFY_HEAP
784  // Verifies the object.
785  void Verify();
786 #endif
787 };
788 
789 
790 #define OBJECT_TYPE_LIST(V) \
791  V(Smi) \
792  V(HeapObject) \
793  V(Number) \
794 
795 #define HEAP_OBJECT_TYPE_LIST(V) \
796  V(HeapNumber) \
797  V(String) \
798  V(Symbol) \
799  V(SeqString) \
800  V(ExternalString) \
801  V(ConsString) \
802  V(SlicedString) \
803  V(ExternalTwoByteString) \
804  V(ExternalAsciiString) \
805  V(SeqTwoByteString) \
806  V(SeqAsciiString) \
807  \
808  V(ExternalArray) \
809  V(ExternalByteArray) \
810  V(ExternalUnsignedByteArray) \
811  V(ExternalShortArray) \
812  V(ExternalUnsignedShortArray) \
813  V(ExternalIntArray) \
814  V(ExternalUnsignedIntArray) \
815  V(ExternalFloatArray) \
816  V(ExternalDoubleArray) \
817  V(ExternalPixelArray) \
818  V(ByteArray) \
819  V(FreeSpace) \
820  V(JSReceiver) \
821  V(JSObject) \
822  V(JSContextExtensionObject) \
823  V(JSModule) \
824  V(Map) \
825  V(DescriptorArray) \
826  V(TransitionArray) \
827  V(DeoptimizationInputData) \
828  V(DeoptimizationOutputData) \
829  V(TypeFeedbackCells) \
830  V(FixedArray) \
831  V(FixedDoubleArray) \
832  V(Context) \
833  V(NativeContext) \
834  V(ScopeInfo) \
835  V(JSFunction) \
836  V(Code) \
837  V(Oddball) \
838  V(SharedFunctionInfo) \
839  V(JSValue) \
840  V(JSDate) \
841  V(JSMessageObject) \
842  V(StringWrapper) \
843  V(Foreign) \
844  V(Boolean) \
845  V(JSArray) \
846  V(JSProxy) \
847  V(JSFunctionProxy) \
848  V(JSSet) \
849  V(JSMap) \
850  V(JSWeakMap) \
851  V(JSRegExp) \
852  V(HashTable) \
853  V(Dictionary) \
854  V(SymbolTable) \
855  V(JSFunctionResultCache) \
856  V(NormalizedMapCache) \
857  V(CompilationCacheTable) \
858  V(CodeCacheHashTable) \
859  V(PolymorphicCodeCacheHashTable) \
860  V(MapCache) \
861  V(Primitive) \
862  V(GlobalObject) \
863  V(JSGlobalObject) \
864  V(JSBuiltinsObject) \
865  V(JSGlobalProxy) \
866  V(UndetectableObject) \
867  V(AccessCheckNeeded) \
868  V(JSGlobalPropertyCell) \
869 
870 
871 class JSReceiver;
872 
873 // Object is the abstract superclass for all classes in the
874 // object hierarchy.
875 // Object does not use any virtual functions to avoid the
876 // allocation of the C++ vtable.
877 // Since Smi and Failure are subclasses of Object no
878 // data members can be present in Object.
879 class Object : public MaybeObject {
880  public:
881  // Type testing.
882  bool IsObject() { return true; }
883 
884 #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_();
887 #undef IS_TYPE_FUNCTION_DECL
888 
889  inline bool IsFixedArrayBase();
890 
891  // Returns true if this object is an instance of the specified
892  // function template.
893  inline bool IsInstanceOf(FunctionTemplateInfo* type);
894 
895  inline bool IsStruct();
896 #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
898 #undef DECLARE_STRUCT_PREDICATE
899 
900  INLINE(bool IsSpecObject());
901  INLINE(bool IsSpecFunction());
902 
903  // Oddball testing.
904  INLINE(bool IsUndefined());
905  INLINE(bool IsNull());
906  INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation.
907  INLINE(bool IsTrue());
908  INLINE(bool IsFalse());
909  inline bool IsArgumentsMarker();
910  inline bool NonFailureIsHeapObject();
911 
912  // Filler objects (fillers and free space objects).
913  inline bool IsFiller();
914 
915  // Extract the number.
916  inline double Number();
917  inline bool IsNaN();
918 
919  // Returns true if the object is of the correct type to be used as a
920  // implementation of a JSObject's elements.
921  inline bool HasValidElements();
922 
923  inline bool HasSpecificClassOf(String* name);
924 
925  MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9.
926  Object* ToBoolean(); // ECMA-262 9.2.
927 
928  // Convert to a JSObject if needed.
929  // native_context is used when creating wrapper object.
930  MUST_USE_RESULT MaybeObject* ToObject(Context* native_context);
931 
932  // Converts this to a Smi if possible.
933  // Failure is returned otherwise.
934  MUST_USE_RESULT inline MaybeObject* ToSmi();
935 
936  void Lookup(String* name, LookupResult* result);
937 
938  // Property access.
939  MUST_USE_RESULT inline MaybeObject* GetProperty(String* key);
940  MUST_USE_RESULT inline MaybeObject* GetProperty(
941  String* key,
942  PropertyAttributes* attributes);
944  Object* receiver,
945  String* key,
946  PropertyAttributes* attributes);
947 
948  static Handle<Object> GetProperty(Handle<Object> object,
949  Handle<Object> receiver,
950  LookupResult* result,
951  Handle<String> key,
952  PropertyAttributes* attributes);
953 
954  MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver,
955  LookupResult* result,
956  String* key,
957  PropertyAttributes* attributes);
958 
959  MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
960  JSReceiver* getter);
961 
962  static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
963  MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index);
964  // For use when we know that no exception can be thrown.
965  inline Object* GetElementNoExceptionThrown(uint32_t index);
966  MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver,
967  uint32_t index);
968 
969  // Return the object's prototype (might be Heap::null_value()).
970  Object* GetPrototype();
971 
972  // Returns the permanent hash code associated with this object depending on
973  // the actual object type. Might return a failure in case no hash was
974  // created yet or GC was caused by creation.
976 
977  // Checks whether this object has the same value as the given one. This
978  // function is implemented according to ES5, section 9.12 and can be used
979  // to implement the Harmony "egal" function.
980  bool SameValue(Object* other);
981 
982  // Tries to convert an object to an array index. Returns true and sets
983  // the output parameter if it succeeds.
984  inline bool ToArrayIndex(uint32_t* index);
985 
986  // Returns true if this is a JSValue containing a string and the index is
987  // < the length of the string. Used to implement [] on strings.
988  inline bool IsStringObjectWithCharacterAt(uint32_t index);
989 
990 #ifdef VERIFY_HEAP
991  // Verify a pointer is a valid object pointer.
992  static void VerifyPointer(Object* p);
993 #endif
994 
995  inline void VerifyApiCallResultType();
996 
997  // Prints this object without details.
998  inline void ShortPrint() {
999  ShortPrint(stdout);
1000  }
1001  void ShortPrint(FILE* out);
1002 
1003  // Prints this object without details to a message accumulator.
1004  void ShortPrint(StringStream* accumulator);
1005 
1006  // Casting: This cast is only needed to satisfy macros in objects-inl.h.
1007  static Object* cast(Object* value) { return value; }
1008 
1009  // Layout description.
1010  static const int kHeaderSize = 0; // Object does not take up any space.
1011 
1012  private:
1013  DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
1014 };
1015 
1016 
1017 // Smi represents integer Numbers that can be stored in 31 bits.
1018 // Smis are immediate which means they are NOT allocated in the heap.
1019 // The this pointer has the following format: [31 bit signed int] 0
1020 // For long smis it has the following format:
1021 // [32 bit signed int] [31 bits zero padding] 0
1022 // Smi stands for small integer.
1023 class Smi: public Object {
1024  public:
1025  // Returns the integer value.
1026  inline int value();
1027 
1028  // Convert a value to a Smi object.
1029  static inline Smi* FromInt(int value);
1030 
1031  static inline Smi* FromIntptr(intptr_t value);
1032 
1033  // Returns whether value can be represented in a Smi.
1034  static inline bool IsValid(intptr_t value);
1035 
1036  // Casting.
1037  static inline Smi* cast(Object* object);
1038 
1039  // Dispatched behavior.
1040  inline void SmiPrint() {
1041  SmiPrint(stdout);
1042  }
1043  void SmiPrint(FILE* out);
1044  void SmiPrint(StringStream* accumulator);
1045 
1047 
1048  static const int kMinValue =
1049  (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
1050  static const int kMaxValue = -(kMinValue + 1);
1051 
1052  private:
1053  DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1054 };
1055 
1056 
1057 // Failure is used for reporting out of memory situations and
1058 // propagating exceptions through the runtime system. Failure objects
1059 // are transient and cannot occur as part of the object graph.
1060 //
1061 // Failures are a single word, encoded as follows:
1062 // +-------------------------+---+--+--+
1063 // |.........unused..........|sss|tt|11|
1064 // +-------------------------+---+--+--+
1065 // 7 6 4 32 10
1066 //
1067 //
1068 // The low two bits, 0-1, are the failure tag, 11. The next two bits,
1069 // 2-3, are a failure type tag 'tt' with possible values:
1070 // 00 RETRY_AFTER_GC
1071 // 01 EXCEPTION
1072 // 10 INTERNAL_ERROR
1073 // 11 OUT_OF_MEMORY_EXCEPTION
1074 //
1075 // The next three bits, 4-6, are an allocation space tag 'sss'. The
1076 // allocation space tag is 000 for all failure types except
1077 // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the
1078 // allocation spaces (the encoding is found in globals.h).
1079 
1080 // Failure type tag info.
1081 const int kFailureTypeTagSize = 2;
1082 const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
1083 
1084 class Failure: public MaybeObject {
1085  public:
1086  // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
1087  enum Type {
1088  RETRY_AFTER_GC = 0,
1089  EXCEPTION = 1, // Returning this marker tells the real exception
1090  // is in Isolate::pending_exception.
1091  INTERNAL_ERROR = 2,
1092  OUT_OF_MEMORY_EXCEPTION = 3
1093  };
1094 
1095  inline Type type() const;
1096 
1097  // Returns the space that needs to be collected for RetryAfterGC failures.
1098  inline AllocationSpace allocation_space() const;
1099 
1100  inline bool IsInternalError() const;
1101  inline bool IsOutOfMemoryException() const;
1102 
1103  static inline Failure* RetryAfterGC(AllocationSpace space);
1104  static inline Failure* RetryAfterGC(); // NEW_SPACE
1105  static inline Failure* Exception();
1106  static inline Failure* InternalError();
1107  static inline Failure* OutOfMemoryException();
1108  // Casting.
1109  static inline Failure* cast(MaybeObject* object);
1110 
1111  // Dispatched behavior.
1112  inline void FailurePrint() {
1113  FailurePrint(stdout);
1114  }
1115  void FailurePrint(FILE* out);
1116  void FailurePrint(StringStream* accumulator);
1117 
1119 
1120  private:
1121  inline intptr_t value() const;
1122  static inline Failure* Construct(Type type, intptr_t value = 0);
1123 
1124  DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
1125 };
1126 
1127 
1128 // Heap objects typically have a map pointer in their first word. However,
1129 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes
1130 // encoded in the first word. The class MapWord is an abstraction of the
1131 // value in a heap object's first word.
1132 class MapWord BASE_EMBEDDED {
1133  public:
1134  // Normal state: the map word contains a map pointer.
1135 
1136  // Create a map word from a map pointer.
1137  static inline MapWord FromMap(Map* map);
1138 
1139  // View this map word as a map pointer.
1140  inline Map* ToMap();
1141 
1142 
1143  // Scavenge collection: the map word of live objects in the from space
1144  // contains a forwarding address (a heap object pointer in the to space).
1145 
1146  // True if this map word is a forwarding address for a scavenge
1147  // collection. Only valid during a scavenge collection (specifically,
1148  // when all map words are heap object pointers, i.e. not during a full GC).
1149  inline bool IsForwardingAddress();
1150 
1151  // Create a map word from a forwarding address.
1152  static inline MapWord FromForwardingAddress(HeapObject* object);
1153 
1154  // View this map word as a forwarding address.
1155  inline HeapObject* ToForwardingAddress();
1156 
1157  static inline MapWord FromRawValue(uintptr_t value) {
1158  return MapWord(value);
1159  }
1160 
1161  inline uintptr_t ToRawValue() {
1162  return value_;
1163  }
1164 
1165  private:
1166  // HeapObject calls the private constructor and directly reads the value.
1167  friend class HeapObject;
1168 
1169  explicit MapWord(uintptr_t value) : value_(value) {}
1170 
1171  uintptr_t value_;
1172 };
1173 
1174 
1175 // HeapObject is the superclass for all classes describing heap allocated
1176 // objects.
1177 class HeapObject: public Object {
1178  public:
1179  // [map]: Contains a map which contains the object's reflective
1180  // information.
1181  inline Map* map();
1182  inline void set_map(Map* value);
1183  // The no-write-barrier version. This is OK if the object is white and in
1184  // new space, or if the value is an immortal immutable object, like the maps
1185  // of primitive (non-JS) objects like strings, heap numbers etc.
1186  inline void set_map_no_write_barrier(Map* value);
1187 
1188  // During garbage collection, the map word of a heap object does not
1189  // necessarily contain a map pointer.
1190  inline MapWord map_word();
1191  inline void set_map_word(MapWord map_word);
1192 
1193  // The Heap the object was allocated in. Used also to access Isolate.
1194  inline Heap* GetHeap();
1195 
1196  // Convenience method to get current isolate. This method can be
1197  // accessed only when its result is the same as
1198  // Isolate::Current(), it ASSERTs this. See also comment for GetHeap.
1199  inline Isolate* GetIsolate();
1200 
1201  // Converts an address to a HeapObject pointer.
1202  static inline HeapObject* FromAddress(Address address);
1203 
1204  // Returns the address of this HeapObject.
1205  inline Address address();
1206 
1207  // Iterates over pointers contained in the object (including the Map)
1208  void Iterate(ObjectVisitor* v);
1209 
1210  // Iterates over all pointers contained in the object except the
1211  // first map pointer. The object type is given in the first
1212  // parameter. This function does not access the map pointer in the
1213  // object, and so is safe to call while the map pointer is modified.
1214  void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1215 
1216  // Returns the heap object's size in bytes
1217  inline int Size();
1218 
1219  // Given a heap object's map pointer, returns the heap size in bytes
1220  // Useful when the map pointer field is used for other purposes.
1221  // GC internal.
1222  inline int SizeFromMap(Map* map);
1223 
1224  // Returns the field at offset in obj, as a read/write Object* reference.
1225  // Does no checking, and is safe to use during GC, while maps are invalid.
1226  // Does not invoke write barrier, so should only be assigned to
1227  // during marking GC.
1228  static inline Object** RawField(HeapObject* obj, int offset);
1229 
1230  // Casting.
1231  static inline HeapObject* cast(Object* obj);
1232 
1233  // Return the write barrier mode for this. Callers of this function
1234  // must be able to present a reference to an AssertNoAllocation
1235  // object as a sign that they are not going to use this function
1236  // from code that allocates and thus invalidates the returned write
1237  // barrier mode.
1238  inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&);
1239 
1240  // Dispatched behavior.
1241  void HeapObjectShortPrint(StringStream* accumulator);
1242 #ifdef OBJECT_PRINT
1243  inline void HeapObjectPrint() {
1244  HeapObjectPrint(stdout);
1245  }
1246  void HeapObjectPrint(FILE* out);
1247  void PrintHeader(FILE* out, const char* id);
1248 #endif
1250 #ifdef VERIFY_HEAP
1251  inline void VerifyObjectField(int offset);
1252  inline void VerifySmiField(int offset);
1253 
1254  // Verify a pointer is a valid HeapObject pointer that points to object
1255  // areas in the heap.
1256  static void VerifyHeapPointer(Object* p);
1257 #endif
1258 
1259  // Layout description.
1260  // First field in a heap object is map.
1261  static const int kMapOffset = Object::kHeaderSize;
1262  static const int kHeaderSize = kMapOffset + kPointerSize;
1263 
1265 
1266  protected:
1267  // helpers for calling an ObjectVisitor to iterate over pointers in the
1268  // half-open range [start, end) specified as integer offsets
1269  inline void IteratePointers(ObjectVisitor* v, int start, int end);
1270  // as above, for the single element at "offset"
1271  inline void IteratePointer(ObjectVisitor* v, int offset);
1272 
1273  private:
1275 };
1276 
1277 
1278 // This class describes a body of an object of a fixed size
1279 // in which all pointer fields are located in the [start_offset, end_offset)
1280 // interval.
1281 template<int start_offset, int end_offset, int size>
1283  public:
1284  static const int kStartOffset = start_offset;
1285  static const int kEndOffset = end_offset;
1286  static const int kSize = size;
1287 
1288  static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1289 
1290  template<typename StaticVisitor>
1291  static inline void IterateBody(HeapObject* obj) {
1292  StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1293  HeapObject::RawField(obj, end_offset));
1294  }
1295 };
1296 
1297 
1298 // This class describes a body of an object of a variable size
1299 // in which all pointer fields are located in the [start_offset, object_size)
1300 // interval.
1301 template<int start_offset>
1303  public:
1304  static const int kStartOffset = start_offset;
1305 
1306  static inline void IterateBody(HeapObject* obj,
1307  int object_size,
1308  ObjectVisitor* v);
1309 
1310  template<typename StaticVisitor>
1311  static inline void IterateBody(HeapObject* obj, int object_size) {
1312  StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset),
1313  HeapObject::RawField(obj, object_size));
1314  }
1315 };
1316 
1317 
1318 // The HeapNumber class describes heap allocated numbers that cannot be
1319 // represented in a Smi (small integer)
1320 class HeapNumber: public HeapObject {
1321  public:
1322  // [value]: number value.
1323  inline double value();
1324  inline void set_value(double value);
1325 
1326  // Casting.
1327  static inline HeapNumber* cast(Object* obj);
1328 
1329  // Dispatched behavior.
1330  Object* HeapNumberToBoolean();
1331  inline void HeapNumberPrint() {
1332  HeapNumberPrint(stdout);
1333  }
1334  void HeapNumberPrint(FILE* out);
1335  void HeapNumberPrint(StringStream* accumulator);
1337 
1338  inline int get_exponent();
1339  inline int get_sign();
1340 
1341  // Layout description.
1342  static const int kValueOffset = HeapObject::kHeaderSize;
1343  // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1344  // is a mixture of sign, exponent and mantissa. Our current platforms are all
1345  // little endian apart from non-EABI arm which is little endian with big
1346  // endian floating point word ordering!
1347  static const int kMantissaOffset = kValueOffset;
1348  static const int kExponentOffset = kValueOffset + 4;
1349 
1350  static const int kSize = kValueOffset + kDoubleSize;
1351  static const uint32_t kSignMask = 0x80000000u;
1352  static const uint32_t kExponentMask = 0x7ff00000u;
1353  static const uint32_t kMantissaMask = 0xfffffu;
1354  static const int kMantissaBits = 52;
1355  static const int kExponentBits = 11;
1356  static const int kExponentBias = 1023;
1357  static const int kExponentShift = 20;
1358  static const int kMantissaBitsInTopWord = 20;
1359  static const int kNonMantissaBitsInTopWord = 12;
1360 
1361  private:
1362  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1363 };
1364 
1365 
1370 };
1371 
1372 
1373 // Indicates whether a property should be set or (re)defined. Setting of a
1374 // property causes attributes to remain unchanged, writability to be checked
1375 // and callbacks to be called. Defining of a property causes attributes to
1376 // be updated and callbacks to be overridden.
1380 };
1381 
1382 
1383 // Indicator for one component of an AccessorPair.
1387 };
1388 
1389 
1390 // JSReceiver includes types on which properties can be defined, i.e.,
1391 // JSObject and JSProxy.
1392 class JSReceiver: public HeapObject {
1393  public:
1394  enum DeleteMode {
1397  FORCE_DELETION
1398  };
1399 
1400  // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
1401  // a keyed store is of the form a[expression] = foo.
1404  CERTAINLY_NOT_STORE_FROM_KEYED
1405  };
1406 
1407  // Internal properties (e.g. the hidden properties dictionary) might
1408  // be added even though the receiver is non-extensible.
1411  OMIT_EXTENSIBILITY_CHECK
1412  };
1413 
1414  // Casting.
1415  static inline JSReceiver* cast(Object* obj);
1416 
1418  Handle<String> key,
1419  Handle<Object> value,
1420  PropertyAttributes attributes,
1421  StrictModeFlag strict_mode);
1422  // Can cause GC.
1423  MUST_USE_RESULT MaybeObject* SetProperty(
1424  String* key,
1425  Object* value,
1426  PropertyAttributes attributes,
1427  StrictModeFlag strict_mode,
1428  StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
1429  MUST_USE_RESULT MaybeObject* SetProperty(
1430  LookupResult* result,
1431  String* key,
1432  Object* value,
1433  PropertyAttributes attributes,
1434  StrictModeFlag strict_mode,
1435  StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
1436  MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter,
1437  Object* value);
1438 
1439  MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1440  MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1441 
1442  // Set the index'th array element.
1443  // Can cause GC, or return failure if GC is required.
1444  MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1445  Object* value,
1446  PropertyAttributes attributes,
1447  StrictModeFlag strict_mode,
1448  bool check_prototype);
1449 
1450  // Tests for the fast common case for property enumeration.
1451  bool IsSimpleEnum();
1452 
1453  // Returns the class name ([[Class]] property in the specification).
1454  String* class_name();
1455 
1456  // Returns the constructor name (the name (possibly, inferred name) of the
1457  // function that was used to instantiate the object).
1458  String* constructor_name();
1459 
1460  inline PropertyAttributes GetPropertyAttribute(String* name);
1461  PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver,
1462  String* name);
1463  PropertyAttributes GetLocalPropertyAttribute(String* name);
1464 
1465  // Can cause a GC.
1466  inline bool HasProperty(String* name);
1467  inline bool HasLocalProperty(String* name);
1468  inline bool HasElement(uint32_t index);
1469 
1470  // Return the object's prototype (might be Heap::null_value()).
1471  inline Object* GetPrototype();
1472 
1473  // Return the constructor function (may be Heap::null_value()).
1474  inline Object* GetConstructor();
1475 
1476  // Set the object's prototype (only JSReceiver and null are allowed).
1477  MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1478  bool skip_hidden_prototypes);
1479 
1480  // Retrieves a permanent object identity hash code. The undefined value might
1481  // be returned in case no hash was created yet and OMIT_CREATION was used.
1482  inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1483 
1484  // Lookup a property. If found, the result is valid and has
1485  // detailed information.
1486  void LocalLookup(String* name, LookupResult* result);
1487  void Lookup(String* name, LookupResult* result);
1488 
1489  protected:
1490  Smi* GenerateIdentityHash();
1491 
1492  private:
1493  PropertyAttributes GetPropertyAttribute(JSReceiver* receiver,
1494  LookupResult* result,
1495  String* name,
1496  bool continue_search);
1497 
1499 };
1500 
1501 // The JSObject describes real heap allocated JavaScript objects with
1502 // properties.
1503 // Note that the map of JSObject changes during execution to enable inline
1504 // caching.
1505 class JSObject: public JSReceiver {
1506  public:
1507  // [properties]: Backing storage for properties.
1508  // properties is a FixedArray in the fast case and a Dictionary in the
1509  // slow case.
1510  DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1511  inline void initialize_properties();
1512  inline bool HasFastProperties();
1513  inline StringDictionary* property_dictionary(); // Gets slow properties.
1514 
1515  // [elements]: The elements (properties with names that are integers).
1516  //
1517  // Elements can be in two general modes: fast and slow. Each mode
1518  // corrensponds to a set of object representations of elements that
1519  // have something in common.
1520  //
1521  // In the fast mode elements is a FixedArray and so each element can
1522  // be quickly accessed. This fact is used in the generated code. The
1523  // elements array can have one of three maps in this mode:
1524  // fixed_array_map, non_strict_arguments_elements_map or
1525  // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1526  // the elements array may be shared by a few objects and so before
1527  // writing to any element the array must be copied. Use
1528  // EnsureWritableFastElements in this case.
1529  //
1530  // In the slow mode the elements is either a NumberDictionary, an
1531  // ExternalArray, or a FixedArray parameter map for a (non-strict)
1532  // arguments object.
1533  DECL_ACCESSORS(elements, FixedArrayBase)
1534  inline void initialize_elements();
1535  MUST_USE_RESULT inline MaybeObject* ResetElements();
1536  inline ElementsKind GetElementsKind();
1537  inline ElementsAccessor* GetElementsAccessor();
1538  // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
1539  inline bool HasFastSmiElements();
1540  // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
1541  inline bool HasFastObjectElements();
1542  // Returns true if an object has elements of FAST_ELEMENTS or
1543  // FAST_SMI_ONLY_ELEMENTS.
1544  inline bool HasFastSmiOrObjectElements();
1545  // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
1546  // ElementsKind.
1547  inline bool HasFastDoubleElements();
1548  // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
1549  // ElementsKind.
1550  inline bool HasFastHoleyElements();
1551  inline bool HasNonStrictArgumentsElements();
1552  inline bool HasDictionaryElements();
1553  inline bool HasExternalPixelElements();
1554  inline bool HasExternalArrayElements();
1555  inline bool HasExternalByteElements();
1556  inline bool HasExternalUnsignedByteElements();
1557  inline bool HasExternalShortElements();
1558  inline bool HasExternalUnsignedShortElements();
1559  inline bool HasExternalIntElements();
1560  inline bool HasExternalUnsignedIntElements();
1561  inline bool HasExternalFloatElements();
1562  inline bool HasExternalDoubleElements();
1563  bool HasFastArgumentsElements();
1564  bool HasDictionaryArgumentsElements();
1565  inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
1566 
1567  inline void set_map_and_elements(
1568  Map* map,
1569  FixedArrayBase* value,
1571 
1572  // Requires: HasFastElements().
1573  MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements();
1574 
1575  // Collects elements starting at index 0.
1576  // Undefined values are placed after non-undefined values.
1577  // Returns the number of non-undefined values.
1578  MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit);
1579  // As PrepareElementsForSort, but only on objects where elements is
1580  // a dictionary, and it will stay a dictionary.
1581  MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit);
1582 
1583  MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver,
1584  Object* structure,
1585  String* name);
1586 
1587  // Can cause GC.
1588  MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result,
1589  String* key,
1590  Object* value,
1591  PropertyAttributes attributes,
1592  StrictModeFlag strict_mode,
1593  StoreFromKeyed store_mode);
1594  MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck(
1595  LookupResult* result,
1596  String* name,
1597  Object* value,
1598  bool check_prototype,
1599  StrictModeFlag strict_mode);
1600  MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(
1601  Object* structure,
1602  String* name,
1603  Object* value,
1604  JSObject* holder,
1605  StrictModeFlag strict_mode);
1607  String* name,
1608  Object* value,
1609  PropertyAttributes attributes,
1610  StrictModeFlag strict_mode);
1611  MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor(
1612  String* name,
1613  Object* value,
1614  PropertyAttributes attributes,
1615  StrictModeFlag strict_mode,
1616  ExtensibilityCheck extensibility_check);
1617 
1618  static Handle<Object> SetLocalPropertyIgnoreAttributes(
1619  Handle<JSObject> object,
1620  Handle<String> key,
1621  Handle<Object> value,
1622  PropertyAttributes attributes);
1623 
1624  // Try to follow an existing transition to a field with attributes NONE. The
1625  // return value indicates whether the transition was successful.
1626  static inline bool TryTransitionToField(Handle<JSObject> object,
1627  Handle<String> key);
1628 
1629  inline int LastAddedFieldIndex();
1630 
1631  // Extend the receiver with a single fast property appeared first in the
1632  // passed map. This also extends the property backing store if necessary.
1633  static void AddFastPropertyUsingMap(Handle<JSObject> object, Handle<Map> map);
1634  inline MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* map);
1635 
1636  // Can cause GC.
1637  MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes(
1638  String* key,
1639  Object* value,
1640  PropertyAttributes attributes);
1641 
1642  // Retrieve a value in a normalized object given a lookup result.
1643  // Handles the special representation of JS global objects.
1644  Object* GetNormalizedProperty(LookupResult* result);
1645 
1646  // Sets the property value in a normalized object given a lookup result.
1647  // Handles the special representation of JS global objects.
1648  Object* SetNormalizedProperty(LookupResult* result, Object* value);
1649 
1650  // Sets the property value in a normalized object given (key, value, details).
1651  // Handles the special representation of JS global objects.
1652  static Handle<Object> SetNormalizedProperty(Handle<JSObject> object,
1653  Handle<String> key,
1654  Handle<Object> value,
1655  PropertyDetails details);
1656 
1657  MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name,
1658  Object* value,
1659  PropertyDetails details);
1660 
1661  // Deletes the named property in a normalized object.
1662  MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name,
1663  DeleteMode mode);
1664 
1665  MUST_USE_RESULT MaybeObject* OptimizeAsPrototype();
1666 
1667  // Retrieve interceptors.
1668  InterceptorInfo* GetNamedInterceptor();
1669  InterceptorInfo* GetIndexedInterceptor();
1670 
1671  // Used from JSReceiver.
1672  PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1673  String* name,
1674  bool continue_search);
1675  PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1676  String* name,
1677  bool continue_search);
1678  PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1679  Object* receiver,
1680  LookupResult* result,
1681  String* name,
1682  bool continue_search);
1683 
1684  static void DefineAccessor(Handle<JSObject> object,
1685  Handle<String> name,
1686  Handle<Object> getter,
1687  Handle<Object> setter,
1688  PropertyAttributes attributes);
1689  MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
1690  Object* getter,
1691  Object* setter,
1692  PropertyAttributes attributes);
1693  // Try to define a single accessor paying attention to map transitions.
1694  // Returns a JavaScript null if this was not possible and we have to use the
1695  // slow case. Note that we can fail due to allocations, too.
1696  MUST_USE_RESULT MaybeObject* DefineFastAccessor(
1697  String* name,
1698  AccessorComponent component,
1699  Object* accessor,
1700  PropertyAttributes attributes);
1701  Object* LookupAccessor(String* name, AccessorComponent component);
1702 
1703  MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
1704 
1705  // Used from Object::GetProperty().
1706  MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck(
1707  Object* receiver,
1708  LookupResult* result,
1709  String* name,
1710  PropertyAttributes* attributes);
1712  Object* receiver,
1713  String* name,
1714  PropertyAttributes* attributes);
1715  MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor(
1716  Object* receiver,
1717  String* name,
1718  PropertyAttributes* attributes);
1719  MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor(
1720  Object* receiver,
1721  String* name,
1722  PropertyAttributes* attributes);
1723 
1724  // Returns true if this is an instance of an api function and has
1725  // been modified since it was created. May give false positives.
1726  bool IsDirty();
1727 
1728  // If the receiver is a JSGlobalProxy this method will return its prototype,
1729  // otherwise the result is the receiver itself.
1730  inline Object* BypassGlobalProxy();
1731 
1732  // Accessors for hidden properties object.
1733  //
1734  // Hidden properties are not local properties of the object itself.
1735  // Instead they are stored in an auxiliary structure kept as a local
1736  // property with a special name Heap::hidden_symbol(). But if the
1737  // receiver is a JSGlobalProxy then the auxiliary object is a property
1738  // of its prototype, and if it's a detached proxy, then you can't have
1739  // hidden properties.
1740 
1741  // Sets a hidden property on this object. Returns this object if successful,
1742  // undefined if called on a detached proxy.
1743  static Handle<Object> SetHiddenProperty(Handle<JSObject> obj,
1744  Handle<String> key,
1745  Handle<Object> value);
1746  // Returns a failure if a GC is required.
1747  MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value);
1748  // Gets the value of a hidden property with the given key. Returns undefined
1749  // if the property doesn't exist (or if called on a detached proxy),
1750  // otherwise returns the value set for the key.
1751  Object* GetHiddenProperty(String* key);
1752  // Deletes a hidden property. Deleting a non-existing property is
1753  // considered successful.
1754  void DeleteHiddenProperty(String* key);
1755  // Returns true if the object has a property with the hidden symbol as name.
1756  bool HasHiddenProperties();
1757 
1758  static int GetIdentityHash(Handle<JSObject> obj);
1759  MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1760  MUST_USE_RESULT MaybeObject* SetIdentityHash(Smi* hash, CreationFlag flag);
1761 
1762  static Handle<Object> DeleteProperty(Handle<JSObject> obj,
1763  Handle<String> name);
1764  MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1765 
1766  static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index);
1767  MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1768 
1769  inline void ValidateElements();
1770 
1771  // Makes sure that this object can contain HeapObject as elements.
1772  MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements();
1773 
1774  // Makes sure that this object can contain the specified elements.
1775  MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1776  Object** elements,
1777  uint32_t count,
1778  EnsureElementsMode mode);
1779  MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1780  FixedArrayBase* elements,
1781  uint32_t length,
1782  EnsureElementsMode mode);
1783  MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
1784  Arguments* arguments,
1785  uint32_t first_arg,
1786  uint32_t arg_count,
1787  EnsureElementsMode mode);
1788 
1789  // Do we want to keep the elements in fast case when increasing the
1790  // capacity?
1791  bool ShouldConvertToSlowElements(int new_capacity);
1792  // Returns true if the backing storage for the slow-case elements of
1793  // this object takes up nearly as much space as a fast-case backing
1794  // storage would. In that case the JSObject should have fast
1795  // elements.
1796  bool ShouldConvertToFastElements();
1797  // Returns true if the elements of JSObject contains only values that can be
1798  // represented in a FixedDoubleArray and has at least one value that can only
1799  // be represented as a double and not a Smi.
1800  bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements);
1801 
1802  // Tells whether the index'th element is present.
1803  bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index);
1804 
1805  // Computes the new capacity when expanding the elements of a JSObject.
1806  static int NewElementsCapacity(int old_capacity) {
1807  // (old_capacity + 50%) + 16
1808  return old_capacity + (old_capacity >> 1) + 16;
1809  }
1810 
1811  // Tells whether the index'th element is present and how it is stored.
1813  // There is no element with given index.
1815 
1816  // Element with given index is handled by interceptor.
1818 
1819  // Element with given index is character in string.
1821 
1822  // Element with given index is stored in fast backing store.
1824 
1825  // Element with given index is stored in slow backing store.
1826  DICTIONARY_ELEMENT
1827  };
1828 
1829  LocalElementType HasLocalElement(uint32_t index);
1830 
1831  bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
1832 
1833  MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1834  Object* value,
1835  StrictModeFlag strict_mode,
1836  bool check_prototype);
1837 
1838  MUST_USE_RESULT MaybeObject* SetDictionaryElement(
1839  uint32_t index,
1840  Object* value,
1841  PropertyAttributes attributes,
1842  StrictModeFlag strict_mode,
1843  bool check_prototype,
1844  SetPropertyMode set_mode = SET_PROPERTY);
1845 
1846  MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1847  uint32_t index,
1848  Object* value,
1849  StrictModeFlag strict_mode,
1850  bool check_prototype = true);
1851 
1852  static Handle<Object> SetOwnElement(Handle<JSObject> object,
1853  uint32_t index,
1854  Handle<Object> value,
1855  StrictModeFlag strict_mode);
1856 
1857  // Empty handle is returned if the element cannot be set to the given value.
1858  static MUST_USE_RESULT Handle<Object> SetElement(
1859  Handle<JSObject> object,
1860  uint32_t index,
1861  Handle<Object> value,
1862  PropertyAttributes attr,
1863  StrictModeFlag strict_mode,
1864  SetPropertyMode set_mode = SET_PROPERTY);
1865 
1866  // A Failure object is returned if GC is needed.
1867  MUST_USE_RESULT MaybeObject* SetElement(
1868  uint32_t index,
1869  Object* value,
1870  PropertyAttributes attributes,
1871  StrictModeFlag strict_mode,
1872  bool check_prototype = true,
1873  SetPropertyMode set_mode = SET_PROPERTY);
1874 
1875  // Returns the index'th element.
1876  // The undefined object if index is out of bounds.
1877  MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver,
1878  uint32_t index);
1879 
1883  kDontAllowSmiElements
1884  };
1885 
1886  // Replace the elements' backing store with fast elements of the given
1887  // capacity. Update the length for JSArrays. Returns the new backing
1888  // store.
1889  MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1890  int capacity,
1891  int length,
1892  SetFastElementsCapacitySmiMode smi_mode);
1893  MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1894  int capacity,
1895  int length);
1896 
1897  // Lookup interceptors are used for handling properties controlled by host
1898  // objects.
1899  inline bool HasNamedInterceptor();
1900  inline bool HasIndexedInterceptor();
1901 
1902  // Support functions for v8 api (needed for correct interceptor behavior).
1903  bool HasRealNamedProperty(String* key);
1904  bool HasRealElementProperty(uint32_t index);
1905  bool HasRealNamedCallbackProperty(String* key);
1906 
1907  // Get the header size for a JSObject. Used to compute the index of
1908  // internal fields as well as the number of internal fields.
1909  inline int GetHeaderSize();
1910 
1911  inline int GetInternalFieldCount();
1912  inline int GetInternalFieldOffset(int index);
1913  inline Object* GetInternalField(int index);
1914  inline void SetInternalField(int index, Object* value);
1915  inline void SetInternalField(int index, Smi* value);
1916 
1917  // The following lookup functions skip interceptors.
1918  void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1919  void LookupRealNamedProperty(String* name, LookupResult* result);
1920  void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
1921  MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
1922  uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode);
1923  void LookupCallbackProperty(String* name, LookupResult* result);
1924 
1925  // Returns the number of properties on this object filtering out properties
1926  // with the specified attributes (ignoring interceptors).
1927  int NumberOfLocalProperties(PropertyAttributes filter = NONE);
1928  // Fill in details for properties into storage starting at the specified
1929  // index.
1930  void GetLocalPropertyNames(FixedArray* storage, int index);
1931 
1932  // Returns the number of properties on this object filtering out properties
1933  // with the specified attributes (ignoring interceptors).
1934  int NumberOfLocalElements(PropertyAttributes filter);
1935  // Returns the number of enumerable elements (ignoring interceptors).
1936  int NumberOfEnumElements();
1937  // Returns the number of elements on this object filtering out elements
1938  // with the specified attributes (ignoring interceptors).
1939  int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1940  // Count and fill in the enumerable elements into storage.
1941  // (storage->length() == NumberOfEnumElements()).
1942  // If storage is NULL, will count the elements without adding
1943  // them to any storage.
1944  // Returns the number of enumerable elements.
1945  int GetEnumElementKeys(FixedArray* storage);
1946 
1947  // Add a property to a fast-case object using a map transition to
1948  // new_map.
1949  MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map,
1950  String* name,
1951  Object* value,
1952  int field_index);
1953 
1954  // Add a constant function property to a fast-case object.
1955  // This leaves a CONSTANT_TRANSITION in the old map, and
1956  // if it is called on a second object with this map, a
1957  // normal property is added instead, with a map transition.
1958  // This avoids the creation of many maps with the same constant
1959  // function, all orphaned.
1960  MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty(
1961  String* name,
1962  JSFunction* function,
1963  PropertyAttributes attributes);
1964 
1965  MUST_USE_RESULT MaybeObject* ReplaceSlowProperty(
1966  String* name,
1967  Object* value,
1968  PropertyAttributes attributes);
1969 
1970  // Returns a new map with all transitions dropped from the object's current
1971  // map and the ElementsKind set.
1972  static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
1973  ElementsKind to_kind);
1974  inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap(
1975  Isolate* isolate,
1976  ElementsKind elements_kind);
1977  MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow(
1978  ElementsKind elements_kind);
1979 
1980  static Handle<Object> TransitionElementsKind(Handle<JSObject> object,
1981  ElementsKind to_kind);
1982 
1983  MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
1984 
1985  // Replaces an existing transition with a transition to a map with a FIELD.
1986  MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition(
1987  int transition_index,
1988  String* name,
1989  Object* new_value,
1990  PropertyAttributes attributes);
1991 
1992  // Converts a descriptor of any other type to a real field, backed by the
1993  // properties array.
1994  MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
1995  String* name,
1996  Object* new_value,
1997  PropertyAttributes attributes);
1998 
1999  // Add a property to a fast-case object.
2000  MUST_USE_RESULT MaybeObject* AddFastProperty(
2001  String* name,
2002  Object* value,
2003  PropertyAttributes attributes,
2004  StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
2005 
2006  // Add a property to a slow-case object.
2007  MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name,
2008  Object* value,
2009  PropertyAttributes attributes);
2010 
2011  // Add a property to an object.
2012  MUST_USE_RESULT MaybeObject* AddProperty(
2013  String* name,
2014  Object* value,
2015  PropertyAttributes attributes,
2016  StrictModeFlag strict_mode,
2017  StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED,
2018  ExtensibilityCheck extensibility_check = PERFORM_EXTENSIBILITY_CHECK);
2019 
2020  // Convert the object to use the canonical dictionary
2021  // representation. If the object is expected to have additional properties
2022  // added this number can be indicated to have the backing store allocated to
2023  // an initial capacity for holding these properties.
2024  static void NormalizeProperties(Handle<JSObject> object,
2026  int expected_additional_properties);
2027 
2028  MUST_USE_RESULT MaybeObject* NormalizeProperties(
2030  int expected_additional_properties);
2031 
2032  // Convert and update the elements backing store to be a
2033  // SeededNumberDictionary dictionary. Returns the backing after conversion.
2034  static Handle<SeededNumberDictionary> NormalizeElements(
2035  Handle<JSObject> object);
2036 
2037  MUST_USE_RESULT MaybeObject* NormalizeElements();
2038 
2039  static void UpdateMapCodeCache(Handle<JSObject> object,
2040  Handle<String> name,
2041  Handle<Code> code);
2042 
2043  MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code);
2044 
2045  // Transform slow named properties to fast variants.
2046  // Returns failure if allocation failed.
2047  static void TransformToFastProperties(Handle<JSObject> object,
2048  int unused_property_fields);
2049 
2050  MUST_USE_RESULT MaybeObject* TransformToFastProperties(
2051  int unused_property_fields);
2052 
2053  // Access fast-case object properties at index.
2054  inline Object* FastPropertyAt(int index);
2055  inline Object* FastPropertyAtPut(int index, Object* value);
2056 
2057  // Access to in object properties.
2058  inline int GetInObjectPropertyOffset(int index);
2059  inline Object* InObjectPropertyAt(int index);
2060  inline Object* InObjectPropertyAtPut(int index,
2061  Object* value,
2062  WriteBarrierMode mode
2064 
2065  // Initializes the body after properties slot, properties slot is
2066  // initialized by set_properties. Fill the pre-allocated fields with
2067  // pre_allocated_value and the rest with filler_value.
2068  // Note: this call does not update write barrier, the caller is responsible
2069  // to ensure that |filler_value| can be collected without WB here.
2070  inline void InitializeBody(Map* map,
2071  Object* pre_allocated_value,
2072  Object* filler_value);
2073 
2074  // Check whether this object references another object
2075  bool ReferencesObject(Object* obj);
2076 
2077  // Casting.
2078  static inline JSObject* cast(Object* obj);
2079 
2080  // Disalow further properties to be added to the object.
2081  static Handle<Object> PreventExtensions(Handle<JSObject> object);
2082  MUST_USE_RESULT MaybeObject* PreventExtensions();
2083 
2084 
2085  // Dispatched behavior.
2086  void JSObjectShortPrint(StringStream* accumulator);
2087 #ifdef OBJECT_PRINT
2088  inline void JSObjectPrint() {
2089  JSObjectPrint(stdout);
2090  }
2091  void JSObjectPrint(FILE* out);
2092 #endif
2093  DECLARE_VERIFIER(JSObject)
2094 #ifdef OBJECT_PRINT
2095  inline void PrintProperties() {
2096  PrintProperties(stdout);
2097  }
2098  void PrintProperties(FILE* out);
2099 
2100  inline void PrintElements() {
2101  PrintElements(stdout);
2102  }
2103  void PrintElements(FILE* out);
2104  inline void PrintTransitions() {
2105  PrintTransitions(stdout);
2106  }
2107  void PrintTransitions(FILE* out);
2108 #endif
2109 
2110  void PrintElementsTransition(
2111  FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements,
2112  ElementsKind to_kind, FixedArrayBase* to_elements);
2113 
2114 #ifdef DEBUG
2115  // Structure for collecting spill information about JSObjects.
2116  class SpillInformation {
2117  public:
2118  void Clear();
2119  void Print();
2120  int number_of_objects_;
2121  int number_of_objects_with_fast_properties_;
2122  int number_of_objects_with_fast_elements_;
2123  int number_of_fast_used_fields_;
2124  int number_of_fast_unused_fields_;
2125  int number_of_slow_used_properties_;
2126  int number_of_slow_unused_properties_;
2127  int number_of_fast_used_elements_;
2128  int number_of_fast_unused_elements_;
2129  int number_of_slow_used_elements_;
2130  int number_of_slow_unused_elements_;
2131  };
2132 
2133  void IncrementSpillStatistics(SpillInformation* info);
2134 #endif
2135  Object* SlowReverseLookup(Object* value);
2136 
2137  // Maximal number of fast properties for the JSObject. Used to
2138  // restrict the number of map transitions to avoid an explosion in
2139  // the number of maps for objects used as dictionaries.
2140  inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode);
2141 
2142  // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2143  // Also maximal value of JSArray's length property.
2144  static const uint32_t kMaxElementCount = 0xffffffffu;
2145 
2146  // Constants for heuristics controlling conversion of fast elements
2147  // to slow elements.
2148 
2149  // Maximal gap that can be introduced by adding an element beyond
2150  // the current elements length.
2151  static const uint32_t kMaxGap = 1024;
2152 
2153  // Maximal length of fast elements array that won't be checked for
2154  // being dense enough on expansion.
2155  static const int kMaxUncheckedFastElementsLength = 5000;
2156 
2157  // Same as above but for old arrays. This limit is more strict. We
2158  // don't want to be wasteful with long lived objects.
2159  static const int kMaxUncheckedOldFastElementsLength = 500;
2160 
2161  static const int kInitialMaxFastElementArray = 100000;
2162  static const int kFastPropertiesSoftLimit = 12;
2163  static const int kMaxFastProperties = 64;
2164  static const int kMaxInstanceSize = 255 * kPointerSize;
2165  // When extending the backing storage for property values, we increase
2166  // its size by more than the 1 entry necessary, so sequentially adding fields
2167  // to the same object requires fewer allocations and copies.
2168  static const int kFieldsAdded = 3;
2169 
2170  // Layout description.
2171  static const int kPropertiesOffset = HeapObject::kHeaderSize;
2172  static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2173  static const int kHeaderSize = kElementsOffset + kPointerSize;
2174 
2176 
2177  class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2178  public:
2179  static inline int SizeOf(Map* map, HeapObject* object);
2180  };
2181 
2182  private:
2184 
2185  MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
2186  Object* structure,
2187  uint32_t index,
2188  Object* holder);
2189  MUST_USE_RESULT MaybeObject* SetElementWithCallback(
2190  Object* structure,
2191  uint32_t index,
2192  Object* value,
2193  JSObject* holder,
2194  StrictModeFlag strict_mode);
2195  MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(
2196  uint32_t index,
2197  Object* value,
2198  PropertyAttributes attributes,
2199  StrictModeFlag strict_mode,
2200  bool check_prototype,
2201  SetPropertyMode set_mode);
2202  MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(
2203  uint32_t index,
2204  Object* value,
2205  PropertyAttributes attributes,
2206  StrictModeFlag strict_mode,
2207  bool check_prototype,
2208  SetPropertyMode set_mode);
2209 
2210  // Searches the prototype chain for property 'name'. If it is found and
2211  // has a setter, invoke it and set '*done' to true. If it is found and is
2212  // read-only, reject and set '*done' to true. Otherwise, set '*done' to
2213  // false. Can cause GC and can return a failure result with '*done==true'.
2214  MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypes(
2215  String* name,
2216  Object* value,
2217  PropertyAttributes attributes,
2218  StrictModeFlag strict_mode,
2219  bool* done);
2220 
2221  MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name,
2222  DeleteMode mode);
2223  MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name);
2224 
2225  MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index);
2226 
2227  MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index);
2228  MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index,
2229  DeleteMode mode);
2230 
2231  bool ReferencesObjectFromElements(FixedArray* elements,
2232  ElementsKind kind,
2233  Object* object);
2234 
2235  // Returns true if most of the elements backing storage is used.
2236  bool HasDenseElements();
2237 
2238  // Gets the current elements capacity and the number of used elements.
2239  void GetElementsCapacityAndUsage(int* capacity, int* used);
2240 
2241  bool CanSetCallback(String* name);
2242  MUST_USE_RESULT MaybeObject* SetElementCallback(
2243  uint32_t index,
2244  Object* structure,
2245  PropertyAttributes attributes);
2246  MUST_USE_RESULT MaybeObject* SetPropertyCallback(
2247  String* name,
2248  Object* structure,
2249  PropertyAttributes attributes);
2250  MUST_USE_RESULT MaybeObject* DefineElementAccessor(
2251  uint32_t index,
2252  Object* getter,
2253  Object* setter,
2254  PropertyAttributes attributes);
2255  MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name);
2256  MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
2257  String* name,
2258  Object* getter,
2259  Object* setter,
2260  PropertyAttributes attributes);
2261 
2262 
2263  enum InitializeHiddenProperties {
2264  CREATE_NEW_IF_ABSENT,
2265  ONLY_RETURN_INLINE_VALUE
2266  };
2267 
2268  // If create_if_absent is true, return the hash table backing store
2269  // for hidden properties. If there is no backing store, allocate one.
2270  // If create_if_absent is false, return the hash table backing store
2271  // or the inline stored identity hash, whatever is found.
2272  MUST_USE_RESULT MaybeObject* GetHiddenPropertiesHashTable(
2273  InitializeHiddenProperties init_option);
2274  // Set the hidden property backing store to either a hash table or
2275  // the inline-stored identity hash.
2276  MUST_USE_RESULT MaybeObject* SetHiddenPropertiesHashTable(
2277  Object* value);
2278 
2280 };
2281 
2282 
2283 // Common superclass for FixedArrays that allow implementations to share
2284 // common accessors and some code paths.
2286  public:
2287  // [length]: length of the array.
2288  inline int length();
2289  inline void set_length(int value);
2290 
2291  inline static FixedArrayBase* cast(Object* object);
2292 
2293  // Layout description.
2294  // Length is smi tagged when it is stored.
2295  static const int kLengthOffset = HeapObject::kHeaderSize;
2296  static const int kHeaderSize = kLengthOffset + kPointerSize;
2297 };
2298 
2299 
2300 class FixedDoubleArray;
2301 class IncrementalMarking;
2302 
2303 
2304 // FixedArray describes fixed-sized arrays with element type Object*.
2306  public:
2307  // Setter and getter for elements.
2308  inline Object* get(int index);
2309  // Setter that uses write barrier.
2310  inline void set(int index, Object* value);
2311  inline bool is_the_hole(int index);
2312 
2313  // Setter that doesn't need write barrier).
2314  inline void set(int index, Smi* value);
2315  // Setter with explicit barrier mode.
2316  inline void set(int index, Object* value, WriteBarrierMode mode);
2317 
2318  // Setters for frequently used oddballs located in old space.
2319  inline void set_undefined(int index);
2320  // TODO(isolates): duplicate.
2321  inline void set_undefined(Heap* heap, int index);
2322  inline void set_null(int index);
2323  // TODO(isolates): duplicate.
2324  inline void set_null(Heap* heap, int index);
2325  inline void set_the_hole(int index);
2326 
2327  // Setters with less debug checks for the GC to use.
2328  inline void set_unchecked(int index, Smi* value);
2329  inline void set_null_unchecked(Heap* heap, int index);
2330  inline void set_unchecked(Heap* heap, int index, Object* value,
2331  WriteBarrierMode mode);
2332 
2333  // Gives access to raw memory which stores the array's data.
2334  inline Object** data_start();
2335 
2336  inline Object** GetFirstElementAddress();
2337  inline bool ContainsOnlySmisOrHoles();
2338 
2339  // Copy operations.
2340  MUST_USE_RESULT inline MaybeObject* Copy();
2341  MUST_USE_RESULT MaybeObject* CopySize(int new_length);
2342 
2343  // Add the elements of a JSArray to this FixedArray.
2344  MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
2345 
2346  // Compute the union of this and other.
2347  MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
2348 
2349  // Copy a sub array from the receiver to dest.
2350  void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2351 
2352  // Garbage collection support.
2353  static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2354 
2355  // Code Generation support.
2356  static int OffsetOfElementAt(int index) { return SizeFor(index); }
2357 
2358  // Casting.
2359  static inline FixedArray* cast(Object* obj);
2360 
2361  // Maximal allowed size, in bytes, of a single FixedArray.
2362  // Prevents overflowing size computations, as well as extreme memory
2363  // consumption.
2364  static const int kMaxSize = 128 * MB * kPointerSize;
2365  // Maximally allowed length of a FixedArray.
2366  static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
2367 
2368  // Dispatched behavior.
2369 #ifdef OBJECT_PRINT
2370  inline void FixedArrayPrint() {
2371  FixedArrayPrint(stdout);
2372  }
2373  void FixedArrayPrint(FILE* out);
2374 #endif
2376 #ifdef DEBUG
2377  // Checks if two FixedArrays have identical contents.
2378  bool IsEqualTo(FixedArray* other);
2379 #endif
2380 
2381  // Swap two elements in a pair of arrays. If this array and the
2382  // numbers array are the same object, the elements are only swapped
2383  // once.
2384  void SwapPairs(FixedArray* numbers, int i, int j);
2385 
2386  // Sort prefix of this array and the numbers array as pairs wrt. the
2387  // numbers. If the numbers array and the this array are the same
2388  // object, the prefix of this array is sorted.
2389  void SortPairs(FixedArray* numbers, uint32_t len);
2390 
2391  class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2392  public:
2393  static inline int SizeOf(Map* map, HeapObject* object) {
2394  return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2395  }
2396  };
2397 
2398  protected:
2399  // Set operation on FixedArray without using write barriers. Can
2400  // only be used for storing old space objects or smis.
2401  static inline void NoWriteBarrierSet(FixedArray* array,
2402  int index,
2403  Object* value);
2404 
2405  // Set operation on FixedArray without incremental write barrier. Can
2406  // only be used if the object is guaranteed to be white (whiteness witness
2407  // is present).
2408  static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2409  int index,
2410  Object* value);
2411 
2412  private:
2414 };
2415 
2416 
2417 // FixedDoubleArray describes fixed-sized arrays with element type double.
2419  public:
2420  // Setter and getter for elements.
2421  inline double get_scalar(int index);
2422  inline int64_t get_representation(int index);
2423  MUST_USE_RESULT inline MaybeObject* get(int index);
2424  inline void set(int index, double value);
2425  inline void set_the_hole(int index);
2426 
2427  // Checking for the hole.
2428  inline bool is_the_hole(int index);
2429 
2430  // Copy operations
2431  MUST_USE_RESULT inline MaybeObject* Copy();
2432 
2433  // Garbage collection support.
2434  inline static int SizeFor(int length) {
2435  return kHeaderSize + length * kDoubleSize;
2436  }
2437 
2438  // Code Generation support.
2439  static int OffsetOfElementAt(int index) { return SizeFor(index); }
2440 
2441  inline static bool is_the_hole_nan(double value);
2442  inline static double hole_nan_as_double();
2443  inline static double canonical_not_the_hole_nan_as_double();
2444 
2445  // Casting.
2446  static inline FixedDoubleArray* cast(Object* obj);
2447 
2448  // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2449  // Prevents overflowing size computations, as well as extreme memory
2450  // consumption.
2451  static const int kMaxSize = 512 * MB;
2452  // Maximally allowed length of a FixedArray.
2453  static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2454 
2455  // Dispatched behavior.
2456 #ifdef OBJECT_PRINT
2457  inline void FixedDoubleArrayPrint() {
2458  FixedDoubleArrayPrint(stdout);
2459  }
2460  void FixedDoubleArrayPrint(FILE* out);
2461 #endif
2463 
2464  private:
2465  DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2466 };
2467 
2468 
2469 // DescriptorArrays are fixed arrays used to hold instance descriptors.
2470 // The format of the these objects is:
2471 // [0]: Number of descriptors
2472 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array:
2473 // [0]: pointer to fixed array with enum cache
2474 // [1]: either Smi(0) or pointer to fixed array with indices
2475 // [2]: first key
2476 // [2 + number of descriptors * kDescriptorSize]: start of slack
2478  public:
2479  // WhitenessWitness is used to prove that a descriptor array is white
2480  // (unmarked), so incremental write barriers can be skipped because the
2481  // marking invariant cannot be broken and slots pointing into evacuation
2482  // candidates will be discovered when the object is scanned. A witness is
2483  // always stack-allocated right after creating an array. By allocating a
2484  // witness, incremental marking is globally disabled. The witness is then
2485  // passed along wherever needed to statically prove that the array is known to
2486  // be white.
2488  public:
2489  inline explicit WhitenessWitness(FixedArray* array);
2490  inline ~WhitenessWitness();
2491 
2492  private:
2493  IncrementalMarking* marking_;
2494  };
2495 
2496  // Returns true for both shared empty_descriptor_array and for smis, which the
2497  // map uses to encode additional bit fields when the descriptor array is not
2498  // yet used.
2499  inline bool IsEmpty();
2500 
2501  // Returns the number of descriptors in the array.
2503  ASSERT(length() >= kFirstIndex || IsEmpty());
2504  int len = length();
2505  return len == 0 ? 0 : Smi::cast(get(kDescriptorLengthIndex))->value();
2506  }
2507 
2509  int len = length();
2510  return len == 0 ? 0 : (len - kFirstIndex) / kDescriptorSize;
2511  }
2512 
2514  return number_of_descriptors_storage() - number_of_descriptors();
2515  }
2516 
2517  inline void SetNumberOfDescriptors(int number_of_descriptors);
2518  inline int number_of_entries() { return number_of_descriptors(); }
2519 
2520  bool HasEnumCache() {
2521  return !IsEmpty() && !get(kEnumCacheIndex)->IsSmi();
2522  }
2523 
2525  set(kEnumCacheIndex, array->get(kEnumCacheIndex));
2526  }
2527 
2528  FixedArray* GetEnumCache() {
2529  ASSERT(HasEnumCache());
2530  FixedArray* bridge = FixedArray::cast(get(kEnumCacheIndex));
2531  return FixedArray::cast(bridge->get(kEnumCacheBridgeCacheIndex));
2532  }
2533 
2535  if (IsEmpty()) return false;
2536  Object* object = get(kEnumCacheIndex);
2537  if (object->IsSmi()) return false;
2538  FixedArray* bridge = FixedArray::cast(object);
2539  return !bridge->get(kEnumCacheBridgeIndicesCacheIndex)->IsSmi();
2540  }
2541 
2542  FixedArray* GetEnumIndicesCache() {
2543  ASSERT(HasEnumIndicesCache());
2544  FixedArray* bridge = FixedArray::cast(get(kEnumCacheIndex));
2545  return FixedArray::cast(bridge->get(kEnumCacheBridgeIndicesCacheIndex));
2546  }
2547 
2549  ASSERT(HasEnumCache());
2550  return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2551  kEnumCacheOffset);
2552  }
2553 
2554  void ClearEnumCache();
2555 
2556  // Initialize or change the enum cache,
2557  // using the supplied storage for the small "bridge".
2558  void SetEnumCache(FixedArray* bridge_storage,
2559  FixedArray* new_cache,
2560  Object* new_index_cache);
2561 
2562  // Accessors for fetching instance descriptor at descriptor number.
2563  inline String* GetKey(int descriptor_number);
2564  inline Object** GetKeySlot(int descriptor_number);
2565  inline Object* GetValue(int descriptor_number);
2566  inline Object** GetValueSlot(int descriptor_number);
2567  inline PropertyDetails GetDetails(int descriptor_number);
2568  inline PropertyType GetType(int descriptor_number);
2569  inline int GetFieldIndex(int descriptor_number);
2570  inline JSFunction* GetConstantFunction(int descriptor_number);
2571  inline Object* GetCallbacksObject(int descriptor_number);
2572  inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2573 
2574  inline String* GetSortedKey(int descriptor_number);
2575  inline int GetSortedKeyIndex(int descriptor_number);
2576  inline void SetSortedKey(int pointer, int descriptor_number);
2577 
2578  // Accessor for complete descriptor.
2579  inline void Get(int descriptor_number, Descriptor* desc);
2580  inline void Set(int descriptor_number,
2581  Descriptor* desc,
2582  const WhitenessWitness&);
2583  inline void Set(int descriptor_number, Descriptor* desc);
2584 
2585  // Append automatically sets the enumeration index. This should only be used
2586  // to add descriptors in bulk at the end, followed by sorting the descriptor
2587  // array.
2588  inline void Append(Descriptor* desc, const WhitenessWitness&);
2589  inline void Append(Descriptor* desc);
2590 
2591  // Transfer a complete descriptor from the src descriptor array to this
2592  // descriptor array.
2593  void CopyFrom(int dst_index,
2594  DescriptorArray* src,
2595  int src_index,
2596  const WhitenessWitness&);
2597 
2598  MUST_USE_RESULT MaybeObject* CopyUpTo(int enumeration_index);
2599 
2600  // Sort the instance descriptors by the hash codes of their keys.
2601  void Sort();
2602 
2603  // Search the instance descriptors for given name.
2604  INLINE(int Search(String* name, int number_of_own_descriptors));
2605 
2606  // As the above, but uses DescriptorLookupCache and updates it when
2607  // necessary.
2608  INLINE(int SearchWithCache(String* name, Map* map));
2609 
2610  // Allocates a DescriptorArray, but returns the singleton
2611  // empty descriptor array object if number_of_descriptors is 0.
2612  MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2613  int slack = 0);
2614 
2615  // Casting.
2616  static inline DescriptorArray* cast(Object* obj);
2617 
2618  // Constant for denoting key was not found.
2619  static const int kNotFound = -1;
2620 
2621  static const int kDescriptorLengthIndex = 0;
2622  static const int kEnumCacheIndex = 1;
2623  static const int kFirstIndex = 2;
2624 
2625  // The length of the "bridge" to the enum cache.
2626  static const int kEnumCacheBridgeLength = 2;
2627  static const int kEnumCacheBridgeCacheIndex = 0;
2628  static const int kEnumCacheBridgeIndicesCacheIndex = 1;
2629 
2630  // Layout description.
2631  static const int kDescriptorLengthOffset = FixedArray::kHeaderSize;
2632  static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize;
2633  static const int kFirstOffset = kEnumCacheOffset + kPointerSize;
2634 
2635  // Layout description for the bridge array.
2636  static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
2637 
2638  // Layout of descriptor.
2639  static const int kDescriptorKey = 0;
2640  static const int kDescriptorDetails = 1;
2641  static const int kDescriptorValue = 2;
2642  static const int kDescriptorSize = 3;
2643 
2644 #ifdef OBJECT_PRINT
2645  // Print all the descriptors.
2646  inline void PrintDescriptors() {
2647  PrintDescriptors(stdout);
2648  }
2649  void PrintDescriptors(FILE* out);
2650 #endif
2651 
2652 #ifdef DEBUG
2653  // Is the descriptor array sorted and without duplicates?
2654  bool IsSortedNoDuplicates(int valid_descriptors = -1);
2655 
2656  // Is the descriptor array consistent with the back pointers in targets?
2657  bool IsConsistentWithBackPointers(Map* current_map);
2658 
2659  // Are two DescriptorArrays equal?
2660  bool IsEqualTo(DescriptorArray* other);
2661 #endif
2662 
2663  // The maximum number of descriptors we want in a descriptor array (should
2664  // fit in a page).
2665  static const int kMaxNumberOfDescriptors = 1024 + 512;
2666 
2667  // Returns the fixed array length required to hold number_of_descriptors
2668  // descriptors.
2669  static int LengthFor(int number_of_descriptors) {
2670  return ToKeyIndex(number_of_descriptors);
2671  }
2672 
2673  private:
2674  // An entry in a DescriptorArray, represented as an (array, index) pair.
2675  class Entry {
2676  public:
2677  inline explicit Entry(DescriptorArray* descs, int index) :
2678  descs_(descs), index_(index) { }
2679 
2680  inline PropertyType type() { return descs_->GetType(index_); }
2681  inline Object* GetCallbackObject() { return descs_->GetValue(index_); }
2682 
2683  private:
2684  DescriptorArray* descs_;
2685  int index_;
2686  };
2687 
2688  // Conversion from descriptor number to array indices.
2689  static int ToKeyIndex(int descriptor_number) {
2690  return kFirstIndex +
2691  (descriptor_number * kDescriptorSize) +
2692  kDescriptorKey;
2693  }
2694 
2695  static int ToDetailsIndex(int descriptor_number) {
2696  return kFirstIndex +
2697  (descriptor_number * kDescriptorSize) +
2698  kDescriptorDetails;
2699  }
2700 
2701  static int ToValueIndex(int descriptor_number) {
2702  return kFirstIndex +
2703  (descriptor_number * kDescriptorSize) +
2704  kDescriptorValue;
2705  }
2706 
2707  // Swap first and second descriptor.
2708  inline void SwapSortedKeys(int first, int second);
2709 
2710  DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2711 };
2712 
2713 
2715 
2716 template<SearchMode search_mode, typename T>
2717 inline int LinearSearch(T* array, String* name, int len, int valid_entries);
2718 
2719 
2720 template<SearchMode search_mode, typename T>
2721 inline int Search(T* array, String* name, int valid_entries = 0);
2722 
2723 
2724 // HashTable is a subclass of FixedArray that implements a hash table
2725 // that uses open addressing and quadratic probing.
2726 //
2727 // In order for the quadratic probing to work, elements that have not
2728 // yet been used and elements that have been deleted are
2729 // distinguished. Probing continues when deleted elements are
2730 // encountered and stops when unused elements are encountered.
2731 //
2732 // - Elements with key == undefined have not been used yet.
2733 // - Elements with key == the_hole have been deleted.
2734 //
2735 // The hash table class is parameterized with a Shape and a Key.
2736 // Shape must be a class with the following interface:
2737 // class ExampleShape {
2738 // public:
2739 // // Tells whether key matches other.
2740 // static bool IsMatch(Key key, Object* other);
2741 // // Returns the hash value for key.
2742 // static uint32_t Hash(Key key);
2743 // // Returns the hash value for object.
2744 // static uint32_t HashForObject(Key key, Object* object);
2745 // // Convert key to an object.
2746 // static inline Object* AsObject(Key key);
2747 // // The prefix size indicates number of elements in the beginning
2748 // // of the backing storage.
2749 // static const int kPrefixSize = ..;
2750 // // The Element size indicates number of elements per entry.
2751 // static const int kEntrySize = ..;
2752 // };
2753 // The prefix size indicates an amount of memory in the
2754 // beginning of the backing storage that can be used for non-element
2755 // information by subclasses.
2756 
2757 template<typename Key>
2758 class BaseShape {
2759  public:
2760  static const bool UsesSeed = false;
2761  static uint32_t Hash(Key key) { return 0; }
2762  static uint32_t SeededHash(Key key, uint32_t seed) {
2763  ASSERT(UsesSeed);
2764  return Hash(key);
2765  }
2766  static uint32_t HashForObject(Key key, Object* object) { return 0; }
2767  static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
2768  ASSERT(UsesSeed);
2769  return HashForObject(key, object);
2770  }
2771 };
2772 
2773 template<typename Shape, typename Key>
2774 class HashTable: public FixedArray {
2775  public:
2778  USE_CUSTOM_MINIMUM_CAPACITY
2779  };
2780 
2781  // Wrapper methods
2782  inline uint32_t Hash(Key key) {
2783  if (Shape::UsesSeed) {
2784  return Shape::SeededHash(key,
2785  GetHeap()->HashSeed());
2786  } else {
2787  return Shape::Hash(key);
2788  }
2789  }
2790 
2791  inline uint32_t HashForObject(Key key, Object* object) {
2792  if (Shape::UsesSeed) {
2793  return Shape::SeededHashForObject(key,
2794  GetHeap()->HashSeed(), object);
2795  } else {
2796  return Shape::HashForObject(key, object);
2797  }
2798  }
2799 
2800  // Returns the number of elements in the hash table.
2802  return Smi::cast(get(kNumberOfElementsIndex))->value();
2803  }
2804 
2805  // Returns the number of deleted elements in the hash table.
2807  return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2808  }
2809 
2810  // Returns the capacity of the hash table.
2811  int Capacity() {
2812  return Smi::cast(get(kCapacityIndex))->value();
2813  }
2814 
2815  // ElementAdded should be called whenever an element is added to a
2816  // hash table.
2817  void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2818 
2819  // ElementRemoved should be called whenever an element is removed from
2820  // a hash table.
2822  SetNumberOfElements(NumberOfElements() - 1);
2823  SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2824  }
2825  void ElementsRemoved(int n) {
2826  SetNumberOfElements(NumberOfElements() - n);
2827  SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2828  }
2829 
2830  // Returns a new HashTable object. Might return Failure.
2831  MUST_USE_RESULT static MaybeObject* Allocate(
2832  int at_least_space_for,
2833  MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
2834  PretenureFlag pretenure = NOT_TENURED);
2835 
2836  // Computes the required capacity for a table holding the given
2837  // number of elements. May be more than HashTable::kMaxCapacity.
2838  static int ComputeCapacity(int at_least_space_for);
2839 
2840  // Returns the key at entry.
2841  Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2842 
2843  // Tells whether k is a real key. The hole and undefined are not allowed
2844  // as keys and can be used to indicate missing or deleted elements.
2845  bool IsKey(Object* k) {
2846  return !k->IsTheHole() && !k->IsUndefined();
2847  }
2848 
2849  // Garbage collection support.
2850  void IteratePrefix(ObjectVisitor* visitor);
2851  void IterateElements(ObjectVisitor* visitor);
2852 
2853  // Casting.
2854  static inline HashTable* cast(Object* obj);
2855 
2856  // Compute the probe offset (quadratic probing).
2857  INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2858  return (n + n * n) >> 1;
2859  }
2860 
2861  static const int kNumberOfElementsIndex = 0;
2862  static const int kNumberOfDeletedElementsIndex = 1;
2863  static const int kCapacityIndex = 2;
2864  static const int kPrefixStartIndex = 3;
2865  static const int kElementsStartIndex =
2866  kPrefixStartIndex + Shape::kPrefixSize;
2867  static const int kEntrySize = Shape::kEntrySize;
2868  static const int kElementsStartOffset =
2869  kHeaderSize + kElementsStartIndex * kPointerSize;
2870  static const int kCapacityOffset =
2871  kHeaderSize + kCapacityIndex * kPointerSize;
2872 
2873  // Constant used for denoting a absent entry.
2874  static const int kNotFound = -1;
2875 
2876  // Maximal capacity of HashTable. Based on maximal length of underlying
2877  // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
2878  // cannot overflow.
2879  static const int kMaxCapacity =
2880  (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
2881 
2882  // Find entry for key otherwise return kNotFound.
2883  inline int FindEntry(Key key);
2884  int FindEntry(Isolate* isolate, Key key);
2885 
2886  protected:
2887  // Find the entry at which to insert element with the given key that
2888  // has the given hash value.
2889  uint32_t FindInsertionEntry(uint32_t hash);
2890 
2891  // Returns the index for an entry (of the key)
2892  static inline int EntryToIndex(int entry) {
2893  return (entry * kEntrySize) + kElementsStartIndex;
2894  }
2895 
2896  // Update the number of elements in the hash table.
2897  void SetNumberOfElements(int nof) {
2898  set(kNumberOfElementsIndex, Smi::FromInt(nof));
2899  }
2900 
2901  // Update the number of deleted elements in the hash table.
2903  set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
2904  }
2905 
2906  // Sets the capacity of the hash table.
2907  void SetCapacity(int capacity) {
2908  // To scale a computed hash code to fit within the hash table, we
2909  // use bit-wise AND with a mask, so the capacity must be positive
2910  // and non-zero.
2911  ASSERT(capacity > 0);
2912  ASSERT(capacity <= kMaxCapacity);
2913  set(kCapacityIndex, Smi::FromInt(capacity));
2914  }
2915 
2916 
2917  // Returns probe entry.
2918  static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2919  ASSERT(IsPowerOf2(size));
2920  return (hash + GetProbeOffset(number)) & (size - 1);
2921  }
2922 
2923  inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2924  return hash & (size - 1);
2925  }
2926 
2927  inline static uint32_t NextProbe(
2928  uint32_t last, uint32_t number, uint32_t size) {
2929  return (last + number) & (size - 1);
2930  }
2931 
2932  // Rehashes this hash-table into the new table.
2933  MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key);
2934 
2935  // Attempt to shrink hash table after removal of key.
2936  MUST_USE_RESULT MaybeObject* Shrink(Key key);
2937 
2938  // Ensure enough space for n additional elements.
2939  MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
2940 };
2941 
2942 
2943 // HashTableKey is an abstract superclass for virtual key behavior.
2945  public:
2946  // Returns whether the other object matches this key.
2947  virtual bool IsMatch(Object* other) = 0;
2948  // Returns the hash value for this key.
2949  virtual uint32_t Hash() = 0;
2950  // Returns the hash value for object.
2951  virtual uint32_t HashForObject(Object* key) = 0;
2952  // Returns the key object for storing into the hash table.
2953  // If allocations fails a failure object is returned.
2954  MUST_USE_RESULT virtual MaybeObject* AsObject() = 0;
2955  // Required.
2956  virtual ~HashTableKey() {}
2957 };
2958 
2959 
2960 class SymbolTableShape : public BaseShape<HashTableKey*> {
2961  public:
2962  static inline bool IsMatch(HashTableKey* key, Object* value) {
2963  return key->IsMatch(value);
2964  }
2965  static inline uint32_t Hash(HashTableKey* key) {
2966  return key->Hash();
2967  }
2968  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
2969  return key->HashForObject(object);
2970  }
2971  MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
2972  return key->AsObject();
2973  }
2974 
2975  static const int kPrefixSize = 0;
2976  static const int kEntrySize = 1;
2977 };
2978 
2979 class SeqAsciiString;
2980 
2981 // SymbolTable.
2982 //
2983 // No special elements in the prefix and the element size is 1
2984 // because only the symbol itself (the key) needs to be stored.
2985 class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
2986  public:
2987  // Find symbol in the symbol table. If it is not there yet, it is
2988  // added. The return value is the symbol table which might have
2989  // been enlarged. If the return value is not a failure, the symbol
2990  // pointer *s is set to the symbol found.
2991  MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s);
2992  MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str,
2993  Object** s);
2994  MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol(
2996  int from,
2997  int length,
2998  Object** s);
2999  MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str,
3000  Object** s);
3001  MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s);
3002 
3003  // Looks up a symbol that is equal to the given string and returns
3004  // true if it is found, assigning the symbol to the given output
3005  // parameter.
3006  bool LookupSymbolIfExists(String* str, String** symbol);
3007  bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
3008 
3009  // Casting.
3010  static inline SymbolTable* cast(Object* obj);
3011 
3012  private:
3013  MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s);
3014 
3015  template <bool seq_ascii> friend class JsonParser;
3016 
3018 };
3019 
3020 
3021 class MapCacheShape : public BaseShape<HashTableKey*> {
3022  public:
3023  static inline bool IsMatch(HashTableKey* key, Object* value) {
3024  return key->IsMatch(value);
3025  }
3026  static inline uint32_t Hash(HashTableKey* key) {
3027  return key->Hash();
3028  }
3029 
3030  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
3031  return key->HashForObject(object);
3032  }
3033 
3034  MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
3035  return key->AsObject();
3036  }
3037 
3038  static const int kPrefixSize = 0;
3039  static const int kEntrySize = 2;
3040 };
3041 
3042 
3043 // MapCache.
3044 //
3045 // Maps keys that are a fixed array of symbols to a map.
3046 // Used for canonicalize maps for object literals.
3047 class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
3048  public:
3049  // Find cached value for a string key, otherwise return null.
3050  Object* Lookup(FixedArray* key);
3051  MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
3052  static inline MapCache* cast(Object* obj);
3053 
3054  private:
3056 };
3057 
3058 
3059 template <typename Shape, typename Key>
3060 class Dictionary: public HashTable<Shape, Key> {
3061  public:
3062  static inline Dictionary<Shape, Key>* cast(Object* obj) {
3063  return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
3064  }
3065 
3066  // Returns the value at entry.
3067  Object* ValueAt(int entry) {
3068  return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
3069  }
3070 
3071  // Set the value for entry.
3072  void ValueAtPut(int entry, Object* value) {
3073  this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
3074  }
3075 
3076  // Returns the property details for the property at entry.
3077  PropertyDetails DetailsAt(int entry) {
3078  ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
3079  return PropertyDetails(
3080  Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
3081  }
3082 
3083  // Set the details for entry.
3084  void DetailsAtPut(int entry, PropertyDetails value) {
3085  this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
3086  }
3087 
3088  // Sorting support
3089  void CopyValuesTo(FixedArray* elements);
3090 
3091  // Delete a property from the dictionary.
3092  Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
3093 
3094  // Attempt to shrink the dictionary after deletion of key.
3095  MUST_USE_RESULT MaybeObject* Shrink(Key key);
3096 
3097  // Returns the number of elements in the dictionary filtering out properties
3098  // with the specified attributes.
3099  int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3100 
3101  // Returns the number of enumerable elements in the dictionary.
3102  int NumberOfEnumElements();
3103 
3104  enum SortMode { UNSORTED, SORTED };
3105  // Copies keys to preallocated fixed array.
3106  void CopyKeysTo(FixedArray* storage,
3107  PropertyAttributes filter,
3108  SortMode sort_mode);
3109  // Fill in details for properties into storage.
3110  void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode);
3111 
3112  // Accessors for next enumeration index.
3113  void SetNextEnumerationIndex(int index) {
3114  ASSERT(index != 0);
3115  this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
3116  }
3117 
3119  return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
3120  }
3121 
3122  // Returns a new array for dictionary usage. Might return Failure.
3123  MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for);
3124 
3125  // Ensure enough space for n additional elements.
3126  MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
3127 
3128 #ifdef OBJECT_PRINT
3129  inline void Print() {
3130  Print(stdout);
3131  }
3132  void Print(FILE* out);
3133 #endif
3134  // Returns the key (slow).
3135  Object* SlowReverseLookup(Object* value);
3136 
3137  // Sets the entry to (key, value) pair.
3138  inline void SetEntry(int entry,
3139  Object* key,
3140  Object* value);
3141  inline void SetEntry(int entry,
3142  Object* key,
3143  Object* value,
3144  PropertyDetails details);
3145 
3146  MUST_USE_RESULT MaybeObject* Add(Key key,
3147  Object* value,
3148  PropertyDetails details);
3149 
3150  protected:
3151  // Generic at put operation.
3152  MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
3153 
3154  // Add entry to dictionary.
3155  MUST_USE_RESULT MaybeObject* AddEntry(Key key,
3156  Object* value,
3157  PropertyDetails details,
3158  uint32_t hash);
3159 
3160  // Generate new enumeration indices to avoid enumeration index overflow.
3161  MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
3162  static const int kMaxNumberKeyIndex =
3164  static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3165 };
3166 
3167 
3168 class StringDictionaryShape : public BaseShape<String*> {
3169  public:
3170  static inline bool IsMatch(String* key, Object* other);
3171  static inline uint32_t Hash(String* key);
3172  static inline uint32_t HashForObject(String* key, Object* object);
3173  MUST_USE_RESULT static inline MaybeObject* AsObject(String* key);
3174  static const int kPrefixSize = 2;
3175  static const int kEntrySize = 3;
3176  static const bool kIsEnumerable = true;
3177 };
3178 
3179 
3180 class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
3181  public:
3182  static inline StringDictionary* cast(Object* obj) {
3183  ASSERT(obj->IsDictionary());
3184  return reinterpret_cast<StringDictionary*>(obj);
3185  }
3186 
3187  // Copies enumerable keys to preallocated fixed array.
3188  FixedArray* CopyEnumKeysTo(FixedArray* storage);
3189  static void DoGenerateNewEnumerationIndices(
3190  Handle<StringDictionary> dictionary);
3191 
3192  // For transforming properties of a JSObject.
3193  MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor(
3194  JSObject* obj,
3195  int unused_property_fields);
3196 
3197  // Find entry for key, otherwise return kNotFound. Optimized version of
3198  // HashTable::FindEntry.
3199  int FindEntry(String* key);
3200 };
3201 
3202 
3203 class NumberDictionaryShape : public BaseShape<uint32_t> {
3204  public:
3205  static inline bool IsMatch(uint32_t key, Object* other);
3206  MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
3207  static const int kEntrySize = 3;
3208  static const bool kIsEnumerable = false;
3209 };
3210 
3211 
3213  public:
3214  static const bool UsesSeed = true;
3215  static const int kPrefixSize = 2;
3216 
3217  static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3218  static inline uint32_t SeededHashForObject(uint32_t key,
3219  uint32_t seed,
3220  Object* object);
3221 };
3222 
3223 
3225  public:
3226  static const int kPrefixSize = 0;
3227 
3228  static inline uint32_t Hash(uint32_t key);
3229  static inline uint32_t HashForObject(uint32_t key, Object* object);
3230 };
3231 
3232 
3234  : public Dictionary<SeededNumberDictionaryShape, uint32_t> {
3235  public:
3237  ASSERT(obj->IsDictionary());
3238  return reinterpret_cast<SeededNumberDictionary*>(obj);
3239  }
3240 
3241  // Type specific at put (default NONE attributes is used when adding).
3242  MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3243  MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key,
3244  Object* value,
3245  PropertyDetails details);
3246 
3247  // Set an existing entry or add a new one if needed.
3248  // Return the updated dictionary.
3250  Handle<SeededNumberDictionary> dictionary,
3251  uint32_t index,
3252  Handle<Object> value,
3253  PropertyDetails details);
3254 
3255  MUST_USE_RESULT MaybeObject* Set(uint32_t key,
3256  Object* value,
3257  PropertyDetails details);
3258 
3259  void UpdateMaxNumberKey(uint32_t key);
3260 
3261  // If slow elements are required we will never go back to fast-case
3262  // for the elements kept in this dictionary. We require slow
3263  // elements if an element has been added at an index larger than
3264  // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3265  // when defining a getter or setter with a number key.
3266  inline bool requires_slow_elements();
3267  inline void set_requires_slow_elements();
3268 
3269  // Get the value of the max number key that has been added to this
3270  // dictionary. max_number_key can only be called if
3271  // requires_slow_elements returns false.
3272  inline uint32_t max_number_key();
3273 
3274  // Bit masks.
3275  static const int kRequiresSlowElementsMask = 1;
3276  static const int kRequiresSlowElementsTagSize = 1;
3277  static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
3278 };
3279 
3280 
3282  : public Dictionary<UnseededNumberDictionaryShape, uint32_t> {
3283  public:
3285  ASSERT(obj->IsDictionary());
3286  return reinterpret_cast<UnseededNumberDictionary*>(obj);
3287  }
3288 
3289  // Type specific at put (default NONE attributes is used when adding).
3290  MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3291  MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value);
3292 
3293  // Set an existing entry or add a new one if needed.
3294  // Return the updated dictionary.
3297  uint32_t index,
3298  Handle<Object> value);
3299 
3300  MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value);
3301 };
3302 
3303 
3304 template <int entrysize>
3305 class ObjectHashTableShape : public BaseShape<Object*> {
3306  public:
3307  static inline bool IsMatch(Object* key, Object* other);
3308  static inline uint32_t Hash(Object* key);
3309  static inline uint32_t HashForObject(Object* key, Object* object);
3310  MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
3311  static const int kPrefixSize = 0;
3312  static const int kEntrySize = entrysize;
3313 };
3314 
3315 
3316 // ObjectHashSet holds keys that are arbitrary objects by using the identity
3317 // hash of the key for hashing purposes.
3318 class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
3319  public:
3320  static inline ObjectHashSet* cast(Object* obj) {
3321  ASSERT(obj->IsHashTable());
3322  return reinterpret_cast<ObjectHashSet*>(obj);
3323  }
3324 
3325  // Looks up whether the given key is part of this hash set.
3326  bool Contains(Object* key);
3327 
3328  // Adds the given key to this hash set.
3329  MUST_USE_RESULT MaybeObject* Add(Object* key);
3330 
3331  // Removes the given key from this hash set.
3332  MUST_USE_RESULT MaybeObject* Remove(Object* key);
3333 };
3334 
3335 
3336 // ObjectHashTable maps keys that are arbitrary objects to object values by
3337 // using the identity hash of the key for hashing purposes.
3338 class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
3339  public:
3340  static inline ObjectHashTable* cast(Object* obj) {
3341  ASSERT(obj->IsHashTable());
3342  return reinterpret_cast<ObjectHashTable*>(obj);
3343  }
3344 
3345  // Looks up the value associated with the given key. The hole value is
3346  // returned in case the key is not present.
3347  Object* Lookup(Object* key);
3348 
3349  // Adds (or overwrites) the value associated with the given key. Mapping a
3350  // key to the hole value causes removal of the whole entry.
3351  MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
3352 
3353  private:
3354  friend class MarkCompactCollector;
3355 
3356  void AddEntry(int entry, Object* key, Object* value);
3357  void RemoveEntry(int entry);
3358 
3359  // Returns the index to the value of an entry.
3360  static inline int EntryToValueIndex(int entry) {
3361  return EntryToIndex(entry) + 1;
3362  }
3363 };
3364 
3365 
3366 // JSFunctionResultCache caches results of some JSFunction invocation.
3367 // It is a fixed array with fixed structure:
3368 // [0]: factory function
3369 // [1]: finger index
3370 // [2]: current cache size
3371 // [3]: dummy field.
3372 // The rest of array are key/value pairs.
3373 class JSFunctionResultCache: public FixedArray {
3374  public:
3375  static const int kFactoryIndex = 0;
3376  static const int kFingerIndex = kFactoryIndex + 1;
3377  static const int kCacheSizeIndex = kFingerIndex + 1;
3378  static const int kDummyIndex = kCacheSizeIndex + 1;
3379  static const int kEntriesIndex = kDummyIndex + 1;
3380 
3381  static const int kEntrySize = 2; // key + value
3382 
3383  static const int kFactoryOffset = kHeaderSize;
3384  static const int kFingerOffset = kFactoryOffset + kPointerSize;
3385  static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
3386 
3387  inline void MakeZeroSize();
3388  inline void Clear();
3389 
3390  inline int size();
3391  inline void set_size(int size);
3392  inline int finger_index();
3393  inline void set_finger_index(int finger_index);
3394 
3395  // Casting
3396  static inline JSFunctionResultCache* cast(Object* obj);
3397 
3399 };
3400 
3401 
3402 // ScopeInfo represents information about different scopes of a source
3403 // program and the allocation of the scope's variables. Scope information
3404 // is stored in a compressed form in ScopeInfo objects and is used
3405 // at runtime (stack dumps, deoptimization, etc.).
3406 
3407 // This object provides quick access to scope info details for runtime
3408 // routines.
3409 class ScopeInfo : public FixedArray {
3410  public:
3411  static inline ScopeInfo* cast(Object* object);
3412 
3413  // Return the type of this scope.
3414  ScopeType Type();
3415 
3416  // Does this scope call eval?
3417  bool CallsEval();
3418 
3419  // Return the language mode of this scope.
3420  LanguageMode language_mode();
3421 
3422  // Does this scope make a non-strict eval call?
3424  return CallsEval() && (language_mode() == CLASSIC_MODE);
3425  }
3426 
3427  // Return the total number of locals allocated on the stack and in the
3428  // context. This includes the parameters that are allocated in the context.
3429  int LocalCount();
3430 
3431  // Return the number of stack slots for code. This number consists of two
3432  // parts:
3433  // 1. One stack slot per stack allocated local.
3434  // 2. One stack slot for the function name if it is stack allocated.
3435  int StackSlotCount();
3436 
3437  // Return the number of context slots for code if a context is allocated. This
3438  // number consists of three parts:
3439  // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3440  // 2. One context slot per context allocated local.
3441  // 3. One context slot for the function name if it is context allocated.
3442  // Parameters allocated in the context count as context allocated locals. If
3443  // no contexts are allocated for this scope ContextLength returns 0.
3444  int ContextLength();
3445 
3446  // Is this scope the scope of a named function expression?
3447  bool HasFunctionName();
3448 
3449  // Return if this has context allocated locals.
3450  bool HasHeapAllocatedLocals();
3451 
3452  // Return if contexts are allocated for this scope.
3453  bool HasContext();
3454 
3455  // Return the function_name if present.
3456  String* FunctionName();
3457 
3458  // Return the name of the given parameter.
3459  String* ParameterName(int var);
3460 
3461  // Return the name of the given local.
3462  String* LocalName(int var);
3463 
3464  // Return the name of the given stack local.
3465  String* StackLocalName(int var);
3466 
3467  // Return the name of the given context local.
3468  String* ContextLocalName(int var);
3469 
3470  // Return the mode of the given context local.
3471  VariableMode ContextLocalMode(int var);
3472 
3473  // Return the initialization flag of the given context local.
3474  InitializationFlag ContextLocalInitFlag(int var);
3475 
3476  // Lookup support for serialized scope info. Returns the
3477  // the stack slot index for a given slot name if the slot is
3478  // present; otherwise returns a value < 0. The name must be a symbol
3479  // (canonicalized).
3480  int StackSlotIndex(String* name);
3481 
3482  // Lookup support for serialized scope info. Returns the
3483  // context slot index for a given slot name if the slot is present; otherwise
3484  // returns a value < 0. The name must be a symbol (canonicalized).
3485  // If the slot is present and mode != NULL, sets *mode to the corresponding
3486  // mode for that variable.
3487  int ContextSlotIndex(String* name,
3488  VariableMode* mode,
3489  InitializationFlag* init_flag);
3490 
3491  // Lookup support for serialized scope info. Returns the
3492  // parameter index for a given parameter name if the parameter is present;
3493  // otherwise returns a value < 0. The name must be a symbol (canonicalized).
3494  int ParameterIndex(String* name);
3495 
3496  // Lookup support for serialized scope info. Returns the function context
3497  // slot index if the function name is present and context-allocated (named
3498  // function expressions, only), otherwise returns a value < 0. The name
3499  // must be a symbol (canonicalized).
3500  int FunctionContextSlotIndex(String* name, VariableMode* mode);
3501 
3502  static Handle<ScopeInfo> Create(Scope* scope, Zone* zone);
3503 
3504  // Serializes empty scope info.
3505  static ScopeInfo* Empty();
3506 
3507 #ifdef DEBUG
3508  void Print();
3509 #endif
3510 
3511  // The layout of the static part of a ScopeInfo is as follows. Each entry is
3512  // numeric and occupies one array slot.
3513  // 1. A set of properties of the scope
3514  // 2. The number of parameters. This only applies to function scopes. For
3515  // non-function scopes this is 0.
3516  // 3. The number of non-parameter variables allocated on the stack.
3517  // 4. The number of non-parameter and parameter variables allocated in the
3518  // context.
3519 #define FOR_EACH_NUMERIC_FIELD(V) \
3520  V(Flags) \
3521  V(ParameterCount) \
3522  V(StackLocalCount) \
3523  V(ContextLocalCount)
3524 
3525 #define FIELD_ACCESSORS(name) \
3526  void Set##name(int value) { \
3527  set(k##name, Smi::FromInt(value)); \
3528  } \
3529  int name() { \
3530  if (length() > 0) { \
3531  return Smi::cast(get(k##name))->value(); \
3532  } else { \
3533  return 0; \
3534  } \
3535  }
3537 #undef FIELD_ACCESSORS
3538 
3539  private:
3540  enum {
3541 #define DECL_INDEX(name) k##name,
3543 #undef DECL_INDEX
3544 #undef FOR_EACH_NUMERIC_FIELD
3545  kVariablePartIndex
3546  };
3547 
3548  // The layout of the variable part of a ScopeInfo is as follows:
3549  // 1. ParameterEntries:
3550  // This part stores the names of the parameters for function scopes. One
3551  // slot is used per parameter, so in total this part occupies
3552  // ParameterCount() slots in the array. For other scopes than function
3553  // scopes ParameterCount() is 0.
3554  // 2. StackLocalEntries:
3555  // Contains the names of local variables that are allocated on the stack,
3556  // in increasing order of the stack slot index. One slot is used per stack
3557  // local, so in total this part occupies StackLocalCount() slots in the
3558  // array.
3559  // 3. ContextLocalNameEntries:
3560  // Contains the names of local variables and parameters that are allocated
3561  // in the context. They are stored in increasing order of the context slot
3562  // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3563  // context local, so in total this part occupies ContextLocalCount() slots
3564  // in the array.
3565  // 4. ContextLocalInfoEntries:
3566  // Contains the variable modes and initialization flags corresponding to
3567  // the context locals in ContextLocalNameEntries. One slot is used per
3568  // context local, so in total this part occupies ContextLocalCount()
3569  // slots in the array.
3570  // 5. FunctionNameEntryIndex:
3571  // If the scope belongs to a named function expression this part contains
3572  // information about the function variable. It always occupies two array
3573  // slots: a. The name of the function variable.
3574  // b. The context or stack slot index for the variable.
3575  int ParameterEntriesIndex();
3576  int StackLocalEntriesIndex();
3577  int ContextLocalNameEntriesIndex();
3578  int ContextLocalInfoEntriesIndex();
3579  int FunctionNameEntryIndex();
3580 
3581  // Location of the function variable for named function expressions.
3582  enum FunctionVariableInfo {
3583  NONE, // No function name present.
3584  STACK, // Function
3585  CONTEXT,
3586  UNUSED
3587  };
3588 
3589  // Properties of scopes.
3590  class TypeField: public BitField<ScopeType, 0, 3> {};
3591  class CallsEvalField: public BitField<bool, 3, 1> {};
3592  class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
3593  class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {};
3594  class FunctionVariableMode: public BitField<VariableMode, 8, 3> {};
3595 
3596  // BitFields representing the encoded information for context locals in the
3597  // ContextLocalInfoEntries part.
3598  class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
3599  class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
3600 };
3601 
3602 
3603 // The cache for maps used by normalized (dictionary mode) objects.
3604 // Such maps do not have property descriptors, so a typical program
3605 // needs very limited number of distinct normalized maps.
3606 class NormalizedMapCache: public FixedArray {
3607  public:
3608  static const int kEntries = 64;
3609 
3610  MUST_USE_RESULT MaybeObject* Get(JSObject* object,
3612 
3613  void Clear();
3614 
3615  // Casting
3616  static inline NormalizedMapCache* cast(Object* obj);
3617 
3619 };
3620 
3621 
3622 // ByteArray represents fixed sized byte arrays. Used for the relocation info
3623 // that is attached to code objects.
3624 class ByteArray: public FixedArrayBase {
3625  public:
3626  inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
3627 
3628  // Setter and getter.
3629  inline byte get(int index);
3630  inline void set(int index, byte value);
3631 
3632  // Treat contents as an int array.
3633  inline int get_int(int index);
3634 
3635  static int SizeFor(int length) {
3636  return OBJECT_POINTER_ALIGN(kHeaderSize + length);
3637  }
3638  // We use byte arrays for free blocks in the heap. Given a desired size in
3639  // bytes that is a multiple of the word size and big enough to hold a byte
3640  // array, this function returns the number of elements a byte array should
3641  // have.
3642  static int LengthFor(int size_in_bytes) {
3643  ASSERT(IsAligned(size_in_bytes, kPointerSize));
3644  ASSERT(size_in_bytes >= kHeaderSize);
3645  return size_in_bytes - kHeaderSize;
3646  }
3647 
3648  // Returns data start address.
3649  inline Address GetDataStartAddress();
3650 
3651  // Returns a pointer to the ByteArray object for a given data start address.
3652  static inline ByteArray* FromDataStartAddress(Address address);
3653 
3654  // Casting.
3655  static inline ByteArray* cast(Object* obj);
3656 
3657  // Dispatched behavior.
3658  inline int ByteArraySize() {
3659  return SizeFor(this->length());
3660  }
3661 #ifdef OBJECT_PRINT
3662  inline void ByteArrayPrint() {
3663  ByteArrayPrint(stdout);
3664  }
3665  void ByteArrayPrint(FILE* out);
3666 #endif
3667  DECLARE_VERIFIER(ByteArray)
3668 
3669  // Layout description.
3670  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3671 
3672  // Maximal memory consumption for a single ByteArray.
3673  static const int kMaxSize = 512 * MB;
3674  // Maximal length of a single ByteArray.
3675  static const int kMaxLength = kMaxSize - kHeaderSize;
3676 
3677  private:
3678  DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
3679 };
3680 
3681 
3682 // FreeSpace represents fixed sized areas of the heap that are not currently in
3683 // use. Used by the heap and GC.
3684 class FreeSpace: public HeapObject {
3685  public:
3686  // [size]: size of the free space including the header.
3687  inline int size();
3688  inline void set_size(int value);
3689 
3690  inline int Size() { return size(); }
3691 
3692  // Casting.
3693  static inline FreeSpace* cast(Object* obj);
3694 
3695 #ifdef OBJECT_PRINT
3696  inline void FreeSpacePrint() {
3697  FreeSpacePrint(stdout);
3698  }
3699  void FreeSpacePrint(FILE* out);
3700 #endif
3701  DECLARE_VERIFIER(FreeSpace)
3702 
3703  // Layout description.
3704  // Size is smi tagged when it is stored.
3705  static const int kSizeOffset = HeapObject::kHeaderSize;
3706  static const int kHeaderSize = kSizeOffset + kPointerSize;
3707 
3708  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3709 
3710  private:
3711  DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
3712 };
3713 
3714 
3715 // An ExternalArray represents a fixed-size array of primitive values
3716 // which live outside the JavaScript heap. Its subclasses are used to
3717 // implement the CanvasArray types being defined in the WebGL
3718 // specification. As of this writing the first public draft is not yet
3719 // available, but Khronos members can access the draft at:
3720 // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
3721 //
3722 // The semantics of these arrays differ from CanvasPixelArray.
3723 // Out-of-range values passed to the setter are converted via a C
3724 // cast, not clamping. Out-of-range indices cause exceptions to be
3725 // raised rather than being silently ignored.
3727  public:
3728  inline bool is_the_hole(int index) { return false; }
3729 
3730  // [external_pointer]: The pointer to the external memory area backing this
3731  // external array.
3732  DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
3733 
3734  // Casting.
3735  static inline ExternalArray* cast(Object* obj);
3736 
3737  // Maximal acceptable length for an external array.
3738  static const int kMaxLength = 0x3fffffff;
3739 
3740  // ExternalArray headers are not quadword aligned.
3741  static const int kExternalPointerOffset =
3742  POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize);
3743  static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
3744  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3745 
3746  private:
3747  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
3748 };
3749 
3750 
3751 // A ExternalPixelArray represents a fixed-size byte array with special
3752 // semantics used for implementing the CanvasPixelArray object. Please see the
3753 // specification at:
3754 
3755 // http://www.whatwg.org/specs/web-apps/current-work/
3756 // multipage/the-canvas-element.html#canvaspixelarray
3757 // In particular, write access clamps the value written to 0 or 255 if the
3758 // value written is outside this range.
3759 class ExternalPixelArray: public ExternalArray {
3760  public:
3761  inline uint8_t* external_pixel_pointer();
3762 
3763  // Setter and getter.
3764  inline uint8_t get_scalar(int index);
3765  MUST_USE_RESULT inline MaybeObject* get(int index);
3766  inline void set(int index, uint8_t value);
3767 
3768  // This accessor applies the correct conversion from Smi, HeapNumber and
3769  // undefined and clamps the converted value between 0 and 255.
3770  Object* SetValue(uint32_t index, Object* value);
3771 
3772  // Casting.
3773  static inline ExternalPixelArray* cast(Object* obj);
3774 
3775 #ifdef OBJECT_PRINT
3776  inline void ExternalPixelArrayPrint() {
3777  ExternalPixelArrayPrint(stdout);
3778  }
3779  void ExternalPixelArrayPrint(FILE* out);
3780 #endif
3782 
3783  private:
3785 };
3786 
3787 
3789  public:
3790  // Setter and getter.
3791  inline int8_t get_scalar(int index);
3792  MUST_USE_RESULT inline MaybeObject* get(int index);
3793  inline void set(int index, int8_t value);
3794 
3795  // This accessor applies the correct conversion from Smi, HeapNumber
3796  // and undefined.
3797  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3798 
3799  // Casting.
3800  static inline ExternalByteArray* cast(Object* obj);
3801 
3802 #ifdef OBJECT_PRINT
3803  inline void ExternalByteArrayPrint() {
3804  ExternalByteArrayPrint(stdout);
3805  }
3806  void ExternalByteArrayPrint(FILE* out);
3807 #endif
3809 
3810  private:
3812 };
3813 
3814 
3816  public:
3817  // Setter and getter.
3818  inline uint8_t get_scalar(int index);
3819  MUST_USE_RESULT inline MaybeObject* get(int index);
3820  inline void set(int index, uint8_t value);
3821 
3822  // This accessor applies the correct conversion from Smi, HeapNumber
3823  // and undefined.
3824  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3825 
3826  // Casting.
3827  static inline ExternalUnsignedByteArray* cast(Object* obj);
3828 
3829 #ifdef OBJECT_PRINT
3830  inline void ExternalUnsignedByteArrayPrint() {
3831  ExternalUnsignedByteArrayPrint(stdout);
3832  }
3833  void ExternalUnsignedByteArrayPrint(FILE* out);
3834 #endif
3836 
3837  private:
3839 };
3840 
3841 
3843  public:
3844  // Setter and getter.
3845  inline int16_t get_scalar(int index);
3846  MUST_USE_RESULT inline MaybeObject* get(int index);
3847  inline void set(int index, int16_t value);
3848 
3849  // This accessor applies the correct conversion from Smi, HeapNumber
3850  // and undefined.
3851  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3852 
3853  // Casting.
3854  static inline ExternalShortArray* cast(Object* obj);
3855 
3856 #ifdef OBJECT_PRINT
3857  inline void ExternalShortArrayPrint() {
3858  ExternalShortArrayPrint(stdout);
3859  }
3860  void ExternalShortArrayPrint(FILE* out);
3861 #endif
3863 
3864  private:
3866 };
3867 
3868 
3870  public:
3871  // Setter and getter.
3872  inline uint16_t get_scalar(int index);
3873  MUST_USE_RESULT inline MaybeObject* get(int index);
3874  inline void set(int index, uint16_t value);
3875 
3876  // This accessor applies the correct conversion from Smi, HeapNumber
3877  // and undefined.
3878  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3879 
3880  // Casting.
3881  static inline ExternalUnsignedShortArray* cast(Object* obj);
3882 
3883 #ifdef OBJECT_PRINT
3884  inline void ExternalUnsignedShortArrayPrint() {
3885  ExternalUnsignedShortArrayPrint(stdout);
3886  }
3887  void ExternalUnsignedShortArrayPrint(FILE* out);
3888 #endif
3890 
3891  private:
3893 };
3894 
3895 
3897  public:
3898  // Setter and getter.
3899  inline int32_t get_scalar(int index);
3900  MUST_USE_RESULT inline MaybeObject* get(int index);
3901  inline void set(int index, int32_t value);
3902 
3903  // This accessor applies the correct conversion from Smi, HeapNumber
3904  // and undefined.
3905  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3906 
3907  // Casting.
3908  static inline ExternalIntArray* cast(Object* obj);
3909 
3910 #ifdef OBJECT_PRINT
3911  inline void ExternalIntArrayPrint() {
3912  ExternalIntArrayPrint(stdout);
3913  }
3914  void ExternalIntArrayPrint(FILE* out);
3915 #endif
3917 
3918  private:
3920 };
3921 
3922 
3924  public:
3925  // Setter and getter.
3926  inline uint32_t get_scalar(int index);
3927  MUST_USE_RESULT inline MaybeObject* get(int index);
3928  inline void set(int index, uint32_t value);
3929 
3930  // This accessor applies the correct conversion from Smi, HeapNumber
3931  // and undefined.
3932  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3933 
3934  // Casting.
3935  static inline ExternalUnsignedIntArray* cast(Object* obj);
3936 
3937 #ifdef OBJECT_PRINT
3938  inline void ExternalUnsignedIntArrayPrint() {
3939  ExternalUnsignedIntArrayPrint(stdout);
3940  }
3941  void ExternalUnsignedIntArrayPrint(FILE* out);
3942 #endif
3944 
3945  private:
3947 };
3948 
3949 
3951  public:
3952  // Setter and getter.
3953  inline float get_scalar(int index);
3954  MUST_USE_RESULT inline MaybeObject* get(int index);
3955  inline void set(int index, float value);
3956 
3957  // This accessor applies the correct conversion from Smi, HeapNumber
3958  // and undefined.
3959  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3960 
3961  // Casting.
3962  static inline ExternalFloatArray* cast(Object* obj);
3963 
3964 #ifdef OBJECT_PRINT
3965  inline void ExternalFloatArrayPrint() {
3966  ExternalFloatArrayPrint(stdout);
3967  }
3968  void ExternalFloatArrayPrint(FILE* out);
3969 #endif
3971 
3972  private:
3974 };
3975 
3976 
3978  public:
3979  // Setter and getter.
3980  inline double get_scalar(int index);
3981  MUST_USE_RESULT inline MaybeObject* get(int index);
3982  inline void set(int index, double value);
3983 
3984  // This accessor applies the correct conversion from Smi, HeapNumber
3985  // and undefined.
3986  MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
3987 
3988  // Casting.
3989  static inline ExternalDoubleArray* cast(Object* obj);
3990 
3991 #ifdef OBJECT_PRINT
3992  inline void ExternalDoubleArrayPrint() {
3993  ExternalDoubleArrayPrint(stdout);
3994  }
3995  void ExternalDoubleArrayPrint(FILE* out);
3996 #endif // OBJECT_PRINT
3998 
3999  private:
4001 };
4002 
4003 
4004 // DeoptimizationInputData is a fixed array used to hold the deoptimization
4005 // data for code generated by the Hydrogen/Lithium compiler. It also
4006 // contains information about functions that were inlined. If N different
4007 // functions were inlined then first N elements of the literal array will
4008 // contain these functions.
4009 //
4010 // It can be empty.
4011 class DeoptimizationInputData: public FixedArray {
4012  public:
4013  // Layout description. Indices in the array.
4014  static const int kTranslationByteArrayIndex = 0;
4015  static const int kInlinedFunctionCountIndex = 1;
4016  static const int kLiteralArrayIndex = 2;
4017  static const int kOsrAstIdIndex = 3;
4018  static const int kOsrPcOffsetIndex = 4;
4019  static const int kFirstDeoptEntryIndex = 5;
4020 
4021  // Offsets of deopt entry elements relative to the start of the entry.
4022  static const int kAstIdRawOffset = 0;
4023  static const int kTranslationIndexOffset = 1;
4024  static const int kArgumentsStackHeightOffset = 2;
4025  static const int kPcOffset = 3;
4026  static const int kDeoptEntrySize = 4;
4027 
4028  // Simple element accessors.
4029 #define DEFINE_ELEMENT_ACCESSORS(name, type) \
4030  type* name() { \
4031  return type::cast(get(k##name##Index)); \
4032  } \
4033  void Set##name(type* value) { \
4034  set(k##name##Index, value); \
4035  }
4036 
4037  DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4038  DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4039  DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4040  DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4041  DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4042 
4043 #undef DEFINE_ELEMENT_ACCESSORS
4044 
4045  // Accessors for elements of the ith deoptimization entry.
4046 #define DEFINE_ENTRY_ACCESSORS(name, type) \
4047  type* name(int i) { \
4048  return type::cast(get(IndexForEntry(i) + k##name##Offset)); \
4049  } \
4050  void Set##name(int i, type* value) { \
4051  set(IndexForEntry(i) + k##name##Offset, value); \
4052  }
4053 
4054  DEFINE_ENTRY_ACCESSORS(AstIdRaw, Smi)
4055  DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4056  DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
4057  DEFINE_ENTRY_ACCESSORS(Pc, Smi)
4058 
4059 #undef DEFINE_ENTRY_ACCESSORS
4060 
4061  BailoutId AstId(int i) {
4062  return BailoutId(AstIdRaw(i)->value());
4063  }
4064 
4065  void SetAstId(int i, BailoutId value) {
4066  SetAstIdRaw(i, Smi::FromInt(value.ToInt()));
4067  }
4068 
4069  int DeoptCount() {
4070  return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
4071  }
4072 
4073  // Allocates a DeoptimizationInputData.
4074  MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count,
4075  PretenureFlag pretenure);
4076 
4077  // Casting.
4078  static inline DeoptimizationInputData* cast(Object* obj);
4079 
4080 #ifdef ENABLE_DISASSEMBLER
4081  void DeoptimizationInputDataPrint(FILE* out);
4082 #endif
4083 
4084  private:
4085  static int IndexForEntry(int i) {
4086  return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4087  }
4088 
4089  static int LengthFor(int entry_count) {
4090  return IndexForEntry(entry_count);
4091  }
4092 };
4093 
4094 
4095 // DeoptimizationOutputData is a fixed array used to hold the deoptimization
4096 // data for code generated by the full compiler.
4097 // The format of the these objects is
4098 // [i * 2]: Ast ID for ith deoptimization.
4099 // [i * 2 + 1]: PC and state of ith deoptimization
4100 class DeoptimizationOutputData: public FixedArray {
4101  public:
4102  int DeoptPoints() { return length() / 2; }
4103 
4104  BailoutId AstId(int index) {
4105  return BailoutId(Smi::cast(get(index * 2))->value());
4106  }
4107 
4108  void SetAstId(int index, BailoutId id) {
4109  set(index * 2, Smi::FromInt(id.ToInt()));
4110  }
4111 
4112  Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
4113  void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
4114 
4115  static int LengthOfFixedArray(int deopt_points) {
4116  return deopt_points * 2;
4117  }
4118 
4119  // Allocates a DeoptimizationOutputData.
4120  MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points,
4121  PretenureFlag pretenure);
4122 
4123  // Casting.
4124  static inline DeoptimizationOutputData* cast(Object* obj);
4125 
4126 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
4127  void DeoptimizationOutputDataPrint(FILE* out);
4128 #endif
4129 };
4130 
4131 
4132 // Forward declaration.
4133 class JSGlobalPropertyCell;
4134 
4135 // TypeFeedbackCells is a fixed array used to hold the association between
4136 // cache cells and AST ids for code generated by the full compiler.
4137 // The format of the these objects is
4138 // [i * 2]: Global property cell of ith cache cell.
4139 // [i * 2 + 1]: Ast ID for ith cache cell.
4140 class TypeFeedbackCells: public FixedArray {
4141  public:
4142  int CellCount() { return length() / 2; }
4143  static int LengthOfFixedArray(int cell_count) { return cell_count * 2; }
4144 
4145  // Accessors for AST ids associated with cache values.
4146  inline TypeFeedbackId AstId(int index);
4147  inline void SetAstId(int index, TypeFeedbackId id);
4148 
4149  // Accessors for global property cells holding the cache values.
4150  inline JSGlobalPropertyCell* Cell(int index);
4151  inline void SetCell(int index, JSGlobalPropertyCell* cell);
4152 
4153  // The object that indicates an uninitialized cache.
4154  static inline Handle<Object> UninitializedSentinel(Isolate* isolate);
4155 
4156  // The object that indicates a megamorphic state.
4157  static inline Handle<Object> MegamorphicSentinel(Isolate* isolate);
4158 
4159  // A raw version of the uninitialized sentinel that's safe to read during
4160  // garbage collection (e.g., for patching the cache).
4161  static inline Object* RawUninitializedSentinel(Heap* heap);
4162 
4163  // Casting.
4164  static inline TypeFeedbackCells* cast(Object* obj);
4165 
4166  static const int kForInFastCaseMarker = 0;
4167  static const int kForInSlowCaseMarker = 1;
4168 };
4169 
4170 
4171 // Forward declaration.
4172 class SafepointEntry;
4173 class TypeFeedbackInfo;
4174 
4175 // Code describes objects with on-the-fly generated machine code.
4176 class Code: public HeapObject {
4177  public:
4178  // Opaque data type for encapsulating code flags like kind, inline
4179  // cache state, and arguments count.
4180  // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that
4181  // enumeration type has correct value range (see Issue 830 for more details).
4182  enum Flags {
4183  FLAGS_MIN_VALUE = kMinInt,
4184  FLAGS_MAX_VALUE = kMaxInt
4185  };
4186 
4187 #define CODE_KIND_LIST(V) \
4188  V(FUNCTION) \
4189  V(OPTIMIZED_FUNCTION) \
4190  V(STUB) \
4191  V(BUILTIN) \
4192  V(LOAD_IC) \
4193  V(KEYED_LOAD_IC) \
4194  V(CALL_IC) \
4195  V(KEYED_CALL_IC) \
4196  V(STORE_IC) \
4197  V(KEYED_STORE_IC) \
4198  V(UNARY_OP_IC) \
4199  V(BINARY_OP_IC) \
4200  V(COMPARE_IC) \
4201  V(TO_BOOLEAN_IC)
4202 
4203  enum Kind {
4204 #define DEFINE_CODE_KIND_ENUM(name) name,
4206 #undef DEFINE_CODE_KIND_ENUM
4207 
4208  // Pseudo-kinds.
4209  LAST_CODE_KIND = TO_BOOLEAN_IC,
4210  REGEXP = BUILTIN,
4211  FIRST_IC_KIND = LOAD_IC,
4212  LAST_IC_KIND = TO_BOOLEAN_IC
4213  };
4214 
4215  // No more than 16 kinds. The value is currently encoded in four bits in
4216  // Flags.
4217  STATIC_ASSERT(LAST_CODE_KIND < 16);
4218 
4219  // Types of stubs.
4220  enum StubType {
4228  };
4229 
4230  enum {
4231  NUMBER_OF_KINDS = LAST_IC_KIND + 1
4232  };
4233 
4234  typedef int ExtraICState;
4235 
4236  static const ExtraICState kNoExtraICState = 0;
4237 
4238 #ifdef ENABLE_DISASSEMBLER
4239  // Printing
4240  static const char* Kind2String(Kind kind);
4241  static const char* ICState2String(InlineCacheState state);
4242  static const char* StubType2String(StubType type);
4243  static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra);
4244  inline void Disassemble(const char* name) {
4245  Disassemble(name, stdout);
4246  }
4247  void Disassemble(const char* name, FILE* out);
4248 #endif // ENABLE_DISASSEMBLER
4249 
4250  // [instruction_size]: Size of the native instructions
4251  inline int instruction_size();
4252  inline void set_instruction_size(int value);
4253 
4254  // [relocation_info]: Code relocation information
4255  DECL_ACCESSORS(relocation_info, ByteArray)
4256  void InvalidateRelocation();
4257 
4258  // [handler_table]: Fixed array containing offsets of exception handlers.
4259  DECL_ACCESSORS(handler_table, FixedArray)
4260 
4261  // [deoptimization_data]: Array containing data for deopt.
4262  DECL_ACCESSORS(deoptimization_data, FixedArray)
4263 
4264  // [type_feedback_info]: Struct containing type feedback information.
4265  // Will contain either a TypeFeedbackInfo object, or undefined.
4266  DECL_ACCESSORS(type_feedback_info, Object)
4267 
4268  // [gc_metadata]: Field used to hold GC related metadata. The contents of this
4269  // field does not have to be traced during garbage collection since
4270  // it is only used by the garbage collector itself.
4271  DECL_ACCESSORS(gc_metadata, Object)
4272 
4273  // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4274  // at the moment when this object was created.
4275  inline void set_ic_age(int count);
4276  inline int ic_age();
4277 
4278  // Unchecked accessors to be used during GC.
4279  inline ByteArray* unchecked_relocation_info();
4280  inline FixedArray* unchecked_deoptimization_data();
4281 
4282  inline int relocation_size();
4283 
4284  // [flags]: Various code flags.
4285  inline Flags flags();
4286  inline void set_flags(Flags flags);
4287 
4288  // [flags]: Access to specific code flags.
4289  inline Kind kind();
4290  inline InlineCacheState ic_state(); // Only valid for IC stubs.
4291  inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
4292  inline StubType type(); // Only valid for monomorphic IC stubs.
4293  inline int arguments_count(); // Only valid for call IC stubs.
4294 
4295  // Testers for IC stub kinds.
4296  inline bool is_inline_cache_stub();
4297  inline bool is_load_stub() { return kind() == LOAD_IC; }
4298  inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
4299  inline bool is_store_stub() { return kind() == STORE_IC; }
4300  inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
4301  inline bool is_call_stub() { return kind() == CALL_IC; }
4302  inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; }
4303  inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; }
4304  inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; }
4305  inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
4306  inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; }
4307 
4308  // [major_key]: For kind STUB or BINARY_OP_IC, the major key.
4309  inline int major_key();
4310  inline void set_major_key(int value);
4311 
4312  // For stubs, tells whether they should always exist, so that they can be
4313  // called from other stubs.
4314  inline bool is_pregenerated();
4315  inline void set_is_pregenerated(bool value);
4316 
4317  // [optimizable]: For FUNCTION kind, tells if it is optimizable.
4318  inline bool optimizable();
4319  inline void set_optimizable(bool value);
4320 
4321  // [has_deoptimization_support]: For FUNCTION kind, tells if it has
4322  // deoptimization support.
4323  inline bool has_deoptimization_support();
4324  inline void set_has_deoptimization_support(bool value);
4325 
4326  // [has_debug_break_slots]: For FUNCTION kind, tells if it has
4327  // been compiled with debug break slots.
4328  inline bool has_debug_break_slots();
4329  inline void set_has_debug_break_slots(bool value);
4330 
4331  // [compiled_with_optimizing]: For FUNCTION kind, tells if it has
4332  // been compiled with IsOptimizing set to true.
4333  inline bool is_compiled_optimizable();
4334  inline void set_compiled_optimizable(bool value);
4335 
4336  // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
4337  // how long the function has been marked for OSR and therefore which
4338  // level of loop nesting we are willing to do on-stack replacement
4339  // for.
4340  inline void set_allow_osr_at_loop_nesting_level(int level);
4341  inline int allow_osr_at_loop_nesting_level();
4342 
4343  // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
4344  // the code object was seen on the stack with no IC patching going on.
4345  inline int profiler_ticks();
4346  inline void set_profiler_ticks(int ticks);
4347 
4348  // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
4349  // reserved in the code prologue.
4350  inline unsigned stack_slots();
4351  inline void set_stack_slots(unsigned slots);
4352 
4353  // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in
4354  // the instruction stream where the safepoint table starts.
4355  inline unsigned safepoint_table_offset();
4356  inline void set_safepoint_table_offset(unsigned offset);
4357 
4358  // [stack_check_table_start]: For kind FUNCTION, the offset in the
4359  // instruction stream where the stack check table starts.
4360  inline unsigned stack_check_table_offset();
4361  inline void set_stack_check_table_offset(unsigned offset);
4362 
4363  // [check type]: For kind CALL_IC, tells how to check if the
4364  // receiver is valid for the given call.
4365  inline CheckType check_type();
4366  inline void set_check_type(CheckType value);
4367 
4368  // [type-recording unary op type]: For kind UNARY_OP_IC.
4369  inline byte unary_op_type();
4370  inline void set_unary_op_type(byte value);
4371 
4372  // [type-recording binary op type]: For kind BINARY_OP_IC.
4373  inline byte binary_op_type();
4374  inline void set_binary_op_type(byte value);
4375  inline byte binary_op_result_type();
4376  inline void set_binary_op_result_type(byte value);
4377 
4378  // [compare state]: For kind COMPARE_IC, tells what state the stub is in.
4379  inline byte compare_state();
4380  inline void set_compare_state(byte value);
4381 
4382  // [compare_operation]: For kind COMPARE_IC tells what compare operation the
4383  // stub was generated for.
4384  inline byte compare_operation();
4385  inline void set_compare_operation(byte value);
4386 
4387  // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
4388  inline byte to_boolean_state();
4389  inline void set_to_boolean_state(byte value);
4390 
4391  // [has_function_cache]: For kind STUB tells whether there is a function
4392  // cache is passed to the stub.
4393  inline bool has_function_cache();
4394  inline void set_has_function_cache(bool flag);
4395 
4396  bool allowed_in_shared_map_code_cache();
4397 
4398  // Get the safepoint entry for the given pc.
4399  SafepointEntry GetSafepointEntry(Address pc);
4400 
4401  // Mark this code object as not having a stack check table. Assumes kind
4402  // is FUNCTION.
4403  void SetNoStackCheckTable();
4404 
4405  // Find the first map in an IC stub.
4406  Map* FindFirstMap();
4407 
4408  class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {};
4410  public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT
4411 
4412  static const int kExtraICStateGrowModeShift = 1;
4413 
4414  static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) {
4415  return ExtraICStateStrictMode::decode(extra_ic_state);
4416  }
4417 
4419  ExtraICState extra_ic_state) {
4420  return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state);
4421  }
4422 
4424  KeyedAccessGrowMode grow_mode,
4425  StrictModeFlag strict_mode) {
4426  return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) |
4427  ExtraICStateStrictMode::encode(strict_mode);
4428  }
4429 
4430  // Flags operations.
4431  static inline Flags ComputeFlags(
4432  Kind kind,
4433  InlineCacheState ic_state = UNINITIALIZED,
4434  ExtraICState extra_ic_state = kNoExtraICState,
4435  StubType type = NORMAL,
4436  int argc = -1,
4437  InlineCacheHolderFlag holder = OWN_MAP);
4438 
4439  static inline Flags ComputeMonomorphicFlags(
4440  Kind kind,
4441  StubType type,
4442  ExtraICState extra_ic_state = kNoExtraICState,
4443  InlineCacheHolderFlag holder = OWN_MAP,
4444  int argc = -1);
4445 
4446  static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
4447  static inline StubType ExtractTypeFromFlags(Flags flags);
4448  static inline Kind ExtractKindFromFlags(Flags flags);
4449  static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
4450  static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
4451  static inline int ExtractArgumentsCountFromFlags(Flags flags);
4452 
4453  static inline Flags RemoveTypeFromFlags(Flags flags);
4454 
4455  // Convert a target address into a code object.
4456  static inline Code* GetCodeFromTargetAddress(Address address);
4457 
4458  // Convert an entry address into an object.
4459  static inline Object* GetObjectFromEntryAddress(Address location_of_address);
4460 
4461  // Returns the address of the first instruction.
4462  inline byte* instruction_start();
4463 
4464  // Returns the address right after the last instruction.
4465  inline byte* instruction_end();
4466 
4467  // Returns the size of the instructions, padding, and relocation information.
4468  inline int body_size();
4469 
4470  // Returns the address of the first relocation info (read backwards!).
4471  inline byte* relocation_start();
4472 
4473  // Code entry point.
4474  inline byte* entry();
4475 
4476  // Returns true if pc is inside this object's instructions.
4477  inline bool contains(byte* pc);
4478 
4479  // Relocate the code by delta bytes. Called to signal that this code
4480  // object has been moved by delta bytes.
4481  void Relocate(intptr_t delta);
4482 
4483  // Migrate code described by desc.
4484  void CopyFrom(const CodeDesc& desc);
4485 
4486  // Returns the object size for a given body (used for allocation).
4487  static int SizeFor(int body_size) {
4488  ASSERT_SIZE_TAG_ALIGNED(body_size);
4489  return RoundUp(kHeaderSize + body_size, kCodeAlignment);
4490  }
4491 
4492  // Calculate the size of the code object to report for log events. This takes
4493  // the layout of the code object into account.
4495  // Check that the assumptions about the layout of the code object holds.
4496  ASSERT_EQ(static_cast<int>(instruction_start() - address()),
4498  return instruction_size() + Code::kHeaderSize;
4499  }
4500 
4501  // Locating source position.
4502  int SourcePosition(Address pc);
4503  int SourceStatementPosition(Address pc);
4504 
4505  // Casting.
4506  static inline Code* cast(Object* obj);
4507 
4508  // Dispatched behavior.
4509  int CodeSize() { return SizeFor(body_size()); }
4510  inline void CodeIterateBody(ObjectVisitor* v);
4511 
4512  template<typename StaticVisitor>
4513  inline void CodeIterateBody(Heap* heap);
4514 #ifdef OBJECT_PRINT
4515  inline void CodePrint() {
4516  CodePrint(stdout);
4517  }
4518  void CodePrint(FILE* out);
4519 #endif
4520  DECLARE_VERIFIER(Code)
4521 
4522  void ClearInlineCaches();
4523  void ClearTypeFeedbackCells(Heap* heap);
4524 
4525  // Max loop nesting marker used to postpose OSR. We don't take loop
4526  // nesting that is deeper than 5 levels into account.
4527  static const int kMaxLoopNestingMarker = 6;
4528 
4529  // Layout description.
4530  static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
4531  static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
4532  static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
4533  static const int kDeoptimizationDataOffset =
4534  kHandlerTableOffset + kPointerSize;
4535  static const int kTypeFeedbackInfoOffset =
4536  kDeoptimizationDataOffset + kPointerSize;
4537  static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize;
4538  static const int kICAgeOffset =
4539  kGCMetadataOffset + kPointerSize;
4540  static const int kFlagsOffset = kICAgeOffset + kIntSize;
4541  static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize;
4542  static const int kKindSpecificFlags2Offset =
4543  kKindSpecificFlags1Offset + kIntSize;
4544 
4545  static const int kHeaderPaddingStart = kKindSpecificFlags2Offset + kIntSize;
4546 
4547  // Add padding to align the instruction start following right after
4548  // the Code object header.
4549  static const int kHeaderSize =
4550  (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
4551 
4552  // Byte offsets within kKindSpecificFlags1Offset.
4553  static const int kOptimizableOffset = kKindSpecificFlags1Offset;
4554  static const int kCheckTypeOffset = kKindSpecificFlags1Offset;
4555 
4556  static const int kFullCodeFlags = kOptimizableOffset + 1;
4558  public BitField<bool, 0, 1> {}; // NOLINT
4559  class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
4560  class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {};
4561 
4562  static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1;
4563  static const int kProfilerTicksOffset = kAllowOSRAtLoopNestingLevelOffset + 1;
4564 
4565  // Flags layout. BitField<type, shift, size>.
4566  class ICStateField: public BitField<InlineCacheState, 0, 3> {};
4567  class TypeField: public BitField<StubType, 3, 3> {};
4568  class CacheHolderField: public BitField<InlineCacheHolderFlag, 6, 1> {};
4569  class KindField: public BitField<Kind, 7, 4> {};
4570  class ExtraICStateField: public BitField<ExtraICState, 11, 2> {};
4571  class IsPregeneratedField: public BitField<bool, 13, 1> {};
4572 
4573  // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION)
4574  static const int kStackSlotsFirstBit = 0;
4575  static const int kStackSlotsBitCount = 24;
4576  static const int kUnaryOpTypeFirstBit =
4577  kStackSlotsFirstBit + kStackSlotsBitCount;
4578  static const int kUnaryOpTypeBitCount = 3;
4579  static const int kBinaryOpTypeFirstBit =
4580  kStackSlotsFirstBit + kStackSlotsBitCount;
4581  static const int kBinaryOpTypeBitCount = 3;
4582  static const int kBinaryOpResultTypeFirstBit =
4583  kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount;
4584  static const int kBinaryOpResultTypeBitCount = 3;
4585  static const int kCompareStateFirstBit =
4586  kStackSlotsFirstBit + kStackSlotsBitCount;
4587  static const int kCompareStateBitCount = 3;
4588  static const int kCompareOperationFirstBit =
4589  kCompareStateFirstBit + kCompareStateBitCount;
4590  static const int kCompareOperationBitCount = 4;
4591  static const int kToBooleanStateFirstBit =
4592  kStackSlotsFirstBit + kStackSlotsBitCount;
4593  static const int kToBooleanStateBitCount = 8;
4594  static const int kHasFunctionCacheFirstBit =
4595  kStackSlotsFirstBit + kStackSlotsBitCount;
4596  static const int kHasFunctionCacheBitCount = 1;
4597 
4598  STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32);
4599  STATIC_ASSERT(kUnaryOpTypeFirstBit + kUnaryOpTypeBitCount <= 32);
4600  STATIC_ASSERT(kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount <= 32);
4601  STATIC_ASSERT(kBinaryOpResultTypeFirstBit +
4602  kBinaryOpResultTypeBitCount <= 32);
4603  STATIC_ASSERT(kCompareStateFirstBit + kCompareStateBitCount <= 32);
4604  STATIC_ASSERT(kCompareOperationFirstBit + kCompareOperationBitCount <= 32);
4605  STATIC_ASSERT(kToBooleanStateFirstBit + kToBooleanStateBitCount <= 32);
4606  STATIC_ASSERT(kHasFunctionCacheFirstBit + kHasFunctionCacheBitCount <= 32);
4607 
4608  class StackSlotsField: public BitField<int,
4609  kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT
4610  class UnaryOpTypeField: public BitField<int,
4611  kUnaryOpTypeFirstBit, kUnaryOpTypeBitCount> {}; // NOLINT
4612  class BinaryOpTypeField: public BitField<int,
4613  kBinaryOpTypeFirstBit, kBinaryOpTypeBitCount> {}; // NOLINT
4615  kBinaryOpResultTypeFirstBit, kBinaryOpResultTypeBitCount> {}; // NOLINT
4616  class CompareStateField: public BitField<int,
4617  kCompareStateFirstBit, kCompareStateBitCount> {}; // NOLINT
4618  class CompareOperationField: public BitField<int,
4619  kCompareOperationFirstBit, kCompareOperationBitCount> {}; // NOLINT
4620  class ToBooleanStateField: public BitField<int,
4621  kToBooleanStateFirstBit, kToBooleanStateBitCount> {}; // NOLINT
4622  class HasFunctionCacheField: public BitField<bool,
4623  kHasFunctionCacheFirstBit, kHasFunctionCacheBitCount> {}; // NOLINT
4624 
4625  // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
4626  static const int kStubMajorKeyFirstBit = 0;
4627  static const int kSafepointTableOffsetFirstBit =
4628  kStubMajorKeyFirstBit + kStubMajorKeyBits;
4629  static const int kSafepointTableOffsetBitCount = 26;
4630 
4631  STATIC_ASSERT(kStubMajorKeyFirstBit + kStubMajorKeyBits <= 32);
4632  STATIC_ASSERT(kSafepointTableOffsetFirstBit +
4633  kSafepointTableOffsetBitCount <= 32);
4634 
4636  kSafepointTableOffsetFirstBit,
4637  kSafepointTableOffsetBitCount> {}; // NOLINT
4638  class StubMajorKeyField: public BitField<int,
4639  kStubMajorKeyFirstBit, kStubMajorKeyBits> {}; // NOLINT
4640 
4641  // KindSpecificFlags2 layout (FUNCTION)
4642  class StackCheckTableOffsetField: public BitField<int, 0, 31> {};
4643 
4644  // Signed field cannot be encoded using the BitField class.
4645  static const int kArgumentsCountShift = 14;
4646  static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1);
4647 
4648  // This constant should be encodable in an ARM instruction.
4649  static const int kFlagsNotUsedInLookup =
4650  TypeField::kMask | CacheHolderField::kMask;
4651 
4652  private:
4654 };
4655 
4656 
4657 // All heap objects have a Map that describes their structure.
4658 // A Map contains information about:
4659 // - Size information about the object
4660 // - How to iterate over an object (for garbage collection)
4661 class Map: public HeapObject {
4662  public:
4663  // Instance size.
4664  // Size in bytes or kVariableSizeSentinel if instances do not have
4665  // a fixed size.
4666  inline int instance_size();
4667  inline void set_instance_size(int value);
4668 
4669  // Count of properties allocated in the object.
4670  inline int inobject_properties();
4671  inline void set_inobject_properties(int value);
4672 
4673  // Count of property fields pre-allocated in the object when first allocated.
4674  inline int pre_allocated_property_fields();
4675  inline void set_pre_allocated_property_fields(int value);
4676 
4677  // Instance type.
4678  inline InstanceType instance_type();
4679  inline void set_instance_type(InstanceType value);
4680 
4681  // Tells how many unused property fields are available in the
4682  // instance (only used for JSObject in fast mode).
4683  inline int unused_property_fields();
4684  inline void set_unused_property_fields(int value);
4685 
4686  // Bit field.
4687  inline byte bit_field();
4688  inline void set_bit_field(byte value);
4689 
4690  // Bit field 2.
4691  inline byte bit_field2();
4692  inline void set_bit_field2(byte value);
4693 
4694  // Bit field 3.
4695  inline int bit_field3();
4696  inline void set_bit_field3(int value);
4697 
4698  class EnumLengthBits: public BitField<int, 0, 11> {};
4699  class NumberOfOwnDescriptorsBits: public BitField<int, 11, 11> {};
4700  class IsShared: public BitField<bool, 22, 1> {};
4701  class FunctionWithPrototype: public BitField<bool, 23, 1> {};
4702  class DictionaryMap: public BitField<bool, 24, 1> {};
4703  class OwnsDescriptors: public BitField<bool, 25, 1> {};
4704 
4705  // Tells whether the object in the prototype property will be used
4706  // for instances created from this function. If the prototype
4707  // property is set to a value that is not a JSObject, the prototype
4708  // property will not be used to create instances of the function.
4709  // See ECMA-262, 13.2.2.
4710  inline void set_non_instance_prototype(bool value);
4711  inline bool has_non_instance_prototype();
4712 
4713  // Tells whether function has special prototype property. If not, prototype
4714  // property will not be created when accessed (will return undefined),
4715  // and construction from this function will not be allowed.
4716  inline void set_function_with_prototype(bool value);
4717  inline bool function_with_prototype();
4718 
4719  // Tells whether the instance with this map should be ignored by the
4720  // __proto__ accessor.
4721  inline void set_is_hidden_prototype() {
4722  set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
4723  }
4724 
4725  inline bool is_hidden_prototype() {
4726  return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
4727  }
4728 
4729  // Records and queries whether the instance has a named interceptor.
4731  set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
4732  }
4733 
4734  inline bool has_named_interceptor() {
4735  return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
4736  }
4737 
4738  // Records and queries whether the instance has an indexed interceptor.
4740  set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
4741  }
4742 
4743  inline bool has_indexed_interceptor() {
4744  return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
4745  }
4746 
4747  // Tells whether the instance is undetectable.
4748  // An undetectable object is a special class of JSObject: 'typeof' operator
4749  // returns undefined, ToBoolean returns false. Otherwise it behaves like
4750  // a normal JS object. It is useful for implementing undetectable
4751  // document.all in Firefox & Safari.
4752  // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
4753  inline void set_is_undetectable() {
4754  set_bit_field(bit_field() | (1 << kIsUndetectable));
4755  }
4756 
4757  inline bool is_undetectable() {
4758  return ((1 << kIsUndetectable) & bit_field()) != 0;
4759  }
4760 
4761  // Tells whether the instance has a call-as-function handler.
4763  set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
4764  }
4765 
4767  return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
4768  }
4769 
4770  inline void set_is_extensible(bool value);
4771  inline bool is_extensible();
4772 
4773  inline void set_elements_kind(ElementsKind elements_kind) {
4774  ASSERT(elements_kind < kElementsKindCount);
4775  ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount));
4776  set_bit_field2((bit_field2() & ~kElementsKindMask) |
4777  (elements_kind << kElementsKindShift));
4778  ASSERT(this->elements_kind() == elements_kind);
4779  }
4780 
4782  return static_cast<ElementsKind>(
4783  (bit_field2() & kElementsKindMask) >> kElementsKindShift);
4784  }
4785 
4786  // Tells whether the instance has fast elements that are only Smis.
4787  inline bool has_fast_smi_elements() {
4788  return IsFastSmiElementsKind(elements_kind());
4789  }
4790 
4791  // Tells whether the instance has fast elements.
4793  return IsFastObjectElementsKind(elements_kind());
4794  }
4795 
4797  return IsFastSmiOrObjectElementsKind(elements_kind());
4798  }
4799 
4801  return IsFastDoubleElementsKind(elements_kind());
4802  }
4803 
4805  return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4806  }
4807 
4809  return IsExternalArrayElementsKind(elements_kind());
4810  }
4811 
4812  inline bool has_dictionary_elements() {
4813  return IsDictionaryElementsKind(elements_kind());
4814  }
4815 
4816  inline bool has_slow_elements_kind() {
4817  return elements_kind() == DICTIONARY_ELEMENTS
4818  || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4819  }
4820 
4821  static bool IsValidElementsTransition(ElementsKind from_kind,
4822  ElementsKind to_kind);
4823 
4824  inline bool HasTransitionArray();
4825  inline bool HasElementsTransition();
4826  inline Map* elements_transition_map();
4827  MUST_USE_RESULT inline MaybeObject* set_elements_transition_map(
4828  Map* transitioned_map);
4829  inline void SetTransition(int transition_index, Map* target);
4830  inline Map* GetTransition(int transition_index);
4831  MUST_USE_RESULT inline MaybeObject* AddTransition(String* key,
4832  Map* target,
4833  SimpleTransitionFlag flag);
4834  DECL_ACCESSORS(transitions, TransitionArray)
4835  inline void ClearTransitions(Heap* heap,
4837 
4838  // Tells whether the map is attached to SharedFunctionInfo
4839  // (for inobject slack tracking).
4840  inline void set_attached_to_shared_function_info(bool value);
4841 
4842  inline bool attached_to_shared_function_info();
4843 
4844  // Tells whether the map is shared between objects that may have different
4845  // behavior. If true, the map should never be modified, instead a clone
4846  // should be created and modified.
4847  inline void set_is_shared(bool value);
4848  inline bool is_shared();
4849 
4850  // Tells whether the map is used for JSObjects in dictionary mode (ie
4851  // normalized objects, ie objects for which HasFastProperties returns false).
4852  // A map can never be used for both dictionary mode and fast mode JSObjects.
4853  // False by default and for HeapObjects that are not JSObjects.
4854  inline void set_dictionary_map(bool value);
4855  inline bool is_dictionary_map();
4856 
4857  // Tells whether the instance needs security checks when accessing its
4858  // properties.
4859  inline void set_is_access_check_needed(bool access_check_needed);
4860  inline bool is_access_check_needed();
4861 
4862  // [prototype]: implicit prototype object.
4863  DECL_ACCESSORS(prototype, Object)
4864 
4865  // [constructor]: points back to the function responsible for this map.
4866  DECL_ACCESSORS(constructor, Object)
4867 
4868  inline JSFunction* unchecked_constructor();
4869 
4870  // [instance descriptors]: describes the object.
4871  DECL_ACCESSORS(instance_descriptors, DescriptorArray)
4872  inline void InitializeDescriptors(DescriptorArray* descriptors);
4873 
4874  // [stub cache]: contains stubs compiled for this map.
4875  DECL_ACCESSORS(code_cache, Object)
4876 
4877  // [back pointer]: points back to the parent map from which a transition
4878  // leads to this map. The field overlaps with prototype transitions and the
4879  // back pointer will be moved into the prototype transitions array if
4880  // required.
4881  inline Object* GetBackPointer();
4882  inline void SetBackPointer(Object* value,
4883  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4884  inline void init_back_pointer(Object* undefined);
4885 
4886  // [prototype transitions]: cache of prototype transitions.
4887  // Prototype transition is a transition that happens
4888  // when we change object's prototype to a new one.
4889  // Cache format:
4890  // 0: finger - index of the first free cell in the cache
4891  // 1: back pointer that overlaps with prototype transitions field.
4892  // 2 + 2 * i: prototype
4893  // 3 + 2 * i: target map
4894  inline FixedArray* GetPrototypeTransitions();
4895  MUST_USE_RESULT inline MaybeObject* SetPrototypeTransitions(
4896  FixedArray* prototype_transitions);
4897  inline bool HasPrototypeTransitions();
4898 
4899  inline HeapObject* UncheckedPrototypeTransitions();
4900  inline TransitionArray* unchecked_transition_array();
4901 
4902  static const int kProtoTransitionHeaderSize = 1;
4903  static const int kProtoTransitionNumberOfEntriesOffset = 0;
4904  static const int kProtoTransitionElementsPerEntry = 2;
4905  static const int kProtoTransitionPrototypeOffset = 0;
4906  static const int kProtoTransitionMapOffset = 1;
4907 
4908  inline int NumberOfProtoTransitions() {
4909  FixedArray* cache = GetPrototypeTransitions();
4910  if (cache->length() == 0) return 0;
4911  return
4912  Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value();
4913  }
4914 
4915  inline void SetNumberOfProtoTransitions(int value) {
4916  FixedArray* cache = GetPrototypeTransitions();
4917  ASSERT(cache->length() != 0);
4918  cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset,
4919  Smi::FromInt(value));
4920  }
4921 
4922  // Lookup in the map's instance descriptors and fill out the result
4923  // with the given holder if the name is found. The holder may be
4924  // NULL when this function is used from the compiler.
4925  inline void LookupDescriptor(JSObject* holder,
4926  String* name,
4927  LookupResult* result);
4928 
4929  inline void LookupTransition(JSObject* holder,
4930  String* name,
4931  LookupResult* result);
4932 
4933  // The size of transition arrays are limited so they do not end up in large
4934  // object space. Otherwise ClearNonLiveTransitions would leak memory while
4935  // applying in-place right trimming.
4936  inline bool CanHaveMoreTransitions();
4937 
4938  int LastAdded() {
4939  int number_of_own_descriptors = NumberOfOwnDescriptors();
4940  ASSERT(number_of_own_descriptors > 0);
4941  return number_of_own_descriptors - 1;
4942  }
4943 
4945  return NumberOfOwnDescriptorsBits::decode(bit_field3());
4946  }
4947 
4948  void SetNumberOfOwnDescriptors(int number) {
4949  ASSERT(number <= instance_descriptors()->number_of_descriptors());
4950  set_bit_field3(NumberOfOwnDescriptorsBits::update(bit_field3(), number));
4951  }
4952 
4953  inline JSGlobalPropertyCell* RetrieveDescriptorsPointer();
4954 
4955  int EnumLength() {
4956  return EnumLengthBits::decode(bit_field3());
4957  }
4958 
4959  void SetEnumLength(int length) {
4960  if (length != kInvalidEnumCache) {
4961  ASSERT(length >= 0);
4962  ASSERT(length == 0 || instance_descriptors()->HasEnumCache());
4963  ASSERT(length <= NumberOfOwnDescriptors());
4964  }
4965  set_bit_field3(EnumLengthBits::update(bit_field3(), length));
4966  }
4967 
4968 
4969  inline bool owns_descriptors();
4970  inline void set_owns_descriptors(bool is_shared);
4971 
4972  MUST_USE_RESULT MaybeObject* RawCopy(int instance_size);
4973  MUST_USE_RESULT MaybeObject* CopyWithPreallocatedFieldDescriptors();
4974  MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
4975  MUST_USE_RESULT MaybeObject* CopyReplaceDescriptors(
4976  DescriptorArray* descriptors,
4977  String* name,
4978  TransitionFlag flag,
4979  int descriptor_index);
4980  MUST_USE_RESULT MaybeObject* ShareDescriptor(DescriptorArray* descriptors,
4981  Descriptor* descriptor);
4982  MUST_USE_RESULT MaybeObject* CopyAddDescriptor(Descriptor* descriptor,
4983  TransitionFlag flag);
4984  MUST_USE_RESULT MaybeObject* CopyInsertDescriptor(Descriptor* descriptor,
4985  TransitionFlag flag);
4986  MUST_USE_RESULT MaybeObject* CopyReplaceDescriptor(
4987  DescriptorArray* descriptors,
4988  Descriptor* descriptor,
4989  int index,
4990  TransitionFlag flag);
4991  MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind,
4992  TransitionFlag flag);
4993 
4994  MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
4995  NormalizedMapSharingMode sharing);
4996 
4997  inline void AppendDescriptor(Descriptor* desc,
4999 
5000  // Returns a copy of the map, with all transitions dropped from the
5001  // instance descriptors.
5002  MUST_USE_RESULT MaybeObject* Copy();
5003 
5004  // Returns the property index for name (only valid for FAST MODE).
5005  int PropertyIndexFor(String* name);
5006 
5007  // Returns the next free property index (only valid for FAST MODE).
5008  int NextFreePropertyIndex();
5009 
5010  // Returns the number of properties described in instance_descriptors
5011  // filtering out properties with the specified attributes.
5012  int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
5013  PropertyAttributes filter = NONE);
5014 
5015  // Casting.
5016  static inline Map* cast(Object* obj);
5017 
5018  // Locate an accessor in the instance descriptor.
5019  AccessorDescriptor* FindAccessor(String* name);
5020 
5021  // Code cache operations.
5022 
5023  // Clears the code cache.
5024  inline void ClearCodeCache(Heap* heap);
5025 
5026  // Update code cache.
5027  static void UpdateCodeCache(Handle<Map> map,
5028  Handle<String> name,
5029  Handle<Code> code);
5030  MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
5031 
5032  // Extend the descriptor array of the map with the list of descriptors.
5033  // In case of duplicates, the latest descriptor is used.
5034  static void AppendCallbackDescriptors(Handle<Map> map,
5035  Handle<Object> descriptors);
5036 
5037  static void EnsureDescriptorSlack(Handle<Map> map, int slack);
5038 
5039  // Returns the found code or undefined if absent.
5040  Object* FindInCodeCache(String* name, Code::Flags flags);
5041 
5042  // Returns the non-negative index of the code object if it is in the
5043  // cache and -1 otherwise.
5044  int IndexInCodeCache(Object* name, Code* code);
5045 
5046  // Removes a code object from the code cache at the given index.
5047  void RemoveFromCodeCache(String* name, Code* code, int index);
5048 
5049  // Set all map transitions from this map to dead maps to null. Also clear
5050  // back pointers in transition targets so that we do not process this map
5051  // again while following back pointers.
5052  void ClearNonLiveTransitions(Heap* heap);
5053 
5054  // Computes a hash value for this map, to be used in HashTables and such.
5055  int Hash();
5056 
5057  // Compares this map to another to see if they describe equivalent objects.
5058  // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
5059  // it had exactly zero inobject properties.
5060  // The "shared" flags of both this map and |other| are ignored.
5061  bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
5062 
5063  // Returns the map that this map transitions to if its elements_kind
5064  // is changed to |elements_kind|, or NULL if no such map is cached yet.
5065  // |safe_to_add_transitions| is set to false if adding transitions is not
5066  // allowed.
5067  Map* LookupElementsTransitionMap(ElementsKind elements_kind);
5068 
5069  // Returns the transitioned map for this map with the most generic
5070  // elements_kind that's found in |candidates|, or null handle if no match is
5071  // found at all.
5072  Handle<Map> FindTransitionedMap(MapHandleList* candidates);
5073  Map* FindTransitionedMap(MapList* candidates);
5074 
5075  // Zaps the contents of backing data structures. Note that the
5076  // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
5077  // holding weak references when incremental marking is used, because it also
5078  // iterates over objects that are otherwise unreachable.
5079  // In general we only want to call these functions in release mode when
5080  // heap verification is turned on.
5081  void ZapPrototypeTransitions();
5082  void ZapTransitions();
5083 
5084  // Dispatched behavior.
5085 #ifdef OBJECT_PRINT
5086  inline void MapPrint() {
5087  MapPrint(stdout);
5088  }
5089  void MapPrint(FILE* out);
5090 #endif
5091  DECLARE_VERIFIER(Map)
5092 
5093 #ifdef VERIFY_HEAP
5094  void SharedMapVerify();
5095 #endif
5096 
5097  inline int visitor_id();
5098  inline void set_visitor_id(int visitor_id);
5099 
5100  typedef void (*TraverseCallback)(Map* map, void* data);
5101 
5102  void TraverseTransitionTree(TraverseCallback callback, void* data);
5103 
5104  // When you set the prototype of an object using the __proto__ accessor you
5105  // need a new map for the object (the prototype is stored in the map). In
5106  // order not to multiply maps unnecessarily we store these as transitions in
5107  // the original map. That way we can transition to the same map if the same
5108  // prototype is set, rather than creating a new map every time. The
5109  // transitions are in the form of a map where the keys are prototype objects
5110  // and the values are the maps the are transitioned to.
5111  static const int kMaxCachedPrototypeTransitions = 256;
5112 
5113  Map* GetPrototypeTransition(Object* prototype);
5114 
5115  MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype,
5116  Map* map);
5117 
5118  static const int kMaxPreAllocatedPropertyFields = 255;
5119 
5120  // Constant for denoting that the enum cache is not yet initialized.
5121  static const int kInvalidEnumCache = EnumLengthBits::kMax;
5122 
5123  // Layout description.
5124  static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
5125  static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
5126  static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
5127  static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
5128  // Storage for the transition array is overloaded to directly contain a back
5129  // pointer if unused. When the map has transitions, the back pointer is
5130  // transferred to the transition array and accessed through an extra
5131  // indirection.
5132  static const int kTransitionsOrBackPointerOffset =
5133  kConstructorOffset + kPointerSize;
5134  static const int kDescriptorsOffset =
5135  kTransitionsOrBackPointerOffset + kPointerSize;
5136  static const int kCodeCacheOffset =
5137  kDescriptorsOffset + kPointerSize;
5138  static const int kBitField3Offset = kCodeCacheOffset + kPointerSize;
5139  static const int kSize = kBitField3Offset + kPointerSize;
5140 
5141  // Layout of pointer fields. Heap iteration code relies on them
5142  // being continuously allocated.
5143  static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
5144  static const int kPointerFieldsEndOffset = kBitField3Offset + kPointerSize;
5145 
5146  // Byte offsets within kInstanceSizesOffset.
5147  static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
5148  static const int kInObjectPropertiesByte = 1;
5149  static const int kInObjectPropertiesOffset =
5150  kInstanceSizesOffset + kInObjectPropertiesByte;
5151  static const int kPreAllocatedPropertyFieldsByte = 2;
5152  static const int kPreAllocatedPropertyFieldsOffset =
5153  kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
5154  static const int kVisitorIdByte = 3;
5155  static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
5156 
5157  // Byte offsets within kInstanceAttributesOffset attributes.
5158  static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
5159  static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
5160  static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
5161  static const int kBitField2Offset = kInstanceAttributesOffset + 3;
5162 
5163  STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
5164 
5165  // Bit positions for bit field.
5166  static const int kUnused = 0; // To be used for marking recently used maps.
5167  static const int kHasNonInstancePrototype = 1;
5168  static const int kIsHiddenPrototype = 2;
5169  static const int kHasNamedInterceptor = 3;
5170  static const int kHasIndexedInterceptor = 4;
5171  static const int kIsUndetectable = 5;
5172  static const int kHasInstanceCallHandler = 6;
5173  static const int kIsAccessCheckNeeded = 7;
5174 
5175  // Bit positions for bit field 2
5176  static const int kIsExtensible = 0;
5177  static const int kStringWrapperSafeForDefaultValueOf = 1;
5178  static const int kAttachedToSharedFunctionInfo = 2;
5179  // No bits can be used after kElementsKindFirstBit, they are all reserved for
5180  // storing ElementKind.
5181  static const int kElementsKindShift = 3;
5182  static const int kElementsKindBitCount = 5;
5183 
5184  // Derived values from bit field 2
5185  static const int kElementsKindMask = (-1 << kElementsKindShift) &
5186  ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
5187  static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
5188  (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
5189  static const int8_t kMaximumBitField2FastSmiElementValue =
5190  static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
5192  static const int8_t kMaximumBitField2FastHoleyElementValue =
5193  static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
5195  static const int8_t kMaximumBitField2FastHoleySmiElementValue =
5196  static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
5198 
5199  typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
5200  kPointerFieldsEndOffset,
5202 
5203  private:
5205 };
5206 
5207 
5208 // An abstract superclass, a marker class really, for simple structure classes.
5209 // It doesn't carry much functionality but allows struct classes to be
5210 // identified in the type system.
5211 class Struct: public HeapObject {
5212  public:
5213  inline void InitializeBody(int object_size);
5214  static inline Struct* cast(Object* that);
5215 };
5216 
5217 
5218 // Script describes a script which has been added to the VM.
5219 class Script: public Struct {
5220  public:
5221  // Script types.
5222  enum Type {
5223  TYPE_NATIVE = 0,
5224  TYPE_EXTENSION = 1,
5225  TYPE_NORMAL = 2
5226  };
5227 
5228  // Script compilation types.
5230  COMPILATION_TYPE_HOST = 0,
5231  COMPILATION_TYPE_EVAL = 1
5232  };
5233 
5234  // Script compilation state.
5236  COMPILATION_STATE_INITIAL = 0,
5237  COMPILATION_STATE_COMPILED = 1
5238  };
5239 
5240  // [source]: the script source.
5241  DECL_ACCESSORS(source, Object)
5242 
5243  // [name]: the script name.
5244  DECL_ACCESSORS(name, Object)
5245 
5246  // [id]: the script id.
5247  DECL_ACCESSORS(id, Object)
5248 
5249  // [line_offset]: script line offset in resource from where it was extracted.
5250  DECL_ACCESSORS(line_offset, Smi)
5251 
5252  // [column_offset]: script column offset in resource from where it was
5253  // extracted.
5254  DECL_ACCESSORS(column_offset, Smi)
5255 
5256  // [data]: additional data associated with this script.
5257  DECL_ACCESSORS(data, Object)
5258 
5259  // [context_data]: context data for the context this script was compiled in.
5260  DECL_ACCESSORS(context_data, Object)
5261 
5262  // [wrapper]: the wrapper cache.
5263  DECL_ACCESSORS(wrapper, Foreign)
5264 
5265  // [type]: the script type.
5266  DECL_ACCESSORS(type, Smi)
5267 
5268  // [compilation]: how the the script was compiled.
5269  DECL_ACCESSORS(compilation_type, Smi)
5270 
5271  // [is_compiled]: determines whether the script has already been compiled.
5272  DECL_ACCESSORS(compilation_state, Smi)
5273 
5274  // [line_ends]: FixedArray of line ends positions.
5275  DECL_ACCESSORS(line_ends, Object)
5276 
5277  // [eval_from_shared]: for eval scripts the shared funcion info for the
5278  // function from which eval was called.
5279  DECL_ACCESSORS(eval_from_shared, Object)
5280 
5281  // [eval_from_instructions_offset]: the instruction offset in the code for the
5282  // function from which eval was called where eval was called.
5284 
5285  static inline Script* cast(Object* obj);
5286 
5287  // If script source is an external string, check that the underlying
5288  // resource is accessible. Otherwise, always return true.
5289  inline bool HasValidSource();
5290 
5291 #ifdef OBJECT_PRINT
5292  inline void ScriptPrint() {
5293  ScriptPrint(stdout);
5294  }
5295  void ScriptPrint(FILE* out);
5296 #endif
5298 
5299  static const int kSourceOffset = HeapObject::kHeaderSize;
5300  static const int kNameOffset = kSourceOffset + kPointerSize;
5301  static const int kLineOffsetOffset = kNameOffset + kPointerSize;
5302  static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
5303  static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
5304  static const int kContextOffset = kDataOffset + kPointerSize;
5305  static const int kWrapperOffset = kContextOffset + kPointerSize;
5306  static const int kTypeOffset = kWrapperOffset + kPointerSize;
5307  static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
5308  static const int kCompilationStateOffset =
5309  kCompilationTypeOffset + kPointerSize;
5310  static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize;
5311  static const int kIdOffset = kLineEndsOffset + kPointerSize;
5312  static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
5313  static const int kEvalFrominstructionsOffsetOffset =
5314  kEvalFromSharedOffset + kPointerSize;
5315  static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
5316 
5317  private:
5318  DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
5319 };
5320 
5321 
5322 // List of builtin functions we want to identify to improve code
5323 // generation.
5324 //
5325 // Each entry has a name of a global object property holding an object
5326 // optionally followed by ".prototype", a name of a builtin function
5327 // on the object (the one the id is set for), and a label.
5328 //
5329 // Installation of ids for the selected builtin functions is handled
5330 // by the bootstrapper.
5331 //
5332 // NOTE: Order is important: math functions should be at the end of
5333 // the list and MathFloor should be the first math function.
5334 #define FUNCTIONS_WITH_ID_LIST(V) \
5335  V(Array.prototype, push, ArrayPush) \
5336  V(Array.prototype, pop, ArrayPop) \
5337  V(Function.prototype, apply, FunctionApply) \
5338  V(String.prototype, charCodeAt, StringCharCodeAt) \
5339  V(String.prototype, charAt, StringCharAt) \
5340  V(String, fromCharCode, StringFromCharCode) \
5341  V(Math, floor, MathFloor) \
5342  V(Math, round, MathRound) \
5343  V(Math, ceil, MathCeil) \
5344  V(Math, abs, MathAbs) \
5345  V(Math, log, MathLog) \
5346  V(Math, sin, MathSin) \
5347  V(Math, cos, MathCos) \
5348  V(Math, tan, MathTan) \
5349  V(Math, asin, MathASin) \
5350  V(Math, acos, MathACos) \
5351  V(Math, atan, MathATan) \
5352  V(Math, exp, MathExp) \
5353  V(Math, sqrt, MathSqrt) \
5354  V(Math, pow, MathPow) \
5355  V(Math, random, MathRandom) \
5356  V(Math, max, MathMax) \
5357  V(Math, min, MathMin)
5358 
5359 
5361 #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
5362  k##name,
5364 #undef DECLARE_FUNCTION_ID
5365  // Fake id for a special case of Math.pow. Note, it continues the
5366  // list of math functions.
5369 };
5370 
5371 
5372 // SharedFunctionInfo describes the JSFunction information that can be
5373 // shared by multiple instances of the function.
5374 class SharedFunctionInfo: public HeapObject {
5375  public:
5376  // [name]: Function name.
5377  DECL_ACCESSORS(name, Object)
5378 
5379  // [code]: Function code.
5381 
5382  // [optimized_code_map]: Map from native context to optimized code
5383  // and a shared literals array or Smi 0 if none.
5384  DECL_ACCESSORS(optimized_code_map, Object)
5385 
5386  // Returns index i of the entry with the specified context. At position
5387  // i - 1 is the context, position i the code, and i + 1 the literals array.
5388  // Returns -1 when no matching entry is found.
5389  int SearchOptimizedCodeMap(Context* native_context);
5390 
5391  // Installs optimized code from the code map on the given closure. The
5392  // index has to be consistent with a search result as defined above.
5393  void InstallFromOptimizedCodeMap(JSFunction* function, int index);
5394 
5395  // Clear optimized code map.
5396  void ClearOptimizedCodeMap();
5397 
5398  // Add a new entry to the optimized code map.
5399  static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
5400  Handle<Context> native_context,
5402  Handle<FixedArray> literals);
5403  static const int kEntryLength = 3;
5404 
5405  // [scope_info]: Scope info.
5406  DECL_ACCESSORS(scope_info, ScopeInfo)
5407 
5408  // [construct stub]: Code stub for constructing instances of this function.
5409  DECL_ACCESSORS(construct_stub, Code)
5410 
5411  inline Code* unchecked_code();
5412 
5413  // Returns if this function has been compiled to native code yet.
5414  inline bool is_compiled();
5415 
5416  // [length]: The function length - usually the number of declared parameters.
5417  // Use up to 2^30 parameters.
5418  inline int length();
5419  inline void set_length(int value);
5420 
5421  // [formal parameter count]: The declared number of parameters.
5422  inline int formal_parameter_count();
5423  inline void set_formal_parameter_count(int value);
5424 
5425  // Set the formal parameter count so the function code will be
5426  // called without using argument adaptor frames.
5427  inline void DontAdaptArguments();
5428 
5429  // [expected_nof_properties]: Expected number of properties for the function.
5430  inline int expected_nof_properties();
5431  inline void set_expected_nof_properties(int value);
5432 
5433  // Inobject slack tracking is the way to reclaim unused inobject space.
5434  //
5435  // The instance size is initially determined by adding some slack to
5436  // expected_nof_properties (to allow for a few extra properties added
5437  // after the constructor). There is no guarantee that the extra space
5438  // will not be wasted.
5439  //
5440  // Here is the algorithm to reclaim the unused inobject space:
5441  // - Detect the first constructor call for this SharedFunctionInfo.
5442  // When it happens enter the "in progress" state: remember the
5443  // constructor's initial_map and install a special construct stub that
5444  // counts constructor calls.
5445  // - While the tracking is in progress create objects filled with
5446  // one_pointer_filler_map instead of undefined_value. This way they can be
5447  // resized quickly and safely.
5448  // - Once enough (kGenerousAllocationCount) objects have been created
5449  // compute the 'slack' (traverse the map transition tree starting from the
5450  // initial_map and find the lowest value of unused_property_fields).
5451  // - Traverse the transition tree again and decrease the instance size
5452  // of every map. Existing objects will resize automatically (they are
5453  // filled with one_pointer_filler_map). All further allocations will
5454  // use the adjusted instance size.
5455  // - Decrease expected_nof_properties so that an allocations made from
5456  // another context will use the adjusted instance size too.
5457  // - Exit "in progress" state by clearing the reference to the initial_map
5458  // and setting the regular construct stub (generic or inline).
5459  //
5460  // The above is the main event sequence. Some special cases are possible
5461  // while the tracking is in progress:
5462  //
5463  // - GC occurs.
5464  // Check if the initial_map is referenced by any live objects (except this
5465  // SharedFunctionInfo). If it is, continue tracking as usual.
5466  // If it is not, clear the reference and reset the tracking state. The
5467  // tracking will be initiated again on the next constructor call.
5468  //
5469  // - The constructor is called from another context.
5470  // Immediately complete the tracking, perform all the necessary changes
5471  // to maps. This is necessary because there is no efficient way to track
5472  // multiple initial_maps.
5473  // Proceed to create an object in the current context (with the adjusted
5474  // size).
5475  //
5476  // - A different constructor function sharing the same SharedFunctionInfo is
5477  // called in the same context. This could be another closure in the same
5478  // context, or the first function could have been disposed.
5479  // This is handled the same way as the previous case.
5480  //
5481  // Important: inobject slack tracking is not attempted during the snapshot
5482  // creation.
5483 
5484  static const int kGenerousAllocationCount = 8;
5485 
5486  // [construction_count]: Counter for constructor calls made during
5487  // the tracking phase.
5488  inline int construction_count();
5489  inline void set_construction_count(int value);
5490 
5491  // [initial_map]: initial map of the first function called as a constructor.
5492  // Saved for the duration of the tracking phase.
5493  // This is a weak link (GC resets it to undefined_value if no other live
5494  // object reference this map).
5495  DECL_ACCESSORS(initial_map, Object)
5496 
5497  // True if the initial_map is not undefined and the countdown stub is
5498  // installed.
5499  inline bool IsInobjectSlackTrackingInProgress();
5500 
5501  // Starts the tracking.
5502  // Stores the initial map and installs the countdown stub.
5503  // IsInobjectSlackTrackingInProgress is normally true after this call,
5504  // except when tracking have not been started (e.g. the map has no unused
5505  // properties or the snapshot is being built).
5506  void StartInobjectSlackTracking(Map* map);
5507 
5508  // Completes the tracking.
5509  // IsInobjectSlackTrackingInProgress is false after this call.
5510  void CompleteInobjectSlackTracking();
5511 
5512  // Invoked before pointers in SharedFunctionInfo are being marked.
5513  // Also clears the optimized code map.
5514  inline void BeforeVisitingPointers();
5515 
5516  // Clears the initial_map before the GC marking phase to ensure the reference
5517  // is weak. IsInobjectSlackTrackingInProgress is false after this call.
5518  void DetachInitialMap();
5519 
5520  // Restores the link to the initial map after the GC marking phase.
5521  // IsInobjectSlackTrackingInProgress is true after this call.
5522  void AttachInitialMap(Map* map);
5523 
5524  // False if there are definitely no live objects created from this function.
5525  // True if live objects _may_ exist (existence not guaranteed).
5526  // May go back from true to false after GC.
5527  DECL_BOOLEAN_ACCESSORS(live_objects_may_exist)
5528 
5529  // [instance class name]: class name for instances.
5531 
5532  // [function data]: This field holds some additional data for function.
5533  // Currently it either has FunctionTemplateInfo to make benefit the API
5534  // or Smi identifying a builtin function.
5535  // In the long run we don't want all functions to have this field but
5536  // we can fix that when we have a better model for storing hidden data
5537  // on objects.
5538  DECL_ACCESSORS(function_data, Object)
5539 
5540  inline bool IsApiFunction();
5541  inline FunctionTemplateInfo* get_api_func_data();
5542  inline bool HasBuiltinFunctionId();
5543  inline BuiltinFunctionId builtin_function_id();
5544 
5545  // [script info]: Script from which the function originates.
5546  DECL_ACCESSORS(script, Object)
5547 
5548  // [num_literals]: Number of literals used by this function.
5549  inline int num_literals();
5550  inline void set_num_literals(int value);
5551 
5552  // [start_position_and_type]: Field used to store both the source code
5553  // position, whether or not the function is a function expression,
5554  // and whether or not the function is a toplevel function. The two
5555  // least significants bit indicates whether the function is an
5556  // expression and the rest contains the source code position.
5557  inline int start_position_and_type();
5558  inline void set_start_position_and_type(int value);
5559 
5560  // [debug info]: Debug information.
5561  DECL_ACCESSORS(debug_info, Object)
5562 
5563  // [inferred name]: Name inferred from variable or property
5564  // assignment of this function. Used to facilitate debugging and
5565  // profiling of JavaScript code written in OO style, where almost
5566  // all functions are anonymous but are assigned to object
5567  // properties.
5568  DECL_ACCESSORS(inferred_name, String)
5569 
5570  // The function's name if it is non-empty, otherwise the inferred name.
5571  String* DebugName();
5572 
5573  // Position of the 'function' token in the script source.
5574  inline int function_token_position();
5575  inline void set_function_token_position(int function_token_position);
5576 
5577  // Position of this function in the script source.
5578  inline int start_position();
5579  inline void set_start_position(int start_position);
5580 
5581  // End position of this function in the script source.
5582  inline int end_position();
5583  inline void set_end_position(int end_position);
5584 
5585  // Is this function a function expression in the source code.
5586  DECL_BOOLEAN_ACCESSORS(is_expression)
5587 
5588  // Is this function a top-level function (scripts, evals).
5590 
5591  // Bit field containing various information collected by the compiler to
5592  // drive optimization.
5593  inline int compiler_hints();
5594  inline void set_compiler_hints(int value);
5595 
5596  inline int ast_node_count();
5597  inline void set_ast_node_count(int count);
5598 
5599  // A counter used to determine when to stress the deoptimizer with a
5600  // deopt.
5601  inline int stress_deopt_counter();
5602  inline void set_stress_deopt_counter(int counter);
5603 
5604  inline int profiler_ticks();
5605 
5606  // Inline cache age is used to infer whether the function survived a context
5607  // disposal or not. In the former case we reset the opt_count.
5608  inline int ic_age();
5609  inline void set_ic_age(int age);
5610 
5611  // Add information on assignments of the form this.x = ...;
5612  void SetThisPropertyAssignmentsInfo(
5613  bool has_only_simple_this_property_assignments,
5614  FixedArray* this_property_assignments);
5615 
5616  // Clear information on assignments of the form this.x = ...;
5617  void ClearThisPropertyAssignmentsInfo();
5618 
5619  // Indicate that this function only consists of assignments of the form
5620  // this.x = y; where y is either a constant or refers to an argument.
5621  inline bool has_only_simple_this_property_assignments();
5622 
5623  // Indicates if this function can be lazy compiled.
5624  // This is used to determine if we can safely flush code from a function
5625  // when doing GC if we expect that the function will no longer be used.
5627 
5628  // Indicates if this function can be lazy compiled without a context.
5629  // This is used to determine if we can force compilation without reaching
5630  // the function through program execution but through other means (e.g. heap
5631  // iteration by the debugger).
5632  DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context)
5633 
5634  // Indicates how many full GCs this function has survived with assigned
5635  // code object. Used to determine when it is relatively safe to flush
5636  // this code object and replace it with lazy compilation stub.
5637  // Age is reset when GC notices that the code object is referenced
5638  // from the stack or compilation cache.
5639  inline int code_age();
5640  inline void set_code_age(int age);
5641 
5642  // Indicates whether optimizations have been disabled for this
5643  // shared function info. If a function is repeatedly optimized or if
5644  // we cannot optimize the function we disable optimization to avoid
5645  // spending time attempting to optimize it again.
5646  DECL_BOOLEAN_ACCESSORS(optimization_disabled)
5647 
5648  // Indicates the language mode of the function's code as defined by the
5649  // current harmony drafts for the next ES language standard. Possible
5650  // values are:
5651  // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5.
5652  // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5.
5653  // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5.
5654  inline LanguageMode language_mode();
5655  inline void set_language_mode(LanguageMode language_mode);
5656 
5657  // Indicates whether the language mode of this function is CLASSIC_MODE.
5658  inline bool is_classic_mode();
5659 
5660  // Indicates whether the language mode of this function is EXTENDED_MODE.
5661  inline bool is_extended_mode();
5662 
5663  // False if the function definitely does not allocate an arguments object.
5665 
5666  // True if the function has any duplicated parameter names.
5667  DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
5668 
5669  // Indicates whether the function is a native function.
5670  // These needs special treatment in .call and .apply since
5671  // null passed as the receiver should not be translated to the
5672  // global object.
5673  DECL_BOOLEAN_ACCESSORS(native)
5674 
5675  // Indicates that the function was created by the Function function.
5676  // Though it's anonymous, toString should treat it as if it had the name
5677  // "anonymous". We don't set the name itself so that the system does not
5678  // see a binding for it.
5680 
5681  // Indicates whether the function is a bound function created using
5682  // the bind function.
5683  DECL_BOOLEAN_ACCESSORS(bound)
5684 
5685  // Indicates that the function is anonymous (the name field can be set
5686  // through the API, which does not change this flag).
5687  DECL_BOOLEAN_ACCESSORS(is_anonymous)
5688 
5689  // Is this a function or top-level/eval code.
5690  DECL_BOOLEAN_ACCESSORS(is_function)
5691 
5692  // Indicates that the function cannot be optimized.
5693  DECL_BOOLEAN_ACCESSORS(dont_optimize)
5694 
5695  // Indicates that the function cannot be inlined.
5696  DECL_BOOLEAN_ACCESSORS(dont_inline)
5697 
5698  // Indicates that code for this function cannot be cached.
5699  DECL_BOOLEAN_ACCESSORS(dont_cache)
5700 
5701  // Indicates whether or not the code in the shared function support
5702  // deoptimization.
5703  inline bool has_deoptimization_support();
5704 
5705  // Enable deoptimization support through recompiled code.
5706  void EnableDeoptimizationSupport(Code* recompiled);
5707 
5708  // Disable (further) attempted optimization of all functions sharing this
5709  // shared function info.
5710  void DisableOptimization(const char* reason);
5711 
5712  // Lookup the bailout ID and ASSERT that it exists in the non-optimized
5713  // code, returns whether it asserted (i.e., always true if assertions are
5714  // disabled).
5715  bool VerifyBailoutId(BailoutId id);
5716 
5717  // Check whether a inlined constructor can be generated with the given
5718  // prototype.
5719  bool CanGenerateInlineConstructor(Object* prototype);
5720 
5721  // Prevents further attempts to generate inline constructors.
5722  // To be called if generation failed for any reason.
5723  void ForbidInlineConstructor();
5724 
5725  // For functions which only contains this property assignments this provides
5726  // access to the names for the properties assigned.
5727  DECL_ACCESSORS(this_property_assignments, Object)
5728  inline int this_property_assignments_count();
5729  inline void set_this_property_assignments_count(int value);
5730  String* GetThisPropertyAssignmentName(int index);
5731  bool IsThisPropertyAssignmentArgument(int index);
5732  int GetThisPropertyAssignmentArgument(int index);
5733  Object* GetThisPropertyAssignmentConstant(int index);
5734 
5735  // [source code]: Source code for the function.
5736  bool HasSourceCode();
5737  Handle<Object> GetSourceCode();
5738 
5739  // Number of times the function was optimized.
5740  inline int opt_count();
5741  inline void set_opt_count(int opt_count);
5742 
5743  // Number of times the function was deoptimized.
5744  inline void set_deopt_count(int value);
5745  inline int deopt_count();
5746  inline void increment_deopt_count();
5747 
5748  // Number of time we tried to re-enable optimization after it
5749  // was disabled due to high number of deoptimizations.
5750  inline void set_opt_reenable_tries(int value);
5751  inline int opt_reenable_tries();
5752 
5753  inline void TryReenableOptimization();
5754 
5755  // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
5756  inline void set_counters(int value);
5757  inline int counters();
5758 
5759  // Source size of this function.
5760  int SourceSize();
5761 
5762  // Calculate the instance size.
5763  int CalculateInstanceSize();
5764 
5765  // Calculate the number of in-object properties.
5766  int CalculateInObjectProperties();
5767 
5768  // Dispatched behavior.
5769  // Set max_length to -1 for unlimited length.
5770  void SourceCodePrint(StringStream* accumulator, int max_length);
5771 #ifdef OBJECT_PRINT
5772  inline void SharedFunctionInfoPrint() {
5773  SharedFunctionInfoPrint(stdout);
5774  }
5775  void SharedFunctionInfoPrint(FILE* out);
5776 #endif
5778 
5779  void ResetForNewContext(int new_ic_age);
5780 
5781  // Helper to compile the shared code. Returns true on success, false on
5782  // failure (e.g., stack overflow during compilation). This is only used by
5783  // the debugger, it is not possible to compile without a context otherwise.
5784  static bool CompileLazy(Handle<SharedFunctionInfo> shared,
5785  ClearExceptionFlag flag);
5786 
5787  // Casting.
5788  static inline SharedFunctionInfo* cast(Object* obj);
5789 
5790  // Constants.
5791  static const int kDontAdaptArgumentsSentinel = -1;
5792 
5793  // Layout description.
5794  // Pointer fields.
5795  static const int kNameOffset = HeapObject::kHeaderSize;
5796  static const int kCodeOffset = kNameOffset + kPointerSize;
5797  static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
5798  static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
5799  static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
5800  static const int kInstanceClassNameOffset =
5801  kConstructStubOffset + kPointerSize;
5802  static const int kFunctionDataOffset =
5803  kInstanceClassNameOffset + kPointerSize;
5804  static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
5805  static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
5806  static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
5807  static const int kInitialMapOffset =
5808  kInferredNameOffset + kPointerSize;
5809  static const int kThisPropertyAssignmentsOffset =
5810  kInitialMapOffset + kPointerSize;
5811  // ast_node_count is a Smi field. It could be grouped with another Smi field
5812  // into a PSEUDO_SMI_ACCESSORS pair (on x64), if one becomes available.
5813  static const int kAstNodeCountOffset =
5814  kThisPropertyAssignmentsOffset + kPointerSize;
5815 #if V8_HOST_ARCH_32_BIT
5816  // Smi fields.
5817  static const int kLengthOffset =
5818  kAstNodeCountOffset + kPointerSize;
5819  static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
5820  static const int kExpectedNofPropertiesOffset =
5821  kFormalParameterCountOffset + kPointerSize;
5822  static const int kNumLiteralsOffset =
5823  kExpectedNofPropertiesOffset + kPointerSize;
5824  static const int kStartPositionAndTypeOffset =
5825  kNumLiteralsOffset + kPointerSize;
5826  static const int kEndPositionOffset =
5827  kStartPositionAndTypeOffset + kPointerSize;
5828  static const int kFunctionTokenPositionOffset =
5829  kEndPositionOffset + kPointerSize;
5830  static const int kCompilerHintsOffset =
5831  kFunctionTokenPositionOffset + kPointerSize;
5832  static const int kThisPropertyAssignmentsCountOffset =
5833  kCompilerHintsOffset + kPointerSize;
5834  static const int kOptCountOffset =
5835  kThisPropertyAssignmentsCountOffset + kPointerSize;
5836  static const int kCountersOffset = kOptCountOffset + kPointerSize;
5837  static const int kStressDeoptCounterOffset = kCountersOffset + kPointerSize;
5838 
5839  // Total size.
5840  static const int kSize = kStressDeoptCounterOffset + kPointerSize;
5841 #else
5842  // The only reason to use smi fields instead of int fields
5843  // is to allow iteration without maps decoding during
5844  // garbage collections.
5845  // To avoid wasting space on 64-bit architectures we use
5846  // the following trick: we group integer fields into pairs
5847  // First integer in each pair is shifted left by 1.
5848  // By doing this we guarantee that LSB of each kPointerSize aligned
5849  // word is not set and thus this word cannot be treated as pointer
5850  // to HeapObject during old space traversal.
5851  static const int kLengthOffset =
5852  kAstNodeCountOffset + kPointerSize;
5853  static const int kFormalParameterCountOffset =
5854  kLengthOffset + kIntSize;
5855 
5856  static const int kExpectedNofPropertiesOffset =
5857  kFormalParameterCountOffset + kIntSize;
5858  static const int kNumLiteralsOffset =
5859  kExpectedNofPropertiesOffset + kIntSize;
5860 
5861  static const int kEndPositionOffset =
5862  kNumLiteralsOffset + kIntSize;
5863  static const int kStartPositionAndTypeOffset =
5864  kEndPositionOffset + kIntSize;
5865 
5866  static const int kFunctionTokenPositionOffset =
5867  kStartPositionAndTypeOffset + kIntSize;
5868  static const int kCompilerHintsOffset =
5869  kFunctionTokenPositionOffset + kIntSize;
5870 
5871  static const int kThisPropertyAssignmentsCountOffset =
5872  kCompilerHintsOffset + kIntSize;
5873  static const int kOptCountOffset =
5874  kThisPropertyAssignmentsCountOffset + kIntSize;
5875 
5876  static const int kCountersOffset = kOptCountOffset + kIntSize;
5877  static const int kStressDeoptCounterOffset = kCountersOffset + kIntSize;
5878 
5879  // Total size.
5880  static const int kSize = kStressDeoptCounterOffset + kIntSize;
5881 
5882 #endif
5883 
5884  // The construction counter for inobject slack tracking is stored in the
5885  // most significant byte of compiler_hints which is otherwise unused.
5886  // Its offset depends on the endian-ness of the architecture.
5887 #if __BYTE_ORDER == __LITTLE_ENDIAN
5888  static const int kConstructionCountOffset = kCompilerHintsOffset + 3;
5889 #elif __BYTE_ORDER == __BIG_ENDIAN
5890  static const int kConstructionCountOffset = kCompilerHintsOffset + 0;
5891 #else
5892 #error Unknown byte ordering
5893 #endif
5894 
5895  static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
5896 
5897  typedef FixedBodyDescriptor<kNameOffset,
5898  kThisPropertyAssignmentsOffset + kPointerSize,
5900 
5901  // Bit positions in start_position_and_type.
5902  // The source code start position is in the 30 most significant bits of
5903  // the start_position_and_type field.
5904  static const int kIsExpressionBit = 0;
5905  static const int kIsTopLevelBit = 1;
5906  static const int kStartPositionShift = 2;
5907  static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
5908 
5909  // Bit positions in compiler_hints.
5910  static const int kCodeAgeSize = 3;
5911  static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1;
5912 
5919  kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize,
5932  kCompilerHintsCount // Pseudo entry
5933  };
5934 
5935  class DeoptCountBits: public BitField<int, 0, 4> {};
5936  class OptReenableTriesBits: public BitField<int, 4, 18> {};
5937  class ICAgeBits: public BitField<int, 22, 8> {};
5938 
5939  private:
5940 #if V8_HOST_ARCH_32_BIT
5941  // On 32 bit platforms, compiler hints is a smi.
5942  static const int kCompilerHintsSmiTagSize = kSmiTagSize;
5943  static const int kCompilerHintsSize = kPointerSize;
5944 #else
5945  // On 64 bit platforms, compiler hints is not a smi, see comment above.
5946  static const int kCompilerHintsSmiTagSize = 0;
5947  static const int kCompilerHintsSize = kIntSize;
5948 #endif
5949 
5951  SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
5952 
5953  public:
5954  // Constants for optimizing codegen for strict mode function and
5955  // native tests.
5956  // Allows to use byte-width instructions.
5957  static const int kStrictModeBitWithinByte =
5958  (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5959 
5960  static const int kExtendedModeBitWithinByte =
5961  (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5962 
5963  static const int kNativeBitWithinByte =
5964  (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
5965 
5966 #if __BYTE_ORDER == __LITTLE_ENDIAN
5967  static const int kStrictModeByteOffset = kCompilerHintsOffset +
5968  (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
5969  static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5970  (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
5971  static const int kNativeByteOffset = kCompilerHintsOffset +
5972  (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
5973 #elif __BYTE_ORDER == __BIG_ENDIAN
5974  static const int kStrictModeByteOffset = kCompilerHintsOffset +
5975  (kCompilerHintsSize - 1) -
5976  ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
5977  static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5978  (kCompilerHintsSize - 1) -
5979  ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
5980  static const int kNativeByteOffset = kCompilerHintsOffset +
5981  (kCompilerHintsSize - 1) -
5982  ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
5983 #else
5984 #error Unknown byte ordering
5985 #endif
5986 
5987  private:
5989 };
5990 
5991 
5992 // Representation for module instance objects.
5993 class JSModule: public JSObject {
5994  public:
5995  // [context]: the context holding the module's locals, or undefined if none.
5996  DECL_ACCESSORS(context, Object)
5997 
5998  // [scope_info]: Scope info.
5999  DECL_ACCESSORS(scope_info, ScopeInfo)
6000 
6001  // Casting.
6002  static inline JSModule* cast(Object* obj);
6003 
6004  // Dispatched behavior.
6005 #ifdef OBJECT_PRINT
6006  inline void JSModulePrint() {
6007  JSModulePrint(stdout);
6008  }
6009  void JSModulePrint(FILE* out);
6010 #endif
6012 
6013  // Layout description.
6014  static const int kContextOffset = JSObject::kHeaderSize;
6015  static const int kScopeInfoOffset = kContextOffset + kPointerSize;
6016  static const int kSize = kScopeInfoOffset + kPointerSize;
6017 
6018  private:
6019  DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule);
6020 };
6021 
6022 
6023 // JSFunction describes JavaScript functions.
6024 class JSFunction: public JSObject {
6025  public:
6026  // [prototype_or_initial_map]:
6027  DECL_ACCESSORS(prototype_or_initial_map, Object)
6028 
6029  // [shared]: The information about the function that
6030  // can be shared by instances.
6032 
6033  inline SharedFunctionInfo* unchecked_shared();
6034 
6035  // [context]: The context for this function.
6036  inline Context* context();
6037  inline Object* unchecked_context();
6038  inline void set_context(Object* context);
6039 
6040  // [code]: The generated code object for this function. Executed
6041  // when the function is invoked, e.g. foo() or new foo(). See
6042  // [[Call]] and [[Construct]] description in ECMA-262, section
6043  // 8.6.2, page 27.
6044  inline Code* code();
6045  inline void set_code(Code* code);
6046  inline void ReplaceCode(Code* code);
6047 
6048  inline Code* unchecked_code();
6049 
6050  // Tells whether this function is builtin.
6051  inline bool IsBuiltin();
6052 
6053  // Tells whether or not the function needs arguments adaption.
6054  inline bool NeedsArgumentsAdaption();
6055 
6056  // Tells whether or not this function has been optimized.
6057  inline bool IsOptimized();
6058 
6059  // Tells whether or not this function can be optimized.
6060  inline bool IsOptimizable();
6061 
6062  // Mark this function for lazy recompilation. The function will be
6063  // recompiled the next time it is executed.
6064  void MarkForLazyRecompilation();
6065  void MarkForParallelRecompilation();
6066 
6067  // Helpers to compile this function. Returns true on success, false on
6068  // failure (e.g., stack overflow during compilation).
6069  static bool EnsureCompiled(Handle<JSFunction> function,
6070  ClearExceptionFlag flag);
6071  static bool CompileLazy(Handle<JSFunction> function,
6072  ClearExceptionFlag flag);
6073  static bool CompileOptimized(Handle<JSFunction> function,
6074  BailoutId osr_ast_id,
6075  ClearExceptionFlag flag);
6076 
6077  // Tells whether or not the function is already marked for lazy
6078  // recompilation.
6079  inline bool IsMarkedForLazyRecompilation();
6080  inline bool IsMarkedForParallelRecompilation();
6081 
6082  // Tells whether or not the function is on the parallel
6083  // recompilation queue.
6084  inline bool IsInRecompileQueue();
6085 
6086  // Check whether or not this function is inlineable.
6087  bool IsInlineable();
6088 
6089  // [literals_or_bindings]: Fixed array holding either
6090  // the materialized literals or the bindings of a bound function.
6091  //
6092  // If the function contains object, regexp or array literals, the
6093  // literals array prefix contains the object, regexp, and array
6094  // function to be used when creating these literals. This is
6095  // necessary so that we do not dynamically lookup the object, regexp
6096  // or array functions. Performing a dynamic lookup, we might end up
6097  // using the functions from a new context that we should not have
6098  // access to.
6099  //
6100  // On bound functions, the array is a (copy-on-write) fixed-array containing
6101  // the function that was bound, bound this-value and any bound
6102  // arguments. Bound functions never contain literals.
6103  DECL_ACCESSORS(literals_or_bindings, FixedArray)
6104 
6105  inline FixedArray* literals();
6106  inline void set_literals(FixedArray* literals);
6107 
6108  inline FixedArray* function_bindings();
6109  inline void set_function_bindings(FixedArray* bindings);
6110 
6111  // The initial map for an object created by this constructor.
6112  inline Map* initial_map();
6113  inline void set_initial_map(Map* value);
6114  MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions(
6115  Map* value);
6116  inline bool has_initial_map();
6117 
6118  // Get and set the prototype property on a JSFunction. If the
6119  // function has an initial map the prototype is set on the initial
6120  // map. Otherwise, the prototype is put in the initial map field
6121  // until an initial map is needed.
6122  inline bool has_prototype();
6123  inline bool has_instance_prototype();
6124  inline Object* prototype();
6125  inline Object* instance_prototype();
6126  MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value);
6127  MUST_USE_RESULT MaybeObject* SetPrototype(Object* value);
6128 
6129  // After prototype is removed, it will not be created when accessed, and
6130  // [[Construct]] from this function will not be allowed.
6131  void RemovePrototype();
6132  inline bool should_have_prototype();
6133 
6134  // Accessor for this function's initial map's [[class]]
6135  // property. This is primarily used by ECMA native functions. This
6136  // method sets the class_name field of this function's initial map
6137  // to a given value. It creates an initial map if this function does
6138  // not have one. Note that this method does not copy the initial map
6139  // if it has one already, but simply replaces it with the new value.
6140  // Instances created afterwards will have a map whose [[class]] is
6141  // set to 'value', but there is no guarantees on instances created
6142  // before.
6143  void SetInstanceClassName(String* name);
6144 
6145  // Returns if this function has been compiled to native code yet.
6146  inline bool is_compiled();
6147 
6148  // [next_function_link]: Field for linking functions. This list is treated as
6149  // a weak list by the GC.
6150  DECL_ACCESSORS(next_function_link, Object)
6151 
6152  // Prints the name of the function using PrintF.
6153  inline void PrintName() {
6154  PrintName(stdout);
6155  }
6156  void PrintName(FILE* out);
6157 
6158  // Casting.
6159  static inline JSFunction* cast(Object* obj);
6160 
6161  // Iterates the objects, including code objects indirectly referenced
6162  // through pointers to the first instruction in the code object.
6163  void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
6164 
6165  // Dispatched behavior.
6166 #ifdef OBJECT_PRINT
6167  inline void JSFunctionPrint() {
6168  JSFunctionPrint(stdout);
6169  }
6170  void JSFunctionPrint(FILE* out);
6171 #endif
6172  DECLARE_VERIFIER(JSFunction)
6173 
6174  // Returns the number of allocated literals.
6175  inline int NumberOfLiterals();
6176 
6177  // Retrieve the native context from a function's literal array.
6178  static Context* NativeContextFromLiterals(FixedArray* literals);
6179 
6180  // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
6181  // kSize) is weak and has special handling during garbage collection.
6182  static const int kCodeEntryOffset = JSObject::kHeaderSize;
6183  static const int kPrototypeOrInitialMapOffset =
6184  kCodeEntryOffset + kPointerSize;
6185  static const int kSharedFunctionInfoOffset =
6186  kPrototypeOrInitialMapOffset + kPointerSize;
6187  static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
6188  static const int kLiteralsOffset = kContextOffset + kPointerSize;
6189  static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
6190  static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
6191  static const int kSize = kNextFunctionLinkOffset + kPointerSize;
6192 
6193  // Layout of the literals array.
6194  static const int kLiteralsPrefixSize = 1;
6195  static const int kLiteralNativeContextIndex = 0;
6196 
6197  // Layout of the bound-function binding array.
6198  static const int kBoundFunctionIndex = 0;
6199  static const int kBoundThisIndex = 1;
6200  static const int kBoundArgumentsStartIndex = 2;
6201 
6202  private:
6203  DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
6204 };
6205 
6206 
6207 // JSGlobalProxy's prototype must be a JSGlobalObject or null,
6208 // and the prototype is hidden. JSGlobalProxy always delegates
6209 // property accesses to its prototype if the prototype is not null.
6210 //
6211 // A JSGlobalProxy can be reinitialized which will preserve its identity.
6212 //
6213 // Accessing a JSGlobalProxy requires security check.
6214 
6215 class JSGlobalProxy : public JSObject {
6216  public:
6217  // [native_context]: the owner native context of this global proxy object.
6218  // It is null value if this object is not used by any context.
6219  DECL_ACCESSORS(native_context, Object)
6220 
6221  // Casting.
6222  static inline JSGlobalProxy* cast(Object* obj);
6223 
6224  // Dispatched behavior.
6225 #ifdef OBJECT_PRINT
6226  inline void JSGlobalProxyPrint() {
6227  JSGlobalProxyPrint(stdout);
6228  }
6229  void JSGlobalProxyPrint(FILE* out);
6230 #endif
6232 
6233  // Layout description.
6234  static const int kNativeContextOffset = JSObject::kHeaderSize;
6235  static const int kSize = kNativeContextOffset + kPointerSize;
6236 
6237  private:
6238  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
6239 };
6240 
6241 
6242 // Forward declaration.
6243 class JSBuiltinsObject;
6244 
6245 // Common super class for JavaScript global objects and the special
6246 // builtins global objects.
6247 class GlobalObject: public JSObject {
6248  public:
6249  // [builtins]: the object holding the runtime routines written in JS.
6250  DECL_ACCESSORS(builtins, JSBuiltinsObject)
6251 
6252  // [native context]: the natives corresponding to this global object.
6253  DECL_ACCESSORS(native_context, Context)
6254 
6255  // [global context]: the most recent (i.e. innermost) global context.
6256  DECL_ACCESSORS(global_context, Context)
6257 
6258  // [global receiver]: the global receiver object of the context
6259  DECL_ACCESSORS(global_receiver, JSObject)
6260 
6261  // Retrieve the property cell used to store a property.
6262  JSGlobalPropertyCell* GetPropertyCell(LookupResult* result);
6263 
6264  // This is like GetProperty, but is used when you know the lookup won't fail
6265  // by throwing an exception. This is for the debug and builtins global
6266  // objects, where it is known which properties can be expected to be present
6267  // on the object.
6269  Object* answer = GetProperty(key)->ToObjectUnchecked();
6270  return answer;
6271  }
6272 
6273  // Ensure that the global object has a cell for the given property name.
6274  static Handle<JSGlobalPropertyCell> EnsurePropertyCell(
6275  Handle<GlobalObject> global,
6276  Handle<String> name);
6277  // TODO(kmillikin): This function can be eliminated once the stub cache is
6278  // full handlified (and the static helper can be written directly).
6279  MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name);
6280 
6281  // Casting.
6282  static inline GlobalObject* cast(Object* obj);
6283 
6284  // Layout description.
6285  static const int kBuiltinsOffset = JSObject::kHeaderSize;
6286  static const int kNativeContextOffset = kBuiltinsOffset + kPointerSize;
6287  static const int kGlobalContextOffset = kNativeContextOffset + kPointerSize;
6288  static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
6289  static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
6290 
6291  private:
6293 };
6294 
6295 
6296 // JavaScript global object.
6298  public:
6299  // Casting.
6300  static inline JSGlobalObject* cast(Object* obj);
6301 
6302  // Dispatched behavior.
6303 #ifdef OBJECT_PRINT
6304  inline void JSGlobalObjectPrint() {
6305  JSGlobalObjectPrint(stdout);
6306  }
6307  void JSGlobalObjectPrint(FILE* out);
6308 #endif
6310 
6311  // Layout description.
6312  static const int kSize = GlobalObject::kHeaderSize;
6313 
6314  private:
6315  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
6316 };
6317 
6318 
6319 // Builtins global object which holds the runtime routines written in
6320 // JavaScript.
6322  public:
6323  // Accessors for the runtime routines written in JavaScript.
6324  inline Object* javascript_builtin(Builtins::JavaScript id);
6325  inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
6326 
6327  // Accessors for code of the runtime routines written in JavaScript.
6328  inline Code* javascript_builtin_code(Builtins::JavaScript id);
6329  inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
6330 
6331  // Casting.
6332  static inline JSBuiltinsObject* cast(Object* obj);
6333 
6334  // Dispatched behavior.
6335 #ifdef OBJECT_PRINT
6336  inline void JSBuiltinsObjectPrint() {
6337  JSBuiltinsObjectPrint(stdout);
6338  }
6339  void JSBuiltinsObjectPrint(FILE* out);
6340 #endif
6342 
6343  // Layout description. The size of the builtins object includes
6344  // room for two pointers per runtime routine written in javascript
6345  // (function and code object).
6346  static const int kJSBuiltinsCount = Builtins::id_count;
6347  static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
6348  static const int kJSBuiltinsCodeOffset =
6349  GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
6350  static const int kSize =
6351  kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
6352 
6353  static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
6354  return kJSBuiltinsOffset + id * kPointerSize;
6355  }
6356 
6358  return kJSBuiltinsCodeOffset + id * kPointerSize;
6359  }
6360 
6361  private:
6363 };
6364 
6365 
6366 // Representation for JS Wrapper objects, String, Number, Boolean, etc.
6367 class JSValue: public JSObject {
6368  public:
6369  // [value]: the object being wrapped.
6370  DECL_ACCESSORS(value, Object)
6371 
6372  // Casting.
6373  static inline JSValue* cast(Object* obj);
6374 
6375  // Dispatched behavior.
6376 #ifdef OBJECT_PRINT
6377  inline void JSValuePrint() {
6378  JSValuePrint(stdout);
6379  }
6380  void JSValuePrint(FILE* out);
6381 #endif
6383 
6384  // Layout description.
6385  static const int kValueOffset = JSObject::kHeaderSize;
6386  static const int kSize = kValueOffset + kPointerSize;
6387 
6388  private:
6389  DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
6390 };
6391 
6392 
6393 class DateCache;
6394 
6395 // Representation for JS date objects.
6396 class JSDate: public JSObject {
6397  public:
6398  // If one component is NaN, all of them are, indicating a NaN time value.
6399  // [value]: the time value.
6400  DECL_ACCESSORS(value, Object)
6401  // [year]: caches year. Either undefined, smi, or NaN.
6402  DECL_ACCESSORS(year, Object)
6403  // [month]: caches month. Either undefined, smi, or NaN.
6404  DECL_ACCESSORS(month, Object)
6405  // [day]: caches day. Either undefined, smi, or NaN.
6406  DECL_ACCESSORS(day, Object)
6407  // [weekday]: caches day of week. Either undefined, smi, or NaN.
6408  DECL_ACCESSORS(weekday, Object)
6409  // [hour]: caches hours. Either undefined, smi, or NaN.
6410  DECL_ACCESSORS(hour, Object)
6411  // [min]: caches minutes. Either undefined, smi, or NaN.
6412  DECL_ACCESSORS(min, Object)
6413  // [sec]: caches seconds. Either undefined, smi, or NaN.
6414  DECL_ACCESSORS(sec, Object)
6415  // [cache stamp]: sample of the date cache stamp at the
6416  // moment when local fields were cached.
6417  DECL_ACCESSORS(cache_stamp, Object)
6418 
6419  // Casting.
6420  static inline JSDate* cast(Object* obj);
6421 
6422  // Returns the date field with the specified index.
6423  // See FieldIndex for the list of date fields.
6424  static Object* GetField(Object* date, Smi* index);
6425 
6426  void SetValue(Object* value, bool is_value_nan);
6427 
6428 
6429  // Dispatched behavior.
6430 #ifdef OBJECT_PRINT
6431  inline void JSDatePrint() {
6432  JSDatePrint(stdout);
6433  }
6434  void JSDatePrint(FILE* out);
6435 #endif
6437 
6438  // The order is important. It must be kept in sync with date macros
6439  // in macros.py.
6440  enum FieldIndex {
6450  kMillisecond = kFirstUncachedField,
6454  kYearUTC = kFirstUTCField,
6464  kTimezoneOffset
6465  };
6466 
6467  // Layout description.
6468  static const int kValueOffset = JSObject::kHeaderSize;
6469  static const int kYearOffset = kValueOffset + kPointerSize;
6470  static const int kMonthOffset = kYearOffset + kPointerSize;
6471  static const int kDayOffset = kMonthOffset + kPointerSize;
6472  static const int kWeekdayOffset = kDayOffset + kPointerSize;
6473  static const int kHourOffset = kWeekdayOffset + kPointerSize;
6474  static const int kMinOffset = kHourOffset + kPointerSize;
6475  static const int kSecOffset = kMinOffset + kPointerSize;
6476  static const int kCacheStampOffset = kSecOffset + kPointerSize;
6477  static const int kSize = kCacheStampOffset + kPointerSize;
6478 
6479  private:
6480  inline Object* DoGetField(FieldIndex index);
6481 
6482  Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
6483 
6484  // Computes and caches the cacheable fields of the date.
6485  inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache);
6486 
6487 
6489 };
6490 
6491 
6492 // Representation of message objects used for error reporting through
6493 // the API. The messages are formatted in JavaScript so this object is
6494 // a real JavaScript object. The information used for formatting the
6495 // error messages are not directly accessible from JavaScript to
6496 // prevent leaking information to user code called during error
6497 // formatting.
6498 class JSMessageObject: public JSObject {
6499  public:
6500  // [type]: the type of error message.
6501  DECL_ACCESSORS(type, String)
6502 
6503  // [arguments]: the arguments for formatting the error message.
6504  DECL_ACCESSORS(arguments, JSArray)
6505 
6506  // [script]: the script from which the error message originated.
6507  DECL_ACCESSORS(script, Object)
6508 
6509  // [stack_trace]: the stack trace for this error message.
6510  DECL_ACCESSORS(stack_trace, Object)
6511 
6512  // [stack_frames]: an array of stack frames for this error object.
6513  DECL_ACCESSORS(stack_frames, Object)
6514 
6515  // [start_position]: the start position in the script for the error message.
6516  inline int start_position();
6517  inline void set_start_position(int value);
6518 
6519  // [end_position]: the end position in the script for the error message.
6520  inline int end_position();
6521  inline void set_end_position(int value);
6522 
6523  // Casting.
6524  static inline JSMessageObject* cast(Object* obj);
6525 
6526  // Dispatched behavior.
6527 #ifdef OBJECT_PRINT
6528  inline void JSMessageObjectPrint() {
6529  JSMessageObjectPrint(stdout);
6530  }
6531  void JSMessageObjectPrint(FILE* out);
6532 #endif
6534 
6535  // Layout description.
6536  static const int kTypeOffset = JSObject::kHeaderSize;
6537  static const int kArgumentsOffset = kTypeOffset + kPointerSize;
6538  static const int kScriptOffset = kArgumentsOffset + kPointerSize;
6539  static const int kStackTraceOffset = kScriptOffset + kPointerSize;
6540  static const int kStackFramesOffset = kStackTraceOffset + kPointerSize;
6541  static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
6542  static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
6543  static const int kSize = kEndPositionOffset + kPointerSize;
6544 
6545  typedef FixedBodyDescriptor<HeapObject::kMapOffset,
6546  kStackFramesOffset + kPointerSize,
6548 };
6549 
6550 
6551 // Regular expressions
6552 // The regular expression holds a single reference to a FixedArray in
6553 // the kDataOffset field.
6554 // The FixedArray contains the following data:
6555 // - tag : type of regexp implementation (not compiled yet, atom or irregexp)
6556 // - reference to the original source string
6557 // - reference to the original flag string
6558 // If it is an atom regexp
6559 // - a reference to a literal string to search for
6560 // If it is an irregexp regexp:
6561 // - a reference to code for ASCII inputs (bytecode or compiled), or a smi
6562 // used for tracking the last usage (used for code flushing).
6563 // - a reference to code for UC16 inputs (bytecode or compiled), or a smi
6564 // used for tracking the last usage (used for code flushing)..
6565 // - max number of registers used by irregexp implementations.
6566 // - number of capture registers (output values) of the regexp.
6567 class JSRegExp: public JSObject {
6568  public:
6569  // Meaning of Type:
6570  // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
6571  // ATOM: A simple string to match against using an indexOf operation.
6572  // IRREGEXP: Compiled with Irregexp.
6573  // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
6574  enum Type { NOT_COMPILED, ATOM, IRREGEXP };
6575  enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
6576 
6577  class Flags {
6578  public:
6579  explicit Flags(uint32_t value) : value_(value) { }
6580  bool is_global() { return (value_ & GLOBAL) != 0; }
6581  bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
6582  bool is_multiline() { return (value_ & MULTILINE) != 0; }
6583  uint32_t value() { return value_; }
6584  private:
6585  uint32_t value_;
6586  };
6587 
6588  DECL_ACCESSORS(data, Object)
6589 
6590  inline Type TypeTag();
6591  inline int CaptureCount();
6592  inline Flags GetFlags();
6593  inline String* Pattern();
6594  inline Object* DataAt(int index);
6595  // Set implementation data after the object has been prepared.
6596  inline void SetDataAt(int index, Object* value);
6597 
6598  // Used during GC when flushing code or setting age.
6599  inline Object* DataAtUnchecked(int index);
6600  inline void SetDataAtUnchecked(int index, Object* value, Heap* heap);
6601  inline Type TypeTagUnchecked();
6602 
6603  static int code_index(bool is_ascii) {
6604  if (is_ascii) {
6605  return kIrregexpASCIICodeIndex;
6606  } else {
6607  return kIrregexpUC16CodeIndex;
6608  }
6609  }
6610 
6611  static int saved_code_index(bool is_ascii) {
6612  if (is_ascii) {
6613  return kIrregexpASCIICodeSavedIndex;
6614  } else {
6615  return kIrregexpUC16CodeSavedIndex;
6616  }
6617  }
6618 
6619  static inline JSRegExp* cast(Object* obj);
6620 
6621  // Dispatched behavior.
6623 
6624  static const int kDataOffset = JSObject::kHeaderSize;
6625  static const int kSize = kDataOffset + kPointerSize;
6626 
6627  // Indices in the data array.
6628  static const int kTagIndex = 0;
6629  static const int kSourceIndex = kTagIndex + 1;
6630  static const int kFlagsIndex = kSourceIndex + 1;
6631  static const int kDataIndex = kFlagsIndex + 1;
6632  // The data fields are used in different ways depending on the
6633  // value of the tag.
6634  // Atom regexps (literal strings).
6635  static const int kAtomPatternIndex = kDataIndex;
6636 
6637  static const int kAtomDataSize = kAtomPatternIndex + 1;
6638 
6639  // Irregexp compiled code or bytecode for ASCII. If compilation
6640  // fails, this fields hold an exception object that should be
6641  // thrown if the regexp is used again.
6642  static const int kIrregexpASCIICodeIndex = kDataIndex;
6643  // Irregexp compiled code or bytecode for UC16. If compilation
6644  // fails, this fields hold an exception object that should be
6645  // thrown if the regexp is used again.
6646  static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
6647 
6648  // Saved instance of Irregexp compiled code or bytecode for ASCII that
6649  // is a potential candidate for flushing.
6650  static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2;
6651  // Saved instance of Irregexp compiled code or bytecode for UC16 that is
6652  // a potential candidate for flushing.
6653  static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
6654 
6655  // Maximal number of registers used by either ASCII or UC16.
6656  // Only used to check that there is enough stack space
6657  static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
6658  // Number of captures in the compiled regexp.
6659  static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
6660 
6661  static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
6662 
6663  // Offsets directly into the data fixed array.
6664  static const int kDataTagOffset =
6665  FixedArray::kHeaderSize + kTagIndex * kPointerSize;
6666  static const int kDataAsciiCodeOffset =
6667  FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize;
6668  static const int kDataUC16CodeOffset =
6669  FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
6670  static const int kIrregexpCaptureCountOffset =
6671  FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
6672 
6673  // In-object fields.
6674  static const int kSourceFieldIndex = 0;
6675  static const int kGlobalFieldIndex = 1;
6676  static const int kIgnoreCaseFieldIndex = 2;
6677  static const int kMultilineFieldIndex = 3;
6678  static const int kLastIndexFieldIndex = 4;
6679  static const int kInObjectFieldCount = 5;
6680 
6681  // The uninitialized value for a regexp code object.
6682  static const int kUninitializedValue = -1;
6683 
6684  // The compilation error value for the regexp code object. The real error
6685  // object is in the saved code field.
6686  static const int kCompilationErrorValue = -2;
6687 
6688  // When we store the sweep generation at which we moved the code from the
6689  // code index to the saved code index we mask it of to be in the [0:255]
6690  // range.
6691  static const int kCodeAgeMask = 0xff;
6692 };
6693 
6694 
6696  public:
6697  static inline bool IsMatch(HashTableKey* key, Object* value) {
6698  return key->IsMatch(value);
6699  }
6700 
6701  static inline uint32_t Hash(HashTableKey* key) {
6702  return key->Hash();
6703  }
6704 
6705  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6706  return key->HashForObject(object);
6707  }
6708 
6709  MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
6710  return key->AsObject();
6711  }
6712 
6713  static const int kPrefixSize = 0;
6714  static const int kEntrySize = 2;
6715 };
6716 
6717 
6718 class CompilationCacheTable: public HashTable<CompilationCacheShape,
6719  HashTableKey*> {
6720  public:
6721  // Find cached value for a string key, otherwise return null.
6722  Object* Lookup(String* src, Context* context);
6723  Object* LookupEval(String* src,
6724  Context* context,
6725  LanguageMode language_mode,
6726  int scope_position);
6727  Object* LookupRegExp(String* source, JSRegExp::Flags flags);
6728  MUST_USE_RESULT MaybeObject* Put(String* src,
6729  Context* context,
6730  Object* value);
6731  MUST_USE_RESULT MaybeObject* PutEval(String* src,
6732  Context* context,
6733  SharedFunctionInfo* value,
6734  int scope_position);
6735  MUST_USE_RESULT MaybeObject* PutRegExp(String* src,
6736  JSRegExp::Flags flags,
6737  FixedArray* value);
6738 
6739  // Remove given value from cache.
6740  void Remove(Object* value);
6741 
6742  static inline CompilationCacheTable* cast(Object* obj);
6743 
6744  private:
6746 };
6747 
6748 
6749 class CodeCache: public Struct {
6750  public:
6751  DECL_ACCESSORS(default_cache, FixedArray)
6752  DECL_ACCESSORS(normal_type_cache, Object)
6753 
6754  // Add the code object to the cache.
6755  MUST_USE_RESULT MaybeObject* Update(String* name, Code* code);
6756 
6757  // Lookup code object in the cache. Returns code object if found and undefined
6758  // if not.
6760 
6761  // Get the internal index of a code object in the cache. Returns -1 if the
6762  // code object is not in that cache. This index can be used to later call
6763  // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
6764  // RemoveByIndex.
6765  int GetIndex(Object* name, Code* code);
6766 
6767  // Remove an object from the cache with the provided internal index.
6768  void RemoveByIndex(Object* name, Code* code, int index);
6769 
6770  static inline CodeCache* cast(Object* obj);
6771 
6772 #ifdef OBJECT_PRINT
6773  inline void CodeCachePrint() {
6774  CodeCachePrint(stdout);
6775  }
6776  void CodeCachePrint(FILE* out);
6777 #endif
6779 
6780  static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
6781  static const int kNormalTypeCacheOffset =
6782  kDefaultCacheOffset + kPointerSize;
6783  static const int kSize = kNormalTypeCacheOffset + kPointerSize;
6784 
6785  private:
6786  MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code);
6787  MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code);
6788  Object* LookupDefaultCache(String* name, Code::Flags flags);
6789  Object* LookupNormalTypeCache(String* name, Code::Flags flags);
6790 
6791  // Code cache layout of the default cache. Elements are alternating name and
6792  // code objects for non normal load/store/call IC's.
6793  static const int kCodeCacheEntrySize = 2;
6794  static const int kCodeCacheEntryNameOffset = 0;
6795  static const int kCodeCacheEntryCodeOffset = 1;
6796 
6797  DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
6798 };
6799 
6800 
6802  public:
6803  static inline bool IsMatch(HashTableKey* key, Object* value) {
6804  return key->IsMatch(value);
6805  }
6806 
6807  static inline uint32_t Hash(HashTableKey* key) {
6808  return key->Hash();
6809  }
6810 
6811  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6812  return key->HashForObject(object);
6813  }
6814 
6815  MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
6816  return key->AsObject();
6817  }
6818 
6819  static const int kPrefixSize = 0;
6820  static const int kEntrySize = 2;
6821 };
6822 
6823 
6824 class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
6825  HashTableKey*> {
6826  public:
6828  MUST_USE_RESULT MaybeObject* Put(String* name, Code* code);
6829 
6830  int GetIndex(String* name, Code::Flags flags);
6831  void RemoveByIndex(int index);
6832 
6833  static inline CodeCacheHashTable* cast(Object* obj);
6834 
6835  // Initial size of the fixed array backing the hash table.
6836  static const int kInitialSize = 64;
6837 
6838  private:
6840 };
6841 
6842 
6844  public:
6845  DECL_ACCESSORS(cache, Object)
6846 
6847  static void Update(Handle<PolymorphicCodeCache> cache,
6848  MapHandleList* maps,
6850  Handle<Code> code);
6851 
6852  MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps,
6853  Code::Flags flags,
6854  Code* code);
6855 
6856  // Returns an undefined value if the entry is not found.
6858 
6859  static inline PolymorphicCodeCache* cast(Object* obj);
6860 
6861 #ifdef OBJECT_PRINT
6862  inline void PolymorphicCodeCachePrint() {
6863  PolymorphicCodeCachePrint(stdout);
6864  }
6865  void PolymorphicCodeCachePrint(FILE* out);
6866 #endif
6868 
6869  static const int kCacheOffset = HeapObject::kHeaderSize;
6870  static const int kSize = kCacheOffset + kPointerSize;
6871 
6872  private:
6873  DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
6874 };
6875 
6876 
6879  public:
6880  Object* Lookup(MapHandleList* maps, int code_kind);
6881 
6882  MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps,
6883  int code_kind,
6884  Code* code);
6885 
6886  static inline PolymorphicCodeCacheHashTable* cast(Object* obj);
6887 
6888  static const int kInitialSize = 64;
6889  private:
6891 };
6892 
6893 
6894 class TypeFeedbackInfo: public Struct {
6895  public:
6896  inline int ic_total_count();
6897  inline void set_ic_total_count(int count);
6898 
6899  inline int ic_with_type_info_count();
6900  inline void change_ic_with_type_info_count(int count);
6901 
6902  inline void initialize_storage();
6903 
6904  inline void change_own_type_change_checksum();
6905  inline int own_type_change_checksum();
6906 
6907  inline void set_inlined_type_change_checksum(int checksum);
6908  inline bool matches_inlined_type_change_checksum(int checksum);
6909 
6910  DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells)
6911 
6912  static inline TypeFeedbackInfo* cast(Object* obj);
6913 
6914 #ifdef OBJECT_PRINT
6915  inline void TypeFeedbackInfoPrint() {
6916  TypeFeedbackInfoPrint(stdout);
6917  }
6918  void TypeFeedbackInfoPrint(FILE* out);
6919 #endif
6921 
6922  static const int kStorage1Offset = HeapObject::kHeaderSize;
6923  static const int kStorage2Offset = kStorage1Offset + kPointerSize;
6924  static const int kTypeFeedbackCellsOffset = kStorage2Offset + kPointerSize;
6925  static const int kSize = kTypeFeedbackCellsOffset + kPointerSize;
6926 
6927  private:
6928  static const int kTypeChangeChecksumBits = 7;
6929 
6930  class ICTotalCountField: public BitField<int, 0,
6931  kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
6932  class OwnTypeChangeChecksum: public BitField<int,
6933  kSmiValueSize - kTypeChangeChecksumBits,
6934  kTypeChangeChecksumBits> {}; // NOLINT
6935  class ICsWithTypeInfoCountField: public BitField<int, 0,
6936  kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
6937  class InlinedTypeChangeChecksum: public BitField<int,
6938  kSmiValueSize - kTypeChangeChecksumBits,
6939  kTypeChangeChecksumBits> {}; // NOLINT
6940 
6941  DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
6942 };
6943 
6944 
6945 // Representation of a slow alias as part of a non-strict arguments objects.
6946 // For fast aliases (if HasNonStrictArgumentsElements()):
6947 // - the parameter map contains an index into the context
6948 // - all attributes of the element have default values
6949 // For slow aliases (if HasDictionaryArgumentsElements()):
6950 // - the parameter map contains no fast alias mapping (i.e. the hole)
6951 // - this struct (in the slow backing store) contains an index into the context
6952 // - all attributes are available as part if the property details
6954  public:
6955  inline int aliased_context_slot();
6956  inline void set_aliased_context_slot(int count);
6957 
6958  static inline AliasedArgumentsEntry* cast(Object* obj);
6959 
6960 #ifdef OBJECT_PRINT
6961  inline void AliasedArgumentsEntryPrint() {
6962  AliasedArgumentsEntryPrint(stdout);
6963  }
6964  void AliasedArgumentsEntryPrint(FILE* out);
6965 #endif
6967 
6968  static const int kAliasedContextSlot = HeapObject::kHeaderSize;
6969  static const int kSize = kAliasedContextSlot + kPointerSize;
6970 
6971  private:
6972  DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
6973 };
6974 
6975 
6978 
6979 
6981  public:
6982  explicit inline StringHasher(int length, uint32_t seed);
6983 
6984  // Returns true if the hash of this string can be computed without
6985  // looking at the contents.
6986  inline bool has_trivial_hash();
6987 
6988  // Add a character to the hash and update the array index calculation.
6989  inline void AddCharacter(uint32_t c);
6990 
6991  // Adds a character to the hash but does not update the array index
6992  // calculation. This can only be called when it has been verified
6993  // that the input is not an array index.
6994  inline void AddCharacterNoIndex(uint32_t c);
6995 
6996  // Add a character above 0xffff as a surrogate pair. These can get into
6997  // the hasher through the routines that take a UTF-8 string and make a symbol.
6998  void AddSurrogatePair(uc32 c);
6999  void AddSurrogatePairNoIndex(uc32 c);
7000 
7001  // Returns the value to store in the hash field of a string with
7002  // the given length and contents.
7003  uint32_t GetHashField();
7004 
7005  // Returns true if the characters seen so far make up a legal array
7006  // index.
7007  bool is_array_index() { return is_array_index_; }
7008 
7009  // Calculated hash value for a string consisting of 1 to
7010  // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
7011  // value is represented decimal value.
7012  static uint32_t MakeArrayIndexHash(uint32_t value, int length);
7013 
7014  // No string is allowed to have a hash of zero. That value is reserved
7015  // for internal properties. If the hash calculation yields zero then we
7016  // use 27 instead.
7017  static const int kZeroHash = 27;
7018 
7019  private:
7020  uint32_t array_index() {
7021  ASSERT(is_array_index());
7022  return array_index_;
7023  }
7024 
7025  inline uint32_t GetHash();
7026 
7027  // Reusable parts of the hashing algorithm.
7028  INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint32_t c));
7029  INLINE(static uint32_t GetHashCore(uint32_t running_hash));
7030 
7031  int length_;
7032  uint32_t raw_running_hash_;
7033  uint32_t array_index_;
7034  bool is_array_index_;
7035  bool is_first_char_;
7036  friend class TwoCharHashTableKey;
7037 
7038  template <bool seq_ascii> friend class JsonParser;
7039 };
7040 
7041 
7043  public:
7044  explicit inline IncrementalAsciiStringHasher(uint32_t seed, char first_char);
7045  inline void AddCharacter(uc32 c);
7046  inline uint32_t GetHash();
7047 
7048  private:
7049  int length_;
7050  uint32_t raw_running_hash_;
7051  uint32_t array_index_;
7052  bool is_array_index_;
7053  char first_char_;
7054 };
7055 
7056 
7057 // Calculates string hash.
7058 template <typename schar>
7059 inline uint32_t HashSequentialString(const schar* chars,
7060  int length,
7061  uint32_t seed);
7062 
7063 
7064 // The characteristics of a string are stored in its map. Retrieving these
7065 // few bits of information is moderately expensive, involving two memory
7066 // loads where the second is dependent on the first. To improve efficiency
7067 // the shape of the string is given its own class so that it can be retrieved
7068 // once and used for several string operations. A StringShape is small enough
7069 // to be passed by value and is immutable, but be aware that flattening a
7070 // string can potentially alter its shape. Also be aware that a GC caused by
7071 // something else can alter the shape of a string due to ConsString
7072 // shortcutting. Keeping these restrictions in mind has proven to be error-
7073 // prone and so we no longer put StringShapes in variables unless there is a
7074 // concrete performance benefit at that particular point in the code.
7075 class StringShape BASE_EMBEDDED {
7076  public:
7077  inline explicit StringShape(String* s);
7078  inline explicit StringShape(Map* s);
7079  inline explicit StringShape(InstanceType t);
7080  inline bool IsSequential();
7081  inline bool IsExternal();
7082  inline bool IsCons();
7083  inline bool IsSliced();
7084  inline bool IsIndirect();
7085  inline bool IsExternalAscii();
7086  inline bool IsExternalTwoByte();
7087  inline bool IsSequentialAscii();
7088  inline bool IsSequentialTwoByte();
7089  inline bool IsSymbol();
7090  inline StringRepresentationTag representation_tag();
7091  inline uint32_t encoding_tag();
7092  inline uint32_t full_representation_tag();
7093  inline uint32_t size_tag();
7094 #ifdef DEBUG
7095  inline uint32_t type() { return type_; }
7096  inline void invalidate() { valid_ = false; }
7097  inline bool valid() { return valid_; }
7098 #else
7099  inline void invalidate() { }
7100 #endif
7101 
7102  private:
7103  uint32_t type_;
7104 #ifdef DEBUG
7105  inline void set_valid() { valid_ = true; }
7106  bool valid_;
7107 #else
7108  inline void set_valid() { }
7109 #endif
7110 };
7111 
7112 
7113 // The String abstract class captures JavaScript string values:
7114 //
7115 // Ecma-262:
7116 // 4.3.16 String Value
7117 // A string value is a member of the type String and is a finite
7118 // ordered sequence of zero or more 16-bit unsigned integer values.
7119 //
7120 // All string values have a length field.
7121 class String: public HeapObject {
7122  public:
7123  // Representation of the flat content of a String.
7124  // A non-flat string doesn't have flat content.
7125  // A flat string has content that's encoded as a sequence of either
7126  // ASCII chars or two-byte UC16.
7127  // Returned by String::GetFlatContent().
7128  class FlatContent {
7129  public:
7130  // Returns true if the string is flat and this structure contains content.
7131  bool IsFlat() { return state_ != NON_FLAT; }
7132  // Returns true if the structure contains ASCII content.
7133  bool IsAscii() { return state_ == ASCII; }
7134  // Returns true if the structure contains two-byte content.
7135  bool IsTwoByte() { return state_ == TWO_BYTE; }
7136 
7137  // Return the ASCII content of the string. Only use if IsAscii() returns
7138  // true.
7140  ASSERT_EQ(ASCII, state_);
7142  }
7143  // Return the two-byte content of the string. Only use if IsTwoByte()
7144  // returns true.
7146  ASSERT_EQ(TWO_BYTE, state_);
7148  }
7149 
7150  private:
7151  enum State { NON_FLAT, ASCII, TWO_BYTE };
7152 
7153  // Constructors only used by String::GetFlatContent().
7154  explicit FlatContent(Vector<const char> chars)
7155  : buffer_(Vector<const byte>::cast(chars)),
7156  state_(ASCII) { }
7157  explicit FlatContent(Vector<const uc16> chars)
7158  : buffer_(Vector<const byte>::cast(chars)),
7159  state_(TWO_BYTE) { }
7160  FlatContent() : buffer_(), state_(NON_FLAT) { }
7161 
7162  Vector<const byte> buffer_;
7163  State state_;
7164 
7165  friend class String;
7166  };
7167 
7168  // Get and set the length of the string.
7169  inline int length();
7170  inline void set_length(int value);
7171 
7172  // Get and set the hash field of the string.
7173  inline uint32_t hash_field();
7174  inline void set_hash_field(uint32_t value);
7175 
7176  // Returns whether this string has only ASCII chars, i.e. all of them can
7177  // be ASCII encoded. This might be the case even if the string is
7178  // two-byte. Such strings may appear when the embedder prefers
7179  // two-byte external representations even for ASCII data.
7180  inline bool IsAsciiRepresentation();
7181  inline bool IsTwoByteRepresentation();
7182 
7183  // Cons and slices have an encoding flag that may not represent the actual
7184  // encoding of the underlying string. This is taken into account here.
7185  // Requires: this->IsFlat()
7186  inline bool IsAsciiRepresentationUnderneath();
7187  inline bool IsTwoByteRepresentationUnderneath();
7188 
7189  // NOTE: this should be considered only a hint. False negatives are
7190  // possible.
7191  inline bool HasOnlyAsciiChars();
7192 
7193  // Get and set individual two byte chars in the string.
7194  inline void Set(int index, uint16_t value);
7195  // Get individual two byte char in the string. Repeated calls
7196  // to this method are not efficient unless the string is flat.
7197  INLINE(uint16_t Get(int index));
7198 
7199  // Try to flatten the string. Checks first inline to see if it is
7200  // necessary. Does nothing if the string is not a cons string.
7201  // Flattening allocates a sequential string with the same data as
7202  // the given string and mutates the cons string to a degenerate
7203  // form, where the first component is the new sequential string and
7204  // the second component is the empty string. If allocation fails,
7205  // this function returns a failure. If flattening succeeds, this
7206  // function returns the sequential string that is now the first
7207  // component of the cons string.
7208  //
7209  // Degenerate cons strings are handled specially by the garbage
7210  // collector (see IsShortcutCandidate).
7211  //
7212  // Use FlattenString from Handles.cc to flatten even in case an
7213  // allocation failure happens.
7214  inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
7215 
7216  // Convenience function. Has exactly the same behavior as
7217  // TryFlatten(), except in the case of failure returns the original
7218  // string.
7219  inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
7220 
7221  // Tries to return the content of a flat string as a structure holding either
7222  // a flat vector of char or of uc16.
7223  // If the string isn't flat, and therefore doesn't have flat content, the
7224  // returned structure will report so, and can't provide a vector of either
7225  // kind.
7226  FlatContent GetFlatContent();
7227 
7228  // Returns the parent of a sliced string or first part of a flat cons string.
7229  // Requires: StringShape(this).IsIndirect() && this->IsFlat()
7230  inline String* GetUnderlying();
7231 
7232  // Mark the string as an undetectable object. It only applies to
7233  // ASCII and two byte string types.
7234  bool MarkAsUndetectable();
7235 
7236  // Return a substring.
7237  MUST_USE_RESULT MaybeObject* SubString(int from,
7238  int to,
7239  PretenureFlag pretenure = NOT_TENURED);
7240 
7241  // String equality operations.
7242  inline bool Equals(String* other);
7243  bool IsEqualTo(Vector<const char> str);
7244  bool IsAsciiEqualTo(Vector<const char> str);
7245  bool IsTwoByteEqualTo(Vector<const uc16> str);
7246 
7247  // Return a UTF8 representation of the string. The string is null
7248  // terminated but may optionally contain nulls. Length is returned
7249  // in length_output if length_output is not a null pointer The string
7250  // should be nearly flat, otherwise the performance of this method may
7251  // be very slow (quadratic in the length). Setting robustness_flag to
7252  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7253  // handles unexpected data without causing assert failures and it does not
7254  // do any heap allocations. This is useful when printing stack traces.
7256  RobustnessFlag robustness_flag,
7257  int offset,
7258  int length,
7259  int* length_output = 0);
7261  AllowNullsFlag allow_nulls = DISALLOW_NULLS,
7262  RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
7263  int* length_output = 0);
7264 
7265  // Return a 16 bit Unicode representation of the string.
7266  // The string should be nearly flat, otherwise the performance of
7267  // of this method may be very bad. Setting robustness_flag to
7268  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7269  // handles unexpected data without causing assert failures and it does not
7270  // do any heap allocations. This is useful when printing stack traces.
7271  SmartArrayPointer<uc16> ToWideCString(
7272  RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
7273 
7274  // Tells whether the hash code has been computed.
7275  inline bool HasHashCode();
7276 
7277  // Returns a hash value used for the property table
7278  inline uint32_t Hash();
7279 
7280  static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
7281  int length,
7282  uint32_t seed);
7283 
7284  static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
7285  uint32_t* index,
7286  int length);
7287 
7288  // Externalization.
7289  bool MakeExternal(v8::String::ExternalStringResource* resource);
7290  bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
7291 
7292  // Conversion.
7293  inline bool AsArrayIndex(uint32_t* index);
7294 
7295  // Casting.
7296  static inline String* cast(Object* obj);
7297 
7298  void PrintOn(FILE* out);
7299 
7300  // For use during stack traces. Performs rudimentary sanity check.
7301  bool LooksValid();
7302 
7303  // Dispatched behavior.
7304  void StringShortPrint(StringStream* accumulator);
7305 #ifdef OBJECT_PRINT
7306  inline void StringPrint() {
7307  StringPrint(stdout);
7308  }
7309  void StringPrint(FILE* out);
7310 
7311  char* ToAsciiArray();
7312 #endif
7314 
7315  inline bool IsFlat();
7316 
7317  // Layout description.
7318  static const int kLengthOffset = HeapObject::kHeaderSize;
7319  static const int kHashFieldOffset = kLengthOffset + kPointerSize;
7320  static const int kSize = kHashFieldOffset + kPointerSize;
7321 
7322  // Maximum number of characters to consider when trying to convert a string
7323  // value into an array index.
7324  static const int kMaxArrayIndexSize = 10;
7325 
7326  // Max ASCII char code.
7327  static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
7328  static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
7329  static const int kMaxUtf16CodeUnit = 0xffff;
7330 
7331  // Mask constant for checking if a string has a computed hash code
7332  // and if it is an array index. The least significant bit indicates
7333  // whether a hash code has been computed. If the hash code has been
7334  // computed the 2nd bit tells whether the string can be used as an
7335  // array index.
7336  static const int kHashNotComputedMask = 1;
7337  static const int kIsNotArrayIndexMask = 1 << 1;
7338  static const int kNofHashBitFields = 2;
7339 
7340  // Shift constant retrieving hash code from hash field.
7341  static const int kHashShift = kNofHashBitFields;
7342 
7343  // Only these bits are relevant in the hash, since the top two are shifted
7344  // out.
7345  static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
7346 
7347  // Array index strings this short can keep their index in the hash
7348  // field.
7349  static const int kMaxCachedArrayIndexLength = 7;
7350 
7351  // For strings which are array indexes the hash value has the string length
7352  // mixed into the hash, mainly to avoid a hash value of zero which would be
7353  // the case for the string '0'. 24 bits are used for the array index value.
7354  static const int kArrayIndexValueBits = 24;
7355  static const int kArrayIndexLengthBits =
7356  kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
7357 
7358  STATIC_CHECK((kArrayIndexLengthBits > 0));
7359  STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
7360 
7361  static const int kArrayIndexHashLengthShift =
7362  kArrayIndexValueBits + kNofHashBitFields;
7363 
7364  static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1;
7365 
7366  static const int kArrayIndexValueMask =
7367  ((1 << kArrayIndexValueBits) - 1) << kHashShift;
7368 
7369  // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
7370  // could use a mask to test if the length of string is less than or equal to
7371  // kMaxCachedArrayIndexLength.
7372  STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
7373 
7374  static const int kContainsCachedArrayIndexMask =
7375  (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) |
7376  kIsNotArrayIndexMask;
7377 
7378  // Value of empty hash field indicating that the hash is not computed.
7379  static const int kEmptyHashField =
7380  kIsNotArrayIndexMask | kHashNotComputedMask;
7381 
7382  // Value of hash field containing computed hash equal to zero.
7383  static const int kEmptyStringHash = kIsNotArrayIndexMask;
7384 
7385  // Maximal string length.
7386  static const int kMaxLength = (1 << (32 - 2)) - 1;
7387 
7388  // Max length for computing hash. For strings longer than this limit the
7389  // string length is used as the hash value.
7390  static const int kMaxHashCalcLength = 16383;
7391 
7392  // Limit for truncation in short printing.
7393  static const int kMaxShortPrintLength = 1024;
7394 
7395  // Support for regular expressions.
7396  const uc16* GetTwoByteData();
7397  const uc16* GetTwoByteData(unsigned start);
7398 
7399  // Support for StringInputBuffer
7400  static const unibrow::byte* ReadBlock(String* input,
7401  unibrow::byte* util_buffer,
7402  unsigned capacity,
7403  unsigned* remaining,
7404  unsigned* offset);
7405  static const unibrow::byte* ReadBlock(String** input,
7406  unibrow::byte* util_buffer,
7407  unsigned capacity,
7408  unsigned* remaining,
7409  unsigned* offset);
7410 
7411  // Helper function for flattening strings.
7412  template <typename sinkchar>
7413  static void WriteToFlat(String* source,
7414  sinkchar* sink,
7415  int from,
7416  int to);
7417 
7418  // The return value may point to the first aligned word containing the
7419  // first non-ascii character, rather than directly to the non-ascii character.
7420  // If the return value is >= the passed length, the entire string was ASCII.
7421  static inline int NonAsciiStart(const char* chars, int length) {
7422  const char* start = chars;
7423  const char* limit = chars + length;
7424 #ifdef V8_HOST_CAN_READ_UNALIGNED
7425  ASSERT(kMaxAsciiCharCode == 0x7F);
7426  const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
7427  while (chars + sizeof(uintptr_t) <= limit) {
7428  if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
7429  return static_cast<int>(chars - start);
7430  }
7431  chars += sizeof(uintptr_t);
7432  }
7433 #endif
7434  while (chars < limit) {
7435  if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) {
7436  return static_cast<int>(chars - start);
7437  }
7438  ++chars;
7439  }
7440  return static_cast<int>(chars - start);
7441  }
7442 
7443  static inline bool IsAscii(const char* chars, int length) {
7444  return NonAsciiStart(chars, length) >= length;
7445  }
7446 
7447  static inline int NonAsciiStart(const uc16* chars, int length) {
7448  const uc16* limit = chars + length;
7449  const uc16* start = chars;
7450  while (chars < limit) {
7451  if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start);
7452  ++chars;
7453  }
7454  return static_cast<int>(chars - start);
7455  }
7456 
7457  static inline bool IsAscii(const uc16* chars, int length) {
7458  return NonAsciiStart(chars, length) >= length;
7459  }
7460 
7461  protected:
7463  public:
7465  unsigned cursor_,
7466  unsigned capacity_,
7467  unsigned remaining_) :
7468  util_buffer(util_buffer_),
7469  cursor(cursor_),
7470  capacity(capacity_),
7471  remaining(remaining_) {
7472  }
7474  unsigned cursor;
7475  unsigned capacity;
7476  unsigned remaining;
7477  };
7478 
7479  static inline const unibrow::byte* ReadBlock(String* input,
7480  ReadBlockBuffer* buffer,
7481  unsigned* offset,
7482  unsigned max_chars);
7483  static void ReadBlockIntoBuffer(String* input,
7484  ReadBlockBuffer* buffer,
7485  unsigned* offset_ptr,
7486  unsigned max_chars);
7487 
7488  private:
7489  // Try to flatten the top level ConsString that is hiding behind this
7490  // string. This is a no-op unless the string is a ConsString. Flatten
7491  // mutates the ConsString and might return a failure.
7492  MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
7493 
7494  static inline bool IsHashFieldComputed(uint32_t field);
7495 
7496  // Slow case of String::Equals. This implementation works on any strings
7497  // but it is most efficient on strings that are almost flat.
7498  bool SlowEquals(String* other);
7499 
7500  // Slow case of AsArrayIndex.
7501  bool SlowAsArrayIndex(uint32_t* index);
7502 
7503  // Compute and set the hash code.
7504  uint32_t ComputeAndSetHash();
7505 
7507 };
7508 
7509 
7510 // The SeqString abstract class captures sequential string values.
7511 class SeqString: public String {
7512  public:
7513  // Casting.
7514  static inline SeqString* cast(Object* obj);
7515 
7516  // Layout description.
7517  static const int kHeaderSize = String::kSize;
7518 
7519  private:
7521 };
7522 
7523 
7524 // The AsciiString class captures sequential ASCII string objects.
7525 // Each character in the AsciiString is an ASCII character.
7526 class SeqAsciiString: public SeqString {
7527  public:
7528  static const bool kHasAsciiEncoding = true;
7529 
7530  // Dispatched behavior.
7531  inline uint16_t SeqAsciiStringGet(int index);
7532  inline void SeqAsciiStringSet(int index, uint16_t value);
7533 
7534  // Get the address of the characters in this string.
7535  inline Address GetCharsAddress();
7536 
7537  inline char* GetChars();
7538 
7539  // Casting
7540  static inline SeqAsciiString* cast(Object* obj);
7541 
7542  // Garbage collection support. This method is called by the
7543  // garbage collector to compute the actual size of an AsciiString
7544  // instance.
7545  inline int SeqAsciiStringSize(InstanceType instance_type);
7546 
7547  // Computes the size for an AsciiString instance of a given length.
7548  static int SizeFor(int length) {
7549  return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
7550  }
7551 
7552  // Maximal memory usage for a single sequential ASCII string.
7553  static const int kMaxSize = 512 * MB - 1;
7554  // Maximal length of a single sequential ASCII string.
7555  // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7556  static const int kMaxLength = (kMaxSize - kHeaderSize);
7557 
7558  // Support for StringInputBuffer.
7559  inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7560  unsigned* offset,
7561  unsigned chars);
7562  inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
7563  unsigned* offset,
7564  unsigned chars);
7565 
7567 
7568  private:
7569  DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
7570 };
7571 
7572 
7573 // The TwoByteString class captures sequential unicode string objects.
7574 // Each character in the TwoByteString is a two-byte uint16_t.
7576  public:
7577  static const bool kHasAsciiEncoding = false;
7578 
7579  // Dispatched behavior.
7580  inline uint16_t SeqTwoByteStringGet(int index);
7581  inline void SeqTwoByteStringSet(int index, uint16_t value);
7582 
7583  // Get the address of the characters in this string.
7584  inline Address GetCharsAddress();
7585 
7586  inline uc16* GetChars();
7587 
7588  // For regexp code.
7589  const uint16_t* SeqTwoByteStringGetData(unsigned start);
7590 
7591  // Casting
7592  static inline SeqTwoByteString* cast(Object* obj);
7593 
7594  // Garbage collection support. This method is called by the
7595  // garbage collector to compute the actual size of a TwoByteString
7596  // instance.
7597  inline int SeqTwoByteStringSize(InstanceType instance_type);
7598 
7599  // Computes the size for a TwoByteString instance of a given length.
7600  static int SizeFor(int length) {
7601  return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
7602  }
7603 
7604  // Maximal memory usage for a single sequential two-byte string.
7605  static const int kMaxSize = 512 * MB - 1;
7606  // Maximal length of a single sequential two-byte string.
7607  // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7608  static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
7609 
7610  // Support for StringInputBuffer.
7611  inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7612  unsigned* offset_ptr,
7613  unsigned chars);
7614 
7615  private:
7617 };
7618 
7619 
7620 // The ConsString class describes string values built by using the
7621 // addition operator on strings. A ConsString is a pair where the
7622 // first and second components are pointers to other string values.
7623 // One or both components of a ConsString can be pointers to other
7624 // ConsStrings, creating a binary tree of ConsStrings where the leaves
7625 // are non-ConsString string values. The string value represented by
7626 // a ConsString can be obtained by concatenating the leaf string
7627 // values in a left-to-right depth-first traversal of the tree.
7628 class ConsString: public String {
7629  public:
7630  // First string of the cons cell.
7631  inline String* first();
7632  // Doesn't check that the result is a string, even in debug mode. This is
7633  // useful during GC where the mark bits confuse the checks.
7634  inline Object* unchecked_first();
7635  inline void set_first(String* first,
7637 
7638  // Second string of the cons cell.
7639  inline String* second();
7640  // Doesn't check that the result is a string, even in debug mode. This is
7641  // useful during GC where the mark bits confuse the checks.
7642  inline Object* unchecked_second();
7643  inline void set_second(String* second,
7645 
7646  // Dispatched behavior.
7647  uint16_t ConsStringGet(int index);
7648 
7649  // Casting.
7650  static inline ConsString* cast(Object* obj);
7651 
7652  // Layout description.
7653  static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
7654  static const int kSecondOffset = kFirstOffset + kPointerSize;
7655  static const int kSize = kSecondOffset + kPointerSize;
7656 
7657  // Support for StringInputBuffer.
7658  inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
7659  unsigned* offset_ptr,
7660  unsigned chars);
7661  inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7662  unsigned* offset_ptr,
7663  unsigned chars);
7664 
7665  // Minimum length for a cons string.
7666  static const int kMinLength = 13;
7667 
7670 
7672 
7673  private:
7674  DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
7675 };
7676 
7677 
7678 // The Sliced String class describes strings that are substrings of another
7679 // sequential string. The motivation is to save time and memory when creating
7680 // a substring. A Sliced String is described as a pointer to the parent,
7681 // the offset from the start of the parent string and the length. Using
7682 // a Sliced String therefore requires unpacking of the parent string and
7683 // adding the offset to the start address. A substring of a Sliced String
7684 // are not nested since the double indirection is simplified when creating
7685 // such a substring.
7686 // Currently missing features are:
7687 // - handling externalized parent strings
7688 // - external strings as parent
7689 // - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
7690 class SlicedString: public String {
7691  public:
7692  inline String* parent();
7693  inline void set_parent(String* parent,
7695  inline int offset();
7696  inline void set_offset(int offset);
7697 
7698  // Dispatched behavior.
7699  uint16_t SlicedStringGet(int index);
7700 
7701  // Casting.
7702  static inline SlicedString* cast(Object* obj);
7703 
7704  // Layout description.
7705  static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
7706  static const int kOffsetOffset = kParentOffset + kPointerSize;
7707  static const int kSize = kOffsetOffset + kPointerSize;
7708 
7709  // Support for StringInputBuffer
7710  inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
7711  unsigned* offset_ptr,
7712  unsigned chars);
7713  inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7714  unsigned* offset_ptr,
7715  unsigned chars);
7716  // Minimum length for a sliced string.
7717  static const int kMinLength = 13;
7718 
7719  typedef FixedBodyDescriptor<kParentOffset,
7720  kOffsetOffset + kPointerSize, kSize>
7722 
7724 
7725  private:
7726  DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
7727 };
7728 
7729 
7730 // The ExternalString class describes string values that are backed by
7731 // a string resource that lies outside the V8 heap. ExternalStrings
7732 // consist of the length field common to all strings, a pointer to the
7733 // external resource. It is important to ensure (externally) that the
7734 // resource is not deallocated while the ExternalString is live in the
7735 // V8 heap.
7736 //
7737 // The API expects that all ExternalStrings are created through the
7738 // API. Therefore, ExternalStrings should not be used internally.
7739 class ExternalString: public String {
7740  public:
7741  // Casting
7742  static inline ExternalString* cast(Object* obj);
7743 
7744  // Layout description.
7745  static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
7746  static const int kShortSize = kResourceOffset + kPointerSize;
7747  static const int kResourceDataOffset = kResourceOffset + kPointerSize;
7748  static const int kSize = kResourceDataOffset + kPointerSize;
7749 
7750  // Return whether external string is short (data pointer is not cached).
7751  inline bool is_short();
7752 
7753  STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
7754 
7755  private:
7757 };
7758 
7759 
7760 // The ExternalAsciiString class is an external string backed by an
7761 // ASCII string.
7763  public:
7764  static const bool kHasAsciiEncoding = true;
7765 
7767 
7768  // The underlying resource.
7769  inline const Resource* resource();
7770  inline void set_resource(const Resource* buffer);
7771 
7772  // Update the pointer cache to the external character array.
7773  // The cached pointer is always valid, as the external character array does =
7774  // not move during lifetime. Deserialization is the only exception, after
7775  // which the pointer cache has to be refreshed.
7776  inline void update_data_cache();
7777 
7778  inline const char* GetChars();
7779 
7780  // Dispatched behavior.
7781  inline uint16_t ExternalAsciiStringGet(int index);
7782 
7783  // Casting.
7784  static inline ExternalAsciiString* cast(Object* obj);
7785 
7786  // Garbage collection support.
7787  inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
7788 
7789  template<typename StaticVisitor>
7790  inline void ExternalAsciiStringIterateBody();
7791 
7792  // Support for StringInputBuffer.
7793  const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
7794  unsigned* offset,
7795  unsigned chars);
7796  inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7797  unsigned* offset,
7798  unsigned chars);
7799 
7800  private:
7802 };
7803 
7804 
7805 // The ExternalTwoByteString class is an external string backed by a UTF-16
7806 // encoded string.
7808  public:
7809  static const bool kHasAsciiEncoding = false;
7810 
7812 
7813  // The underlying string resource.
7814  inline const Resource* resource();
7815  inline void set_resource(const Resource* buffer);
7816 
7817  // Update the pointer cache to the external character array.
7818  // The cached pointer is always valid, as the external character array does =
7819  // not move during lifetime. Deserialization is the only exception, after
7820  // which the pointer cache has to be refreshed.
7821  inline void update_data_cache();
7822 
7823  inline const uint16_t* GetChars();
7824 
7825  // Dispatched behavior.
7826  inline uint16_t ExternalTwoByteStringGet(int index);
7827 
7828  // For regexp code.
7829  inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
7830 
7831  // Casting.
7832  static inline ExternalTwoByteString* cast(Object* obj);
7833 
7834  // Garbage collection support.
7835  inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
7836 
7837  template<typename StaticVisitor>
7838  inline void ExternalTwoByteStringIterateBody();
7839 
7840 
7841  // Support for StringInputBuffer.
7842  void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7843  unsigned* offset_ptr,
7844  unsigned chars);
7845 
7846  private:
7848 };
7849 
7850 
7851 // Utility superclass for stack-allocated objects that must be updated
7852 // on gc. It provides two ways for the gc to update instances, either
7853 // iterating or updating after gc.
7854 class Relocatable BASE_EMBEDDED {
7855  public:
7856  explicit inline Relocatable(Isolate* isolate);
7857  inline virtual ~Relocatable();
7858  virtual void IterateInstance(ObjectVisitor* v) { }
7859  virtual void PostGarbageCollection() { }
7860 
7861  static void PostGarbageCollectionProcessing();
7862  static int ArchiveSpacePerThread();
7863  static char* ArchiveState(Isolate* isolate, char* to);
7864  static char* RestoreState(Isolate* isolate, char* from);
7865  static void Iterate(ObjectVisitor* v);
7866  static void Iterate(ObjectVisitor* v, Relocatable* top);
7867  static char* Iterate(ObjectVisitor* v, char* t);
7868  private:
7869  Isolate* isolate_;
7870  Relocatable* prev_;
7871 };
7872 
7873 
7874 // A flat string reader provides random access to the contents of a
7875 // string independent of the character width of the string. The handle
7876 // must be valid as long as the reader is being used.
7877 class FlatStringReader : public Relocatable {
7878  public:
7879  FlatStringReader(Isolate* isolate, Handle<String> str);
7880  FlatStringReader(Isolate* isolate, Vector<const char> input);
7881  void PostGarbageCollection();
7882  inline uc32 Get(int index);
7883  int length() { return length_; }
7884  private:
7885  String** str_;
7886  bool is_ascii_;
7887  int length_;
7888  const void* start_;
7889 };
7890 
7891 
7892 // Note that StringInputBuffers are not valid across a GC! To fix this
7893 // it would have to store a String Handle instead of a String* and
7894 // AsciiStringReadBlock would have to be modified to use memcpy.
7895 //
7896 // StringInputBuffer is able to traverse any string regardless of how
7897 // deeply nested a sequence of ConsStrings it is made of. However,
7898 // performance will be better if deep strings are flattened before they
7899 // are traversed. Since flattening requires memory allocation this is
7900 // not always desirable, however (esp. in debugging situations).
7901 class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
7902  public:
7903  virtual void Seek(unsigned pos);
7904  inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
7905  explicit inline StringInputBuffer(String* backing):
7906  unibrow::InputBuffer<String, String*, 1024>(backing) {}
7907 };
7908 
7909 
7911  : public unibrow::InputBuffer<String, String**, 256> {
7912  public:
7913  virtual void Seek(unsigned pos);
7915  : unibrow::InputBuffer<String, String**, 256>() {}
7916  explicit inline SafeStringInputBuffer(String** backing)
7917  : unibrow::InputBuffer<String, String**, 256>(backing) {}
7918 };
7919 
7920 
7921 template <typename T>
7923  public:
7924  VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
7925  explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
7926  T GetNext() { return data_[index_++]; }
7927  bool has_more() { return index_ < data_.length(); }
7928  private:
7929  Vector<const T> data_;
7930  int index_;
7931 };
7932 
7933 
7934 // The Oddball describes objects null, undefined, true, and false.
7935 class Oddball: public HeapObject {
7936  public:
7937  // [to_string]: Cached to_string computed at startup.
7938  DECL_ACCESSORS(to_string, String)
7939 
7940  // [to_number]: Cached to_number computed at startup.
7941  DECL_ACCESSORS(to_number, Object)
7942 
7943  inline byte kind();
7944  inline void set_kind(byte kind);
7945 
7946  // Casting.
7947  static inline Oddball* cast(Object* obj);
7948 
7949  // Dispatched behavior.
7951 
7952  // Initialize the fields.
7953  MUST_USE_RESULT MaybeObject* Initialize(const char* to_string,
7954  Object* to_number,
7955  byte kind);
7956 
7957  // Layout description.
7958  static const int kToStringOffset = HeapObject::kHeaderSize;
7959  static const int kToNumberOffset = kToStringOffset + kPointerSize;
7960  static const int kKindOffset = kToNumberOffset + kPointerSize;
7961  static const int kSize = kKindOffset + kPointerSize;
7962 
7963  static const byte kFalse = 0;
7964  static const byte kTrue = 1;
7965  static const byte kNotBooleanMask = ~1;
7966  static const byte kTheHole = 2;
7967  static const byte kNull = 3;
7968  static const byte kArgumentMarker = 4;
7969  static const byte kUndefined = 5;
7970  static const byte kOther = 6;
7971 
7972  typedef FixedBodyDescriptor<kToStringOffset,
7973  kToNumberOffset + kPointerSize,
7975 
7979 
7980  private:
7982 };
7983 
7984 
7985 class JSGlobalPropertyCell: public HeapObject {
7986  public:
7987  // [value]: value of the global property.
7988  DECL_ACCESSORS(value, Object)
7989 
7990  // Casting.
7991  static inline JSGlobalPropertyCell* cast(Object* obj);
7992 
7994  return cast(FromAddress(value - kValueOffset));
7995  }
7996 
7998  return address() + kValueOffset;
7999  }
8000 
8002 
8003 #ifdef OBJECT_PRINT
8004  inline void JSGlobalPropertyCellPrint() {
8005  JSGlobalPropertyCellPrint(stdout);
8006  }
8007  void JSGlobalPropertyCellPrint(FILE* out);
8008 #endif
8009 
8010  // Layout description.
8011  static const int kValueOffset = HeapObject::kHeaderSize;
8012  static const int kSize = kValueOffset + kPointerSize;
8013 
8014  typedef FixedBodyDescriptor<kValueOffset,
8015  kValueOffset + kPointerSize,
8017 
8018  private:
8020 };
8021 
8022 
8023 // The JSProxy describes EcmaScript Harmony proxies
8024 class JSProxy: public JSReceiver {
8025  public:
8026  // [handler]: The handler property.
8027  DECL_ACCESSORS(handler, Object)
8028 
8029  // [hash]: The hash code property (undefined if not initialized yet).
8030  DECL_ACCESSORS(hash, Object)
8031 
8032  // Casting.
8033  static inline JSProxy* cast(Object* obj);
8034 
8035  bool HasPropertyWithHandler(String* name);
8036  bool HasElementWithHandler(uint32_t index);
8037 
8038  MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(
8039  Object* receiver,
8040  String* name);
8041  MUST_USE_RESULT MaybeObject* GetElementWithHandler(
8042  Object* receiver,
8043  uint32_t index);
8044 
8045  MUST_USE_RESULT MaybeObject* SetPropertyWithHandler(
8046  JSReceiver* receiver,
8047  String* name,
8048  Object* value,
8049  PropertyAttributes attributes,
8050  StrictModeFlag strict_mode);
8051  MUST_USE_RESULT MaybeObject* SetElementWithHandler(
8052  JSReceiver* receiver,
8053  uint32_t index,
8054  Object* value,
8055  StrictModeFlag strict_mode);
8056 
8057  // If the handler defines an accessor property with a setter, invoke it.
8058  // If it defines an accessor property without a setter, or a data property
8059  // that is read-only, throw. In all these cases set '*done' to true,
8060  // otherwise set it to false.
8061  MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypesWithHandler(
8062  JSReceiver* receiver,
8063  String* name,
8064  Object* value,
8065  PropertyAttributes attributes,
8066  StrictModeFlag strict_mode,
8067  bool* done);
8068 
8069  MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler(
8070  String* name,
8071  DeleteMode mode);
8072  MUST_USE_RESULT MaybeObject* DeleteElementWithHandler(
8073  uint32_t index,
8074  DeleteMode mode);
8075 
8076  MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler(
8077  JSReceiver* receiver,
8078  String* name);
8079  MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler(
8080  JSReceiver* receiver,
8081  uint32_t index);
8082 
8083  MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
8084 
8085  // Turn this into an (empty) JSObject.
8086  void Fix();
8087 
8088  // Initializes the body after the handler slot.
8089  inline void InitializeBody(int object_size, Object* value);
8090 
8091  // Invoke a trap by name. If the trap does not exist on this's handler,
8092  // but derived_trap is non-NULL, invoke that instead. May cause GC.
8093  Handle<Object> CallTrap(const char* name,
8094  Handle<Object> derived_trap,
8095  int argc,
8096  Handle<Object> args[]);
8097 
8098  // Dispatched behavior.
8099 #ifdef OBJECT_PRINT
8100  inline void JSProxyPrint() {
8101  JSProxyPrint(stdout);
8102  }
8103  void JSProxyPrint(FILE* out);
8104 #endif
8106 
8107  // Layout description. We add padding so that a proxy has the same
8108  // size as a virgin JSObject. This is essential for becoming a JSObject
8109  // upon freeze.
8110  static const int kHandlerOffset = HeapObject::kHeaderSize;
8111  static const int kHashOffset = kHandlerOffset + kPointerSize;
8112  static const int kPaddingOffset = kHashOffset + kPointerSize;
8113  static const int kSize = JSObject::kHeaderSize;
8114  static const int kHeaderSize = kPaddingOffset;
8115  static const int kPaddingSize = kSize - kPaddingOffset;
8116 
8117  STATIC_CHECK(kPaddingSize >= 0);
8118 
8119  typedef FixedBodyDescriptor<kHandlerOffset,
8120  kPaddingOffset,
8122 
8123  private:
8124  DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
8125 };
8126 
8127 
8128 class JSFunctionProxy: public JSProxy {
8129  public:
8130  // [call_trap]: The call trap.
8131  DECL_ACCESSORS(call_trap, Object)
8132 
8133  // [construct_trap]: The construct trap.
8134  DECL_ACCESSORS(construct_trap, Object)
8135 
8136  // Casting.
8137  static inline JSFunctionProxy* cast(Object* obj);
8138 
8139  // Dispatched behavior.
8140 #ifdef OBJECT_PRINT
8141  inline void JSFunctionProxyPrint() {
8142  JSFunctionProxyPrint(stdout);
8143  }
8144  void JSFunctionProxyPrint(FILE* out);
8145 #endif
8147 
8148  // Layout description.
8149  static const int kCallTrapOffset = JSProxy::kPaddingOffset;
8150  static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
8151  static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
8152  static const int kSize = JSFunction::kSize;
8153  static const int kPaddingSize = kSize - kPaddingOffset;
8154 
8155  STATIC_CHECK(kPaddingSize >= 0);
8156 
8157  typedef FixedBodyDescriptor<kHandlerOffset,
8158  kConstructTrapOffset + kPointerSize,
8159  kSize> BodyDescriptor;
8160 
8161  private:
8162  DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
8163 };
8164 
8165 
8166 // The JSSet describes EcmaScript Harmony sets
8167 class JSSet: public JSObject {
8168  public:
8169  // [set]: the backing hash set containing keys.
8170  DECL_ACCESSORS(table, Object)
8171 
8172  // Casting.
8173  static inline JSSet* cast(Object* obj);
8174 
8175 #ifdef OBJECT_PRINT
8176  inline void JSSetPrint() {
8177  JSSetPrint(stdout);
8178  }
8179  void JSSetPrint(FILE* out);
8180 #endif
8182 
8183  static const int kTableOffset = JSObject::kHeaderSize;
8184  static const int kSize = kTableOffset + kPointerSize;
8185 
8186  private:
8187  DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
8188 };
8189 
8190 
8191 // The JSMap describes EcmaScript Harmony maps
8192 class JSMap: public JSObject {
8193  public:
8194  // [table]: the backing hash table mapping keys to values.
8195  DECL_ACCESSORS(table, Object)
8196 
8197  // Casting.
8198  static inline JSMap* cast(Object* obj);
8199 
8200 #ifdef OBJECT_PRINT
8201  inline void JSMapPrint() {
8202  JSMapPrint(stdout);
8203  }
8204  void JSMapPrint(FILE* out);
8205 #endif
8207 
8208  static const int kTableOffset = JSObject::kHeaderSize;
8209  static const int kSize = kTableOffset + kPointerSize;
8210 
8211  private:
8212  DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
8213 };
8214 
8215 
8216 // The JSWeakMap describes EcmaScript Harmony weak maps
8217 class JSWeakMap: public JSObject {
8218  public:
8219  // [table]: the backing hash table mapping keys to values.
8220  DECL_ACCESSORS(table, Object)
8221 
8222  // [next]: linked list of encountered weak maps during GC.
8223  DECL_ACCESSORS(next, Object)
8224 
8225  // Casting.
8226  static inline JSWeakMap* cast(Object* obj);
8227 
8228 #ifdef OBJECT_PRINT
8229  inline void JSWeakMapPrint() {
8230  JSWeakMapPrint(stdout);
8231  }
8232  void JSWeakMapPrint(FILE* out);
8233 #endif
8235 
8236  static const int kTableOffset = JSObject::kHeaderSize;
8237  static const int kNextOffset = kTableOffset + kPointerSize;
8238  static const int kSize = kNextOffset + kPointerSize;
8239 
8240  private:
8241  DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
8242 };
8243 
8244 
8245 // Foreign describes objects pointing from JavaScript to C structures.
8246 // Since they cannot contain references to JS HeapObjects they can be
8247 // placed in old_data_space.
8248 class Foreign: public HeapObject {
8249  public:
8250  // [address]: field containing the address.
8251  inline Address foreign_address();
8252  inline void set_foreign_address(Address value);
8253 
8254  // Casting.
8255  static inline Foreign* cast(Object* obj);
8256 
8257  // Dispatched behavior.
8258  inline void ForeignIterateBody(ObjectVisitor* v);
8259 
8260  template<typename StaticVisitor>
8261  inline void ForeignIterateBody();
8262 
8263 #ifdef OBJECT_PRINT
8264  inline void ForeignPrint() {
8265  ForeignPrint(stdout);
8266  }
8267  void ForeignPrint(FILE* out);
8268 #endif
8270 
8271  // Layout description.
8272 
8273  static const int kForeignAddressOffset = HeapObject::kHeaderSize;
8274  static const int kSize = kForeignAddressOffset + kPointerSize;
8275 
8276  STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset);
8277 
8278  private:
8279  DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
8280 };
8281 
8282 
8283 // The JSArray describes JavaScript Arrays
8284 // Such an array can be in one of two modes:
8285 // - fast, backing storage is a FixedArray and length <= elements.length();
8286 // Please note: push and pop can be used to grow and shrink the array.
8287 // - slow, backing storage is a HashTable with numbers as keys.
8288 class JSArray: public JSObject {
8289  public:
8290  // [length]: The length property.
8291  DECL_ACCESSORS(length, Object)
8292 
8293  // Overload the length setter to skip write barrier when the length
8294  // is set to a smi. This matches the set function on FixedArray.
8295  inline void set_length(Smi* length);
8296 
8297  MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
8298  Object* value);
8299 
8300  // Initialize the array with the given capacity. The function may
8301  // fail due to out-of-memory situations, but only if the requested
8302  // capacity is non-zero.
8303  MUST_USE_RESULT MaybeObject* Initialize(int capacity);
8304 
8305  // Initializes the array to a certain length.
8306  inline bool AllowsSetElementsLength();
8307  MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);
8308 
8309  // Set the content of the array to the content of storage.
8310  MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
8311 
8312  // Casting.
8313  static inline JSArray* cast(Object* obj);
8314 
8315  // Uses handles. Ensures that the fixed array backing the JSArray has at
8316  // least the stated size.
8317  inline void EnsureSize(int minimum_size_of_backing_fixed_array);
8318 
8319  // Dispatched behavior.
8320 #ifdef OBJECT_PRINT
8321  inline void JSArrayPrint() {
8322  JSArrayPrint(stdout);
8323  }
8324  void JSArrayPrint(FILE* out);
8325 #endif
8327 
8328  // Number of element slots to pre-allocate for an empty array.
8329  static const int kPreallocatedArrayElements = 4;
8330 
8331  // Layout description.
8332  static const int kLengthOffset = JSObject::kHeaderSize;
8333  static const int kSize = kLengthOffset + kPointerSize;
8334 
8335  private:
8336  // Expand the fixed array backing of a fast-case JSArray to at least
8337  // the requested size.
8338  void Expand(int minimum_size_of_backing_fixed_array);
8339 
8340  DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
8341 };
8342 
8343 
8344 // JSRegExpResult is just a JSArray with a specific initial map.
8345 // This initial map adds in-object properties for "index" and "input"
8346 // properties, as assigned by RegExp.prototype.exec, which allows
8347 // faster creation of RegExp exec results.
8348 // This class just holds constants used when creating the result.
8349 // After creation the result must be treated as a JSArray in all regards.
8350 class JSRegExpResult: public JSArray {
8351  public:
8352  // Offsets of object fields.
8353  static const int kIndexOffset = JSArray::kSize;
8354  static const int kInputOffset = kIndexOffset + kPointerSize;
8355  static const int kSize = kInputOffset + kPointerSize;
8356  // Indices of in-object properties.
8357  static const int kIndexIndex = 0;
8358  static const int kInputIndex = 1;
8359  private:
8361 };
8362 
8363 
8364 // An accessor must have a getter, but can have no setter.
8365 //
8366 // When setting a property, V8 searches accessors in prototypes.
8367 // If an accessor was found and it does not have a setter,
8368 // the request is ignored.
8369 //
8370 // If the accessor in the prototype has the READ_ONLY property attribute, then
8371 // a new value is added to the local object when the property is set.
8372 // This shadows the accessor in the prototype.
8373 class AccessorInfo: public Struct {
8374  public:
8375  DECL_ACCESSORS(getter, Object)
8376  DECL_ACCESSORS(setter, Object)
8377  DECL_ACCESSORS(data, Object)
8378  DECL_ACCESSORS(name, Object)
8379  DECL_ACCESSORS(flag, Smi)
8380  DECL_ACCESSORS(expected_receiver_type, Object)
8381 
8382  inline bool all_can_read();
8383  inline void set_all_can_read(bool value);
8384 
8385  inline bool all_can_write();
8386  inline void set_all_can_write(bool value);
8387 
8388  inline bool prohibits_overwriting();
8389  inline void set_prohibits_overwriting(bool value);
8390 
8391  inline PropertyAttributes property_attributes();
8392  inline void set_property_attributes(PropertyAttributes attributes);
8393 
8394  // Checks whether the given receiver is compatible with this accessor.
8395  inline bool IsCompatibleReceiver(Object* receiver);
8396 
8397  static inline AccessorInfo* cast(Object* obj);
8398 
8399 #ifdef OBJECT_PRINT
8400  inline void AccessorInfoPrint() {
8401  AccessorInfoPrint(stdout);
8402  }
8403  void AccessorInfoPrint(FILE* out);
8404 #endif
8406 
8407  static const int kGetterOffset = HeapObject::kHeaderSize;
8408  static const int kSetterOffset = kGetterOffset + kPointerSize;
8409  static const int kDataOffset = kSetterOffset + kPointerSize;
8410  static const int kNameOffset = kDataOffset + kPointerSize;
8411  static const int kFlagOffset = kNameOffset + kPointerSize;
8412  static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
8413  static const int kSize = kExpectedReceiverTypeOffset + kPointerSize;
8414 
8415  private:
8416  // Bit positions in flag.
8417  static const int kAllCanReadBit = 0;
8418  static const int kAllCanWriteBit = 1;
8419  static const int kProhibitsOverwritingBit = 2;
8420  class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
8421 
8423 };
8424 
8425 
8426 // Support for JavaScript accessors: A pair of a getter and a setter. Each
8427 // accessor can either be
8428 // * a pointer to a JavaScript function or proxy: a real accessor
8429 // * undefined: considered an accessor by the spec, too, strangely enough
8430 // * the hole: an accessor which has not been set
8431 // * a pointer to a map: a transition used to ensure map sharing
8432 class AccessorPair: public Struct {
8433  public:
8434  DECL_ACCESSORS(getter, Object)
8435  DECL_ACCESSORS(setter, Object)
8436 
8437  static inline AccessorPair* cast(Object* obj);
8438 
8439  MUST_USE_RESULT MaybeObject* Copy();
8440 
8441  Object* get(AccessorComponent component) {
8442  return component == ACCESSOR_GETTER ? getter() : setter();
8443  }
8444 
8445  void set(AccessorComponent component, Object* value) {
8446  if (component == ACCESSOR_GETTER) {
8447  set_getter(value);
8448  } else {
8449  set_setter(value);
8450  }
8451  }
8452 
8453  // Note: Returns undefined instead in case of a hole.
8454  Object* GetComponent(AccessorComponent component);
8455 
8456  // Set both components, skipping arguments which are a JavaScript null.
8457  void SetComponents(Object* getter, Object* setter) {
8458  if (!getter->IsNull()) set_getter(getter);
8459  if (!setter->IsNull()) set_setter(setter);
8460  }
8461 
8463  return IsJSAccessor(getter()) || IsJSAccessor(setter());
8464  }
8465 
8466 #ifdef OBJECT_PRINT
8467  void AccessorPairPrint(FILE* out = stdout);
8468 #endif
8470 
8471  static const int kGetterOffset = HeapObject::kHeaderSize;
8472  static const int kSetterOffset = kGetterOffset + kPointerSize;
8473  static const int kSize = kSetterOffset + kPointerSize;
8474 
8475  private:
8476  // Strangely enough, in addition to functions and harmony proxies, the spec
8477  // requires us to consider undefined as a kind of accessor, too:
8478  // var obj = {};
8479  // Object.defineProperty(obj, "foo", {get: undefined});
8480  // assertTrue("foo" in obj);
8481  bool IsJSAccessor(Object* obj) {
8482  return obj->IsSpecFunction() || obj->IsUndefined();
8483  }
8484 
8486 };
8487 
8488 
8489 class AccessCheckInfo: public Struct {
8490  public:
8491  DECL_ACCESSORS(named_callback, Object)
8492  DECL_ACCESSORS(indexed_callback, Object)
8493  DECL_ACCESSORS(data, Object)
8494 
8495  static inline AccessCheckInfo* cast(Object* obj);
8496 
8497 #ifdef OBJECT_PRINT
8498  inline void AccessCheckInfoPrint() {
8499  AccessCheckInfoPrint(stdout);
8500  }
8501  void AccessCheckInfoPrint(FILE* out);
8502 #endif
8504 
8505  static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
8506  static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
8507  static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
8508  static const int kSize = kDataOffset + kPointerSize;
8509 
8510  private:
8511  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
8512 };
8513 
8514 
8515 class InterceptorInfo: public Struct {
8516  public:
8517  DECL_ACCESSORS(getter, Object)
8518  DECL_ACCESSORS(setter, Object)
8519  DECL_ACCESSORS(query, Object)
8520  DECL_ACCESSORS(deleter, Object)
8521  DECL_ACCESSORS(enumerator, Object)
8522  DECL_ACCESSORS(data, Object)
8523 
8524  static inline InterceptorInfo* cast(Object* obj);
8525 
8526 #ifdef OBJECT_PRINT
8527  inline void InterceptorInfoPrint() {
8528  InterceptorInfoPrint(stdout);
8529  }
8530  void InterceptorInfoPrint(FILE* out);
8531 #endif
8533 
8534  static const int kGetterOffset = HeapObject::kHeaderSize;
8535  static const int kSetterOffset = kGetterOffset + kPointerSize;
8536  static const int kQueryOffset = kSetterOffset + kPointerSize;
8537  static const int kDeleterOffset = kQueryOffset + kPointerSize;
8538  static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
8539  static const int kDataOffset = kEnumeratorOffset + kPointerSize;
8540  static const int kSize = kDataOffset + kPointerSize;
8541 
8542  private:
8543  DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
8544 };
8545 
8546 
8547 class CallHandlerInfo: public Struct {
8548  public:
8549  DECL_ACCESSORS(callback, Object)
8550  DECL_ACCESSORS(data, Object)
8551 
8552  static inline CallHandlerInfo* cast(Object* obj);
8553 
8554 #ifdef OBJECT_PRINT
8555  inline void CallHandlerInfoPrint() {
8556  CallHandlerInfoPrint(stdout);
8557  }
8558  void CallHandlerInfoPrint(FILE* out);
8559 #endif
8561 
8562  static const int kCallbackOffset = HeapObject::kHeaderSize;
8563  static const int kDataOffset = kCallbackOffset + kPointerSize;
8564  static const int kSize = kDataOffset + kPointerSize;
8565 
8566  private:
8567  DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
8568 };
8569 
8570 
8571 class TemplateInfo: public Struct {
8572  public:
8573  DECL_ACCESSORS(tag, Object)
8574  DECL_ACCESSORS(property_list, Object)
8575 
8577 
8578  static const int kTagOffset = HeapObject::kHeaderSize;
8579  static const int kPropertyListOffset = kTagOffset + kPointerSize;
8580  static const int kHeaderSize = kPropertyListOffset + kPointerSize;
8581 
8582  private:
8583  DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
8584 };
8585 
8586 
8587 class FunctionTemplateInfo: public TemplateInfo {
8588  public:
8589  DECL_ACCESSORS(serial_number, Object)
8590  DECL_ACCESSORS(call_code, Object)
8592  DECL_ACCESSORS(prototype_template, Object)
8593  DECL_ACCESSORS(parent_template, Object)
8595  DECL_ACCESSORS(indexed_property_handler, Object)
8597  DECL_ACCESSORS(class_name, Object)
8598  DECL_ACCESSORS(signature, Object)
8599  DECL_ACCESSORS(instance_call_handler, Object)
8601  DECL_ACCESSORS(flag, Smi)
8602 
8603  // Following properties use flag bits.
8605  DECL_BOOLEAN_ACCESSORS(undetectable)
8606  // If the bit is set, object instances created by this function
8607  // requires access check.
8608  DECL_BOOLEAN_ACCESSORS(needs_access_check)
8610 
8611  static inline FunctionTemplateInfo* cast(Object* obj);
8612 
8613 #ifdef OBJECT_PRINT
8614  inline void FunctionTemplateInfoPrint() {
8615  FunctionTemplateInfoPrint(stdout);
8616  }
8617  void FunctionTemplateInfoPrint(FILE* out);
8618 #endif
8620 
8621  static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
8622  static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
8623  static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
8624  static const int kPrototypeTemplateOffset =
8625  kPropertyAccessorsOffset + kPointerSize;
8626  static const int kParentTemplateOffset =
8627  kPrototypeTemplateOffset + kPointerSize;
8628  static const int kNamedPropertyHandlerOffset =
8629  kParentTemplateOffset + kPointerSize;
8630  static const int kIndexedPropertyHandlerOffset =
8631  kNamedPropertyHandlerOffset + kPointerSize;
8632  static const int kInstanceTemplateOffset =
8633  kIndexedPropertyHandlerOffset + kPointerSize;
8634  static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
8635  static const int kSignatureOffset = kClassNameOffset + kPointerSize;
8636  static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
8637  static const int kAccessCheckInfoOffset =
8638  kInstanceCallHandlerOffset + kPointerSize;
8639  static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
8640  static const int kSize = kFlagOffset + kPointerSize;
8641 
8642  private:
8643  // Bit position in the flag, from least significant bit position.
8644  static const int kHiddenPrototypeBit = 0;
8645  static const int kUndetectableBit = 1;
8646  static const int kNeedsAccessCheckBit = 2;
8647  static const int kReadOnlyPrototypeBit = 3;
8648 
8649  DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
8650 };
8651 
8652 
8653 class ObjectTemplateInfo: public TemplateInfo {
8654  public:
8655  DECL_ACCESSORS(constructor, Object)
8656  DECL_ACCESSORS(internal_field_count, Object)
8657 
8658  static inline ObjectTemplateInfo* cast(Object* obj);
8659 
8660 #ifdef OBJECT_PRINT
8661  inline void ObjectTemplateInfoPrint() {
8662  ObjectTemplateInfoPrint(stdout);
8663  }
8664  void ObjectTemplateInfoPrint(FILE* out);
8665 #endif
8667 
8668  static const int kConstructorOffset = TemplateInfo::kHeaderSize;
8669  static const int kInternalFieldCountOffset =
8670  kConstructorOffset + kPointerSize;
8671  static const int kSize = kInternalFieldCountOffset + kPointerSize;
8672 };
8673 
8674 
8675 class SignatureInfo: public Struct {
8676  public:
8677  DECL_ACCESSORS(receiver, Object)
8678  DECL_ACCESSORS(args, Object)
8679 
8680  static inline SignatureInfo* cast(Object* obj);
8681 
8682 #ifdef OBJECT_PRINT
8683  inline void SignatureInfoPrint() {
8684  SignatureInfoPrint(stdout);
8685  }
8686  void SignatureInfoPrint(FILE* out);
8687 #endif
8689 
8690  static const int kReceiverOffset = Struct::kHeaderSize;
8691  static const int kArgsOffset = kReceiverOffset + kPointerSize;
8692  static const int kSize = kArgsOffset + kPointerSize;
8693 
8694  private:
8695  DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
8696 };
8697 
8698 
8699 class TypeSwitchInfo: public Struct {
8700  public:
8701  DECL_ACCESSORS(types, Object)
8702 
8703  static inline TypeSwitchInfo* cast(Object* obj);
8704 
8705 #ifdef OBJECT_PRINT
8706  inline void TypeSwitchInfoPrint() {
8707  TypeSwitchInfoPrint(stdout);
8708  }
8709  void TypeSwitchInfoPrint(FILE* out);
8710 #endif
8712 
8713  static const int kTypesOffset = Struct::kHeaderSize;
8714  static const int kSize = kTypesOffset + kPointerSize;
8715 };
8716 
8717 
8718 #ifdef ENABLE_DEBUGGER_SUPPORT
8719 // The DebugInfo class holds additional information for a function being
8720 // debugged.
8721 class DebugInfo: public Struct {
8722  public:
8723  // The shared function info for the source being debugged.
8725  // Code object for the original code.
8726  DECL_ACCESSORS(original_code, Code)
8727  // Code object for the patched code. This code object is the code object
8728  // currently active for the function.
8729  DECL_ACCESSORS(code, Code)
8730  // Fixed array holding status information for each active break point.
8731  DECL_ACCESSORS(break_points, FixedArray)
8732 
8733  // Check if there is a break point at a code position.
8734  bool HasBreakPoint(int code_position);
8735  // Get the break point info object for a code position.
8736  Object* GetBreakPointInfo(int code_position);
8737  // Clear a break point.
8738  static void ClearBreakPoint(Handle<DebugInfo> debug_info,
8739  int code_position,
8740  Handle<Object> break_point_object);
8741  // Set a break point.
8742  static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
8743  int source_position, int statement_position,
8744  Handle<Object> break_point_object);
8745  // Get the break point objects for a code position.
8746  Object* GetBreakPointObjects(int code_position);
8747  // Find the break point info holding this break point object.
8748  static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
8749  Handle<Object> break_point_object);
8750  // Get the number of break points for this function.
8751  int GetBreakPointCount();
8752 
8753  static inline DebugInfo* cast(Object* obj);
8754 
8755 #ifdef OBJECT_PRINT
8756  inline void DebugInfoPrint() {
8757  DebugInfoPrint(stdout);
8758  }
8759  void DebugInfoPrint(FILE* out);
8760 #endif
8761  DECLARE_VERIFIER(DebugInfo)
8762 
8763  static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
8764  static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
8765  static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
8766  static const int kActiveBreakPointsCountIndex =
8767  kPatchedCodeIndex + kPointerSize;
8768  static const int kBreakPointsStateIndex =
8769  kActiveBreakPointsCountIndex + kPointerSize;
8770  static const int kSize = kBreakPointsStateIndex + kPointerSize;
8771 
8772  private:
8773  static const int kNoBreakPointInfo = -1;
8774 
8775  // Lookup the index in the break_points array for a code position.
8776  int GetBreakPointInfoIndex(int code_position);
8777 
8778  DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
8779 };
8780 
8781 
8782 // The BreakPointInfo class holds information for break points set in a
8783 // function. The DebugInfo object holds a BreakPointInfo object for each code
8784 // position with one or more break points.
8785 class BreakPointInfo: public Struct {
8786  public:
8787  // The position in the code for the break point.
8788  DECL_ACCESSORS(code_position, Smi)
8789  // The position in the source for the break position.
8790  DECL_ACCESSORS(source_position, Smi)
8791  // The position in the source for the last statement before this break
8792  // position.
8793  DECL_ACCESSORS(statement_position, Smi)
8794  // List of related JavaScript break points.
8795  DECL_ACCESSORS(break_point_objects, Object)
8796 
8797  // Removes a break point.
8798  static void ClearBreakPoint(Handle<BreakPointInfo> info,
8799  Handle<Object> break_point_object);
8800  // Set a break point.
8801  static void SetBreakPoint(Handle<BreakPointInfo> info,
8802  Handle<Object> break_point_object);
8803  // Check if break point info has this break point object.
8804  static bool HasBreakPointObject(Handle<BreakPointInfo> info,
8805  Handle<Object> break_point_object);
8806  // Get the number of break points for this code position.
8807  int GetBreakPointCount();
8808 
8809  static inline BreakPointInfo* cast(Object* obj);
8810 
8811 #ifdef OBJECT_PRINT
8812  inline void BreakPointInfoPrint() {
8813  BreakPointInfoPrint(stdout);
8814  }
8815  void BreakPointInfoPrint(FILE* out);
8816 #endif
8817  DECLARE_VERIFIER(BreakPointInfo)
8818 
8819  static const int kCodePositionIndex = Struct::kHeaderSize;
8820  static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
8821  static const int kStatementPositionIndex =
8822  kSourcePositionIndex + kPointerSize;
8823  static const int kBreakPointObjectsIndex =
8824  kStatementPositionIndex + kPointerSize;
8825  static const int kSize = kBreakPointObjectsIndex + kPointerSize;
8826 
8827  private:
8828  DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
8829 };
8830 #endif // ENABLE_DEBUGGER_SUPPORT
8831 
8832 
8833 #undef DECL_BOOLEAN_ACCESSORS
8834 #undef DECL_ACCESSORS
8835 #undef DECLARE_VERIFIER
8836 
8837 #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
8838  V(kSymbolTable, "symbol_table", "(Symbols)") \
8839  V(kExternalStringsTable, "external_strings_table", "(External strings)") \
8840  V(kStrongRootList, "strong_root_list", "(Strong roots)") \
8841  V(kSymbol, "symbol", "(Symbol)") \
8842  V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
8843  V(kTop, "top", "(Isolate)") \
8844  V(kRelocatable, "relocatable", "(Relocatable)") \
8845  V(kDebug, "debug", "(Debugger)") \
8846  V(kCompilationCache, "compilationcache", "(Compilation cache)") \
8847  V(kHandleScope, "handlescope", "(Handle scope)") \
8848  V(kBuiltins, "builtins", "(Builtins)") \
8849  V(kGlobalHandles, "globalhandles", "(Global handles)") \
8850  V(kThreadManager, "threadmanager", "(Thread manager)") \
8851  V(kExtensions, "Extensions", "(Extensions)")
8852 
8854  public:
8855 #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
8856  enum SyncTag {
8858  kNumberOfSyncTags
8859  };
8860 #undef DECLARE_ENUM
8861 
8862  static const char* const kTags[kNumberOfSyncTags];
8863  static const char* const kTagNames[kNumberOfSyncTags];
8864 };
8865 
8866 // Abstract base class for visiting, and optionally modifying, the
8867 // pointers contained in Objects. Used in GC and serialization/deserialization.
8868 class ObjectVisitor BASE_EMBEDDED {
8869  public:
8870  virtual ~ObjectVisitor() {}
8871 
8872  // Visits a contiguous arrays of pointers in the half-open range
8873  // [start, end). Any or all of the values may be modified on return.
8874  virtual void VisitPointers(Object** start, Object** end) = 0;
8875 
8876  // To allow lazy clearing of inline caches the visitor has
8877  // a rich interface for iterating over Code objects..
8878 
8879  // Visits a code target in the instruction stream.
8880  virtual void VisitCodeTarget(RelocInfo* rinfo);
8881 
8882  // Visits a code entry in a JS function.
8883  virtual void VisitCodeEntry(Address entry_address);
8884 
8885  // Visits a global property cell reference in the instruction stream.
8886  virtual void VisitGlobalPropertyCell(RelocInfo* rinfo);
8887 
8888  // Visits a runtime entry in the instruction stream.
8889  virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
8890 
8891  // Visits the resource of an ASCII or two-byte string.
8895  v8::String::ExternalStringResource** resource) {}
8896 
8897  // Visits a debug call target in the instruction stream.
8898  virtual void VisitDebugTarget(RelocInfo* rinfo);
8899 
8900  // Handy shorthand for visiting a single pointer.
8901  virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
8902 
8903  // Visit pointer embedded into a code object.
8904  virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
8905 
8906  // Visits a contiguous arrays of external references (references to the C++
8907  // heap) in the half-open range [start, end). Any or all of the values
8908  // may be modified on return.
8909  virtual void VisitExternalReferences(Address* start, Address* end) {}
8910 
8911  virtual void VisitExternalReference(RelocInfo* rinfo);
8912 
8914  VisitExternalReferences(p, p + 1);
8915  }
8916 
8917  // Visits a handle that has an embedder-assigned class ID.
8918  virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
8919 
8920  // Intended for serialization/deserialization checking: insert, or
8921  // check for the presence of, a tag at this position in the stream.
8922  // Also used for marking up GC roots in heap snapshots.
8924 };
8925 
8926 
8927 class StructBodyDescriptor : public
8928  FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
8929  public:
8930  static inline int SizeOf(Map* map, HeapObject* object) {
8931  return map->instance_size();
8932  }
8933 };
8934 
8935 
8936 // BooleanBit is a helper class for setting and getting a bit in an
8937 // integer or Smi.
8938 class BooleanBit : public AllStatic {
8939  public:
8940  static inline bool get(Smi* smi, int bit_position) {
8941  return get(smi->value(), bit_position);
8942  }
8943 
8944  static inline bool get(int value, int bit_position) {
8945  return (value & (1 << bit_position)) != 0;
8946  }
8947 
8948  static inline Smi* set(Smi* smi, int bit_position, bool v) {
8949  return Smi::FromInt(set(smi->value(), bit_position, v));
8950  }
8951 
8952  static inline int set(int value, int bit_position, bool v) {
8953  if (v) {
8954  value |= (1 << bit_position);
8955  } else {
8956  value &= ~(1 << bit_position);
8957  }
8958  return value;
8959  }
8960 };
8961 
8962 } } // namespace v8::internal
8963 
8964 #endif // V8_OBJECTS_H_
Object * GetPrototype()
Definition: objects.cc:725
byte * Address
Definition: globals.h:157
MUST_USE_RESULT MaybeObject * GetElementWithReceiver(Object *receiver, uint32_t index)
Definition: objects.cc:667
static MapWord FromRawValue(uintptr_t value)
Definition: objects.h:1157
const uint32_t kShortcutTypeTag
Definition: objects.h:515
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset eval_from_instructions_offset
Definition: objects-inl.h:3892
void set_elements_kind(ElementsKind elements_kind)
Definition: objects.h:4773
virtual void VisitExternalAsciiString(v8::String::ExternalAsciiStringResource **resource)
Definition: objects.h:8892
const int kMinInt
Definition: globals.h:211
FixedArraySubInstanceType
Definition: objects.h:686
Object * KeyAt(int entry)
Definition: objects.h:2841
InstanceType type
Definition: objects.h:724
STATIC_CHECK((kStringRepresentationMask|kStringEncodingMask)==Internals::kFullStringRepresentationMask)
static const int kMaxLength
Definition: objects.h:2366
#define FOR_EACH_NUMERIC_FIELD(V)
Definition: objects.h:3519
virtual void VisitExternalTwoByteString(v8::String::ExternalStringResource **resource)
Definition: objects.h:8894
StringInputBuffer(String *backing)
Definition: objects.h:7905
bool IsExternalArrayElementsKind(ElementsKind kind)
Definition: elements-kind.h:94
static const int kSize
Definition: objects.h:7320
static uint32_t SeededHash(Key key, uint32_t seed)
Definition: objects.h:2762
bool has_external_array_elements()
Definition: objects.h:4808
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit read_only_prototype
Definition: objects-inl.h:3928
static int EntryToIndex(int entry)
Definition: objects.h:2892
const char * ToCString(const v8::String::Utf8Value &value)
FixedBodyDescriptor< kNameOffset, kThisPropertyAssignmentsOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:5899
virtual uint32_t Hash()=0
virtual void Synchronize(VisitorSynchronization::SyncTag tag)
Definition: objects.h:8923
FixedBodyDescriptor< kParentOffset, kOffsetOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:7721
bool has_non_strict_arguments_elements()
Definition: objects.h:4804
bool is_hidden_prototype()
Definition: objects.h:4725
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:6701
void SetAstId(int index, BailoutId id)
Definition: objects.h:4108
#define DECLARE_FUNCTION_ID(ignored1, ignore2, name)
Definition: objects.h:5361
void DetailsAtPut(int entry, PropertyDetails value)
Definition: objects.h:3084
const uint32_t kNotSymbolTag
Definition: objects.h:463
FixedBodyDescriptor< kToStringOffset, kToNumberOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:7974
const uint32_t kTwoByteStringTag
Definition: objects.h:469
Handle< FixedArray > AddKeysFromJSArray(Handle< FixedArray > content, Handle< JSArray > array)
Definition: handles.cc:133
const int kFailureTypeTagSize
Definition: objects.h:1081
Handle< Object > SetPropertyWithInterceptor(Handle< JSObject > object, Handle< String > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
Definition: handles.cc:268
virtual uint32_t HashForObject(Object *key)=0
const int kStubMajorKeyBits
Definition: objects.h:201
static int SizeOf(Map *map, HeapObject *object)
Definition: objects.h:2393
virtual void VisitRuntimeEntry(RelocInfo *rinfo)
Definition: objects.h:8889
static Smi * FromInt(int value)
Definition: objects-inl.h:981
bool IsFastObjectElementsKind(ElementsKind kind)
static const int kOddballKindOffset
Definition: v8.h:4079
NormalizedMapSharingMode
Definition: objects.h:161
MUST_USE_RESULT MaybeObject * ToSmi()
Definition: objects-inl.h:823
const intptr_t kCodeAlignmentMask
Definition: v8globals.h:59
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kIsTopLevelBit allows_lazy_compilation
Definition: objects-inl.h:3939
int NumberOfOwnDescriptors()
Definition: objects.h:4944
virtual void VisitPointer(Object **p)
Definition: objects.h:8901
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:6807
MUST_USE_RESULT MaybeObject * GetPropertyWithDefinedGetter(Object *receiver, JSReceiver *getter)
Definition: objects.cc:286
void VerifyApiCallResultType()
Definition: objects-inl.h:1715
static const int kFirstNonstringType
Definition: v8.h:4097
static bool IsAscii(const uc16 *chars, int length)
Definition: objects.h:7457
void set_has_named_interceptor()
Definition: objects.h:4730
bool is_the_hole(int index)
Definition: objects.h:3728
const int kSmiValueSize
Definition: v8.h:4061
const int kVariableSizeSentinel
Definition: objects.h:199
int32_t uc32
Definition: globals.h:260
Vector< const char > ToAsciiVector()
Definition: objects.h:7139
static KeyedAccessGrowMode GetKeyedAccessGrowMode(ExtraICState extra_ic_state)
Definition: objects.h:4418
#define DECL_INDEX(name)
Definition: objects.h:3541
Object * ToBoolean()
Definition: objects.cc:107
MUST_USE_RESULT MaybeObject * GetPropertyWithReceiver(Object *receiver, String *key, PropertyAttributes *attributes)
Definition: objects.cc:154
bool has_fast_object_elements()
Definition: objects.h:4792
const uint32_t kMaxAsciiCharCodeU
Definition: globals.h:264
int int32_t
Definition: unicode.cc:47
bool SameValue(Object *other)
Definition: objects.cc:780
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit is_toplevel
Definition: objects-inl.h:3932
const int kMaxInt
Definition: globals.h:210
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:3023
MUST_USE_RESULT MaybeObject * ToObject()
Definition: objects.cc:85
const int kSignMask
bool has_fast_double_elements()
Definition: objects.h:4800
static Smi * FromIntptr(intptr_t value)
Definition: objects-inl.h:990
void SetEnumLength(int length)
Definition: objects.h:4959
Handle< FixedArray > UnionOfKeys(Handle< FixedArray > first, Handle< FixedArray > second)
Definition: handles.cc:140
virtual void PostGarbageCollection()
Definition: objects.h:7859
#define ASSERT(condition)
Definition: checks.h:270
v8::Handle< v8::Value > Print(const v8::Arguments &args)
static int NonAsciiStart(const uc16 *chars, int length)
Definition: objects.h:7447
unsigned short uint16_t
Definition: unicode.cc:46
#define OBJECT_TYPE_LIST(V)
Definition: objects.h:790
#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V)
Definition: objects.h:8837
VectorIterator(Vector< const T > data)
Definition: objects.h:7925
static Dictionary< Shape, Key > * cast(Object *obj)
Definition: objects.h:3062
const intptr_t kCodeAlignment
Definition: v8globals.h:58
kPropertyAccessorsOffset kNamedPropertyHandlerOffset instance_template
Definition: objects-inl.h:3860
#define POINTER_SIZE_ALIGN(value)
Definition: v8globals.h:387
#define IS_TYPE_FUNCTION_DECL(type_)
Definition: objects.h:884
const uint32_t kStringRepresentationMask
Definition: objects.h:474
bool NonFailureIsHeapObject()
Definition: objects-inl.h:166
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:3026
#define CHECK(condition)
Definition: checks.h:56
const int kExternalArrayTypeCount
Definition: objects.h:666
void set_is_undetectable()
Definition: objects.h:4753
Handle< Object > GetPropertyWithInterceptor(Handle< JSObject > receiver, Handle< JSObject > holder, Handle< String > name, PropertyAttributes *attributes)
Definition: handles.cc:298
static const int kStringResourceOffset
Definition: v8.h:4077
#define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name)
Definition: objects.h:687
bool HasSpecificClassOf(String *name)
Definition: objects-inl.h:836
StringInputBuffer *const buffer_
v8::String::ExternalStringResource Resource
Definition: objects.h:7811
#define DEFINE_ELEMENT_ACCESSORS(name, type)
Definition: objects.h:4029
uint32_t Hash(Key key)
Definition: objects.h:2782
static const int kJSObjectHeaderSize
Definition: v8.h:4081
PropertyAttributes
const uint32_t kAsciiDataHintTag
Definition: objects.h:498
static uint32_t Hash(HashTableKey *key)
Definition: objects.h:2965
const uint32_t kShortExternalStringMask
Definition: objects.h:502
int ToInt() const
Definition: utils.h:1012
static Object ** RawField(HeapObject *obj, int offset)
Definition: objects-inl.h:971
const int kIntSize
Definition: globals.h:217
static Smi * cast(Object *object)
unsigned int seed
Definition: test-strings.cc:18
Handle< String > SubString(Handle< String > str, int start, int end, PretenureFlag pretenure)
Definition: handles.cc:326
static const int kHeaderSize
Definition: objects.h:1262
void Lookup(String *name, LookupResult *result)
Definition: objects.cc:132
static bool IsAscii(const char *chars, int length)
Definition: objects.h:7443
static const int kSize
Definition: objects.h:8333
bool has_instance_call_handler()
Definition: objects.h:4766
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kIsTopLevelBit kAllowLazyCompilation kUsesArguments kFormalParameterCountOffset kStartPositionAndTypeOffset kCompilerHintsOffset stress_deopt_counter
Definition: objects-inl.h:4030
void set_has_instance_call_handler()
Definition: objects.h:4762
bool has_slow_elements_kind()
Definition: objects.h:4816
uint8_t byte
Definition: globals.h:156
virtual MUST_USE_RESULT MaybeObject * AsObject()=0
static int set(int value, int bit_position, bool v)
Definition: objects.h:8952
Object * ValueAt(int entry)
Definition: objects.h:3067
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kIsTopLevelBit compiler_hints
Definition: objects-inl.h:3939
void SetAstId(int i, BailoutId value)
Definition: objects.h:4065
static const int kHeaderSize
Definition: objects.h:1010
const uint32_t kNotStringTag
Definition: objects.h:457
void CopyEnumCacheFrom(DescriptorArray *array)
Definition: objects.h:2524
void SetPcAndState(int index, Smi *offset)
Definition: objects.h:4113
Object * GetElementNoExceptionThrown(uint32_t index)
Definition: objects-inl.h:850
static int SizeOf(Map *map, HeapObject *object)
Definition: objects.h:8930
virtual void IterateInstance(ObjectVisitor *v)
Definition: objects.h:7858
static int LengthFor(int size_in_bytes)
Definition: objects.h:3642
STATIC_ASSERT((FixedDoubleArray::kHeaderSize &kDoubleAlignmentMask)==0)
static SeededNumberDictionary * cast(Object *obj)
Definition: objects.h:3236
bool has_fast_smi_elements()
Definition: objects.h:4787
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:2962
const uint32_t kIsSymbolMask
Definition: objects.h:462
void set_unchecked(int index, Smi *value)
Definition: objects-inl.h:1910
bool IsStringObjectWithCharacterAt(uint32_t index)
Definition: objects-inl.h:1701
#define MUST_USE_RESULT
Definition: globals.h:346
const int kDoubleSize
Definition: globals.h:218
#define DECLARE_ENUM(enum_item, ignore1, ignore2)
Definition: objects.h:8855
void SetNumberOfProtoTransitions(int value)
Definition: objects.h:4915
void SetNumberOfElements(int nof)
Definition: objects.h:2897
static const int kMapInstanceTypeOffset
Definition: v8.h:4076
int LinearSearch(T *array, String *name, int len, int valid_entries)
Definition: objects-inl.h:1993
static MUST_USE_RESULT MaybeObject * AsObject(HashTableKey *key)
Definition: objects.h:6815
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1059
const uint32_t kIsIndirectStringMask
Definition: objects.h:481
static const int kMinValue
Definition: objects.h:1048
bool ToArrayIndex(uint32_t *index)
Definition: objects-inl.h:1682
bool is_store_stub()
Definition: objects.h:4299
static StrictModeFlag GetStrictMode(ExtraICState extra_ic_state)
Definition: objects.h:4414
const int kPointerSize
Definition: globals.h:220
#define DECLARE_VERIFIER(Name)
Definition: objects.h:737
Handle< Object > SetProperty(Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
Definition: handles.cc:232
uint32_t HashForObject(Key key, Object *object)
Definition: objects.h:2791
FixedBodyDescriptor< kPointerFieldsBeginOffset, kPointerFieldsEndOffset, kSize > BodyDescriptor
Definition: objects.h:5201
static UnseededNumberDictionary * cast(Object *obj)
Definition: objects.h:3284
bool IsAligned(T value, U alignment)
Definition: utils.h:206
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition: globals.h:318
const uint32_t kAsciiDataHintMask
Definition: objects.h:497
const uintptr_t kUintptrAllBitsSet
Definition: globals.h:234
INLINE(static uint32_t GetProbeOffset(uint32_t n))
Definition: objects.h:2857
static ExtraICState ComputeExtraICState(KeyedAccessGrowMode grow_mode, StrictModeFlag strict_mode)
Definition: objects.h:4423
void SetCapacity(int capacity)
Definition: objects.h:2907
const uint32_t kShortcutTypeMask
Definition: objects.h:511
const Register pc
Vector< const uc16 > ToUC16Vector()
Definition: objects.h:7145
static void IterateBody(HeapObject *obj, int object_size)
Definition: objects.h:1311
kPropertyAccessorsOffset named_property_handler
Definition: objects-inl.h:3856
T RoundUp(T x, intptr_t m)
Definition: utils.h:150
bool is_unary_op_stub()
Definition: objects.h:4303
bool IsFastSmiElementsKind(ElementsKind kind)
static int OffsetOfElementAt(int index)
Definition: objects.h:2439
#define FIELD_ACCESSORS(name)
Definition: objects.h:3525
const uint32_t kShortExternalStringTag
Definition: objects.h:503
void SetNumberOfOwnDescriptors(int number)
Definition: objects.h:4948
FixedArray * GetEnumIndicesCache()
Definition: objects.h:2542
static const int kOddballType
Definition: v8.h:4098
const int kBitsPerByte
Definition: globals.h:237
StringRepresentationTag
Definition: objects.h:475
static int SizeFor(int length)
Definition: objects.h:2434
bool IsPowerOf2(T x)
Definition: utils.h:50
#define DEFINE_CODE_KIND_ENUM(name)
Definition: objects.h:4204
void SetNumberOfDeletedElements(int nod)
Definition: objects.h:2902
const uint32_t kStringTag
Definition: objects.h:456
bool is_call_stub()
Definition: objects.h:4301
#define BASE_EMBEDDED
Definition: allocation.h:68
Object * ToObjectUnchecked()
Definition: objects.h:756
void set_has_indexed_interceptor()
Definition: objects.h:4739
const int kBitsPerInt
Definition: globals.h:240
SafeStringInputBuffer(String **backing)
Definition: objects.h:7916
Definition: v8.h:598
bool is_binary_op_stub()
Definition: objects.h:4304
VectorIterator(T *d, int l)
Definition: objects.h:7924
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kIsTopLevelBit kAllowLazyCompilation kUsesArguments formal_parameter_count
Definition: objects-inl.h:4003
static int OffsetOfElementAt(int index)
Definition: objects.h:2356
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:2968
static int SizeFor(int length)
Definition: objects.h:2353
#define T(name, string, precedence)
Definition: token.cc:48
bool IsFastSmiOrObjectElementsKind(ElementsKind kind)
void SetNextEnumerationIndex(int index)
Definition: objects.h:3113
static uint32_t SeededHashForObject(Key key, uint32_t seed, Object *object)
Definition: objects.h:2767
const int kElementsKindCount
Definition: elements-kind.h:76
static const int kHeaderSize
Definition: objects.h:2296
PropertyNormalizationMode
Definition: objects.h:153
bool IsKey(Object *k)
Definition: objects.h:2845
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit start_position_and_type
Definition: objects-inl.h:3932
SimpleTransitionFlag
Definition: objects.h:184
static int SizeFor(int length)
Definition: objects.h:3635
bool has_named_interceptor()
Definition: objects.h:4734
#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)
Definition: objects.h:675
const uint32_t kIsNotStringMask
Definition: objects.h:455
static StringDictionary * cast(Object *obj)
Definition: objects.h:3182
const uint32_t kSlicedNotConsMask
Definition: objects.h:492
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:6811
bool is_compare_ic_stub()
Definition: objects.h:4305
static uint32_t HashForObject(Key key, Object *object)
Definition: objects.h:2766
static ObjectHashTable * cast(Object *obj)
Definition: objects.h:3340
FixedBodyDescriptor< kFirstOffset, kSecondOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:7669
static const int kHeapObjectMapOffset
Definition: v8.h:4075
const int kStubMinorKeyBits
Definition: objects.h:202
#define STRUCT_LIST(V)
Definition: objects.h:448
#define CODE_KIND_LIST(V)
Definition: objects.h:4187
static int SizeFor(int length)
Definition: objects.h:7548
#define OBJECT_POINTER_ALIGN(value)
Definition: v8globals.h:383
#define IS_POWER_OF_TWO(x)
Definition: utils.h:45
Object * ToObjectChecked()
Definition: objects.h:760
bool has_fast_smi_or_object_elements()
Definition: objects.h:4796
static JSGlobalPropertyCell * FromValueAddress(Address value)
Definition: objects.h:7993
INLINE(static HeapObject *EnsureDoubleAligned(Heap *heap, HeapObject *object, int size))
static Vector< T > cast(Vector< S > input)
Definition: utils.h:445
static Object * cast(Object *value)
Definition: objects.h:1007
name_should_print_as_anonymous
Definition: objects-inl.h:4115
bool has_indexed_interceptor()
Definition: objects.h:4743
FixedBodyDescriptor< kValueOffset, kValueOffset+kPointerSize, kSize > BodyDescriptor
Definition: objects.h:8016
uint16_t uc16
Definition: globals.h:259
int ExecutableSize()
Definition: objects.h:4494
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:6697
v8::String::ExternalAsciiStringResource Resource
Definition: objects.h:7766
PropertyDetails DetailsAt(int entry)
Definition: objects.h:3077
static int SizeFor(int length)
Definition: objects.h:7600
const int kSmiTagSize
Definition: v8.h:4015
static const int kHeaderSize
Definition: objects.h:4549
uint32_t HashSequentialString(const schar *chars, int length, uint32_t seed)
Definition: objects-inl.h:5013
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset hidden_prototype
Definition: objects-inl.h:3923
void ValueAtPut(int entry, Object *value)
Definition: objects.h:3072
bool is_undetectable()
Definition: objects.h:4757
bool is_keyed_store_stub()
Definition: objects.h:4300
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:6705
int Search(T *array, String *name, int valid_entries)
Definition: objects-inl.h:2016
MUST_USE_RESULT MaybeObject * GetProperty(String *key)
Definition: objects-inl.h:859
#define ASSERT_EQ(v1, v2)
Definition: checks.h:271
static MUST_USE_RESULT MaybeObject * AsObject(HashTableKey *key)
Definition: objects.h:2971
const int kShortSize
Definition: globals.h:216
static bool IsMatch(HashTableKey *key, Object *value)
Definition: objects.h:6803
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset instance_class_name
Definition: objects-inl.h:3912
Failure * ToFailureUnchecked()
Definition: objects.h:752
static const int kElementsKindShift
Definition: objects.h:5181
bool is_to_boolean_ic_stub()
Definition: objects.h:4306
static void IterateBody(HeapObject *obj)
Definition: objects.h:1291
static MUST_USE_RESULT MaybeObject * AsObject(HashTableKey *key)
Definition: objects.h:6709
static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size)
Definition: objects.h:2927
#define DECL_ACCESSORS(name, type)
Definition: objects.h:708
virtual bool IsMatch(Object *other)=0
static FixedArray * cast(Object *obj)
static const int kUndefinedOddballKind
Definition: v8.h:4101
#define HEAP_OBJECT_TYPE_LIST(V)
Definition: objects.h:795
static const int kHeaderSize
Definition: objects.h:2173
static Smi * set(Smi *smi, int bit_position, bool v)
Definition: objects.h:8948
bool ToObject(Object **obj)
Definition: objects.h:747
ElementsKind elements_kind()
Definition: objects.h:4781
static int LengthOfFixedArray(int cell_count)
Definition: objects.h:4143
static Handle< Object > GetElement(Handle< Object > object, uint32_t index)
Definition: objects.cc:250
FixedArray * GetEnumCache()
Definition: objects.h:2528
const uint32_t kIsIndirectStringTag
Definition: objects.h:482
virtual void VisitEmbedderReference(Object **p, uint16_t class_id)
Definition: objects.h:8918
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Definition: flags.cc:301
Object * get(int index)
Definition: objects-inl.h:1737
static const int kPrototypeOffset
Definition: objects.h:5126
bool IsInstanceOf(FunctionTemplateInfo *type)
Definition: objects-inl.h:137
static uint32_t HashForObject(HashTableKey *key, Object *object)
Definition: objects.h:3030
static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size)
Definition: objects.h:2918
void set(AccessorComponent component, Object *value)
Definition: objects.h:8445
static int LengthOfFixedArray(int deopt_points)
Definition: objects.h:4115
static uint32_t Hash(Key key)
Definition: objects.h:2761
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static int SizeFor(int body_size)
Definition: objects.h:4487
static int LengthFor(int number_of_descriptors)
Definition: objects.h:2669
const uint32_t kSymbolTag
Definition: objects.h:464
const int kFailureTypeTagMask
Definition: objects.h:1082
Definition: objects.h:6953
bool is_keyed_call_stub()
Definition: objects.h:4302
Handle< Object > SetPrototype(Handle< JSFunction > function, Handle< Object > prototype)
Definition: handles.cc:221
static const int kForeignType
Definition: v8.h:4099
const uint32_t kAsciiStringTag
Definition: objects.h:470
virtual void VisitExternalReferences(Address *start, Address *end)
Definition: objects.h:8909
signed short int16_t
Definition: unicode.cc:45
#define FUNCTIONS_WITH_ID_LIST(V)
Definition: objects.h:5334
MUST_USE_RESULT MaybeObject * GetHash(CreationFlag flag)
Definition: objects.cc:756
static uint32_t FirstProbe(uint32_t hash, uint32_t size)
Definition: objects.h:2923
KeyedAccessGrowMode
Definition: objects.h:142
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including flags
Definition: flags.cc:495
static int NewElementsCapacity(int old_capacity)
Definition: objects.h:1806
#define DEFINE_ENTRY_ACCESSORS(name, type)
Definition: objects.h:4046
unsigned char byte
Definition: unicode.h:41
ReadBlockBuffer(unibrow::byte *util_buffer_, unsigned cursor_, unsigned capacity_, unsigned remaining_)
Definition: objects.h:7464
static const int kMaxValue
Definition: objects.h:1050
bool has_dictionary_elements()
Definition: objects.h:4812
const uc32 kMaxAsciiCharCode
Definition: globals.h:263
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset kHiddenPrototypeBit kReadOnlyPrototypeBit kIsTopLevelBit kAllowLazyCompilation uses_arguments
Definition: objects-inl.h:3947
static const int kNullOddballKind
Definition: v8.h:4102
INLINE(bool IsSpecObject())
const int kCharSize
Definition: globals.h:215
static int saved_code_index(bool is_ascii)
Definition: objects.h:6611
#define ASSERT_SIZE_TAG_ALIGNED(size)
Definition: v8checks.h:62
void ElementsRemoved(int n)
Definition: objects.h:2825
static ObjectHashSet * cast(Object *obj)
Definition: objects.h:3320
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset access_check_info
Definition: objects-inl.h:3866
bool IsDictionaryElementsKind(ElementsKind kind)
Definition: elements-kind.h:89
static int OffsetOfCodeWithId(Builtins::JavaScript id)
Definition: objects.h:6357
const char * str
Definition: objects.h:726
void VisitExternalReference(Address *p)
Definition: objects.h:8913
bool IsFastDoubleElementsKind(ElementsKind kind)
bool is_keyed_load_stub()
Definition: objects.h:4298
const uint32_t kStringEncodingMask
Definition: objects.h:468
static MUST_USE_RESULT MaybeObject * AsObject(HashTableKey *key)
Definition: objects.h:3034
static const int kJSObjectType
Definition: v8.h:4096
void SetComponents(Object *getter, Object *setter)
Definition: objects.h:8457
#define DECLARE_STRUCT_PREDICATE(NAME, Name, name)
Definition: objects.h:896
void set_is_hidden_prototype()
Definition: objects.h:4721
#define DECL_BOOLEAN_ACCESSORS(name)
Definition: objects.h:703
Handle< JSObject > Copy(Handle< JSObject > obj)
Definition: handles.cc:335
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset flag
Definition: objects-inl.h:3923
const int MB
Definition: globals.h:208
Object * GetPropertyNoExceptionThrown(String *key)
Definition: objects.h:6268