Line data Source code
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_
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 : class BodyDescriptorBase BASE_EMBEDDED {
30 : public:
31 : template <typename ObjectVisitor>
32 : static inline void IteratePointers(HeapObject* obj, int start_offset,
33 : int end_offset, ObjectVisitor* v);
34 :
35 : template <typename ObjectVisitor>
36 : static inline void IteratePointer(HeapObject* obj, int offset,
37 : ObjectVisitor* v);
38 :
39 : protected:
40 : // Returns true for all header and embedder fields.
41 : static inline bool IsValidSlotImpl(HeapObject* obj, int offset);
42 :
43 : // Treats all header and embedder fields in the range as tagged.
44 : template <typename ObjectVisitor>
45 : static inline void IterateBodyImpl(HeapObject* obj, int start_offset,
46 : int end_offset, ObjectVisitor* v);
47 : };
48 :
49 :
50 : // This class describes a body of an object of a fixed size
51 : // in which all pointer fields are located in the [start_offset, end_offset)
52 : // interval.
53 : template <int start_offset, int end_offset, int size>
54 : class FixedBodyDescriptor final : public BodyDescriptorBase {
55 : public:
56 : static const int kStartOffset = start_offset;
57 : static const int kEndOffset = end_offset;
58 : static const int kSize = size;
59 :
60 : static bool IsValidSlot(HeapObject* obj, int offset) {
61 0 : return offset >= kStartOffset && offset < kEndOffset;
62 : }
63 :
64 : template <typename ObjectVisitor>
65 : static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) {
66 66841628 : IteratePointers(obj, start_offset, end_offset, v);
67 : }
68 :
69 : template <typename ObjectVisitor>
70 136590321 : static inline void IterateBody(HeapObject* obj, int object_size,
71 : ObjectVisitor* v) {
72 : IterateBody(obj, v);
73 136456578 : }
74 :
75 188719793 : static inline int SizeOf(Map* map, HeapObject* object) { return kSize; }
76 : };
77 :
78 :
79 : // This class describes a body of an object of a variable size
80 : // in which all pointer fields are located in the [start_offset, object_size)
81 : // interval.
82 : template <int start_offset>
83 : class FlexibleBodyDescriptor final : public BodyDescriptorBase {
84 : public:
85 : static const int kStartOffset = start_offset;
86 :
87 : static bool IsValidSlot(HeapObject* obj, int offset) {
88 0 : return (offset >= kStartOffset);
89 : }
90 :
91 : template <typename ObjectVisitor>
92 45113683 : static inline void IterateBody(HeapObject* obj, int object_size,
93 : ObjectVisitor* v) {
94 33142902 : IteratePointers(obj, start_offset, object_size, v);
95 45102865 : }
96 :
97 : static inline int SizeOf(Map* map, HeapObject* object);
98 : };
99 :
100 :
101 : typedef FlexibleBodyDescriptor<HeapObject::kHeaderSize> StructBodyDescriptor;
102 :
103 : } // namespace internal
104 : } // namespace v8
105 :
106 : #endif // V8_OBJECTS_BODY_DESCRIPTORS_H_
|