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 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 // Structure for tracking global handles. | 39 // Structure for tracking global handles. |
40 // A single list keeps all the allocated global handles. | 40 // A single list keeps all the allocated global handles. |
41 // 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. |
42 // 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 |
43 // and deallocated. | 43 // and deallocated. |
44 | 44 |
45 // Data structures for tracking object groups and implicit references. | |
46 | |
45 // An object group is treated like a single JS object: if one of object in | 47 // An object group is treated like a single JS object: if one of object in |
46 // the group is alive, all objects in the same group are considered alive. | 48 // the group is alive, all objects in the same group are considered alive. |
47 // An object group is used to simulate object relationship in a DOM tree. | 49 // An object group is used to simulate object relationship in a DOM tree. |
48 | 50 |
51 // An implicit references group consists of two parts: a parent object and a | |
52 // list of children objects. If the parent is alive, all the children are alive | |
53 // too. | |
54 | |
49 struct ObjectGroupConnection { | 55 struct ObjectGroupConnection { |
50 ObjectGroupConnection(UniqueId id, Object** object) | 56 ObjectGroupConnection(UniqueId id, Object** object) |
51 : id(id), object(object) {} | 57 : id(id), object(object) {} |
52 | 58 |
53 bool operator==(const ObjectGroupConnection& other) const { | 59 bool operator==(const ObjectGroupConnection& other) const { |
54 return id == other.id; | 60 return id == other.id; |
55 } | 61 } |
56 | 62 |
57 bool operator<(const ObjectGroupConnection& other) const { | 63 bool operator<(const ObjectGroupConnection& other) const { |
58 return id < other.id; | 64 return id < other.id; |
(...skipping 14 matching lines...) Expand all Loading... | |
73 | 79 |
74 bool operator<(const ObjectGroupRetainerInfo& other) const { | 80 bool operator<(const ObjectGroupRetainerInfo& other) const { |
75 return id < other.id; | 81 return id < other.id; |
76 } | 82 } |
77 | 83 |
78 UniqueId id; | 84 UniqueId id; |
79 RetainedObjectInfo* info; | 85 RetainedObjectInfo* info; |
80 }; | 86 }; |
81 | 87 |
82 | 88 |
83 // An implicit references group consists of two parts: a parent object and | 89 struct ObjectGroupRepresentativeObject { |
Michael Starzinger
2013/04/16 10:42:16
Let's just call this structure "ObjectGroupReprese
marja
2013/04/16 12:28:37
Done.
| |
84 // a list of children objects. If the parent is alive, all the children | 90 ObjectGroupRepresentativeObject(UniqueId id, |
85 // are alive too. | 91 HeapObject** object) |
86 class ImplicitRefGroup { | 92 : id(id), object(object) {} |
87 public: | 93 |
88 static ImplicitRefGroup* New(HeapObject** parent, | 94 bool operator==(const ObjectGroupRepresentativeObject& other) const { |
89 Object*** children, | 95 return id == other.id; |
90 size_t length) { | |
91 ASSERT(length > 0); | |
92 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( | |
93 malloc(OFFSET_OF(ImplicitRefGroup, children_[length]))); | |
94 group->parent_ = parent; | |
95 group->length_ = length; | |
96 CopyWords(group->children_, children, static_cast<int>(length)); | |
97 return group; | |
98 } | 96 } |
99 | 97 |
100 void Dispose() { | 98 bool operator<(const ObjectGroupRepresentativeObject& other) const { |
101 free(this); | 99 return id < other.id; |
102 } | 100 } |
103 | 101 |
104 HeapObject** parent_; | 102 UniqueId id; |
105 size_t length_; | 103 HeapObject** object; |
106 Object** children_[1]; // Variable sized array. | |
107 | |
108 private: | |
109 void* operator new(size_t size); | |
110 void operator delete(void* p); | |
111 ~ImplicitRefGroup(); | |
112 DISALLOW_IMPLICIT_CONSTRUCTORS(ImplicitRefGroup); | |
113 }; | 104 }; |
114 | 105 |
115 | 106 |
116 class GlobalHandles { | 107 class GlobalHandles { |
117 public: | 108 public: |
118 ~GlobalHandles(); | 109 ~GlobalHandles(); |
119 | 110 |
120 // Creates a new global handle that is alive until Destroy is called. | 111 // Creates a new global handle that is alive until Destroy is called. |
121 Handle<Object> Create(Object* value); | 112 Handle<Object> Create(Object* value); |
122 | 113 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 // All groups are destroyed after a garbage collection. | 207 // All groups are destroyed after a garbage collection. |
217 void AddObjectGroup(Object*** handles, | 208 void AddObjectGroup(Object*** handles, |
218 size_t length, | 209 size_t length, |
219 v8::RetainedObjectInfo* info); | 210 v8::RetainedObjectInfo* info); |
220 | 211 |
221 // Associates handle with the object group represented by id. | 212 // Associates handle with the object group represented by id. |
222 // Should be only used in GC callback function before a collection. | 213 // Should be only used in GC callback function before a collection. |
223 // All groups are destroyed after a garbage collection. | 214 // All groups are destroyed after a garbage collection. |
224 void SetObjectGroupId(Object** handle, UniqueId id); | 215 void SetObjectGroupId(Object** handle, UniqueId id); |
225 | 216 |
226 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info = NULL); | 217 // Set RetainedObjectInfo for an object group. Should not be called more than |
218 // once for a group. Should not be called for a group which contains no | |
219 // handles. | |
220 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); | |
221 | |
222 // Sets a representative object for an object group. Should not be called more | |
223 // than once for a group. Should not be called for a group which contains no | |
224 // handles. | |
225 void SetRepresentativeObject(UniqueId id, HeapObject** representative_object); | |
227 | 226 |
228 // Add an implicit references' group. | 227 // Add an implicit references' group. |
229 // Should be only used in GC callback function before a collection. | 228 // Should be only used in GC callback function before a collection. |
230 // All groups are destroyed after a mark-compact collection. | 229 // All groups are destroyed after a mark-compact collection. |
231 void AddImplicitReferences(HeapObject** parent, | 230 void AddImplicitReferences(HeapObject** parent, |
232 Object*** children, | 231 Object*** children, |
233 size_t length); | 232 size_t length); |
234 | 233 |
234 // Adds an implicit reference from a group (representative object of that | |
235 // group) to an object. Should be only used in GC callback function before a | |
236 // collection. All implicit references are destroyed after a mark-compact | |
237 // collection. | |
238 void AddImplicitReference(UniqueId id, Object** child); | |
239 | |
235 List<ObjectGroupConnection>* object_groups() { | 240 List<ObjectGroupConnection>* object_groups() { |
236 return &object_groups_; | 241 return &object_groups_; |
237 } | 242 } |
238 | 243 |
239 List<ObjectGroupRetainerInfo>* retainer_infos() { | 244 List<ObjectGroupRetainerInfo>* retainer_infos() { |
240 return &retainer_infos_; | 245 return &retainer_infos_; |
241 } | 246 } |
242 | 247 |
243 // Returns the implicit references' groups. | 248 List<ObjectGroupConnection>* implicit_ref_groups() { |
244 List<ImplicitRefGroup*>* implicit_ref_groups() { | |
245 return &implicit_ref_groups_; | 249 return &implicit_ref_groups_; |
246 } | 250 } |
247 | 251 |
252 List<ObjectGroupRepresentativeObject>* representative_objects() { | |
253 return &representative_objects_; | |
254 } | |
255 | |
248 // Remove bags, this should only happen after GC. | 256 // Remove bags, this should only happen after GC. |
249 void RemoveObjectGroups(); | 257 void RemoveObjectGroups(); |
250 void RemoveImplicitRefGroups(); | 258 void RemoveImplicitRefGroups(); |
251 | 259 |
252 // Tear down the global handle structure. | 260 // Tear down the global handle structure. |
253 void TearDown(); | 261 void TearDown(); |
254 | 262 |
255 Isolate* isolate() { return isolate_; } | 263 Isolate* isolate() { return isolate_; } |
256 | 264 |
257 #ifdef DEBUG | 265 #ifdef DEBUG |
(...skipping 22 matching lines...) Expand all Loading... | |
280 | 288 |
281 // Free list of nodes. | 289 // Free list of nodes. |
282 Node* first_free_; | 290 Node* first_free_; |
283 | 291 |
284 // Contains all nodes holding new space objects. Note: when the list | 292 // Contains all nodes holding new space objects. Note: when the list |
285 // is accessed, some of the objects may have been promoted already. | 293 // is accessed, some of the objects may have been promoted already. |
286 List<Node*> new_space_nodes_; | 294 List<Node*> new_space_nodes_; |
287 | 295 |
288 int post_gc_processing_count_; | 296 int post_gc_processing_count_; |
289 | 297 |
298 // Object groups. | |
290 List<ObjectGroupConnection> object_groups_; | 299 List<ObjectGroupConnection> object_groups_; |
291 List<ObjectGroupRetainerInfo> retainer_infos_; | 300 List<ObjectGroupRetainerInfo> retainer_infos_; |
292 List<ImplicitRefGroup*> implicit_ref_groups_; | 301 List<ObjectGroupRepresentativeObject> representative_objects_; |
302 | |
303 // Implicit references. | |
304 List<ObjectGroupConnection> implicit_ref_groups_; | |
293 | 305 |
294 friend class Isolate; | 306 friend class Isolate; |
295 | 307 |
296 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 308 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
297 }; | 309 }; |
298 | 310 |
299 | 311 |
300 } } // namespace v8::internal | 312 } } // namespace v8::internal |
301 | 313 |
302 #endif // V8_GLOBAL_HANDLES_H_ | 314 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |