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

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

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 11 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
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/cctest/test-regexp.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 CHECK_EQ(0, gc_starts); 297 CHECK_EQ(0, gc_starts);
298 CHECK_EQ(gc_ends, gc_starts); 298 CHECK_EQ(gc_ends, gc_starts);
299 299
300 HEAP->CollectGarbage(OLD_POINTER_SPACE); 300 HEAP->CollectGarbage(OLD_POINTER_SPACE);
301 CHECK_EQ(1, gc_starts); 301 CHECK_EQ(1, gc_starts);
302 CHECK_EQ(gc_ends, gc_starts); 302 CHECK_EQ(gc_ends, gc_starts);
303 } 303 }
304 304
305 305
306 static int NumberOfWeakCalls = 0; 306 static int NumberOfWeakCalls = 0;
307 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { 307 static void WeakPointerCallback(v8::Isolate* isolate,
308 v8::Persistent<v8::Value> handle,
309 void* id) {
308 ASSERT(id == reinterpret_cast<void*>(1234)); 310 ASSERT(id == reinterpret_cast<void*>(1234));
309 NumberOfWeakCalls++; 311 NumberOfWeakCalls++;
310 handle.Dispose(); 312 handle.Dispose(isolate);
311 } 313 }
312 314
313 TEST(ObjectGroups) { 315 TEST(ObjectGroups) {
314 FLAG_incremental_marking = false; 316 FLAG_incremental_marking = false;
315 InitializeVM(); 317 InitializeVM();
316 GlobalHandles* global_handles = Isolate::Current()->global_handles(); 318 GlobalHandles* global_handles = Isolate::Current()->global_handles();
317 319
318 NumberOfWeakCalls = 0; 320 NumberOfWeakCalls = 0;
319 v8::HandleScope handle_scope; 321 v8::HandleScope handle_scope;
320 322
321 Handle<Object> g1s1 = 323 Handle<Object> g1s1 =
322 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 324 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
323 Handle<Object> g1s2 = 325 Handle<Object> g1s2 =
324 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 326 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
325 Handle<Object> g1c1 = 327 Handle<Object> g1c1 =
326 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 328 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
327 global_handles->MakeWeak(g1s1.location(), 329 global_handles->MakeWeak(g1s1.location(),
328 reinterpret_cast<void*>(1234), 330 reinterpret_cast<void*>(1234),
331 NULL,
329 &WeakPointerCallback); 332 &WeakPointerCallback);
330 global_handles->MakeWeak(g1s2.location(), 333 global_handles->MakeWeak(g1s2.location(),
331 reinterpret_cast<void*>(1234), 334 reinterpret_cast<void*>(1234),
335 NULL,
332 &WeakPointerCallback); 336 &WeakPointerCallback);
333 global_handles->MakeWeak(g1c1.location(), 337 global_handles->MakeWeak(g1c1.location(),
334 reinterpret_cast<void*>(1234), 338 reinterpret_cast<void*>(1234),
339 NULL,
335 &WeakPointerCallback); 340 &WeakPointerCallback);
336 341
337 Handle<Object> g2s1 = 342 Handle<Object> g2s1 =
338 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 343 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
339 Handle<Object> g2s2 = 344 Handle<Object> g2s2 =
340 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 345 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
341 Handle<Object> g2c1 = 346 Handle<Object> g2c1 =
342 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 347 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
343 global_handles->MakeWeak(g2s1.location(), 348 global_handles->MakeWeak(g2s1.location(),
344 reinterpret_cast<void*>(1234), 349 reinterpret_cast<void*>(1234),
350 NULL,
345 &WeakPointerCallback); 351 &WeakPointerCallback);
346 global_handles->MakeWeak(g2s2.location(), 352 global_handles->MakeWeak(g2s2.location(),
347 reinterpret_cast<void*>(1234), 353 reinterpret_cast<void*>(1234),
354 NULL,
348 &WeakPointerCallback); 355 &WeakPointerCallback);
349 global_handles->MakeWeak(g2c1.location(), 356 global_handles->MakeWeak(g2c1.location(),
350 reinterpret_cast<void*>(1234), 357 reinterpret_cast<void*>(1234),
358 NULL,
351 &WeakPointerCallback); 359 &WeakPointerCallback);
352 360
353 Handle<Object> root = global_handles->Create(*g1s1); // make a root. 361 Handle<Object> root = global_handles->Create(*g1s1); // make a root.
354 362
355 // Connect group 1 and 2, make a cycle. 363 // Connect group 1 and 2, make a cycle.
356 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); 364 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2);
357 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); 365 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1);
358 366
359 { 367 {
360 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 368 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
361 Object** g1_children[] = { g1c1.location() }; 369 Object** g1_children[] = { g1c1.location() };
362 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 370 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
363 Object** g2_children[] = { g2c1.location() }; 371 Object** g2_children[] = { g2c1.location() };
364 global_handles->AddObjectGroup(g1_objects, 2, NULL); 372 global_handles->AddObjectGroup(g1_objects, 2, NULL);
365 global_handles->AddImplicitReferences( 373 global_handles->AddImplicitReferences(
366 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); 374 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1);
367 global_handles->AddObjectGroup(g2_objects, 2, NULL); 375 global_handles->AddObjectGroup(g2_objects, 2, NULL);
368 global_handles->AddImplicitReferences( 376 global_handles->AddImplicitReferences(
369 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); 377 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1);
370 } 378 }
371 // Do a full GC 379 // Do a full GC
372 HEAP->CollectGarbage(OLD_POINTER_SPACE); 380 HEAP->CollectGarbage(OLD_POINTER_SPACE);
373 381
374 // All object should be alive. 382 // All object should be alive.
375 CHECK_EQ(0, NumberOfWeakCalls); 383 CHECK_EQ(0, NumberOfWeakCalls);
376 384
377 // Weaken the root. 385 // Weaken the root.
378 global_handles->MakeWeak(root.location(), 386 global_handles->MakeWeak(root.location(),
379 reinterpret_cast<void*>(1234), 387 reinterpret_cast<void*>(1234),
388 NULL,
380 &WeakPointerCallback); 389 &WeakPointerCallback);
381 // But make children strong roots---all the objects (except for children) 390 // But make children strong roots---all the objects (except for children)
382 // should be collectable now. 391 // should be collectable now.
383 global_handles->ClearWeakness(g1c1.location()); 392 global_handles->ClearWeakness(g1c1.location());
384 global_handles->ClearWeakness(g2c1.location()); 393 global_handles->ClearWeakness(g2c1.location());
385 394
386 // Groups are deleted, rebuild groups. 395 // Groups are deleted, rebuild groups.
387 { 396 {
388 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 397 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
389 Object** g1_children[] = { g1c1.location() }; 398 Object** g1_children[] = { g1c1.location() };
390 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 399 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
391 Object** g2_children[] = { g2c1.location() }; 400 Object** g2_children[] = { g2c1.location() };
392 global_handles->AddObjectGroup(g1_objects, 2, NULL); 401 global_handles->AddObjectGroup(g1_objects, 2, NULL);
393 global_handles->AddImplicitReferences( 402 global_handles->AddImplicitReferences(
394 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); 403 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1);
395 global_handles->AddObjectGroup(g2_objects, 2, NULL); 404 global_handles->AddObjectGroup(g2_objects, 2, NULL);
396 global_handles->AddImplicitReferences( 405 global_handles->AddImplicitReferences(
397 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); 406 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1);
398 } 407 }
399 408
400 HEAP->CollectGarbage(OLD_POINTER_SPACE); 409 HEAP->CollectGarbage(OLD_POINTER_SPACE);
401 410
402 // All objects should be gone. 5 global handles in total. 411 // All objects should be gone. 5 global handles in total.
403 CHECK_EQ(5, NumberOfWeakCalls); 412 CHECK_EQ(5, NumberOfWeakCalls);
404 413
405 // And now make children weak again and collect them. 414 // And now make children weak again and collect them.
406 global_handles->MakeWeak(g1c1.location(), 415 global_handles->MakeWeak(g1c1.location(),
407 reinterpret_cast<void*>(1234), 416 reinterpret_cast<void*>(1234),
417 NULL,
408 &WeakPointerCallback); 418 &WeakPointerCallback);
409 global_handles->MakeWeak(g2c1.location(), 419 global_handles->MakeWeak(g2c1.location(),
410 reinterpret_cast<void*>(1234), 420 reinterpret_cast<void*>(1234),
421 NULL,
411 &WeakPointerCallback); 422 &WeakPointerCallback);
412 423
413 HEAP->CollectGarbage(OLD_POINTER_SPACE); 424 HEAP->CollectGarbage(OLD_POINTER_SPACE);
414 CHECK_EQ(7, NumberOfWeakCalls); 425 CHECK_EQ(7, NumberOfWeakCalls);
415 } 426 }
416 427
417 428
418 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { 429 class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
419 public: 430 public:
420 TestRetainedObjectInfo() : has_been_disposed_(false) {} 431 TestRetainedObjectInfo() : has_been_disposed_(false) {}
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (v8::internal::Snapshot::IsEnabled()) { 564 if (v8::internal::Snapshot::IsEnabled()) {
554 CHECK_LE(delta, 2600 * 1024); 565 CHECK_LE(delta, 2600 * 1024);
555 } else { 566 } else {
556 CHECK_LE(delta, 3000 * 1024); 567 CHECK_LE(delta, 3000 * 1024);
557 } 568 }
558 } 569 }
559 } 570 }
560 } 571 }
561 572
562 #endif // __linux__ and !USE_SIMULATOR 573 #endif // __linux__ and !USE_SIMULATOR
OLDNEW
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698