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

Side by Side Diff: test/cctest/test-heap.cc

Issue 99193002: Remove all stuff marked as V8_DEPRECATED. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 7 years 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 | « src/runtime.cc ('k') | test/cctest/test-mark-compact.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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 <stdlib.h> 28 #include <stdlib.h>
29 #include <utility>
29 30
30 #include "v8.h" 31 #include "v8.h"
31 32
32 #include "compilation-cache.h" 33 #include "compilation-cache.h"
33 #include "execution.h" 34 #include "execution.h"
34 #include "factory.h" 35 #include "factory.h"
35 #include "macro-assembler.h" 36 #include "macro-assembler.h"
36 #include "global-handles.h" 37 #include "global-handles.h"
37 #include "stub-cache.h" 38 #include "stub-cache.h"
38 #include "cctest.h" 39 #include "cctest.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 376
376 // after gc, it should survive 377 // after gc, it should survive
377 heap->CollectGarbage(NEW_SPACE); 378 heap->CollectGarbage(NEW_SPACE);
378 379
379 CHECK((*h1)->IsString()); 380 CHECK((*h1)->IsString());
380 CHECK((*h2)->IsHeapNumber()); 381 CHECK((*h2)->IsHeapNumber());
381 CHECK((*h3)->IsString()); 382 CHECK((*h3)->IsString());
382 CHECK((*h4)->IsHeapNumber()); 383 CHECK((*h4)->IsHeapNumber());
383 384
384 CHECK_EQ(*h3, *h1); 385 CHECK_EQ(*h3, *h1);
385 global_handles->Destroy(h1.location()); 386 GlobalHandles::Destroy(h1.location());
386 global_handles->Destroy(h3.location()); 387 GlobalHandles::Destroy(h3.location());
387 388
388 CHECK_EQ(*h4, *h2); 389 CHECK_EQ(*h4, *h2);
389 global_handles->Destroy(h2.location()); 390 GlobalHandles::Destroy(h2.location());
390 global_handles->Destroy(h4.location()); 391 GlobalHandles::Destroy(h4.location());
391 } 392 }
392 393
393 394
394 static bool WeakPointerCleared = false; 395 static bool WeakPointerCleared = false;
395 396
396 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, 397 static void TestWeakGlobalHandleCallback(
397 v8::Persistent<v8::Value>* handle, 398 const v8::WeakCallbackData<v8::Value, void>& data) {
398 void* id) { 399 std::pair<v8::Persistent<v8::Value>*, int>* p =
399 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; 400 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
400 handle->Reset(); 401 data.GetParameter());
402 if (p->second == 1234) WeakPointerCleared = true;
403 p->first->Reset();
401 } 404 }
402 405
403 406
404 TEST(WeakGlobalHandlesScavenge) { 407 TEST(WeakGlobalHandlesScavenge) {
405 i::FLAG_stress_compaction = false; 408 i::FLAG_stress_compaction = false;
406 CcTest::InitializeVM(); 409 CcTest::InitializeVM();
407 Isolate* isolate = CcTest::i_isolate(); 410 Isolate* isolate = CcTest::i_isolate();
408 Heap* heap = isolate->heap(); 411 Heap* heap = isolate->heap();
409 Factory* factory = isolate->factory(); 412 Factory* factory = isolate->factory();
410 GlobalHandles* global_handles = isolate->global_handles(); 413 GlobalHandles* global_handles = isolate->global_handles();
411 414
412 WeakPointerCleared = false; 415 WeakPointerCleared = false;
413 416
414 Handle<Object> h1; 417 Handle<Object> h1;
415 Handle<Object> h2; 418 Handle<Object> h2;
416 419
417 { 420 {
418 HandleScope scope(isolate); 421 HandleScope scope(isolate);
419 422
420 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); 423 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
421 Handle<Object> u = factory->NewNumber(1.12344); 424 Handle<Object> u = factory->NewNumber(1.12344);
422 425
423 h1 = global_handles->Create(*i); 426 h1 = global_handles->Create(*i);
424 h2 = global_handles->Create(*u); 427 h2 = global_handles->Create(*u);
425 } 428 }
426 429
427 global_handles->MakeWeak(h2.location(), 430 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
428 reinterpret_cast<void*>(1234), 431 GlobalHandles::MakeWeak(h2.location(),
429 &TestWeakGlobalHandleCallback); 432 reinterpret_cast<void*>(&handle_and_id),
433 &TestWeakGlobalHandleCallback);
430 434
431 // Scavenge treats weak pointers as normal roots. 435 // Scavenge treats weak pointers as normal roots.
432 heap->PerformScavenge(); 436 heap->PerformScavenge();
433 437
434 CHECK((*h1)->IsString()); 438 CHECK((*h1)->IsString());
435 CHECK((*h2)->IsHeapNumber()); 439 CHECK((*h2)->IsHeapNumber());
436 440
437 CHECK(!WeakPointerCleared); 441 CHECK(!WeakPointerCleared);
438 CHECK(!global_handles->IsNearDeath(h2.location())); 442 CHECK(!global_handles->IsNearDeath(h2.location()));
439 CHECK(!global_handles->IsNearDeath(h1.location())); 443 CHECK(!global_handles->IsNearDeath(h1.location()));
440 444
441 global_handles->Destroy(h1.location()); 445 GlobalHandles::Destroy(h1.location());
442 global_handles->Destroy(h2.location()); 446 GlobalHandles::Destroy(h2.location());
443 } 447 }
444 448
445 449
446 TEST(WeakGlobalHandlesMark) { 450 TEST(WeakGlobalHandlesMark) {
447 CcTest::InitializeVM(); 451 CcTest::InitializeVM();
448 Isolate* isolate = CcTest::i_isolate(); 452 Isolate* isolate = CcTest::i_isolate();
449 Heap* heap = isolate->heap(); 453 Heap* heap = isolate->heap();
450 Factory* factory = isolate->factory(); 454 Factory* factory = isolate->factory();
451 GlobalHandles* global_handles = isolate->global_handles(); 455 GlobalHandles* global_handles = isolate->global_handles();
452 456
(...skipping 10 matching lines...) Expand all
463 467
464 h1 = global_handles->Create(*i); 468 h1 = global_handles->Create(*i);
465 h2 = global_handles->Create(*u); 469 h2 = global_handles->Create(*u);
466 } 470 }
467 471
468 // Make sure the objects are promoted. 472 // Make sure the objects are promoted.
469 heap->CollectGarbage(OLD_POINTER_SPACE); 473 heap->CollectGarbage(OLD_POINTER_SPACE);
470 heap->CollectGarbage(NEW_SPACE); 474 heap->CollectGarbage(NEW_SPACE);
471 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2)); 475 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
472 476
473 global_handles->MakeWeak(h2.location(), 477 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
474 reinterpret_cast<void*>(1234), 478 GlobalHandles::MakeWeak(h2.location(),
475 &TestWeakGlobalHandleCallback); 479 reinterpret_cast<void*>(&handle_and_id),
480 &TestWeakGlobalHandleCallback);
476 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 481 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
477 CHECK(!GlobalHandles::IsNearDeath(h2.location())); 482 CHECK(!GlobalHandles::IsNearDeath(h2.location()));
478 483
479 // Incremental marking potentially marked handles before they turned weak. 484 // Incremental marking potentially marked handles before they turned weak.
480 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 485 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
481 486
482 CHECK((*h1)->IsString()); 487 CHECK((*h1)->IsString());
483 488
484 CHECK(WeakPointerCleared); 489 CHECK(WeakPointerCleared);
485 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 490 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
486 491
487 global_handles->Destroy(h1.location()); 492 GlobalHandles::Destroy(h1.location());
488 } 493 }
489 494
490 495
491 TEST(DeleteWeakGlobalHandle) { 496 TEST(DeleteWeakGlobalHandle) {
492 i::FLAG_stress_compaction = false; 497 i::FLAG_stress_compaction = false;
493 CcTest::InitializeVM(); 498 CcTest::InitializeVM();
494 Isolate* isolate = CcTest::i_isolate(); 499 Isolate* isolate = CcTest::i_isolate();
495 Heap* heap = isolate->heap(); 500 Heap* heap = isolate->heap();
496 Factory* factory = isolate->factory(); 501 Factory* factory = isolate->factory();
497 GlobalHandles* global_handles = isolate->global_handles(); 502 GlobalHandles* global_handles = isolate->global_handles();
498 503
499 WeakPointerCleared = false; 504 WeakPointerCleared = false;
500 505
501 Handle<Object> h; 506 Handle<Object> h;
502 507
503 { 508 {
504 HandleScope scope(isolate); 509 HandleScope scope(isolate);
505 510
506 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); 511 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
507 h = global_handles->Create(*i); 512 h = global_handles->Create(*i);
508 } 513 }
509 514
510 global_handles->MakeWeak(h.location(), 515 std::pair<Handle<Object>*, int> handle_and_id(&h, 1234);
511 reinterpret_cast<void*>(1234), 516 GlobalHandles::MakeWeak(h.location(),
512 &TestWeakGlobalHandleCallback); 517 reinterpret_cast<void*>(&handle_and_id),
518 &TestWeakGlobalHandleCallback);
513 519
514 // Scanvenge does not recognize weak reference. 520 // Scanvenge does not recognize weak reference.
515 heap->PerformScavenge(); 521 heap->PerformScavenge();
516 522
517 CHECK(!WeakPointerCleared); 523 CHECK(!WeakPointerCleared);
518 524
519 // Mark-compact treats weak reference properly. 525 // Mark-compact treats weak reference properly.
520 heap->CollectGarbage(OLD_POINTER_SPACE); 526 heap->CollectGarbage(OLD_POINTER_SPACE);
521 527
522 CHECK(WeakPointerCleared); 528 CHECK(WeakPointerCleared);
(...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after
3621 for (int i = 0; i < 4; i++) { 3627 for (int i = 0; i < 4; i++) {
3622 heap->CollectAllGarbage(false); 3628 heap->CollectAllGarbage(false);
3623 } 3629 }
3624 3630
3625 // The site still exists because of our global handle, but the code is no 3631 // The site still exists because of our global handle, but the code is no
3626 // longer referred to by dependent_code(). 3632 // longer referred to by dependent_code().
3627 DependentCode::GroupStartIndexes starts(site->dependent_code()); 3633 DependentCode::GroupStartIndexes starts(site->dependent_code());
3628 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); 3634 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
3629 CHECK(!(site->dependent_code()->is_code_at(index))); 3635 CHECK(!(site->dependent_code()->is_code_at(index)));
3630 } 3636 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698