| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // 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 |
| 103 // earlier, and the 0, 1 or 2 first internal fields. Note that the internal | 103 // earlier, and 0 or 2 first internal fields. Note that the internal |
| 104 // fields must contain aligned non-V8 pointers. Getting pointers to V8 | 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 | 105 // objects through this interface would be GC unsafe so in that case the |
| 106 // embedder gets a null pointer instead. | 106 // embedder gets a null pointer instead. |
| 107 PHANTOM_WEAK_0_INTERNAL_FIELDS, | 107 PHANTOM_WEAK, |
| 108 PHANTOM_WEAK_1_INTERNAL_FIELDS, | |
| 109 PHANTOM_WEAK_2_INTERNAL_FIELDS | 108 PHANTOM_WEAK_2_INTERNAL_FIELDS |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 | 111 |
| 113 class GlobalHandles { | 112 class GlobalHandles { |
| 114 public: | 113 public: |
| 115 ~GlobalHandles(); | 114 ~GlobalHandles(); |
| 116 | 115 |
| 117 // Creates a new global handle that is alive until Destroy is called. | 116 // Creates a new global handle that is alive until Destroy is called. |
| 118 Handle<Object> Create(Object* value); | 117 Handle<Object> Create(Object* value); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 // default the handle still contains a pointer to the object that is being | 137 // default the handle still contains a pointer to the object that is being |
| 139 // collected. For this reason the object is not collected until the next | 138 // collected. For this reason the object is not collected until the next |
| 140 // GC. For a phantom weak handle the handle is cleared (set to a Smi) | 139 // GC. For a phantom weak handle the handle is cleared (set to a Smi) |
| 141 // before the callback is invoked, but the handle can still be identified | 140 // before the callback is invoked, but the handle can still be identified |
| 142 // in the callback by using the location() of the handle. | 141 // in the callback by using the location() of the handle. |
| 143 static void MakeWeak(Object** location, void* parameter, | 142 static void MakeWeak(Object** location, void* parameter, |
| 144 WeakCallback weak_callback); | 143 WeakCallback weak_callback); |
| 145 | 144 |
| 146 // It would be nice to template this one, but it's really hard to get | 145 // It would be nice to template this one, but it's really hard to get |
| 147 // the template instantiator to work right if you do. | 146 // the template instantiator to work right if you do. |
| 148 static void MakePhantom(Object** location, void* parameter, | 147 static void MakeWeak(Object** location, void* parameter, |
| 149 int number_of_internal_fields, | 148 WeakCallbackInfo<void>::Callback weak_callback, |
| 150 PhantomCallbackData<void>::Callback weak_callback); | 149 v8::WeakCallbackType type); |
| 151 | 150 |
| 152 void RecordStats(HeapStats* stats); | 151 void RecordStats(HeapStats* stats); |
| 153 | 152 |
| 154 // Returns the current number of weak handles. | 153 // Returns the current number of weak handles. |
| 155 int NumberOfWeakHandles(); | 154 int NumberOfWeakHandles(); |
| 156 | 155 |
| 157 // Returns the current number of weak handles to global objects. | 156 // Returns the current number of weak handles to global objects. |
| 158 // These handles are also included in NumberOfWeakHandles(). | 157 // These handles are also included in NumberOfWeakHandles(). |
| 159 int NumberOfGlobalObjectWeakHandles(); | 158 int NumberOfGlobalObjectWeakHandles(); |
| 160 | 159 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 List<PendingPhantomCallback> pending_phantom_callbacks_; | 341 List<PendingPhantomCallback> pending_phantom_callbacks_; |
| 343 | 342 |
| 344 friend class Isolate; | 343 friend class Isolate; |
| 345 | 344 |
| 346 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 345 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
| 347 }; | 346 }; |
| 348 | 347 |
| 349 | 348 |
| 350 class GlobalHandles::PendingPhantomCallback { | 349 class GlobalHandles::PendingPhantomCallback { |
| 351 public: | 350 public: |
| 352 typedef PhantomCallbackData<void> Data; | 351 typedef v8::WeakCallbackInfo<void> Data; |
| 353 PendingPhantomCallback(Node* node, Data data, Data::Callback callback) | 352 PendingPhantomCallback(Node* node, Data data, Data::Callback callback) |
| 354 : node_(node), data_(data), callback_(callback) {} | 353 : node_(node), data_(data), callback_(callback) {} |
| 355 | 354 |
| 356 void invoke(); | 355 void invoke(); |
| 357 | 356 |
| 358 Node* node() { return node_; } | 357 Node* node() { return node_; } |
| 359 | 358 |
| 360 private: | 359 private: |
| 361 Node* node_; | 360 Node* node_; |
| 362 Data data_; | 361 Data data_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 List<int> new_space_indices_; | 429 List<int> new_space_indices_; |
| 431 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 430 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
| 432 | 431 |
| 433 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 432 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
| 434 }; | 433 }; |
| 435 | 434 |
| 436 | 435 |
| 437 } } // namespace v8::internal | 436 } } // namespace v8::internal |
| 438 | 437 |
| 439 #endif // V8_GLOBAL_HANDLES_H_ | 438 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |