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