Chromium Code Reviews| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 gcs_since_last_deopt_(0), | 130 gcs_since_last_deopt_(0), |
| 131 allocation_sites_scratchpad_length_(0), | 131 allocation_sites_scratchpad_length_(0), |
| 132 ring_buffer_full_(false), | 132 ring_buffer_full_(false), |
| 133 ring_buffer_end_(0), | 133 ring_buffer_end_(0), |
| 134 promotion_queue_(this), | 134 promotion_queue_(this), |
| 135 configured_(false), | 135 configured_(false), |
| 136 current_gc_flags_(Heap::kNoGCFlags), | 136 current_gc_flags_(Heap::kNoGCFlags), |
| 137 current_gc_callback_flags_(GCCallbackFlags::kNoGCCallbackFlags), | 137 current_gc_callback_flags_(GCCallbackFlags::kNoGCCallbackFlags), |
| 138 external_string_table_(this), | 138 external_string_table_(this), |
| 139 chunks_queued_for_free_(NULL), | 139 chunks_queued_for_free_(NULL), |
| 140 pending_unmap_job_semaphore_(0), | 140 concurrent_unmaping_tasks_active_(0), |
| 141 pending_unmap_tasks_semaphore_(0), | |
| 141 gc_callbacks_depth_(0), | 142 gc_callbacks_depth_(0), |
| 142 deserialization_complete_(false), | 143 deserialization_complete_(false), |
| 143 concurrent_sweeping_enabled_(false), | 144 concurrent_sweeping_enabled_(false), |
| 144 strong_roots_list_(NULL) { | 145 strong_roots_list_(NULL) { |
| 145 // Allow build-time customization of the max semispace size. Building | 146 // Allow build-time customization of the max semispace size. Building |
| 146 // V8 with snapshots and a non-default max semispace size is much | 147 // V8 with snapshots and a non-default max semispace size is much |
| 147 // easier if you can define it as part of the build environment. | 148 // easier if you can define it as part of the build environment. |
| 148 #if defined(V8_MAX_SEMISPACE_SIZE) | 149 #if defined(V8_MAX_SEMISPACE_SIZE) |
| 149 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 150 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
| 150 #endif | 151 #endif |
| (...skipping 5602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5753 if (FLAG_verify_predictable) { | 5754 if (FLAG_verify_predictable) { |
| 5754 PrintAlloctionsHash(); | 5755 PrintAlloctionsHash(); |
| 5755 } | 5756 } |
| 5756 | 5757 |
| 5757 if (memory_reducer_ != nullptr) { | 5758 if (memory_reducer_ != nullptr) { |
| 5758 memory_reducer_->TearDown(); | 5759 memory_reducer_->TearDown(); |
| 5759 delete memory_reducer_; | 5760 delete memory_reducer_; |
| 5760 memory_reducer_ = nullptr; | 5761 memory_reducer_ = nullptr; |
| 5761 } | 5762 } |
| 5762 | 5763 |
| 5764 WaitUntilUnmappingOfFreeChunksCompleted(); | |
|
Hannes Payer (out of office)
2015/08/27 12:34:37
We should also wait when we tear down the heap.
| |
| 5765 | |
| 5763 TearDownArrayBuffers(); | 5766 TearDownArrayBuffers(); |
| 5764 | 5767 |
| 5765 isolate_->global_handles()->TearDown(); | 5768 isolate_->global_handles()->TearDown(); |
| 5766 | 5769 |
| 5767 external_string_table_.TearDown(); | 5770 external_string_table_.TearDown(); |
| 5768 | 5771 |
| 5769 mark_compact_collector()->TearDown(); | 5772 mark_compact_collector()->TearDown(); |
| 5770 | 5773 |
| 5771 delete tracer_; | 5774 delete tracer_; |
| 5772 tracer_ = nullptr; | 5775 tracer_ = nullptr; |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6517 class Heap::UnmapFreeMemoryTask : public v8::Task { | 6520 class Heap::UnmapFreeMemoryTask : public v8::Task { |
| 6518 public: | 6521 public: |
| 6519 UnmapFreeMemoryTask(Heap* heap, MemoryChunk* head) | 6522 UnmapFreeMemoryTask(Heap* heap, MemoryChunk* head) |
| 6520 : heap_(heap), head_(head) {} | 6523 : heap_(heap), head_(head) {} |
| 6521 virtual ~UnmapFreeMemoryTask() {} | 6524 virtual ~UnmapFreeMemoryTask() {} |
| 6522 | 6525 |
| 6523 private: | 6526 private: |
| 6524 // v8::Task overrides. | 6527 // v8::Task overrides. |
| 6525 void Run() override { | 6528 void Run() override { |
| 6526 heap_->FreeQueuedChunks(head_); | 6529 heap_->FreeQueuedChunks(head_); |
| 6527 heap_->pending_unmap_job_semaphore_.Signal(); | 6530 heap_->pending_unmap_tasks_semaphore_.Signal(); |
| 6528 } | 6531 } |
| 6529 | 6532 |
| 6530 Heap* heap_; | 6533 Heap* heap_; |
| 6531 MemoryChunk* head_; | 6534 MemoryChunk* head_; |
| 6532 | 6535 |
| 6533 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); | 6536 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); |
| 6534 }; | 6537 }; |
| 6535 | 6538 |
| 6536 | 6539 |
| 6537 void Heap::WaitUntilUnmappingOfFreeChunksCompleted() { | 6540 void Heap::WaitUntilUnmappingOfFreeChunksCompleted() { |
| 6538 // We start an unmap job after sweeping and after compaction. | 6541 // We start an unmap job after sweeping and after compaction. |
| 6539 pending_unmap_job_semaphore_.Wait(); | 6542 if (concurrent_unmaping_tasks_active_ > 0) { |
| 6540 pending_unmap_job_semaphore_.Wait(); | 6543 // There should be two concurrent unmapping tasks running. |
| 6544 DCHECK(concurrent_unmaping_tasks_active_ == 2); | |
| 6545 pending_unmap_tasks_semaphore_.Wait(); | |
| 6546 pending_unmap_tasks_semaphore_.Wait(); | |
| 6547 concurrent_unmaping_tasks_active_ = 0; | |
| 6548 } | |
| 6541 } | 6549 } |
| 6542 | 6550 |
| 6543 | 6551 |
| 6544 void Heap::QueueMemoryChunkForFree(MemoryChunk* chunk) { | 6552 void Heap::QueueMemoryChunkForFree(MemoryChunk* chunk) { |
| 6545 // PreFree logically frees the memory chunk. However, the actual freeing | 6553 // PreFree logically frees the memory chunk. However, the actual freeing |
| 6546 // will happen on a separate thread sometime later. | 6554 // will happen on a separate thread sometime later. |
| 6547 isolate_->memory_allocator()->PreFreeMemory(chunk); | 6555 isolate_->memory_allocator()->PreFreeMemory(chunk); |
| 6548 | 6556 |
| 6549 // The chunks added to this queue will be freed by a concurrent thread. | 6557 // The chunks added to this queue will be freed by a concurrent thread. |
| 6550 chunk->set_next_chunk(chunks_queued_for_free_); | 6558 chunk->set_next_chunk(chunks_queued_for_free_); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 6567 | 6575 |
| 6568 void Heap::FreeQueuedChunks() { | 6576 void Heap::FreeQueuedChunks() { |
| 6569 if (chunks_queued_for_free_ != NULL) { | 6577 if (chunks_queued_for_free_ != NULL) { |
| 6570 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 6578 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
| 6571 new UnmapFreeMemoryTask(this, chunks_queued_for_free_), | 6579 new UnmapFreeMemoryTask(this, chunks_queued_for_free_), |
| 6572 v8::Platform::kShortRunningTask); | 6580 v8::Platform::kShortRunningTask); |
| 6573 chunks_queued_for_free_ = NULL; | 6581 chunks_queued_for_free_ = NULL; |
| 6574 } else { | 6582 } else { |
| 6575 // If we do not have anything to unmap, we just signal the semaphore | 6583 // If we do not have anything to unmap, we just signal the semaphore |
| 6576 // that we are done. | 6584 // that we are done. |
| 6577 pending_unmap_job_semaphore_.Signal(); | 6585 pending_unmap_tasks_semaphore_.Signal(); |
| 6578 } | 6586 } |
| 6587 concurrent_unmaping_tasks_active_++; | |
| 6579 } | 6588 } |
| 6580 | 6589 |
| 6581 | 6590 |
| 6582 void Heap::FreeQueuedChunks(MemoryChunk* list_head) { | 6591 void Heap::FreeQueuedChunks(MemoryChunk* list_head) { |
| 6583 MemoryChunk* next; | 6592 MemoryChunk* next; |
| 6584 MemoryChunk* chunk; | 6593 MemoryChunk* chunk; |
| 6585 for (chunk = list_head; chunk != NULL; chunk = next) { | 6594 for (chunk = list_head; chunk != NULL; chunk = next) { |
| 6586 next = chunk->next_chunk(); | 6595 next = chunk->next_chunk(); |
| 6587 isolate_->memory_allocator()->PerformFreeMemory(chunk); | 6596 isolate_->memory_allocator()->PerformFreeMemory(chunk); |
| 6588 } | 6597 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6782 *object_type = "CODE_TYPE"; \ | 6791 *object_type = "CODE_TYPE"; \ |
| 6783 *object_sub_type = "CODE_AGE/" #name; \ | 6792 *object_sub_type = "CODE_AGE/" #name; \ |
| 6784 return true; | 6793 return true; |
| 6785 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6794 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
| 6786 #undef COMPARE_AND_RETURN_NAME | 6795 #undef COMPARE_AND_RETURN_NAME |
| 6787 } | 6796 } |
| 6788 return false; | 6797 return false; |
| 6789 } | 6798 } |
| 6790 } // namespace internal | 6799 } // namespace internal |
| 6791 } // namespace v8 | 6800 } // namespace v8 |
| OLD | NEW |