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

Side by Side Diff: test/cctest/test-global-handles.cc

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 | « test/cctest/test-api.cc ('k') | test/cctest/test-heap-profiler.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 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 12 matching lines...) Expand all
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 #include "global-handles.h" 28 #include "global-handles.h"
29 29
30 #include "cctest.h" 30 #include "cctest.h"
31 31
32 using namespace v8::internal; 32 using namespace v8::internal;
33 using v8::UniqueId;
34 33
35 static int NumberOfWeakCalls = 0; 34 static int NumberOfWeakCalls = 0;
36 static void WeakPointerCallback(v8::Isolate* isolate, 35 static void WeakPointerCallback(v8::Isolate* isolate,
37 v8::Persistent<v8::Value> handle, 36 v8::Persistent<v8::Value> handle,
38 void* id) { 37 void* id) {
39 ASSERT(id == reinterpret_cast<void*>(1234)); 38 ASSERT(id == reinterpret_cast<void*>(1234));
40 NumberOfWeakCalls++; 39 NumberOfWeakCalls++;
41 handle.Dispose(isolate); 40 handle.Dispose(isolate);
42 } 41 }
43 42
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 ASSERT(can_skip_called_objects.Contains(*g2s1.location()) || 189 ASSERT(can_skip_called_objects.Contains(*g2s1.location()) ||
191 can_skip_called_objects.Contains(*g2s2.location())); 190 can_skip_called_objects.Contains(*g2s2.location()));
192 191
193 // The second group was visited. 192 // The second group was visited.
194 ASSERT(visitor.visited.length() == 2); 193 ASSERT(visitor.visited.length() == 2);
195 ASSERT(visitor.visited.Contains(*g2s1.location())); 194 ASSERT(visitor.visited.Contains(*g2s1.location()));
196 ASSERT(visitor.visited.Contains(*g2s2.location())); 195 ASSERT(visitor.visited.Contains(*g2s2.location()));
197 ASSERT(info2.has_been_disposed()); 196 ASSERT(info2.has_been_disposed());
198 } 197 }
199 } 198 }
200
201 TEST(IterateObjectGroups) {
202 CcTest::InitializeVM();
203 GlobalHandles* global_handles = Isolate::Current()->global_handles();
204
205 v8::HandleScope handle_scope(CcTest::isolate());
206
207 Handle<Object> g1s1 =
208 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
209 Handle<Object> g1s2 =
210 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
211 global_handles->MakeWeak(g1s1.location(),
212 reinterpret_cast<void*>(1234),
213 NULL,
214 &WeakPointerCallback);
215 global_handles->MakeWeak(g1s2.location(),
216 reinterpret_cast<void*>(1234),
217 NULL,
218 &WeakPointerCallback);
219
220 Handle<Object> g2s1 =
221 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
222 Handle<Object> g2s2 =
223 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
224 global_handles->MakeWeak(g2s1.location(),
225 reinterpret_cast<void*>(1234),
226 NULL,
227 &WeakPointerCallback);
228 global_handles->MakeWeak(g2s2.location(),
229 reinterpret_cast<void*>(1234),
230 NULL,
231 &WeakPointerCallback);
232
233 TestRetainedObjectInfo info1;
234 TestRetainedObjectInfo info2;
235 {
236 global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2));
237 global_handles->SetObjectGroupId(g2s2.location(), UniqueId(2));
238 global_handles->SetRetainedObjectInfo(UniqueId(2), &info2);
239 global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1));
240 global_handles->SetObjectGroupId(g1s2.location(), UniqueId(1));
241 global_handles->SetRetainedObjectInfo(UniqueId(1), &info1);
242 }
243
244 // Iterate the object groups. First skip all.
245 {
246 ResetCanSkipData();
247 skippable_objects.Add(*g1s1.location());
248 skippable_objects.Add(*g1s2.location());
249 skippable_objects.Add(*g2s1.location());
250 skippable_objects.Add(*g2s2.location());
251 TestObjectVisitor visitor;
252 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback);
253
254 // CanSkipCallback was called for all objects.
255 ASSERT(can_skip_called_objects.length() == 4);
256 ASSERT(can_skip_called_objects.Contains(*g1s1.location()));
257 ASSERT(can_skip_called_objects.Contains(*g1s2.location()));
258 ASSERT(can_skip_called_objects.Contains(*g2s1.location()));
259 ASSERT(can_skip_called_objects.Contains(*g2s2.location()));
260
261 // Nothing was visited.
262 ASSERT(visitor.visited.length() == 0);
263 ASSERT(!info1.has_been_disposed());
264 ASSERT(!info2.has_been_disposed());
265 }
266
267 // Iterate again, now only skip the second object group.
268 {
269 ResetCanSkipData();
270 // The first grough should still be visited, since only one object is
271 // skipped.
272 skippable_objects.Add(*g1s1.location());
273 skippable_objects.Add(*g2s1.location());
274 skippable_objects.Add(*g2s2.location());
275 TestObjectVisitor visitor;
276 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback);
277
278 // CanSkipCallback was called for all objects.
279 ASSERT(can_skip_called_objects.length() == 3 ||
280 can_skip_called_objects.length() == 4);
281 ASSERT(can_skip_called_objects.Contains(*g1s2.location()));
282 ASSERT(can_skip_called_objects.Contains(*g2s1.location()));
283 ASSERT(can_skip_called_objects.Contains(*g2s2.location()));
284
285 // The first group was visited.
286 ASSERT(visitor.visited.length() == 2);
287 ASSERT(visitor.visited.Contains(*g1s1.location()));
288 ASSERT(visitor.visited.Contains(*g1s2.location()));
289 ASSERT(info1.has_been_disposed());
290 ASSERT(!info2.has_been_disposed());
291 }
292
293 // Iterate again, don't skip anything.
294 {
295 ResetCanSkipData();
296 TestObjectVisitor visitor;
297 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback);
298
299 // CanSkipCallback was called for all objects.
300 fprintf(stderr, "can skip len %d\n", can_skip_called_objects.length());
301 ASSERT(can_skip_called_objects.length() == 1);
302 ASSERT(can_skip_called_objects.Contains(*g2s1.location()) ||
303 can_skip_called_objects.Contains(*g2s2.location()));
304
305 // The second group was visited.
306 ASSERT(visitor.visited.length() == 2);
307 ASSERT(visitor.visited.Contains(*g2s1.location()));
308 ASSERT(visitor.visited.Contains(*g2s2.location()));
309 ASSERT(info2.has_been_disposed());
310 }
311 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698