| 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 "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
| 10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
| (...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 | 1343 |
| 1344 // Object is the abstract superclass for all classes in the | 1344 // Object is the abstract superclass for all classes in the |
| 1345 // object hierarchy. | 1345 // object hierarchy. |
| 1346 // Object does not use any virtual functions to avoid the | 1346 // Object does not use any virtual functions to avoid the |
| 1347 // allocation of the C++ vtable. | 1347 // allocation of the C++ vtable. |
| 1348 // Since both Smi and HeapObject are subclasses of Object no | 1348 // Since both Smi and HeapObject are subclasses of Object no |
| 1349 // data members can be present in Object. | 1349 // data members can be present in Object. |
| 1350 class Object { | 1350 class Object { |
| 1351 public: | 1351 public: |
| 1352 // Type testing. | 1352 // Type testing. |
| 1353 bool IsObject() { return true; } | 1353 bool IsObject() const { return true; } |
| 1354 | 1354 |
| 1355 #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); | 1355 #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
| 1356 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) | 1356 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1357 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) | 1357 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1358 #undef IS_TYPE_FUNCTION_DECL | 1358 #undef IS_TYPE_FUNCTION_DECL |
| 1359 | 1359 |
| 1360 inline bool IsFixedArrayBase(); | 1360 INLINE(bool IsFixedArrayBase() const); |
| 1361 inline bool IsExternal(); | 1361 INLINE(bool IsExternal() const); |
| 1362 inline bool IsAccessorInfo(); | 1362 INLINE(bool IsAccessorInfo() const); |
| 1363 | 1363 |
| 1364 inline bool IsStruct(); | 1364 INLINE(bool IsStruct() const); |
| 1365 #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); | 1365 #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1366 INLINE(bool Is##Name() const); |
| 1366 STRUCT_LIST(DECLARE_STRUCT_PREDICATE) | 1367 STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1367 #undef DECLARE_STRUCT_PREDICATE | 1368 #undef DECLARE_STRUCT_PREDICATE |
| 1368 | 1369 |
| 1369 INLINE(bool IsSpecObject()); | 1370 INLINE(bool IsSpecObject()) const; |
| 1370 INLINE(bool IsSpecFunction()); | 1371 INLINE(bool IsSpecFunction()) const; |
| 1371 INLINE(bool IsTemplateInfo()); | 1372 INLINE(bool IsTemplateInfo()) const; |
| 1372 INLINE(bool IsNameDictionary()); | 1373 INLINE(bool IsNameDictionary() const); |
| 1373 INLINE(bool IsSeededNumberDictionary()); | 1374 INLINE(bool IsSeededNumberDictionary() const); |
| 1374 INLINE(bool IsUnseededNumberDictionary()); | 1375 INLINE(bool IsUnseededNumberDictionary() const); |
| 1375 INLINE(bool IsOrderedHashSet()); | 1376 INLINE(bool IsOrderedHashSet() const); |
| 1376 INLINE(bool IsOrderedHashMap()); | 1377 INLINE(bool IsOrderedHashMap() const); |
| 1377 bool IsCallable(); | 1378 bool IsCallable() const; |
| 1378 | 1379 |
| 1379 // Oddball testing. | 1380 // Oddball testing. |
| 1380 INLINE(bool IsUndefined()); | 1381 INLINE(bool IsUndefined() const); |
| 1381 INLINE(bool IsNull()); | 1382 INLINE(bool IsNull() const); |
| 1382 INLINE(bool IsTheHole()); | 1383 INLINE(bool IsTheHole() const); |
| 1383 INLINE(bool IsException()); | 1384 INLINE(bool IsException() const); |
| 1384 INLINE(bool IsUninitialized()); | 1385 INLINE(bool IsUninitialized() const); |
| 1385 INLINE(bool IsTrue()); | 1386 INLINE(bool IsTrue() const); |
| 1386 INLINE(bool IsFalse()); | 1387 INLINE(bool IsFalse() const); |
| 1387 inline bool IsArgumentsMarker(); | 1388 INLINE(bool IsArgumentsMarker() const); |
| 1388 | 1389 |
| 1389 // Filler objects (fillers and free space objects). | 1390 // Filler objects (fillers and free space objects). |
| 1390 inline bool IsFiller(); | 1391 INLINE(bool IsFiller() const); |
| 1391 | 1392 |
| 1392 // Extract the number. | 1393 // Extract the number. |
| 1393 inline double Number(); | 1394 inline double Number(); |
| 1394 inline bool IsNaN(); | 1395 INLINE(bool IsNaN() const); |
| 1395 bool ToInt32(int32_t* value); | 1396 bool ToInt32(int32_t* value); |
| 1396 bool ToUint32(uint32_t* value); | 1397 bool ToUint32(uint32_t* value); |
| 1397 | 1398 |
| 1398 // Indicates whether OptimalRepresentation can do its work, or whether it | 1399 // Indicates whether OptimalRepresentation can do its work, or whether it |
| 1399 // always has to return Representation::Tagged(). | 1400 // always has to return Representation::Tagged(). |
| 1400 enum ValueType { | 1401 enum ValueType { |
| 1401 OPTIMAL_REPRESENTATION, | 1402 OPTIMAL_REPRESENTATION, |
| 1402 FORCE_TAGGED | 1403 FORCE_TAGGED |
| 1403 }; | 1404 }; |
| 1404 | 1405 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 | 1677 |
| 1677 // During garbage collection, the map word of a heap object does not | 1678 // During garbage collection, the map word of a heap object does not |
| 1678 // necessarily contain a map pointer. | 1679 // necessarily contain a map pointer. |
| 1679 inline MapWord map_word() const; | 1680 inline MapWord map_word() const; |
| 1680 inline void set_map_word(MapWord map_word); | 1681 inline void set_map_word(MapWord map_word); |
| 1681 | 1682 |
| 1682 // The Heap the object was allocated in. Used also to access Isolate. | 1683 // The Heap the object was allocated in. Used also to access Isolate. |
| 1683 inline Heap* GetHeap() const; | 1684 inline Heap* GetHeap() const; |
| 1684 | 1685 |
| 1685 // Convenience method to get current isolate. | 1686 // Convenience method to get current isolate. |
| 1686 inline Isolate* GetIsolate(); | 1687 inline Isolate* GetIsolate() const; |
| 1687 | 1688 |
| 1688 // Converts an address to a HeapObject pointer. | 1689 // Converts an address to a HeapObject pointer. |
| 1689 static inline HeapObject* FromAddress(Address address); | 1690 static inline HeapObject* FromAddress(Address address); |
| 1690 | 1691 |
| 1691 // Returns the address of this HeapObject. | 1692 // Returns the address of this HeapObject. |
| 1692 inline Address address(); | 1693 inline Address address(); |
| 1693 | 1694 |
| 1694 // Iterates over pointers contained in the object (including the Map) | 1695 // Iterates over pointers contained in the object (including the Map) |
| 1695 void Iterate(ObjectVisitor* v); | 1696 void Iterate(ObjectVisitor* v); |
| 1696 | 1697 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 HeapObject::RawField(obj, object_size)); | 1807 HeapObject::RawField(obj, object_size)); |
| 1807 } | 1808 } |
| 1808 }; | 1809 }; |
| 1809 | 1810 |
| 1810 | 1811 |
| 1811 // The HeapNumber class describes heap allocated numbers that cannot be | 1812 // The HeapNumber class describes heap allocated numbers that cannot be |
| 1812 // represented in a Smi (small integer) | 1813 // represented in a Smi (small integer) |
| 1813 class HeapNumber: public HeapObject { | 1814 class HeapNumber: public HeapObject { |
| 1814 public: | 1815 public: |
| 1815 // [value]: number value. | 1816 // [value]: number value. |
| 1816 inline double value(); | 1817 inline double value() const; |
| 1817 inline void set_value(double value); | 1818 inline void set_value(double value); |
| 1818 | 1819 |
| 1819 DECLARE_CAST(HeapNumber) | 1820 DECLARE_CAST(HeapNumber) |
| 1820 | 1821 |
| 1821 // Dispatched behavior. | 1822 // Dispatched behavior. |
| 1822 bool HeapNumberBooleanValue(); | 1823 bool HeapNumberBooleanValue(); |
| 1823 | 1824 |
| 1824 void HeapNumberPrint(FILE* out = stdout); | 1825 void HeapNumberPrint(FILE* out = stdout); |
| 1825 void HeapNumberPrint(StringStream* accumulator); | 1826 void HeapNumberPrint(StringStream* accumulator); |
| 1826 DECLARE_VERIFIER(HeapNumber) | 1827 DECLARE_VERIFIER(HeapNumber) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 Handle<Name> name); | 1963 Handle<Name> name); |
| 1963 | 1964 |
| 1964 static inline PropertyAttributes GetElementAttribute( | 1965 static inline PropertyAttributes GetElementAttribute( |
| 1965 Handle<JSReceiver> object, | 1966 Handle<JSReceiver> object, |
| 1966 uint32_t index); | 1967 uint32_t index); |
| 1967 static inline PropertyAttributes GetOwnElementAttribute( | 1968 static inline PropertyAttributes GetOwnElementAttribute( |
| 1968 Handle<JSReceiver> object, | 1969 Handle<JSReceiver> object, |
| 1969 uint32_t index); | 1970 uint32_t index); |
| 1970 | 1971 |
| 1971 // Return the object's prototype (might be Heap::null_value()). | 1972 // Return the object's prototype (might be Heap::null_value()). |
| 1972 inline Object* GetPrototype(); | 1973 inline Object* GetPrototype() const; |
| 1973 | 1974 |
| 1974 // Return the constructor function (may be Heap::null_value()). | 1975 // Return the constructor function (may be Heap::null_value()). |
| 1975 inline Object* GetConstructor(); | 1976 inline Object* GetConstructor(); |
| 1976 | 1977 |
| 1977 // Retrieves a permanent object identity hash code. The undefined value might | 1978 // Retrieves a permanent object identity hash code. The undefined value might |
| 1978 // be returned in case no hash was created yet. | 1979 // be returned in case no hash was created yet. |
| 1979 inline Object* GetIdentityHash(); | 1980 inline Object* GetIdentityHash(); |
| 1980 | 1981 |
| 1981 // Retrieves a permanent object identity hash code. May create and store a | 1982 // Retrieves a permanent object identity hash code. May create and store a |
| 1982 // hash code if needed and none exists. | 1983 // hash code if needed and none exists. |
| (...skipping 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4763 static Handle<NormalizedMapCache> New(Isolate* isolate); | 4764 static Handle<NormalizedMapCache> New(Isolate* isolate); |
| 4764 | 4765 |
| 4765 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, | 4766 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, |
| 4766 PropertyNormalizationMode mode); | 4767 PropertyNormalizationMode mode); |
| 4767 void Set(Handle<Map> fast_map, Handle<Map> normalized_map); | 4768 void Set(Handle<Map> fast_map, Handle<Map> normalized_map); |
| 4768 | 4769 |
| 4769 void Clear(); | 4770 void Clear(); |
| 4770 | 4771 |
| 4771 DECLARE_CAST(NormalizedMapCache) | 4772 DECLARE_CAST(NormalizedMapCache) |
| 4772 | 4773 |
| 4773 static inline bool IsNormalizedMapCache(Object* obj); | 4774 static inline bool IsNormalizedMapCache(const Object* obj); |
| 4774 | 4775 |
| 4775 DECLARE_VERIFIER(NormalizedMapCache) | 4776 DECLARE_VERIFIER(NormalizedMapCache) |
| 4776 private: | 4777 private: |
| 4777 static const int kEntries = 64; | 4778 static const int kEntries = 64; |
| 4778 | 4779 |
| 4779 static inline int GetIndex(Handle<Map> map); | 4780 static inline int GetIndex(Handle<Map> map); |
| 4780 | 4781 |
| 4781 // The following declarations hide base class methods. | 4782 // The following declarations hide base class methods. |
| 4782 Object* get(int index); | 4783 Object* get(int index); |
| 4783 void set(int index, Object* value); | 4784 void set(int index, Object* value); |
| (...skipping 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7802 public: | 7803 public: |
| 7803 // [native_context]: the owner native context of this global proxy object. | 7804 // [native_context]: the owner native context of this global proxy object. |
| 7804 // It is null value if this object is not used by any context. | 7805 // It is null value if this object is not used by any context. |
| 7805 DECL_ACCESSORS(native_context, Object) | 7806 DECL_ACCESSORS(native_context, Object) |
| 7806 | 7807 |
| 7807 // [hash]: The hash code property (undefined if not initialized yet). | 7808 // [hash]: The hash code property (undefined if not initialized yet). |
| 7808 DECL_ACCESSORS(hash, Object) | 7809 DECL_ACCESSORS(hash, Object) |
| 7809 | 7810 |
| 7810 DECLARE_CAST(JSGlobalProxy) | 7811 DECLARE_CAST(JSGlobalProxy) |
| 7811 | 7812 |
| 7812 inline bool IsDetachedFrom(GlobalObject* global); | 7813 inline bool IsDetachedFrom(GlobalObject* global) const; |
| 7813 | 7814 |
| 7814 // Dispatched behavior. | 7815 // Dispatched behavior. |
| 7815 DECLARE_PRINTER(JSGlobalProxy) | 7816 DECLARE_PRINTER(JSGlobalProxy) |
| 7816 DECLARE_VERIFIER(JSGlobalProxy) | 7817 DECLARE_VERIFIER(JSGlobalProxy) |
| 7817 | 7818 |
| 7818 // Layout description. | 7819 // Layout description. |
| 7819 static const int kNativeContextOffset = JSObject::kHeaderSize; | 7820 static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7820 static const int kHashOffset = kNativeContextOffset + kPointerSize; | 7821 static const int kHashOffset = kNativeContextOffset + kPointerSize; |
| 7821 static const int kSize = kHashOffset + kPointerSize; | 7822 static const int kSize = kHashOffset + kPointerSize; |
| 7822 | 7823 |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8798 // the shape of the string is given its own class so that it can be retrieved | 8799 // the shape of the string is given its own class so that it can be retrieved |
| 8799 // once and used for several string operations. A StringShape is small enough | 8800 // once and used for several string operations. A StringShape is small enough |
| 8800 // to be passed by value and is immutable, but be aware that flattening a | 8801 // to be passed by value and is immutable, but be aware that flattening a |
| 8801 // string can potentially alter its shape. Also be aware that a GC caused by | 8802 // string can potentially alter its shape. Also be aware that a GC caused by |
| 8802 // something else can alter the shape of a string due to ConsString | 8803 // something else can alter the shape of a string due to ConsString |
| 8803 // shortcutting. Keeping these restrictions in mind has proven to be error- | 8804 // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 8804 // prone and so we no longer put StringShapes in variables unless there is a | 8805 // prone and so we no longer put StringShapes in variables unless there is a |
| 8805 // concrete performance benefit at that particular point in the code. | 8806 // concrete performance benefit at that particular point in the code. |
| 8806 class StringShape BASE_EMBEDDED { | 8807 class StringShape BASE_EMBEDDED { |
| 8807 public: | 8808 public: |
| 8808 inline explicit StringShape(String* s); | 8809 inline explicit StringShape(const String* s); |
| 8809 inline explicit StringShape(Map* s); | 8810 inline explicit StringShape(Map* s); |
| 8810 inline explicit StringShape(InstanceType t); | 8811 inline explicit StringShape(InstanceType t); |
| 8811 inline bool IsSequential(); | 8812 inline bool IsSequential(); |
| 8812 inline bool IsExternal(); | 8813 inline bool IsExternal(); |
| 8813 inline bool IsCons(); | 8814 inline bool IsCons(); |
| 8814 inline bool IsSliced(); | 8815 inline bool IsSliced(); |
| 8815 inline bool IsIndirect(); | 8816 inline bool IsIndirect(); |
| 8816 inline bool IsExternalAscii(); | 8817 inline bool IsExternalAscii(); |
| 8817 inline bool IsExternalTwoByte(); | 8818 inline bool IsExternalTwoByte(); |
| 8818 inline bool IsSequentialAscii(); | 8819 inline bool IsSequentialAscii(); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9057 | 9058 |
| 9058 // Get and set the length of the string using acquire loads and release | 9059 // Get and set the length of the string using acquire loads and release |
| 9059 // stores. | 9060 // stores. |
| 9060 inline int synchronized_length() const; | 9061 inline int synchronized_length() const; |
| 9061 inline void synchronized_set_length(int value); | 9062 inline void synchronized_set_length(int value); |
| 9062 | 9063 |
| 9063 // Returns whether this string has only ASCII chars, i.e. all of them can | 9064 // Returns whether this string has only ASCII chars, i.e. all of them can |
| 9064 // be ASCII encoded. This might be the case even if the string is | 9065 // be ASCII encoded. This might be the case even if the string is |
| 9065 // two-byte. Such strings may appear when the embedder prefers | 9066 // two-byte. Such strings may appear when the embedder prefers |
| 9066 // two-byte external representations even for ASCII data. | 9067 // two-byte external representations even for ASCII data. |
| 9067 inline bool IsOneByteRepresentation(); | 9068 inline bool IsOneByteRepresentation() const; |
| 9068 inline bool IsTwoByteRepresentation(); | 9069 inline bool IsTwoByteRepresentation() const; |
| 9069 | 9070 |
| 9070 // Cons and slices have an encoding flag that may not represent the actual | 9071 // Cons and slices have an encoding flag that may not represent the actual |
| 9071 // encoding of the underlying string. This is taken into account here. | 9072 // encoding of the underlying string. This is taken into account here. |
| 9072 // Requires: this->IsFlat() | 9073 // Requires: this->IsFlat() |
| 9073 inline bool IsOneByteRepresentationUnderneath(); | 9074 inline bool IsOneByteRepresentationUnderneath(); |
| 9074 inline bool IsTwoByteRepresentationUnderneath(); | 9075 inline bool IsTwoByteRepresentationUnderneath(); |
| 9075 | 9076 |
| 9076 // NOTE: this should be considered only a hint. False negatives are | 9077 // NOTE: this should be considered only a hint. False negatives are |
| 9077 // possible. | 9078 // possible. |
| 9078 inline bool HasOnlyOneByteChars(); | 9079 inline bool HasOnlyOneByteChars(); |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9726 | 9727 |
| 9727 // The Oddball describes objects null, undefined, true, and false. | 9728 // The Oddball describes objects null, undefined, true, and false. |
| 9728 class Oddball: public HeapObject { | 9729 class Oddball: public HeapObject { |
| 9729 public: | 9730 public: |
| 9730 // [to_string]: Cached to_string computed at startup. | 9731 // [to_string]: Cached to_string computed at startup. |
| 9731 DECL_ACCESSORS(to_string, String) | 9732 DECL_ACCESSORS(to_string, String) |
| 9732 | 9733 |
| 9733 // [to_number]: Cached to_number computed at startup. | 9734 // [to_number]: Cached to_number computed at startup. |
| 9734 DECL_ACCESSORS(to_number, Object) | 9735 DECL_ACCESSORS(to_number, Object) |
| 9735 | 9736 |
| 9736 inline byte kind(); | 9737 inline byte kind() const; |
| 9737 inline void set_kind(byte kind); | 9738 inline void set_kind(byte kind); |
| 9738 | 9739 |
| 9739 DECLARE_CAST(Oddball) | 9740 DECLARE_CAST(Oddball) |
| 9740 | 9741 |
| 9741 // Dispatched behavior. | 9742 // Dispatched behavior. |
| 9742 DECLARE_VERIFIER(Oddball) | 9743 DECLARE_VERIFIER(Oddball) |
| 9743 | 9744 |
| 9744 // Initialize the fields. | 9745 // Initialize the fields. |
| 9745 static void Initialize(Isolate* isolate, | 9746 static void Initialize(Isolate* isolate, |
| 9746 Handle<Oddball> oddball, | 9747 Handle<Oddball> oddball, |
| (...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11147 } else { | 11148 } else { |
| 11148 value &= ~(1 << bit_position); | 11149 value &= ~(1 << bit_position); |
| 11149 } | 11150 } |
| 11150 return value; | 11151 return value; |
| 11151 } | 11152 } |
| 11152 }; | 11153 }; |
| 11153 | 11154 |
| 11154 } } // namespace v8::internal | 11155 } } // namespace v8::internal |
| 11155 | 11156 |
| 11156 #endif // V8_OBJECTS_H_ | 11157 #endif // V8_OBJECTS_H_ |
| OLD | NEW |