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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // Creates a new global handle that is alive until Destroy is called. | 104 // Creates a new global handle that is alive until Destroy is called. |
105 Handle<Object> Create(Object* value); | 105 Handle<Object> Create(Object* value); |
106 | 106 |
107 // Copy a global handle | 107 // Copy a global handle |
108 static Handle<Object> CopyGlobal(Object** location); | 108 static Handle<Object> CopyGlobal(Object** location); |
109 | 109 |
110 // Destroy a global handle. | 110 // Destroy a global handle. |
111 static void Destroy(Object** location); | 111 static void Destroy(Object** location); |
112 | 112 |
113 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; | 113 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; |
| 114 typedef PhantomCallbackData<void>::Callback PhantomCallback; |
114 | 115 |
115 // For a phantom weak reference, the callback does not have access to the | 116 // For a phantom weak reference, the callback does not have access to the |
116 // dying object. Phantom weak references are preferred because they allow | 117 // dying object. Phantom weak references are preferred because they allow |
117 // memory to be reclaimed in one GC cycle rather than two. However, for | 118 // memory to be reclaimed in one GC cycle rather than two. However, for |
118 // historical reasons the default is non-phantom. | 119 // historical reasons the default is non-phantom. |
119 enum PhantomState { Nonphantom, Phantom }; | 120 enum PhantomState { Nonphantom, Phantom }; |
120 | 121 |
121 // Make the global handle weak and set the callback parameter for the | 122 // Make the global handle weak and set the callback parameter for the |
122 // handle. When the garbage collector recognizes that only weak global | 123 // handle. When the garbage collector recognizes that only weak global |
123 // handles point to an object the callback function is invoked (for each | 124 // handles point to an object the callback function is invoked (for each |
124 // handle) with the handle and corresponding parameter as arguments. By | 125 // handle) with the handle and corresponding parameter as arguments. By |
125 // default the handle still contains a pointer to the object that is being | 126 // 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 | 127 // 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) | 128 // 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 | 129 // before the callback is invoked, but the handle can still be identified |
129 // in the callback by using the location() of the handle. | 130 // in the callback by using the location() of the handle. |
130 static void MakeWeak(Object** location, void* parameter, | 131 static void MakeWeak(Object** location, void* parameter, |
131 WeakCallback weak_callback, | 132 WeakCallback weak_callback); |
132 PhantomState phantom = Nonphantom); | 133 |
| 134 static void MakePhantom(Object** location, void* parameter, |
| 135 PhantomCallback weak_callback, |
| 136 int internal_field_index1 = v8::Object::kNoInternalFie
ldIndex, |
| 137 int internal_field_index2 = v8::Object::kNoInternalFie
ldIndex); |
133 | 138 |
134 void RecordStats(HeapStats* stats); | 139 void RecordStats(HeapStats* stats); |
135 | 140 |
136 // Returns the current number of weak handles. | 141 // Returns the current number of weak handles. |
137 int NumberOfWeakHandles(); | 142 int NumberOfWeakHandles(); |
138 | 143 |
139 // Returns the current number of weak handles to global objects. | 144 // Returns the current number of weak handles to global objects. |
140 // These handles are also included in NumberOfWeakHandles(). | 145 // These handles are also included in NumberOfWeakHandles(). |
141 int NumberOfGlobalObjectWeakHandles(); | 146 int NumberOfGlobalObjectWeakHandles(); |
142 | 147 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 List<int> new_space_indices_; | 383 List<int> new_space_indices_; |
379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 384 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
380 | 385 |
381 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 386 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
382 }; | 387 }; |
383 | 388 |
384 | 389 |
385 } } // namespace v8::internal | 390 } } // namespace v8::internal |
386 | 391 |
387 #endif // V8_GLOBAL_HANDLES_H_ | 392 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |