Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: src/objects.h

Issue 1441453002: Avoid manual object's body traversal in GC. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 return reinterpret_cast<Address>(this) - kHeapObjectTag; 1555 return reinterpret_cast<Address>(this) - kHeapObjectTag;
1556 } 1556 }
1557 1557
1558 // Iterates over pointers contained in the object (including the Map) 1558 // Iterates over pointers contained in the object (including the Map)
1559 void Iterate(ObjectVisitor* v); 1559 void Iterate(ObjectVisitor* v);
1560 1560
1561 // Iterates over all pointers contained in the object except the 1561 // Iterates over all pointers contained in the object except the
1562 // first map pointer. The object type is given in the first 1562 // first map pointer. The object type is given in the first
1563 // parameter. This function does not access the map pointer in the 1563 // parameter. This function does not access the map pointer in the
1564 // object, and so is safe to call while the map pointer is modified. 1564 // object, and so is safe to call while the map pointer is modified.
1565 void IterateBody(ObjectVisitor* v);
1565 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); 1566 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1566 1567
1567 // Returns the heap object's size in bytes 1568 // Returns the heap object's size in bytes
1568 inline int Size(); 1569 inline int Size();
1569 1570
1570 // Indicates what type of values this heap object may contain. 1571 // Indicates what type of values this heap object may contain.
1571 inline HeapObjectContents ContentType(); 1572 inline HeapObjectContents ContentType();
1572 1573
1573 // Given a heap object's map pointer, returns the heap size in bytes 1574 // Given a heap object's map pointer, returns the heap size in bytes
1574 // Useful when the map pointer field is used for other purposes. 1575 // Useful when the map pointer field is used for other purposes.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 // as above, for the next code link of a code object. 1633 // as above, for the next code link of a code object.
1633 inline void IterateNextCodeLink(ObjectVisitor* v, int offset); 1634 inline void IterateNextCodeLink(ObjectVisitor* v, int offset);
1634 1635
1635 private: 1636 private:
1636 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); 1637 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1637 }; 1638 };
1638 1639
1639 1640
1640 // This is the base class for object's body descriptors. 1641 // This is the base class for object's body descriptors.
1641 class BodyDescriptorBase { 1642 class BodyDescriptorBase {
1643 public:
1644 template <typename ObjectVisitor>
1645 static inline void IteratePointers(HeapObject* obj, int start_offset,
1646 int end_offset, ObjectVisitor* v);
1647
1648 template <typename StaticVisitor>
1649 static inline void IteratePointers(Heap* heap, HeapObject* obj,
1650 int start_offset, int end_offset);
1651
1652 template <typename ObjectVisitor>
1653 static inline void IteratePointer(HeapObject* obj, int offset,
1654 ObjectVisitor* v);
1655
1656 template <typename StaticVisitor>
1657 static inline void IteratePointer(Heap* heap, HeapObject* obj, int offset);
1658
1642 protected: 1659 protected:
1660 template <typename ObjectVisitor>
1643 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, 1661 static inline void IterateBodyImpl(HeapObject* obj, int start_offset,
1644 int end_offset, ObjectVisitor* v); 1662 int end_offset, ObjectVisitor* v);
1645 1663
1646 template <typename StaticVisitor> 1664 template <typename StaticVisitor>
1647 static inline void IterateBodyImpl(Heap* heap, HeapObject* obj, 1665 static inline void IterateBodyImpl(Heap* heap, HeapObject* obj,
1648 int start_offset, int end_offset); 1666 int start_offset, int end_offset);
1649
1650 static inline void IteratePointers(HeapObject* obj, int start_offset,
1651 int end_offset, ObjectVisitor* v);
1652
1653 template <typename StaticVisitor>
1654 static inline void IteratePointers(Heap* heap, HeapObject* obj,
1655 int start_offset, int end_offset);
1656 }; 1667 };
1657 1668
1658 1669
1659 // This class describes a body of an object of a fixed size 1670 // This class describes a body of an object of a fixed size
1660 // in which all pointer fields are located in the [start_offset, end_offset) 1671 // in which all pointer fields are located in the [start_offset, end_offset)
1661 // interval. 1672 // interval.
1662 template <int start_offset, int end_offset, int size> 1673 template <int start_offset, int end_offset, int size>
1663 class FixedBodyDescriptor : public BodyDescriptorBase { 1674 class FixedBodyDescriptor : public BodyDescriptorBase {
1664 public: 1675 public:
1665 static const int kStartOffset = start_offset; 1676 static const int kStartOffset = start_offset;
1666 static const int kEndOffset = end_offset; 1677 static const int kEndOffset = end_offset;
1667 static const int kSize = size; 1678 static const int kSize = size;
1668 1679
1680 template <typename ObjectVisitor>
1669 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) { 1681 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) {
1670 IterateBodyImpl(obj, start_offset, end_offset, v); 1682 IterateBodyImpl(obj, start_offset, end_offset, v);
1671 } 1683 }
1672 1684
1673 template <typename StaticVisitor> 1685 template <typename StaticVisitor>
1674 static inline void IterateBody(HeapObject* obj) { 1686 static inline void IterateBody(HeapObject* obj) {
1675 Heap* heap = obj->GetHeap(); 1687 Heap* heap = obj->GetHeap();
1676 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, end_offset); 1688 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, end_offset);
1677 } 1689 }
1678 }; 1690 };
1679 1691
1680 1692
1681 // This base class describes a body of an object of a variable size 1693 // This base class describes a body of an object of a variable size
1682 // 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)
1683 // interval. 1695 // interval.
1684 template <int start_offset> 1696 template <int start_offset>
1685 class FlexibleBodyDescriptorBase : public BodyDescriptorBase { 1697 class FlexibleBodyDescriptorBase : public BodyDescriptorBase {
1686 public: 1698 public:
1687 static const int kStartOffset = start_offset; 1699 static const int kStartOffset = start_offset;
1688 1700
1701 template <typename ObjectVisitor>
1689 static inline void IterateBody(HeapObject* obj, int object_size, 1702 static inline void IterateBody(HeapObject* obj, int object_size,
1690 ObjectVisitor* v) { 1703 ObjectVisitor* v) {
1691 IterateBodyImpl(obj, start_offset, object_size, v); 1704 IterateBodyImpl(obj, start_offset, object_size, v);
1692 } 1705 }
1693 1706
1694 template <typename StaticVisitor> 1707 template <typename StaticVisitor>
1695 static inline void IterateBody(HeapObject* obj, int object_size) { 1708 static inline void IterateBody(HeapObject* obj, int object_size) {
1696 Heap* heap = obj->GetHeap(); 1709 Heap* heap = obj->GetHeap();
1697 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, object_size); 1710 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, object_size);
1698 } 1711 }
(...skipping 2737 matching lines...) Expand 10 before | Expand all | Expand 10 after
4436 static const int kConstantPoolOffset = kParameterSizeOffset + kIntSize; 4449 static const int kConstantPoolOffset = kParameterSizeOffset + kIntSize;
4437 static const int kHeaderSize = kConstantPoolOffset + kPointerSize; 4450 static const int kHeaderSize = kConstantPoolOffset + kPointerSize;
4438 4451
4439 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); 4452 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
4440 4453
4441 // Maximal memory consumption for a single BytecodeArray. 4454 // Maximal memory consumption for a single BytecodeArray.
4442 static const int kMaxSize = 512 * MB; 4455 static const int kMaxSize = 512 * MB;
4443 // Maximal length of a single BytecodeArray. 4456 // Maximal length of a single BytecodeArray.
4444 static const int kMaxLength = kMaxSize - kHeaderSize; 4457 static const int kMaxLength = kMaxSize - kHeaderSize;
4445 4458
4459 class BodyDescriptor;
4460
4446 private: 4461 private:
4447 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray); 4462 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray);
4448 }; 4463 };
4449 4464
4450 4465
4451 // FreeSpace are fixed-size free memory blocks used by the heap and GC. 4466 // FreeSpace are fixed-size free memory blocks used by the heap and GC.
4452 // They look like heap objects (are heap object tagged and have a map) so that 4467 // They look like heap objects (are heap object tagged and have a map) so that
4453 // the heap remains iterable. They have a size and a next pointer. 4468 // the heap remains iterable. They have a size and a next pointer.
4454 // The next pointer is the raw address of the next FreeSpace object (or NULL) 4469 // The next pointer is the raw address of the next FreeSpace object (or NULL)
4455 // in the free list. 4470 // in the free list.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4501 public: 4516 public:
4502 // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr. 4517 // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr.
4503 DECL_ACCESSORS(base_pointer, Object) 4518 DECL_ACCESSORS(base_pointer, Object)
4504 4519
4505 // [external_pointer]: Contains the offset between base_pointer and the start 4520 // [external_pointer]: Contains the offset between base_pointer and the start
4506 // of the data. If the base_pointer is a nullptr, the external_pointer 4521 // of the data. If the base_pointer is a nullptr, the external_pointer
4507 // therefore points to the actual backing store. 4522 // therefore points to the actual backing store.
4508 DECL_ACCESSORS(external_pointer, void) 4523 DECL_ACCESSORS(external_pointer, void)
4509 4524
4510 // Dispatched behavior. 4525 // Dispatched behavior.
4511 inline void FixedTypedArrayBaseIterateBody(ObjectVisitor* v);
4512
4513 template <typename StaticVisitor>
4514 inline void FixedTypedArrayBaseIterateBody();
4515
4516 DECLARE_CAST(FixedTypedArrayBase) 4526 DECLARE_CAST(FixedTypedArrayBase)
4517 4527
4518 static const int kBasePointerOffset = FixedArrayBase::kHeaderSize; 4528 static const int kBasePointerOffset = FixedArrayBase::kHeaderSize;
4519 static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize; 4529 static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize;
4520 static const int kHeaderSize = 4530 static const int kHeaderSize =
4521 DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize); 4531 DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize);
4522 4532
4523 static const int kDataOffset = kHeaderSize; 4533 static const int kDataOffset = kHeaderSize;
4524 4534
4535 class BodyDescriptor;
4536
4525 inline int size(); 4537 inline int size();
4526 4538
4527 static inline int TypedArraySize(InstanceType type, int length); 4539 static inline int TypedArraySize(InstanceType type, int length);
4528 inline int TypedArraySize(InstanceType type); 4540 inline int TypedArraySize(InstanceType type);
4529 4541
4530 // Use with care: returns raw pointer into heap. 4542 // Use with care: returns raw pointer into heap.
4531 inline void* DataPtr(); 4543 inline void* DataPtr();
4532 4544
4533 inline int DataSize(); 4545 inline int DataSize();
4534 4546
(...skipping 5344 matching lines...) Expand 10 before | Expand all | Expand 10 after
9879 static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate); 9891 static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
9880 static void Set(Handle<JSWeakCollection> collection, Handle<Object> key, 9892 static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
9881 Handle<Object> value, int32_t hash); 9893 Handle<Object> value, int32_t hash);
9882 static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key, 9894 static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
9883 int32_t hash); 9895 int32_t hash);
9884 9896
9885 static const int kTableOffset = JSObject::kHeaderSize; 9897 static const int kTableOffset = JSObject::kHeaderSize;
9886 static const int kNextOffset = kTableOffset + kPointerSize; 9898 static const int kNextOffset = kTableOffset + kPointerSize;
9887 static const int kSize = kNextOffset + kPointerSize; 9899 static const int kSize = kNextOffset + kPointerSize;
9888 9900
9901 class BodyDescriptor;
9902
9889 private: 9903 private:
9890 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection); 9904 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection);
9891 }; 9905 };
9892 9906
9893 9907
9894 // The JSWeakMap describes EcmaScript Harmony weak maps 9908 // The JSWeakMap describes EcmaScript Harmony weak maps
9895 class JSWeakMap: public JSWeakCollection { 9909 class JSWeakMap: public JSWeakCollection {
9896 public: 9910 public:
9897 DECLARE_CAST(JSWeakMap) 9911 DECLARE_CAST(JSWeakMap)
9898 9912
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9957 static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer, 9971 static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
9958 Isolate* isolate, size_t allocated_length, 9972 Isolate* isolate, size_t allocated_length,
9959 bool initialize = true, 9973 bool initialize = true,
9960 SharedFlag shared = SharedFlag::kNotShared); 9974 SharedFlag shared = SharedFlag::kNotShared);
9961 9975
9962 // Dispatched behavior. 9976 // Dispatched behavior.
9963 DECLARE_PRINTER(JSArrayBuffer) 9977 DECLARE_PRINTER(JSArrayBuffer)
9964 DECLARE_VERIFIER(JSArrayBuffer) 9978 DECLARE_VERIFIER(JSArrayBuffer)
9965 9979
9966 static const int kByteLengthOffset = JSObject::kHeaderSize; 9980 static const int kByteLengthOffset = JSObject::kHeaderSize;
9967
9968 // NOTE: GC will visit objects fields:
9969 // 1. From JSObject::BodyDescriptor::kStartOffset to kByteLengthOffset +
9970 // kPointerSize
9971 // 2. From start of the internal fields and up to the end of them
9972 static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize; 9981 static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize;
9973 static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize; 9982 static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize;
9974 #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT 9983 #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
9975 static const int kBitFieldOffset = kBitFieldSlot; 9984 static const int kBitFieldOffset = kBitFieldSlot;
9976 #else 9985 #else
9977 static const int kBitFieldOffset = kBitFieldSlot + kIntSize; 9986 static const int kBitFieldOffset = kBitFieldSlot + kIntSize;
9978 #endif 9987 #endif
9979 static const int kSize = kBitFieldSlot + kPointerSize; 9988 static const int kSize = kBitFieldSlot + kPointerSize;
9980 9989
9981 static const int kSizeWithInternalFields = 9990 static const int kSizeWithInternalFields =
9982 kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize; 9991 kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize;
9983 9992
9984 template <typename StaticVisitor> 9993 // Iterates all fields in the object including internal ones except
9985 static inline void JSArrayBufferIterateBody(Heap* heap, HeapObject* obj); 9994 // kBackingStoreOffset and kBitFieldSlot.
9986 9995 class BodyDescriptor;
9987 static inline void JSArrayBufferIterateBody(HeapObject* obj,
9988 ObjectVisitor* v);
9989 9996
9990 class IsExternal : public BitField<bool, 1, 1> {}; 9997 class IsExternal : public BitField<bool, 1, 1> {};
9991 class IsNeuterable : public BitField<bool, 2, 1> {}; 9998 class IsNeuterable : public BitField<bool, 2, 1> {};
9992 class WasNeutered : public BitField<bool, 3, 1> {}; 9999 class WasNeutered : public BitField<bool, 3, 1> {};
9993 class IsShared : public BitField<bool, 4, 1> {}; 10000 class IsShared : public BitField<bool, 4, 1> {};
9994 10001
9995 private: 10002 private:
9996 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer); 10003 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer);
9997 }; 10004 };
9998 10005
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
10788 } 10795 }
10789 return value; 10796 return value;
10790 } 10797 }
10791 }; 10798 };
10792 10799
10793 10800
10794 } // NOLINT, false-positive due to second-order macros. 10801 } // NOLINT, false-positive due to second-order macros.
10795 } // NOLINT, false-positive due to second-order macros. 10802 } // NOLINT, false-positive due to second-order macros.
10796 10803
10797 #endif // V8_OBJECTS_H_ 10804 #endif // V8_OBJECTS_H_
OLDNEW
« src/heap/objects-visiting.h ('K') | « src/heap/store-buffer.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698