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

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

Issue 14007008: New GC APIs, try 2. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Moving funcs & code review. Created 7 years, 8 months 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_GLOBAL_HANDLES_H_ 28 #ifndef V8_GLOBAL_HANDLES_H_
29 #define V8_GLOBAL_HANDLES_H_ 29 #define V8_GLOBAL_HANDLES_H_
30 30
31 #include "../include/v8.h"
31 #include "../include/v8-profiler.h" 32 #include "../include/v8-profiler.h"
32 33
33 #include "list.h" 34 #include "list.h"
34 #include "v8utils.h" 35 #include "v8utils.h"
35 36
36 namespace v8 { 37 namespace v8 {
37 namespace internal { 38 namespace internal {
38 39
39 class GCTracer; 40 class GCTracer;
40 class HeapStats; 41 class HeapStats;
41 class ObjectVisitor; 42 class ObjectVisitor;
42 43
43 // Structure for tracking global handles. 44 // Structure for tracking global handles.
44 // A single list keeps all the allocated global handles. 45 // A single list keeps all the allocated global handles.
45 // Destroyed handles stay in the list but is added to the free list. 46 // Destroyed handles stay in the list but is added to the free list.
46 // At GC the destroyed global handles are removed from the free list 47 // At GC the destroyed global handles are removed from the free list
47 // and deallocated. 48 // and deallocated.
48 49
50 // Data structures for tracking object groups and implicit references.
51
49 // An object group is treated like a single JS object: if one of object in 52 // An object group is treated like a single JS object: if one of object in
50 // the group is alive, all objects in the same group are considered alive. 53 // the group is alive, all objects in the same group are considered alive.
51 // An object group is used to simulate object relationship in a DOM tree. 54 // An object group is used to simulate object relationship in a DOM tree.
52 class ObjectGroup { 55
53 public: 56 // An implicit references group consists of two parts: a parent object and a
54 static ObjectGroup* New(Object*** handles, 57 // list of children objects. If the parent is alive, all the children are alive
55 size_t length, 58 // too.
56 v8::RetainedObjectInfo* info) { 59
60 struct ObjectGroup {
61 explicit ObjectGroup(size_t length)
62 : info(NULL), length(length) {
57 ASSERT(length > 0); 63 ASSERT(length > 0);
58 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( 64 objects = new Object**[length];
59 malloc(OFFSET_OF(ObjectGroup, objects_[length])));
60 group->length_ = length;
61 group->info_ = info;
62 CopyWords(group->objects_, handles, static_cast<int>(length));
63 return group;
64 } 65 }
66 ~ObjectGroup();
65 67
66 void Dispose() { 68 v8::RetainedObjectInfo* info;
67 if (info_ != NULL) info_->Dispose(); 69 Object*** objects;
68 free(this); 70 size_t length;
69 }
70
71 size_t length_;
72 v8::RetainedObjectInfo* info_;
73 Object** objects_[1]; // Variable sized array.
74
75 private:
76 void* operator new(size_t size);
77 void operator delete(void* p);
78 ~ObjectGroup();
79 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGroup);
80 }; 71 };
81 72
82 73
83 // An implicit references group consists of two parts: a parent object and 74 struct ImplicitRefGroup {
84 // a list of children objects. If the parent is alive, all the children 75 ImplicitRefGroup(HeapObject** parent, size_t length)
85 // are alive too. 76 : parent(parent), length(length) {
86 class ImplicitRefGroup {
87 public:
88 static ImplicitRefGroup* New(HeapObject** parent,
89 Object*** children,
90 size_t length) {
91 ASSERT(length > 0); 77 ASSERT(length > 0);
92 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( 78 children = new Object**[length];
93 malloc(OFFSET_OF(ImplicitRefGroup, children_[length])));
94 group->parent_ = parent;
95 group->length_ = length;
96 CopyWords(group->children_, children, length);
97 return group;
98 } 79 }
80 ~ImplicitRefGroup();
99 81
100 void Dispose() { 82 HeapObject** parent;
101 free(this); 83 Object*** children;
102 } 84 size_t length;
103
104 HeapObject** parent_;
105 size_t length_;
106 Object** children_[1]; // Variable sized array.
107
108 private:
109 void* operator new(size_t size);
110 void operator delete(void* p);
111 ~ImplicitRefGroup();
112 DISALLOW_IMPLICIT_CONSTRUCTORS(ImplicitRefGroup);
113 }; 85 };
114 86
115 87
88 // For internal bookeeping.
yurys 2013/04/22 14:39:54 typo: bookkeeping
marja 2013/04/23 12:00:05 Done.
89 struct ObjectGroupConnection {
90 ObjectGroupConnection(UniqueId id, Object** object)
91 : id(id), object(object) {}
92
93 bool operator==(const ObjectGroupConnection& other) const {
94 return id == other.id;
95 }
96
97 bool operator<(const ObjectGroupConnection& other) const {
98 return id < other.id;
99 }
100
101 UniqueId id;
102 Object** object;
103 };
104
105
106 struct ObjectGroupRetainerInfo {
107 ObjectGroupRetainerInfo(UniqueId id, RetainedObjectInfo* info)
108 : id(id), info(info) {}
109
110 bool operator==(const ObjectGroupRetainerInfo& other) const {
111 return id == other.id;
112 }
113
114 bool operator<(const ObjectGroupRetainerInfo& other) const {
115 return id < other.id;
116 }
117
118 UniqueId id;
119 RetainedObjectInfo* info;
120 };
121
122
116 class GlobalHandles { 123 class GlobalHandles {
117 public: 124 public:
118 ~GlobalHandles(); 125 ~GlobalHandles();
119 126
120 // Creates a new global handle that is alive until Destroy is called. 127 // Creates a new global handle that is alive until Destroy is called.
121 Handle<Object> Create(Object* value); 128 Handle<Object> Create(Object* value);
122 129
123 // Destroy a global handle. 130 // Destroy a global handle.
124 void Destroy(Object** location); 131 void Destroy(Object** location);
125 132
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // can be skipped and false otherwise. 218 // can be skipped and false otherwise.
212 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); 219 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip);
213 220
214 // Add an object group. 221 // Add an object group.
215 // Should be only used in GC callback function before a collection. 222 // Should be only used in GC callback function before a collection.
216 // All groups are destroyed after a garbage collection. 223 // All groups are destroyed after a garbage collection.
217 void AddObjectGroup(Object*** handles, 224 void AddObjectGroup(Object*** handles,
218 size_t length, 225 size_t length,
219 v8::RetainedObjectInfo* info); 226 v8::RetainedObjectInfo* info);
220 227
228 // Associates handle with the object group represented by id.
229 // Should be only used in GC callback function before a collection.
230 // All groups are destroyed after a garbage collection.
231 void SetObjectGroupId(Object** handle, UniqueId id);
232
233 // Set RetainedObjectInfo for an object group. Should not be called more than
234 // once for a group. Should not be called for a group which contains no
235 // handles.
236 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
237
221 // Add an implicit references' group. 238 // Add an implicit references' group.
222 // Should be only used in GC callback function before a collection. 239 // Should be only used in GC callback function before a collection.
223 // All groups are destroyed after a mark-compact collection. 240 // All groups are destroyed after a mark-compact collection.
224 void AddImplicitReferences(HeapObject** parent, 241 void AddImplicitReferences(HeapObject** parent,
225 Object*** children, 242 Object*** children,
226 size_t length); 243 size_t length);
227 244
228 // Returns the object groups. 245 // Adds an implicit reference from a group (representative object of that
229 List<ObjectGroup*>* object_groups() { return &object_groups_; } 246 // group) to an object. Should be only used in GC callback function before a
247 // collection. All implicit references are destroyed after a mark-compact
248 // collection.
249 void AddImplicitReference(UniqueId id, Object** child);
230 250
231 // Returns the implicit references' groups. 251 List<ObjectGroup*>* object_groups() {
252 ComputeObjectGroupsAndImplicitReferences();
253 return &object_groups_;
254 }
255
232 List<ImplicitRefGroup*>* implicit_ref_groups() { 256 List<ImplicitRefGroup*>* implicit_ref_groups() {
257 ComputeObjectGroupsAndImplicitReferences();
233 return &implicit_ref_groups_; 258 return &implicit_ref_groups_;
234 } 259 }
235 260
236 // Remove bags, this should only happen after GC. 261 // Remove bags, this should only happen after GC.
237 void RemoveObjectGroups(); 262 void RemoveObjectGroups();
238 void RemoveImplicitRefGroups(); 263 void RemoveImplicitRefGroups();
239 264
240 // Tear down the global handle structure. 265 // Tear down the global handle structure.
241 void TearDown(); 266 void TearDown();
242 267
243 Isolate* isolate() { return isolate_; } 268 Isolate* isolate() { return isolate_; }
244 269
245 #ifdef DEBUG 270 #ifdef DEBUG
246 void PrintStats(); 271 void PrintStats();
247 void Print(); 272 void Print();
248 #endif 273 #endif
249 274
250 private: 275 private:
251 explicit GlobalHandles(Isolate* isolate); 276 explicit GlobalHandles(Isolate* isolate);
252 277
278 // Migrates data from the internal representation (object_group_connections_,
279 // retainer_infos_ and implicit_ref_connections_) to the public and more
280 // efficient representation (object_groups_ and implicit_ref_groups_).
281 void ComputeObjectGroupsAndImplicitReferences();
282
283 // v8::internal::List is inefficient even for small number of elements, if we
284 // don't assign any initial capacity.
285 static const int kObjectGroupConnectionsCapacity;
286
253 // Internal node structures. 287 // Internal node structures.
254 class Node; 288 class Node;
255 class NodeBlock; 289 class NodeBlock;
256 class NodeIterator; 290 class NodeIterator;
257 291
258 Isolate* isolate_; 292 Isolate* isolate_;
259 293
260 // Field always containing the number of handles to global objects. 294 // Field always containing the number of handles to global objects.
261 int number_of_global_handles_; 295 int number_of_global_handles_;
262 296
263 // List of all allocated node blocks. 297 // List of all allocated node blocks.
264 NodeBlock* first_block_; 298 NodeBlock* first_block_;
265 299
266 // List of node blocks with used nodes. 300 // List of node blocks with used nodes.
267 NodeBlock* first_used_block_; 301 NodeBlock* first_used_block_;
268 302
269 // Free list of nodes. 303 // Free list of nodes.
270 Node* first_free_; 304 Node* first_free_;
271 305
272 // Contains all nodes holding new space objects. Note: when the list 306 // Contains all nodes holding new space objects. Note: when the list
273 // is accessed, some of the objects may have been promoted already. 307 // is accessed, some of the objects may have been promoted already.
274 List<Node*> new_space_nodes_; 308 List<Node*> new_space_nodes_;
275 309
276 int post_gc_processing_count_; 310 int post_gc_processing_count_;
277 311
312 // Object groups and implicit references, public and more efficient
313 // representation.
278 List<ObjectGroup*> object_groups_; 314 List<ObjectGroup*> object_groups_;
279 List<ImplicitRefGroup*> implicit_ref_groups_; 315 List<ImplicitRefGroup*> implicit_ref_groups_;
280 316
317 // Object groups and implicit references, temporary representation while
318 // constructing the groups.
319 List<ObjectGroupConnection> object_group_connections_;
320 List<ObjectGroupRetainerInfo> retainer_infos_;
321 List<ObjectGroupConnection> implicit_ref_connections_;
322
281 friend class Isolate; 323 friend class Isolate;
282 324
283 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); 325 DISALLOW_COPY_AND_ASSIGN(GlobalHandles);
284 }; 326 };
285 327
286 328
287 } } // namespace v8::internal 329 } } // namespace v8::internal
288 330
289 #endif // V8_GLOBAL_HANDLES_H_ 331 #endif // V8_GLOBAL_HANDLES_H_
OLDNEW
« include/v8.h ('K') | « src/api.cc ('k') | src/global-handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698