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_VISITING_H_ | 5 #ifndef V8_OBJECTS_VISITING_H_ |
6 #define V8_OBJECTS_VISITING_H_ | 6 #define V8_OBJECTS_VISITING_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/heap/heap.h" |
9 #include "src/heap/spaces.h" | 10 #include "src/heap/spaces.h" |
10 #include "src/layout-descriptor.h" | 11 #include "src/layout-descriptor.h" |
11 | 12 |
12 // This file provides base classes and auxiliary methods for defining | 13 // This file provides base classes and auxiliary methods for defining |
13 // static object visitors used during GC. | 14 // static object visitors used during GC. |
14 // Visiting HeapObject body with a normal ObjectVisitor requires performing | 15 // Visiting HeapObject body with a normal ObjectVisitor requires performing |
15 // two switches on object's instance type to determine object size and layout | 16 // two switches on object's instance type to determine object size and layout |
16 // and one or more virtual method calls on visitor itself. | 17 // and one or more virtual method calls on visitor itself. |
17 // Static visitor is different: it provides a dispatch table which contains | 18 // Static visitor is different: it provides a dispatch table which contains |
18 // pointers to specialized visit functions. Each map has the visitor_id | 19 // pointers to specialized visit functions. Each map has the visitor_id |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // id of specialized visitor from given instance size, base visitor id and | 93 // id of specialized visitor from given instance size, base visitor id and |
93 // generic visitor's id. | 94 // generic visitor's id. |
94 enum VisitorId { | 95 enum VisitorId { |
95 #define VISITOR_ID_ENUM_DECL(id) kVisit##id, | 96 #define VISITOR_ID_ENUM_DECL(id) kVisit##id, |
96 VISITOR_ID_LIST(VISITOR_ID_ENUM_DECL) | 97 VISITOR_ID_LIST(VISITOR_ID_ENUM_DECL) |
97 #undef VISITOR_ID_ENUM_DECL | 98 #undef VISITOR_ID_ENUM_DECL |
98 kVisitorIdCount, | 99 kVisitorIdCount, |
99 kVisitDataObject = kVisitDataObject2, | 100 kVisitDataObject = kVisitDataObject2, |
100 kVisitJSObject = kVisitJSObject2, | 101 kVisitJSObject = kVisitJSObject2, |
101 kVisitStruct = kVisitStruct2, | 102 kVisitStruct = kVisitStruct2, |
102 kMinObjectSizeInWords = 2 | |
103 }; | 103 }; |
104 | 104 |
105 // Visitor ID should fit in one byte. | 105 // Visitor ID should fit in one byte. |
106 STATIC_ASSERT(kVisitorIdCount <= 256); | 106 STATIC_ASSERT(kVisitorIdCount <= 256); |
107 | 107 |
108 // Determine which specialized visitor should be used for given instance type | 108 // Determine which specialized visitor should be used for given instance type |
109 // and instance type. | 109 // and instance type. |
110 static VisitorId GetVisitorId(int instance_type, int instance_size, | 110 static VisitorId GetVisitorId(int instance_type, int instance_size, |
111 bool has_unboxed_fields); | 111 bool has_unboxed_fields); |
112 | 112 |
113 // Determine which specialized visitor should be used for given map. | 113 // Determine which specialized visitor should be used for given map. |
114 static VisitorId GetVisitorId(Map* map); | 114 static VisitorId GetVisitorId(Map* map); |
115 | 115 |
116 // For visitors that allow specialization by size calculate VisitorId based | 116 // For visitors that allow specialization by size calculate VisitorId based |
117 // on size, base visitor id and generic visitor id. | 117 // on size, base visitor id and generic visitor id. |
118 static VisitorId GetVisitorIdForSize(VisitorId base, VisitorId generic, | 118 static VisitorId GetVisitorIdForSize(VisitorId base, VisitorId generic, |
119 int object_size, | 119 int object_size, |
120 bool has_unboxed_fields) { | 120 bool has_unboxed_fields) { |
121 DCHECK((base == kVisitDataObject) || (base == kVisitStruct) || | 121 DCHECK((base == kVisitDataObject) || (base == kVisitStruct) || |
122 (base == kVisitJSObject)); | 122 (base == kVisitJSObject)); |
123 DCHECK(IsAligned(object_size, kPointerSize)); | 123 DCHECK(IsAligned(object_size, kPointerSize)); |
124 DCHECK(kMinObjectSizeInWords * kPointerSize <= object_size); | 124 DCHECK(Heap::kMinObjectSizeInWords * kPointerSize <= object_size); |
125 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); | 125 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); |
126 DCHECK(!has_unboxed_fields || (base == kVisitJSObject)); | 126 DCHECK(!has_unboxed_fields || (base == kVisitJSObject)); |
127 | 127 |
128 if (has_unboxed_fields) return generic; | 128 if (has_unboxed_fields) return generic; |
129 | 129 |
130 int visitor_id = | 130 int visitor_id = Min( |
131 Min(base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords, | 131 base + (object_size >> kPointerSizeLog2) - Heap::kMinObjectSizeInWords, |
132 static_cast<int>(generic)); | 132 static_cast<int>(generic)); |
133 | 133 |
134 return static_cast<VisitorId>(visitor_id); | 134 return static_cast<VisitorId>(visitor_id); |
135 } | 135 } |
136 }; | 136 }; |
137 | 137 |
138 | 138 |
139 template <typename Callback> | 139 template <typename Callback> |
140 class VisitorDispatchTable { | 140 class VisitorDispatchTable { |
141 public: | 141 public: |
142 void CopyFrom(VisitorDispatchTable* other) { | 142 void CopyFrom(VisitorDispatchTable* other) { |
(...skipping 21 matching lines...) Expand all Loading... |
164 void RegisterSpecialization() { | 164 void RegisterSpecialization() { |
165 static const int size = object_size_in_words * kPointerSize; | 165 static const int size = object_size_in_words * kPointerSize; |
166 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size, false), | 166 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size, false), |
167 &Visitor::template VisitSpecialized<size>); | 167 &Visitor::template VisitSpecialized<size>); |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 template <typename Visitor, StaticVisitorBase::VisitorId base, | 171 template <typename Visitor, StaticVisitorBase::VisitorId base, |
172 StaticVisitorBase::VisitorId generic> | 172 StaticVisitorBase::VisitorId generic> |
173 void RegisterSpecializations() { | 173 void RegisterSpecializations() { |
174 STATIC_ASSERT((generic - base + StaticVisitorBase::kMinObjectSizeInWords) == | 174 STATIC_ASSERT((generic - base + Heap::kMinObjectSizeInWords) == 10); |
175 10); | |
176 RegisterSpecialization<Visitor, base, generic, 2>(); | 175 RegisterSpecialization<Visitor, base, generic, 2>(); |
177 RegisterSpecialization<Visitor, base, generic, 3>(); | 176 RegisterSpecialization<Visitor, base, generic, 3>(); |
178 RegisterSpecialization<Visitor, base, generic, 4>(); | 177 RegisterSpecialization<Visitor, base, generic, 4>(); |
179 RegisterSpecialization<Visitor, base, generic, 5>(); | 178 RegisterSpecialization<Visitor, base, generic, 5>(); |
180 RegisterSpecialization<Visitor, base, generic, 6>(); | 179 RegisterSpecialization<Visitor, base, generic, 6>(); |
181 RegisterSpecialization<Visitor, base, generic, 7>(); | 180 RegisterSpecialization<Visitor, base, generic, 7>(); |
182 RegisterSpecialization<Visitor, base, generic, 8>(); | 181 RegisterSpecialization<Visitor, base, generic, 8>(); |
183 RegisterSpecialization<Visitor, base, generic, 9>(); | 182 RegisterSpecialization<Visitor, base, generic, 9>(); |
184 Register(generic, &Visitor::Visit); | 183 Register(generic, &Visitor::Visit); |
185 } | 184 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // the next element. Given the head of the list, this function removes dead | 488 // the next element. Given the head of the list, this function removes dead |
490 // elements from the list and if requested records slots for next-element | 489 // elements from the list and if requested records slots for next-element |
491 // pointers. The template parameter T is a WeakListVisitor that defines how to | 490 // pointers. The template parameter T is a WeakListVisitor that defines how to |
492 // access the next-element pointers. | 491 // access the next-element pointers. |
493 template <class T> | 492 template <class T> |
494 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); | 493 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); |
495 } | 494 } |
496 } // namespace v8::internal | 495 } // namespace v8::internal |
497 | 496 |
498 #endif // V8_OBJECTS_VISITING_H_ | 497 #endif // V8_OBJECTS_VISITING_H_ |
OLD | NEW |