OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_GLOBAL_HANDLES_H_ | 28 #ifndef V8_GLOBAL_HANDLES_H_ |
29 #define V8_GLOBAL_HANDLES_H_ | 29 #define V8_GLOBAL_HANDLES_H_ |
30 | 30 |
31 #include "../include/v8.h" | |
31 #include "../include/v8-profiler.h" | 32 #include "../include/v8-profiler.h" |
32 | 33 |
33 #include "list.h" | 34 #include "list.h" |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 // Structure for tracking global handles. | 39 // Structure for tracking global handles. |
39 // A single list keeps all the allocated global handles. | 40 // A single list keeps all the allocated global handles. |
40 // Destroyed handles stay in the list but is added to the free list. | 41 // Destroyed handles stay in the list but is added to the free list. |
41 // At GC the destroyed global handles are removed from the free list | 42 // At GC the destroyed global handles are removed from the free list |
42 // and deallocated. | 43 // and deallocated. |
43 | 44 |
44 // An object group is treated like a single JS object: if one of object in | 45 // An object group is treated like a single JS object: if one of object in |
45 // the group is alive, all objects in the same group are considered alive. | 46 // the group is alive, all objects in the same group are considered alive. |
46 // An object group is used to simulate object relationship in a DOM tree. | 47 // An object group is used to simulate object relationship in a DOM tree. |
47 class ObjectGroup { | 48 |
48 public: | 49 struct ObjectGroupConnection { |
49 static ObjectGroup* New(Object*** handles, | 50 ObjectGroupConnection(UniqueId id, Object** object) |
50 size_t length, | 51 : id(id), object(object) {} |
51 v8::RetainedObjectInfo* info) { | 52 |
52 ASSERT(length > 0); | 53 bool operator==(const ObjectGroupConnection& other) const { |
53 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( | 54 return id == other.id; |
54 malloc(OFFSET_OF(ObjectGroup, objects_[length]))); | |
55 group->length_ = length; | |
56 group->info_ = info; | |
57 CopyWords(group->objects_, handles, static_cast<int>(length)); | |
58 return group; | |
59 } | 55 } |
60 | 56 |
61 void Dispose() { | 57 bool operator<(const ObjectGroupConnection& other) const { |
62 if (info_ != NULL) info_->Dispose(); | 58 return id < other.id; |
63 free(this); | |
64 } | 59 } |
65 | 60 |
66 size_t length_; | 61 UniqueId id; |
67 v8::RetainedObjectInfo* info_; | 62 Object** object; |
68 Object** objects_[1]; // Variable sized array. | |
69 | |
70 private: | |
71 void* operator new(size_t size); | |
72 void operator delete(void* p); | |
73 ~ObjectGroup(); | |
74 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGroup); | |
75 }; | 63 }; |
76 | 64 |
77 | 65 |
66 struct GroupRetainedObjectInfo { | |
Michael Starzinger
2013/04/10 10:54:16
suggestion: We could call this struct either "Obje
marja
2013/04/10 13:14:51
Renamed to ObjectGroupRetainerInfo.
| |
67 GroupRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info) | |
68 : id(id), info(info) {} | |
69 | |
70 bool operator==(const GroupRetainedObjectInfo& other) const { | |
71 return id == other.id; | |
72 } | |
73 | |
74 bool operator<(const GroupRetainedObjectInfo& other) const { | |
75 return id < other.id; | |
76 } | |
77 | |
78 UniqueId id; | |
79 RetainedObjectInfo* info; | |
80 }; | |
81 | |
82 | |
78 // An implicit references group consists of two parts: a parent object and | 83 // An implicit references group consists of two parts: a parent object and |
79 // a list of children objects. If the parent is alive, all the children | 84 // a list of children objects. If the parent is alive, all the children |
80 // are alive too. | 85 // are alive too. |
81 class ImplicitRefGroup { | 86 class ImplicitRefGroup { |
82 public: | 87 public: |
83 static ImplicitRefGroup* New(HeapObject** parent, | 88 static ImplicitRefGroup* New(HeapObject** parent, |
84 Object*** children, | 89 Object*** children, |
85 size_t length) { | 90 size_t length) { |
86 ASSERT(length > 0); | 91 ASSERT(length > 0); |
87 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( | 92 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 // can be skipped and false otherwise. | 211 // can be skipped and false otherwise. |
207 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); | 212 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); |
208 | 213 |
209 // Add an object group. | 214 // Add an object group. |
210 // Should be only used in GC callback function before a collection. | 215 // Should be only used in GC callback function before a collection. |
211 // All groups are destroyed after a garbage collection. | 216 // All groups are destroyed after a garbage collection. |
212 void AddObjectGroup(Object*** handles, | 217 void AddObjectGroup(Object*** handles, |
213 size_t length, | 218 size_t length, |
214 v8::RetainedObjectInfo* info); | 219 v8::RetainedObjectInfo* info); |
215 | 220 |
221 // Associates handle with the object group represented by id. | |
222 // Should be only used in GC callback function before a collection. | |
223 // All groups are destroyed after a garbage collection. | |
224 void SetObjectGroupId(Object** handle, | |
Michael Starzinger
2013/04/10 10:54:16
nit: Fits into one line.
marja
2013/04/10 13:14:51
Done.
| |
225 UniqueId id); | |
226 | |
227 void SetRetainedObjectInfo(UniqueId id, | |
Michael Starzinger
2013/04/10 10:54:16
nit: Fits into one line.
marja
2013/04/10 13:14:51
Done.
| |
228 RetainedObjectInfo* info = NULL); | |
229 | |
216 // Add an implicit references' group. | 230 // Add an implicit references' group. |
217 // Should be only used in GC callback function before a collection. | 231 // Should be only used in GC callback function before a collection. |
218 // All groups are destroyed after a mark-compact collection. | 232 // All groups are destroyed after a mark-compact collection. |
219 void AddImplicitReferences(HeapObject** parent, | 233 void AddImplicitReferences(HeapObject** parent, |
220 Object*** children, | 234 Object*** children, |
221 size_t length); | 235 size_t length); |
222 | 236 |
223 // Returns the object groups. | 237 List<ObjectGroupConnection>* object_groups() { |
224 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 238 return &object_groups_; |
239 } | |
240 | |
241 List<GroupRetainedObjectInfo>* retained_object_infos() { | |
242 return &retained_object_infos_; | |
243 } | |
225 | 244 |
226 // Returns the implicit references' groups. | 245 // Returns the implicit references' groups. |
227 List<ImplicitRefGroup*>* implicit_ref_groups() { | 246 List<ImplicitRefGroup*>* implicit_ref_groups() { |
228 return &implicit_ref_groups_; | 247 return &implicit_ref_groups_; |
229 } | 248 } |
230 | 249 |
231 // Remove bags, this should only happen after GC. | 250 // Remove bags, this should only happen after GC. |
232 void RemoveObjectGroups(); | 251 void RemoveObjectGroups(); |
233 void RemoveImplicitRefGroups(); | 252 void RemoveImplicitRefGroups(); |
234 | 253 |
(...skipping 28 matching lines...) Expand all Loading... | |
263 | 282 |
264 // Free list of nodes. | 283 // Free list of nodes. |
265 Node* first_free_; | 284 Node* first_free_; |
266 | 285 |
267 // Contains all nodes holding new space objects. Note: when the list | 286 // Contains all nodes holding new space objects. Note: when the list |
268 // is accessed, some of the objects may have been promoted already. | 287 // is accessed, some of the objects may have been promoted already. |
269 List<Node*> new_space_nodes_; | 288 List<Node*> new_space_nodes_; |
270 | 289 |
271 int post_gc_processing_count_; | 290 int post_gc_processing_count_; |
272 | 291 |
273 List<ObjectGroup*> object_groups_; | 292 List<ObjectGroupConnection> object_groups_; |
293 List<GroupRetainedObjectInfo> retained_object_infos_; | |
274 List<ImplicitRefGroup*> implicit_ref_groups_; | 294 List<ImplicitRefGroup*> implicit_ref_groups_; |
275 | 295 |
276 friend class Isolate; | 296 friend class Isolate; |
277 | 297 |
278 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 298 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
279 }; | 299 }; |
280 | 300 |
281 | 301 |
282 } } // namespace v8::internal | 302 } } // namespace v8::internal |
283 | 303 |
284 #endif // V8_GLOBAL_HANDLES_H_ | 304 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |