OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "allocation.h" | 8 #include "allocation.h" |
9 #include "assert-scope.h" | 9 #include "assert-scope.h" |
10 #include "builtins.h" | 10 #include "builtins.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "mips/constants-mips.h" | 22 #include "mips/constants-mips.h" |
23 #endif | 23 #endif |
24 #include "v8checks.h" | 24 #include "v8checks.h" |
25 #include "zone.h" | 25 #include "zone.h" |
26 | 26 |
27 | 27 |
28 // | 28 // |
29 // Most object types in the V8 JavaScript are described in this file. | 29 // Most object types in the V8 JavaScript are described in this file. |
30 // | 30 // |
31 // Inheritance hierarchy: | 31 // Inheritance hierarchy: |
32 // - MaybeObject (an object or a failure) | 32 // - Object |
33 // - Failure (immediate for marking failed operation) | 33 // - Smi (immediate small integer) |
34 // - Object | 34 // - HeapObject (superclass for everything allocated in the heap) |
35 // - Smi (immediate small integer) | 35 // - JSReceiver (suitable for property access) |
36 // - HeapObject (superclass for everything allocated in the heap) | 36 // - JSObject |
37 // - JSReceiver (suitable for property access) | 37 // - JSArray |
38 // - JSObject | 38 // - JSArrayBuffer |
39 // - JSArray | 39 // - JSArrayBufferView |
40 // - JSArrayBuffer | 40 // - JSTypedArray |
41 // - JSArrayBufferView | 41 // - JSDataView |
42 // - JSTypedArray | 42 // - JSSet |
43 // - JSDataView | 43 // - JSMap |
44 // - JSSet | 44 // - JSSetIterator |
45 // - JSMap | 45 // - JSMapIterator |
46 // - JSSetIterator | 46 // - JSWeakCollection |
47 // - JSMapIterator | 47 // - JSWeakMap |
48 // - JSWeakCollection | 48 // - JSWeakSet |
49 // - JSWeakMap | 49 // - JSRegExp |
50 // - JSWeakSet | 50 // - JSFunction |
51 // - JSRegExp | 51 // - JSGeneratorObject |
52 // - JSFunction | 52 // - JSModule |
53 // - JSGeneratorObject | 53 // - GlobalObject |
54 // - JSModule | 54 // - JSGlobalObject |
55 // - GlobalObject | 55 // - JSBuiltinsObject |
56 // - JSGlobalObject | 56 // - JSGlobalProxy |
57 // - JSBuiltinsObject | 57 // - JSValue |
58 // - JSGlobalProxy | 58 // - JSDate |
59 // - JSValue | 59 // - JSMessageObject |
60 // - JSDate | 60 // - JSProxy |
61 // - JSMessageObject | 61 // - JSFunctionProxy |
62 // - JSProxy | 62 // - FixedArrayBase |
63 // - JSFunctionProxy | 63 // - ByteArray |
64 // - FixedArrayBase | 64 // - FixedArray |
65 // - ByteArray | 65 // - DescriptorArray |
66 // - FixedArray | 66 // - HashTable |
67 // - DescriptorArray | 67 // - Dictionary |
68 // - HashTable | 68 // - StringTable |
69 // - Dictionary | 69 // - CompilationCacheTable |
70 // - StringTable | 70 // - CodeCacheHashTable |
71 // - CompilationCacheTable | 71 // - MapCache |
72 // - CodeCacheHashTable | 72 // - OrderedHashTable |
73 // - MapCache | 73 // - OrderedHashSet |
74 // - OrderedHashTable | 74 // - OrderedHashMap |
75 // - OrderedHashSet | 75 // - Context |
76 // - OrderedHashMap | 76 // - JSFunctionResultCache |
77 // - Context | 77 // - ScopeInfo |
78 // - JSFunctionResultCache | 78 // - TransitionArray |
79 // - ScopeInfo | 79 // - FixedDoubleArray |
80 // - TransitionArray | 80 // - ExternalArray |
81 // - FixedDoubleArray | 81 // - ExternalUint8ClampedArray |
82 // - ExternalArray | 82 // - ExternalInt8Array |
83 // - ExternalUint8ClampedArray | 83 // - ExternalUint8Array |
84 // - ExternalInt8Array | 84 // - ExternalInt16Array |
85 // - ExternalUint8Array | 85 // - ExternalUint16Array |
86 // - ExternalInt16Array | 86 // - ExternalInt32Array |
87 // - ExternalUint16Array | 87 // - ExternalUint32Array |
88 // - ExternalInt32Array | 88 // - ExternalFloat32Array |
89 // - ExternalUint32Array | 89 // - Name |
90 // - ExternalFloat32Array | 90 // - String |
91 // - Name | 91 // - SeqString |
92 // - String | 92 // - SeqOneByteString |
93 // - SeqString | 93 // - SeqTwoByteString |
94 // - SeqOneByteString | 94 // - SlicedString |
95 // - SeqTwoByteString | 95 // - ConsString |
96 // - SlicedString | 96 // - ExternalString |
97 // - ConsString | 97 // - ExternalAsciiString |
98 // - ExternalString | 98 // - ExternalTwoByteString |
99 // - ExternalAsciiString | 99 // - InternalizedString |
100 // - ExternalTwoByteString | 100 // - SeqInternalizedString |
101 // - InternalizedString | 101 // - SeqOneByteInternalizedString |
102 // - SeqInternalizedString | 102 // - SeqTwoByteInternalizedString |
103 // - SeqOneByteInternalizedString | 103 // - ConsInternalizedString |
104 // - SeqTwoByteInternalizedString | 104 // - ExternalInternalizedString |
105 // - ConsInternalizedString | 105 // - ExternalAsciiInternalizedString |
106 // - ExternalInternalizedString | 106 // - ExternalTwoByteInternalizedString |
107 // - ExternalAsciiInternalizedString | 107 // - Symbol |
108 // - ExternalTwoByteInternalizedString | 108 // - HeapNumber |
109 // - Symbol | 109 // - Cell |
110 // - HeapNumber | 110 // - PropertyCell |
111 // - Cell | 111 // - Code |
112 // - PropertyCell | 112 // - Map |
113 // - Code | 113 // - Oddball |
114 // - Map | 114 // - Foreign |
115 // - Oddball | 115 // - SharedFunctionInfo |
116 // - Foreign | 116 // - Struct |
117 // - SharedFunctionInfo | 117 // - Box |
118 // - Struct | 118 // - DeclaredAccessorDescriptor |
119 // - Box | 119 // - AccessorInfo |
120 // - DeclaredAccessorDescriptor | 120 // - DeclaredAccessorInfo |
121 // - AccessorInfo | 121 // - ExecutableAccessorInfo |
122 // - DeclaredAccessorInfo | 122 // - AccessorPair |
123 // - ExecutableAccessorInfo | 123 // - AccessCheckInfo |
124 // - AccessorPair | 124 // - InterceptorInfo |
125 // - AccessCheckInfo | 125 // - CallHandlerInfo |
126 // - InterceptorInfo | 126 // - TemplateInfo |
127 // - CallHandlerInfo | 127 // - FunctionTemplateInfo |
128 // - TemplateInfo | 128 // - ObjectTemplateInfo |
129 // - FunctionTemplateInfo | 129 // - Script |
130 // - ObjectTemplateInfo | 130 // - SignatureInfo |
131 // - Script | 131 // - TypeSwitchInfo |
132 // - SignatureInfo | 132 // - DebugInfo |
133 // - TypeSwitchInfo | 133 // - BreakPointInfo |
134 // - DebugInfo | 134 // - CodeCache |
135 // - BreakPointInfo | |
136 // - CodeCache | |
137 // | 135 // |
138 // Formats of Object*: | 136 // Formats of Object*: |
139 // Smi: [31 bit signed int] 0 | 137 // Smi: [31 bit signed int] 0 |
140 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 | 138 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
141 // Failure: [30 bit signed int] 11 | |
142 | 139 |
143 namespace v8 { | 140 namespace v8 { |
144 namespace internal { | 141 namespace internal { |
145 | 142 |
146 enum KeyedAccessStoreMode { | 143 enum KeyedAccessStoreMode { |
147 STANDARD_STORE, | 144 STANDARD_STORE, |
148 STORE_TRANSITION_SMI_TO_OBJECT, | 145 STORE_TRANSITION_SMI_TO_OBJECT, |
149 STORE_TRANSITION_SMI_TO_DOUBLE, | 146 STORE_TRANSITION_SMI_TO_DOUBLE, |
150 STORE_TRANSITION_DOUBLE_TO_OBJECT, | 147 STORE_TRANSITION_DOUBLE_TO_OBJECT, |
151 STORE_TRANSITION_HOLEY_SMI_TO_OBJECT, | 148 STORE_TRANSITION_HOLEY_SMI_TO_OBJECT, |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 inline type* name(); \ | 851 inline type* name(); \ |
855 inline void set_##name(type* value, \ | 852 inline void set_##name(type* value, \ |
856 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ | 853 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
857 | 854 |
858 class AccessorPair; | 855 class AccessorPair; |
859 class AllocationSite; | 856 class AllocationSite; |
860 class AllocationSiteCreationContext; | 857 class AllocationSiteCreationContext; |
861 class AllocationSiteUsageContext; | 858 class AllocationSiteUsageContext; |
862 class DictionaryElementsAccessor; | 859 class DictionaryElementsAccessor; |
863 class ElementsAccessor; | 860 class ElementsAccessor; |
864 class Failure; | |
865 class FixedArrayBase; | 861 class FixedArrayBase; |
866 class GlobalObject; | 862 class GlobalObject; |
867 class ObjectVisitor; | 863 class ObjectVisitor; |
868 class StringStream; | 864 class StringStream; |
869 // We cannot just say "class HeapType;" if it is created from a template... =8-? | 865 // We cannot just say "class HeapType;" if it is created from a template... =8-? |
870 template<class> class TypeImpl; | 866 template<class> class TypeImpl; |
871 struct HeapTypeConfig; | 867 struct HeapTypeConfig; |
872 typedef TypeImpl<HeapTypeConfig> HeapType; | 868 typedef TypeImpl<HeapTypeConfig> HeapType; |
873 | 869 |
874 | 870 |
875 // A template-ized version of the IsXXX functions. | 871 // A template-ized version of the IsXXX functions. |
876 template <class C> inline bool Is(Object* obj); | 872 template <class C> inline bool Is(Object* obj); |
877 | 873 |
878 #ifdef VERIFY_HEAP | 874 #ifdef VERIFY_HEAP |
879 #define DECLARE_VERIFIER(Name) void Name##Verify(); | 875 #define DECLARE_VERIFIER(Name) void Name##Verify(); |
880 #else | 876 #else |
881 #define DECLARE_VERIFIER(Name) | 877 #define DECLARE_VERIFIER(Name) |
882 #endif | 878 #endif |
883 | 879 |
884 #ifdef OBJECT_PRINT | 880 #ifdef OBJECT_PRINT |
885 #define DECLARE_PRINTER(Name) void Name##Print(FILE* out = stdout); | 881 #define DECLARE_PRINTER(Name) void Name##Print(FILE* out = stdout); |
886 #else | 882 #else |
887 #define DECLARE_PRINTER(Name) | 883 #define DECLARE_PRINTER(Name) |
888 #endif | 884 #endif |
889 | 885 |
890 class MaybeObject BASE_EMBEDDED { | |
891 public: | |
892 inline bool IsFailure(); | |
893 inline bool IsRetryAfterGC(); | |
894 inline bool ToObject(Object** obj) { | |
895 if (IsFailure()) return false; | |
896 *obj = reinterpret_cast<Object*>(this); | |
897 return true; | |
898 } | |
899 inline Object* ToObjectUnchecked() { | |
900 // TODO(jkummerow): Turn this back into an ASSERT when we can be certain | |
901 // that it never fires in Release mode in the wild. | |
902 CHECK(!IsFailure()); | |
903 return reinterpret_cast<Object*>(this); | |
904 } | |
905 inline Object* ToObjectChecked() { | |
906 CHECK(!IsFailure()); | |
907 return reinterpret_cast<Object*>(this); | |
908 } | |
909 | |
910 template<typename T> | |
911 inline bool To(T** obj) { | |
912 if (IsFailure()) return false; | |
913 *obj = T::cast(reinterpret_cast<Object*>(this)); | |
914 return true; | |
915 } | |
916 | |
917 #ifdef OBJECT_PRINT | |
918 // Prints this object with details. | |
919 void Print(); | |
920 void Print(FILE* out); | |
921 void PrintLn(); | |
922 void PrintLn(FILE* out); | |
923 #endif | |
924 #ifdef VERIFY_HEAP | |
925 // Verifies the object. | |
926 void Verify(); | |
927 #endif | |
928 }; | |
929 | |
930 | 886 |
931 #define OBJECT_TYPE_LIST(V) \ | 887 #define OBJECT_TYPE_LIST(V) \ |
932 V(Smi) \ | 888 V(Smi) \ |
933 V(HeapObject) \ | 889 V(HeapObject) \ |
934 V(Number) \ | 890 V(Number) \ |
935 | 891 |
936 #define HEAP_OBJECT_TYPE_LIST(V) \ | 892 #define HEAP_OBJECT_TYPE_LIST(V) \ |
937 V(HeapNumber) \ | 893 V(HeapNumber) \ |
938 V(Name) \ | 894 V(Name) \ |
939 V(UniqueName) \ | 895 V(UniqueName) \ |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 #undef ERROR_MESSAGES_CONSTANTS | 1332 #undef ERROR_MESSAGES_CONSTANTS |
1377 | 1333 |
1378 | 1334 |
1379 const char* GetBailoutReason(BailoutReason reason); | 1335 const char* GetBailoutReason(BailoutReason reason); |
1380 | 1336 |
1381 | 1337 |
1382 // Object is the abstract superclass for all classes in the | 1338 // Object is the abstract superclass for all classes in the |
1383 // object hierarchy. | 1339 // object hierarchy. |
1384 // Object does not use any virtual functions to avoid the | 1340 // Object does not use any virtual functions to avoid the |
1385 // allocation of the C++ vtable. | 1341 // allocation of the C++ vtable. |
1386 // Since Smi and Failure are subclasses of Object no | 1342 // Since both Smi and HeapObject are subclasses of Object no |
1387 // data members can be present in Object. | 1343 // data members can be present in Object. |
1388 class Object : public MaybeObject { | 1344 class Object { |
1389 public: | 1345 public: |
1390 // Type testing. | 1346 // Type testing. |
1391 bool IsObject() { return true; } | 1347 bool IsObject() { return true; } |
1392 | 1348 |
1393 #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); | 1349 #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
1394 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) | 1350 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
1395 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) | 1351 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
1396 #undef IS_TYPE_FUNCTION_DECL | 1352 #undef IS_TYPE_FUNCTION_DECL |
1397 | 1353 |
1398 inline bool IsFixedArrayBase(); | 1354 inline bool IsFixedArrayBase(); |
(...skipping 12 matching lines...) Expand all Loading... |
1411 | 1367 |
1412 // Oddball testing. | 1368 // Oddball testing. |
1413 INLINE(bool IsUndefined()); | 1369 INLINE(bool IsUndefined()); |
1414 INLINE(bool IsNull()); | 1370 INLINE(bool IsNull()); |
1415 INLINE(bool IsTheHole()); | 1371 INLINE(bool IsTheHole()); |
1416 INLINE(bool IsException()); | 1372 INLINE(bool IsException()); |
1417 INLINE(bool IsUninitialized()); | 1373 INLINE(bool IsUninitialized()); |
1418 INLINE(bool IsTrue()); | 1374 INLINE(bool IsTrue()); |
1419 INLINE(bool IsFalse()); | 1375 INLINE(bool IsFalse()); |
1420 inline bool IsArgumentsMarker(); | 1376 inline bool IsArgumentsMarker(); |
1421 inline bool NonFailureIsHeapObject(); | |
1422 | 1377 |
1423 // Filler objects (fillers and free space objects). | 1378 // Filler objects (fillers and free space objects). |
1424 inline bool IsFiller(); | 1379 inline bool IsFiller(); |
1425 | 1380 |
1426 // Extract the number. | 1381 // Extract the number. |
1427 inline double Number(); | 1382 inline double Number(); |
1428 inline bool IsNaN(); | 1383 inline bool IsNaN(); |
1429 bool ToInt32(int32_t* value); | 1384 bool ToInt32(int32_t* value); |
1430 bool ToUint32(uint32_t* value); | 1385 bool ToUint32(uint32_t* value); |
1431 | 1386 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 | 1531 |
1577 // Prints this object without details to a message accumulator. | 1532 // Prints this object without details to a message accumulator. |
1578 void ShortPrint(StringStream* accumulator); | 1533 void ShortPrint(StringStream* accumulator); |
1579 | 1534 |
1580 // Casting: This cast is only needed to satisfy macros in objects-inl.h. | 1535 // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
1581 static Object* cast(Object* value) { return value; } | 1536 static Object* cast(Object* value) { return value; } |
1582 | 1537 |
1583 // Layout description. | 1538 // Layout description. |
1584 static const int kHeaderSize = 0; // Object does not take up any space. | 1539 static const int kHeaderSize = 0; // Object does not take up any space. |
1585 | 1540 |
| 1541 #ifdef OBJECT_PRINT |
| 1542 // Prints this object with details. |
| 1543 void Print(); |
| 1544 void Print(FILE* out); |
| 1545 void PrintLn(); |
| 1546 void PrintLn(FILE* out); |
| 1547 #endif |
| 1548 |
1586 private: | 1549 private: |
1587 DISALLOW_IMPLICIT_CONSTRUCTORS(Object); | 1550 DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
1588 }; | 1551 }; |
1589 | 1552 |
1590 | 1553 |
1591 // Smi represents integer Numbers that can be stored in 31 bits. | 1554 // Smi represents integer Numbers that can be stored in 31 bits. |
1592 // Smis are immediate which means they are NOT allocated in the heap. | 1555 // Smis are immediate which means they are NOT allocated in the heap. |
1593 // The this pointer has the following format: [31 bit signed int] 0 | 1556 // The this pointer has the following format: [31 bit signed int] 0 |
1594 // For long smis it has the following format: | 1557 // For long smis it has the following format: |
1595 // [32 bit signed int] [31 bits zero padding] 0 | 1558 // [32 bit signed int] [31 bits zero padding] 0 |
(...skipping 22 matching lines...) Expand all Loading... |
1618 | 1581 |
1619 static const int kMinValue = | 1582 static const int kMinValue = |
1620 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); | 1583 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
1621 static const int kMaxValue = -(kMinValue + 1); | 1584 static const int kMaxValue = -(kMinValue + 1); |
1622 | 1585 |
1623 private: | 1586 private: |
1624 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); | 1587 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
1625 }; | 1588 }; |
1626 | 1589 |
1627 | 1590 |
1628 // Failure is mainly used for reporting a situation requiring a GC. | |
1629 // Failure objects are transient and cannot occur as part of the object graph. | |
1630 // | |
1631 // Failures are a single word, encoded as follows: | |
1632 // +-------------------------+---+--+--+ | |
1633 // |.........unused..........|sss|tt|11| | |
1634 // +-------------------------+---+--+--+ | |
1635 // 7 6 4 32 10 | |
1636 // | |
1637 // | |
1638 // The low two bits, 0-1, are the failure tag, 11. The next two bits, | |
1639 // 2-3, are a failure type tag 'tt' with possible values: | |
1640 // 00 RETRY_AFTER_GC | |
1641 // | |
1642 // The next three bits, 4-6, are an allocation space tag 'sss'. The | |
1643 // allocation space tag is 000 for all failure types except | |
1644 // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the | |
1645 // allocation spaces (the encoding is found in globals.h). | |
1646 | |
1647 // Failure type tag info. | |
1648 const int kFailureTypeTagSize = 2; | |
1649 const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; | |
1650 | |
1651 class Failure: public MaybeObject { | |
1652 public: | |
1653 enum Type { | |
1654 RETRY_AFTER_GC = 0 | |
1655 }; | |
1656 | |
1657 inline Type type() const; | |
1658 | |
1659 // Returns the space that needs to be collected for RetryAfterGC failures. | |
1660 inline AllocationSpace allocation_space() const; | |
1661 | |
1662 static inline Failure* RetryAfterGC(AllocationSpace space); | |
1663 static inline Failure* RetryAfterGC(); // NEW_SPACE | |
1664 // Casting. | |
1665 static inline Failure* cast(MaybeObject* object); | |
1666 | |
1667 // Dispatched behavior. | |
1668 void FailurePrint(FILE* out = stdout); | |
1669 void FailurePrint(StringStream* accumulator); | |
1670 | |
1671 DECLARE_VERIFIER(Failure) | |
1672 | |
1673 private: | |
1674 inline intptr_t value() const; | |
1675 static inline Failure* Construct(Type type, intptr_t value = 0); | |
1676 | |
1677 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); | |
1678 }; | |
1679 | |
1680 | |
1681 // Heap objects typically have a map pointer in their first word. However, | 1591 // Heap objects typically have a map pointer in their first word. However, |
1682 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes | 1592 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
1683 // encoded in the first word. The class MapWord is an abstraction of the | 1593 // encoded in the first word. The class MapWord is an abstraction of the |
1684 // value in a heap object's first word. | 1594 // value in a heap object's first word. |
1685 class MapWord BASE_EMBEDDED { | 1595 class MapWord BASE_EMBEDDED { |
1686 public: | 1596 public: |
1687 // Normal state: the map word contains a map pointer. | 1597 // Normal state: the map word contains a map pointer. |
1688 | 1598 |
1689 // Create a map word from a map pointer. | 1599 // Create a map word from a map pointer. |
1690 static inline MapWord FromMap(Map* map); | 1600 static inline MapWord FromMap(Map* map); |
(...skipping 9489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11180 } else { | 11090 } else { |
11181 value &= ~(1 << bit_position); | 11091 value &= ~(1 << bit_position); |
11182 } | 11092 } |
11183 return value; | 11093 return value; |
11184 } | 11094 } |
11185 }; | 11095 }; |
11186 | 11096 |
11187 } } // namespace v8::internal | 11097 } } // namespace v8::internal |
11188 | 11098 |
11189 #endif // V8_OBJECTS_H_ | 11099 #endif // V8_OBJECTS_H_ |
OLD | NEW |