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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 114 |
115 // 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 // memory to be reclaimed in one GC cycle rather than two. However, for | |
118 // historical reasons the default is non-phantom. | |
119 enum PhantomState { Nonphantom, Phantom }; | |
120 | |
121 // Make the global handle weak and set the callback parameter for the | 115 // Make the global handle weak and set the callback parameter for the |
122 // handle. When the garbage collector recognizes that only weak global | 116 // handle. When the garbage collector recognizes that only weak global |
123 // handles point to an object the callback function is invoked (for each | 117 // handles point to an object the handles are cleared and the callback |
124 // handle) with the handle and corresponding parameter as arguments. By | 118 // function is invoked (for each handle) with the handle and corresponding |
125 // default the handle still contains a pointer to the object that is being | 119 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
126 // collected. For this reason the object is not collected until the next | 120 // reason is that Smi::FromInt(0) does not change during garage collection. |
127 // GC. For a phantom weak handle the handle is cleared (set to a Smi) | 121 static void MakeWeak(Object** location, |
128 // before the callback is invoked, but the handle can still be identified | 122 void* parameter, |
129 // in the callback by using the location() of the handle. | 123 WeakCallback weak_callback); |
130 static void MakeWeak(Object** location, void* parameter, | |
131 WeakCallback weak_callback, | |
132 PhantomState phantom = Nonphantom); | |
133 | 124 |
134 void RecordStats(HeapStats* stats); | 125 void RecordStats(HeapStats* stats); |
135 | 126 |
136 // Returns the current number of weak handles. | 127 // Returns the current number of weak handles. |
137 int NumberOfWeakHandles(); | 128 int NumberOfWeakHandles(); |
138 | 129 |
139 // Returns the current number of weak handles to global objects. | 130 // Returns the current number of weak handles to global objects. |
140 // These handles are also included in NumberOfWeakHandles(). | 131 // These handles are also included in NumberOfWeakHandles(). |
141 int NumberOfGlobalObjectWeakHandles(); | 132 int NumberOfGlobalObjectWeakHandles(); |
142 | 133 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 List<int> new_space_indices_; | 369 List<int> new_space_indices_; |
379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 370 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
380 | 371 |
381 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 372 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
382 }; | 373 }; |
383 | 374 |
384 | 375 |
385 } } // namespace v8::internal | 376 } } // namespace v8::internal |
386 | 377 |
387 #endif // V8_GLOBAL_HANDLES_H_ | 378 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |