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

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

Issue 2798333002: [heap] Fix page promotions tests (Closed)
Patch Set: Address comment 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/page-parallel-job.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/factory.h" 5 #include "src/factory.h"
6 #include "src/heap/array-buffer-tracker.h" 6 #include "src/heap/array-buffer-tracker.h"
7 #include "src/heap/spaces-inl.h" 7 #include "src/heap/spaces-inl.h"
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 // FIXME(mstarzinger, marja): This is weird, but required because of the missing 9 // FIXME(mstarzinger, marja): This is weird, but required because of the missing
10 // (disallowed) include: src/factory.h -> src/objects-inl.h 10 // (disallowed) include: src/factory.h -> src/objects-inl.h
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 { 50 {
51 v8::Isolate::Scope isolate_scope(isolate); 51 v8::Isolate::Scope isolate_scope(isolate);
52 v8::HandleScope handle_scope(isolate); 52 v8::HandleScope handle_scope(isolate);
53 v8::Context::New(isolate)->Enter(); 53 v8::Context::New(isolate)->Enter();
54 Heap* heap = i_isolate->heap(); 54 Heap* heap = i_isolate->heap();
55 55
56 std::vector<Handle<FixedArray>> handles; 56 std::vector<Handle<FixedArray>> handles;
57 heap::SimulateFullSpace(heap->new_space(), &handles); 57 heap::SimulateFullSpace(heap->new_space(), &handles);
58 heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting); 58 heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting);
59 CHECK_GT(handles.size(), 0u); 59 CHECK_GT(handles.size(), 0u);
60 // First object in handle should be on the first page. 60 // Last object in handles should definitely be on a page that does not
61 Handle<FixedArray> first_object = handles.front(); 61 // contain the age mark, thus qualifying for moving.
62 Page* first_page = Page::FromAddress(first_object->address()); 62 Handle<FixedArray> last_object = handles.back();
63 Page* to_be_promoted_page = Page::FromAddress(last_object->address());
64 CHECK(!to_be_promoted_page->Contains(heap->new_space()->age_mark()));
63 // To perform a sanity check on live bytes we need to mark the heap. 65 // To perform a sanity check on live bytes we need to mark the heap.
64 heap::SimulateIncrementalMarking(heap, true); 66 heap::SimulateIncrementalMarking(heap, true);
65 // Sanity check that the page meets the requirements for promotion. 67 // Sanity check that the page meets the requirements for promotion.
66 const int threshold_bytes = 68 const int threshold_bytes =
67 FLAG_page_promotion_threshold * Page::kAllocatableMemory / 100; 69 FLAG_page_promotion_threshold * Page::kAllocatableMemory / 100;
68 CHECK_GE(MarkingState::Internal(first_page).live_bytes(), threshold_bytes); 70 CHECK_GE(MarkingState::Internal(to_be_promoted_page).live_bytes(),
71 threshold_bytes);
69 72
70 // Actual checks: The page is in new space first, but is moved to old space 73 // Actual checks: The page is in new space first, but is moved to old space
71 // during a full GC. 74 // during a full GC.
72 CHECK(heap->new_space()->ContainsSlow(first_page->address())); 75 CHECK(heap->new_space()->ContainsSlow(to_be_promoted_page->address()));
73 CHECK(!heap->old_space()->ContainsSlow(first_page->address())); 76 CHECK(!heap->old_space()->ContainsSlow(to_be_promoted_page->address()));
74 heap::GcAndSweep(heap, OLD_SPACE); 77 heap::GcAndSweep(heap, OLD_SPACE);
75 CHECK(!heap->new_space()->ContainsSlow(first_page->address())); 78 CHECK(!heap->new_space()->ContainsSlow(to_be_promoted_page->address()));
76 CHECK(heap->old_space()->ContainsSlow(first_page->address())); 79 CHECK(heap->old_space()->ContainsSlow(to_be_promoted_page->address()));
77 } 80 }
78 } 81 }
79 82
80 UNINITIALIZED_TEST(PagePromotion_NewToNew) { 83 UNINITIALIZED_TEST(PagePromotion_NewToNew) {
81 if (!i::FLAG_page_promotion) return; 84 if (!i::FLAG_page_promotion) return;
82 85
83 v8::Isolate* isolate = NewIsolateForPagePromotion(); 86 v8::Isolate* isolate = NewIsolateForPagePromotion();
84 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate); 87 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
85 { 88 {
86 v8::Isolate::Scope isolate_scope(isolate); 89 v8::Isolate::Scope isolate_scope(isolate);
87 v8::HandleScope handle_scope(isolate); 90 v8::HandleScope handle_scope(isolate);
88 v8::Context::New(isolate)->Enter(); 91 v8::Context::New(isolate)->Enter();
89 Heap* heap = i_isolate->heap(); 92 Heap* heap = i_isolate->heap();
90 93
91 std::vector<Handle<FixedArray>> handles; 94 std::vector<Handle<FixedArray>> handles;
92 heap::SimulateFullSpace(heap->new_space(), &handles); 95 heap::SimulateFullSpace(heap->new_space(), &handles);
93 CHECK_GT(handles.size(), 0u); 96 CHECK_GT(handles.size(), 0u);
94 // Last object in handles should definitely be on the last page which does 97 // Last object in handles should definitely be on a page that does not
95 // not contain the age mark. 98 // contain the age mark, thus qualifying for moving.
96 Handle<FixedArray> last_object = handles.back(); 99 Handle<FixedArray> last_object = handles.back();
97 Page* to_be_promoted_page = Page::FromAddress(last_object->address()); 100 Page* to_be_promoted_page = Page::FromAddress(last_object->address());
101 CHECK(!to_be_promoted_page->Contains(heap->new_space()->age_mark()));
98 CHECK(to_be_promoted_page->Contains(last_object->address())); 102 CHECK(to_be_promoted_page->Contains(last_object->address()));
99 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address())); 103 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
100 heap::GcAndSweep(heap, OLD_SPACE); 104 heap::GcAndSweep(heap, OLD_SPACE);
101 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address())); 105 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
102 CHECK(to_be_promoted_page->Contains(last_object->address())); 106 CHECK(to_be_promoted_page->Contains(last_object->address()));
103 } 107 }
104 } 108 }
105 109
106 UNINITIALIZED_TEST(PagePromotion_NewToNewJSArrayBuffer) { 110 UNINITIALIZED_TEST(PagePromotion_NewToNewJSArrayBuffer) {
107 if (!i::FLAG_page_promotion) return; 111 if (!i::FLAG_page_promotion) return;
(...skipping 11 matching lines...) Expand all
119 // Fill the current page which potentially contains the age mark. 123 // Fill the current page which potentially contains the age mark.
120 heap::FillCurrentPage(heap->new_space()); 124 heap::FillCurrentPage(heap->new_space());
121 // Allocate a buffer we would like to check against. 125 // Allocate a buffer we would like to check against.
122 Handle<JSArrayBuffer> buffer = 126 Handle<JSArrayBuffer> buffer =
123 i_isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared); 127 i_isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared);
124 CHECK(JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, 100)); 128 CHECK(JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, 100));
125 std::vector<Handle<FixedArray>> handles; 129 std::vector<Handle<FixedArray>> handles;
126 // Simulate a full space, filling the interesting page with live objects. 130 // Simulate a full space, filling the interesting page with live objects.
127 heap::SimulateFullSpace(heap->new_space(), &handles); 131 heap::SimulateFullSpace(heap->new_space(), &handles);
128 CHECK_GT(handles.size(), 0u); 132 CHECK_GT(handles.size(), 0u);
129 // Last object in handles should definitely be on the last page which does 133 // First object in handles should be on the same page as the allocated
130 // not contain the age mark. 134 // JSArrayBuffer.
131 Handle<FixedArray> first_object = handles.front(); 135 Handle<FixedArray> first_object = handles.front();
132 Page* to_be_promoted_page = Page::FromAddress(first_object->address()); 136 Page* to_be_promoted_page = Page::FromAddress(first_object->address());
137 CHECK(!to_be_promoted_page->Contains(heap->new_space()->age_mark()));
133 CHECK(to_be_promoted_page->Contains(first_object->address())); 138 CHECK(to_be_promoted_page->Contains(first_object->address()));
134 CHECK(to_be_promoted_page->Contains(buffer->address())); 139 CHECK(to_be_promoted_page->Contains(buffer->address()));
135 CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address())); 140 CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address()));
136 CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address())); 141 CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address()));
137 heap::GcAndSweep(heap, OLD_SPACE); 142 heap::GcAndSweep(heap, OLD_SPACE);
138 CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address())); 143 CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address()));
139 CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address())); 144 CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address()));
140 CHECK(to_be_promoted_page->Contains(first_object->address())); 145 CHECK(to_be_promoted_page->Contains(first_object->address()));
141 CHECK(to_be_promoted_page->Contains(buffer->address())); 146 CHECK(to_be_promoted_page->Contains(buffer->address()));
142 CHECK(ArrayBufferTracker::IsTracked(*buffer)); 147 CHECK(ArrayBufferTracker::IsTracked(*buffer));
(...skipping 10 matching lines...) Expand all
153 v8::HandleScope handle_scope(isolate); 158 v8::HandleScope handle_scope(isolate);
154 v8::Context::New(isolate)->Enter(); 159 v8::Context::New(isolate)->Enter();
155 Heap* heap = i_isolate->heap(); 160 Heap* heap = i_isolate->heap();
156 heap->delay_sweeper_tasks_for_testing_ = true; 161 heap->delay_sweeper_tasks_for_testing_ = true;
157 heap->new_space()->Grow(); 162 heap->new_space()->Grow();
158 { 163 {
159 v8::HandleScope inner_handle_scope(isolate); 164 v8::HandleScope inner_handle_scope(isolate);
160 std::vector<Handle<FixedArray>> handles; 165 std::vector<Handle<FixedArray>> handles;
161 heap::SimulateFullSpace(heap->new_space(), &handles); 166 heap::SimulateFullSpace(heap->new_space(), &handles);
162 CHECK_GT(handles.size(), 0u); 167 CHECK_GT(handles.size(), 0u);
163 // Last object in handles should definitely be on the last page which does 168 // Last object in handles should definitely be on a page that does not
164 // not contain the age mark. 169 // contain the age mark, thus qualifying for moving.
165 Handle<FixedArray> last_object = handles.back(); 170 Handle<FixedArray> last_object = handles.back();
166 Page* to_be_promoted_page = Page::FromAddress(last_object->address()); 171 Page* to_be_promoted_page = Page::FromAddress(last_object->address());
172 CHECK(!to_be_promoted_page->Contains(heap->new_space()->age_mark()));
167 CHECK(to_be_promoted_page->Contains(last_object->address())); 173 CHECK(to_be_promoted_page->Contains(last_object->address()));
168 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address())); 174 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
169 heap->CollectGarbage(OLD_SPACE, i::GarbageCollectionReason::kTesting); 175 heap->CollectGarbage(OLD_SPACE, i::GarbageCollectionReason::kTesting);
170 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address())); 176 CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
171 CHECK(to_be_promoted_page->Contains(last_object->address())); 177 CHECK(to_be_promoted_page->Contains(last_object->address()));
172 } 178 }
173 heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting); 179 heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting);
174 heap->new_space()->Shrink(); 180 heap->new_space()->Shrink();
175 heap->memory_allocator()->unmapper()->WaitUntilCompleted(); 181 heap->memory_allocator()->unmapper()->WaitUntilCompleted();
176 heap->mark_compact_collector()->sweeper().StartSweeperTasks(); 182 heap->mark_compact_collector()->sweeper().StartSweeperTasks();
177 heap->mark_compact_collector()->EnsureSweepingCompleted(); 183 heap->mark_compact_collector()->EnsureSweepingCompleted();
178 } 184 }
179 } 185 }
180 186
181 } // namespace internal 187 } // namespace internal
182 } // namespace v8 188 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/page-parallel-job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698