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 26 matching lines...) Loading... | |
37 | 37 |
38 // Structure for tracking global handles. | 38 // Structure for tracking global handles. |
39 // A single list keeps all the allocated global handles. | 39 // A single list keeps all the allocated global handles. |
40 // Destroyed handles stay in the list but is added to the free list. | 40 // 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 | 41 // At GC the destroyed global handles are removed from the free list |
42 // and deallocated. | 42 // and deallocated. |
43 | 43 |
44 // An object group is treated like a single JS object: if one of object in | 44 // 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. | 45 // 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. | 46 // An object group is used to simulate object relationship in a DOM tree. |
47 class ObjectGroup { | 47 |
48 public: | 48 struct ObjectGroupConnection { |
49 static ObjectGroup* New(Object*** handles, | 49 ObjectGroupConnection(void* id, Object** object) |
50 size_t length, | 50 : id(id), object(object) {} |
51 v8::RetainedObjectInfo* info) { | 51 |
52 ASSERT(length > 0); | 52 bool operator==(const ObjectGroupConnection& other) const { |
53 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( | 53 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 } | 54 } |
60 | 55 |
61 void Dispose() { | 56 bool operator<(const ObjectGroupConnection& other) const { |
62 if (info_ != NULL) info_->Dispose(); | 57 return id < other.id; |
63 free(this); | |
64 } | 58 } |
65 | 59 |
66 size_t length_; | 60 void* id; |
67 v8::RetainedObjectInfo* info_; | 61 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 }; | 62 }; |
76 | 63 |
77 | 64 |
65 struct GroupRetainedObjectInfo { | |
66 GroupRetainedObjectInfo(void* id, RetainedObjectInfo* info) | |
67 : id(id), info(info) {} | |
68 | |
69 ~GroupRetainedObjectInfo(); | |
Sven Panne
2013/04/10 08:37:49
Kill me! :-)
marja
2013/04/10 09:31:07
Done.
| |
70 | |
71 bool operator==(const GroupRetainedObjectInfo& other) const { | |
72 return id == other.id; | |
73 } | |
74 | |
75 bool operator<(const GroupRetainedObjectInfo& other) const { | |
76 return id < other.id; | |
77 } | |
78 | |
79 void* id; | |
80 RetainedObjectInfo* info; | |
81 }; | |
82 | |
83 | |
78 // An implicit references group consists of two parts: a parent object and | 84 // 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 | 85 // a list of children objects. If the parent is alive, all the children |
80 // are alive too. | 86 // are alive too. |
81 class ImplicitRefGroup { | 87 class ImplicitRefGroup { |
82 public: | 88 public: |
83 static ImplicitRefGroup* New(HeapObject** parent, | 89 static ImplicitRefGroup* New(HeapObject** parent, |
84 Object*** children, | 90 Object*** children, |
85 size_t length) { | 91 size_t length) { |
86 ASSERT(length > 0); | 92 ASSERT(length > 0); |
87 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( | 93 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( |
(...skipping 118 matching lines...) Loading... | |
206 // can be skipped and false otherwise. | 212 // can be skipped and false otherwise. |
207 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); | 213 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); |
208 | 214 |
209 // Add an object group. | 215 // Add an object group. |
210 // Should be only used in GC callback function before a collection. | 216 // Should be only used in GC callback function before a collection. |
211 // All groups are destroyed after a garbage collection. | 217 // All groups are destroyed after a garbage collection. |
212 void AddObjectGroup(Object*** handles, | 218 void AddObjectGroup(Object*** handles, |
213 size_t length, | 219 size_t length, |
214 v8::RetainedObjectInfo* info); | 220 v8::RetainedObjectInfo* info); |
215 | 221 |
222 // Associates handle with the object group represented by id. | |
223 // Should be only used in GC callback function before a collection. | |
224 // All groups are destroyed after a garbage collection. | |
225 void SetObjectGroupId(Object** handle, | |
226 void* id); | |
227 | |
228 void SetRetainedObjectInfo(void* id, | |
229 RetainedObjectInfo* info = NULL); | |
230 | |
216 // Add an implicit references' group. | 231 // Add an implicit references' group. |
217 // Should be only used in GC callback function before a collection. | 232 // Should be only used in GC callback function before a collection. |
218 // All groups are destroyed after a mark-compact collection. | 233 // All groups are destroyed after a mark-compact collection. |
219 void AddImplicitReferences(HeapObject** parent, | 234 void AddImplicitReferences(HeapObject** parent, |
220 Object*** children, | 235 Object*** children, |
221 size_t length); | 236 size_t length); |
222 | 237 |
223 // Returns the object groups. | 238 List<ObjectGroupConnection>* object_groups() { |
224 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 239 return &object_groups_; |
240 } | |
241 | |
242 List<GroupRetainedObjectInfo>* retained_object_infos() { | |
243 return &retained_object_infos_; | |
244 } | |
225 | 245 |
226 // Returns the implicit references' groups. | 246 // Returns the implicit references' groups. |
227 List<ImplicitRefGroup*>* implicit_ref_groups() { | 247 List<ImplicitRefGroup*>* implicit_ref_groups() { |
228 return &implicit_ref_groups_; | 248 return &implicit_ref_groups_; |
229 } | 249 } |
230 | 250 |
231 // Remove bags, this should only happen after GC. | 251 // Remove bags, this should only happen after GC. |
232 void RemoveObjectGroups(); | 252 void RemoveObjectGroups(); |
233 void RemoveImplicitRefGroups(); | 253 void RemoveImplicitRefGroups(); |
234 | 254 |
(...skipping 28 matching lines...) Loading... | |
263 | 283 |
264 // Free list of nodes. | 284 // Free list of nodes. |
265 Node* first_free_; | 285 Node* first_free_; |
266 | 286 |
267 // Contains all nodes holding new space objects. Note: when the list | 287 // Contains all nodes holding new space objects. Note: when the list |
268 // is accessed, some of the objects may have been promoted already. | 288 // is accessed, some of the objects may have been promoted already. |
269 List<Node*> new_space_nodes_; | 289 List<Node*> new_space_nodes_; |
270 | 290 |
271 int post_gc_processing_count_; | 291 int post_gc_processing_count_; |
272 | 292 |
273 List<ObjectGroup*> object_groups_; | 293 List<ObjectGroupConnection> object_groups_; |
294 List<GroupRetainedObjectInfo> retained_object_infos_; | |
274 List<ImplicitRefGroup*> implicit_ref_groups_; | 295 List<ImplicitRefGroup*> implicit_ref_groups_; |
275 | 296 |
276 friend class Isolate; | 297 friend class Isolate; |
277 | 298 |
278 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 299 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
279 }; | 300 }; |
280 | 301 |
281 | 302 |
282 } } // namespace v8::internal | 303 } } // namespace v8::internal |
283 | 304 |
284 #endif // V8_GLOBAL_HANDLES_H_ | 305 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |