OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_GLOBAL_HANDLES_H_ | 5 #ifndef V8_GLOBAL_HANDLES_H_ |
6 #define V8_GLOBAL_HANDLES_H_ | 6 #define V8_GLOBAL_HANDLES_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "include/v8-profiler.h" | 9 #include "include/v8-profiler.h" |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 bool operator<(const ObjectGroupRetainerInfo& other) const { | 91 bool operator<(const ObjectGroupRetainerInfo& other) const { |
92 return id < other.id; | 92 return id < other.id; |
93 } | 93 } |
94 | 94 |
95 UniqueId id; | 95 UniqueId id; |
96 RetainedObjectInfo* info; | 96 RetainedObjectInfo* info; |
97 }; | 97 }; |
98 | 98 |
99 enum WeaknessType { | 99 enum WeaknessType { |
| 100 // Embedder gets a handle to the dying object. |
| 101 FINALIZER_WEAK, |
100 // In the following cases, the embedder gets the parameter they passed in | 102 // In the following cases, the embedder gets the parameter they passed in |
101 // earlier, and 0 or 2 first internal fields. Note that the internal | 103 // earlier, and 0 or 2 first internal fields. Note that the internal |
102 // fields must contain aligned non-V8 pointers. Getting pointers to V8 | 104 // fields must contain aligned non-V8 pointers. Getting pointers to V8 |
103 // objects through this interface would be GC unsafe so in that case the | 105 // objects through this interface would be GC unsafe so in that case the |
104 // embedder gets a null pointer instead. | 106 // embedder gets a null pointer instead. |
105 PHANTOM_WEAK, | 107 PHANTOM_WEAK, |
106 PHANTOM_WEAK_2_INTERNAL_FIELDS, | 108 PHANTOM_WEAK_2_INTERNAL_FIELDS, |
107 // Embedder gets a handle to the dying object. | 109 // The handle is automatically reset by the garbage collector when |
108 FINALIZER_WEAK, | 110 // the object is no longer reachable. |
| 111 PHANTOM_WEAK_RESET_HANDLE |
109 }; | 112 }; |
110 | 113 |
111 class GlobalHandles { | 114 class GlobalHandles { |
112 public: | 115 public: |
113 ~GlobalHandles(); | 116 ~GlobalHandles(); |
114 | 117 |
115 // Creates a new global handle that is alive until Destroy is called. | 118 // Creates a new global handle that is alive until Destroy is called. |
116 Handle<Object> Create(Object* value); | 119 Handle<Object> Create(Object* value); |
117 | 120 |
118 // Copy a global handle | 121 // Copy a global handle |
119 static Handle<Object> CopyGlobal(Object** location); | 122 static Handle<Object> CopyGlobal(Object** location); |
120 | 123 |
121 // Destroy a global handle. | 124 // Destroy a global handle. |
122 static void Destroy(Object** location); | 125 static void Destroy(Object** location); |
123 | 126 |
124 // Make the global handle weak and set the callback parameter for the | 127 // Make the global handle weak and set the callback parameter for the |
125 // handle. When the garbage collector recognizes that only weak global | 128 // handle. When the garbage collector recognizes that only weak global |
126 // handles point to an object the callback function is invoked (for each | 129 // handles point to an object the callback function is invoked (for each |
127 // handle) with the handle and corresponding parameter as arguments. By | 130 // handle) with the handle and corresponding parameter as arguments. By |
128 // default the handle still contains a pointer to the object that is being | 131 // default the handle still contains a pointer to the object that is being |
129 // collected. For this reason the object is not collected until the next | 132 // collected. For this reason the object is not collected until the next |
130 // GC. For a phantom weak handle the handle is cleared (set to a Smi) | 133 // GC. For a phantom weak handle the handle is cleared (set to a Smi) |
131 // before the callback is invoked, but the handle can still be identified | 134 // before the callback is invoked, but the handle can still be identified |
132 // in the callback by using the location() of the handle. | 135 // in the callback by using the location() of the handle. |
133 static void MakeWeak(Object** location, void* parameter, | 136 static void MakeWeak(Object** location, void* parameter, |
134 WeakCallbackInfo<void>::Callback weak_callback, | 137 WeakCallbackInfo<void>::Callback weak_callback, |
135 v8::WeakCallbackType type); | 138 v8::WeakCallbackType type); |
136 | 139 |
| 140 static void MakeWeak(Object*** location_addr); |
| 141 |
137 void RecordStats(HeapStats* stats); | 142 void RecordStats(HeapStats* stats); |
138 | 143 |
139 // Returns the current number of weak handles. | 144 // Returns the current number of weak handles. |
140 int NumberOfWeakHandles(); | 145 int NumberOfWeakHandles(); |
141 | 146 |
142 // Returns the current number of weak handles to global objects. | 147 // Returns the current number of weak handles to global objects. |
143 // These handles are also included in NumberOfWeakHandles(). | 148 // These handles are also included in NumberOfWeakHandles(). |
144 int NumberOfGlobalObjectWeakHandles(); | 149 int NumberOfGlobalObjectWeakHandles(); |
145 | 150 |
146 // Returns the current number of handles to global objects. | 151 // Returns the current number of handles to global objects. |
147 int global_handles_count() const { | 152 int global_handles_count() const { |
148 return number_of_global_handles_; | 153 return number_of_global_handles_; |
149 } | 154 } |
150 | 155 |
| 156 size_t NumberOfPhantomHandleResets() { |
| 157 return number_of_phantom_handle_resets_; |
| 158 } |
| 159 |
| 160 void ResetNumberOfPhantomHandleResets() { |
| 161 number_of_phantom_handle_resets_ = 0; |
| 162 } |
| 163 |
151 // Clear the weakness of a global handle. | 164 // Clear the weakness of a global handle. |
152 static void* ClearWeakness(Object** location); | 165 static void* ClearWeakness(Object** location); |
153 | 166 |
154 // Mark the reference to this object independent of any object group. | 167 // Mark the reference to this object independent of any object group. |
155 static void MarkIndependent(Object** location); | 168 static void MarkIndependent(Object** location); |
156 | 169 |
157 // Mark the reference to this object externaly unreachable. | 170 // Mark the reference to this object externaly unreachable. |
158 static void MarkPartiallyDependent(Object** location); | 171 static void MarkPartiallyDependent(Object** location); |
159 | 172 |
160 static bool IsIndependent(Object** location); | 173 static bool IsIndependent(Object** location); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 336 |
324 // Free list of nodes. | 337 // Free list of nodes. |
325 Node* first_free_; | 338 Node* first_free_; |
326 | 339 |
327 // Contains all nodes holding new space objects. Note: when the list | 340 // Contains all nodes holding new space objects. Note: when the list |
328 // is accessed, some of the objects may have been promoted already. | 341 // is accessed, some of the objects may have been promoted already. |
329 List<Node*> new_space_nodes_; | 342 List<Node*> new_space_nodes_; |
330 | 343 |
331 int post_gc_processing_count_; | 344 int post_gc_processing_count_; |
332 | 345 |
| 346 size_t number_of_phantom_handle_resets_; |
| 347 |
333 // Object groups and implicit references, public and more efficient | 348 // Object groups and implicit references, public and more efficient |
334 // representation. | 349 // representation. |
335 List<ObjectGroup*> object_groups_; | 350 List<ObjectGroup*> object_groups_; |
336 List<ImplicitRefGroup*> implicit_ref_groups_; | 351 List<ImplicitRefGroup*> implicit_ref_groups_; |
337 | 352 |
338 // Object groups and implicit references, temporary representation while | 353 // Object groups and implicit references, temporary representation while |
339 // constructing the groups. | 354 // constructing the groups. |
340 List<ObjectGroupConnection> object_group_connections_; | 355 List<ObjectGroupConnection> object_group_connections_; |
341 List<ObjectGroupRetainerInfo> retainer_infos_; | 356 List<ObjectGroupRetainerInfo> retainer_infos_; |
342 List<ObjectGroupConnection> implicit_ref_connections_; | 357 List<ObjectGroupConnection> implicit_ref_connections_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 456 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
442 | 457 |
443 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 458 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
444 }; | 459 }; |
445 | 460 |
446 | 461 |
447 } // namespace internal | 462 } // namespace internal |
448 } // namespace v8 | 463 } // namespace v8 |
449 | 464 |
450 #endif // V8_GLOBAL_HANDLES_H_ | 465 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |