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

Side by Side Diff: src/objects-body-descriptors.h

Issue 1440243002: Object's body descriptors refactoring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@new-visitor-base
Patch Set: Refactoring & cleanup 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
(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_
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 IsPointerImpl(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 return IsPointerImpl(obj, offset);
115 }
116
117 template <typename ObjectVisitor>
118 static inline void IterateBody(HeapObject* obj, int object_size,
119 ObjectVisitor* v) {
120 IterateBodyImpl(obj, start_offset, object_size, v);
121 }
122
123 template <typename StaticVisitor>
124 static inline void IterateBody(HeapObject* obj, int object_size) {
125 Heap* heap = obj->GetHeap();
126 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, object_size);
127 }
128
129 static inline int SizeOf(Map* map, HeapObject* object);
130 };
131
132
133 typedef FlexibleBodyDescriptor<HeapObject::kHeaderSize> StructBodyDescriptor;
134
135 } // namespace internal
136 } // namespace v8
137
138 #endif // V8_OBJECTS_BODY_DESCRIPTORS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698