| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Callback function on handling weak global handles. | 42 // Callback function on handling weak global handles. |
| 43 // typedef bool (*WeakSlotCallback)(Object** pointer); | 43 // typedef bool (*WeakSlotCallback)(Object** pointer); |
| 44 | 44 |
| 45 // An object group is treated like a single JS object: if one of object in | 45 // 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. | 46 // 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. | 47 // An object group is used to simulate object relationship in a DOM tree. |
| 48 class ObjectGroup : public Malloced { | 48 class ObjectGroup : public Malloced { |
| 49 public: | 49 public: |
| 50 ObjectGroup() : objects_(4) {} | 50 ObjectGroup() : objects_(4) {} |
| 51 explicit ObjectGroup(size_t capacity) | 51 ObjectGroup(size_t capacity, v8::RetainedObjectInfo* info) |
| 52 : objects_(static_cast<int>(capacity)) { } | 52 : objects_(static_cast<int>(capacity)), |
| 53 info_(info) { } |
| 54 ~ObjectGroup(); |
| 53 | 55 |
| 54 List<Object**> objects_; | 56 List<Object**> objects_; |
| 57 v8::RetainedObjectInfo* info_; |
| 58 |
| 59 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(ObjectGroup); |
| 55 }; | 61 }; |
| 56 | 62 |
| 57 | 63 |
| 58 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); | 64 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); |
| 59 | 65 |
| 60 class GlobalHandles { | 66 class GlobalHandles { |
| 61 public: | 67 public: |
| 62 ~GlobalHandles(); | 68 ~GlobalHandles(); |
| 63 | 69 |
| 64 // Creates a new global handle that is alive until Destroy is called. | 70 // Creates a new global handle that is alive until Destroy is called. |
| 65 Handle<Object> Create(Object* value); | 71 Handle<Object> Create(Object* value); |
| 66 | 72 |
| 67 // Destroy a global handle. | 73 // Destroy a global handle. |
| 68 void Destroy(Object** location); | 74 void Destroy(Object** location); |
| 69 | 75 |
| 70 // Make the global handle weak and set the callback parameter for the | 76 // Make the global handle weak and set the callback parameter for the |
| 71 // handle. When the garbage collector recognizes that only weak global | 77 // handle. When the garbage collector recognizes that only weak global |
| 72 // handles point to an object the handles are cleared and the callback | 78 // handles point to an object the handles are cleared and the callback |
| 73 // function is invoked (for each handle) with the handle and corresponding | 79 // function is invoked (for each handle) with the handle and corresponding |
| 74 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The | 80 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
| 75 // reason is that Smi::FromInt(0) does not change during garage collection. | 81 // reason is that Smi::FromInt(0) does not change during garage collection. |
| 76 void MakeWeak(Object** location, | 82 void MakeWeak(Object** location, |
| 77 void* parameter, | 83 void* parameter, |
| 78 WeakReferenceCallback callback); | 84 WeakReferenceCallback callback); |
| 79 | 85 |
| 86 static void SetWrapperClassId(Object** location, uint16_t class_id); |
| 87 |
| 80 // Returns the current number of weak handles. | 88 // Returns the current number of weak handles. |
| 81 int NumberOfWeakHandles() { return number_of_weak_handles_; } | 89 int NumberOfWeakHandles() { return number_of_weak_handles_; } |
| 82 | 90 |
| 83 void RecordStats(HeapStats* stats); | 91 void RecordStats(HeapStats* stats); |
| 84 | 92 |
| 85 // Returns the current number of weak handles to global objects. | 93 // Returns the current number of weak handles to global objects. |
| 86 // These handles are also included in NumberOfWeakHandles(). | 94 // These handles are also included in NumberOfWeakHandles(). |
| 87 int NumberOfGlobalObjectWeakHandles() { | 95 int NumberOfGlobalObjectWeakHandles() { |
| 88 return number_of_global_object_weak_handles_; | 96 return number_of_global_object_weak_handles_; |
| 89 } | 97 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 // Process pending weak handles. | 108 // Process pending weak handles. |
| 101 // Returns true if next major GC is likely to collect more garbage. | 109 // Returns true if next major GC is likely to collect more garbage. |
| 102 bool PostGarbageCollectionProcessing(); | 110 bool PostGarbageCollectionProcessing(); |
| 103 | 111 |
| 104 // Iterates over all strong handles. | 112 // Iterates over all strong handles. |
| 105 void IterateStrongRoots(ObjectVisitor* v); | 113 void IterateStrongRoots(ObjectVisitor* v); |
| 106 | 114 |
| 107 // Iterates over all handles. | 115 // Iterates over all handles. |
| 108 void IterateAllRoots(ObjectVisitor* v); | 116 void IterateAllRoots(ObjectVisitor* v); |
| 109 | 117 |
| 118 // Iterates over all handles that have embedder-assigned class ID. |
| 119 void IterateAllRootsWithClassIds(ObjectVisitor* v); |
| 120 |
| 110 // Iterates over all weak roots in heap. | 121 // Iterates over all weak roots in heap. |
| 111 void IterateWeakRoots(ObjectVisitor* v); | 122 void IterateWeakRoots(ObjectVisitor* v); |
| 112 | 123 |
| 113 // Iterates over weak roots that are bound to a given callback. | 124 // Iterates over weak roots that are bound to a given callback. |
| 114 void IterateWeakRoots(WeakReferenceGuest f, | 125 void IterateWeakRoots(WeakReferenceGuest f, |
| 115 WeakReferenceCallback callback); | 126 WeakReferenceCallback callback); |
| 116 | 127 |
| 117 // Find all weak handles satisfying the callback predicate, mark | 128 // Find all weak handles satisfying the callback predicate, mark |
| 118 // them as pending. | 129 // them as pending. |
| 119 void IdentifyWeakHandles(WeakSlotCallback f); | 130 void IdentifyWeakHandles(WeakSlotCallback f); |
| 120 | 131 |
| 121 // Add an object group. | 132 // Add an object group. |
| 122 // Should only used in GC callback function before a collection. | 133 // Should only used in GC callback function before a collection. |
| 123 // All groups are destroyed after a mark-compact collection. | 134 // All groups are destroyed after a mark-compact collection. |
| 124 void AddGroup(Object*** handles, size_t length); | 135 void AddGroup(Object*** handles, |
| 136 size_t length, |
| 137 v8::RetainedObjectInfo* info); |
| 125 | 138 |
| 126 // Returns the object groups. | 139 // Returns the object groups. |
| 127 List<ObjectGroup*>* object_groups() { return &object_groups_; } | 140 List<ObjectGroup*>* object_groups() { return &object_groups_; } |
| 128 | 141 |
| 129 // Remove bags, this should only happen after GC. | 142 // Remove bags, this should only happen after GC. |
| 130 void RemoveObjectGroups(); | 143 void RemoveObjectGroups(); |
| 131 | 144 |
| 132 // Tear down the global handle structure. | 145 // Tear down the global handle structure. |
| 133 void TearDown(); | 146 void TearDown(); |
| 134 | 147 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 199 |
| 187 friend class Isolate; | 200 friend class Isolate; |
| 188 | 201 |
| 189 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 202 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 190 }; | 203 }; |
| 191 | 204 |
| 192 | 205 |
| 193 } } // namespace v8::internal | 206 } } // namespace v8::internal |
| 194 | 207 |
| 195 #endif // V8_GLOBAL_HANDLES_H_ | 208 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |