OLD | NEW |
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 NOT_EXECUTABLE); | 298 NOT_EXECUTABLE); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 | 302 |
303 TEST(MemoryAllocator) { | 303 TEST(MemoryAllocator) { |
304 Isolate* isolate = CcTest::i_isolate(); | 304 Isolate* isolate = CcTest::i_isolate(); |
305 Heap* heap = isolate->heap(); | 305 Heap* heap = isolate->heap(); |
306 | 306 |
307 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 307 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
| 308 CHECK(memory_allocator != nullptr); |
308 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 309 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
309 heap->MaxExecutableSize())); | 310 heap->MaxExecutableSize())); |
| 311 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); |
310 | 312 |
311 int total_pages = 0; | 313 { |
312 OldSpace faked_space(heap, OLD_SPACE, NOT_EXECUTABLE); | 314 int total_pages = 0; |
313 Page* first_page = memory_allocator->AllocatePage( | 315 OldSpace faked_space(heap, OLD_SPACE, NOT_EXECUTABLE); |
314 faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE); | 316 Page* first_page = memory_allocator->AllocatePage( |
| 317 faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE); |
315 | 318 |
316 first_page->InsertAfter(faked_space.anchor()->prev_page()); | 319 first_page->InsertAfter(faked_space.anchor()->prev_page()); |
317 CHECK(first_page->is_valid()); | 320 CHECK(first_page->is_valid()); |
318 CHECK(first_page->next_page() == faked_space.anchor()); | 321 CHECK(first_page->next_page() == faked_space.anchor()); |
319 total_pages++; | 322 total_pages++; |
320 | 323 |
321 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { | 324 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
322 CHECK(p->owner() == &faked_space); | 325 CHECK(p->owner() == &faked_space); |
| 326 } |
| 327 |
| 328 // Again, we should get n or n - 1 pages. |
| 329 Page* other = memory_allocator->AllocatePage(faked_space.AreaSize(), |
| 330 &faked_space, NOT_EXECUTABLE); |
| 331 CHECK(other->is_valid()); |
| 332 total_pages++; |
| 333 other->InsertAfter(first_page); |
| 334 int page_count = 0; |
| 335 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
| 336 CHECK(p->owner() == &faked_space); |
| 337 page_count++; |
| 338 } |
| 339 CHECK(total_pages == page_count); |
| 340 |
| 341 Page* second_page = first_page->next_page(); |
| 342 CHECK(second_page->is_valid()); |
| 343 |
| 344 // OldSpace's destructor will tear down the space and free up all pages. |
323 } | 345 } |
324 | |
325 // Again, we should get n or n - 1 pages. | |
326 Page* other = memory_allocator->AllocatePage( | |
327 faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE); | |
328 CHECK(other->is_valid()); | |
329 total_pages++; | |
330 other->InsertAfter(first_page); | |
331 int page_count = 0; | |
332 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { | |
333 CHECK(p->owner() == &faked_space); | |
334 page_count++; | |
335 } | |
336 CHECK(total_pages == page_count); | |
337 | |
338 Page* second_page = first_page->next_page(); | |
339 CHECK(second_page->is_valid()); | |
340 memory_allocator->Free(first_page); | |
341 memory_allocator->Free(second_page); | |
342 memory_allocator->TearDown(); | 346 memory_allocator->TearDown(); |
343 delete memory_allocator; | 347 delete memory_allocator; |
344 } | 348 } |
345 | 349 |
346 | 350 |
347 TEST(NewSpace) { | 351 TEST(NewSpace) { |
348 Isolate* isolate = CcTest::i_isolate(); | 352 Isolate* isolate = CcTest::i_isolate(); |
349 Heap* heap = isolate->heap(); | 353 Heap* heap = isolate->heap(); |
350 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 354 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
351 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 355 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
(...skipping 29 matching lines...) Expand all Loading... |
381 | 385 |
382 OldSpace* s = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE); | 386 OldSpace* s = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE); |
383 CHECK(s != NULL); | 387 CHECK(s != NULL); |
384 | 388 |
385 CHECK(s->SetUp()); | 389 CHECK(s->SetUp()); |
386 | 390 |
387 while (s->Available() > 0) { | 391 while (s->Available() > 0) { |
388 s->AllocateRawUnaligned(Page::kMaxRegularHeapObjectSize).ToObjectChecked(); | 392 s->AllocateRawUnaligned(Page::kMaxRegularHeapObjectSize).ToObjectChecked(); |
389 } | 393 } |
390 | 394 |
391 s->TearDown(); | |
392 delete s; | 395 delete s; |
393 memory_allocator->TearDown(); | 396 memory_allocator->TearDown(); |
394 delete memory_allocator; | 397 delete memory_allocator; |
395 } | 398 } |
396 | 399 |
397 | 400 |
| 401 TEST(CompactionSpace) { |
| 402 Isolate* isolate = CcTest::i_isolate(); |
| 403 Heap* heap = isolate->heap(); |
| 404 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
| 405 CHECK(memory_allocator != nullptr); |
| 406 CHECK( |
| 407 memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize())); |
| 408 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); |
| 409 |
| 410 CompactionSpace* compaction_space = |
| 411 new CompactionSpace(heap, OLD_SPACE, NOT_EXECUTABLE); |
| 412 CHECK(compaction_space != NULL); |
| 413 CHECK(compaction_space->SetUp()); |
| 414 |
| 415 OldSpace* old_space = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE); |
| 416 CHECK(old_space != NULL); |
| 417 CHECK(old_space->SetUp()); |
| 418 |
| 419 // Cannot loop until "Available()" since we initially have 0 bytes available |
| 420 // and would thus neither grow, nor be able to allocate an object. |
| 421 const int kNumObjects = 100; |
| 422 const int kExpectedPages = kNumObjects; |
| 423 for (int i = 0; i < kNumObjects; i++) { |
| 424 compaction_space->AllocateRawUnaligned(Page::kMaxRegularHeapObjectSize) |
| 425 .ToObjectChecked(); |
| 426 } |
| 427 int pages_in_old_space = old_space->CountTotalPages(); |
| 428 int pages_in_compaction_space = compaction_space->CountTotalPages(); |
| 429 CHECK_EQ(pages_in_compaction_space, kExpectedPages); |
| 430 CHECK_LE(pages_in_old_space, 1); |
| 431 |
| 432 old_space->MergeCompactionSpace(compaction_space); |
| 433 CHECK_EQ(old_space->CountTotalPages(), |
| 434 pages_in_old_space + pages_in_compaction_space); |
| 435 |
| 436 delete compaction_space; |
| 437 delete old_space; |
| 438 |
| 439 memory_allocator->TearDown(); |
| 440 delete memory_allocator; |
| 441 } |
| 442 |
| 443 |
398 TEST(LargeObjectSpace) { | 444 TEST(LargeObjectSpace) { |
399 v8::V8::Initialize(); | 445 v8::V8::Initialize(); |
400 | 446 |
401 LargeObjectSpace* lo = CcTest::heap()->lo_space(); | 447 LargeObjectSpace* lo = CcTest::heap()->lo_space(); |
402 CHECK(lo != NULL); | 448 CHECK(lo != NULL); |
403 | 449 |
404 int lo_size = Page::kPageSize; | 450 int lo_size = Page::kPageSize; |
405 | 451 |
406 Object* obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE).ToObjectChecked(); | 452 Object* obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE).ToObjectChecked(); |
407 CHECK(obj->IsHeapObject()); | 453 CHECK(obj->IsHeapObject()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 542 |
497 // Turn the allocation into a proper object so isolate teardown won't | 543 // Turn the allocation into a proper object so isolate teardown won't |
498 // crash. | 544 // crash. |
499 HeapObject* free_space = NULL; | 545 HeapObject* free_space = NULL; |
500 CHECK(allocation.To(&free_space)); | 546 CHECK(allocation.To(&free_space)); |
501 new_space->heap()->CreateFillerObjectAt(free_space->address(), 80); | 547 new_space->heap()->CreateFillerObjectAt(free_space->address(), 80); |
502 } | 548 } |
503 } | 549 } |
504 isolate->Dispose(); | 550 isolate->Dispose(); |
505 } | 551 } |
OLD | NEW |