Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: src/global-handles.h

Issue 687003005: Introduce phantom weak handles in the API and use them internally for debug info (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/debug.cc ('k') | src/global-handles.cc » ('j') | src/global-handles.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/global-handles.h
diff --git a/src/global-handles.h b/src/global-handles.h
index a06cba0856487f625be72721819fb1342341e46a..aacdcbc072d0ae26af7ce6264767d8366ee17f7a 100644
--- a/src/global-handles.h
+++ b/src/global-handles.h
@@ -112,15 +112,24 @@ class GlobalHandles {
typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
+ // For a phantom weak reference, the callback does not have access to the
+ // dying object. Phantom weak references are preferred because they allow
+ // memory to be reclaimed in one GC cycle rather than two. However, for
+ // historical reasons the default is non-phantom.
+ enum PhantomState { Nonphantom, Phantom };
+
// Make the global handle weak and set the callback parameter for the
// handle. When the garbage collector recognizes that only weak global
- // handles point to an object the handles are cleared and the callback
- // function is invoked (for each handle) with the handle and corresponding
- // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The
- // reason is that Smi::FromInt(0) does not change during garage collection.
- static void MakeWeak(Object** location,
- void* parameter,
- WeakCallback weak_callback);
+ // handles point to an object the callback function is invoked (for each
+ // handle) with the handle and corresponding parameter as arguments. By
+ // default the handle still contains a pointer to the object that is being
+ // collected. For this reason the object is not collected until the next
+ // GC. For a phantom weak handle the handle is cleared (set to a Smi)
+ // before the callback is invoked, but the handle can still be identified
+ // in the callback by using the location() of the handle.
+ static void MakeWeak(Object** location, void* parameter,
+ WeakCallback weak_callback,
+ PhantomState phantom = Nonphantom);
void RecordStats(HeapStats* stats);
« no previous file with comments | « src/debug.cc ('k') | src/global-handles.cc » ('j') | src/global-handles.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698