| 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...) Expand all 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 struct ObjectGroup { |
| 48 public: | 48 ObjectGroup() |
| 49 static ObjectGroup* New(Object*** handles, | 49 : info(NULL) {} |
| 50 size_t length, | 50 |
| 51 v8::RetainedObjectInfo* info) { | 51 ~ObjectGroup(); |
| 52 ASSERT(length > 0); | 52 |
| 53 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( | 53 v8::RetainedObjectInfo* info; |
| 54 malloc(OFFSET_OF(ObjectGroup, objects_[length]))); | 54 List<Object**> objects; |
| 55 group->length_ = length; | 55 }; |
| 56 group->info_ = info; | 56 |
| 57 CopyWords(group->objects_, handles, static_cast<int>(length)); | 57 |
| 58 return group; | 58 struct ObjectGroupConnection { |
| 59 ObjectGroupConnection(void* id, Object** object) |
| 60 : id(id), object(object) {} |
| 61 |
| 62 bool operator==(const ObjectGroupConnection& other) const { |
| 63 return id == other.id; |
| 59 } | 64 } |
| 60 | 65 |
| 61 void Dispose() { | 66 bool operator<(const ObjectGroupConnection& other) const { |
| 62 if (info_ != NULL) info_->Dispose(); | 67 return id < other.id; |
| 63 free(this); | |
| 64 } | 68 } |
| 65 | 69 |
| 66 size_t length_; | 70 void* id; |
| 67 v8::RetainedObjectInfo* info_; | 71 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 }; | 72 }; |
| 76 | 73 |
| 77 | 74 |
| 75 struct GroupRetainedObjectInfo { |
| 76 GroupRetainedObjectInfo(void* id, RetainedObjectInfo* info) |
| 77 : id(id), info(info) {} |
| 78 |
| 79 ~GroupRetainedObjectInfo(); |
| 80 |
| 81 bool operator==(const GroupRetainedObjectInfo& other) const { |
| 82 return id == other.id; |
| 83 } |
| 84 |
| 85 bool operator<(const GroupRetainedObjectInfo& other) const { |
| 86 return id < other.id; |
| 87 } |
| 88 |
| 89 void* id; |
| 90 RetainedObjectInfo* info; |
| 91 }; |
| 92 |
| 78 // An implicit references group consists of two parts: a parent object and | 93 // 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 | 94 // a list of children objects. If the parent is alive, all the children |
| 80 // are alive too. | 95 // are alive too. |
| 81 class ImplicitRefGroup { | 96 class ImplicitRefGroup { |
| 82 public: | 97 public: |
| 83 static ImplicitRefGroup* New(HeapObject** parent, | 98 static ImplicitRefGroup* New(HeapObject** parent, |
| 84 Object*** children, | 99 Object*** children, |
| 85 size_t length) { | 100 size_t length) { |
| 86 ASSERT(length > 0); | 101 ASSERT(length > 0); |
| 87 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( | 102 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. | 221 // can be skipped and false otherwise. |
| 207 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); | 222 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); |
| 208 | 223 |
| 209 // Add an object group. | 224 // Add an object group. |
| 210 // Should be only used in GC callback function before a collection. | 225 // Should be only used in GC callback function before a collection. |
| 211 // All groups are destroyed after a garbage collection. | 226 // All groups are destroyed after a garbage collection. |
| 212 void AddObjectGroup(Object*** handles, | 227 void AddObjectGroup(Object*** handles, |
| 213 size_t length, | 228 size_t length, |
| 214 v8::RetainedObjectInfo* info); | 229 v8::RetainedObjectInfo* info); |
| 215 | 230 |
| 231 // Associates handle with the object group represented by id. |
| 232 // Should be only used in GC callback function before a collection. |
| 233 // All groups are destroyed after a garbage collection. |
| 234 void SetObjectGroupId(Object** handle, |
| 235 void* id); |
| 236 |
| 237 void SetRetainedObjectInfo(void* id, |
| 238 RetainedObjectInfo* info = NULL); |
| 239 |
| 216 // Add an implicit references' group. | 240 // Add an implicit references' group. |
| 217 // Should be only used in GC callback function before a collection. | 241 // Should be only used in GC callback function before a collection. |
| 218 // All groups are destroyed after a mark-compact collection. | 242 // All groups are destroyed after a mark-compact collection. |
| 219 void AddImplicitReferences(HeapObject** parent, | 243 void AddImplicitReferences(HeapObject** parent, |
| 220 Object*** children, | 244 Object*** children, |
| 221 size_t length); | 245 size_t length); |
| 222 | 246 |
| 223 // Returns the object groups. | 247 // Returns the object groups. Caller takes ownership of the list, and the |
| 224 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 248 // ObjectGroup pointers in it, and the RetainedObjectInfo pointers in the |
| 249 // object groups. |
| 250 List<ObjectGroup*>* object_groups(); |
| 225 | 251 |
| 226 // Returns the implicit references' groups. | 252 // Returns the implicit references' groups. |
| 227 List<ImplicitRefGroup*>* implicit_ref_groups() { | 253 List<ImplicitRefGroup*>* implicit_ref_groups() { |
| 228 return &implicit_ref_groups_; | 254 return &implicit_ref_groups_; |
| 229 } | 255 } |
| 230 | 256 |
| 231 // Remove bags, this should only happen after GC. | 257 // Remove bags, this should only happen after GC. |
| 232 void RemoveObjectGroups(); | 258 void RemoveObjectGroups(); |
| 233 void RemoveImplicitRefGroups(); | 259 void RemoveImplicitRefGroups(); |
| 234 | 260 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 263 | 289 |
| 264 // Free list of nodes. | 290 // Free list of nodes. |
| 265 Node* first_free_; | 291 Node* first_free_; |
| 266 | 292 |
| 267 // Contains all nodes holding new space objects. Note: when the list | 293 // Contains all nodes holding new space objects. Note: when the list |
| 268 // is accessed, some of the objects may have been promoted already. | 294 // is accessed, some of the objects may have been promoted already. |
| 269 List<Node*> new_space_nodes_; | 295 List<Node*> new_space_nodes_; |
| 270 | 296 |
| 271 int post_gc_processing_count_; | 297 int post_gc_processing_count_; |
| 272 | 298 |
| 273 List<ObjectGroup*> object_groups_; | 299 List<ObjectGroupConnection>* object_groups_; |
| 300 List<GroupRetainedObjectInfo> retained_object_infos_; |
| 274 List<ImplicitRefGroup*> implicit_ref_groups_; | 301 List<ImplicitRefGroup*> implicit_ref_groups_; |
| 275 | 302 |
| 276 friend class Isolate; | 303 friend class Isolate; |
| 277 | 304 |
| 278 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 305 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 279 }; | 306 }; |
| 280 | 307 |
| 281 | 308 |
| 282 } } // namespace v8::internal | 309 } } // namespace v8::internal |
| 283 | 310 |
| 284 #endif // V8_GLOBAL_HANDLES_H_ | 311 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |