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

Side by Side Diff: test/cctest/test-mark-compact.cc

Issue 6711027: [Isolates] Merge 7201:7258 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 CHECK_EQ(gc_ends, gc_starts); 286 CHECK_EQ(gc_ends, gc_starts);
287 287
288 HEAP->CollectGarbage(OLD_POINTER_SPACE); 288 HEAP->CollectGarbage(OLD_POINTER_SPACE);
289 CHECK_EQ(1, gc_starts); 289 CHECK_EQ(1, gc_starts);
290 CHECK_EQ(gc_ends, gc_starts); 290 CHECK_EQ(gc_ends, gc_starts);
291 } 291 }
292 292
293 293
294 static int NumberOfWeakCalls = 0; 294 static int NumberOfWeakCalls = 0;
295 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { 295 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) {
296 ASSERT(id == reinterpret_cast<void*>(1234));
296 NumberOfWeakCalls++; 297 NumberOfWeakCalls++;
297 handle.Dispose(); 298 handle.Dispose();
298 } 299 }
299 300
300 TEST(ObjectGroups) { 301 TEST(ObjectGroups) {
301 GlobalHandles* global_handles = Isolate::Current()->global_handles(); 302 GlobalHandles* global_handles = Isolate::Current()->global_handles();
302 InitializeVM(); 303 InitializeVM();
303 304
304 NumberOfWeakCalls = 0; 305 NumberOfWeakCalls = 0;
305 v8::HandleScope handle_scope; 306 v8::HandleScope handle_scope;
306 307
307 Handle<Object> g1s1 = 308 Handle<Object> g1s1 =
308 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 309 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
309 Handle<Object> g1s2 = 310 Handle<Object> g1s2 =
310 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 311 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
312 Handle<Object> g1c1 =
313 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
311 global_handles->MakeWeak(g1s1.location(), 314 global_handles->MakeWeak(g1s1.location(),
312 reinterpret_cast<void*>(1234), 315 reinterpret_cast<void*>(1234),
313 &WeakPointerCallback); 316 &WeakPointerCallback);
314 global_handles->MakeWeak(g1s2.location(), 317 global_handles->MakeWeak(g1s2.location(),
315 reinterpret_cast<void*>(1234), 318 reinterpret_cast<void*>(1234),
316 &WeakPointerCallback); 319 &WeakPointerCallback);
320 global_handles->MakeWeak(g1c1.location(),
321 reinterpret_cast<void*>(1234),
322 &WeakPointerCallback);
317 323
318 Handle<Object> g2s1 = 324 Handle<Object> g2s1 =
319 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
320 Handle<Object> g2s2 = 326 Handle<Object> g2s2 =
321 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
328 Handle<Object> g2c1 =
329 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
322 global_handles->MakeWeak(g2s1.location(), 330 global_handles->MakeWeak(g2s1.location(),
323 reinterpret_cast<void*>(1234), 331 reinterpret_cast<void*>(1234),
324 &WeakPointerCallback); 332 &WeakPointerCallback);
325 global_handles->MakeWeak(g2s2.location(), 333 global_handles->MakeWeak(g2s2.location(),
326 reinterpret_cast<void*>(1234), 334 reinterpret_cast<void*>(1234),
327 &WeakPointerCallback); 335 &WeakPointerCallback);
336 global_handles->MakeWeak(g2c1.location(),
337 reinterpret_cast<void*>(1234),
338 &WeakPointerCallback);
328 339
329 Handle<Object> root = global_handles->Create(*g1s1); // make a root. 340 Handle<Object> root = global_handles->Create(*g1s1); // make a root.
330 341
331 // Connect group 1 and 2, make a cycle. 342 // Connect group 1 and 2, make a cycle.
332 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); 343 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2);
333 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); 344 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1);
334 345
335 { 346 {
336 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 347 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
348 Object** g1_children[] = { g1c1.location() };
337 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 349 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
338 global_handles->AddGroup(g1_objects, 2, NULL); 350 Object** g2_children[] = { g2c1.location() };
339 global_handles->AddGroup(g2_objects, 2, NULL); 351 global_handles->AddObjectGroup(g1_objects, 2, NULL);
352 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1),
353 g1_children, 1);
354 global_handles->AddObjectGroup(g2_objects, 2, NULL);
355 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2),
356 g2_children, 1);
340 } 357 }
341 // Do a full GC 358 // Do a full GC
342 HEAP->CollectGarbage(OLD_POINTER_SPACE); 359 HEAP->CollectGarbage(OLD_POINTER_SPACE);
343 360
344 // All object should be alive. 361 // All object should be alive.
345 CHECK_EQ(0, NumberOfWeakCalls); 362 CHECK_EQ(0, NumberOfWeakCalls);
346 363
347 // Weaken the root. 364 // Weaken the root.
348 global_handles->MakeWeak(root.location(), 365 global_handles->MakeWeak(root.location(),
349 reinterpret_cast<void*>(1234), 366 reinterpret_cast<void*>(1234),
350 &WeakPointerCallback); 367 &WeakPointerCallback);
368 // But make children strong roots---all the objects (except for children)
369 // should be collectable now.
370 global_handles->ClearWeakness(g1c1.location());
371 global_handles->ClearWeakness(g2c1.location());
351 372
352 // Groups are deleted, rebuild groups. 373 // Groups are deleted, rebuild groups.
353 { 374 {
354 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 375 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
376 Object** g1_children[] = { g1c1.location() };
355 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 377 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
356 global_handles->AddGroup(g1_objects, 2, NULL); 378 Object** g2_children[] = { g2c1.location() };
357 global_handles->AddGroup(g2_objects, 2, NULL); 379 global_handles->AddObjectGroup(g1_objects, 2, NULL);
380 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1),
381 g1_children, 1);
382 global_handles->AddObjectGroup(g2_objects, 2, NULL);
383 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2),
384 g2_children, 1);
358 } 385 }
359 386
360 HEAP->CollectGarbage(OLD_POINTER_SPACE); 387 HEAP->CollectGarbage(OLD_POINTER_SPACE);
361 388
362 // All objects should be gone. 5 global handles in total. 389 // All objects should be gone. 5 global handles in total.
363 CHECK_EQ(5, NumberOfWeakCalls); 390 CHECK_EQ(5, NumberOfWeakCalls);
391
392 // And now make children weak again and collect them.
393 global_handles->MakeWeak(g1c1.location(),
394 reinterpret_cast<void*>(1234),
395 &WeakPointerCallback);
396 global_handles->MakeWeak(g2c1.location(),
397 reinterpret_cast<void*>(1234),
398 &WeakPointerCallback);
399
400 HEAP->CollectGarbage(OLD_POINTER_SPACE);
401 CHECK_EQ(7, NumberOfWeakCalls);
364 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698