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

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

Issue 5987005: Refactor MemoryAllocator to allow big normal pages (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: remove rogue printf Created 9 years, 12 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-mark-compact.cc ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 14 matching lines...) Expand all
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 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "cctest.h" 31 #include "cctest.h"
32 32
33 using namespace v8::internal; 33 using namespace v8::internal;
34 34
35 #if 0
35 static void VerifyRegionMarking(Address page_start) { 36 static void VerifyRegionMarking(Address page_start) {
36 #ifdef ENABLE_CARDMARKING_WRITE_BARRIER 37 #ifdef ENABLE_CARDMARKING_WRITE_BARRIER
37 Page* p = Page::FromAddress(page_start); 38 Page* p = Page::FromAddress(page_start);
38 39
39 p->SetRegionMarks(Page::kAllRegionsCleanMarks); 40 p->SetRegionMarks(Page::kAllRegionsCleanMarks);
40 41
41 for (Address addr = p->ObjectAreaStart(); 42 for (Address addr = p->ObjectAreaStart();
42 addr < p->ObjectAreaEnd(); 43 addr < p->ObjectAreaEnd();
43 addr += kPointerSize) { 44 addr += kPointerSize) {
44 CHECK(!Page::FromAddress(addr)->IsRegionDirty(addr)); 45 CHECK(!Page::FromAddress(addr)->IsRegionDirty(addr));
45 } 46 }
46 47
47 for (Address addr = p->ObjectAreaStart(); 48 for (Address addr = p->ObjectAreaStart();
48 addr < p->ObjectAreaEnd(); 49 addr < p->ObjectAreaEnd();
49 addr += kPointerSize) { 50 addr += kPointerSize) {
50 Page::FromAddress(addr)->MarkRegionDirty(addr); 51 Page::FromAddress(addr)->MarkRegionDirty(addr);
51 } 52 }
52 53
53 for (Address addr = p->ObjectAreaStart(); 54 for (Address addr = p->ObjectAreaStart();
54 addr < p->ObjectAreaEnd(); 55 addr < p->ObjectAreaEnd();
55 addr += kPointerSize) { 56 addr += kPointerSize) {
56 CHECK(Page::FromAddress(addr)->IsRegionDirty(addr)); 57 CHECK(Page::FromAddress(addr)->IsRegionDirty(addr));
57 } 58 }
58 #endif 59 #endif
59 } 60 }
61 #endif
60 62
61 63
64 // TODO(gc) you can no longer allocate pages like this. Details are hidden.
65 #if 0
62 TEST(Page) { 66 TEST(Page) {
63 byte* mem = NewArray<byte>(2*Page::kPageSize); 67 byte* mem = NewArray<byte>(2*Page::kPageSize);
64 CHECK(mem != NULL); 68 CHECK(mem != NULL);
65 69
66 Address start = reinterpret_cast<Address>(mem); 70 Address start = reinterpret_cast<Address>(mem);
67 Address page_start = RoundUp(start, Page::kPageSize); 71 Address page_start = RoundUp(start, Page::kPageSize);
68 72
69 Page* p = Page::FromAddress(page_start); 73 Page* p = Page::FromAddress(page_start);
70 CHECK(p->address() == page_start); 74 CHECK(p->address() == page_start);
71 CHECK(p->is_valid()); 75 CHECK(p->is_valid());
(...skipping 10 matching lines...) Expand all
82 CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize); 86 CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize);
83 87
84 CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart()); 88 CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart());
85 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); 89 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd());
86 90
87 // test region marking 91 // test region marking
88 VerifyRegionMarking(page_start); 92 VerifyRegionMarking(page_start);
89 93
90 DeleteArray(mem); 94 DeleteArray(mem);
91 } 95 }
96 #endif
92 97
93 98
94 TEST(MemoryAllocator) { 99 TEST(MemoryAllocator) {
95 CHECK(Heap::ConfigureHeapDefault()); 100 CHECK(Heap::ConfigureHeapDefault());
96 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); 101 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize()));
97 102
103 int total_pages = 0;
98 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE); 104 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE);
99 int total_pages = 0;
100 int requested = MemoryAllocator::kPagesPerChunk;
101 int allocated;
102 // If we request n pages, we should get n or n - 1.
103 Page* first_page = 105 Page* first_page =
104 MemoryAllocator::AllocatePages(requested, &allocated, &faked_space); 106 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE);
105 CHECK(first_page->is_valid()); 107 CHECK(first_page->is_valid());
106 CHECK(allocated == requested || allocated == requested - 1); 108 CHECK(!first_page->next_page()->is_valid());
107 total_pages += allocated; 109 total_pages++;
108 110
109 Page* last_page = first_page; 111 Page* last_page = first_page;
110 for (Page* p = first_page; p->is_valid(); p = p->next_page()) { 112 for (Page* p = first_page; p->is_valid(); p = p->next_page()) {
111 CHECK(MemoryAllocator::IsPageInSpace(p, &faked_space)); 113 CHECK(p->owner() == &faked_space);
112 last_page = p; 114 last_page = p;
113 } 115 }
114 116
117 CHECK(last_page == first_page);
118
115 // Again, we should get n or n - 1 pages. 119 // Again, we should get n or n - 1 pages.
116 Page* others = 120 Page* other =
117 MemoryAllocator::AllocatePages(requested, &allocated, &faked_space); 121 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE);
118 CHECK(others->is_valid()); 122 CHECK(other->is_valid());
119 CHECK(allocated == requested || allocated == requested - 1); 123 total_pages++;
120 total_pages += allocated; 124 last_page->set_next_page(other);
121
122 MemoryAllocator::SetNextPage(last_page, others);
123 int page_count = 0; 125 int page_count = 0;
124 for (Page* p = first_page; p->is_valid(); p = p->next_page()) { 126 for (Page* p = first_page; p->is_valid(); p = p->next_page()) {
125 CHECK(MemoryAllocator::IsPageInSpace(p, &faked_space)); 127 CHECK(p->owner() == &faked_space);
126 page_count++; 128 page_count++;
127 } 129 }
128 CHECK(total_pages == page_count); 130 CHECK(total_pages == page_count);
129 131
130 Page* second_page = first_page->next_page(); 132 Page* second_page = first_page->next_page();
131 CHECK(second_page->is_valid()); 133 CHECK(second_page->is_valid());
132 134 MemoryAllocator::Free(first_page);
133 // Freeing pages at the first chunk starting at or after the second page 135 MemoryAllocator::Free(second_page);
134 // should free the entire second chunk. It will return the page it was passed
135 // (since the second page was in the first chunk).
136 Page* free_return = MemoryAllocator::FreePages(second_page);
137 CHECK(free_return == second_page);
138 MemoryAllocator::SetNextPage(first_page, free_return);
139
140 // Freeing pages in the first chunk starting at the first page should free
141 // the first chunk and return an invalid page.
142 Page* invalid_page = MemoryAllocator::FreePages(first_page);
143 CHECK(!invalid_page->is_valid());
144
145 MemoryAllocator::TearDown(); 136 MemoryAllocator::TearDown();
146 } 137 }
147 138
148 139
149 TEST(NewSpace) { 140 TEST(NewSpace) {
150 CHECK(Heap::ConfigureHeapDefault()); 141 CHECK(Heap::ConfigureHeapDefault());
151 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); 142 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize()));
152 143
153 NewSpace new_space; 144 NewSpace new_space;
154 145
155 void* chunk = 146 CHECK(new_space.Setup(Heap::ReservedSemiSpaceSize()));
156 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize());
157 CHECK(chunk != NULL);
158 Address start = RoundUp(static_cast<Address>(chunk),
159 2 * Heap::ReservedSemiSpaceSize());
160 CHECK(new_space.Setup(start, 2 * Heap::ReservedSemiSpaceSize()));
161 CHECK(new_space.HasBeenSetup()); 147 CHECK(new_space.HasBeenSetup());
162 148
163 while (new_space.Available() >= Page::kMaxHeapObjectSize) { 149 while (new_space.Available() >= Page::kMaxHeapObjectSize) {
164 Object* obj = 150 Object* obj =
165 new_space.AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); 151 new_space.AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked();
166 CHECK(new_space.Contains(HeapObject::cast(obj))); 152 CHECK(new_space.Contains(HeapObject::cast(obj)));
167 } 153 }
168 154
169 new_space.TearDown(); 155 new_space.TearDown();
170 MemoryAllocator::TearDown(); 156 MemoryAllocator::TearDown();
171 } 157 }
172 158
173 159
174 TEST(OldSpace) { 160 TEST(OldSpace) {
175 CHECK(Heap::ConfigureHeapDefault()); 161 CHECK(Heap::ConfigureHeapDefault());
176 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); 162 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize()));
177 163
178 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(), 164 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(),
179 OLD_POINTER_SPACE, 165 OLD_POINTER_SPACE,
180 NOT_EXECUTABLE); 166 NOT_EXECUTABLE);
181 CHECK(s != NULL); 167 CHECK(s != NULL);
182 168
183 void* chunk = 169 CHECK(s->Setup());
184 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize());
185 CHECK(chunk != NULL);
186 Address start = static_cast<Address>(chunk);
187 size_t size = RoundUp(start, 2 * Heap::ReservedSemiSpaceSize()) - start;
188
189 CHECK(s->Setup(start, size));
190 170
191 while (s->Available() > 0) { 171 while (s->Available() > 0) {
192 s->AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); 172 s->AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked();
193 } 173 }
194 174
195 s->TearDown(); 175 s->TearDown();
196 delete s; 176 delete s;
197 MemoryAllocator::TearDown(); 177 MemoryAllocator::TearDown();
198 } 178 }
199 179
(...skipping 25 matching lines...) Expand all
225 if (!maybe_obj->ToObject(&obj)) break; 205 if (!maybe_obj->ToObject(&obj)) break;
226 } 206 }
227 HeapObject::cast(obj)->set_map(faked_map); 207 HeapObject::cast(obj)->set_map(faked_map);
228 CHECK(lo->Available() < available); 208 CHECK(lo->Available() < available);
229 }; 209 };
230 210
231 CHECK(!lo->IsEmpty()); 211 CHECK(!lo->IsEmpty());
232 212
233 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); 213 CHECK(lo->AllocateRaw(lo_size)->IsFailure());
234 214
235 lo->TearDown(); 215 Heap::TearDown();
236 delete lo;
237
238 MemoryAllocator::TearDown();
239 } 216 }
OLDNEW
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698