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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 ObjectGroup() : objects_(4) {} | 50 ObjectGroup() : objects_(4) {} |
51 explicit ObjectGroup(size_t capacity) | 51 explicit ObjectGroup(size_t capacity) |
52 : objects_(static_cast<int>(capacity)) { } | 52 : objects_(static_cast<int>(capacity)) { } |
53 | 53 |
54 List<Object**> objects_; | 54 List<Object**> objects_; |
55 }; | 55 }; |
56 | 56 |
57 | 57 |
58 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); | 58 typedef void (*WeakReferenceGuest)(Object* object, void* parameter); |
59 | 59 |
| 60 class GlobalHandlesPrivateData; |
| 61 |
| 62 class GlobalHandlesData { |
| 63 // Internal node structure, one for each global handle. |
| 64 class Node; |
| 65 |
| 66 // Field always containing the number of weak and near-death handles. |
| 67 int number_of_weak_handles_; |
| 68 |
| 69 // Field always containing the number of weak and near-death handles |
| 70 // to global objects. These objects are also included in |
| 71 // number_of_weak_handles_. |
| 72 int number_of_global_object_weak_handles_; |
| 73 |
| 74 // Global handles are kept in a single linked list pointed to by head_. |
| 75 Node* head_; |
| 76 |
| 77 // Free list for DESTROYED global handles not yet deallocated. |
| 78 Node* first_free_; |
| 79 // List of deallocated nodes. |
| 80 // Deallocated nodes form a prefix of all the nodes and |
| 81 // |first_deallocated| points to last deallocated node before |
| 82 // |head|. Those deallocated nodes are additionally linked |
| 83 // by |next_free|: |
| 84 // 1st deallocated head |
| 85 // | | |
| 86 // V V |
| 87 // node node ... node node |
| 88 // .next -> .next -> .next -> |
| 89 // <- .next_free <- .next_free <- .next_free |
| 90 Node* first_deallocated_; |
| 91 |
| 92 GlobalHandlesPrivateData& private_data_; |
| 93 friend class GlobalHandles; |
| 94 friend class V8Context; |
| 95 |
| 96 GlobalHandlesData(); |
| 97 ~GlobalHandlesData(); |
| 98 DISALLOW_COPY_AND_ASSIGN(GlobalHandlesData); |
| 99 }; |
| 100 |
60 class GlobalHandles : public AllStatic { | 101 class GlobalHandles : public AllStatic { |
61 public: | 102 public: |
62 // Creates a new global handle that is alive until Destroy is called. | 103 // Creates a new global handle that is alive until Destroy is called. |
63 static Handle<Object> Create(Object* value); | 104 static Handle<Object> Create(Object* value); |
64 | 105 |
65 // Destroy a global handle. | 106 // Destroy a global handle. |
66 static void Destroy(Object** location); | 107 static void Destroy(Object** location); |
67 | 108 |
68 // Make the global handle weak and set the callback parameter for the | 109 // Make the global handle weak and set the callback parameter for the |
69 // handle. When the garbage collector recognizes that only weak global | 110 // handle. When the garbage collector recognizes that only weak global |
70 // handles point to an object the handles are cleared and the callback | 111 // handles point to an object the handles are cleared and the callback |
71 // function is invoked (for each handle) with the handle and corresponding | 112 // function is invoked (for each handle) with the handle and corresponding |
72 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The | 113 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
73 // reason is that Smi::FromInt(0) does not change during garage collection. | 114 // reason is that Smi::FromInt(0) does not change during garage collection. |
74 static void MakeWeak(Object** location, | 115 static void MakeWeak(Object** location, |
75 void* parameter, | 116 void* parameter, |
76 WeakReferenceCallback callback); | 117 WeakReferenceCallback callback); |
77 | 118 |
78 // Returns the current number of weak handles. | 119 // Returns the current number of weak handles. |
79 static int NumberOfWeakHandles() { return number_of_weak_handles_; } | 120 static int NumberOfWeakHandles() { |
| 121 return v8_context()->global_handles_data_.number_of_weak_handles_; |
| 122 } |
80 | 123 |
81 static void RecordStats(HeapStats* stats); | 124 static void RecordStats(HeapStats* stats); |
82 | 125 |
83 // Returns the current number of weak handles to global objects. | 126 // Returns the current number of weak handles to global objects. |
84 // These handles are also included in NumberOfWeakHandles(). | 127 // These handles are also included in NumberOfWeakHandles(). |
85 static int NumberOfGlobalObjectWeakHandles() { | 128 static int NumberOfGlobalObjectWeakHandles() { |
86 return number_of_global_object_weak_handles_; | 129 return v8_context()->global_handles_data_. |
| 130 number_of_global_object_weak_handles_; |
87 } | 131 } |
88 | 132 |
89 // Clear the weakness of a global handle. | 133 // Clear the weakness of a global handle. |
90 static void ClearWeakness(Object** location); | 134 static void ClearWeakness(Object** location); |
91 | 135 |
92 // Tells whether global handle is near death. | 136 // Tells whether global handle is near death. |
93 static bool IsNearDeath(Object** location); | 137 static bool IsNearDeath(Object** location); |
94 | 138 |
95 // Tells whether global handle is weak. | 139 // Tells whether global handle is weak. |
96 static bool IsWeak(Object** location); | 140 static bool IsWeak(Object** location); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 172 |
129 // Tear down the global handle structure. | 173 // Tear down the global handle structure. |
130 static void TearDown(); | 174 static void TearDown(); |
131 | 175 |
132 #ifdef DEBUG | 176 #ifdef DEBUG |
133 static void PrintStats(); | 177 static void PrintStats(); |
134 static void Print(); | 178 static void Print(); |
135 #endif | 179 #endif |
136 class Pool; | 180 class Pool; |
137 private: | 181 private: |
138 // Internal node structure, one for each global handle. | 182 typedef GlobalHandlesData::Node Node; |
139 class Node; | 183 static Node* head() { |
| 184 return v8_context()->global_handles_data_.head_; |
| 185 } |
140 | 186 |
141 // Field always containing the number of weak and near-death handles. | 187 static void set_head(Node* value) { |
142 static int number_of_weak_handles_; | 188 v8_context()->global_handles_data_.head_ = value; |
| 189 } |
143 | 190 |
144 // Field always containing the number of weak and near-death handles | 191 static Node* first_free() { |
145 // to global objects. These objects are also included in | 192 return v8_context()->global_handles_data_.first_free_; |
146 // number_of_weak_handles_. | 193 } |
147 static int number_of_global_object_weak_handles_; | 194 static void set_first_free(Node* value) { |
| 195 v8_context()->global_handles_data_.first_free_ = value; |
| 196 } |
148 | 197 |
149 // Global handles are kept in a single linked list pointed to by head_. | 198 static Node* first_deallocated() { |
150 static Node* head_; | 199 return v8_context()->global_handles_data_.first_deallocated_; |
151 static Node* head() { return head_; } | 200 } |
152 static void set_head(Node* value) { head_ = value; } | 201 static void set_first_deallocated(Node* value) { |
| 202 v8_context()->global_handles_data_.first_deallocated_ = value; |
| 203 } |
153 | 204 |
154 // Free list for DESTROYED global handles not yet deallocated. | 205 friend class GlobalHandlesData; |
155 static Node* first_free_; | |
156 static Node* first_free() { return first_free_; } | |
157 static void set_first_free(Node* value) { first_free_ = value; } | |
158 | |
159 // List of deallocated nodes. | |
160 // Deallocated nodes form a prefix of all the nodes and | |
161 // |first_deallocated| points to last deallocated node before | |
162 // |head|. Those deallocated nodes are additionally linked | |
163 // by |next_free|: | |
164 // 1st deallocated head | |
165 // | | | |
166 // V V | |
167 // node node ... node node | |
168 // .next -> .next -> .next -> | |
169 // <- .next_free <- .next_free <- .next_free | |
170 static Node* first_deallocated_; | |
171 static Node* first_deallocated() { return first_deallocated_; } | |
172 static void set_first_deallocated(Node* value) { | |
173 first_deallocated_ = value; | |
174 } | |
175 }; | 206 }; |
176 | 207 |
177 | 208 |
178 } } // namespace v8::internal | 209 } } // namespace v8::internal |
179 | 210 |
180 #endif // V8_GLOBAL_HANDLES_H_ | 211 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |