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

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

Issue 23641009: Refactor and cleanup VirtualMemory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nits. Created 7 years, 3 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-platform-win32.cc ('k') | test/cctest/test-virtual-memory.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 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 } } // namespace v8::internal 145 } } // namespace v8::internal
146 146
147 147
148 static void VerifyMemoryChunk(Isolate* isolate, 148 static void VerifyMemoryChunk(Isolate* isolate,
149 Heap* heap, 149 Heap* heap,
150 CodeRange* code_range, 150 CodeRange* code_range,
151 size_t reserve_area_size, 151 size_t reserve_area_size,
152 size_t commit_area_size, 152 size_t commit_area_size,
153 size_t second_commit_area_size, 153 size_t second_commit_area_size,
154 Executability executable) { 154 VirtualMemory::Executability executability) {
155 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); 155 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
156 CHECK(memory_allocator->SetUp(heap->MaxReserved(), 156 CHECK(memory_allocator->SetUp(heap->MaxReserved(),
157 heap->MaxExecutableSize())); 157 heap->MaxExecutableSize()));
158 TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); 158 TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
159 TestCodeRangeScope test_code_range_scope(isolate, code_range); 159 TestCodeRangeScope test_code_range_scope(isolate, code_range);
160 160
161 size_t header_size = (executable == EXECUTABLE) 161 size_t header_size = (executability == VirtualMemory::EXECUTABLE)
162 ? MemoryAllocator::CodePageGuardStartOffset() 162 ? MemoryAllocator::CodePageGuardStartOffset()
163 : MemoryChunk::kObjectStartOffset; 163 : MemoryChunk::kObjectStartOffset;
164 size_t guard_size = (executable == EXECUTABLE) 164 size_t guard_size = (executability == VirtualMemory::EXECUTABLE)
165 ? MemoryAllocator::CodePageGuardSize() 165 ? MemoryAllocator::CodePageGuardSize()
166 : 0; 166 : 0;
167 167
168 MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size, 168 MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size,
169 commit_area_size, 169 commit_area_size,
170 executable, 170 executability,
171 NULL); 171 NULL);
172 size_t alignment = code_range->exists() ? 172 size_t alignment = code_range->exists() ?
173 MemoryChunk::kAlignment : OS::CommitPageSize(); 173 MemoryChunk::kAlignment : VirtualMemory::GetPageSize();
174 size_t reserved_size = ((executable == EXECUTABLE)) 174 size_t reserved_size = ((executability == VirtualMemory::EXECUTABLE))
175 ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, 175 ? RoundUp(header_size + guard_size + reserve_area_size + guard_size,
176 alignment) 176 alignment)
177 : RoundUp(header_size + reserve_area_size, OS::CommitPageSize()); 177 : RoundUp(header_size + reserve_area_size, VirtualMemory::GetPageSize());
178 CHECK(memory_chunk->size() == reserved_size); 178 CHECK(memory_chunk->size() == reserved_size);
179 CHECK(memory_chunk->area_start() < memory_chunk->address() + 179 CHECK(memory_chunk->area_start() < memory_chunk->address() +
180 memory_chunk->size()); 180 memory_chunk->size());
181 CHECK(memory_chunk->area_end() <= memory_chunk->address() + 181 CHECK(memory_chunk->area_end() <= memory_chunk->address() +
182 memory_chunk->size()); 182 memory_chunk->size());
183 CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size); 183 CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size);
184 184
185 Address area_start = memory_chunk->area_start(); 185 Address area_start = memory_chunk->area_start();
186 186
187 memory_chunk->CommitArea(second_commit_area_size); 187 memory_chunk->CommitArea(second_commit_area_size);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 CodeRange* code_range = new CodeRange(isolate); 223 CodeRange* code_range = new CodeRange(isolate);
224 const int code_range_size = 32 * MB; 224 const int code_range_size = 32 * MB;
225 if (!code_range->SetUp(code_range_size)) return; 225 if (!code_range->SetUp(code_range_size)) return;
226 226
227 VerifyMemoryChunk(isolate, 227 VerifyMemoryChunk(isolate,
228 heap, 228 heap,
229 code_range, 229 code_range,
230 reserve_area_size, 230 reserve_area_size,
231 initial_commit_area_size, 231 initial_commit_area_size,
232 second_commit_area_size, 232 second_commit_area_size,
233 EXECUTABLE); 233 VirtualMemory::EXECUTABLE);
234 234
235 VerifyMemoryChunk(isolate, 235 VerifyMemoryChunk(isolate,
236 heap, 236 heap,
237 code_range, 237 code_range,
238 reserve_area_size, 238 reserve_area_size,
239 initial_commit_area_size, 239 initial_commit_area_size,
240 second_commit_area_size, 240 second_commit_area_size,
241 NOT_EXECUTABLE); 241 VirtualMemory::NOT_EXECUTABLE);
242 delete code_range; 242 delete code_range;
243 243
244 // Without CodeRange. 244 // Without CodeRange.
245 code_range = NULL; 245 code_range = NULL;
246 VerifyMemoryChunk(isolate, 246 VerifyMemoryChunk(isolate,
247 heap, 247 heap,
248 code_range, 248 code_range,
249 reserve_area_size, 249 reserve_area_size,
250 initial_commit_area_size, 250 initial_commit_area_size,
251 second_commit_area_size, 251 second_commit_area_size,
252 EXECUTABLE); 252 VirtualMemory::EXECUTABLE);
253 253
254 VerifyMemoryChunk(isolate, 254 VerifyMemoryChunk(isolate,
255 heap, 255 heap,
256 code_range, 256 code_range,
257 reserve_area_size, 257 reserve_area_size,
258 initial_commit_area_size, 258 initial_commit_area_size,
259 second_commit_area_size, 259 second_commit_area_size,
260 NOT_EXECUTABLE); 260 VirtualMemory::NOT_EXECUTABLE);
261 } 261 }
262 } 262 }
263 263
264 264
265 TEST(MemoryAllocator) { 265 TEST(MemoryAllocator) {
266 Isolate* isolate = Isolate::Current(); 266 Isolate* isolate = Isolate::Current();
267 isolate->InitializeLoggingAndCounters(); 267 isolate->InitializeLoggingAndCounters();
268 Heap* heap = isolate->heap(); 268 Heap* heap = isolate->heap();
269 CHECK(isolate->heap()->ConfigureHeapDefault()); 269 CHECK(isolate->heap()->ConfigureHeapDefault());
270 270
271 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); 271 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
272 CHECK(memory_allocator->SetUp(heap->MaxReserved(), 272 CHECK(memory_allocator->SetUp(heap->MaxReserved(),
273 heap->MaxExecutableSize())); 273 heap->MaxExecutableSize()));
274 274
275 int total_pages = 0; 275 int total_pages = 0;
276 OldSpace faked_space(heap, 276 OldSpace faked_space(heap,
277 heap->MaxReserved(), 277 heap->MaxReserved(),
278 OLD_POINTER_SPACE, 278 OLD_POINTER_SPACE,
279 NOT_EXECUTABLE); 279 VirtualMemory::NOT_EXECUTABLE);
280 Page* first_page = memory_allocator->AllocatePage( 280 Page* first_page = memory_allocator->AllocatePage(
281 faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE); 281 faked_space.AreaSize(), &faked_space, VirtualMemory::NOT_EXECUTABLE);
282 282
283 first_page->InsertAfter(faked_space.anchor()->prev_page()); 283 first_page->InsertAfter(faked_space.anchor()->prev_page());
284 CHECK(first_page->is_valid()); 284 CHECK(first_page->is_valid());
285 CHECK(first_page->next_page() == faked_space.anchor()); 285 CHECK(first_page->next_page() == faked_space.anchor());
286 total_pages++; 286 total_pages++;
287 287
288 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { 288 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) {
289 CHECK(p->owner() == &faked_space); 289 CHECK(p->owner() == &faked_space);
290 } 290 }
291 291
292 // Again, we should get n or n - 1 pages. 292 // Again, we should get n or n - 1 pages.
293 Page* other = memory_allocator->AllocatePage( 293 Page* other = memory_allocator->AllocatePage(
294 faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE); 294 faked_space.AreaSize(), &faked_space, VirtualMemory::NOT_EXECUTABLE);
295 CHECK(other->is_valid()); 295 CHECK(other->is_valid());
296 total_pages++; 296 total_pages++;
297 other->InsertAfter(first_page); 297 other->InsertAfter(first_page);
298 int page_count = 0; 298 int page_count = 0;
299 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { 299 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) {
300 CHECK(p->owner() == &faked_space); 300 CHECK(p->owner() == &faked_space);
301 page_count++; 301 page_count++;
302 } 302 }
303 CHECK(total_pages == page_count); 303 CHECK(total_pages == page_count);
304 304
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 Heap* heap = isolate->heap(); 346 Heap* heap = isolate->heap();
347 CHECK(heap->ConfigureHeapDefault()); 347 CHECK(heap->ConfigureHeapDefault());
348 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); 348 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
349 CHECK(memory_allocator->SetUp(heap->MaxReserved(), 349 CHECK(memory_allocator->SetUp(heap->MaxReserved(),
350 heap->MaxExecutableSize())); 350 heap->MaxExecutableSize()));
351 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); 351 TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
352 352
353 OldSpace* s = new OldSpace(heap, 353 OldSpace* s = new OldSpace(heap,
354 heap->MaxOldGenerationSize(), 354 heap->MaxOldGenerationSize(),
355 OLD_POINTER_SPACE, 355 OLD_POINTER_SPACE,
356 NOT_EXECUTABLE); 356 VirtualMemory::NOT_EXECUTABLE);
357 CHECK(s != NULL); 357 CHECK(s != NULL);
358 358
359 CHECK(s->SetUp()); 359 CHECK(s->SetUp());
360 360
361 while (s->Available() > 0) { 361 while (s->Available() > 0) {
362 s->AllocateRaw(Page::kMaxNonCodeHeapObjectSize)->ToObjectUnchecked(); 362 s->AllocateRaw(Page::kMaxNonCodeHeapObjectSize)->ToObjectUnchecked();
363 } 363 }
364 364
365 s->TearDown(); 365 s->TearDown();
366 delete s; 366 delete s;
367 memory_allocator->TearDown(); 367 memory_allocator->TearDown();
368 delete memory_allocator; 368 delete memory_allocator;
369 } 369 }
370 370
371 371
372 TEST(LargeObjectSpace) { 372 TEST(LargeObjectSpace) {
373 v8::V8::Initialize(); 373 v8::V8::Initialize();
374 374
375 LargeObjectSpace* lo = HEAP->lo_space(); 375 LargeObjectSpace* lo = HEAP->lo_space();
376 CHECK(lo != NULL); 376 CHECK(lo != NULL);
377 377
378 int lo_size = Page::kPageSize; 378 int lo_size = Page::kPageSize;
379 379
380 Object* obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE)->ToObjectUnchecked(); 380 Object* obj = lo->AllocateRaw(
381 lo_size, VirtualMemory::NOT_EXECUTABLE)->ToObjectUnchecked();
381 CHECK(obj->IsHeapObject()); 382 CHECK(obj->IsHeapObject());
382 383
383 HeapObject* ho = HeapObject::cast(obj); 384 HeapObject* ho = HeapObject::cast(obj);
384 385
385 CHECK(lo->Contains(HeapObject::cast(obj))); 386 CHECK(lo->Contains(HeapObject::cast(obj)));
386 387
387 CHECK(lo->FindObject(ho->address()) == obj); 388 CHECK(lo->FindObject(ho->address()) == obj);
388 389
389 CHECK(lo->Contains(ho)); 390 CHECK(lo->Contains(ho));
390 391
391 while (true) { 392 while (true) {
392 intptr_t available = lo->Available(); 393 intptr_t available = lo->Available();
393 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE); 394 { MaybeObject* maybe_obj = lo->AllocateRaw(
395 lo_size, VirtualMemory::NOT_EXECUTABLE);
394 if (!maybe_obj->ToObject(&obj)) break; 396 if (!maybe_obj->ToObject(&obj)) break;
395 } 397 }
396 CHECK(lo->Available() < available); 398 CHECK(lo->Available() < available);
397 }; 399 };
398 400
399 CHECK(!lo->IsEmpty()); 401 CHECK(!lo->IsEmpty());
400 402
401 CHECK(lo->AllocateRaw(lo_size, NOT_EXECUTABLE)->IsFailure()); 403 CHECK(lo->AllocateRaw(lo_size, VirtualMemory::NOT_EXECUTABLE)->IsFailure());
402 } 404 }
OLDNEW
« no previous file with comments | « test/cctest/test-platform-win32.cc ('k') | test/cctest/test-virtual-memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698