| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // Structure for tracking global handles. | 35 // Structure for tracking global handles. |
| 36 // A single list keeps all the allocated global handles. | 36 // A single list keeps all the allocated global handles. |
| 37 // Destroyed handles stay in the list but is added to the free list. | 37 // Destroyed handles stay in the list but is added to the free list. |
| 38 // At GC the destroyed global handles are removed from the free list | 38 // At GC the destroyed global handles are removed from the free list |
| 39 // and deallocated. | 39 // and deallocated. |
| 40 | 40 |
| 41 // Callback function on handling weak global handles. | 41 // Callback function on handling weak global handles. |
| 42 // typedef bool (*WeakSlotCallback)(Object** pointer); | 42 // typedef bool (*WeakSlotCallback)(Object** pointer); |
| 43 | 43 |
| 44 // An object group is indexed by an id. An object group is treated like | 44 // An object group is treated like a single JS object: if one of object in |
| 45 // a single JS object: if one of object in the group is alive, | 45 // the group is alive, all objects in the same group are considered alive. |
| 46 // all objects in the same group are considered alive. | |
| 47 // 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. |
| 48 class ObjectGroup : public Malloced { | 47 class ObjectGroup : public Malloced { |
| 49 public: | 48 public: |
| 50 explicit ObjectGroup(void* id) : id_(id), objects_(4) {} | 49 ObjectGroup() : objects_(4) {} |
| 50 explicit ObjectGroup(size_t capacity) : objects_(capacity) {} |
| 51 | 51 |
| 52 void* id_; | |
| 53 List<Object**> objects_; | 52 List<Object**> objects_; |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 | 55 |
| 57 class GlobalHandles : public AllStatic { | 56 class GlobalHandles : public AllStatic { |
| 58 public: | 57 public: |
| 59 // Creates a new global handle that is alive until Destroy is called. | 58 // Creates a new global handle that is alive until Destroy is called. |
| 60 static Handle<Object> Create(Object* value); | 59 static Handle<Object> Create(Object* value); |
| 61 | 60 |
| 62 // Destroy a global handle. | 61 // Destroy a global handle. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 94 |
| 96 // Iterates over all handles. | 95 // Iterates over all handles. |
| 97 static void IterateRoots(ObjectVisitor* v); | 96 static void IterateRoots(ObjectVisitor* v); |
| 98 | 97 |
| 99 // Iterates over all weak roots in heap. | 98 // Iterates over all weak roots in heap. |
| 100 static void IterateWeakRoots(ObjectVisitor* v); | 99 static void IterateWeakRoots(ObjectVisitor* v); |
| 101 | 100 |
| 102 // Mark the weak pointers based on the callback. | 101 // Mark the weak pointers based on the callback. |
| 103 static void MarkWeakRoots(WeakSlotCallback f); | 102 static void MarkWeakRoots(WeakSlotCallback f); |
| 104 | 103 |
| 105 // Add an object to a group indexed by an id. | 104 // Add an object group. |
| 106 // Should only used in GC callback function before a collection. | 105 // Should only used in GC callback function before a collection. |
| 107 // All groups are destroyed after a mark-compact collection. | 106 // All groups are destroyed after a mark-compact collection. |
| 108 static void AddToGroup(void* id, Object** location); | 107 static void AddGroup(Object*** handles, size_t length); |
| 109 | 108 |
| 110 // Returns the object groups. | 109 // Returns the object groups. |
| 111 static List<ObjectGroup*>& ObjectGroups() { | 110 static List<ObjectGroup*>* ObjectGroups(); |
| 112 return object_groups_; | |
| 113 } | |
| 114 | 111 |
| 115 // Remove bags, this should only happen after GC. | 112 // Remove bags, this should only happen after GC. |
| 116 static void RemoveObjectGroups(); | 113 static void RemoveObjectGroups(); |
| 117 | 114 |
| 118 // Tear down the global handle structure. | 115 // Tear down the global handle structure. |
| 119 static void TearDown(); | 116 static void TearDown(); |
| 120 | 117 |
| 121 #ifdef DEBUG | 118 #ifdef DEBUG |
| 122 static void PrintStats(); | 119 static void PrintStats(); |
| 123 static void Print(); | 120 static void Print(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 | 133 |
| 137 // Global handles are kept in a single linked list pointed to by head_. | 134 // Global handles are kept in a single linked list pointed to by head_. |
| 138 static Node* head_; | 135 static Node* head_; |
| 139 static Node* head() { return head_; } | 136 static Node* head() { return head_; } |
| 140 static void set_head(Node* value) { head_ = value; } | 137 static void set_head(Node* value) { head_ = value; } |
| 141 | 138 |
| 142 // Free list for DESTROYED global handles not yet deallocated. | 139 // Free list for DESTROYED global handles not yet deallocated. |
| 143 static Node* first_free_; | 140 static Node* first_free_; |
| 144 static Node* first_free() { return first_free_; } | 141 static Node* first_free() { return first_free_; } |
| 145 static void set_first_free(Node* value) { first_free_ = value; } | 142 static void set_first_free(Node* value) { first_free_ = value; } |
| 146 | |
| 147 // A list of object groups. | |
| 148 static List<ObjectGroup*> object_groups_; | |
| 149 }; | 143 }; |
| 150 | 144 |
| 151 | 145 |
| 152 } } // namespace v8::internal | 146 } } // namespace v8::internal |
| 153 | 147 |
| 154 #endif // V8_GLOBAL_HANDLES_H_ | 148 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |