blob: 24a2273e36d584e50043e7a4d8acc31a6efe51b6 [file] [log] [blame]
Ben Murdoch257744e2011-11-30 15:57:28 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_GLOBAL_HANDLES_H_
6#define V8_GLOBAL_HANDLES_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "include/v8.h"
9#include "include/v8-profiler.h"
Ben Murdoch8b112d22011-06-08 16:22:53 +010010
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/handles.h"
12#include "src/list.h"
13#include "src/utils.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000014
15namespace v8 {
16namespace internal {
17
Ben Murdochb8a8cc12014-11-26 15:28:44 +000018class HeapStats;
19class ObjectVisitor;
20
Steve Blocka7e24c12009-10-30 11:49:00 +000021// Structure for tracking global handles.
22// A single list keeps all the allocated global handles.
23// Destroyed handles stay in the list but is added to the free list.
24// At GC the destroyed global handles are removed from the free list
25// and deallocated.
26
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027// Data structures for tracking object groups and implicit references.
28
Steve Blocka7e24c12009-10-30 11:49:00 +000029// An object group is treated like a single JS object: if one of object in
30// the group is alive, all objects in the same group are considered alive.
31// An object group is used to simulate object relationship in a DOM tree.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032
33// An implicit references group consists of two parts: a parent object and a
34// list of children objects. If the parent is alive, all the children are alive
35// too.
36
37struct ObjectGroup {
38 explicit ObjectGroup(size_t length)
39 : info(NULL), length(length) {
40 DCHECK(length > 0);
41 objects = new Object**[length];
Ben Murdoch8b112d22011-06-08 16:22:53 +010042 }
Ben Murdoch8b112d22011-06-08 16:22:53 +010043 ~ObjectGroup();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044
45 v8::RetainedObjectInfo* info;
46 Object*** objects;
47 size_t length;
Steve Block44f0eee2011-05-26 01:26:41 +010048};
49
50
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051struct ImplicitRefGroup {
52 ImplicitRefGroup(HeapObject** parent, size_t length)
53 : parent(parent), length(length) {
54 DCHECK(length > 0);
55 children = new Object**[length];
Ben Murdoch8b112d22011-06-08 16:22:53 +010056 }
Ben Murdoch8b112d22011-06-08 16:22:53 +010057 ~ImplicitRefGroup();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058
59 HeapObject** parent;
60 Object*** children;
61 size_t length;
Steve Blocka7e24c12009-10-30 11:49:00 +000062};
63
64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065// For internal bookkeeping.
66struct ObjectGroupConnection {
67 ObjectGroupConnection(UniqueId id, Object** object)
68 : id(id), object(object) {}
69
70 bool operator==(const ObjectGroupConnection& other) const {
71 return id == other.id;
72 }
73
74 bool operator<(const ObjectGroupConnection& other) const {
75 return id < other.id;
76 }
77
78 UniqueId id;
79 Object** object;
80};
81
82
83struct ObjectGroupRetainerInfo {
84 ObjectGroupRetainerInfo(UniqueId id, RetainedObjectInfo* info)
85 : id(id), info(info) {}
86
87 bool operator==(const ObjectGroupRetainerInfo& other) const {
88 return id == other.id;
89 }
90
91 bool operator<(const ObjectGroupRetainerInfo& other) const {
92 return id < other.id;
93 }
94
95 UniqueId id;
96 RetainedObjectInfo* info;
97};
98
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099enum WeaknessType {
Ben Murdochc5610432016-08-08 18:44:38 +0100100 // Embedder gets a handle to the dying object.
101 FINALIZER_WEAK,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000102 // In the following cases, the embedder gets the parameter they passed in
103 // earlier, and 0 or 2 first internal fields. Note that the internal
104 // fields must contain aligned non-V8 pointers. Getting pointers to V8
105 // objects through this interface would be GC unsafe so in that case the
106 // embedder gets a null pointer instead.
107 PHANTOM_WEAK,
Ben Murdochc5610432016-08-08 18:44:38 +0100108 PHANTOM_WEAK_2_INTERNAL_FIELDS,
109 // The handle is automatically reset by the garbage collector when
110 // the object is no longer reachable.
111 PHANTOM_WEAK_RESET_HANDLE
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400112};
113
Steve Block44f0eee2011-05-26 01:26:41 +0100114class GlobalHandles {
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100116 ~GlobalHandles();
117
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 // Creates a new global handle that is alive until Destroy is called.
Steve Block44f0eee2011-05-26 01:26:41 +0100119 Handle<Object> Create(Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000120
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000121 // Copy a global handle
122 static Handle<Object> CopyGlobal(Object** location);
123
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 // Destroy a global handle.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 static void Destroy(Object** location);
126
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 // Make the global handle weak and set the callback parameter for the
128 // handle. When the garbage collector recognizes that only weak global
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400129 // handles point to an object the callback function is invoked (for each
130 // handle) with the handle and corresponding parameter as arguments. By
131 // default the handle still contains a pointer to the object that is being
132 // collected. For this reason the object is not collected until the next
133 // GC. For a phantom weak handle the handle is cleared (set to a Smi)
134 // before the callback is invoked, but the handle can still be identified
135 // in the callback by using the location() of the handle.
136 static void MakeWeak(Object** location, void* parameter,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 WeakCallbackInfo<void>::Callback weak_callback,
138 v8::WeakCallbackType type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400139
Ben Murdochc5610432016-08-08 18:44:38 +0100140 static void MakeWeak(Object*** location_addr);
141
Steve Block44f0eee2011-05-26 01:26:41 +0100142 void RecordStats(HeapStats* stats);
Steve Blockd0582a62009-12-15 09:54:21 +0000143
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000144 // Returns the current number of weak handles.
145 int NumberOfWeakHandles();
146
Steve Blocka7e24c12009-10-30 11:49:00 +0000147 // Returns the current number of weak handles to global objects.
148 // These handles are also included in NumberOfWeakHandles().
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 int NumberOfGlobalObjectWeakHandles();
Steve Blocka7e24c12009-10-30 11:49:00 +0000150
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100151 // Returns the current number of handles to global objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000152 int global_handles_count() const {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100153 return number_of_global_handles_;
154 }
155
Ben Murdochc5610432016-08-08 18:44:38 +0100156 size_t NumberOfPhantomHandleResets() {
157 return number_of_phantom_handle_resets_;
158 }
159
160 void ResetNumberOfPhantomHandleResets() {
161 number_of_phantom_handle_resets_ = 0;
162 }
163
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 // Clear the weakness of a global handle.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165 static void* ClearWeakness(Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
Ben Murdochda12d292016-06-02 14:46:10 +0100167 // Mark the reference to this object independent of any object group.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000168 static void MarkIndependent(Object** location);
169
170 // Mark the reference to this object externaly unreachable.
171 static void MarkPartiallyDependent(Object** location);
172
173 static bool IsIndependent(Object** location);
Ben Murdoch257744e2011-11-30 15:57:28 +0000174
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 // Tells whether global handle is near death.
176 static bool IsNearDeath(Object** location);
177
178 // Tells whether global handle is weak.
179 static bool IsWeak(Object** location);
180
John Reck59135872010-11-02 12:39:01 -0700181 // Process pending weak handles.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000182 // Returns the number of freed nodes.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000183 int PostGarbageCollectionProcessing(
184 GarbageCollector collector, const v8::GCCallbackFlags gc_callback_flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Steve Blockd0582a62009-12-15 09:54:21 +0000186 // Iterates over all strong handles.
Steve Block44f0eee2011-05-26 01:26:41 +0100187 void IterateStrongRoots(ObjectVisitor* v);
Steve Blockd0582a62009-12-15 09:54:21 +0000188
Steve Blocka7e24c12009-10-30 11:49:00 +0000189 // Iterates over all handles.
Steve Block44f0eee2011-05-26 01:26:41 +0100190 void IterateAllRoots(ObjectVisitor* v);
191
192 // Iterates over all handles that have embedder-assigned class ID.
193 void IterateAllRootsWithClassIds(ObjectVisitor* v);
Steve Blocka7e24c12009-10-30 11:49:00 +0000194
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195 // Iterates over all handles in the new space that have embedder-assigned
196 // class ID.
197 void IterateAllRootsInNewSpaceWithClassIds(ObjectVisitor* v);
198
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000199 // Iterate over all handles in the new space that are weak, unmodified
200 // and have class IDs
201 void IterateWeakRootsInNewSpaceWithClassIds(ObjectVisitor* v);
202
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 // Iterates over all weak roots in heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100204 void IterateWeakRoots(ObjectVisitor* v);
Steve Blocka7e24c12009-10-30 11:49:00 +0000205
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 // Find all weak handles satisfying the callback predicate, mark
207 // them as pending.
Steve Block44f0eee2011-05-26 01:26:41 +0100208 void IdentifyWeakHandles(WeakSlotCallback f);
Steve Blocka7e24c12009-10-30 11:49:00 +0000209
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000210 // NOTE: Five ...NewSpace... functions below are used during
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000211 // scavenge collections and iterate over sets of handles that are
212 // guaranteed to contain all handles holding new space objects (but
213 // may also include old space objects).
214
215 // Iterates over strong and dependent handles. See the node above.
216 void IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v);
217
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 // Finds weak independent or partially independent handles satisfying
219 // the callback predicate and marks them as pending. See the note above.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000220 void IdentifyNewSpaceWeakIndependentHandles(WeakSlotCallbackWithHeap f);
221
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000222 // Iterates over weak independent or partially independent handles.
223 // See the note above.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000224 void IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v);
Ben Murdoch257744e2011-11-30 15:57:28 +0000225
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000226 // Finds weak independent or unmodified handles satisfying
227 // the callback predicate and marks them as pending. See the note above.
228 void MarkNewSpaceWeakUnmodifiedObjectsPending(
229 WeakSlotCallbackWithHeap is_unscavenged);
230
231 // Iterates over weak independent or unmodified handles.
232 // See the note above.
233 void IterateNewSpaceWeakUnmodifiedRoots(ObjectVisitor* v);
234
235 // Identify unmodified objects that are in weak state and marks them
236 // unmodified
237 void IdentifyWeakUnmodifiedObjects(WeakSlotCallback is_unmodified);
238
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 // Iterate over objects in object groups that have at least one object
240 // which requires visiting. The callback has to return true if objects
241 // can be skipped and false otherwise.
242 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip);
243
Ben Murdochda12d292016-06-02 14:46:10 +0100244 // Print all objects in object groups
245 void PrintObjectGroups();
246
Steve Blocka7e24c12009-10-30 11:49:00 +0000247 // Add an object group.
Steve Block44f0eee2011-05-26 01:26:41 +0100248 // Should be only used in GC callback function before a collection.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000249 // All groups are destroyed after a garbage collection.
Steve Block44f0eee2011-05-26 01:26:41 +0100250 void AddObjectGroup(Object*** handles,
251 size_t length,
252 v8::RetainedObjectInfo* info);
253
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000254 // Associates handle with the object group represented by id.
Steve Block44f0eee2011-05-26 01:26:41 +0100255 // Should be only used in GC callback function before a collection.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 // All groups are destroyed after a garbage collection.
257 void SetObjectGroupId(Object** handle, UniqueId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000258
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000259 // Set RetainedObjectInfo for an object group. Should not be called more than
260 // once for a group. Should not be called for a group which contains no
261 // handles.
262 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
Steve Block44f0eee2011-05-26 01:26:41 +0100263
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264 // Adds an implicit reference from a group to an object. Should be only used
265 // in GC callback function before a collection. All implicit references are
266 // destroyed after a mark-compact collection.
267 void SetReferenceFromGroup(UniqueId id, Object** child);
268
269 // Adds an implicit reference from a parent object to a child object. Should
270 // be only used in GC callback function before a collection. All implicit
271 // references are destroyed after a mark-compact collection.
272 void SetReference(HeapObject** parent, Object** child);
273
274 List<ObjectGroup*>* object_groups() {
275 ComputeObjectGroupsAndImplicitReferences();
276 return &object_groups_;
277 }
278
Steve Block44f0eee2011-05-26 01:26:41 +0100279 List<ImplicitRefGroup*>* implicit_ref_groups() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280 ComputeObjectGroupsAndImplicitReferences();
Steve Block44f0eee2011-05-26 01:26:41 +0100281 return &implicit_ref_groups_;
282 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
284 // Remove bags, this should only happen after GC.
Steve Block44f0eee2011-05-26 01:26:41 +0100285 void RemoveObjectGroups();
286 void RemoveImplicitRefGroups();
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
288 // Tear down the global handle structure.
Steve Block44f0eee2011-05-26 01:26:41 +0100289 void TearDown();
290
291 Isolate* isolate() { return isolate_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000292
293#ifdef DEBUG
Steve Block44f0eee2011-05-26 01:26:41 +0100294 void PrintStats();
295 void Print();
Steve Blocka7e24c12009-10-30 11:49:00 +0000296#endif
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000297
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100299 explicit GlobalHandles(Isolate* isolate);
300
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 // Migrates data from the internal representation (object_group_connections_,
302 // retainer_infos_ and implicit_ref_connections_) to the public and more
303 // efficient representation (object_groups_ and implicit_ref_groups_).
304 void ComputeObjectGroupsAndImplicitReferences();
305
306 // v8::internal::List is inefficient even for small number of elements, if we
307 // don't assign any initial capacity.
308 static const int kObjectGroupConnectionsCapacity = 20;
309
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000310 class PendingPhantomCallback;
311
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400312 // Helpers for PostGarbageCollectionProcessing.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000313 static void InvokeSecondPassPhantomCallbacks(
314 List<PendingPhantomCallback>* callbacks, Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400315 int PostScavengeProcessing(int initial_post_gc_processing_count);
316 int PostMarkSweepProcessing(int initial_post_gc_processing_count);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000317 int DispatchPendingPhantomCallbacks(bool synchronous_second_pass);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400318 void UpdateListOfNewSpaceNodes();
319
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000320 // Internal node structures.
Steve Blocka7e24c12009-10-30 11:49:00 +0000321 class Node;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000322 class NodeBlock;
323 class NodeIterator;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324 class PendingPhantomCallbacksSecondPassTask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
Steve Block44f0eee2011-05-26 01:26:41 +0100326 Isolate* isolate_;
327
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100328 // Field always containing the number of handles to global objects.
329 int number_of_global_handles_;
330
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000331 // List of all allocated node blocks.
332 NodeBlock* first_block_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000333
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000334 // List of node blocks with used nodes.
335 NodeBlock* first_used_block_;
336
337 // Free list of nodes.
Steve Block44f0eee2011-05-26 01:26:41 +0100338 Node* first_free_;
Steve Blockd0582a62009-12-15 09:54:21 +0000339
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000340 // Contains all nodes holding new space objects. Note: when the list
341 // is accessed, some of the objects may have been promoted already.
342 List<Node*> new_space_nodes_;
Steve Block44f0eee2011-05-26 01:26:41 +0100343
Steve Block44f0eee2011-05-26 01:26:41 +0100344 int post_gc_processing_count_;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000345
Ben Murdochc5610432016-08-08 18:44:38 +0100346 size_t number_of_phantom_handle_resets_;
347
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000348 // Object groups and implicit references, public and more efficient
349 // representation.
Steve Block44f0eee2011-05-26 01:26:41 +0100350 List<ObjectGroup*> object_groups_;
351 List<ImplicitRefGroup*> implicit_ref_groups_;
352
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000353 // Object groups and implicit references, temporary representation while
354 // constructing the groups.
355 List<ObjectGroupConnection> object_group_connections_;
356 List<ObjectGroupRetainerInfo> retainer_infos_;
357 List<ObjectGroupConnection> implicit_ref_connections_;
358
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400359 List<PendingPhantomCallback> pending_phantom_callbacks_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400360
Steve Block44f0eee2011-05-26 01:26:41 +0100361 friend class Isolate;
362
363 DISALLOW_COPY_AND_ASSIGN(GlobalHandles);
Steve Blocka7e24c12009-10-30 11:49:00 +0000364};
365
366
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400367class GlobalHandles::PendingPhantomCallback {
368 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000369 typedef v8::WeakCallbackInfo<void> Data;
370 PendingPhantomCallback(
371 Node* node, Data::Callback callback, void* parameter,
372 void* internal_fields[v8::kInternalFieldsInWeakCallback])
373 : node_(node), callback_(callback), parameter_(parameter) {
374 for (int i = 0; i < v8::kInternalFieldsInWeakCallback; ++i) {
375 internal_fields_[i] = internal_fields[i];
376 }
377 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400378
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000379 void Invoke(Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400380
381 Node* node() { return node_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000382 Data::Callback callback() { return callback_; }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400383
384 private:
385 Node* node_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400386 Data::Callback callback_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000387 void* parameter_;
388 void* internal_fields_[v8::kInternalFieldsInWeakCallback];
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400389};
390
391
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000392class EternalHandles {
393 public:
394 enum SingletonHandle {
395 I18N_TEMPLATE_ONE,
396 I18N_TEMPLATE_TWO,
397 DATE_CACHE_VERSION,
398
399 NUMBER_OF_SINGLETON_HANDLES
400 };
401
402 EternalHandles();
403 ~EternalHandles();
404
405 int NumberOfHandles() { return size_; }
406
407 // Create an EternalHandle, overwriting the index.
408 void Create(Isolate* isolate, Object* object, int* index);
409
410 // Grab the handle for an existing EternalHandle.
411 inline Handle<Object> Get(int index) {
412 return Handle<Object>(GetLocation(index));
413 }
414
415 // Grab the handle for an existing SingletonHandle.
416 inline Handle<Object> GetSingleton(SingletonHandle singleton) {
417 DCHECK(Exists(singleton));
418 return Get(singleton_handles_[singleton]);
419 }
420
421 // Checks whether a SingletonHandle has been assigned.
422 inline bool Exists(SingletonHandle singleton) {
423 return singleton_handles_[singleton] != kInvalidIndex;
424 }
425
426 // Assign a SingletonHandle to an empty slot and returns the handle.
427 Handle<Object> CreateSingleton(Isolate* isolate,
428 Object* object,
429 SingletonHandle singleton) {
430 Create(isolate, object, &singleton_handles_[singleton]);
431 return Get(singleton_handles_[singleton]);
432 }
433
434 // Iterates over all handles.
435 void IterateAllRoots(ObjectVisitor* visitor);
436 // Iterates over all handles which might be in new space.
437 void IterateNewSpaceRoots(ObjectVisitor* visitor);
438 // Rebuilds new space list.
439 void PostGarbageCollectionProcessing(Heap* heap);
440
441 private:
442 static const int kInvalidIndex = -1;
443 static const int kShift = 8;
444 static const int kSize = 1 << kShift;
445 static const int kMask = 0xff;
446
447 // Gets the slot for an index
448 inline Object** GetLocation(int index) {
449 DCHECK(index >= 0 && index < size_);
450 return &blocks_[index >> kShift][index & kMask];
451 }
452
453 int size_;
454 List<Object**> blocks_;
455 List<int> new_space_indices_;
456 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES];
457
458 DISALLOW_COPY_AND_ASSIGN(EternalHandles);
459};
460
461
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000462} // namespace internal
463} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000464
465#endif // V8_GLOBAL_HANDLES_H_