| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 // Structure for tracking global handles. | 36 // Structure for tracking global handles. |
| 37 // A single list keeps all the allocated global handles. | 37 // A single list keeps all the allocated global handles. |
| 38 // Destroyed handles stay in the list but is added to the free list. | 38 // Destroyed handles stay in the list but is added to the free list. |
| 39 // At GC the destroyed global handles are removed from the free list | 39 // At GC the destroyed global handles are removed from the free list |
| 40 // and deallocated. | 40 // and deallocated. |
| 41 | 41 |
| 42 // An object group is treated like a single JS object: if one of object in | 42 // An object group is treated like a single JS object: if one of object in |
| 43 // the group is alive, all objects in the same group are considered alive. | 43 // the group is alive, all objects in the same group are considered alive. |
| 44 // An object group is used to simulate object relationship in a DOM tree. | 44 // An object group is used to simulate object relationship in a DOM tree. |
| 45 class ObjectGroup : public Malloced { | 45 class ObjectGroup { |
| 46 public: | 46 public: |
| 47 ObjectGroup() : objects_(4) {} | 47 static ObjectGroup* New(Object*** handles, |
| 48 ObjectGroup(size_t capacity, v8::RetainedObjectInfo* info) | 48 size_t length, |
| 49 : objects_(static_cast<int>(capacity)), | 49 v8::RetainedObjectInfo* info) { |
| 50 info_(info) { } | 50 ASSERT(length > 0); |
| 51 ~ObjectGroup(); | 51 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( |
| 52 malloc(OFFSET_OF(ObjectGroup, objects_[length]))); |
| 53 group->length_ = length; |
| 54 group->info_ = info; |
| 55 CopyWords(group->objects_, handles, length); |
| 56 return group; |
| 57 } |
| 52 | 58 |
| 53 List<Object**> objects_; | 59 void Dispose() { |
| 60 free(this); |
| 61 } |
| 62 |
| 63 size_t length_; |
| 54 v8::RetainedObjectInfo* info_; | 64 v8::RetainedObjectInfo* info_; |
| 65 Object** objects_[1]; // Variable sized array. |
| 55 | 66 |
| 56 private: | 67 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(ObjectGroup); | 68 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGroup); |
| 69 ~ObjectGroup(); |
| 70 void* operator new(size_t size); |
| 71 void operator delete(void* p); |
| 58 }; | 72 }; |
| 59 | 73 |
| 60 | 74 |
| 61 // An implicit references group consists of two parts: a parent object and | 75 // An implicit references group consists of two parts: a parent object and |
| 62 // a list of children objects. If the parent is alive, all the children | 76 // a list of children objects. If the parent is alive, all the children |
| 63 // are alive too. | 77 // are alive too. |
| 64 class ImplicitRefGroup : public Malloced { | 78 class ImplicitRefGroup { |
| 65 public: | 79 public: |
| 66 ImplicitRefGroup() : children_(4) {} | 80 static ImplicitRefGroup* New(HeapObject** parent, |
| 67 ImplicitRefGroup(HeapObject* parent, size_t capacity) | 81 Object*** children, |
| 68 : parent_(parent), | 82 size_t length) { |
| 69 children_(static_cast<int>(capacity)) { } | 83 ASSERT(length > 0); |
| 84 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( |
| 85 malloc(OFFSET_OF(ImplicitRefGroup, children_[length]))); |
| 86 group->parent_ = parent; |
| 87 group->length_ = length; |
| 88 CopyWords(group->children_, children, length); |
| 89 return group; |
| 90 } |
| 70 | 91 |
| 71 HeapObject* parent_; | 92 void Dispose() { |
| 72 List<Object**> children_; | 93 free(this); |
| 94 } |
| 95 |
| 96 HeapObject** parent_; |
| 97 size_t length_; |
| 98 Object** children_[1]; // Variable sized array. |
| 73 | 99 |
| 74 private: | 100 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(ImplicitRefGroup); | 101 DISALLOW_IMPLICIT_CONSTRUCTORS(ImplicitRefGroup); |
| 102 ~ImplicitRefGroup(); |
| 103 void* operator new(size_t size); |
| 104 void operator delete(void* p); |
| 76 }; | 105 }; |
| 77 | 106 |
| 78 | 107 |
| 79 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); | 108 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); |
| 80 | 109 |
| 81 class GlobalHandles { | 110 class GlobalHandles { |
| 82 public: | 111 public: |
| 83 ~GlobalHandles(); | 112 ~GlobalHandles(); |
| 84 | 113 |
| 85 // Creates a new global handle that is alive until Destroy is called. | 114 // Creates a new global handle that is alive until Destroy is called. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Add an object group. | 176 // Add an object group. |
| 148 // Should be only used in GC callback function before a collection. | 177 // Should be only used in GC callback function before a collection. |
| 149 // All groups are destroyed after a mark-compact collection. | 178 // All groups are destroyed after a mark-compact collection. |
| 150 void AddObjectGroup(Object*** handles, | 179 void AddObjectGroup(Object*** handles, |
| 151 size_t length, | 180 size_t length, |
| 152 v8::RetainedObjectInfo* info); | 181 v8::RetainedObjectInfo* info); |
| 153 | 182 |
| 154 // Add an implicit references' group. | 183 // Add an implicit references' group. |
| 155 // Should be only used in GC callback function before a collection. | 184 // Should be only used in GC callback function before a collection. |
| 156 // All groups are destroyed after a mark-compact collection. | 185 // All groups are destroyed after a mark-compact collection. |
| 157 void AddImplicitReferences(HeapObject* parent, | 186 void AddImplicitReferences(HeapObject** parent, |
| 158 Object*** children, | 187 Object*** children, |
| 159 size_t length); | 188 size_t length); |
| 160 | 189 |
| 161 // Returns the object groups. | 190 // Returns the object groups. |
| 162 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 191 List<ObjectGroup*>* object_groups() { return &object_groups_; } |
| 163 | 192 |
| 164 // Returns the implicit references' groups. | 193 // Returns the implicit references' groups. |
| 165 List<ImplicitRefGroup*>* implicit_ref_groups() { | 194 List<ImplicitRefGroup*>* implicit_ref_groups() { |
| 166 return &implicit_ref_groups_; | 195 return &implicit_ref_groups_; |
| 167 } | 196 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 259 |
| 231 friend class Isolate; | 260 friend class Isolate; |
| 232 | 261 |
| 233 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 262 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 234 }; | 263 }; |
| 235 | 264 |
| 236 | 265 |
| 237 } } // namespace v8::internal | 266 } } // namespace v8::internal |
| 238 | 267 |
| 239 #endif // V8_GLOBAL_HANDLES_H_ | 268 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |