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 | 99 |
| 100 enum WeaknessType { |
| 101 NORMAL_WEAK, // Embedder gets a handle to the dying object. |
| 102 PHANTOM_WEAK, // Embedder gets the parameter they passed in earlier. |
| 103 INTERNAL_FIELDS_WEAK // Embedder gets 2 internal fields from dying object. |
| 104 }; |
| 105 |
| 106 |
100 class GlobalHandles { | 107 class GlobalHandles { |
101 public: | 108 public: |
102 ~GlobalHandles(); | 109 ~GlobalHandles(); |
103 | 110 |
104 // Creates a new global handle that is alive until Destroy is called. | 111 // Creates a new global handle that is alive until Destroy is called. |
105 Handle<Object> Create(Object* value); | 112 Handle<Object> Create(Object* value); |
106 | 113 |
107 // Copy a global handle | 114 // Copy a global handle |
108 static Handle<Object> CopyGlobal(Object** location); | 115 static Handle<Object> CopyGlobal(Object** location); |
109 | 116 |
(...skipping 11 matching lines...) Expand all Loading... |
121 // Make the global handle weak and set the callback parameter for the | 128 // Make the global handle weak and set the callback parameter for the |
122 // handle. When the garbage collector recognizes that only weak global | 129 // handle. When the garbage collector recognizes that only weak global |
123 // handles point to an object the callback function is invoked (for each | 130 // handles point to an object the callback function is invoked (for each |
124 // handle) with the handle and corresponding parameter as arguments. By | 131 // handle) with the handle and corresponding parameter as arguments. By |
125 // default the handle still contains a pointer to the object that is being | 132 // default the handle still contains a pointer to the object that is being |
126 // collected. For this reason the object is not collected until the next | 133 // collected. For this reason the object is not collected until the next |
127 // GC. For a phantom weak handle the handle is cleared (set to a Smi) | 134 // GC. For a phantom weak handle the handle is cleared (set to a Smi) |
128 // before the callback is invoked, but the handle can still be identified | 135 // before the callback is invoked, but the handle can still be identified |
129 // in the callback by using the location() of the handle. | 136 // in the callback by using the location() of the handle. |
130 static void MakeWeak(Object** location, void* parameter, | 137 static void MakeWeak(Object** location, void* parameter, |
131 WeakCallback weak_callback, | 138 WeakCallback weak_callback); |
132 PhantomState phantom = Nonphantom); | 139 |
| 140 // It would be nice to template this one, but it's really hard to get |
| 141 // the template instantiator to work right if you do. |
| 142 static void MakePhantom(Object** location, void* parameter, |
| 143 PhantomCallbackData<void>::Callback weak_callback); |
| 144 |
| 145 static void MakePhantom( |
| 146 Object** location, |
| 147 v8::InternalFieldsCallbackData<void, void>::Callback weak_callback, |
| 148 int16_t internal_field_index1, |
| 149 int16_t internal_field_index2 = v8::Object::kNoInternalFieldIndex); |
133 | 150 |
134 void RecordStats(HeapStats* stats); | 151 void RecordStats(HeapStats* stats); |
135 | 152 |
136 // Returns the current number of weak handles. | 153 // Returns the current number of weak handles. |
137 int NumberOfWeakHandles(); | 154 int NumberOfWeakHandles(); |
138 | 155 |
139 // Returns the current number of weak handles to global objects. | 156 // Returns the current number of weak handles to global objects. |
140 // These handles are also included in NumberOfWeakHandles(). | 157 // These handles are also included in NumberOfWeakHandles(). |
141 int NumberOfGlobalObjectWeakHandles(); | 158 int NumberOfGlobalObjectWeakHandles(); |
142 | 159 |
143 // Returns the current number of handles to global objects. | 160 // Returns the current number of handles to global objects. |
144 int global_handles_count() const { | 161 int global_handles_count() const { |
145 return number_of_global_handles_; | 162 return number_of_global_handles_; |
146 } | 163 } |
147 | 164 |
| 165 // Collect up data for the weak handle callbacks after GC has completed, but |
| 166 // before memory is reclaimed. |
| 167 void CollectPhantomCallbackData(); |
| 168 |
148 // Clear the weakness of a global handle. | 169 // Clear the weakness of a global handle. |
149 static void* ClearWeakness(Object** location); | 170 static void* ClearWeakness(Object** location); |
150 | 171 |
151 // Clear the weakness of a global handle. | 172 // Clear the weakness of a global handle. |
152 static void MarkIndependent(Object** location); | 173 static void MarkIndependent(Object** location); |
153 | 174 |
154 // Mark the reference to this object externaly unreachable. | 175 // Mark the reference to this object externaly unreachable. |
155 static void MarkPartiallyDependent(Object** location); | 176 static void MarkPartiallyDependent(Object** location); |
156 | 177 |
157 static bool IsIndependent(Object** location); | 178 static bool IsIndependent(Object** location); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 284 |
264 // Migrates data from the internal representation (object_group_connections_, | 285 // Migrates data from the internal representation (object_group_connections_, |
265 // retainer_infos_ and implicit_ref_connections_) to the public and more | 286 // retainer_infos_ and implicit_ref_connections_) to the public and more |
266 // efficient representation (object_groups_ and implicit_ref_groups_). | 287 // efficient representation (object_groups_ and implicit_ref_groups_). |
267 void ComputeObjectGroupsAndImplicitReferences(); | 288 void ComputeObjectGroupsAndImplicitReferences(); |
268 | 289 |
269 // v8::internal::List is inefficient even for small number of elements, if we | 290 // v8::internal::List is inefficient even for small number of elements, if we |
270 // don't assign any initial capacity. | 291 // don't assign any initial capacity. |
271 static const int kObjectGroupConnectionsCapacity = 20; | 292 static const int kObjectGroupConnectionsCapacity = 20; |
272 | 293 |
| 294 // Helpers for PostGarbageCollectionProcessing. |
| 295 int PostScavengeProcessing(int initial_post_gc_processing_count); |
| 296 int PostMarkSweepProcessing(int initial_post_gc_processing_count); |
| 297 int DispatchPendingPhantomCallbacks(); |
| 298 void UpdateListOfNewSpaceNodes(); |
| 299 |
273 // Internal node structures. | 300 // Internal node structures. |
274 class Node; | 301 class Node; |
275 class NodeBlock; | 302 class NodeBlock; |
276 class NodeIterator; | 303 class NodeIterator; |
| 304 class PendingPhantomCallback; |
| 305 class PendingInternalFieldsCallback; |
277 | 306 |
278 Isolate* isolate_; | 307 Isolate* isolate_; |
279 | 308 |
280 // Field always containing the number of handles to global objects. | 309 // Field always containing the number of handles to global objects. |
281 int number_of_global_handles_; | 310 int number_of_global_handles_; |
282 | 311 |
283 // List of all allocated node blocks. | 312 // List of all allocated node blocks. |
284 NodeBlock* first_block_; | 313 NodeBlock* first_block_; |
285 | 314 |
286 // List of node blocks with used nodes. | 315 // List of node blocks with used nodes. |
(...skipping 12 matching lines...) Expand all Loading... |
299 // representation. | 328 // representation. |
300 List<ObjectGroup*> object_groups_; | 329 List<ObjectGroup*> object_groups_; |
301 List<ImplicitRefGroup*> implicit_ref_groups_; | 330 List<ImplicitRefGroup*> implicit_ref_groups_; |
302 | 331 |
303 // Object groups and implicit references, temporary representation while | 332 // Object groups and implicit references, temporary representation while |
304 // constructing the groups. | 333 // constructing the groups. |
305 List<ObjectGroupConnection> object_group_connections_; | 334 List<ObjectGroupConnection> object_group_connections_; |
306 List<ObjectGroupRetainerInfo> retainer_infos_; | 335 List<ObjectGroupRetainerInfo> retainer_infos_; |
307 List<ObjectGroupConnection> implicit_ref_connections_; | 336 List<ObjectGroupConnection> implicit_ref_connections_; |
308 | 337 |
| 338 List<PendingPhantomCallback> pending_phantom_callbacks_; |
| 339 List<PendingInternalFieldsCallback> pending_internal_fields_callbacks_; |
| 340 |
309 friend class Isolate; | 341 friend class Isolate; |
310 | 342 |
311 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 343 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
312 }; | 344 }; |
313 | 345 |
314 | 346 |
| 347 class GlobalHandles::PendingPhantomCallback { |
| 348 public: |
| 349 typedef PhantomCallbackData<void> Data; |
| 350 PendingPhantomCallback(Node* node, Data data, Data::Callback callback) |
| 351 : node_(node), data_(data), callback_(callback) {} |
| 352 |
| 353 void invoke(); |
| 354 |
| 355 Node* node() { return node_; } |
| 356 |
| 357 private: |
| 358 Node* node_; |
| 359 Data data_; |
| 360 Data::Callback callback_; |
| 361 }; |
| 362 |
| 363 |
| 364 class GlobalHandles::PendingInternalFieldsCallback { |
| 365 public: |
| 366 typedef InternalFieldsCallbackData<void, void> Data; |
| 367 PendingInternalFieldsCallback(Data data, Data::Callback callback) |
| 368 : data_(data), callback_(callback) {} |
| 369 |
| 370 void invoke() { callback_(data_); } |
| 371 |
| 372 private: |
| 373 Data data_; |
| 374 Data::Callback callback_; |
| 375 }; |
| 376 |
| 377 |
315 class EternalHandles { | 378 class EternalHandles { |
316 public: | 379 public: |
317 enum SingletonHandle { | 380 enum SingletonHandle { |
318 I18N_TEMPLATE_ONE, | 381 I18N_TEMPLATE_ONE, |
319 I18N_TEMPLATE_TWO, | 382 I18N_TEMPLATE_TWO, |
320 DATE_CACHE_VERSION, | 383 DATE_CACHE_VERSION, |
321 | 384 |
322 NUMBER_OF_SINGLETON_HANDLES | 385 NUMBER_OF_SINGLETON_HANDLES |
323 }; | 386 }; |
324 | 387 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 List<int> new_space_indices_; | 441 List<int> new_space_indices_; |
379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 442 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
380 | 443 |
381 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 444 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
382 }; | 445 }; |
383 | 446 |
384 | 447 |
385 } } // namespace v8::internal | 448 } } // namespace v8::internal |
386 | 449 |
387 #endif // V8_GLOBAL_HANDLES_H_ | 450 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |