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

Side by Side Diff: src/heap/heap.h

Issue 1813963002: Add memory pressure notification API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add tests, address comments Created 4 years, 9 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
OLDNEW
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 #ifndef V8_HEAP_HEAP_H_ 5 #ifndef V8_HEAP_HEAP_H_
6 #define V8_HEAP_HEAP_H_ 6 #define V8_HEAP_HEAP_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 10
11 // Clients of this interface shouldn't depend on lots of heap internals. 11 // Clients of this interface shouldn't depend on lots of heap internals.
12 // Do not include anything from src/heap here! 12 // Do not include anything from src/heap here!
13 #include "include/v8.h"
13 #include "src/allocation.h" 14 #include "src/allocation.h"
14 #include "src/assert-scope.h" 15 #include "src/assert-scope.h"
15 #include "src/atomic-utils.h" 16 #include "src/atomic-utils.h"
16 #include "src/globals.h" 17 #include "src/globals.h"
17 #include "src/heap-symbols.h" 18 #include "src/heap-symbols.h"
18 // TODO(mstarzinger): Two more includes to kill! 19 // TODO(mstarzinger): Two more includes to kill!
19 #include "src/heap/spaces.h" 20 #include "src/heap/spaces.h"
20 #include "src/heap/store-buffer.h" 21 #include "src/heap/store-buffer.h"
21 #include "src/list.h" 22 #include "src/list.h"
22 23
23 namespace v8 { 24 namespace v8 {
24 namespace internal { 25 namespace internal {
25 26
27 using v8::MemoryPressureLevel;
28
26 // Defines all the roots in Heap. 29 // Defines all the roots in Heap.
27 #define STRONG_ROOT_LIST(V) \ 30 #define STRONG_ROOT_LIST(V) \
28 V(Map, byte_array_map, ByteArrayMap) \ 31 V(Map, byte_array_map, ByteArrayMap) \
29 V(Map, free_space_map, FreeSpaceMap) \ 32 V(Map, free_space_map, FreeSpaceMap) \
30 V(Map, one_pointer_filler_map, OnePointerFillerMap) \ 33 V(Map, one_pointer_filler_map, OnePointerFillerMap) \
31 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ 34 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \
32 /* Cluster the most popular ones in a few cache lines here at the top. */ \ 35 /* Cluster the most popular ones in a few cache lines here at the top. */ \
33 V(Smi, store_buffer_top, StoreBufferTop) \ 36 V(Smi, store_buffer_top, StoreBufferTop) \
34 V(Oddball, undefined_value, UndefinedValue) \ 37 V(Oddball, undefined_value, UndefinedValue) \
35 V(Oddball, the_hole_value, TheHoleValue) \ 38 V(Oddball, the_hole_value, TheHoleValue) \
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // 732 //
730 // Support for the API. 733 // Support for the API.
731 // 734 //
732 735
733 void CreateApiObjects(); 736 void CreateApiObjects();
734 737
735 // Implements the corresponding V8 API function. 738 // Implements the corresponding V8 API function.
736 bool IdleNotification(double deadline_in_seconds); 739 bool IdleNotification(double deadline_in_seconds);
737 bool IdleNotification(int idle_time_in_ms); 740 bool IdleNotification(int idle_time_in_ms);
738 741
742 void MemoryPressureNotification(MemoryPressureLevel level,
743 bool is_isolate_locked);
744
739 double MonotonicallyIncreasingTimeInMs(); 745 double MonotonicallyIncreasingTimeInMs();
740 746
741 void RecordStats(HeapStats* stats, bool take_snapshot = false); 747 void RecordStats(HeapStats* stats, bool take_snapshot = false);
742 748
743 // Check new space expansion criteria and expand semispaces if it was hit. 749 // Check new space expansion criteria and expand semispaces if it was hit.
744 void CheckNewSpaceExpansionCriteria(); 750 void CheckNewSpaceExpansionCriteria();
745 751
746 inline bool HeapIsFullEnoughToStartIncrementalMarking(intptr_t limit) { 752 inline bool HeapIsFullEnoughToStartIncrementalMarking(intptr_t limit) {
747 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true; 753 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true;
748 754
749 intptr_t adjusted_allocation_limit = limit - new_space_.Capacity(); 755 intptr_t adjusted_allocation_limit = limit - new_space_.Capacity();
750 756
751 if (PromotedTotalSize() >= adjusted_allocation_limit) return true; 757 if (PromotedTotalSize() >= adjusted_allocation_limit) return true;
752 758
759 if (memory_pressure_level_.Value() != MemoryPressureLevel::kNone)
760 return true;
761
753 return false; 762 return false;
754 } 763 }
755 764
756 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); 765 void VisitExternalResources(v8::ExternalResourceVisitor* visitor);
757 766
758 // An object should be promoted if the object has survived a 767 // An object should be promoted if the object has survived a
759 // scavenge operation. 768 // scavenge operation.
760 inline bool ShouldBePromoted(Address old_address, int object_size); 769 inline bool ShouldBePromoted(Address old_address, int object_size);
761 770
762 void ClearNormalizedMapCaches(); 771 void ClearNormalizedMapCaches();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 int size_in_bytes); 835 int size_in_bytes);
827 836
828 bool deserialization_complete() const { return deserialization_complete_; } 837 bool deserialization_complete() const { return deserialization_complete_; }
829 838
830 bool HasLowAllocationRate(); 839 bool HasLowAllocationRate();
831 bool HasHighFragmentation(); 840 bool HasHighFragmentation();
832 bool HasHighFragmentation(intptr_t used, intptr_t committed); 841 bool HasHighFragmentation(intptr_t used, intptr_t committed);
833 842
834 void SetOptimizeForLatency() { optimize_for_memory_usage_ = false; } 843 void SetOptimizeForLatency() { optimize_for_memory_usage_ = false; }
835 void SetOptimizeForMemoryUsage(); 844 void SetOptimizeForMemoryUsage();
836 bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; } 845 bool ShouldOptimizeForMemoryUsage() {
846 return optimize_for_memory_usage_ ||
847 memory_pressure_level_.Value() != MemoryPressureLevel::kNone;
848 }
837 849
838 // =========================================================================== 850 // ===========================================================================
839 // Initialization. =========================================================== 851 // Initialization. ===========================================================
840 // =========================================================================== 852 // ===========================================================================
841 853
842 // Configure heap size in MB before setup. Return false if the heap has been 854 // Configure heap size in MB before setup. Return false if the heap has been
843 // set up already. 855 // set up already.
844 bool ConfigureHeap(int max_semi_space_size, int max_old_space_size, 856 bool ConfigureHeap(int max_semi_space_size, int max_old_space_size,
845 int max_executable_size, size_t code_range_size); 857 int max_executable_size, size_t code_range_size);
846 bool ConfigureHeapDefault(); 858 bool ConfigureHeapDefault();
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 // scavenge since last new space expansion. 2001 // scavenge since last new space expansion.
1990 intptr_t survived_since_last_expansion_; 2002 intptr_t survived_since_last_expansion_;
1991 2003
1992 // ... and since the last scavenge. 2004 // ... and since the last scavenge.
1993 intptr_t survived_last_scavenge_; 2005 intptr_t survived_last_scavenge_;
1994 2006
1995 // This is not the depth of nested AlwaysAllocateScope's but rather a single 2007 // This is not the depth of nested AlwaysAllocateScope's but rather a single
1996 // count, as scopes can be acquired from multiple tasks (read: threads). 2008 // count, as scopes can be acquired from multiple tasks (read: threads).
1997 AtomicNumber<size_t> always_allocate_scope_count_; 2009 AtomicNumber<size_t> always_allocate_scope_count_;
1998 2010
2011 AtomicValue<MemoryPressureLevel> memory_pressure_level_;
Hannes Payer (out of office) 2016/03/18 13:27:26 For completeness, add a comment to describe that f
ulan 2016/03/18 16:10:00 Done.
2012
1999 // For keeping track of context disposals. 2013 // For keeping track of context disposals.
2000 int contexts_disposed_; 2014 int contexts_disposed_;
2001 2015
2002 // The length of the retained_maps array at the time of context disposal. 2016 // The length of the retained_maps array at the time of context disposal.
2003 // This separates maps in the retained_maps array that were created before 2017 // This separates maps in the retained_maps array that were created before
2004 // and after context disposal. 2018 // and after context disposal.
2005 int number_of_disposed_maps_; 2019 int number_of_disposed_maps_;
2006 2020
2007 int global_ic_age_; 2021 int global_ic_age_;
2008 2022
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 friend class LargeObjectSpace; 2648 friend class LargeObjectSpace;
2635 friend class NewSpace; 2649 friend class NewSpace;
2636 friend class PagedSpace; 2650 friend class PagedSpace;
2637 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); 2651 DISALLOW_COPY_AND_ASSIGN(AllocationObserver);
2638 }; 2652 };
2639 2653
2640 } // namespace internal 2654 } // namespace internal
2641 } // namespace v8 2655 } // namespace v8
2642 2656
2643 #endif // V8_HEAP_HEAP_H_ 2657 #endif // V8_HEAP_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698