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

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

Issue 13786002: [WIP] New GC related APIs. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/api.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 // 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 26 matching lines...) Expand all
37 37
38 // Structure for tracking global handles. 38 // Structure for tracking global handles.
39 // A single list keeps all the allocated global handles. 39 // A single list keeps all the allocated global handles.
40 // Destroyed handles stay in the list but is added to the free list. 40 // Destroyed handles stay in the list but is added to the free list.
41 // At GC the destroyed global handles are removed from the free list 41 // At GC the destroyed global handles are removed from the free list
42 // and deallocated. 42 // and deallocated.
43 43
44 // An object group is treated like a single JS object: if one of object in 44 // An object group is treated like a single JS object: if one of object in
45 // the group is alive, all objects in the same group are considered alive. 45 // the group is alive, all objects in the same group are considered alive.
46 // An object group is used to simulate object relationship in a DOM tree. 46 // An object group is used to simulate object relationship in a DOM tree.
47 class ObjectGroup { 47 struct ObjectGroup {
48 public: 48 public:
Sven Panne 2013/04/09 11:12:45 No need for "public" here...
49 static ObjectGroup* New(Object*** handles, 49 ObjectGroup()
50 size_t length, 50 : info(NULL) {}
51 v8::RetainedObjectInfo* info) { 51
52 ASSERT(length > 0); 52 ~ObjectGroup();
53 ObjectGroup* group = reinterpret_cast<ObjectGroup*>( 53
54 malloc(OFFSET_OF(ObjectGroup, objects_[length]))); 54 v8::RetainedObjectInfo* info;
55 group->length_ = length; 55 List<Object**> objects;
56 group->info_ = info; 56 };
57 CopyWords(group->objects_, handles, static_cast<int>(length)); 57
58 return group; 58
59 struct ObjectGroupConnection {
60 ObjectGroupConnection(void* id, Object** object)
61 : id(id), object(object) {}
62
63 bool operator==(const ObjectGroupConnection& other) const {
64 return id == other.id;
59 } 65 }
60 66
61 void Dispose() { 67 bool operator<(const ObjectGroupConnection& other) const {
62 if (info_ != NULL) info_->Dispose(); 68 return id < other.id;
63 free(this);
64 } 69 }
65 70
66 size_t length_; 71 void* id;
67 v8::RetainedObjectInfo* info_; 72 Object** object;
68 Object** objects_[1]; // Variable sized array.
69
70 private:
71 void* operator new(size_t size);
72 void operator delete(void* p);
73 ~ObjectGroup();
74 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGroup);
75 }; 73 };
76 74
77 75
76 struct GroupRetainedObjectInfo {
77 GroupRetainedObjectInfo(void* id, RetainedObjectInfo* info)
78 : id(id), info(info) {}
79
80 ~GroupRetainedObjectInfo();
81
82 bool operator==(const GroupRetainedObjectInfo& other) const {
83 return id == other.id;
84 }
85
86 bool operator<(const GroupRetainedObjectInfo& other) const {
87 return id < other.id;
88 }
89
90 void* id;
91 RetainedObjectInfo* info;
92 };
93
78 // An implicit references group consists of two parts: a parent object and 94 // An implicit references group consists of two parts: a parent object and
79 // a list of children objects. If the parent is alive, all the children 95 // a list of children objects. If the parent is alive, all the children
80 // are alive too. 96 // are alive too.
81 class ImplicitRefGroup { 97 class ImplicitRefGroup {
82 public: 98 public:
83 static ImplicitRefGroup* New(HeapObject** parent, 99 static ImplicitRefGroup* New(HeapObject** parent,
84 Object*** children, 100 Object*** children,
85 size_t length) { 101 size_t length) {
86 ASSERT(length > 0); 102 ASSERT(length > 0);
87 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>( 103 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // can be skipped and false otherwise. 222 // can be skipped and false otherwise.
207 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); 223 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip);
208 224
209 // Add an object group. 225 // Add an object group.
210 // Should be only used in GC callback function before a collection. 226 // Should be only used in GC callback function before a collection.
211 // All groups are destroyed after a garbage collection. 227 // All groups are destroyed after a garbage collection.
212 void AddObjectGroup(Object*** handles, 228 void AddObjectGroup(Object*** handles,
213 size_t length, 229 size_t length,
214 v8::RetainedObjectInfo* info); 230 v8::RetainedObjectInfo* info);
215 231
232 // Associates handle with the object group represented by id.
233 // Should be only used in GC callback function before a collection.
234 // All groups are destroyed after a garbage collection.
235 void SetObjectGroupId(Object** handle,
236 void* id);
237
238 void SetRetainedObjectInfo(void* id,
239 RetainedObjectInfo* info = NULL);
240
216 // Add an implicit references' group. 241 // Add an implicit references' group.
217 // Should be only used in GC callback function before a collection. 242 // Should be only used in GC callback function before a collection.
218 // All groups are destroyed after a mark-compact collection. 243 // All groups are destroyed after a mark-compact collection.
219 void AddImplicitReferences(HeapObject** parent, 244 void AddImplicitReferences(HeapObject** parent,
220 Object*** children, 245 Object*** children,
221 size_t length); 246 size_t length);
222 247
223 // Returns the object groups. 248 // Returns the object groups. Caller takes ownership of the list, and the
224 List<ObjectGroup*>* object_groups() { return &object_groups_; } 249 // ObjectGroup pointers in it, and the RetainedObjectInfo pointers in the
250 // object groups.
251 List<ObjectGroup*>* object_groups();
225 252
226 // Returns the implicit references' groups. 253 // Returns the implicit references' groups.
227 List<ImplicitRefGroup*>* implicit_ref_groups() { 254 List<ImplicitRefGroup*>* implicit_ref_groups() {
228 return &implicit_ref_groups_; 255 return &implicit_ref_groups_;
229 } 256 }
230 257
231 // Remove bags, this should only happen after GC. 258 // Remove bags, this should only happen after GC.
232 void RemoveObjectGroups(); 259 void RemoveObjectGroups();
233 void RemoveImplicitRefGroups(); 260 void RemoveImplicitRefGroups();
234 261
(...skipping 28 matching lines...) Expand all
263 290
264 // Free list of nodes. 291 // Free list of nodes.
265 Node* first_free_; 292 Node* first_free_;
266 293
267 // Contains all nodes holding new space objects. Note: when the list 294 // Contains all nodes holding new space objects. Note: when the list
268 // is accessed, some of the objects may have been promoted already. 295 // is accessed, some of the objects may have been promoted already.
269 List<Node*> new_space_nodes_; 296 List<Node*> new_space_nodes_;
270 297
271 int post_gc_processing_count_; 298 int post_gc_processing_count_;
272 299
273 List<ObjectGroup*> object_groups_; 300 List<ObjectGroupConnection>* object_groups_;
301 List<GroupRetainedObjectInfo> retained_object_infos_;
274 List<ImplicitRefGroup*> implicit_ref_groups_; 302 List<ImplicitRefGroup*> implicit_ref_groups_;
275 303
276 friend class Isolate; 304 friend class Isolate;
277 305
278 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); 306 DISALLOW_COPY_AND_ASSIGN(GlobalHandles);
279 }; 307 };
280 308
281 309
282 } } // namespace v8::internal 310 } } // namespace v8::internal
283 311
284 #endif // V8_GLOBAL_HANDLES_H_ 312 #endif // V8_GLOBAL_HANDLES_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/global-handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698