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() { if (info_ != NULL) info_->Dispose(); } |
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 : public AllStatic { | 66 class GlobalHandles : public AllStatic { |
61 public: | 67 public: |
62 // Creates a new global handle that is alive until Destroy is called. | 68 // Creates a new global handle that is alive until Destroy is called. |
63 static Handle<Object> Create(Object* value); | 69 static Handle<Object> Create(Object* value); |
64 | 70 |
65 // Destroy a global handle. | 71 // Destroy a global handle. |
66 static void Destroy(Object** location); | 72 static void Destroy(Object** location); |
67 | 73 |
68 // Make the global handle weak and set the callback parameter for the | 74 // Make the global handle weak and set the callback parameter for the |
69 // handle. When the garbage collector recognizes that only weak global | 75 // handle. When the garbage collector recognizes that only weak global |
70 // handles point to an object the handles are cleared and the callback | 76 // handles point to an object the handles are cleared and the callback |
71 // function is invoked (for each handle) with the handle and corresponding | 77 // function is invoked (for each handle) with the handle and corresponding |
72 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The | 78 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
73 // reason is that Smi::FromInt(0) does not change during garage collection. | 79 // reason is that Smi::FromInt(0) does not change during garage collection. |
74 static void MakeWeak(Object** location, | 80 static void MakeWeak(Object** location, |
75 void* parameter, | 81 void* parameter, |
76 WeakReferenceCallback callback); | 82 WeakReferenceCallback callback); |
77 | 83 |
| 84 static void SetWrapperClassId(Object** location, uint16_t class_id); |
| 85 |
78 // Returns the current number of weak handles. | 86 // Returns the current number of weak handles. |
79 static int NumberOfWeakHandles() { return number_of_weak_handles_; } | 87 static int NumberOfWeakHandles() { return number_of_weak_handles_; } |
80 | 88 |
81 static void RecordStats(HeapStats* stats); | 89 static void RecordStats(HeapStats* stats); |
82 | 90 |
83 // Returns the current number of weak handles to global objects. | 91 // Returns the current number of weak handles to global objects. |
84 // These handles are also included in NumberOfWeakHandles(). | 92 // These handles are also included in NumberOfWeakHandles(). |
85 static int NumberOfGlobalObjectWeakHandles() { | 93 static int NumberOfGlobalObjectWeakHandles() { |
86 return number_of_global_object_weak_handles_; | 94 return number_of_global_object_weak_handles_; |
87 } | 95 } |
(...skipping 10 matching lines...) Expand all Loading... |
98 // Process pending weak handles. | 106 // Process pending weak handles. |
99 // Returns true if next major GC is likely to collect more garbage. | 107 // Returns true if next major GC is likely to collect more garbage. |
100 static bool PostGarbageCollectionProcessing(); | 108 static bool PostGarbageCollectionProcessing(); |
101 | 109 |
102 // Iterates over all strong handles. | 110 // Iterates over all strong handles. |
103 static void IterateStrongRoots(ObjectVisitor* v); | 111 static void IterateStrongRoots(ObjectVisitor* v); |
104 | 112 |
105 // Iterates over all handles. | 113 // Iterates over all handles. |
106 static void IterateAllRoots(ObjectVisitor* v); | 114 static void IterateAllRoots(ObjectVisitor* v); |
107 | 115 |
| 116 // Iterates over all handles that have embedder-assigned class ID. |
| 117 static void IterateAllRootsWithClassIds(ObjectVisitor* v); |
| 118 |
108 // Iterates over all weak roots in heap. | 119 // Iterates over all weak roots in heap. |
109 static void IterateWeakRoots(ObjectVisitor* v); | 120 static void IterateWeakRoots(ObjectVisitor* v); |
110 | 121 |
111 // Iterates over weak roots that are bound to a given callback. | 122 // Iterates over weak roots that are bound to a given callback. |
112 static void IterateWeakRoots(WeakReferenceGuest f, | 123 static void IterateWeakRoots(WeakReferenceGuest f, |
113 WeakReferenceCallback callback); | 124 WeakReferenceCallback callback); |
114 | 125 |
115 // Find all weak handles satisfying the callback predicate, mark | 126 // Find all weak handles satisfying the callback predicate, mark |
116 // them as pending. | 127 // them as pending. |
117 static void IdentifyWeakHandles(WeakSlotCallback f); | 128 static void IdentifyWeakHandles(WeakSlotCallback f); |
118 | 129 |
119 // Add an object group. | 130 // Add an object group. |
120 // Should only used in GC callback function before a collection. | 131 // Should only used in GC callback function before a collection. |
121 // All groups are destroyed after a mark-compact collection. | 132 // All groups are destroyed after a mark-compact collection. |
122 static void AddGroup(Object*** handles, size_t length); | 133 static void AddGroup(Object*** handles, |
| 134 size_t length, |
| 135 v8::RetainedObjectInfo* info); |
123 | 136 |
124 // Returns the object groups. | 137 // Returns the object groups. |
125 static List<ObjectGroup*>* ObjectGroups(); | 138 static List<ObjectGroup*>* ObjectGroups(); |
126 | 139 |
127 // Remove bags, this should only happen after GC. | 140 // Remove bags, this should only happen after GC. |
128 static void RemoveObjectGroups(); | 141 static void RemoveObjectGroups(); |
129 | 142 |
130 // Tear down the global handle structure. | 143 // Tear down the global handle structure. |
131 static void TearDown(); | 144 static void TearDown(); |
132 | 145 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 static Node* first_deallocated() { return first_deallocated_; } | 185 static Node* first_deallocated() { return first_deallocated_; } |
173 static void set_first_deallocated(Node* value) { | 186 static void set_first_deallocated(Node* value) { |
174 first_deallocated_ = value; | 187 first_deallocated_ = value; |
175 } | 188 } |
176 }; | 189 }; |
177 | 190 |
178 | 191 |
179 } } // namespace v8::internal | 192 } } // namespace v8::internal |
180 | 193 |
181 #endif // V8_GLOBAL_HANDLES_H_ | 194 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |