| 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/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ring_buffer_end_(0), | 156 ring_buffer_end_(0), |
| 157 promotion_queue_(this), | 157 promotion_queue_(this), |
| 158 configured_(false), | 158 configured_(false), |
| 159 current_gc_flags_(Heap::kNoGCFlags), | 159 current_gc_flags_(Heap::kNoGCFlags), |
| 160 current_gc_callback_flags_(GCCallbackFlags::kNoGCCallbackFlags), | 160 current_gc_callback_flags_(GCCallbackFlags::kNoGCCallbackFlags), |
| 161 external_string_table_(this), | 161 external_string_table_(this), |
| 162 gc_callbacks_depth_(0), | 162 gc_callbacks_depth_(0), |
| 163 deserialization_complete_(false), | 163 deserialization_complete_(false), |
| 164 strong_roots_list_(NULL), | 164 strong_roots_list_(NULL), |
| 165 heap_iterator_depth_(0), | 165 heap_iterator_depth_(0), |
| 166 force_oom_(false) { | 166 force_oom_(false), |
| 167 array_buffer_tracker_(nullptr) { |
| 167 // Allow build-time customization of the max semispace size. Building | 168 // Allow build-time customization of the max semispace size. Building |
| 168 // V8 with snapshots and a non-default max semispace size is much | 169 // V8 with snapshots and a non-default max semispace size is much |
| 169 // easier if you can define it as part of the build environment. | 170 // easier if you can define it as part of the build environment. |
| 170 #if defined(V8_MAX_SEMISPACE_SIZE) | 171 #if defined(V8_MAX_SEMISPACE_SIZE) |
| 171 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 172 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
| 172 #endif | 173 #endif |
| 173 | 174 |
| 174 // Ensure old_generation_size_ is a multiple of kPageSize. | 175 // Ensure old_generation_size_ is a multiple of kPageSize. |
| 175 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0); | 176 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0); |
| 176 | 177 |
| (...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1710 incremental_marking()->UpdateMarkingDequeAfterScavenge(); | 1711 incremental_marking()->UpdateMarkingDequeAfterScavenge(); |
| 1711 | 1712 |
| 1712 ScavengeWeakObjectRetainer weak_object_retainer(this); | 1713 ScavengeWeakObjectRetainer weak_object_retainer(this); |
| 1713 ProcessYoungWeakReferences(&weak_object_retainer); | 1714 ProcessYoungWeakReferences(&weak_object_retainer); |
| 1714 | 1715 |
| 1715 DCHECK(new_space_front == new_space_.top()); | 1716 DCHECK(new_space_front == new_space_.top()); |
| 1716 | 1717 |
| 1717 // Set age mark. | 1718 // Set age mark. |
| 1718 new_space_.set_age_mark(new_space_.top()); | 1719 new_space_.set_age_mark(new_space_.top()); |
| 1719 | 1720 |
| 1720 ArrayBufferTracker::FreeDeadInNewSpace(this); | 1721 array_buffer_tracker()->FreeDeadInNewSpace(this); |
| 1721 | 1722 |
| 1722 // Update how much has survived scavenge. | 1723 // Update how much has survived scavenge. |
| 1723 IncrementYoungSurvivorsCounter(static_cast<int>( | 1724 IncrementYoungSurvivorsCounter(static_cast<int>( |
| 1724 (PromotedSpaceSizeOfObjects() - survived_watermark) + new_space_.Size())); | 1725 (PromotedSpaceSizeOfObjects() - survived_watermark) + new_space_.Size())); |
| 1725 | 1726 |
| 1726 LOG(isolate_, ResourceEvent("scavenge", "end")); | 1727 LOG(isolate_, ResourceEvent("scavenge", "end")); |
| 1727 | 1728 |
| 1728 gc_state_ = NOT_IN_GC; | 1729 gc_state_ = NOT_IN_GC; |
| 1729 } | 1730 } |
| 1730 | 1731 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 return object; | 1997 return object; |
| 1997 } | 1998 } |
| 1998 | 1999 |
| 1999 | 2000 |
| 2000 HeapObject* Heap::DoubleAlignForDeserialization(HeapObject* object, int size) { | 2001 HeapObject* Heap::DoubleAlignForDeserialization(HeapObject* object, int size) { |
| 2001 return AlignWithFiller(object, size - kPointerSize, size, kDoubleAligned); | 2002 return AlignWithFiller(object, size - kPointerSize, size, kDoubleAligned); |
| 2002 } | 2003 } |
| 2003 | 2004 |
| 2004 | 2005 |
| 2005 void Heap::RegisterNewArrayBuffer(JSArrayBuffer* buffer) { | 2006 void Heap::RegisterNewArrayBuffer(JSArrayBuffer* buffer) { |
| 2006 ArrayBufferTracker::RegisterNew(this, buffer); | 2007 array_buffer_tracker()->RegisterNew(this, buffer); |
| 2007 } | 2008 } |
| 2008 | 2009 |
| 2009 | 2010 |
| 2010 void Heap::UnregisterArrayBuffer(JSArrayBuffer* buffer) { | 2011 void Heap::UnregisterArrayBuffer(JSArrayBuffer* buffer) { |
| 2011 ArrayBufferTracker::Unregister(this, buffer); | 2012 array_buffer_tracker()->Unregister(this, buffer); |
| 2012 } | 2013 } |
| 2013 | 2014 |
| 2014 | 2015 |
| 2015 void Heap::ConfigureInitialOldGenerationSize() { | 2016 void Heap::ConfigureInitialOldGenerationSize() { |
| 2016 if (!old_generation_size_configured_ && tracer()->SurvivalEventsRecorded()) { | 2017 if (!old_generation_size_configured_ && tracer()->SurvivalEventsRecorded()) { |
| 2017 old_generation_allocation_limit_ = | 2018 old_generation_allocation_limit_ = |
| 2018 Max(kMinimumOldGenerationAllocationLimit, | 2019 Max(kMinimumOldGenerationAllocationLimit, |
| 2019 static_cast<intptr_t>( | 2020 static_cast<intptr_t>( |
| 2020 static_cast<double>(old_generation_allocation_limit_) * | 2021 static_cast<double>(old_generation_allocation_limit_) * |
| 2021 (tracer()->AverageSurvivalRatio() / 100))); | 2022 (tracer()->AverageSurvivalRatio() / 100))); |
| (...skipping 3328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5350 LOG(isolate_, IntPtrTEvent("heap-available", Available())); | 5351 LOG(isolate_, IntPtrTEvent("heap-available", Available())); |
| 5351 | 5352 |
| 5352 store_buffer()->SetUp(); | 5353 store_buffer()->SetUp(); |
| 5353 | 5354 |
| 5354 mark_compact_collector()->SetUp(); | 5355 mark_compact_collector()->SetUp(); |
| 5355 | 5356 |
| 5356 idle_scavenge_observer_ = new IdleScavengeObserver( | 5357 idle_scavenge_observer_ = new IdleScavengeObserver( |
| 5357 *this, ScavengeJob::kBytesAllocatedBeforeNextIdleTask); | 5358 *this, ScavengeJob::kBytesAllocatedBeforeNextIdleTask); |
| 5358 new_space()->AddAllocationObserver(idle_scavenge_observer_); | 5359 new_space()->AddAllocationObserver(idle_scavenge_observer_); |
| 5359 | 5360 |
| 5361 array_buffer_tracker_ = new ArrayBufferTracker(this); |
| 5362 |
| 5360 return true; | 5363 return true; |
| 5361 } | 5364 } |
| 5362 | 5365 |
| 5363 | 5366 |
| 5364 bool Heap::CreateHeapObjects() { | 5367 bool Heap::CreateHeapObjects() { |
| 5365 // Create initial maps. | 5368 // Create initial maps. |
| 5366 if (!CreateInitialMaps()) return false; | 5369 if (!CreateInitialMaps()) return false; |
| 5367 CreateApiObjects(); | 5370 CreateApiObjects(); |
| 5368 | 5371 |
| 5369 // Create initial objects | 5372 // Create initial objects |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5550 StrongRootsList* next = NULL; | 5553 StrongRootsList* next = NULL; |
| 5551 for (StrongRootsList* list = strong_roots_list_; list; list = next) { | 5554 for (StrongRootsList* list = strong_roots_list_; list; list = next) { |
| 5552 next = list->next; | 5555 next = list->next; |
| 5553 delete list; | 5556 delete list; |
| 5554 } | 5557 } |
| 5555 strong_roots_list_ = NULL; | 5558 strong_roots_list_ = NULL; |
| 5556 | 5559 |
| 5557 delete store_buffer_; | 5560 delete store_buffer_; |
| 5558 store_buffer_ = nullptr; | 5561 store_buffer_ = nullptr; |
| 5559 | 5562 |
| 5563 delete array_buffer_tracker_; |
| 5564 array_buffer_tracker_ = nullptr; |
| 5565 |
| 5560 delete memory_allocator_; | 5566 delete memory_allocator_; |
| 5561 memory_allocator_ = nullptr; | 5567 memory_allocator_ = nullptr; |
| 5562 } | 5568 } |
| 5563 | 5569 |
| 5564 | 5570 |
| 5565 void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback, | 5571 void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback, |
| 5566 GCType gc_type, bool pass_isolate) { | 5572 GCType gc_type, bool pass_isolate) { |
| 5567 DCHECK(callback != NULL); | 5573 DCHECK(callback != NULL); |
| 5568 GCCallbackPair pair(callback, gc_type, pass_isolate); | 5574 GCCallbackPair pair(callback, gc_type, pass_isolate); |
| 5569 DCHECK(!gc_prologue_callbacks_.Contains(pair)); | 5575 DCHECK(!gc_prologue_callbacks_.Contains(pair)); |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6460 } | 6466 } |
| 6461 | 6467 |
| 6462 | 6468 |
| 6463 // static | 6469 // static |
| 6464 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6470 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6465 return StaticVisitorBase::GetVisitorId(map); | 6471 return StaticVisitorBase::GetVisitorId(map); |
| 6466 } | 6472 } |
| 6467 | 6473 |
| 6468 } // namespace internal | 6474 } // namespace internal |
| 6469 } // namespace v8 | 6475 } // namespace v8 |
| OLD | NEW |