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/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 old_generation_size_at_last_gc_(0), | 128 old_generation_size_at_last_gc_(0), |
129 gcs_since_last_deopt_(0), | 129 gcs_since_last_deopt_(0), |
130 allocation_sites_scratchpad_length_(0), | 130 allocation_sites_scratchpad_length_(0), |
131 ring_buffer_full_(false), | 131 ring_buffer_full_(false), |
132 ring_buffer_end_(0), | 132 ring_buffer_end_(0), |
133 promotion_queue_(this), | 133 promotion_queue_(this), |
134 configured_(false), | 134 configured_(false), |
135 current_gc_flags_(Heap::kNoGCFlags), | 135 current_gc_flags_(Heap::kNoGCFlags), |
136 external_string_table_(this), | 136 external_string_table_(this), |
137 chunks_queued_for_free_(NULL), | 137 chunks_queued_for_free_(NULL), |
138 pending_unmap_job_semaphore_(0), | |
138 gc_callbacks_depth_(0), | 139 gc_callbacks_depth_(0), |
139 deserialization_complete_(false), | 140 deserialization_complete_(false), |
140 concurrent_sweeping_enabled_(false), | 141 concurrent_sweeping_enabled_(false), |
141 strong_roots_list_(NULL) { | 142 strong_roots_list_(NULL) { |
142 // Allow build-time customization of the max semispace size. Building | 143 // Allow build-time customization of the max semispace size. Building |
143 // V8 with snapshots and a non-default max semispace size is much | 144 // V8 with snapshots and a non-default max semispace size is much |
144 // easier if you can define it as part of the build environment. | 145 // easier if you can define it as part of the build environment. |
145 #if defined(V8_MAX_SEMISPACE_SIZE) | 146 #if defined(V8_MAX_SEMISPACE_SIZE) |
146 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 147 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
147 #endif | 148 #endif |
(...skipping 6359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6507 heap_->FinalizeExternalString(ExternalString::cast(new_space_strings_[i])); | 6508 heap_->FinalizeExternalString(ExternalString::cast(new_space_strings_[i])); |
6508 } | 6509 } |
6509 new_space_strings_.Free(); | 6510 new_space_strings_.Free(); |
6510 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6511 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6511 heap_->FinalizeExternalString(ExternalString::cast(old_space_strings_[i])); | 6512 heap_->FinalizeExternalString(ExternalString::cast(old_space_strings_[i])); |
6512 } | 6513 } |
6513 old_space_strings_.Free(); | 6514 old_space_strings_.Free(); |
6514 } | 6515 } |
6515 | 6516 |
6516 | 6517 |
6518 class Heap::UnmapFreeMemoryTask : public v8::Task { | |
6519 public: | |
6520 UnmapFreeMemoryTask(Heap* heap, MemoryChunk* head) | |
6521 : heap_(heap), head_(head) {} | |
6522 virtual ~UnmapFreeMemoryTask() {} | |
6523 | |
6524 private: | |
6525 // v8::Task overrides. | |
6526 void Run() override { | |
6527 heap_->FreeQueuedChunks(head_); | |
6528 heap_->pending_unmap_job_semaphore_.Signal(); | |
6529 } | |
6530 | |
6531 Heap* heap_; | |
6532 MemoryChunk* head_; | |
6533 | |
6534 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); | |
6535 }; | |
6536 | |
6537 | |
6538 void Heap::WaitUntilUnmappingOfFreeChunksCompleted() { | |
6539 // We start an unmap job after sweeping and after compaction. | |
6540 pending_unmap_job_semaphore_.Wait(); | |
6541 pending_unmap_job_semaphore_.Wait(); | |
6542 } | |
6543 | |
6544 | |
6517 void Heap::QueueMemoryChunkForFree(MemoryChunk* chunk) { | 6545 void Heap::QueueMemoryChunkForFree(MemoryChunk* chunk) { |
6546 // PreFree logically frees the memory chunk. However, the actual freeing | |
6547 // will happen on a separate thread sometime later. | |
6548 isolate_->memory_allocator()->PreFreeMemory(chunk); | |
6549 | |
6550 // The chunks added to this queue will be freed by a concurrent thread. | |
6518 chunk->set_next_chunk(chunks_queued_for_free_); | 6551 chunk->set_next_chunk(chunks_queued_for_free_); |
6519 chunks_queued_for_free_ = chunk; | 6552 chunks_queued_for_free_ = chunk; |
6520 } | 6553 } |
6521 | 6554 |
6522 | 6555 |
6523 void Heap::FilterStoreBufferEntriesOnAboutToBeFreedPages() { | 6556 void Heap::FilterStoreBufferEntriesOnAboutToBeFreedPages() { |
6524 if (chunks_queued_for_free_ == NULL) return; | 6557 if (chunks_queued_for_free_ == NULL) return; |
6525 MemoryChunk* next; | 6558 MemoryChunk* next; |
6526 MemoryChunk* chunk; | 6559 MemoryChunk* chunk; |
6527 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6560 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6528 next = chunk->next_chunk(); | 6561 next = chunk->next_chunk(); |
6529 chunk->SetFlag(MemoryChunk::ABOUT_TO_BE_FREED); | 6562 chunk->SetFlag(MemoryChunk::ABOUT_TO_BE_FREED); |
6530 } | 6563 } |
6531 isolate_->heap()->store_buffer()->Compact(); | 6564 store_buffer()->Compact(); |
6532 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6565 store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6533 } | 6566 } |
6534 | 6567 |
6535 | 6568 |
6536 void Heap::FreeQueuedChunks() { | 6569 void Heap::FreeQueuedChunks() { |
6537 MemoryChunk* next; | 6570 if (chunks_queued_for_free_ != NULL) { |
6538 MemoryChunk* chunk; | 6571 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
6539 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6572 new UnmapFreeMemoryTask(this, chunks_queued_for_free_), |
6540 next = chunk->next_chunk(); | 6573 v8::Platform::kShortRunningTask); |
6541 isolate_->memory_allocator()->Free(chunk); | 6574 chunks_queued_for_free_ = NULL; |
6575 } else { | |
6576 // If we do not have anything to unmap, we just signal the semaphore | |
6577 // that we are done. | |
6578 pending_unmap_job_semaphore_.Signal(); | |
6542 } | 6579 } |
6543 chunks_queued_for_free_ = NULL; | |
6544 } | 6580 } |
6545 | 6581 |
6546 | 6582 |
6583 void Heap::FreeQueuedChunks(MemoryChunk* list_head) { | |
Michael Lippautz
2015/08/24 13:43:12
This is a candidate for a static on {MemoryChunk}?
| |
6584 MemoryChunk* next; | |
6585 MemoryChunk* chunk; | |
6586 for (chunk = list_head; chunk != NULL; chunk = next) { | |
6587 next = chunk->next_chunk(); | |
6588 isolate_->memory_allocator()->PerformFreeMemory(chunk); | |
6589 } | |
6590 } | |
6591 | |
6592 | |
6547 void Heap::RememberUnmappedPage(Address page, bool compacted) { | 6593 void Heap::RememberUnmappedPage(Address page, bool compacted) { |
6548 uintptr_t p = reinterpret_cast<uintptr_t>(page); | 6594 uintptr_t p = reinterpret_cast<uintptr_t>(page); |
6549 // Tag the page pointer to make it findable in the dump file. | 6595 // Tag the page pointer to make it findable in the dump file. |
6550 if (compacted) { | 6596 if (compacted) { |
6551 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. | 6597 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. |
6552 } else { | 6598 } else { |
6553 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died. | 6599 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died. |
6554 } | 6600 } |
6555 remembered_unmapped_pages_[remembered_unmapped_pages_index_] = | 6601 remembered_unmapped_pages_[remembered_unmapped_pages_index_] = |
6556 reinterpret_cast<Address>(p); | 6602 reinterpret_cast<Address>(p); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6737 *object_type = "CODE_TYPE"; \ | 6783 *object_type = "CODE_TYPE"; \ |
6738 *object_sub_type = "CODE_AGE/" #name; \ | 6784 *object_sub_type = "CODE_AGE/" #name; \ |
6739 return true; | 6785 return true; |
6740 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6786 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
6741 #undef COMPARE_AND_RETURN_NAME | 6787 #undef COMPARE_AND_RETURN_NAME |
6742 } | 6788 } |
6743 return false; | 6789 return false; |
6744 } | 6790 } |
6745 } // namespace internal | 6791 } // namespace internal |
6746 } // namespace v8 | 6792 } // namespace v8 |
OLD | NEW |