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 ObjectGroupRetainerInfo { |
| 67 ObjectGroupRetainerInfo(UniqueId id, RetainedObjectInfo* info) |
| 68 : id(id), info(info) {} |
| 69 |
| 70 bool operator==(const ObjectGroupRetainerInfo& other) const { |
| 71 return id == other.id; |
| 72 } |
| 73 |
| 74 bool operator<(const ObjectGroupRetainerInfo& 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, UniqueId id); |
| 225 |
| 226 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info = NULL); |
| 227 |
216 // Add an implicit references' group. | 228 // Add an implicit references' group. |
217 // Should be only used in GC callback function before a collection. | 229 // Should be only used in GC callback function before a collection. |
218 // All groups are destroyed after a mark-compact collection. | 230 // All groups are destroyed after a mark-compact collection. |
219 void AddImplicitReferences(HeapObject** parent, | 231 void AddImplicitReferences(HeapObject** parent, |
220 Object*** children, | 232 Object*** children, |
221 size_t length); | 233 size_t length); |
222 | 234 |
223 // Returns the object groups. | 235 List<ObjectGroupConnection>* object_groups() { |
224 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 236 return &object_groups_; |
| 237 } |
| 238 |
| 239 List<ObjectGroupRetainerInfo>* retainer_infos() { |
| 240 return &retainer_infos_; |
| 241 } |
225 | 242 |
226 // Returns the implicit references' groups. | 243 // Returns the implicit references' groups. |
227 List<ImplicitRefGroup*>* implicit_ref_groups() { | 244 List<ImplicitRefGroup*>* implicit_ref_groups() { |
228 return &implicit_ref_groups_; | 245 return &implicit_ref_groups_; |
229 } | 246 } |
230 | 247 |
231 // Remove bags, this should only happen after GC. | 248 // Remove bags, this should only happen after GC. |
232 void RemoveObjectGroups(); | 249 void RemoveObjectGroups(); |
233 void RemoveImplicitRefGroups(); | 250 void RemoveImplicitRefGroups(); |
234 | 251 |
(...skipping 28 matching lines...) Expand all Loading... |
263 | 280 |
264 // Free list of nodes. | 281 // Free list of nodes. |
265 Node* first_free_; | 282 Node* first_free_; |
266 | 283 |
267 // Contains all nodes holding new space objects. Note: when the list | 284 // Contains all nodes holding new space objects. Note: when the list |
268 // is accessed, some of the objects may have been promoted already. | 285 // is accessed, some of the objects may have been promoted already. |
269 List<Node*> new_space_nodes_; | 286 List<Node*> new_space_nodes_; |
270 | 287 |
271 int post_gc_processing_count_; | 288 int post_gc_processing_count_; |
272 | 289 |
273 List<ObjectGroup*> object_groups_; | 290 List<ObjectGroupConnection> object_groups_; |
| 291 List<ObjectGroupRetainerInfo> retainer_infos_; |
274 List<ImplicitRefGroup*> implicit_ref_groups_; | 292 List<ImplicitRefGroup*> implicit_ref_groups_; |
275 | 293 |
276 friend class Isolate; | 294 friend class Isolate; |
277 | 295 |
278 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 296 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
279 }; | 297 }; |
280 | 298 |
281 | 299 |
282 } } // namespace v8::internal | 300 } } // namespace v8::internal |
283 | 301 |
284 #endif // V8_GLOBAL_HANDLES_H_ | 302 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |