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

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

Issue 14294009: Revert the commits adding new GC-related APIs. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: remove test 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 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"
32 #include "../include/v8-profiler.h" 31 #include "../include/v8-profiler.h"
33 32
34 #include "list.h" 33 #include "list.h"
35 #include "v8utils.h" 34 #include "v8utils.h"
36 35
37 namespace v8 { 36 namespace v8 {
38 namespace internal { 37 namespace internal {
39 38
40 class GCTracer; 39 class GCTracer;
41 class HeapStats; 40 class HeapStats;
42 class ObjectVisitor; 41 class ObjectVisitor;
43 42
44 // Structure for tracking global handles. 43 // Structure for tracking global handles.
45 // A single list keeps all the allocated global handles. 44 // A single list keeps all the allocated global handles.
46 // Destroyed handles stay in the list but is added to the free list. 45 // Destroyed handles stay in the list but is added to the free list.
47 // At GC the destroyed global handles are removed from the free list 46 // At GC the destroyed global handles are removed from the free list
48 // and deallocated. 47 // and deallocated.
49 48
50 // Data structures for tracking object groups and implicit references.
51
52 // An object group is treated like a single JS object: if one of object in 49 // An object group is treated like a single JS object: if one of object in
53 // the group is alive, all objects in the same group are considered alive. 50 // the group is alive, all objects in the same group are considered alive.
54 // An object group is used to simulate object relationship in a DOM tree. 51 // An object group is used to simulate object relationship in a DOM tree.
55 52 class ObjectGroup {
56 // An implicit references group consists of two parts: a parent object and a 53 public:
57 // list of children objects. If the parent is alive, all the children are alive 54 static ObjectGroup* New(Object*** handles,
58 // too. 55 size_t length,
59 56 v8::RetainedObjectInfo* info) {
60 struct ObjectGroupConnection { 57 ASSERT(length > 0);
61 ObjectGroupConnection(UniqueId id, Object** object) 58 ObjectGroup* group = reinterpret_cast<ObjectGroup*>(
62 : id(id), object(object) {} 59 malloc(OFFSET_OF(ObjectGroup, objects_[length])));
63 60 group->length_ = length;
64 bool operator==(const ObjectGroupConnection& other) const { 61 group->info_ = info;
65 return id == other.id; 62 CopyWords(group->objects_, handles, static_cast<int>(length));
63 return group;
66 } 64 }
67 65
68 bool operator<(const ObjectGroupConnection& other) const { 66 void Dispose() {
69 return id < other.id; 67 if (info_ != NULL) info_->Dispose();
68 free(this);
70 } 69 }
71 70
72 UniqueId id; 71 size_t length_;
73 Object** object; 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);
74 }; 80 };
75 81
76 82
77 struct ObjectGroupRetainerInfo { 83 // An implicit references group consists of two parts: a parent object and
78 ObjectGroupRetainerInfo(UniqueId id, RetainedObjectInfo* info) 84 // a list of children objects. If the parent is alive, all the children
79 : id(id), info(info) {} 85 // are alive too.
80 86 class ImplicitRefGroup {
81 bool operator==(const ObjectGroupRetainerInfo& other) const { 87 public:
82 return id == other.id; 88 static ImplicitRefGroup* New(HeapObject** parent,
89 Object*** children,
90 size_t length) {
91 ASSERT(length > 0);
92 ImplicitRefGroup* group = reinterpret_cast<ImplicitRefGroup*>(
93 malloc(OFFSET_OF(ImplicitRefGroup, children_[length])));
94 group->parent_ = parent;
95 group->length_ = length;
96 CopyWords(group->children_, children, length);
97 return group;
83 } 98 }
84 99
85 bool operator<(const ObjectGroupRetainerInfo& other) const { 100 void Dispose() {
86 return id < other.id; 101 free(this);
87 } 102 }
88 103
89 UniqueId id; 104 HeapObject** parent_;
90 RetainedObjectInfo* info; 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);
91 }; 113 };
92 114
93 115
94 struct ObjectGroupRepresentative {
95 ObjectGroupRepresentative(UniqueId id, HeapObject** object)
96 : id(id), object(object) {}
97
98 bool operator==(const ObjectGroupRepresentative& other) const {
99 return id == other.id;
100 }
101
102 bool operator<(const ObjectGroupRepresentative& other) const {
103 return id < other.id;
104 }
105
106 UniqueId id;
107 HeapObject** object;
108 };
109
110
111 class GlobalHandles { 116 class GlobalHandles {
112 public: 117 public:
113 ~GlobalHandles(); 118 ~GlobalHandles();
114 119
115 // Creates a new global handle that is alive until Destroy is called. 120 // Creates a new global handle that is alive until Destroy is called.
116 Handle<Object> Create(Object* value); 121 Handle<Object> Create(Object* value);
117 122
118 // Destroy a global handle. 123 // Destroy a global handle.
119 void Destroy(Object** location); 124 void Destroy(Object** location);
120 125
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // can be skipped and false otherwise. 211 // can be skipped and false otherwise.
207 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip); 212 bool IterateObjectGroups(ObjectVisitor* v, WeakSlotCallbackWithHeap can_skip);
208 213
209 // Add an object group. 214 // Add an object group.
210 // Should be only used in GC callback function before a collection. 215 // Should be only used in GC callback function before a collection.
211 // All groups are destroyed after a garbage collection. 216 // All groups are destroyed after a garbage collection.
212 void AddObjectGroup(Object*** handles, 217 void AddObjectGroup(Object*** handles,
213 size_t length, 218 size_t length,
214 v8::RetainedObjectInfo* info); 219 v8::RetainedObjectInfo* info);
215 220
216 // Associates handle with the object group represented by id.
217 // Should be only used in GC callback function before a collection.
218 // All groups are destroyed after a garbage collection.
219 void SetObjectGroupId(Object** handle, UniqueId id);
220
221 // Set RetainedObjectInfo for an object group. Should not be called more than
222 // once for a group. Should not be called for a group which contains no
223 // handles.
224 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
225
226 // Sets a representative object for an object group. Should not be called more
227 // than once for a group. Should not be called for a group which contains no
228 // handles.
229 void SetObjectGroupRepresentative(UniqueId id,
230 HeapObject** representative_object);
231
232 // Add an implicit references' group. 221 // Add an implicit references' group.
233 // Should be only used in GC callback function before a collection. 222 // Should be only used in GC callback function before a collection.
234 // All groups are destroyed after a mark-compact collection. 223 // All groups are destroyed after a mark-compact collection.
235 void AddImplicitReferences(HeapObject** parent, 224 void AddImplicitReferences(HeapObject** parent,
236 Object*** children, 225 Object*** children,
237 size_t length); 226 size_t length);
238 227
239 // Adds an implicit reference from a group (representative object of that 228 // Returns the object groups.
240 // group) to an object. Should be only used in GC callback function before a 229 List<ObjectGroup*>* object_groups() { return &object_groups_; }
241 // collection. All implicit references are destroyed after a mark-compact
242 // collection.
243 void AddImplicitReference(UniqueId id, Object** child);
244 230
245 List<ObjectGroupConnection>* object_groups() { 231 // Returns the implicit references' groups.
246 return &object_groups_; 232 List<ImplicitRefGroup*>* implicit_ref_groups() {
247 }
248
249 List<ObjectGroupRetainerInfo>* retainer_infos() {
250 return &retainer_infos_;
251 }
252
253 List<ObjectGroupConnection>* implicit_ref_groups() {
254 return &implicit_ref_groups_; 233 return &implicit_ref_groups_;
255 } 234 }
256 235
257 List<ObjectGroupRepresentative>* representative_objects() {
258 return &representative_objects_;
259 }
260
261 // Remove bags, this should only happen after GC. 236 // Remove bags, this should only happen after GC.
262 void RemoveObjectGroups(); 237 void RemoveObjectGroups();
263 void RemoveImplicitRefGroups(); 238 void RemoveImplicitRefGroups();
264 239
265 // Tear down the global handle structure. 240 // Tear down the global handle structure.
266 void TearDown(); 241 void TearDown();
267 242
268 Isolate* isolate() { return isolate_; } 243 Isolate* isolate() { return isolate_; }
269 244
270 #ifdef DEBUG 245 #ifdef DEBUG
(...skipping 22 matching lines...) Expand all
293 268
294 // Free list of nodes. 269 // Free list of nodes.
295 Node* first_free_; 270 Node* first_free_;
296 271
297 // Contains all nodes holding new space objects. Note: when the list 272 // Contains all nodes holding new space objects. Note: when the list
298 // is accessed, some of the objects may have been promoted already. 273 // is accessed, some of the objects may have been promoted already.
299 List<Node*> new_space_nodes_; 274 List<Node*> new_space_nodes_;
300 275
301 int post_gc_processing_count_; 276 int post_gc_processing_count_;
302 277
303 // Object groups. 278 List<ObjectGroup*> object_groups_;
304 List<ObjectGroupConnection> object_groups_; 279 List<ImplicitRefGroup*> implicit_ref_groups_;
305 List<ObjectGroupRetainerInfo> retainer_infos_;
306 List<ObjectGroupRepresentative> representative_objects_;
307
308 // Implicit references.
309 List<ObjectGroupConnection> implicit_ref_groups_;
310 280
311 friend class Isolate; 281 friend class Isolate;
312 282
313 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); 283 DISALLOW_COPY_AND_ASSIGN(GlobalHandles);
314 }; 284 };
315 285
316 286
317 } } // namespace v8::internal 287 } } // namespace v8::internal
318 288
319 #endif // V8_GLOBAL_HANDLES_H_ 289 #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