OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 705 |
706 intptr_t estimated_release = 0; | 706 intptr_t estimated_release = 0; |
707 | 707 |
708 Candidate candidates[kMaxMaxEvacuationCandidates]; | 708 Candidate candidates[kMaxMaxEvacuationCandidates]; |
709 | 709 |
710 max_evacuation_candidates = | 710 max_evacuation_candidates = |
711 Min(kMaxMaxEvacuationCandidates, max_evacuation_candidates); | 711 Min(kMaxMaxEvacuationCandidates, max_evacuation_candidates); |
712 | 712 |
713 int count = 0; | 713 int count = 0; |
714 int fragmentation = 0; | 714 int fragmentation = 0; |
715 int page_number = 0; | |
716 Candidate* least = NULL; | 715 Candidate* least = NULL; |
717 | 716 |
718 PageIterator it(space); | 717 PageIterator it(space); |
719 while (it.has_next()) { | 718 while (it.has_next()) { |
720 Page* p = it.next(); | 719 Page* p = it.next(); |
721 if (p->NeverEvacuate()) continue; | 720 if (p->NeverEvacuate()) continue; |
722 | 721 |
723 // Invariant: Evacuation candidates are just created when marking is | 722 // Invariant: Evacuation candidates are just created when marking is |
724 // started. At the end of a GC all evacuation candidates are cleared and | 723 // started. At the end of a GC all evacuation candidates are cleared and |
725 // their slot buffers are released. | 724 // their slot buffers are released. |
726 CHECK(!p->IsEvacuationCandidate()); | 725 CHECK(!p->IsEvacuationCandidate()); |
727 CHECK(p->slots_buffer() == NULL); | 726 CHECK(p->slots_buffer() == NULL); |
728 | 727 |
729 if (FLAG_stress_compaction) { | 728 if (FLAG_stress_compaction) { |
730 if (FLAG_manual_evacuation_candidates_selection) { | 729 unsigned int counter = space->heap()->ms_count(); |
731 if (p->IsFlagSet(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING)) { | 730 uintptr_t page_number = reinterpret_cast<uintptr_t>(p) >> kPageSizeBits; |
732 p->ClearFlag(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING); | 731 if ((counter & 1) == (page_number & 1)) fragmentation = 1; |
733 fragmentation = 1; | |
734 } | |
735 } else { | |
736 unsigned int counter = space->heap()->ms_count(); | |
737 if ((counter & 1) == (page_number & 1)) fragmentation = 1; | |
738 page_number++; | |
739 } | |
740 } else if (mode == REDUCE_MEMORY_FOOTPRINT) { | 732 } else if (mode == REDUCE_MEMORY_FOOTPRINT) { |
741 // Don't try to release too many pages. | 733 // Don't try to release too many pages. |
742 if (estimated_release >= over_reserved) { | 734 if (estimated_release >= over_reserved) { |
743 continue; | 735 continue; |
744 } | 736 } |
745 | 737 |
746 intptr_t free_bytes = 0; | 738 intptr_t free_bytes = 0; |
747 | 739 |
748 if (!p->WasSwept()) { | 740 if (!p->WasSwept()) { |
749 free_bytes = (p->area_size() - p->LiveBytes()); | 741 free_bytes = (p->area_size() - p->LiveBytes()); |
(...skipping 3613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4363 buffer = allocator->AllocateBuffer(buffer); | 4355 buffer = allocator->AllocateBuffer(buffer); |
4364 *buffer_address = buffer; | 4356 *buffer_address = buffer; |
4365 } | 4357 } |
4366 DCHECK(buffer->HasSpaceForTypedSlot()); | 4358 DCHECK(buffer->HasSpaceForTypedSlot()); |
4367 buffer->Add(reinterpret_cast<ObjectSlot>(type)); | 4359 buffer->Add(reinterpret_cast<ObjectSlot>(type)); |
4368 buffer->Add(reinterpret_cast<ObjectSlot>(addr)); | 4360 buffer->Add(reinterpret_cast<ObjectSlot>(addr)); |
4369 return true; | 4361 return true; |
4370 } | 4362 } |
4371 | 4363 |
4372 | 4364 |
4373 static Object* g_smi_slot = NULL; | |
4374 | |
4375 | |
4376 void SlotsBuffer::RemoveSlot(SlotsBuffer* buffer, ObjectSlot slot_to_remove) { | |
4377 DCHECK_EQ(Smi::FromInt(0), g_smi_slot); | |
4378 DCHECK(!IsTypedSlot(slot_to_remove)); | |
4379 while (buffer != NULL) { | |
4380 ObjectSlot* slots = buffer->slots_; | |
4381 // Remove entries by replacing them with a dummy slot containing a smi. | |
4382 std::replace(&slots[0], &slots[buffer->idx_], slot_to_remove, &g_smi_slot); | |
4383 buffer = buffer->next_; | |
4384 } | |
4385 } | |
4386 | |
4387 | |
4388 static inline SlotsBuffer::SlotType SlotTypeForRMode(RelocInfo::Mode rmode) { | 4365 static inline SlotsBuffer::SlotType SlotTypeForRMode(RelocInfo::Mode rmode) { |
4389 if (RelocInfo::IsCodeTarget(rmode)) { | 4366 if (RelocInfo::IsCodeTarget(rmode)) { |
4390 return SlotsBuffer::CODE_TARGET_SLOT; | 4367 return SlotsBuffer::CODE_TARGET_SLOT; |
4391 } else if (RelocInfo::IsEmbeddedObject(rmode)) { | 4368 } else if (RelocInfo::IsEmbeddedObject(rmode)) { |
4392 return SlotsBuffer::EMBEDDED_OBJECT_SLOT; | 4369 return SlotsBuffer::EMBEDDED_OBJECT_SLOT; |
4393 } else if (RelocInfo::IsDebugBreakSlot(rmode)) { | 4370 } else if (RelocInfo::IsDebugBreakSlot(rmode)) { |
4394 return SlotsBuffer::DEBUG_TARGET_SLOT; | 4371 return SlotsBuffer::DEBUG_TARGET_SLOT; |
4395 } else if (RelocInfo::IsJSReturn(rmode)) { | 4372 } else if (RelocInfo::IsJSReturn(rmode)) { |
4396 return SlotsBuffer::JS_RETURN_SLOT; | 4373 return SlotsBuffer::JS_RETURN_SLOT; |
4397 } | 4374 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4519 SlotsBuffer* buffer = *buffer_address; | 4496 SlotsBuffer* buffer = *buffer_address; |
4520 while (buffer != NULL) { | 4497 while (buffer != NULL) { |
4521 SlotsBuffer* next_buffer = buffer->next(); | 4498 SlotsBuffer* next_buffer = buffer->next(); |
4522 DeallocateBuffer(buffer); | 4499 DeallocateBuffer(buffer); |
4523 buffer = next_buffer; | 4500 buffer = next_buffer; |
4524 } | 4501 } |
4525 *buffer_address = NULL; | 4502 *buffer_address = NULL; |
4526 } | 4503 } |
4527 } | 4504 } |
4528 } // namespace v8::internal | 4505 } // namespace v8::internal |
OLD | NEW |