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 <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1630 // as above, for the single element at "offset" | 1630 // as above, for the single element at "offset" |
1631 inline void IteratePointer(ObjectVisitor* v, int offset); | 1631 inline void IteratePointer(ObjectVisitor* v, int offset); |
1632 // as above, for the next code link of a code object. | 1632 // as above, for the next code link of a code object. |
1633 inline void IterateNextCodeLink(ObjectVisitor* v, int offset); | 1633 inline void IterateNextCodeLink(ObjectVisitor* v, int offset); |
1634 | 1634 |
1635 private: | 1635 private: |
1636 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); | 1636 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
1637 }; | 1637 }; |
1638 | 1638 |
1639 | 1639 |
1640 // This class base class for object's body descriptors. | |
Michael Starzinger
2015/11/05 13:10:25
nit: "This is the base class ..."?
Igor Sheludko
2015/11/05 13:45:12
Done.
| |
1641 class BodyDescriptorBase { | |
1642 protected: | |
1643 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, | |
1644 int end_offset, ObjectVisitor* v); | |
1645 | |
1646 template <typename StaticVisitor> | |
1647 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, | |
1648 int end_offset); | |
1649 }; | |
1650 | |
1651 | |
1640 // This class describes a body of an object of a fixed size | 1652 // This class describes a body of an object of a fixed size |
1641 // in which all pointer fields are located in the [start_offset, end_offset) | 1653 // in which all pointer fields are located in the [start_offset, end_offset) |
1642 // interval. | 1654 // interval. |
1643 template<int start_offset, int end_offset, int size> | 1655 template <int start_offset, int end_offset, int size> |
1644 class FixedBodyDescriptor { | 1656 class FixedBodyDescriptor : public BodyDescriptorBase { |
1645 public: | 1657 public: |
1646 static const int kStartOffset = start_offset; | 1658 static const int kStartOffset = start_offset; |
1647 static const int kEndOffset = end_offset; | 1659 static const int kEndOffset = end_offset; |
1648 static const int kSize = size; | 1660 static const int kSize = size; |
1649 | 1661 |
1650 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); | 1662 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) { |
1663 IterateBodyImpl(obj, start_offset, end_offset, v); | |
1664 } | |
1651 | 1665 |
1652 template<typename StaticVisitor> | 1666 template <typename StaticVisitor> |
1653 static inline void IterateBody(HeapObject* obj) { | 1667 static inline void IterateBody(HeapObject* obj) { |
1654 StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset), | 1668 IterateBodyImpl<StaticVisitor>(obj, start_offset, end_offset); |
1655 HeapObject::RawField(obj, end_offset)); | 1669 } |
1670 }; | |
1671 | |
1672 | |
1673 // This base class describes a body of an object of a variable size | |
1674 // in which all pointer fields are located in the [start_offset, object_size) | |
1675 // interval. | |
1676 template <int start_offset> | |
1677 class FlexibleBodyDescriptorBase : public BodyDescriptorBase { | |
Michael Starzinger
2015/11/05 13:10:25
Is there a particular reason FlexibleBodyDescripto
Michael Starzinger
2015/11/05 13:44:46
As discussed offline: This is used by FixedArray::
Igor Sheludko
2015/11/05 13:45:12
I tried to avoid the confusion, since the FixedArr
| |
1678 public: | |
1679 static const int kStartOffset = start_offset; | |
1680 | |
1681 static inline void IterateBody(HeapObject* obj, int object_size, | |
1682 ObjectVisitor* v) { | |
1683 IterateBodyImpl(obj, start_offset, object_size, v); | |
1684 } | |
1685 | |
1686 template <typename StaticVisitor> | |
1687 static inline void IterateBody(HeapObject* obj, int object_size) { | |
1688 IterateBodyImpl<StaticVisitor>(obj, start_offset, object_size); | |
1656 } | 1689 } |
1657 }; | 1690 }; |
1658 | 1691 |
1659 | 1692 |
1660 // This class describes a body of an object of a variable size | 1693 // This class describes a body of an object of a variable size |
1661 // in which all pointer fields are located in the [start_offset, object_size) | 1694 // in which all pointer fields are located in the [start_offset, object_size) |
1662 // interval. | 1695 // interval. The size of the object is taken from the map. |
1663 template<int start_offset> | 1696 template <int start_offset> |
1664 class FlexibleBodyDescriptor { | 1697 class FlexibleBodyDescriptor : public FlexibleBodyDescriptorBase<start_offset> { |
1665 public: | 1698 public: |
1666 static const int kStartOffset = start_offset; | 1699 static inline int SizeOf(Map* map, HeapObject* object); |
1667 | |
1668 static inline void IterateBody(HeapObject* obj, | |
1669 int object_size, | |
1670 ObjectVisitor* v); | |
1671 | |
1672 template<typename StaticVisitor> | |
1673 static inline void IterateBody(HeapObject* obj, int object_size) { | |
1674 StaticVisitor::VisitPointers(HeapObject::RawField(obj, start_offset), | |
1675 HeapObject::RawField(obj, object_size)); | |
1676 } | |
1677 }; | 1700 }; |
1678 | 1701 |
1679 | 1702 |
1680 // The HeapNumber class describes heap allocated numbers that cannot be | 1703 // The HeapNumber class describes heap allocated numbers that cannot be |
1681 // represented in a Smi (small integer) | 1704 // represented in a Smi (small integer) |
1682 class HeapNumber: public HeapObject { | 1705 class HeapNumber: public HeapObject { |
1683 public: | 1706 public: |
1684 // [value]: number value. | 1707 // [value]: number value. |
1685 inline double value() const; | 1708 inline double value() const; |
1686 inline void set_value(double value); | 1709 inline void set_value(double value); |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2470 // to the same object requires fewer allocations and copies. | 2493 // to the same object requires fewer allocations and copies. |
2471 static const int kFieldsAdded = 3; | 2494 static const int kFieldsAdded = 3; |
2472 | 2495 |
2473 // Layout description. | 2496 // Layout description. |
2474 static const int kPropertiesOffset = HeapObject::kHeaderSize; | 2497 static const int kPropertiesOffset = HeapObject::kHeaderSize; |
2475 static const int kElementsOffset = kPropertiesOffset + kPointerSize; | 2498 static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
2476 static const int kHeaderSize = kElementsOffset + kPointerSize; | 2499 static const int kHeaderSize = kElementsOffset + kPointerSize; |
2477 | 2500 |
2478 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); | 2501 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); |
2479 | 2502 |
2480 class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { | 2503 typedef FlexibleBodyDescriptor<kPropertiesOffset> BodyDescriptor; |
2481 public: | |
2482 static inline int SizeOf(Map* map, HeapObject* object); | |
2483 }; | |
2484 | 2504 |
2485 Context* GetCreationContext(); | 2505 Context* GetCreationContext(); |
2486 | 2506 |
2487 // Enqueue change record for Object.observe. May cause GC. | 2507 // Enqueue change record for Object.observe. May cause GC. |
2488 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( | 2508 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( |
2489 Handle<JSObject> object, const char* type, Handle<Name> name, | 2509 Handle<JSObject> object, const char* type, Handle<Name> name, |
2490 Handle<Object> old_value); | 2510 Handle<Object> old_value); |
2491 | 2511 |
2492 // Gets the number of currently used elements. | 2512 // Gets the number of currently used elements. |
2493 int GetFastElementsUsage(); | 2513 int GetFastElementsUsage(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2652 // Swap two elements in a pair of arrays. If this array and the | 2672 // Swap two elements in a pair of arrays. If this array and the |
2653 // numbers array are the same object, the elements are only swapped | 2673 // numbers array are the same object, the elements are only swapped |
2654 // once. | 2674 // once. |
2655 void SwapPairs(FixedArray* numbers, int i, int j); | 2675 void SwapPairs(FixedArray* numbers, int i, int j); |
2656 | 2676 |
2657 // Sort prefix of this array and the numbers array as pairs wrt. the | 2677 // Sort prefix of this array and the numbers array as pairs wrt. the |
2658 // numbers. If the numbers array and the this array are the same | 2678 // numbers. If the numbers array and the this array are the same |
2659 // object, the prefix of this array is sorted. | 2679 // object, the prefix of this array is sorted. |
2660 void SortPairs(FixedArray* numbers, uint32_t len); | 2680 void SortPairs(FixedArray* numbers, uint32_t len); |
2661 | 2681 |
2662 class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { | 2682 class BodyDescriptor : public FlexibleBodyDescriptorBase<kHeaderSize> { |
2663 public: | 2683 public: |
2664 static inline int SizeOf(Map* map, HeapObject* object); | 2684 static inline int SizeOf(Map* map, HeapObject* object); |
2665 }; | 2685 }; |
2666 | 2686 |
2667 protected: | 2687 protected: |
2668 // Set operation on FixedArray without using write barriers. Can | 2688 // Set operation on FixedArray without using write barriers. Can |
2669 // only be used for storing old space objects or smis. | 2689 // only be used for storing old space objects or smis. |
2670 static inline void NoWriteBarrierSet(FixedArray* array, | 2690 static inline void NoWriteBarrierSet(FixedArray* array, |
2671 int index, | 2691 int index, |
2672 Object* value); | 2692 Object* value); |
(...skipping 8035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10708 // Visits a handle that has an embedder-assigned class ID. | 10728 // Visits a handle that has an embedder-assigned class ID. |
10709 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} | 10729 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
10710 | 10730 |
10711 // Intended for serialization/deserialization checking: insert, or | 10731 // Intended for serialization/deserialization checking: insert, or |
10712 // check for the presence of, a tag at this position in the stream. | 10732 // check for the presence of, a tag at this position in the stream. |
10713 // Also used for marking up GC roots in heap snapshots. | 10733 // Also used for marking up GC roots in heap snapshots. |
10714 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} | 10734 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
10715 }; | 10735 }; |
10716 | 10736 |
10717 | 10737 |
10718 class StructBodyDescriptor : public | 10738 typedef FlexibleBodyDescriptor<HeapObject::kHeaderSize> StructBodyDescriptor; |
10719 FlexibleBodyDescriptor<HeapObject::kHeaderSize> { | |
10720 public: | |
10721 static inline int SizeOf(Map* map, HeapObject* object); | |
10722 }; | |
10723 | 10739 |
10724 | 10740 |
10725 // BooleanBit is a helper class for setting and getting a bit in an integer. | 10741 // BooleanBit is a helper class for setting and getting a bit in an integer. |
10726 class BooleanBit : public AllStatic { | 10742 class BooleanBit : public AllStatic { |
10727 public: | 10743 public: |
10728 static inline bool get(int value, int bit_position) { | 10744 static inline bool get(int value, int bit_position) { |
10729 return (value & (1 << bit_position)) != 0; | 10745 return (value & (1 << bit_position)) != 0; |
10730 } | 10746 } |
10731 | 10747 |
10732 static inline int set(int value, int bit_position, bool v) { | 10748 static inline int set(int value, int bit_position, bool v) { |
10733 if (v) { | 10749 if (v) { |
10734 value |= (1 << bit_position); | 10750 value |= (1 << bit_position); |
10735 } else { | 10751 } else { |
10736 value &= ~(1 << bit_position); | 10752 value &= ~(1 << bit_position); |
10737 } | 10753 } |
10738 return value; | 10754 return value; |
10739 } | 10755 } |
10740 }; | 10756 }; |
10741 | 10757 |
10742 | 10758 |
10743 } // NOLINT, false-positive due to second-order macros. | 10759 } // NOLINT, false-positive due to second-order macros. |
10744 } // NOLINT, false-positive due to second-order macros. | 10760 } // NOLINT, false-positive due to second-order macros. |
10745 | 10761 |
10746 #endif // V8_OBJECTS_H_ | 10762 #endif // V8_OBJECTS_H_ |
OLD | NEW |