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

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

Issue 2792063004: Reland of [heap] Fix CompactionSpace test and move to unittests (Closed)
Patch Set: Fix Created 3 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 | « src/heap/spaces.h ('k') | test/unittests/BUILD.gn » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 while (s->Available() > 0) { 395 while (s->Available() > 0) {
396 s->AllocateRawUnaligned(kMaxRegularHeapObjectSize).ToObjectChecked(); 396 s->AllocateRawUnaligned(kMaxRegularHeapObjectSize).ToObjectChecked();
397 } 397 }
398 398
399 delete s; 399 delete s;
400 memory_allocator->TearDown(); 400 memory_allocator->TearDown();
401 delete memory_allocator; 401 delete memory_allocator;
402 } 402 }
403 403
404
405 TEST(CompactionSpace) {
406 Isolate* isolate = CcTest::i_isolate();
407 Heap* heap = isolate->heap();
408 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
409 CHECK(memory_allocator != nullptr);
410 CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
411 0));
412 TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
413
414 CompactionSpace* compaction_space =
415 new CompactionSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
416 CHECK(compaction_space != NULL);
417 CHECK(compaction_space->SetUp());
418
419 OldSpace* old_space = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
420 CHECK(old_space != NULL);
421 CHECK(old_space->SetUp());
422
423 // Cannot loop until "Available()" since we initially have 0 bytes available
424 // and would thus neither grow, nor be able to allocate an object.
425 const int kNumObjects = 100;
426 const int kNumObjectsPerPage =
427 compaction_space->AreaSize() / kMaxRegularHeapObjectSize;
428 const int kExpectedPages =
429 (kNumObjects + kNumObjectsPerPage - 1) / kNumObjectsPerPage;
430 for (int i = 0; i < kNumObjects; i++) {
431 compaction_space->AllocateRawUnaligned(kMaxRegularHeapObjectSize)
432 .ToObjectChecked();
433 }
434 int pages_in_old_space = old_space->CountTotalPages();
435 int pages_in_compaction_space = compaction_space->CountTotalPages();
436 CHECK_EQ(pages_in_compaction_space, kExpectedPages);
437 CHECK_LE(pages_in_old_space, 1);
438
439 old_space->MergeCompactionSpace(compaction_space);
440 CHECK_EQ(old_space->CountTotalPages(),
441 pages_in_old_space + pages_in_compaction_space);
442
443 delete compaction_space;
444 delete old_space;
445
446 memory_allocator->TearDown();
447 delete memory_allocator;
448 }
449
450
451 TEST(LargeObjectSpace) { 404 TEST(LargeObjectSpace) {
452 // This test does not initialize allocated objects, which confuses the 405 // This test does not initialize allocated objects, which confuses the
453 // incremental marker. 406 // incremental marker.
454 FLAG_incremental_marking = false; 407 FLAG_incremental_marking = false;
455 v8::V8::Initialize(); 408 v8::V8::Initialize();
456 409
457 LargeObjectSpace* lo = CcTest::heap()->lo_space(); 410 LargeObjectSpace* lo = CcTest::heap()->lo_space();
458 CHECK(lo != NULL); 411 CHECK(lo != NULL);
459 412
460 int lo_size = Page::kPageSize; 413 int lo_size = Page::kPageSize;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 HeapObject* filler = 751 HeapObject* filler =
799 HeapObject::FromAddress(array->address() + array->Size()); 752 HeapObject::FromAddress(array->address() + array->Size());
800 CHECK_EQ(filler->map(), CcTest::heap()->two_pointer_filler_map()); 753 CHECK_EQ(filler->map(), CcTest::heap()->two_pointer_filler_map());
801 754
802 const size_t shrinked = page->ShrinkToHighWaterMark(); 755 const size_t shrinked = page->ShrinkToHighWaterMark();
803 CHECK_EQ(0u, shrinked); 756 CHECK_EQ(0u, shrinked);
804 } 757 }
805 758
806 } // namespace internal 759 } // namespace internal
807 } // namespace v8 760 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698