Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_OBJECTS_BODY_DESCRIPTORS_H_ | |
|
Michael Starzinger
2015/11/13 11:30:54
Also add the two new files to the BUILD.gn and the
Igor Sheludko
2015/11/13 11:37:39
Done.
| |
| 6 #define V8_OBJECTS_BODY_DESCRIPTORS_H_ | |
| 7 | |
| 8 #include "src/objects.h" | |
| 9 | |
| 10 namespace v8 { | |
| 11 namespace internal { | |
| 12 | |
| 13 // This is the base class for object's body descriptors. | |
| 14 // | |
| 15 // Each BodyDescriptor subclass must provide the following methods: | |
| 16 // | |
| 17 // 1) Returns true if the object contains a tagged value at given offset. | |
| 18 // It is used for invalid slots filtering. If the offset points outside | |
| 19 // of the object or to the map word, the result is UNDEFINED (!!!). | |
| 20 // | |
| 21 // static bool IsValidSlot(HeapObject* obj, int offset); | |
| 22 // | |
| 23 // | |
| 24 // 2) Iterate object's body using stateful object visitor. | |
| 25 // | |
| 26 // template <typename ObjectVisitor> | |
| 27 // static inline void IterateBody(HeapObject* obj, int object_size, | |
| 28 // ObjectVisitor* v); | |
| 29 // | |
| 30 // | |
| 31 // 3) Iterate object's body using stateless object visitor. | |
| 32 // | |
| 33 // template <typename StaticVisitor> | |
| 34 // static inline void IterateBody(HeapObject* obj, int object_size); | |
| 35 // | |
| 36 class BodyDescriptorBase BASE_EMBEDDED { | |
| 37 public: | |
| 38 template <typename ObjectVisitor> | |
| 39 static inline void IteratePointers(HeapObject* obj, int start_offset, | |
| 40 int end_offset, ObjectVisitor* v); | |
| 41 | |
| 42 template <typename StaticVisitor> | |
| 43 static inline void IteratePointers(Heap* heap, HeapObject* obj, | |
| 44 int start_offset, int end_offset); | |
| 45 | |
| 46 template <typename ObjectVisitor> | |
| 47 static inline void IteratePointer(HeapObject* obj, int offset, | |
| 48 ObjectVisitor* v); | |
| 49 | |
| 50 template <typename StaticVisitor> | |
| 51 static inline void IteratePointer(Heap* heap, HeapObject* obj, int offset); | |
| 52 | |
| 53 protected: | |
| 54 // Returns true for all header fields. | |
| 55 static inline bool IsValidSlotImpl(HeapObject* obj, int offset); | |
| 56 | |
| 57 template <typename ObjectVisitor> | |
| 58 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, | |
| 59 int end_offset, ObjectVisitor* v); | |
| 60 | |
| 61 template <typename StaticVisitor> | |
| 62 static inline void IterateBodyImpl(Heap* heap, HeapObject* obj, | |
| 63 int start_offset, int end_offset); | |
| 64 }; | |
| 65 | |
| 66 | |
| 67 // This class describes a body of an object of a fixed size | |
| 68 // in which all pointer fields are located in the [start_offset, end_offset) | |
| 69 // interval. | |
| 70 template <int start_offset, int end_offset, int size> | |
| 71 class FixedBodyDescriptor final : public BodyDescriptorBase { | |
| 72 public: | |
| 73 static const int kStartOffset = start_offset; | |
| 74 static const int kEndOffset = end_offset; | |
| 75 static const int kSize = size; | |
| 76 | |
| 77 static bool IsValidSlot(HeapObject* obj, int offset) { | |
| 78 return offset >= kStartOffset && offset < kEndOffset; | |
| 79 } | |
| 80 | |
| 81 template <typename ObjectVisitor> | |
| 82 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) { | |
| 83 IterateBodyImpl(obj, start_offset, end_offset, v); | |
| 84 } | |
| 85 | |
| 86 template <typename ObjectVisitor> | |
| 87 static inline void IterateBody(HeapObject* obj, int object_size, | |
| 88 ObjectVisitor* v) { | |
| 89 IterateBody(obj, v); | |
| 90 } | |
| 91 | |
| 92 template <typename StaticVisitor> | |
| 93 static inline void IterateBody(HeapObject* obj) { | |
| 94 Heap* heap = obj->GetHeap(); | |
| 95 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, end_offset); | |
| 96 } | |
| 97 | |
| 98 template <typename StaticVisitor> | |
| 99 static inline void IterateBody(HeapObject* obj, int object_size) { | |
| 100 IterateBody(obj); | |
| 101 } | |
| 102 }; | |
| 103 | |
| 104 | |
| 105 // This class describes a body of an object of a variable size | |
| 106 // in which all pointer fields are located in the [start_offset, object_size) | |
| 107 // interval. | |
| 108 template <int start_offset> | |
| 109 class FlexibleBodyDescriptor final : public BodyDescriptorBase { | |
| 110 public: | |
| 111 static const int kStartOffset = start_offset; | |
| 112 | |
| 113 static bool IsValidSlot(HeapObject* obj, int offset) { | |
| 114 if (offset < kStartOffset) return false; | |
| 115 return IsValidSlotImpl(obj, offset); | |
| 116 } | |
| 117 | |
| 118 template <typename ObjectVisitor> | |
| 119 static inline void IterateBody(HeapObject* obj, int object_size, | |
| 120 ObjectVisitor* v) { | |
| 121 IterateBodyImpl(obj, start_offset, object_size, v); | |
| 122 } | |
| 123 | |
| 124 template <typename StaticVisitor> | |
| 125 static inline void IterateBody(HeapObject* obj, int object_size) { | |
| 126 Heap* heap = obj->GetHeap(); | |
| 127 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, object_size); | |
| 128 } | |
| 129 | |
| 130 static inline int SizeOf(Map* map, HeapObject* object); | |
| 131 }; | |
| 132 | |
| 133 | |
| 134 typedef FlexibleBodyDescriptor<HeapObject::kHeaderSize> StructBodyDescriptor; | |
| 135 | |
| 136 } // namespace internal | |
| 137 } // namespace v8 | |
| 138 | |
| 139 #endif // V8_OBJECTS_BODY_DESCRIPTORS_H_ | |
| OLD | NEW |