Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_GLOBAL_HANDLES_H_ |
| 6 | #define V8_GLOBAL_HANDLES_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "include/v8.h" |
| 9 | #include "include/v8-profiler.h" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/handles.h" |
| 12 | #include "src/list.h" |
| 13 | #include "src/utils.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | class HeapStats; |
| 19 | class ObjectVisitor; |
| 20 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 21 | // 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | // Data structures for tracking object groups and implicit references. |
| 28 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | // 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | |
| 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 | |
| 37 | struct ObjectGroup { |
| 38 | explicit ObjectGroup(size_t length) |
| 39 | : info(NULL), length(length) { |
| 40 | DCHECK(length > 0); |
| 41 | objects = new Object**[length]; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 42 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 43 | ~ObjectGroup(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 44 | |
| 45 | v8::RetainedObjectInfo* info; |
| 46 | Object*** objects; |
| 47 | size_t length; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | struct ImplicitRefGroup { |
| 52 | ImplicitRefGroup(HeapObject** parent, size_t length) |
| 53 | : parent(parent), length(length) { |
| 54 | DCHECK(length > 0); |
| 55 | children = new Object**[length]; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 56 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 57 | ~ImplicitRefGroup(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | |
| 59 | HeapObject** parent; |
| 60 | Object*** children; |
| 61 | size_t length; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | // For internal bookkeeping. |
| 66 | struct 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 | |
| 83 | struct 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 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 99 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 100 | class GlobalHandles { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 102 | ~GlobalHandles(); |
| 103 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | // Creates a new global handle that is alive until Destroy is called. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 105 | Handle<Object> Create(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | // Copy a global handle |
| 108 | static Handle<Object> CopyGlobal(Object** location); |
| 109 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 110 | // Destroy a global handle. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 111 | static void Destroy(Object** location); |
| 112 | |
| 113 | typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 114 | |
| 115 | // Make the global handle weak and set the callback parameter for the |
| 116 | // handle. When the garbage collector recognizes that only weak global |
| 117 | // handles point to an object the handles are cleared and the callback |
| 118 | // function is invoked (for each handle) with the handle and corresponding |
| 119 | // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
| 120 | // reason is that Smi::FromInt(0) does not change during garage collection. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 121 | static void MakeWeak(Object** location, |
| 122 | void* parameter, |
| 123 | WeakCallback weak_callback); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 124 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 125 | void RecordStats(HeapStats* stats); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | // Returns the current number of weak handles. |
| 128 | int NumberOfWeakHandles(); |
| 129 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 130 | // Returns the current number of weak handles to global objects. |
| 131 | // These handles are also included in NumberOfWeakHandles(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | int NumberOfGlobalObjectWeakHandles(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 133 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 134 | // Returns the current number of handles to global objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 135 | int global_handles_count() const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 136 | return number_of_global_handles_; |
| 137 | } |
| 138 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | // Clear the weakness of a global handle. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | static void* ClearWeakness(Object** location); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 141 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 142 | // Clear the weakness of a global handle. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 143 | static void MarkIndependent(Object** location); |
| 144 | |
| 145 | // Mark the reference to this object externaly unreachable. |
| 146 | static void MarkPartiallyDependent(Object** location); |
| 147 | |
| 148 | static bool IsIndependent(Object** location); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 149 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | // Tells whether global handle is near death. |
| 151 | static bool IsNearDeath(Object** location); |
| 152 | |
| 153 | // Tells whether global handle is weak. |
| 154 | static bool IsWeak(Object** location); |
| 155 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 156 | // Process pending weak handles. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 157 | // Returns the number of freed nodes. |
| 158 | int PostGarbageCollectionProcessing(GarbageCollector collector); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 159 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 160 | // Iterates over all strong handles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 161 | void IterateStrongRoots(ObjectVisitor* v); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 162 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 163 | // Iterates over all handles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 164 | void IterateAllRoots(ObjectVisitor* v); |
| 165 | |
| 166 | // Iterates over all handles that have embedder-assigned class ID. |
| 167 | void IterateAllRootsWithClassIds(ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | // Iterates over all handles in the new space that have embedder-assigned |
| 170 | // class ID. |
| 171 | void IterateAllRootsInNewSpaceWithClassIds(ObjectVisitor* v); |
| 172 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | // Iterates over all weak roots in heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 174 | void IterateWeakRoots(ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | // Find all weak handles satisfying the callback predicate, mark |
| 177 | // them as pending. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 178 | void IdentifyWeakHandles(WeakSlotCallback f); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 179 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 180 | // NOTE: Three ...NewSpace... functions below are used during |
| 181 | // scavenge collections and iterate over sets of handles that are |
| 182 | // guaranteed to contain all handles holding new space objects (but |
| 183 | // may also include old space objects). |
| 184 | |
| 185 | // Iterates over strong and dependent handles. See the node above. |
| 186 | void IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v); |
| 187 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 188 | // Finds weak independent or partially independent handles satisfying |
| 189 | // the callback predicate and marks them as pending. See the note above. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 190 | void IdentifyNewSpaceWeakIndependentHandles(WeakSlotCallbackWithHeap f); |
| 191 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | // Iterates over weak independent or partially independent handles. |
| 193 | // See the note above. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 194 | void IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 195 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 196 | // Iterate over objects in object groups that have at least one object |
| 197 | // which requires visiting. The callback has to return true if objects |
| 198 | // can be skipped and false otherwise. |
| 199 | bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); |
| 200 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 201 | // Add an object group. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 202 | // Should be only used in GC callback function before a collection. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | // All groups are destroyed after a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 204 | void AddObjectGroup(Object*** handles, |
| 205 | size_t length, |
| 206 | v8::RetainedObjectInfo* info); |
| 207 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 208 | // Associates handle with the object group represented by id. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 209 | // Should be only used in GC callback function before a collection. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | // All groups are destroyed after a garbage collection. |
| 211 | void SetObjectGroupId(Object** handle, UniqueId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | // Set RetainedObjectInfo for an object group. Should not be called more than |
| 214 | // once for a group. Should not be called for a group which contains no |
| 215 | // handles. |
| 216 | void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 217 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | // Adds an implicit reference from a group to an object. Should be only used |
| 219 | // in GC callback function before a collection. All implicit references are |
| 220 | // destroyed after a mark-compact collection. |
| 221 | void SetReferenceFromGroup(UniqueId id, Object** child); |
| 222 | |
| 223 | // Adds an implicit reference from a parent object to a child object. Should |
| 224 | // be only used in GC callback function before a collection. All implicit |
| 225 | // references are destroyed after a mark-compact collection. |
| 226 | void SetReference(HeapObject** parent, Object** child); |
| 227 | |
| 228 | List<ObjectGroup*>* object_groups() { |
| 229 | ComputeObjectGroupsAndImplicitReferences(); |
| 230 | return &object_groups_; |
| 231 | } |
| 232 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 233 | List<ImplicitRefGroup*>* implicit_ref_groups() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | ComputeObjectGroupsAndImplicitReferences(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 235 | return &implicit_ref_groups_; |
| 236 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 237 | |
| 238 | // Remove bags, this should only happen after GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | void RemoveObjectGroups(); |
| 240 | void RemoveImplicitRefGroups(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | |
| 242 | // Tear down the global handle structure. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 243 | void TearDown(); |
| 244 | |
| 245 | Isolate* isolate() { return isolate_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 246 | |
| 247 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 248 | void PrintStats(); |
| 249 | void Print(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 252 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 253 | explicit GlobalHandles(Isolate* isolate); |
| 254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 255 | // Migrates data from the internal representation (object_group_connections_, |
| 256 | // retainer_infos_ and implicit_ref_connections_) to the public and more |
| 257 | // efficient representation (object_groups_ and implicit_ref_groups_). |
| 258 | void ComputeObjectGroupsAndImplicitReferences(); |
| 259 | |
| 260 | // v8::internal::List is inefficient even for small number of elements, if we |
| 261 | // don't assign any initial capacity. |
| 262 | static const int kObjectGroupConnectionsCapacity = 20; |
| 263 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 264 | // Internal node structures. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 265 | class Node; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 266 | class NodeBlock; |
| 267 | class NodeIterator; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 269 | Isolate* isolate_; |
| 270 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 271 | // Field always containing the number of handles to global objects. |
| 272 | int number_of_global_handles_; |
| 273 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 274 | // List of all allocated node blocks. |
| 275 | NodeBlock* first_block_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 276 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 277 | // List of node blocks with used nodes. |
| 278 | NodeBlock* first_used_block_; |
| 279 | |
| 280 | // Free list of nodes. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 281 | Node* first_free_; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 282 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 283 | // Contains all nodes holding new space objects. Note: when the list |
| 284 | // is accessed, some of the objects may have been promoted already. |
| 285 | List<Node*> new_space_nodes_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 286 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 287 | int post_gc_processing_count_; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 288 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | // Object groups and implicit references, public and more efficient |
| 290 | // representation. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 291 | List<ObjectGroup*> object_groups_; |
| 292 | List<ImplicitRefGroup*> implicit_ref_groups_; |
| 293 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 294 | // Object groups and implicit references, temporary representation while |
| 295 | // constructing the groups. |
| 296 | List<ObjectGroupConnection> object_group_connections_; |
| 297 | List<ObjectGroupRetainerInfo> retainer_infos_; |
| 298 | List<ObjectGroupConnection> implicit_ref_connections_; |
| 299 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 300 | friend class Isolate; |
| 301 | |
| 302 | DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | class EternalHandles { |
| 307 | public: |
| 308 | enum SingletonHandle { |
| 309 | I18N_TEMPLATE_ONE, |
| 310 | I18N_TEMPLATE_TWO, |
| 311 | DATE_CACHE_VERSION, |
| 312 | |
| 313 | NUMBER_OF_SINGLETON_HANDLES |
| 314 | }; |
| 315 | |
| 316 | EternalHandles(); |
| 317 | ~EternalHandles(); |
| 318 | |
| 319 | int NumberOfHandles() { return size_; } |
| 320 | |
| 321 | // Create an EternalHandle, overwriting the index. |
| 322 | void Create(Isolate* isolate, Object* object, int* index); |
| 323 | |
| 324 | // Grab the handle for an existing EternalHandle. |
| 325 | inline Handle<Object> Get(int index) { |
| 326 | return Handle<Object>(GetLocation(index)); |
| 327 | } |
| 328 | |
| 329 | // Grab the handle for an existing SingletonHandle. |
| 330 | inline Handle<Object> GetSingleton(SingletonHandle singleton) { |
| 331 | DCHECK(Exists(singleton)); |
| 332 | return Get(singleton_handles_[singleton]); |
| 333 | } |
| 334 | |
| 335 | // Checks whether a SingletonHandle has been assigned. |
| 336 | inline bool Exists(SingletonHandle singleton) { |
| 337 | return singleton_handles_[singleton] != kInvalidIndex; |
| 338 | } |
| 339 | |
| 340 | // Assign a SingletonHandle to an empty slot and returns the handle. |
| 341 | Handle<Object> CreateSingleton(Isolate* isolate, |
| 342 | Object* object, |
| 343 | SingletonHandle singleton) { |
| 344 | Create(isolate, object, &singleton_handles_[singleton]); |
| 345 | return Get(singleton_handles_[singleton]); |
| 346 | } |
| 347 | |
| 348 | // Iterates over all handles. |
| 349 | void IterateAllRoots(ObjectVisitor* visitor); |
| 350 | // Iterates over all handles which might be in new space. |
| 351 | void IterateNewSpaceRoots(ObjectVisitor* visitor); |
| 352 | // Rebuilds new space list. |
| 353 | void PostGarbageCollectionProcessing(Heap* heap); |
| 354 | |
| 355 | private: |
| 356 | static const int kInvalidIndex = -1; |
| 357 | static const int kShift = 8; |
| 358 | static const int kSize = 1 << kShift; |
| 359 | static const int kMask = 0xff; |
| 360 | |
| 361 | // Gets the slot for an index |
| 362 | inline Object** GetLocation(int index) { |
| 363 | DCHECK(index >= 0 && index < size_); |
| 364 | return &blocks_[index >> kShift][index & kMask]; |
| 365 | } |
| 366 | |
| 367 | int size_; |
| 368 | List<Object**> blocks_; |
| 369 | List<int> new_space_indices_; |
| 370 | int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
| 371 | |
| 372 | DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
| 373 | }; |
| 374 | |
| 375 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 376 | } } // namespace v8::internal |
| 377 | |
| 378 | #endif // V8_GLOBAL_HANDLES_H_ |