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