Chromium Code Reviews| 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 : public CustomlyAllocated { |
| 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 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( |
| 51 ~ObjectGroup(); | 51 malloc(OFFSET_OF(ObjectGroup, objects_[length]))); |
| 52 group->length_ = length; | |
| 53 group->info_ = info; | |
| 54 CopyWords(group->objects_, handles, length); | |
| 55 return group; | |
| 56 } | |
| 52 | 57 |
| 53 List<Object**> objects_; | 58 void Dispose() { |
| 59 free(this); | |
| 60 } | |
| 61 | |
| 62 size_t length_; | |
| 54 v8::RetainedObjectInfo* info_; | 63 v8::RetainedObjectInfo* info_; |
| 64 Object** objects_[1]; | |
|
antonm
2011/04/06 11:01:48
maybe add a comment that it's a placeholder for va
Vitaly Repeshko
2011/04/06 19:11:01
Done.
| |
| 55 | 65 |
| 56 private: | 66 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(ObjectGroup); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGroup); |
| 68 ~ObjectGroup(); | |
| 58 }; | 69 }; |
| 59 | 70 |
| 60 | 71 |
| 61 // An implicit references group consists of two parts: a parent object and | 72 // 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 | 73 // a list of children objects. If the parent is alive, all the children |
| 63 // are alive too. | 74 // are alive too. |
| 64 class ImplicitRefGroup : public Malloced { | 75 class ImplicitRefGroup : public CustomlyAllocated { |
| 65 public: | 76 public: |
| 66 ImplicitRefGroup() : children_(4) {} | 77 static ImplicitRefGroup* New(HeapObject** parent, |
| 67 ImplicitRefGroup(HeapObject* parent, size_t capacity) | 78 Object*** children, |
| 68 : parent_(parent), | 79 size_t length) { |
| 69 children_(static_cast<int>(capacity)) { } | 80 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( |
| 81 malloc(OFFSET_OF(ImplicitRefGroup, children_[length]))); | |
| 82 group->parent_ = parent; | |
| 83 group->length_ = length; | |
| 84 CopyWords(group->children_, children, length); | |
| 85 return group; | |
| 86 } | |
| 70 | 87 |
| 71 HeapObject* parent_; | 88 void Dispose() { |
| 72 List<Object**> children_; | 89 free(this); |
| 90 } | |
| 91 | |
| 92 HeapObject** parent_; | |
| 93 size_t length_; | |
| 94 Object** children_[1]; | |
|
antonm
2011/04/06 11:01:48
ditto
Vitaly Repeshko
2011/04/06 19:11:01
Done.
| |
| 73 | 95 |
| 74 private: | 96 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(ImplicitRefGroup); | 97 DISALLOW_IMPLICIT_CONSTRUCTORS(ImplicitRefGroup); |
| 98 ~ImplicitRefGroup(); | |
| 76 }; | 99 }; |
| 77 | 100 |
| 78 | 101 |
| 79 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); | 102 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); |
| 80 | 103 |
| 81 class GlobalHandles { | 104 class GlobalHandles { |
| 82 public: | 105 public: |
| 83 ~GlobalHandles(); | 106 ~GlobalHandles(); |
| 84 | 107 |
| 85 // Creates a new global handle that is alive until Destroy is called. | 108 // 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. | 170 // Add an object group. |
| 148 // Should be only used in GC callback function before a collection. | 171 // Should be only used in GC callback function before a collection. |
| 149 // All groups are destroyed after a mark-compact collection. | 172 // All groups are destroyed after a mark-compact collection. |
| 150 void AddObjectGroup(Object*** handles, | 173 void AddObjectGroup(Object*** handles, |
| 151 size_t length, | 174 size_t length, |
| 152 v8::RetainedObjectInfo* info); | 175 v8::RetainedObjectInfo* info); |
| 153 | 176 |
| 154 // Add an implicit references' group. | 177 // Add an implicit references' group. |
| 155 // Should be only used in GC callback function before a collection. | 178 // Should be only used in GC callback function before a collection. |
| 156 // All groups are destroyed after a mark-compact collection. | 179 // All groups are destroyed after a mark-compact collection. |
| 157 void AddImplicitReferences(HeapObject* parent, | 180 void AddImplicitReferences(HeapObject** parent, |
| 158 Object*** children, | 181 Object*** children, |
| 159 size_t length); | 182 size_t length); |
| 160 | 183 |
| 161 // Returns the object groups. | 184 // Returns the object groups. |
| 162 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 185 List<ObjectGroup*>* object_groups() { return &object_groups_; } |
| 163 | 186 |
| 164 // Returns the implicit references' groups. | 187 // Returns the implicit references' groups. |
| 165 List<ImplicitRefGroup*>* implicit_ref_groups() { | 188 List<ImplicitRefGroup*>* implicit_ref_groups() { |
| 166 return &implicit_ref_groups_; | 189 return &implicit_ref_groups_; |
| 167 } | 190 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 253 |
| 231 friend class Isolate; | 254 friend class Isolate; |
| 232 | 255 |
| 233 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 256 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 234 }; | 257 }; |
| 235 | 258 |
| 236 | 259 |
| 237 } } // namespace v8::internal | 260 } } // namespace v8::internal |
| 238 | 261 |
| 239 #endif // V8_GLOBAL_HANDLES_H_ | 262 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |