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

Side by Side Diff: src/global-handles.h

Issue 649563006: 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: Rebase 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.cc ('k') | src/global-handles.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
115 // Make the global handle weak and set the callback parameter for the 121 // Make the global handle weak and set the callback parameter for the
116 // handle. When the garbage collector recognizes that only weak global 122 // handle. When the garbage collector recognizes that only weak global
117 // handles point to an object the handles are cleared and the callback 123 // handles point to an object the callback function is invoked (for each
118 // function is invoked (for each handle) with the handle and corresponding 124 // handle) with the handle and corresponding parameter as arguments. By
119 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The 125 // default the handle still contains a pointer to the object that is being
120 // reason is that Smi::FromInt(0) does not change during garage collection. 126 // collected. For this reason the object is not collected until the next
121 static void MakeWeak(Object** location, 127 // GC. For a phantom weak handle the handle is cleared (set to a Smi)
122 void* parameter, 128 // before the callback is invoked, but the handle can still be identified
123 WeakCallback weak_callback); 129 // in the callback by using the location() of the handle.
130 static void MakeWeak(Object** location, void* parameter,
131 WeakCallback weak_callback,
132 PhantomState phantom = Nonphantom);
124 133
125 void RecordStats(HeapStats* stats); 134 void RecordStats(HeapStats* stats);
126 135
127 // Returns the current number of weak handles. 136 // Returns the current number of weak handles.
128 int NumberOfWeakHandles(); 137 int NumberOfWeakHandles();
129 138
130 // Returns the current number of weak handles to global objects. 139 // Returns the current number of weak handles to global objects.
131 // These handles are also included in NumberOfWeakHandles(). 140 // These handles are also included in NumberOfWeakHandles().
132 int NumberOfGlobalObjectWeakHandles(); 141 int NumberOfGlobalObjectWeakHandles();
133 142
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 List<int> new_space_indices_; 378 List<int> new_space_indices_;
370 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; 379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES];
371 380
372 DISALLOW_COPY_AND_ASSIGN(EternalHandles); 381 DISALLOW_COPY_AND_ASSIGN(EternalHandles);
373 }; 382 };
374 383
375 384
376 } } // namespace v8::internal 385 } } // namespace v8::internal
377 386
378 #endif // V8_GLOBAL_HANDLES_H_ 387 #endif // V8_GLOBAL_HANDLES_H_
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/global-handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698