OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 55 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
56 public: | 56 public: |
57 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 57 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
58 | 58 |
59 bool has_been_disposed() { return has_been_disposed_; } | 59 bool has_been_disposed() { return has_been_disposed_; } |
60 | 60 |
61 virtual void Dispose() { | 61 virtual void Dispose() { |
62 DCHECK(!has_been_disposed_); | 62 CHECK(!has_been_disposed_); |
63 has_been_disposed_ = true; | 63 has_been_disposed_ = true; |
64 } | 64 } |
65 | 65 |
66 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { | 66 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { |
67 return other == this; | 67 return other == this; |
68 } | 68 } |
69 | 69 |
70 virtual intptr_t GetHash() { return 0; } | 70 virtual intptr_t GetHash() { return 0; } |
71 | 71 |
72 virtual const char* GetLabel() { return "whatever"; } | 72 virtual const char* GetLabel() { return "whatever"; } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 { | 117 { |
118 ResetCanSkipData(); | 118 ResetCanSkipData(); |
119 skippable_objects.Add(*g1s1.location()); | 119 skippable_objects.Add(*g1s1.location()); |
120 skippable_objects.Add(*g1s2.location()); | 120 skippable_objects.Add(*g1s2.location()); |
121 skippable_objects.Add(*g2s1.location()); | 121 skippable_objects.Add(*g2s1.location()); |
122 skippable_objects.Add(*g2s2.location()); | 122 skippable_objects.Add(*g2s2.location()); |
123 TestObjectVisitor visitor; | 123 TestObjectVisitor visitor; |
124 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 124 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
125 | 125 |
126 // CanSkipCallback was called for all objects. | 126 // CanSkipCallback was called for all objects. |
127 DCHECK(can_skip_called_objects.length() == 4); | 127 CHECK(can_skip_called_objects.length() == 4); |
128 DCHECK(can_skip_called_objects.Contains(*g1s1.location())); | 128 CHECK(can_skip_called_objects.Contains(*g1s1.location())); |
129 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); | 129 CHECK(can_skip_called_objects.Contains(*g1s2.location())); |
130 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); | 130 CHECK(can_skip_called_objects.Contains(*g2s1.location())); |
131 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); | 131 CHECK(can_skip_called_objects.Contains(*g2s2.location())); |
132 | 132 |
133 // Nothing was visited. | 133 // Nothing was visited. |
134 DCHECK(visitor.visited.length() == 0); | 134 CHECK(visitor.visited.length() == 0); |
135 DCHECK(!info1.has_been_disposed()); | 135 CHECK(!info1.has_been_disposed()); |
136 DCHECK(!info2.has_been_disposed()); | 136 CHECK(!info2.has_been_disposed()); |
137 } | 137 } |
138 | 138 |
139 // Iterate again, now only skip the second object group. | 139 // Iterate again, now only skip the second object group. |
140 { | 140 { |
141 ResetCanSkipData(); | 141 ResetCanSkipData(); |
142 // The first grough should still be visited, since only one object is | 142 // The first grough should still be visited, since only one object is |
143 // skipped. | 143 // skipped. |
144 skippable_objects.Add(*g1s1.location()); | 144 skippable_objects.Add(*g1s1.location()); |
145 skippable_objects.Add(*g2s1.location()); | 145 skippable_objects.Add(*g2s1.location()); |
146 skippable_objects.Add(*g2s2.location()); | 146 skippable_objects.Add(*g2s2.location()); |
147 TestObjectVisitor visitor; | 147 TestObjectVisitor visitor; |
148 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 148 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
149 | 149 |
150 // CanSkipCallback was called for all objects. | 150 // CanSkipCallback was called for all objects. |
151 DCHECK(can_skip_called_objects.length() == 3 || | 151 CHECK(can_skip_called_objects.length() == 3 || |
152 can_skip_called_objects.length() == 4); | 152 can_skip_called_objects.length() == 4); |
153 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); | 153 CHECK(can_skip_called_objects.Contains(*g1s2.location())); |
154 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); | 154 CHECK(can_skip_called_objects.Contains(*g2s1.location())); |
155 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); | 155 CHECK(can_skip_called_objects.Contains(*g2s2.location())); |
156 | 156 |
157 // The first group was visited. | 157 // The first group was visited. |
158 DCHECK(visitor.visited.length() == 2); | 158 CHECK(visitor.visited.length() == 2); |
159 DCHECK(visitor.visited.Contains(*g1s1.location())); | 159 CHECK(visitor.visited.Contains(*g1s1.location())); |
160 DCHECK(visitor.visited.Contains(*g1s2.location())); | 160 CHECK(visitor.visited.Contains(*g1s2.location())); |
161 DCHECK(info1.has_been_disposed()); | 161 CHECK(info1.has_been_disposed()); |
162 DCHECK(!info2.has_been_disposed()); | 162 CHECK(!info2.has_been_disposed()); |
163 } | 163 } |
164 | 164 |
165 // Iterate again, don't skip anything. | 165 // Iterate again, don't skip anything. |
166 { | 166 { |
167 ResetCanSkipData(); | 167 ResetCanSkipData(); |
168 TestObjectVisitor visitor; | 168 TestObjectVisitor visitor; |
169 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 169 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
170 | 170 |
171 // CanSkipCallback was called for all objects. | 171 // CanSkipCallback was called for all objects. |
172 DCHECK(can_skip_called_objects.length() == 1); | 172 CHECK(can_skip_called_objects.length() == 1); |
173 DCHECK(can_skip_called_objects.Contains(*g2s1.location()) || | 173 CHECK(can_skip_called_objects.Contains(*g2s1.location()) || |
174 can_skip_called_objects.Contains(*g2s2.location())); | 174 can_skip_called_objects.Contains(*g2s2.location())); |
175 | 175 |
176 // The second group was visited. | 176 // The second group was visited. |
177 DCHECK(visitor.visited.length() == 2); | 177 CHECK(visitor.visited.length() == 2); |
178 DCHECK(visitor.visited.Contains(*g2s1.location())); | 178 CHECK(visitor.visited.Contains(*g2s1.location())); |
179 DCHECK(visitor.visited.Contains(*g2s2.location())); | 179 CHECK(visitor.visited.Contains(*g2s2.location())); |
180 DCHECK(info2.has_been_disposed()); | 180 CHECK(info2.has_been_disposed()); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 TEST(IterateObjectGroups) { | 185 TEST(IterateObjectGroups) { |
186 CcTest::InitializeVM(); | 186 CcTest::InitializeVM(); |
187 Isolate* isolate = CcTest::i_isolate(); | 187 Isolate* isolate = CcTest::i_isolate(); |
188 GlobalHandles* global_handles = isolate->global_handles(); | 188 GlobalHandles* global_handles = isolate->global_handles(); |
189 | 189 |
190 v8::HandleScope handle_scope(CcTest::isolate()); | 190 v8::HandleScope handle_scope(CcTest::isolate()); |
(...skipping 21 matching lines...) Expand all Loading... |
212 { | 212 { |
213 ResetCanSkipData(); | 213 ResetCanSkipData(); |
214 skippable_objects.Add(*g1s1.location()); | 214 skippable_objects.Add(*g1s1.location()); |
215 skippable_objects.Add(*g1s2.location()); | 215 skippable_objects.Add(*g1s2.location()); |
216 skippable_objects.Add(*g2s1.location()); | 216 skippable_objects.Add(*g2s1.location()); |
217 skippable_objects.Add(*g2s2.location()); | 217 skippable_objects.Add(*g2s2.location()); |
218 TestObjectVisitor visitor; | 218 TestObjectVisitor visitor; |
219 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 219 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
220 | 220 |
221 // CanSkipCallback was called for all objects. | 221 // CanSkipCallback was called for all objects. |
222 DCHECK(can_skip_called_objects.length() == 4); | 222 CHECK(can_skip_called_objects.length() == 4); |
223 DCHECK(can_skip_called_objects.Contains(*g1s1.location())); | 223 CHECK(can_skip_called_objects.Contains(*g1s1.location())); |
224 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); | 224 CHECK(can_skip_called_objects.Contains(*g1s2.location())); |
225 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); | 225 CHECK(can_skip_called_objects.Contains(*g2s1.location())); |
226 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); | 226 CHECK(can_skip_called_objects.Contains(*g2s2.location())); |
227 | 227 |
228 // Nothing was visited. | 228 // Nothing was visited. |
229 DCHECK(visitor.visited.length() == 0); | 229 CHECK(visitor.visited.length() == 0); |
230 DCHECK(!info1.has_been_disposed()); | 230 CHECK(!info1.has_been_disposed()); |
231 DCHECK(!info2.has_been_disposed()); | 231 CHECK(!info2.has_been_disposed()); |
232 } | 232 } |
233 | 233 |
234 // Iterate again, now only skip the second object group. | 234 // Iterate again, now only skip the second object group. |
235 { | 235 { |
236 ResetCanSkipData(); | 236 ResetCanSkipData(); |
237 // The first grough should still be visited, since only one object is | 237 // The first grough should still be visited, since only one object is |
238 // skipped. | 238 // skipped. |
239 skippable_objects.Add(*g1s1.location()); | 239 skippable_objects.Add(*g1s1.location()); |
240 skippable_objects.Add(*g2s1.location()); | 240 skippable_objects.Add(*g2s1.location()); |
241 skippable_objects.Add(*g2s2.location()); | 241 skippable_objects.Add(*g2s2.location()); |
242 TestObjectVisitor visitor; | 242 TestObjectVisitor visitor; |
243 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 243 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
244 | 244 |
245 // CanSkipCallback was called for all objects. | 245 // CanSkipCallback was called for all objects. |
246 DCHECK(can_skip_called_objects.length() == 3 || | 246 CHECK(can_skip_called_objects.length() == 3 || |
247 can_skip_called_objects.length() == 4); | 247 can_skip_called_objects.length() == 4); |
248 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); | 248 CHECK(can_skip_called_objects.Contains(*g1s2.location())); |
249 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); | 249 CHECK(can_skip_called_objects.Contains(*g2s1.location())); |
250 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); | 250 CHECK(can_skip_called_objects.Contains(*g2s2.location())); |
251 | 251 |
252 // The first group was visited. | 252 // The first group was visited. |
253 DCHECK(visitor.visited.length() == 2); | 253 CHECK(visitor.visited.length() == 2); |
254 DCHECK(visitor.visited.Contains(*g1s1.location())); | 254 CHECK(visitor.visited.Contains(*g1s1.location())); |
255 DCHECK(visitor.visited.Contains(*g1s2.location())); | 255 CHECK(visitor.visited.Contains(*g1s2.location())); |
256 DCHECK(info1.has_been_disposed()); | 256 CHECK(info1.has_been_disposed()); |
257 DCHECK(!info2.has_been_disposed()); | 257 CHECK(!info2.has_been_disposed()); |
258 } | 258 } |
259 | 259 |
260 // Iterate again, don't skip anything. | 260 // Iterate again, don't skip anything. |
261 { | 261 { |
262 ResetCanSkipData(); | 262 ResetCanSkipData(); |
263 TestObjectVisitor visitor; | 263 TestObjectVisitor visitor; |
264 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 264 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
265 | 265 |
266 // CanSkipCallback was called for all objects. | 266 // CanSkipCallback was called for all objects. |
267 DCHECK(can_skip_called_objects.length() == 1); | 267 CHECK(can_skip_called_objects.length() == 1); |
268 DCHECK(can_skip_called_objects.Contains(*g2s1.location()) || | 268 CHECK(can_skip_called_objects.Contains(*g2s1.location()) || |
269 can_skip_called_objects.Contains(*g2s2.location())); | 269 can_skip_called_objects.Contains(*g2s2.location())); |
270 | 270 |
271 // The second group was visited. | 271 // The second group was visited. |
272 DCHECK(visitor.visited.length() == 2); | 272 CHECK(visitor.visited.length() == 2); |
273 DCHECK(visitor.visited.Contains(*g2s1.location())); | 273 CHECK(visitor.visited.Contains(*g2s1.location())); |
274 DCHECK(visitor.visited.Contains(*g2s2.location())); | 274 CHECK(visitor.visited.Contains(*g2s2.location())); |
275 DCHECK(info2.has_been_disposed()); | 275 CHECK(info2.has_been_disposed()); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 | 279 |
280 TEST(ImplicitReferences) { | 280 TEST(ImplicitReferences) { |
281 CcTest::InitializeVM(); | 281 CcTest::InitializeVM(); |
282 Isolate* isolate = CcTest::i_isolate(); | 282 Isolate* isolate = CcTest::i_isolate(); |
283 GlobalHandles* global_handles = isolate->global_handles(); | 283 GlobalHandles* global_handles = isolate->global_handles(); |
284 | 284 |
285 v8::HandleScope handle_scope(CcTest::isolate()); | 285 v8::HandleScope handle_scope(CcTest::isolate()); |
(...skipping 16 matching lines...) Expand all Loading... |
302 global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1)); | 302 global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1)); |
303 global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2)); | 303 global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2)); |
304 global_handles->SetObjectGroupId(g2s2.location(), UniqueId(2)); | 304 global_handles->SetObjectGroupId(g2s2.location(), UniqueId(2)); |
305 global_handles->SetReferenceFromGroup(UniqueId(1), g1c1.location()); | 305 global_handles->SetReferenceFromGroup(UniqueId(1), g1c1.location()); |
306 global_handles->SetReferenceFromGroup(UniqueId(1), g1c2.location()); | 306 global_handles->SetReferenceFromGroup(UniqueId(1), g1c2.location()); |
307 global_handles->SetReferenceFromGroup(UniqueId(2), g2c1.location()); | 307 global_handles->SetReferenceFromGroup(UniqueId(2), g2c1.location()); |
308 | 308 |
309 List<ImplicitRefGroup*>* implicit_refs = | 309 List<ImplicitRefGroup*>* implicit_refs = |
310 global_handles->implicit_ref_groups(); | 310 global_handles->implicit_ref_groups(); |
311 USE(implicit_refs); | 311 USE(implicit_refs); |
312 DCHECK(implicit_refs->length() == 2); | 312 CHECK(implicit_refs->length() == 2); |
313 DCHECK(implicit_refs->at(0)->parent == | 313 CHECK(implicit_refs->at(0)->parent == |
314 reinterpret_cast<HeapObject**>(g1s1.location())); | 314 reinterpret_cast<HeapObject**>(g1s1.location())); |
315 DCHECK(implicit_refs->at(0)->length == 2); | 315 CHECK(implicit_refs->at(0)->length == 2); |
316 DCHECK(implicit_refs->at(0)->children[0] == g1c1.location()); | 316 CHECK(implicit_refs->at(0)->children[0] == g1c1.location()); |
317 DCHECK(implicit_refs->at(0)->children[1] == g1c2.location()); | 317 CHECK(implicit_refs->at(0)->children[1] == g1c2.location()); |
318 DCHECK(implicit_refs->at(1)->parent == | 318 CHECK(implicit_refs->at(1)->parent == |
319 reinterpret_cast<HeapObject**>(g2s1.location())); | 319 reinterpret_cast<HeapObject**>(g2s1.location())); |
320 DCHECK(implicit_refs->at(1)->length == 1); | 320 CHECK(implicit_refs->at(1)->length == 1); |
321 DCHECK(implicit_refs->at(1)->children[0] == g2c1.location()); | 321 CHECK(implicit_refs->at(1)->children[0] == g2c1.location()); |
322 global_handles->RemoveObjectGroups(); | 322 global_handles->RemoveObjectGroups(); |
323 global_handles->RemoveImplicitRefGroups(); | 323 global_handles->RemoveImplicitRefGroups(); |
324 } | 324 } |
325 | 325 |
326 | 326 |
327 TEST(EternalHandles) { | 327 TEST(EternalHandles) { |
328 CcTest::InitializeVM(); | 328 CcTest::InitializeVM(); |
329 Isolate* isolate = CcTest::i_isolate(); | 329 Isolate* isolate = CcTest::i_isolate(); |
330 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 330 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
331 EternalHandles* eternal_handles = isolate->eternal_handles(); | 331 EternalHandles* eternal_handles = isolate->eternal_handles(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 v8::Local<v8::Object> o = v8::Object::New(isolate); | 397 v8::Local<v8::Object> o = v8::Object::New(isolate); |
398 CHECK(!o.IsEmpty()); | 398 CHECK(!o.IsEmpty()); |
399 v8::Persistent<v8::Object> p(isolate, o); | 399 v8::Persistent<v8::Object> p(isolate, o); |
400 CHECK(o == p.Get(isolate)); | 400 CHECK(o == p.Get(isolate)); |
401 CHECK(v8::Local<v8::Object>::New(isolate, p) == p.Get(isolate)); | 401 CHECK(v8::Local<v8::Object>::New(isolate, p) == p.Get(isolate)); |
402 | 402 |
403 v8::Global<v8::Object> g(isolate, o); | 403 v8::Global<v8::Object> g(isolate, o); |
404 CHECK(o == g.Get(isolate)); | 404 CHECK(o == g.Get(isolate)); |
405 CHECK(v8::Local<v8::Object>::New(isolate, g) == g.Get(isolate)); | 405 CHECK(v8::Local<v8::Object>::New(isolate, g) == g.Get(isolate)); |
406 } | 406 } |
OLD | NEW |