From 1092155c160edb382ba88fef03e246339c289471 Mon Sep 17 00:00:00 2001 From: Michael Lippautz Date: Fri, 11 Aug 2017 12:04:47 +0200 Subject: [PATCH] [heap] Cleanup cctests - Move into v8::internal::heap namespace - Remove card marking ifdefs Bug: Change-Id: Ifd5e5d96c6ab0fea85a3646e5b307583eb13e2c3 Reviewed-on: https://chromium-review.googlesource.com/612066 Reviewed-by: Ulan Degenbaev Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#47305} --- src/heap/heap.h | 9 ++- src/heap/spaces.h | 9 ++- src/isolate.h | 6 +- test/cctest/heap/heap-tester.h | 26 +++---- test/cctest/heap/test-alloc.cc | 22 ++++-- test/cctest/heap/test-array-buffer-tracker.cc | 2 + test/cctest/heap/test-compaction.cc | 2 + test/cctest/heap/test-concurrent-marking.cc | 2 + test/cctest/heap/test-heap.cc | 2 + test/cctest/heap/test-incremental-marking.cc | 2 + test/cctest/heap/test-invalidated-slots.cc | 4 +- test/cctest/heap/test-lab.cc | 2 + test/cctest/heap/test-mark-compact.cc | 8 +++ test/cctest/heap/test-page-promotion.cc | 2 + test/cctest/heap/test-spaces.cc | 69 +------------------ test/cctest/test-api.cc | 7 +- test/cctest/test-debug.cc | 14 ++-- 17 files changed, 86 insertions(+), 102 deletions(-) diff --git a/src/heap/heap.h b/src/heap/heap.h index e68cd8dfbf..6746363b0a 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -26,6 +26,11 @@ namespace v8 { namespace internal { +namespace heap { +class HeapTester; +class TestMemoryAllocatorScope; +} // namespace heap + using v8::MemoryPressureLevel; // Defines all the roots in Heap. @@ -2432,7 +2437,7 @@ class Heap { friend class PagedSpace; friend class Scavenger; friend class StoreBuffer; - friend class TestMemoryAllocatorScope; + friend class heap::TestMemoryAllocatorScope; // The allocator interface. friend class Factory; @@ -2441,7 +2446,7 @@ class Heap { friend class Isolate; // Used in cctest. - friend class HeapTester; + friend class heap::HeapTester; DISALLOW_COPY_AND_ASSIGN(Heap); }; diff --git a/src/heap/spaces.h b/src/heap/spaces.h index e7592bb18d..5ab0feac6c 100644 --- a/src/heap/spaces.h +++ b/src/heap/spaces.h @@ -31,6 +31,11 @@ namespace v8 { namespace internal { +namespace heap { +class HeapTester; +class TestCodeRangeScope; +} // namespace heap + class AllocationInfo; class AllocationObserver; class CompactionSpace; @@ -1432,7 +1437,7 @@ class V8_EXPORT_PRIVATE MemoryAllocator { base::VirtualMemory last_chunk_; Unmapper unmapper_; - friend class TestCodeRangeScope; + friend class heap::TestCodeRangeScope; DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator); }; @@ -2224,7 +2229,7 @@ class V8_EXPORT_PRIVATE PagedSpace : NON_EXPORTED_BASE(public Space) { friend class MarkCompactCollector; // Used in cctest. - friend class HeapTester; + friend class heap::HeapTester; }; enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 }; diff --git a/src/isolate.h b/src/isolate.h index 87cf1bfeaa..2c4ac9b46f 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -40,6 +40,10 @@ class ConsoleDelegate; namespace internal { +namespace heap { +class HeapTester; +} // namespace heap + class AccessCompilerData; class AddressToIndexHashMap; class AstStringConstants; @@ -1611,7 +1615,7 @@ class Isolate { friend class ExecutionAccess; friend class HandleScopeImplementer; - friend class HeapTester; + friend class heap::HeapTester; friend class OptimizingCompileDispatcher; friend class SweeperThread; friend class ThreadManager; diff --git a/test/cctest/heap/heap-tester.h b/test/cctest/heap/heap-tester.h index b749b0cba1..926a750927 100644 --- a/test/cctest/heap/heap-tester.h +++ b/test/cctest/heap/heap-tester.h @@ -43,28 +43,29 @@ V(RegressMissingWriteBarrierInAllocate) \ V(WriteBarriersInCopyJSObject) -#define HEAP_TEST(Name) \ - CcTest register_test_##Name(v8::internal::HeapTester::Test##Name, __FILE__, \ - #Name, true, true); \ - void v8::internal::HeapTester::Test##Name() +#define HEAP_TEST(Name) \ + CcTest register_test_##Name(v8::internal::heap::HeapTester::Test##Name, \ + __FILE__, #Name, true, true); \ + void v8::internal::heap::HeapTester::Test##Name() -#define UNINITIALIZED_HEAP_TEST(Name) \ - CcTest register_test_##Name(v8::internal::HeapTester::Test##Name, __FILE__, \ - #Name, true, false); \ - void v8::internal::HeapTester::Test##Name() +#define UNINITIALIZED_HEAP_TEST(Name) \ + CcTest register_test_##Name(v8::internal::heap::HeapTester::Test##Name, \ + __FILE__, #Name, true, false); \ + void v8::internal::heap::HeapTester::Test##Name() -#define THREADED_HEAP_TEST(Name) \ - RegisterThreadedTest register_##Name(v8::internal::HeapTester::Test##Name, \ - #Name); \ +#define THREADED_HEAP_TEST(Name) \ + RegisterThreadedTest register_##Name( \ + v8::internal::heap::HeapTester::Test##Name, #Name); \ /* */ HEAP_TEST(Name) - namespace v8 { namespace internal { template class Handle; +namespace heap { + class HeapTester { public: #define DECLARE_STATIC(Name) static void Test##Name(); @@ -84,6 +85,7 @@ class HeapTester { static void ResetWeakHandle(bool global_gc); }; +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-alloc.cc b/test/cctest/heap/test-alloc.cc index 27070c9da8..f813c8d105 100644 --- a/test/cctest/heap/test-alloc.cc +++ b/test/cctest/heap/test-alloc.cc @@ -37,8 +37,11 @@ using namespace v8::internal; +namespace v8 { +namespace internal { +namespace heap { -AllocationResult v8::internal::HeapTester::AllocateAfterFailures() { +AllocationResult HeapTester::AllocateAfterFailures() { Heap* heap = CcTest::heap(); // New space. @@ -90,8 +93,7 @@ AllocationResult v8::internal::HeapTester::AllocateAfterFailures() { return heap->true_value(); } - -Handle v8::internal::HeapTester::TestAllocateAfterFailures() { +Handle HeapTester::TestAllocateAfterFailures() { // Similar to what the CALL_AND_RETRY macro does in the last-resort case, we // are wrapping the allocator function in an AlwaysAllocateScope. Test that // all allocations succeed immediately without any retry. @@ -116,8 +118,8 @@ void TestGetter( const v8::PropertyCallbackInfo& info) { i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); HandleScope scope(isolate); - info.GetReturnValue().Set(v8::Utils::ToLocal( - v8::internal::HeapTester::TestAllocateAfterFailures())); + info.GetReturnValue().Set( + v8::Utils::ToLocal(HeapTester::TestAllocateAfterFailures())); } void TestSetter(v8::Local name, v8::Local value, @@ -196,6 +198,7 @@ unsigned int Pseudorandom() { return lo & 0xFFFF; } +namespace { // Plain old data class. Represents a block of allocated memory. class Block { @@ -207,6 +210,7 @@ class Block { int size; }; +} // namespace TEST(CodeRange) { const size_t code_range_size = 32*MB; @@ -215,7 +219,7 @@ TEST(CodeRange) { code_range.SetUp(code_range_size); size_t current_allocated = 0; size_t total_allocated = 0; - List< ::Block> blocks(1000); + List blocks(1000); while (total_allocated < 5 * code_range_size) { if (current_allocated < code_range_size / 10) { @@ -234,7 +238,7 @@ TEST(CodeRange) { requested, requested - (2 * MemoryAllocator::CodePageGuardSize()), &allocated); CHECK(base != NULL); - blocks.Add(::Block(base, static_cast(allocated))); + blocks.Add(Block(base, static_cast(allocated))); current_allocated += static_cast(allocated); total_allocated += static_cast(allocated); } else { @@ -250,3 +254,7 @@ TEST(CodeRange) { } } } + +} // namespace heap +} // namespace internal +} // namespace v8 diff --git a/test/cctest/heap/test-array-buffer-tracker.cc b/test/cctest/heap/test-array-buffer-tracker.cc index 447e349b4b..73286f3970 100644 --- a/test/cctest/heap/test-array-buffer-tracker.cc +++ b/test/cctest/heap/test-array-buffer-tracker.cc @@ -22,6 +22,7 @@ bool IsTracked(i::JSArrayBuffer* buf) { namespace v8 { namespace internal { +namespace heap { // The following tests make sure that JSArrayBuffer tracking works expected when // moving the objects through various spaces during GC phases. @@ -371,5 +372,6 @@ TEST(ArrayBuffer_RetainedSizeDecreases) { CHECK_EQ(0, retained_after - retained_before); } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-compaction.cc b/test/cctest/heap/test-compaction.cc index afa203c369..f9aae97b87 100644 --- a/test/cctest/heap/test-compaction.cc +++ b/test/cctest/heap/test-compaction.cc @@ -18,6 +18,7 @@ namespace v8 { namespace internal { +namespace heap { namespace { @@ -374,5 +375,6 @@ HEAP_TEST(CompactionPartiallyAbortedPageWithStoreBufferEntries) { } } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-concurrent-marking.cc b/test/cctest/heap/test-concurrent-marking.cc index 60e2efe849..bf2af5b1bd 100644 --- a/test/cctest/heap/test-concurrent-marking.cc +++ b/test/cctest/heap/test-concurrent-marking.cc @@ -16,6 +16,7 @@ namespace v8 { namespace internal { +namespace heap { void PublishSegment(ConcurrentMarking::MarkingWorklist* worklist, HeapObject* object) { @@ -57,5 +58,6 @@ TEST(ConcurrentMarkingReschedule) { delete concurrent_marking; } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc index aba2990cb9..c6da5dc0b3 100644 --- a/test/cctest/heap/test-heap.cc +++ b/test/cctest/heap/test-heap.cc @@ -57,6 +57,7 @@ namespace v8 { namespace internal { +namespace heap { // We only start allocation-site tracking with the second instantiation. static const int kPretenureCreationCount = @@ -6222,5 +6223,6 @@ UNINITIALIZED_TEST(ReinitializeStringHashSeed) { } } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-incremental-marking.cc b/test/cctest/heap/test-incremental-marking.cc index e6863ff303..eadedc50cb 100644 --- a/test/cctest/heap/test-incremental-marking.cc +++ b/test/cctest/heap/test-incremental-marking.cc @@ -30,6 +30,7 @@ using v8::Isolate; namespace v8 { namespace internal { +namespace heap { class MockPlatform : public TestPlatform { public: @@ -74,5 +75,6 @@ TEST(IncrementalMarkingUsingTasks) { CHECK(marking->IsStopped()); } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-invalidated-slots.cc b/test/cctest/heap/test-invalidated-slots.cc index 80a678da01..4353fb0bff 100644 --- a/test/cctest/heap/test-invalidated-slots.cc +++ b/test/cctest/heap/test-invalidated-slots.cc @@ -16,8 +16,9 @@ namespace v8 { namespace internal { +namespace heap { -Page* v8::internal::HeapTester::AllocateByteArraysOnPage( +Page* HeapTester::AllocateByteArraysOnPage( Heap* heap, std::vector* byte_arrays) { const int kLength = 256 - ByteArray::kHeaderSize; const int kSize = ByteArray::SizeFor(kLength); @@ -181,5 +182,6 @@ HEAP_TEST(InvalidatedSlotsResetObjectRegression) { } } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-lab.cc b/test/cctest/heap/test-lab.cc index b625206f48..d2f5ac2d54 100644 --- a/test/cctest/heap/test-lab.cc +++ b/test/cctest/heap/test-lab.cc @@ -15,6 +15,7 @@ namespace v8 { namespace internal { +namespace heap { static Address AllocateLabBackingStore(Heap* heap, intptr_t size_in_bytes) { AllocationResult result = heap->old_space()->AllocateRaw( @@ -283,5 +284,6 @@ TEST(AllocateAligned) { } #endif // V8_HOST_ARCH_32_BIT +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-mark-compact.cc b/test/cctest/heap/test-mark-compact.cc index a4a9cacdb3..fd926428cf 100644 --- a/test/cctest/heap/test-mark-compact.cc +++ b/test/cctest/heap/test-mark-compact.cc @@ -52,6 +52,10 @@ using namespace v8::internal; using v8::Just; +namespace v8 { +namespace internal { +namespace heap { + TEST(SequentialMarkingDeque) { CcTest::InitializeVM(); SequentialMarkingDeque s(CcTest::i_isolate()->heap()); @@ -364,3 +368,7 @@ TEST(Regress5829) { } #endif // __linux__ and !USE_SIMULATOR + +} // namespace heap +} // namespace internal +} // namespace v8 diff --git a/test/cctest/heap/test-page-promotion.cc b/test/cctest/heap/test-page-promotion.cc index 95056a8ffe..61c89677ed 100644 --- a/test/cctest/heap/test-page-promotion.cc +++ b/test/cctest/heap/test-page-promotion.cc @@ -15,6 +15,7 @@ namespace v8 { namespace internal { +namespace heap { namespace { @@ -197,5 +198,6 @@ UNINITIALIZED_HEAP_TEST(Regress658718) { isolate->Dispose(); } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/heap/test-spaces.cc b/test/cctest/heap/test-spaces.cc index 3775d91152..a71e24b844 100644 --- a/test/cctest/heap/test-spaces.cc +++ b/test/cctest/heap/test-spaces.cc @@ -28,6 +28,7 @@ #include #include "src/base/platform/platform.h" +#include "src/factory.h" #include "src/heap/spaces-inl.h" // FIXME(mstarzinger, marja): This is weird, but required because of the missing // (disallowed) include: src/heap/incremental-marking.h -> src/objects-inl.h @@ -40,72 +41,7 @@ namespace v8 { namespace internal { - -#if 0 -static void VerifyRegionMarking(Address page_start) { -#ifdef ENABLE_CARDMARKING_WRITE_BARRIER - Page* p = Page::FromAddress(page_start); - - p->SetRegionMarks(Page::kAllRegionsCleanMarks); - - for (Address addr = p->ObjectAreaStart(); - addr < p->ObjectAreaEnd(); - addr += kPointerSize) { - CHECK(!Page::FromAddress(addr)->IsRegionDirty(addr)); - } - - for (Address addr = p->ObjectAreaStart(); - addr < p->ObjectAreaEnd(); - addr += kPointerSize) { - Page::FromAddress(addr)->MarkRegionDirty(addr); - } - - for (Address addr = p->ObjectAreaStart(); - addr < p->ObjectAreaEnd(); - addr += kPointerSize) { - CHECK(Page::FromAddress(addr)->IsRegionDirty(addr)); - } -#endif -} -#endif - - -// TODO(gc) you can no longer allocate pages like this. Details are hidden. -#if 0 -TEST(Page) { - byte* mem = NewArray(2*Page::kPageSize); - CHECK(mem != NULL); - - Address start = reinterpret_cast
(mem); - Address page_start = RoundUp(start, Page::kPageSize); - - Page* p = Page::FromAddress(page_start); - // Initialized Page has heap pointer, normally set by memory_allocator. - p->heap_ = CcTest::heap(); - CHECK(p->address() == page_start); - CHECK(p->is_valid()); - - p->opaque_header = 0; - p->SetIsLargeObjectPage(false); - CHECK(!p->next_page()->is_valid()); - - CHECK(p->ObjectAreaStart() == page_start + Page::kObjectStartOffset); - CHECK(p->ObjectAreaEnd() == page_start + Page::kPageSize); - - CHECK(p->Offset(page_start + Page::kObjectStartOffset) == - Page::kObjectStartOffset); - CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize); - - CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart()); - CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); - - // test region marking - VerifyRegionMarking(page_start); - - DeleteArray(mem); -} -#endif - +namespace heap { // Temporarily sets a given allocator in an isolate. class TestMemoryAllocatorScope { @@ -759,5 +695,6 @@ TEST(ShrinkPageToHighWaterMarkTwoWordFiller) { CHECK_EQ(0u, shrunk); } +} // namespace heap } // namespace internal } // namespace v8 diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 50b1fbcbf3..365be7b51f 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -7787,8 +7787,7 @@ static void ResetUseValueAndSetFlag( data.GetParameter()->flag = true; } - -void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) { +void v8::internal::heap::HeapTester::ResetWeakHandle(bool global_gc) { using v8::Context; using v8::Local; using v8::Object; @@ -7835,8 +7834,8 @@ void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) { THREADED_HEAP_TEST(ResetWeakHandle) { - v8::internal::HeapTester::ResetWeakHandle(false); - v8::internal::HeapTester::ResetWeakHandle(true); + v8::internal::heap::HeapTester::ResetWeakHandle(false); + v8::internal::heap::HeapTester::ResetWeakHandle(true); } static void InvokeScavenge() { CcTest::CollectGarbage(i::NEW_SPACE); } diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index b7ba3efdd4..1ea80b6ae6 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -6065,11 +6065,11 @@ TEST(Regress131642) { // Import from test-heap.cc namespace v8 { namespace internal { - +namespace heap { int CountNativeContexts(); -} -} - +} // namespace heap +} // namespace internal +} // namespace v8 static void NopListener(const v8::Debug::EventDetails& event_details) { } @@ -6078,15 +6078,15 @@ static void NopListener(const v8::Debug::EventDetails& event_details) { TEST(DebuggerCreatesContextIffActive) { DebugLocalContext env; v8::HandleScope scope(env->GetIsolate()); - CHECK_EQ(1, v8::internal::CountNativeContexts()); + CHECK_EQ(1, v8::internal::heap::CountNativeContexts()); SetDebugEventListener(env->GetIsolate(), nullptr); CompileRun("debugger;"); - CHECK_EQ(1, v8::internal::CountNativeContexts()); + CHECK_EQ(1, v8::internal::heap::CountNativeContexts()); SetDebugEventListener(env->GetIsolate(), NopListener); CompileRun("debugger;"); - CHECK_EQ(2, v8::internal::CountNativeContexts()); + CHECK_EQ(2, v8::internal::heap::CountNativeContexts()); SetDebugEventListener(env->GetIsolate(), nullptr); }