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

Side by Side Diff: src/spaces.cc

Issue 9295047: Revert 10542 (boot time memory reduction) due to map alignment (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 10 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 | « src/spaces.h ('k') | src/spaces-inl.h » ('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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "v8.h" 28 #include "v8.h"
29 29
30 #include "liveobjectlist-inl.h" 30 #include "liveobjectlist-inl.h"
31 #include "macro-assembler.h" 31 #include "macro-assembler.h"
32 #include "mark-compact.h" 32 #include "mark-compact.h"
33 #include "platform.h" 33 #include "platform.h"
34 #include "snapshot.h"
35 34
36 namespace v8 { 35 namespace v8 {
37 namespace internal { 36 namespace internal {
38 37
39 38
40 // ---------------------------------------------------------------------------- 39 // ----------------------------------------------------------------------------
41 // HeapObjectIterator 40 // HeapObjectIterator
42 41
43 HeapObjectIterator::HeapObjectIterator(PagedSpace* space) { 42 HeapObjectIterator::HeapObjectIterator(PagedSpace* space) {
44 // You can't actually iterate over the anchor page. It is not a real page, 43 // You can't actually iterate over the anchor page. It is not a real page,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 256
258 257
259 // ----------------------------------------------------------------------------- 258 // -----------------------------------------------------------------------------
260 // MemoryAllocator 259 // MemoryAllocator
261 // 260 //
262 261
263 MemoryAllocator::MemoryAllocator(Isolate* isolate) 262 MemoryAllocator::MemoryAllocator(Isolate* isolate)
264 : isolate_(isolate), 263 : isolate_(isolate),
265 capacity_(0), 264 capacity_(0),
266 capacity_executable_(0), 265 capacity_executable_(0),
267 memory_allocator_reserved_(0), 266 size_(0),
268 size_executable_(0) { 267 size_executable_(0) {
269 } 268 }
270 269
271 270
272 bool MemoryAllocator::SetUp(intptr_t capacity, intptr_t capacity_executable) { 271 bool MemoryAllocator::SetUp(intptr_t capacity, intptr_t capacity_executable) {
273 capacity_ = RoundUp(capacity, Page::kPageSize); 272 capacity_ = RoundUp(capacity, Page::kPageSize);
274 capacity_executable_ = RoundUp(capacity_executable, Page::kPageSize); 273 capacity_executable_ = RoundUp(capacity_executable, Page::kPageSize);
275 ASSERT_GE(capacity_, capacity_executable_); 274 ASSERT_GE(capacity_, capacity_executable_);
276 275
277 memory_allocator_reserved_ = 0; 276 size_ = 0;
278 size_executable_ = 0; 277 size_executable_ = 0;
279 278
280 return true; 279 return true;
281 } 280 }
282 281
283 282
284 void MemoryAllocator::TearDown() { 283 void MemoryAllocator::TearDown() {
285 // Check that spaces were torn down before MemoryAllocator. 284 // Check that spaces were torn down before MemoryAllocator.
286 CHECK_EQ(memory_allocator_reserved_, 0); 285 ASSERT(size_ == 0);
287 // TODO(gc) this will be true again when we fix FreeMemory. 286 // TODO(gc) this will be true again when we fix FreeMemory.
288 // ASSERT(size_executable_ == 0); 287 // ASSERT(size_executable_ == 0);
289 capacity_ = 0; 288 capacity_ = 0;
290 capacity_executable_ = 0; 289 capacity_executable_ = 0;
291 } 290 }
292 291
293 292
294 void MemoryAllocator::FreeMemory(VirtualMemory* reservation, 293 void MemoryAllocator::FreeMemory(VirtualMemory* reservation,
295 Executability executable) { 294 Executability executable) {
296 // TODO(gc) make code_range part of memory allocator? 295 // TODO(gc) make code_range part of memory allocator?
297 ASSERT(reservation->IsReserved()); 296 ASSERT(reservation->IsReserved());
298 size_t size = reservation->size(); 297 size_t size = reservation->size();
299 ASSERT(memory_allocator_reserved_ >= size); 298 ASSERT(size_ >= size);
300 memory_allocator_reserved_ -= size; 299 size_ -= size;
301 300
302 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); 301 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
303 302
304 if (executable == EXECUTABLE) { 303 if (executable == EXECUTABLE) {
305 ASSERT(size_executable_ >= size); 304 ASSERT(size_executable_ >= size);
306 size_executable_ -= size; 305 size_executable_ -= size;
307 } 306 }
308 // Code which is part of the code-range does not have its own VirtualMemory. 307 // Code which is part of the code-range does not have its own VirtualMemory.
309 ASSERT(!isolate_->code_range()->contains( 308 ASSERT(!isolate_->code_range()->contains(
310 static_cast<Address>(reservation->address()))); 309 static_cast<Address>(reservation->address())));
311 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists()); 310 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists());
312 reservation->Release(); 311 reservation->Release();
313 } 312 }
314 313
315 314
316 void MemoryAllocator::FreeMemory(Address base, 315 void MemoryAllocator::FreeMemory(Address base,
317 size_t size, 316 size_t size,
318 Executability executable) { 317 Executability executable) {
319 // TODO(gc) make code_range part of memory allocator? 318 // TODO(gc) make code_range part of memory allocator?
320 ASSERT(memory_allocator_reserved_ >= size); 319 ASSERT(size_ >= size);
321 memory_allocator_reserved_ -= size; 320 size_ -= size;
322 321
323 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); 322 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
324 323
325 if (executable == EXECUTABLE) { 324 if (executable == EXECUTABLE) {
326 ASSERT(size_executable_ >= size); 325 ASSERT(size_executable_ >= size);
327 size_executable_ -= size; 326 size_executable_ -= size;
328 } 327 }
329 if (isolate_->code_range()->contains(static_cast<Address>(base))) { 328 if (isolate_->code_range()->contains(static_cast<Address>(base))) {
330 ASSERT(executable == EXECUTABLE); 329 ASSERT(executable == EXECUTABLE);
331 isolate_->code_range()->FreeRawMemory(base, size); 330 isolate_->code_range()->FreeRawMemory(base, size);
332 } else { 331 } else {
333 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists()); 332 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists());
334 bool result = VirtualMemory::ReleaseRegion(base, size); 333 bool result = VirtualMemory::ReleaseRegion(base, size);
335 USE(result); 334 USE(result);
336 ASSERT(result); 335 ASSERT(result);
337 } 336 }
338 } 337 }
339 338
340 339
341 Address MemoryAllocator::ReserveAlignedMemory(size_t size, 340 Address MemoryAllocator::ReserveAlignedMemory(size_t size,
342 size_t alignment, 341 size_t alignment,
343 VirtualMemory* controller) { 342 VirtualMemory* controller) {
344 VirtualMemory reservation(size, alignment); 343 VirtualMemory reservation(size, alignment);
345 344
346 if (!reservation.IsReserved()) return NULL; 345 if (!reservation.IsReserved()) return NULL;
347 memory_allocator_reserved_ += reservation.size(); 346 size_ += reservation.size();
348 Address base = RoundUp(static_cast<Address>(reservation.address()), 347 Address base = RoundUp(static_cast<Address>(reservation.address()),
349 alignment); 348 alignment);
350 controller->TakeControl(&reservation); 349 controller->TakeControl(&reservation);
351 return base; 350 return base;
352 } 351 }
353 352
354 353
355 Address MemoryAllocator::AllocateAlignedMemory(size_t size, 354 Address MemoryAllocator::AllocateAlignedMemory(size_t size,
356 size_t reserved_size,
357 size_t alignment, 355 size_t alignment,
358 Executability executable, 356 Executability executable,
359 VirtualMemory* controller) { 357 VirtualMemory* controller) {
360 ASSERT(RoundUp(reserved_size, OS::CommitPageSize()) >=
361 RoundUp(size, OS::CommitPageSize()));
362 VirtualMemory reservation; 358 VirtualMemory reservation;
363 Address base = ReserveAlignedMemory(reserved_size, alignment, &reservation); 359 Address base = ReserveAlignedMemory(size, alignment, &reservation);
364 if (base == NULL) return NULL; 360 if (base == NULL) return NULL;
365 if (!reservation.Commit(base, 361 if (!reservation.Commit(base,
366 size, 362 size,
367 executable == EXECUTABLE)) { 363 executable == EXECUTABLE)) {
368 return NULL; 364 return NULL;
369 } 365 }
370 controller->TakeControl(&reservation); 366 controller->TakeControl(&reservation);
371 return base; 367 return base;
372 } 368 }
373 369
374 370
375 void Page::InitializeAsAnchor(PagedSpace* owner) { 371 void Page::InitializeAsAnchor(PagedSpace* owner) {
376 set_owner(owner); 372 set_owner(owner);
377 set_prev_page(this); 373 set_prev_page(this);
378 set_next_page(this); 374 set_next_page(this);
379 } 375 }
380 376
381 377
382 void Page::CommitMore(intptr_t space_needed) {
383 intptr_t reserved_page_size = reservation_.IsReserved() ?
384 reservation_.size() :
385 Page::kPageSize;
386 ASSERT(size() + space_needed <= reserved_page_size);
387 // At increase the page size by at least 64k (this also rounds to OS page
388 // size).
389 int expand = Min(reserved_page_size - size(),
390 RoundUp(size() + space_needed, Page::kGrowthUnit) - size());
391 ASSERT(expand <= kPageSize - size());
392 ASSERT(expand <= reserved_page_size - size());
393 Executability executable =
394 IsFlagSet(IS_EXECUTABLE) ? EXECUTABLE : NOT_EXECUTABLE;
395 Address old_end = ObjectAreaEnd();
396 if (!VirtualMemory::CommitRegion(old_end, expand, executable)) return;
397
398 set_size(size() + expand);
399
400 PagedSpace* paged_space = reinterpret_cast<PagedSpace*>(owner());
401 paged_space->heap()->isolate()->memory_allocator()->AllocationBookkeeping(
402 paged_space,
403 old_end,
404 0, // No new memory was reserved.
405 expand, // New memory committed.
406 executable);
407 paged_space->IncreaseCapacity(expand);
408
409 // In spaces with alignment requirements (e.g. map space) we have to align
410 // the expanded area with the correct object alignment.
411 uintptr_t object_area_size = old_end - ObjectAreaStart();
412 uintptr_t aligned_object_area_size =
413 object_area_size - object_area_size % paged_space->ObjectAlignment();
414 if (aligned_object_area_size != object_area_size) {
415 aligned_object_area_size += paged_space->ObjectAlignment();
416 }
417 Address new_area =
418 reinterpret_cast<Address>(ObjectAreaStart() + aligned_object_area_size);
419 // In spaces with alignment requirements, this will waste the space for one
420 // object per doubling of the page size until the next GC.
421 paged_space->AddToFreeLists(old_end, new_area - old_end);
422
423 expand -= (new_area - old_end);
424
425 paged_space->AddToFreeLists(new_area, expand);
426 }
427
428
429 NewSpacePage* NewSpacePage::Initialize(Heap* heap, 378 NewSpacePage* NewSpacePage::Initialize(Heap* heap,
430 Address start, 379 Address start,
431 SemiSpace* semi_space) { 380 SemiSpace* semi_space) {
432 MemoryChunk* chunk = MemoryChunk::Initialize(heap, 381 MemoryChunk* chunk = MemoryChunk::Initialize(heap,
433 start, 382 start,
434 Page::kPageSize, 383 Page::kPageSize,
435 NOT_EXECUTABLE, 384 NOT_EXECUTABLE,
436 semi_space); 385 semi_space);
437 chunk->set_next_chunk(NULL); 386 chunk->set_next_chunk(NULL);
438 chunk->set_prev_chunk(NULL); 387 chunk->set_prev_chunk(NULL);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 ClearFlag(SCAN_ON_SCAVENGE); 453 ClearFlag(SCAN_ON_SCAVENGE);
505 } 454 }
506 next_chunk_->prev_chunk_ = prev_chunk_; 455 next_chunk_->prev_chunk_ = prev_chunk_;
507 prev_chunk_->next_chunk_ = next_chunk_; 456 prev_chunk_->next_chunk_ = next_chunk_;
508 prev_chunk_ = NULL; 457 prev_chunk_ = NULL;
509 next_chunk_ = NULL; 458 next_chunk_ = NULL;
510 } 459 }
511 460
512 461
513 MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t body_size, 462 MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t body_size,
514 intptr_t committed_body_size,
515 Executability executable, 463 Executability executable,
516 Space* owner) { 464 Space* owner) {
517 ASSERT(body_size >= committed_body_size); 465 size_t chunk_size = MemoryChunk::kObjectStartOffset + body_size;
518 size_t chunk_size = RoundUp(MemoryChunk::kObjectStartOffset + body_size,
519 OS::CommitPageSize());
520 intptr_t committed_chunk_size =
521 committed_body_size + MemoryChunk::kObjectStartOffset;
522 committed_chunk_size = RoundUp(committed_chunk_size, OS::CommitPageSize());
523 Heap* heap = isolate_->heap(); 466 Heap* heap = isolate_->heap();
524 Address base = NULL; 467 Address base = NULL;
525 VirtualMemory reservation; 468 VirtualMemory reservation;
526 if (executable == EXECUTABLE) { 469 if (executable == EXECUTABLE) {
527 // Check executable memory limit. 470 // Check executable memory limit.
528 if (size_executable_ + chunk_size > capacity_executable_) { 471 if (size_executable_ + chunk_size > capacity_executable_) {
529 LOG(isolate_, 472 LOG(isolate_,
530 StringEvent("MemoryAllocator::AllocateRawMemory", 473 StringEvent("MemoryAllocator::AllocateRawMemory",
531 "V8 Executable Allocation capacity exceeded")); 474 "V8 Executable Allocation capacity exceeded"));
532 return NULL; 475 return NULL;
533 } 476 }
534 477
535 // Allocate executable memory either from code range or from the 478 // Allocate executable memory either from code range or from the
536 // OS. 479 // OS.
537 if (isolate_->code_range()->exists()) { 480 if (isolate_->code_range()->exists()) {
538 base = isolate_->code_range()->AllocateRawMemory(chunk_size, &chunk_size); 481 base = isolate_->code_range()->AllocateRawMemory(chunk_size, &chunk_size);
539 ASSERT(IsAligned(reinterpret_cast<intptr_t>(base), 482 ASSERT(IsAligned(reinterpret_cast<intptr_t>(base),
540 MemoryChunk::kAlignment)); 483 MemoryChunk::kAlignment));
541 if (base == NULL) return NULL; 484 if (base == NULL) return NULL;
542 // The AllocateAlignedMemory method will update the memory allocator 485 size_ += chunk_size;
543 // memory used, but we are not using that if we have a code range, so 486 // Update executable memory size.
544 // we update it here. 487 size_executable_ += chunk_size;
545 memory_allocator_reserved_ += chunk_size;
546 } else { 488 } else {
547 base = AllocateAlignedMemory(committed_chunk_size, 489 base = AllocateAlignedMemory(chunk_size,
548 chunk_size,
549 MemoryChunk::kAlignment, 490 MemoryChunk::kAlignment,
550 executable, 491 executable,
551 &reservation); 492 &reservation);
552 if (base == NULL) return NULL; 493 if (base == NULL) return NULL;
494 // Update executable memory size.
495 size_executable_ += reservation.size();
553 } 496 }
554 } else { 497 } else {
555 base = AllocateAlignedMemory(committed_chunk_size, 498 base = AllocateAlignedMemory(chunk_size,
556 chunk_size,
557 MemoryChunk::kAlignment, 499 MemoryChunk::kAlignment,
558 executable, 500 executable,
559 &reservation); 501 &reservation);
560 502
561 if (base == NULL) return NULL; 503 if (base == NULL) return NULL;
562 } 504 }
563 505
564 AllocationBookkeeping( 506 #ifdef DEBUG
565 owner, base, chunk_size, committed_chunk_size, executable); 507 ZapBlock(base, chunk_size);
508 #endif
509 isolate_->counters()->memory_allocated()->
510 Increment(static_cast<int>(chunk_size));
511
512 LOG(isolate_, NewEvent("MemoryChunk", base, chunk_size));
513 if (owner != NULL) {
514 ObjectSpace space = static_cast<ObjectSpace>(1 << owner->identity());
515 PerformAllocationCallback(space, kAllocationActionAllocate, chunk_size);
516 }
566 517
567 MemoryChunk* result = MemoryChunk::Initialize(heap, 518 MemoryChunk* result = MemoryChunk::Initialize(heap,
568 base, 519 base,
569 committed_chunk_size, 520 chunk_size,
570 executable, 521 executable,
571 owner); 522 owner);
572 result->set_reserved_memory(&reservation); 523 result->set_reserved_memory(&reservation);
573 return result; 524 return result;
574 } 525 }
575 526
576 527
577 void MemoryAllocator::AllocationBookkeeping(Space* owner, 528 Page* MemoryAllocator::AllocatePage(PagedSpace* owner,
578 Address base,
579 intptr_t reserved_chunk_size,
580 intptr_t committed_chunk_size,
581 Executability executable) {
582 if (executable == EXECUTABLE) {
583 // Update executable memory size.
584 size_executable_ += reserved_chunk_size;
585 }
586
587 #ifdef DEBUG
588 ZapBlock(base, committed_chunk_size);
589 #endif
590 isolate_->counters()->memory_allocated()->
591 Increment(static_cast<int>(committed_chunk_size));
592
593 LOG(isolate_, NewEvent("MemoryChunk", base, committed_chunk_size));
594 if (owner != NULL) {
595 ObjectSpace space = static_cast<ObjectSpace>(1 << owner->identity());
596 PerformAllocationCallback(
597 space, kAllocationActionAllocate, committed_chunk_size);
598 }
599 }
600
601
602 Page* MemoryAllocator::AllocatePage(intptr_t committed_object_area_size,
603 PagedSpace* owner,
604 Executability executable) { 529 Executability executable) {
605 ASSERT(committed_object_area_size <= Page::kObjectAreaSize); 530 MemoryChunk* chunk = AllocateChunk(Page::kObjectAreaSize, executable, owner);
606
607 MemoryChunk* chunk = AllocateChunk(Page::kObjectAreaSize,
608 committed_object_area_size,
609 executable,
610 owner);
611 531
612 if (chunk == NULL) return NULL; 532 if (chunk == NULL) return NULL;
613 533
614 return Page::Initialize(isolate_->heap(), chunk, executable, owner); 534 return Page::Initialize(isolate_->heap(), chunk, executable, owner);
615 } 535 }
616 536
617 537
618 LargePage* MemoryAllocator::AllocateLargePage(intptr_t object_size, 538 LargePage* MemoryAllocator::AllocateLargePage(intptr_t object_size,
619 Executability executable, 539 Executability executable,
620 Space* owner) { 540 Space* owner) {
621 MemoryChunk* chunk = 541 MemoryChunk* chunk = AllocateChunk(object_size, executable, owner);
622 AllocateChunk(object_size, object_size, executable, owner);
623 if (chunk == NULL) return NULL; 542 if (chunk == NULL) return NULL;
624 return LargePage::Initialize(isolate_->heap(), chunk); 543 return LargePage::Initialize(isolate_->heap(), chunk);
625 } 544 }
626 545
627 546
628 void MemoryAllocator::Free(MemoryChunk* chunk) { 547 void MemoryAllocator::Free(MemoryChunk* chunk) {
629 LOG(isolate_, DeleteEvent("MemoryChunk", chunk)); 548 LOG(isolate_, DeleteEvent("MemoryChunk", chunk));
630 if (chunk->owner() != NULL) { 549 if (chunk->owner() != NULL) {
631 ObjectSpace space = 550 ObjectSpace space =
632 static_cast<ObjectSpace>(1 << chunk->owner()->identity()); 551 static_cast<ObjectSpace>(1 << chunk->owner()->identity());
633 PerformAllocationCallback(space, kAllocationActionFree, chunk->size()); 552 PerformAllocationCallback(space, kAllocationActionFree, chunk->size());
634 } 553 }
635 554
636 delete chunk->slots_buffer(); 555 delete chunk->slots_buffer();
637 delete chunk->skip_list(); 556 delete chunk->skip_list();
638 557
639 VirtualMemory* reservation = chunk->reserved_memory(); 558 VirtualMemory* reservation = chunk->reserved_memory();
640 if (reservation->IsReserved()) { 559 if (reservation->IsReserved()) {
641 FreeMemory(reservation, chunk->executable()); 560 FreeMemory(reservation, chunk->executable());
642 } else { 561 } else {
643 // When we do not have a reservation that is because this allocation
644 // is part of the huge reserved chunk of memory reserved for code on
645 // x64. In that case the size was rounded up to the page size on
646 // allocation so we do the same now when freeing.
647 FreeMemory(chunk->address(), 562 FreeMemory(chunk->address(),
648 RoundUp(chunk->size(), Page::kPageSize), 563 chunk->size(),
649 chunk->executable()); 564 chunk->executable());
650 } 565 }
651 } 566 }
652 567
653 568
654 bool MemoryAllocator::CommitBlock(Address start, 569 bool MemoryAllocator::CommitBlock(Address start,
655 size_t size, 570 size_t size,
656 Executability executable) { 571 Executability executable) {
657 if (!VirtualMemory::CommitRegion(start, size, executable)) return false; 572 if (!VirtualMemory::CommitRegion(start, size, executable)) return false;
658 #ifdef DEBUG 573 #ifdef DEBUG
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 memory_allocation_callbacks_.Remove(i); 633 memory_allocation_callbacks_.Remove(i);
719 return; 634 return;
720 } 635 }
721 } 636 }
722 UNREACHABLE(); 637 UNREACHABLE();
723 } 638 }
724 639
725 640
726 #ifdef DEBUG 641 #ifdef DEBUG
727 void MemoryAllocator::ReportStatistics() { 642 void MemoryAllocator::ReportStatistics() {
728 float pct = 643 float pct = static_cast<float>(capacity_ - size_) / capacity_;
729 static_cast<float>(capacity_ - memory_allocator_reserved_) / capacity_;
730 PrintF(" capacity: %" V8_PTR_PREFIX "d" 644 PrintF(" capacity: %" V8_PTR_PREFIX "d"
731 ", used: %" V8_PTR_PREFIX "d" 645 ", used: %" V8_PTR_PREFIX "d"
732 ", available: %%%d\n\n", 646 ", available: %%%d\n\n",
733 capacity_, memory_allocator_reserved_, static_cast<int>(pct*100)); 647 capacity_, size_, static_cast<int>(pct*100));
734 } 648 }
735 #endif 649 #endif
736 650
737 // ----------------------------------------------------------------------------- 651 // -----------------------------------------------------------------------------
738 // MemoryChunk implementation 652 // MemoryChunk implementation
739 653
740 void MemoryChunk::IncrementLiveBytesFromMutator(Address address, int by) { 654 void MemoryChunk::IncrementLiveBytesFromMutator(Address address, int by) {
741 MemoryChunk* chunk = MemoryChunk::FromAddress(address); 655 MemoryChunk* chunk = MemoryChunk::FromAddress(address);
742 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) { 656 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) {
743 static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by); 657 static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 Address next = cur + obj->Size(); 716 Address next = cur + obj->Size();
803 if ((cur <= addr) && (addr < next)) return obj; 717 if ((cur <= addr) && (addr < next)) return obj;
804 } 718 }
805 719
806 UNREACHABLE(); 720 UNREACHABLE();
807 return Failure::Exception(); 721 return Failure::Exception();
808 } 722 }
809 723
810 bool PagedSpace::CanExpand() { 724 bool PagedSpace::CanExpand() {
811 ASSERT(max_capacity_ % Page::kObjectAreaSize == 0); 725 ASSERT(max_capacity_ % Page::kObjectAreaSize == 0);
726 ASSERT(Capacity() % Page::kObjectAreaSize == 0);
812 727
813 if (Capacity() == max_capacity_) return false; 728 if (Capacity() == max_capacity_) return false;
814 729
815 ASSERT(Capacity() < max_capacity_); 730 ASSERT(Capacity() < max_capacity_);
816 731
817 // Are we going to exceed capacity for this space? 732 // Are we going to exceed capacity for this space?
818 if ((Capacity() + Page::kPageSize) > max_capacity_) return false; 733 if ((Capacity() + Page::kPageSize) > max_capacity_) return false;
819 734
820 return true; 735 return true;
821 } 736 }
822 737
823 bool PagedSpace::Expand(intptr_t size_in_bytes) { 738 bool PagedSpace::Expand() {
824 if (!CanExpand()) return false; 739 if (!CanExpand()) return false;
825 740
826 Page* last_page = anchor_.prev_page();
827 if (last_page != &anchor_) {
828 // We have run out of linear allocation space. This may be because the
829 // most recently allocated page (stored last in the list) is a small one,
830 // that starts on a page aligned boundary, but has not a full kPageSize of
831 // committed memory. Let's commit more memory for the page.
832 intptr_t reserved_page_size = last_page->reserved_memory()->IsReserved() ?
833 last_page->reserved_memory()->size() :
834 Page::kPageSize;
835 if (last_page->size() < reserved_page_size &&
836 (reserved_page_size - last_page->size()) >= size_in_bytes &&
837 !last_page->IsEvacuationCandidate() &&
838 last_page->WasSwept()) {
839 last_page->CommitMore(size_in_bytes);
840 return true;
841 }
842 }
843
844 // We initially only commit a part of the page, but the deserialization
845 // of the initial snapshot makes the assumption that it can deserialize
846 // into linear memory of a certain size per space, so some of the spaces
847 // need to have a little more committed memory.
848 int initial =
849 Max(OS::CommitPageSize(), static_cast<intptr_t>(Page::kGrowthUnit));
850
851 ASSERT(Page::kPageSize - initial < Page::kObjectAreaSize);
852
853 intptr_t expansion_size =
854 Max(initial,
855 RoundUpToPowerOf2(MemoryChunk::kObjectStartOffset + size_in_bytes)) -
856 MemoryChunk::kObjectStartOffset;
857
858 Page* p = heap()->isolate()->memory_allocator()-> 741 Page* p = heap()->isolate()->memory_allocator()->
859 AllocatePage(expansion_size, this, executable()); 742 AllocatePage(this, executable());
860 if (p == NULL) return false; 743 if (p == NULL) return false;
861 744
862 ASSERT(Capacity() <= max_capacity_); 745 ASSERT(Capacity() <= max_capacity_);
863 746
864 p->InsertAfter(anchor_.prev_page()); 747 p->InsertAfter(anchor_.prev_page());
865 748
866 return true; 749 return true;
867 } 750 }
868 751
869 752
(...skipping 24 matching lines...) Expand all
894 accounting_stats_.AllocateBytes(size); 777 accounting_stats_.AllocateBytes(size);
895 ASSERT_EQ(Page::kObjectAreaSize, static_cast<int>(size)); 778 ASSERT_EQ(Page::kObjectAreaSize, static_cast<int>(size));
896 } else { 779 } else {
897 DecreaseUnsweptFreeBytes(page); 780 DecreaseUnsweptFreeBytes(page);
898 } 781 }
899 782
900 if (Page::FromAllocationTop(allocation_info_.top) == page) { 783 if (Page::FromAllocationTop(allocation_info_.top) == page) {
901 allocation_info_.top = allocation_info_.limit = NULL; 784 allocation_info_.top = allocation_info_.limit = NULL;
902 } 785 }
903 786
904 intptr_t size = page->ObjectAreaEnd() - page->ObjectAreaStart();
905
906 page->Unlink(); 787 page->Unlink();
907 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) { 788 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) {
908 heap()->isolate()->memory_allocator()->Free(page); 789 heap()->isolate()->memory_allocator()->Free(page);
909 } else { 790 } else {
910 heap()->QueueMemoryChunkForFree(page); 791 heap()->QueueMemoryChunkForFree(page);
911 } 792 }
912 793
913 ASSERT(Capacity() > 0); 794 ASSERT(Capacity() > 0);
914 accounting_stats_.ShrinkSpace(size); 795 ASSERT(Capacity() % Page::kObjectAreaSize == 0);
796 accounting_stats_.ShrinkSpace(Page::kObjectAreaSize);
915 } 797 }
916 798
917 799
918 void PagedSpace::ReleaseAllUnusedPages() { 800 void PagedSpace::ReleaseAllUnusedPages() {
919 PageIterator it(this); 801 PageIterator it(this);
920 while (it.has_next()) { 802 while (it.has_next()) {
921 Page* page = it.next(); 803 Page* page = it.next();
922 if (!page->WasSwept()) { 804 if (!page->WasSwept()) {
923 if (page->LiveBytes() == 0) ReleasePage(page); 805 if (page->LiveBytes() == 0) ReleasePage(page);
924 } else { 806 } else {
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 // Free lists for old object spaces implementation 1664 // Free lists for old object spaces implementation
1783 1665
1784 void FreeListNode::set_size(Heap* heap, int size_in_bytes) { 1666 void FreeListNode::set_size(Heap* heap, int size_in_bytes) {
1785 ASSERT(size_in_bytes > 0); 1667 ASSERT(size_in_bytes > 0);
1786 ASSERT(IsAligned(size_in_bytes, kPointerSize)); 1668 ASSERT(IsAligned(size_in_bytes, kPointerSize));
1787 1669
1788 // We write a map and possibly size information to the block. If the block 1670 // We write a map and possibly size information to the block. If the block
1789 // is big enough to be a FreeSpace with at least one extra word (the next 1671 // is big enough to be a FreeSpace with at least one extra word (the next
1790 // pointer), we set its map to be the free space map and its size to an 1672 // pointer), we set its map to be the free space map and its size to an
1791 // appropriate array length for the desired size from HeapObject::Size(). 1673 // appropriate array length for the desired size from HeapObject::Size().
1792 // If the block is too small (e.g. one or two words), to hold both a size 1674 // If the block is too small (eg, one or two words), to hold both a size
1793 // field and a next pointer, we give it a filler map that gives it the 1675 // field and a next pointer, we give it a filler map that gives it the
1794 // correct size. 1676 // correct size.
1795 if (size_in_bytes > FreeSpace::kHeaderSize) { 1677 if (size_in_bytes > FreeSpace::kHeaderSize) {
1796 set_map_no_write_barrier(heap->raw_unchecked_free_space_map()); 1678 set_map_no_write_barrier(heap->raw_unchecked_free_space_map());
1797 // Can't use FreeSpace::cast because it fails during deserialization. 1679 // Can't use FreeSpace::cast because it fails during deserialization.
1798 FreeSpace* this_as_free_space = reinterpret_cast<FreeSpace*>(this); 1680 FreeSpace* this_as_free_space = reinterpret_cast<FreeSpace*>(this);
1799 this_as_free_space->set_size(size_in_bytes); 1681 this_as_free_space->set_size(size_in_bytes);
1800 } else if (size_in_bytes == kPointerSize) { 1682 } else if (size_in_bytes == kPointerSize) {
1801 set_map_no_write_barrier(heap->raw_unchecked_one_pointer_filler_map()); 1683 set_map_no_write_barrier(heap->raw_unchecked_one_pointer_filler_map());
1802 } else if (size_in_bytes == 2 * kPointerSize) { 1684 } else if (size_in_bytes == 2 * kPointerSize) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 } else { 1768 } else {
1887 node->set_next(huge_list_); 1769 node->set_next(huge_list_);
1888 huge_list_ = node; 1770 huge_list_ = node;
1889 } 1771 }
1890 available_ += size_in_bytes; 1772 available_ += size_in_bytes;
1891 ASSERT(IsVeryLong() || available_ == SumFreeLists()); 1773 ASSERT(IsVeryLong() || available_ == SumFreeLists());
1892 return 0; 1774 return 0;
1893 } 1775 }
1894 1776
1895 1777
1896 FreeListNode* FreeList::PickNodeFromList(FreeListNode** list, 1778 FreeListNode* FreeList::PickNodeFromList(FreeListNode** list, int* node_size) {
1897 int* node_size,
1898 int minimum_size) {
1899 FreeListNode* node = *list; 1779 FreeListNode* node = *list;
1900 1780
1901 if (node == NULL) return NULL; 1781 if (node == NULL) return NULL;
1902 1782
1903 ASSERT(node->map() == node->GetHeap()->raw_unchecked_free_space_map());
1904
1905 while (node != NULL && 1783 while (node != NULL &&
1906 Page::FromAddress(node->address())->IsEvacuationCandidate()) { 1784 Page::FromAddress(node->address())->IsEvacuationCandidate()) {
1907 available_ -= node->Size(); 1785 available_ -= node->Size();
1908 node = node->next(); 1786 node = node->next();
1909 } 1787 }
1910 1788
1911 if (node == NULL) { 1789 if (node != NULL) {
1790 *node_size = node->Size();
1791 *list = node->next();
1792 } else {
1912 *list = NULL; 1793 *list = NULL;
1913 return NULL;
1914 } 1794 }
1915 1795
1916 // Gets the size without checking the map. When we are booting we have
1917 // a FreeListNode before we have created its map.
1918 intptr_t size = reinterpret_cast<FreeSpace*>(node)->Size();
1919
1920 // We don't search the list for one that fits, preferring to look in the
1921 // list of larger nodes, but we do check the first in the list, because
1922 // if we had to expand the space or page we may have placed an entry that
1923 // was just long enough at the head of one of the lists.
1924 if (size < minimum_size) return NULL;
1925
1926 *node_size = size;
1927 available_ -= size;
1928 *list = node->next();
1929
1930 return node; 1796 return node;
1931 } 1797 }
1932 1798
1933 1799
1934 FreeListNode* FreeList::FindAbuttingNode( 1800 FreeListNode* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
1935 int size_in_bytes, int* node_size, Address limit, FreeListNode** list_head) {
1936 FreeListNode* first_node = *list_head;
1937 if (first_node != NULL &&
1938 first_node->address() == limit &&
1939 reinterpret_cast<FreeSpace*>(first_node)->Size() >= size_in_bytes &&
1940 !Page::FromAddress(first_node->address())->IsEvacuationCandidate()) {
1941 FreeListNode* answer = first_node;
1942 int size = reinterpret_cast<FreeSpace*>(first_node)->Size();
1943 available_ -= size;
1944 *node_size = size;
1945 *list_head = first_node->next();
1946 ASSERT(IsVeryLong() || available_ == SumFreeLists());
1947 return answer;
1948 }
1949 return NULL;
1950 }
1951
1952
1953 FreeListNode* FreeList::FindNodeFor(int size_in_bytes,
1954 int* node_size,
1955 Address limit) {
1956 FreeListNode* node = NULL; 1801 FreeListNode* node = NULL;
1957 1802
1958 if (limit != NULL) { 1803 if (size_in_bytes <= kSmallAllocationMax) {
1959 // We may have a memory area at the head of the free list, which abuts the 1804 node = PickNodeFromList(&small_list_, node_size);
1960 // old linear allocation area. This happens if the linear allocation area
1961 // has been shortened to allow an incremental marking step to be performed.
1962 // In that case we prefer to return the free memory area that is contiguous
1963 // with the old linear allocation area.
1964 node = FindAbuttingNode(size_in_bytes, node_size, limit, &large_list_);
1965 if (node != NULL) return node;
1966 node = FindAbuttingNode(size_in_bytes, node_size, limit, &huge_list_);
1967 if (node != NULL) return node; 1805 if (node != NULL) return node;
1968 } 1806 }
1969 1807
1970 node = PickNodeFromList(&small_list_, node_size, size_in_bytes); 1808 if (size_in_bytes <= kMediumAllocationMax) {
1971 ASSERT(IsVeryLong() || available_ == SumFreeLists()); 1809 node = PickNodeFromList(&medium_list_, node_size);
1972 if (node != NULL) return node;
1973
1974 node = PickNodeFromList(&medium_list_, node_size, size_in_bytes);
1975 ASSERT(IsVeryLong() || available_ == SumFreeLists());
1976 if (node != NULL) return node;
1977
1978 node = PickNodeFromList(&large_list_, node_size, size_in_bytes);
1979 ASSERT(IsVeryLong() || available_ == SumFreeLists());
1980 if (node != NULL) return node;
1981
1982 // The tricky third clause in this for statement is due to the fact that
1983 // PickNodeFromList can cut pages out of the list if they are unavailable for
1984 // new allocation (e.g. if they are on a page that has been scheduled for
1985 // evacuation).
1986 for (FreeListNode** cur = &huge_list_;
1987 *cur != NULL;
1988 cur = (*cur) == NULL ? cur : (*cur)->next_address()) {
1989 node = PickNodeFromList(cur, node_size, size_in_bytes);
1990 ASSERT(IsVeryLong() || available_ == SumFreeLists());
1991 if (node != NULL) return node; 1810 if (node != NULL) return node;
1992 } 1811 }
1993 1812
1813 if (size_in_bytes <= kLargeAllocationMax) {
1814 node = PickNodeFromList(&large_list_, node_size);
1815 if (node != NULL) return node;
1816 }
1817
1818 for (FreeListNode** cur = &huge_list_;
1819 *cur != NULL;
1820 cur = (*cur)->next_address()) {
1821 FreeListNode* cur_node = *cur;
1822 while (cur_node != NULL &&
1823 Page::FromAddress(cur_node->address())->IsEvacuationCandidate()) {
1824 available_ -= reinterpret_cast<FreeSpace*>(cur_node)->Size();
1825 cur_node = cur_node->next();
1826 }
1827
1828 *cur = cur_node;
1829 if (cur_node == NULL) break;
1830
1831 ASSERT((*cur)->map() == HEAP->raw_unchecked_free_space_map());
1832 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(*cur);
1833 int size = cur_as_free_space->Size();
1834 if (size >= size_in_bytes) {
1835 // Large enough node found. Unlink it from the list.
1836 node = *cur;
1837 *node_size = size;
1838 *cur = node->next();
1839 break;
1840 }
1841 }
1842
1994 return node; 1843 return node;
1995 } 1844 }
1996 1845
1997 1846
1998 // Allocation on the old space free list. If it succeeds then a new linear 1847 // Allocation on the old space free list. If it succeeds then a new linear
1999 // allocation space has been set up with the top and limit of the space. If 1848 // allocation space has been set up with the top and limit of the space. If
2000 // the allocation fails then NULL is returned, and the caller can perform a GC 1849 // the allocation fails then NULL is returned, and the caller can perform a GC
2001 // or allocate a new page before retrying. 1850 // or allocate a new page before retrying.
2002 HeapObject* FreeList::Allocate(int size_in_bytes) { 1851 HeapObject* FreeList::Allocate(int size_in_bytes) {
2003 ASSERT(0 < size_in_bytes); 1852 ASSERT(0 < size_in_bytes);
2004 ASSERT(size_in_bytes <= kMaxBlockSize); 1853 ASSERT(size_in_bytes <= kMaxBlockSize);
2005 ASSERT(IsAligned(size_in_bytes, kPointerSize)); 1854 ASSERT(IsAligned(size_in_bytes, kPointerSize));
2006 // Don't free list allocate if there is linear space available. 1855 // Don't free list allocate if there is linear space available.
2007 ASSERT(owner_->limit() - owner_->top() < size_in_bytes); 1856 ASSERT(owner_->limit() - owner_->top() < size_in_bytes);
2008 1857
2009 int new_node_size = 0; 1858 int new_node_size = 0;
2010 FreeListNode* new_node = 1859 FreeListNode* new_node = FindNodeFor(size_in_bytes, &new_node_size);
2011 FindNodeFor(size_in_bytes, &new_node_size, owner_->limit());
2012 if (new_node == NULL) return NULL; 1860 if (new_node == NULL) return NULL;
2013 1861
2014 if (new_node->address() == owner_->limit()) { 1862 available_ -= new_node_size;
2015 // The new freelist node we were given is an extension of the one we had
2016 // last. This is a common thing to happen when we extend a small page by
2017 // committing more memory. In this case we just add the new node to the
2018 // linear allocation area and recurse.
2019 owner_->Allocate(new_node_size);
2020 owner_->SetTop(owner_->top(), new_node->address() + new_node_size);
2021 MaybeObject* allocation = owner_->AllocateRaw(size_in_bytes);
2022 Object* answer;
2023 if (!allocation->ToObject(&answer)) return NULL;
2024 return HeapObject::cast(answer);
2025 }
2026
2027 ASSERT(IsVeryLong() || available_ == SumFreeLists()); 1863 ASSERT(IsVeryLong() || available_ == SumFreeLists());
2028 1864
2029 int bytes_left = new_node_size - size_in_bytes; 1865 int bytes_left = new_node_size - size_in_bytes;
2030 ASSERT(bytes_left >= 0); 1866 ASSERT(bytes_left >= 0);
2031 1867
2032 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); 1868 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top());
2033 // Mark the old linear allocation area with a free space map so it can be 1869 // Mark the old linear allocation area with a free space map so it can be
2034 // skipped when scanning the heap. This also puts it back in the free list 1870 // skipped when scanning the heap. This also puts it back in the free list
2035 // if it is big enough. 1871 // if it is big enough.
2036 if (old_linear_size != 0) { 1872 owner_->Free(owner_->top(), old_linear_size);
2037 owner_->AddToFreeLists(owner_->top(), old_linear_size);
2038 }
2039 1873
2040 #ifdef DEBUG 1874 #ifdef DEBUG
2041 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { 1875 for (int i = 0; i < size_in_bytes / kPointerSize; i++) {
2042 reinterpret_cast<Object**>(new_node->address())[i] = Smi::FromInt(0); 1876 reinterpret_cast<Object**>(new_node->address())[i] = Smi::FromInt(0);
2043 } 1877 }
2044 #endif 1878 #endif
2045 1879
2046 owner_->heap()->incremental_marking()->OldSpaceStep( 1880 owner_->heap()->incremental_marking()->OldSpaceStep(
2047 size_in_bytes - old_linear_size); 1881 size_in_bytes - old_linear_size);
2048 1882
2049 // The old-space-step might have finished sweeping and restarted marking. 1883 // The old-space-step might have finished sweeping and restarted marking.
2050 // Verify that it did not turn the page of the new node into an evacuation 1884 // Verify that it did not turn the page of the new node into an evacuation
2051 // candidate. 1885 // candidate.
2052 ASSERT(!MarkCompactCollector::IsOnEvacuationCandidate(new_node)); 1886 ASSERT(!MarkCompactCollector::IsOnEvacuationCandidate(new_node));
2053 1887
2054 const int kThreshold = IncrementalMarking::kAllocatedThreshold; 1888 const int kThreshold = IncrementalMarking::kAllocatedThreshold;
2055 1889
2056 // Memory in the linear allocation area is counted as allocated. We may free 1890 // Memory in the linear allocation area is counted as allocated. We may free
2057 // a little of this again immediately - see below. 1891 // a little of this again immediately - see below.
2058 owner_->Allocate(new_node_size); 1892 owner_->Allocate(new_node_size);
2059 1893
2060 if (bytes_left > kThreshold && 1894 if (bytes_left > kThreshold &&
2061 owner_->heap()->incremental_marking()->IsMarkingIncomplete() && 1895 owner_->heap()->incremental_marking()->IsMarkingIncomplete() &&
2062 FLAG_incremental_marking_steps) { 1896 FLAG_incremental_marking_steps) {
2063 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold); 1897 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold);
2064 // We don't want to give too large linear areas to the allocator while 1898 // We don't want to give too large linear areas to the allocator while
2065 // incremental marking is going on, because we won't check again whether 1899 // incremental marking is going on, because we won't check again whether
2066 // we want to do another increment until the linear area is used up. 1900 // we want to do another increment until the linear area is used up.
2067 owner_->AddToFreeLists(new_node->address() + size_in_bytes + linear_size, 1901 owner_->Free(new_node->address() + size_in_bytes + linear_size,
2068 new_node_size - size_in_bytes - linear_size); 1902 new_node_size - size_in_bytes - linear_size);
2069 owner_->SetTop(new_node->address() + size_in_bytes, 1903 owner_->SetTop(new_node->address() + size_in_bytes,
2070 new_node->address() + size_in_bytes + linear_size); 1904 new_node->address() + size_in_bytes + linear_size);
2071 } else if (bytes_left > 0) { 1905 } else if (bytes_left > 0) {
2072 // Normally we give the rest of the node to the allocator as its new 1906 // Normally we give the rest of the node to the allocator as its new
2073 // linear allocation area. 1907 // linear allocation area.
2074 owner_->SetTop(new_node->address() + size_in_bytes, 1908 owner_->SetTop(new_node->address() + size_in_bytes,
2075 new_node->address() + new_node_size); 1909 new_node->address() + new_node_size);
2076 } else { 1910 } else {
2077 ASSERT(bytes_left == 0);
2078 // TODO(gc) Try not freeing linear allocation region when bytes_left 1911 // TODO(gc) Try not freeing linear allocation region when bytes_left
2079 // are zero. 1912 // are zero.
2080 owner_->SetTop(NULL, NULL); 1913 owner_->SetTop(NULL, NULL);
2081 } 1914 }
2082 1915
2083 return new_node; 1916 return new_node;
2084 } 1917 }
2085 1918
2086 1919
2087 static intptr_t CountFreeListItemsInList(FreeListNode* n, Page* p) { 1920 static intptr_t CountFreeListItemsInList(FreeListNode* n, Page* p) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 // or because we have lowered the limit in order to get periodic incremental 2033 // or because we have lowered the limit in order to get periodic incremental
2201 // marking. The most reliable way to ensure that there is linear space is 2034 // marking. The most reliable way to ensure that there is linear space is
2202 // to do the allocation, then rewind the limit. 2035 // to do the allocation, then rewind the limit.
2203 ASSERT(bytes <= InitialCapacity()); 2036 ASSERT(bytes <= InitialCapacity());
2204 MaybeObject* maybe = AllocateRaw(bytes); 2037 MaybeObject* maybe = AllocateRaw(bytes);
2205 Object* object = NULL; 2038 Object* object = NULL;
2206 if (!maybe->ToObject(&object)) return false; 2039 if (!maybe->ToObject(&object)) return false;
2207 HeapObject* allocation = HeapObject::cast(object); 2040 HeapObject* allocation = HeapObject::cast(object);
2208 Address top = allocation_info_.top; 2041 Address top = allocation_info_.top;
2209 if ((top - bytes) == allocation->address()) { 2042 if ((top - bytes) == allocation->address()) {
2210 Address new_top = allocation->address(); 2043 allocation_info_.top = allocation->address();
2211 ASSERT(new_top >= Page::FromAddress(new_top - 1)->ObjectAreaStart());
2212 allocation_info_.top = new_top;
2213 return true; 2044 return true;
2214 } 2045 }
2215 // There may be a borderline case here where the allocation succeeded, but 2046 // There may be a borderline case here where the allocation succeeded, but
2216 // the limit and top have moved on to a new page. In that case we try again. 2047 // the limit and top have moved on to a new page. In that case we try again.
2217 return ReserveSpace(bytes); 2048 return ReserveSpace(bytes);
2218 } 2049 }
2219 2050
2220 2051
2221 void PagedSpace::PrepareForMarkCompact() { 2052 void PagedSpace::PrepareForMarkCompact() {
2222 // We don't have a linear allocation area while sweeping. It will be restored 2053 // We don't have a linear allocation area while sweeping. It will be restored
2223 // on the first allocation after the sweep. 2054 // on the first allocation after the sweep.
2224 // Mark the old linear allocation area with a free space map so it can be 2055 // Mark the old linear allocation area with a free space map so it can be
2225 // skipped when scanning the heap. 2056 // skipped when scanning the heap.
2226 int old_linear_size = static_cast<int>(limit() - top()); 2057 int old_linear_size = static_cast<int>(limit() - top());
2227 AddToFreeLists(top(), old_linear_size); 2058 Free(top(), old_linear_size);
2228 SetTop(NULL, NULL); 2059 SetTop(NULL, NULL);
2229 2060
2230 // Stop lazy sweeping and clear marking bits for unswept pages. 2061 // Stop lazy sweeping and clear marking bits for unswept pages.
2231 if (first_unswept_page_ != NULL) { 2062 if (first_unswept_page_ != NULL) {
2232 Page* p = first_unswept_page_; 2063 Page* p = first_unswept_page_;
2233 do { 2064 do {
2234 // Do not use ShouldBeSweptLazily predicate here. 2065 // Do not use ShouldBeSweptLazily predicate here.
2235 // New evacuation candidates were selected but they still have 2066 // New evacuation candidates were selected but they still have
2236 // to be swept before collection starts. 2067 // to be swept before collection starts.
2237 if (!p->WasSwept()) { 2068 if (!p->WasSwept()) {
(...skipping 22 matching lines...) Expand all
2260 if (new_top <= allocation_info_.limit) return true; 2091 if (new_top <= allocation_info_.limit) return true;
2261 2092
2262 HeapObject* new_area = free_list_.Allocate(size_in_bytes); 2093 HeapObject* new_area = free_list_.Allocate(size_in_bytes);
2263 if (new_area == NULL) new_area = SlowAllocateRaw(size_in_bytes); 2094 if (new_area == NULL) new_area = SlowAllocateRaw(size_in_bytes);
2264 if (new_area == NULL) return false; 2095 if (new_area == NULL) return false;
2265 2096
2266 int old_linear_size = static_cast<int>(limit() - top()); 2097 int old_linear_size = static_cast<int>(limit() - top());
2267 // Mark the old linear allocation area with a free space so it can be 2098 // Mark the old linear allocation area with a free space so it can be
2268 // skipped when scanning the heap. This also puts it back in the free list 2099 // skipped when scanning the heap. This also puts it back in the free list
2269 // if it is big enough. 2100 // if it is big enough.
2270 AddToFreeLists(top(), old_linear_size); 2101 Free(top(), old_linear_size);
2271 2102
2272 SetTop(new_area->address(), new_area->address() + size_in_bytes); 2103 SetTop(new_area->address(), new_area->address() + size_in_bytes);
2273 // The AddToFreeLists call above will reduce the size of the space in the 2104 Allocate(size_in_bytes);
2274 // allocation stats. We don't need to add this linear area to the size
2275 // with an Allocate(size_in_bytes) call here, because the
2276 // free_list_.Allocate() call above already accounted for this memory.
2277 return true; 2105 return true;
2278 } 2106 }
2279 2107
2280 2108
2281 // You have to call this last, since the implementation from PagedSpace 2109 // You have to call this last, since the implementation from PagedSpace
2282 // doesn't know that memory was 'promised' to large object space. 2110 // doesn't know that memory was 'promised' to large object space.
2283 bool LargeObjectSpace::ReserveSpace(int bytes) { 2111 bool LargeObjectSpace::ReserveSpace(int bytes) {
2284 return heap()->OldGenerationSpaceAvailable() >= bytes; 2112 return heap()->OldGenerationSpaceAvailable() >= bytes;
2285 } 2113 }
2286 2114
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2347 2175
2348 // Free list allocation failed and there is no next page. Fail if we have 2176 // Free list allocation failed and there is no next page. Fail if we have
2349 // hit the old generation size limit that should cause a garbage 2177 // hit the old generation size limit that should cause a garbage
2350 // collection. 2178 // collection.
2351 if (!heap()->always_allocate() && 2179 if (!heap()->always_allocate() &&
2352 heap()->OldGenerationAllocationLimitReached()) { 2180 heap()->OldGenerationAllocationLimitReached()) {
2353 return NULL; 2181 return NULL;
2354 } 2182 }
2355 2183
2356 // Try to expand the space and allocate in the new next page. 2184 // Try to expand the space and allocate in the new next page.
2357 if (Expand(size_in_bytes)) { 2185 if (Expand()) {
2358 return free_list_.Allocate(size_in_bytes); 2186 return free_list_.Allocate(size_in_bytes);
2359 } 2187 }
2360 2188
2361 // Last ditch, sweep all the remaining pages to try to find space. This may 2189 // Last ditch, sweep all the remaining pages to try to find space. This may
2362 // cause a pause. 2190 // cause a pause.
2363 if (!IsSweepingComplete()) { 2191 if (!IsSweepingComplete()) {
2364 AdvanceSweeper(kMaxInt); 2192 AdvanceSweeper(kMaxInt);
2365 2193
2366 // Retry the free list allocation. 2194 // Retry the free list allocation.
2367 HeapObject* object = free_list_.Allocate(size_in_bytes); 2195 HeapObject* object = free_list_.Allocate(size_in_bytes);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 if (previous == NULL) { 2536 if (previous == NULL) {
2709 first_page_ = current; 2537 first_page_ = current;
2710 } else { 2538 } else {
2711 previous->set_next_page(current); 2539 previous->set_next_page(current);
2712 } 2540 }
2713 2541
2714 // Free the chunk. 2542 // Free the chunk.
2715 heap()->mark_compact_collector()->ReportDeleteIfNeeded( 2543 heap()->mark_compact_collector()->ReportDeleteIfNeeded(
2716 object, heap()->isolate()); 2544 object, heap()->isolate());
2717 size_ -= static_cast<int>(page->size()); 2545 size_ -= static_cast<int>(page->size());
2718 ASSERT(size_ >= 0);
2719 objects_size_ -= object->Size(); 2546 objects_size_ -= object->Size();
2720 page_count_--; 2547 page_count_--;
2721 2548
2722 if (is_pointer_object) { 2549 if (is_pointer_object) {
2723 heap()->QueueMemoryChunkForFree(page); 2550 heap()->QueueMemoryChunkForFree(page);
2724 } else { 2551 } else {
2725 heap()->isolate()->memory_allocator()->Free(page); 2552 heap()->isolate()->memory_allocator()->Free(page);
2726 } 2553 }
2727 } 2554 }
2728 } 2555 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 object->ShortPrint(); 2674 object->ShortPrint();
2848 PrintF("\n"); 2675 PrintF("\n");
2849 } 2676 }
2850 printf(" --------------------------------------\n"); 2677 printf(" --------------------------------------\n");
2851 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 2678 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
2852 } 2679 }
2853 2680
2854 #endif // DEBUG 2681 #endif // DEBUG
2855 2682
2856 } } // namespace v8::internal 2683 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/spaces.h ('k') | src/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698