| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 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 // Callback function on handling weak global handles. | |
| 43 // typedef bool (*WeakSlotCallback)(Object** pointer); | |
| 44 | |
| 45 // 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 |
| 46 // 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. |
| 47 // 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. |
| 48 class ObjectGroup : public Malloced { | 45 class ObjectGroup : public Malloced { |
| 49 public: | 46 public: |
| 50 ObjectGroup() : objects_(4) {} | 47 ObjectGroup() : objects_(4) {} |
| 51 ObjectGroup(size_t capacity, v8::RetainedObjectInfo* info) | 48 ObjectGroup(size_t capacity, v8::RetainedObjectInfo* info) |
| 52 : objects_(static_cast<int>(capacity)), | 49 : objects_(static_cast<int>(capacity)), |
| 53 info_(info) { } | 50 info_(info) { } |
| 54 ~ObjectGroup(); | 51 ~ObjectGroup(); |
| 55 | 52 |
| 56 List<Object**> objects_; | 53 List<Object**> objects_; |
| 57 v8::RetainedObjectInfo* info_; | 54 v8::RetainedObjectInfo* info_; |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(ObjectGroup); | 57 DISALLOW_COPY_AND_ASSIGN(ObjectGroup); |
| 61 }; | 58 }; |
| 62 | 59 |
| 63 | 60 |
| 61 // 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 |
| 63 // are alive too. |
| 64 class ImplicitRefGroup : public Malloced { |
| 65 public: |
| 66 ImplicitRefGroup() : children_(4) {} |
| 67 ImplicitRefGroup(HeapObject* parent, size_t capacity) |
| 68 : parent_(parent), |
| 69 children_(static_cast<int>(capacity)) { } |
| 70 |
| 71 HeapObject* parent_; |
| 72 List<Object**> children_; |
| 73 |
| 74 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(ImplicitRefGroup); |
| 76 }; |
| 77 |
| 78 |
| 64 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); | 79 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); |
| 65 | 80 |
| 66 class GlobalHandles { | 81 class GlobalHandles { |
| 67 public: | 82 public: |
| 68 ~GlobalHandles(); | 83 ~GlobalHandles(); |
| 69 | 84 |
| 70 // Creates a new global handle that is alive until Destroy is called. | 85 // Creates a new global handle that is alive until Destroy is called. |
| 71 Handle<Object> Create(Object* value); | 86 Handle<Object> Create(Object* value); |
| 72 | 87 |
| 73 // Destroy a global handle. | 88 // Destroy a global handle. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 138 |
| 124 // Iterates over weak roots that are bound to a given callback. | 139 // Iterates over weak roots that are bound to a given callback. |
| 125 void IterateWeakRoots(WeakReferenceGuest f, | 140 void IterateWeakRoots(WeakReferenceGuest f, |
| 126 WeakReferenceCallback callback); | 141 WeakReferenceCallback callback); |
| 127 | 142 |
| 128 // Find all weak handles satisfying the callback predicate, mark | 143 // Find all weak handles satisfying the callback predicate, mark |
| 129 // them as pending. | 144 // them as pending. |
| 130 void IdentifyWeakHandles(WeakSlotCallback f); | 145 void IdentifyWeakHandles(WeakSlotCallback f); |
| 131 | 146 |
| 132 // Add an object group. | 147 // Add an object group. |
| 133 // Should only used in GC callback function before a collection. | 148 // Should be only used in GC callback function before a collection. |
| 134 // All groups are destroyed after a mark-compact collection. | 149 // All groups are destroyed after a mark-compact collection. |
| 135 void AddGroup(Object*** handles, | 150 void AddObjectGroup(Object*** handles, |
| 136 size_t length, | 151 size_t length, |
| 137 v8::RetainedObjectInfo* info); | 152 v8::RetainedObjectInfo* info); |
| 153 |
| 154 // Add an implicit references' group. |
| 155 // Should be only used in GC callback function before a collection. |
| 156 // All groups are destroyed after a mark-compact collection. |
| 157 void AddImplicitReferences(HeapObject* parent, |
| 158 Object*** children, |
| 159 size_t length); |
| 138 | 160 |
| 139 // Returns the object groups. | 161 // Returns the object groups. |
| 140 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 162 List<ObjectGroup*>* object_groups() { return &object_groups_; } |
| 141 | 163 |
| 164 // Returns the implicit references' groups. |
| 165 static List<ImplicitRefGroup*>* ImplicitRefGroups(); |
| 166 |
| 142 // Remove bags, this should only happen after GC. | 167 // Remove bags, this should only happen after GC. |
| 143 void RemoveObjectGroups(); | 168 void RemoveObjectGroups(); |
| 169 static void RemoveImplicitRefGroups(); |
| 144 | 170 |
| 145 // Tear down the global handle structure. | 171 // Tear down the global handle structure. |
| 146 void TearDown(); | 172 void TearDown(); |
| 147 | 173 |
| 148 Isolate* isolate() { return isolate_; } | 174 Isolate* isolate() { return isolate_; } |
| 149 | 175 |
| 150 #ifdef DEBUG | 176 #ifdef DEBUG |
| 151 void PrintStats(); | 177 void PrintStats(); |
| 152 void Print(); | 178 void Print(); |
| 153 #endif | 179 #endif |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 227 |
| 202 friend class Isolate; | 228 friend class Isolate; |
| 203 | 229 |
| 204 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 230 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 205 }; | 231 }; |
| 206 | 232 |
| 207 | 233 |
| 208 } } // namespace v8::internal | 234 } } // namespace v8::internal |
| 209 | 235 |
| 210 #endif // V8_GLOBAL_HANDLES_H_ | 236 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |