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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { | 100 enum WeaknessType { |
101 NORMAL_WEAK, // Embedder gets a handle to the dying object. | 101 NORMAL_WEAK, // Embedder gets a handle to the dying object. |
102 PHANTOM_WEAK, // Embedder gets the parameter they passed in earlier. | 102 // In the following cases, the embedder gets the parameter they passed in |
103 INTERNAL_FIELDS_WEAK // Embedder gets 2 internal fields from dying object. | 103 // earlier, and the 0, 1 or 2 first internal fields. Note that the internal |
| 104 // fields must contain aligned non-V8 pointers. Getting pointers to V8 |
| 105 // objects through this interface would be GC unsafe so in that case the |
| 106 // embedder gets a null pointer instead. |
| 107 PHANTOM_WEAK_0_INTERNAL_FIELDS, |
| 108 PHANTOM_WEAK_1_INTERNAL_FIELDS, |
| 109 PHANTOM_WEAK_2_INTERNAL_FIELDS |
104 }; | 110 }; |
105 | 111 |
106 | 112 |
107 class GlobalHandles { | 113 class GlobalHandles { |
108 public: | 114 public: |
109 ~GlobalHandles(); | 115 ~GlobalHandles(); |
110 | 116 |
111 // Creates a new global handle that is alive until Destroy is called. | 117 // Creates a new global handle that is alive until Destroy is called. |
112 Handle<Object> Create(Object* value); | 118 Handle<Object> Create(Object* value); |
113 | 119 |
(...skipping 18 matching lines...) Expand all Loading... |
132 // default the handle still contains a pointer to the object that is being | 138 // default the handle still contains a pointer to the object that is being |
133 // collected. For this reason the object is not collected until the next | 139 // collected. For this reason the object is not collected until the next |
134 // GC. For a phantom weak handle the handle is cleared (set to a Smi) | 140 // GC. For a phantom weak handle the handle is cleared (set to a Smi) |
135 // before the callback is invoked, but the handle can still be identified | 141 // before the callback is invoked, but the handle can still be identified |
136 // in the callback by using the location() of the handle. | 142 // in the callback by using the location() of the handle. |
137 static void MakeWeak(Object** location, void* parameter, | 143 static void MakeWeak(Object** location, void* parameter, |
138 WeakCallback weak_callback); | 144 WeakCallback weak_callback); |
139 | 145 |
140 // It would be nice to template this one, but it's really hard to get | 146 // 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. | 147 // 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( | 148 static void MakePhantom( |
146 Object** location, | 149 Object** location, void* parameter, int number_of_internal_fields, |
147 v8::InternalFieldsCallbackData<void, void>::Callback weak_callback, | 150 PhantomCallbackData<void, void, void>::Callback weak_callback); |
148 int16_t internal_field_index1, | |
149 int16_t internal_field_index2 = v8::Object::kNoInternalFieldIndex); | |
150 | 151 |
151 void RecordStats(HeapStats* stats); | 152 void RecordStats(HeapStats* stats); |
152 | 153 |
153 // Returns the current number of weak handles. | 154 // Returns the current number of weak handles. |
154 int NumberOfWeakHandles(); | 155 int NumberOfWeakHandles(); |
155 | 156 |
156 // Returns the current number of weak handles to global objects. | 157 // Returns the current number of weak handles to global objects. |
157 // These handles are also included in NumberOfWeakHandles(). | 158 // These handles are also included in NumberOfWeakHandles(). |
158 int NumberOfGlobalObjectWeakHandles(); | 159 int NumberOfGlobalObjectWeakHandles(); |
159 | 160 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 int PostScavengeProcessing(int initial_post_gc_processing_count); | 296 int PostScavengeProcessing(int initial_post_gc_processing_count); |
296 int PostMarkSweepProcessing(int initial_post_gc_processing_count); | 297 int PostMarkSweepProcessing(int initial_post_gc_processing_count); |
297 int DispatchPendingPhantomCallbacks(); | 298 int DispatchPendingPhantomCallbacks(); |
298 void UpdateListOfNewSpaceNodes(); | 299 void UpdateListOfNewSpaceNodes(); |
299 | 300 |
300 // Internal node structures. | 301 // Internal node structures. |
301 class Node; | 302 class Node; |
302 class NodeBlock; | 303 class NodeBlock; |
303 class NodeIterator; | 304 class NodeIterator; |
304 class PendingPhantomCallback; | 305 class PendingPhantomCallback; |
305 class PendingInternalFieldsCallback; | |
306 | 306 |
307 Isolate* isolate_; | 307 Isolate* isolate_; |
308 | 308 |
309 // Field always containing the number of handles to global objects. | 309 // Field always containing the number of handles to global objects. |
310 int number_of_global_handles_; | 310 int number_of_global_handles_; |
311 | 311 |
312 // List of all allocated node blocks. | 312 // List of all allocated node blocks. |
313 NodeBlock* first_block_; | 313 NodeBlock* first_block_; |
314 | 314 |
315 // List of node blocks with used nodes. | 315 // List of node blocks with used nodes. |
(...skipping 13 matching lines...) Expand all Loading... |
329 List<ObjectGroup*> object_groups_; | 329 List<ObjectGroup*> object_groups_; |
330 List<ImplicitRefGroup*> implicit_ref_groups_; | 330 List<ImplicitRefGroup*> implicit_ref_groups_; |
331 | 331 |
332 // Object groups and implicit references, temporary representation while | 332 // Object groups and implicit references, temporary representation while |
333 // constructing the groups. | 333 // constructing the groups. |
334 List<ObjectGroupConnection> object_group_connections_; | 334 List<ObjectGroupConnection> object_group_connections_; |
335 List<ObjectGroupRetainerInfo> retainer_infos_; | 335 List<ObjectGroupRetainerInfo> retainer_infos_; |
336 List<ObjectGroupConnection> implicit_ref_connections_; | 336 List<ObjectGroupConnection> implicit_ref_connections_; |
337 | 337 |
338 List<PendingPhantomCallback> pending_phantom_callbacks_; | 338 List<PendingPhantomCallback> pending_phantom_callbacks_; |
339 List<PendingInternalFieldsCallback> pending_internal_fields_callbacks_; | |
340 | 339 |
341 friend class Isolate; | 340 friend class Isolate; |
342 | 341 |
343 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 342 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
344 }; | 343 }; |
345 | 344 |
346 | 345 |
347 class GlobalHandles::PendingPhantomCallback { | 346 class GlobalHandles::PendingPhantomCallback { |
348 public: | 347 public: |
349 typedef PhantomCallbackData<void> Data; | 348 typedef PhantomCallbackData<void, void, void> Data; |
350 PendingPhantomCallback(Node* node, Data data, Data::Callback callback) | 349 PendingPhantomCallback(Node* node, Data data, Data::Callback callback) |
351 : node_(node), data_(data), callback_(callback) {} | 350 : node_(node), data_(data), callback_(callback) {} |
352 | 351 |
353 void invoke(); | 352 void invoke(); |
354 | 353 |
355 Node* node() { return node_; } | 354 Node* node() { return node_; } |
356 | 355 |
357 private: | 356 private: |
358 Node* node_; | 357 Node* node_; |
359 Data data_; | 358 Data data_; |
360 Data::Callback callback_; | 359 Data::Callback callback_; |
361 }; | 360 }; |
362 | 361 |
363 | 362 |
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 | |
378 class EternalHandles { | 363 class EternalHandles { |
379 public: | 364 public: |
380 enum SingletonHandle { | 365 enum SingletonHandle { |
381 I18N_TEMPLATE_ONE, | 366 I18N_TEMPLATE_ONE, |
382 I18N_TEMPLATE_TWO, | 367 I18N_TEMPLATE_TWO, |
383 DATE_CACHE_VERSION, | 368 DATE_CACHE_VERSION, |
384 | 369 |
385 NUMBER_OF_SINGLETON_HANDLES | 370 NUMBER_OF_SINGLETON_HANDLES |
386 }; | 371 }; |
387 | 372 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 List<int> new_space_indices_; | 426 List<int> new_space_indices_; |
442 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 427 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
443 | 428 |
444 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 429 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
445 }; | 430 }; |
446 | 431 |
447 | 432 |
448 } } // namespace v8::internal | 433 } } // namespace v8::internal |
449 | 434 |
450 #endif // V8_GLOBAL_HANDLES_H_ | 435 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |