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

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

Issue 753553002: Phantom references support internal fields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Queue up phantom callbacks during GC to dispatch later Created 6 years 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 bool operator<(const ObjectGroupRetainerInfo& other) const { 91 bool operator<(const ObjectGroupRetainerInfo& other) const {
92 return id < other.id; 92 return id < other.id;
93 } 93 }
94 94
95 UniqueId id; 95 UniqueId id;
96 RetainedObjectInfo* info; 96 RetainedObjectInfo* info;
97 }; 97 };
98 98
99 99
100 class PendingPhantomCallback {
101 public:
102 typedef PhantomCallbackData<void>::Callback Callback;
103 typedef PhantomCallbackData<void> Data;
104 PendingPhantomCallback(Data data, Callback callback)
105 : data_(data),
106 callback_(callback) { }
107
108 void invoke() {
109 callback_(data_);
110 }
111
112 private:
113 PhantomCallbackData<void>::Callback callback_;
114 PhantomCallbackData<void> data_;
115 };
116
117
100 class GlobalHandles { 118 class GlobalHandles {
101 public: 119 public:
102 ~GlobalHandles(); 120 ~GlobalHandles();
103 121
104 // Creates a new global handle that is alive until Destroy is called. 122 // Creates a new global handle that is alive until Destroy is called.
105 Handle<Object> Create(Object* value); 123 Handle<Object> Create(Object* value);
106 124
107 // Copy a global handle 125 // Copy a global handle
108 static Handle<Object> CopyGlobal(Object** location); 126 static Handle<Object> CopyGlobal(Object** location);
109 127
110 // Destroy a global handle. 128 // Destroy a global handle.
111 static void Destroy(Object** location); 129 static void Destroy(Object** location);
112 130
113 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; 131 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
132 typedef PhantomCallbackData<void>::Callback PhantomCallback;
114 133
115 // For a phantom weak reference, the callback does not have access to the 134 // For a phantom weak reference, the callback does not have access to the
116 // dying object. Phantom weak references are preferred because they allow 135 // dying object. Phantom weak references are preferred because they allow
117 // memory to be reclaimed in one GC cycle rather than two. However, for 136 // memory to be reclaimed in one GC cycle rather than two. However, for
118 // historical reasons the default is non-phantom. 137 // historical reasons the default is non-phantom.
119 enum PhantomState { Nonphantom, Phantom }; 138 enum PhantomState { Nonphantom, Phantom };
120 139
121 // Make the global handle weak and set the callback parameter for the 140 // Make the global handle weak and set the callback parameter for the
122 // handle. When the garbage collector recognizes that only weak global 141 // handle. When the garbage collector recognizes that only weak global
123 // handles point to an object the callback function is invoked (for each 142 // handles point to an object the callback function is invoked (for each
124 // handle) with the handle and corresponding parameter as arguments. By 143 // handle) with the handle and corresponding parameter as arguments. By
125 // default the handle still contains a pointer to the object that is being 144 // 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 145 // 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) 146 // 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 147 // before the callback is invoked, but the handle can still be identified
129 // in the callback by using the location() of the handle. 148 // in the callback by using the location() of the handle.
130 static void MakeWeak(Object** location, void* parameter, 149 static void MakeWeak(
131 WeakCallback weak_callback, 150 Object** location, void* parameter, WeakCallback weak_callback);
132 PhantomState phantom = Nonphantom); 151
152 static void MakePhantom(
153 Object** location, void* parameter,
154 PhantomCallback weak_callback,
155 int16_t internal_field_index1 = v8::Object::kNoInternalFieldIndex,
156 int16_t internal_field_index2 = v8::Object::kNoInternalFieldIndex);
133 157
134 void RecordStats(HeapStats* stats); 158 void RecordStats(HeapStats* stats);
135 159
136 // Returns the current number of weak handles. 160 // Returns the current number of weak handles.
137 int NumberOfWeakHandles(); 161 int NumberOfWeakHandles();
138 162
139 // Returns the current number of weak handles to global objects. 163 // Returns the current number of weak handles to global objects.
140 // These handles are also included in NumberOfWeakHandles(). 164 // These handles are also included in NumberOfWeakHandles().
141 int NumberOfGlobalObjectWeakHandles(); 165 int NumberOfGlobalObjectWeakHandles();
142 166
143 // Returns the current number of handles to global objects. 167 // Returns the current number of handles to global objects.
144 int global_handles_count() const { 168 int global_handles_count() const {
145 return number_of_global_handles_; 169 return number_of_global_handles_;
146 } 170 }
147 171
172 // Collect up data for the weak handle callbacks after GC has completed, but
173 // before memory is reclaimed.
174 void CollectPhantomCallbackData();
175
148 // Clear the weakness of a global handle. 176 // Clear the weakness of a global handle.
149 static void* ClearWeakness(Object** location); 177 static void* ClearWeakness(Object** location);
150 178
151 // Clear the weakness of a global handle. 179 // Clear the weakness of a global handle.
152 static void MarkIndependent(Object** location); 180 static void MarkIndependent(Object** location);
153 181
154 // Mark the reference to this object externaly unreachable. 182 // Mark the reference to this object externaly unreachable.
155 static void MarkPartiallyDependent(Object** location); 183 static void MarkPartiallyDependent(Object** location);
156 184
157 static bool IsIndependent(Object** location); 185 static bool IsIndependent(Object** location);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 291
264 // Migrates data from the internal representation (object_group_connections_, 292 // Migrates data from the internal representation (object_group_connections_,
265 // retainer_infos_ and implicit_ref_connections_) to the public and more 293 // retainer_infos_ and implicit_ref_connections_) to the public and more
266 // efficient representation (object_groups_ and implicit_ref_groups_). 294 // efficient representation (object_groups_ and implicit_ref_groups_).
267 void ComputeObjectGroupsAndImplicitReferences(); 295 void ComputeObjectGroupsAndImplicitReferences();
268 296
269 // v8::internal::List is inefficient even for small number of elements, if we 297 // v8::internal::List is inefficient even for small number of elements, if we
270 // don't assign any initial capacity. 298 // don't assign any initial capacity.
271 static const int kObjectGroupConnectionsCapacity = 20; 299 static const int kObjectGroupConnectionsCapacity = 20;
272 300
301 // Helpers for PostGarbageCollectionProcessing.
302 int PostScavengeProcessing(int initial_post_gc_processing_count);
303 int PostMarkSweepProcessing(int initial_post_gc_processing_count);
304 int DispatchPendingPhantomCallbacks();
305 void UpdateListOfNewSpaceNodes();
306
273 // Internal node structures. 307 // Internal node structures.
274 class Node; 308 class Node;
275 class NodeBlock; 309 class NodeBlock;
276 class NodeIterator; 310 class NodeIterator;
277 311
278 Isolate* isolate_; 312 Isolate* isolate_;
279 313
280 // Field always containing the number of handles to global objects. 314 // Field always containing the number of handles to global objects.
281 int number_of_global_handles_; 315 int number_of_global_handles_;
282 316
(...skipping 16 matching lines...) Expand all
299 // representation. 333 // representation.
300 List<ObjectGroup*> object_groups_; 334 List<ObjectGroup*> object_groups_;
301 List<ImplicitRefGroup*> implicit_ref_groups_; 335 List<ImplicitRefGroup*> implicit_ref_groups_;
302 336
303 // Object groups and implicit references, temporary representation while 337 // Object groups and implicit references, temporary representation while
304 // constructing the groups. 338 // constructing the groups.
305 List<ObjectGroupConnection> object_group_connections_; 339 List<ObjectGroupConnection> object_group_connections_;
306 List<ObjectGroupRetainerInfo> retainer_infos_; 340 List<ObjectGroupRetainerInfo> retainer_infos_;
307 List<ObjectGroupConnection> implicit_ref_connections_; 341 List<ObjectGroupConnection> implicit_ref_connections_;
308 342
343 List<PendingPhantomCallback> pending_phantom_callbacks_;
344
309 friend class Isolate; 345 friend class Isolate;
310 346
311 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); 347 DISALLOW_COPY_AND_ASSIGN(GlobalHandles);
312 }; 348 };
313 349
314 350
315 class EternalHandles { 351 class EternalHandles {
316 public: 352 public:
317 enum SingletonHandle { 353 enum SingletonHandle {
318 I18N_TEMPLATE_ONE, 354 I18N_TEMPLATE_ONE,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 List<int> new_space_indices_; 414 List<int> new_space_indices_;
379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; 415 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES];
380 416
381 DISALLOW_COPY_AND_ASSIGN(EternalHandles); 417 DISALLOW_COPY_AND_ASSIGN(EternalHandles);
382 }; 418 };
383 419
384 420
385 } } // namespace v8::internal 421 } } // namespace v8::internal
386 422
387 #endif // V8_GLOBAL_HANDLES_H_ 423 #endif // V8_GLOBAL_HANDLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698