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

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: GC interrupt on kModerate to start incremental marking 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
« no previous file with comments | « src/api.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 // 736 //
734 // Support for the API. 737 // Support for the API.
735 // 738 //
736 739
737 void CreateApiObjects(); 740 void CreateApiObjects();
738 741
739 // Implements the corresponding V8 API function. 742 // Implements the corresponding V8 API function.
740 bool IdleNotification(double deadline_in_seconds); 743 bool IdleNotification(double deadline_in_seconds);
741 bool IdleNotification(int idle_time_in_ms); 744 bool IdleNotification(int idle_time_in_ms);
742 745
746 void MemoryPressureNotification(MemoryPressureLevel level,
747 bool is_isolate_locked);
748 void CheckMemoryPressure();
749
743 double MonotonicallyIncreasingTimeInMs(); 750 double MonotonicallyIncreasingTimeInMs();
744 751
745 void RecordStats(HeapStats* stats, bool take_snapshot = false); 752 void RecordStats(HeapStats* stats, bool take_snapshot = false);
746 753
747 // Check new space expansion criteria and expand semispaces if it was hit. 754 // Check new space expansion criteria and expand semispaces if it was hit.
748 void CheckNewSpaceExpansionCriteria(); 755 void CheckNewSpaceExpansionCriteria();
749 756
750 inline bool HeapIsFullEnoughToStartIncrementalMarking(intptr_t limit) { 757 inline bool HeapIsFullEnoughToStartIncrementalMarking(intptr_t limit) {
751 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true; 758 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true;
752 759
753 intptr_t adjusted_allocation_limit = limit - new_space_.Capacity(); 760 intptr_t adjusted_allocation_limit = limit - new_space_.Capacity();
754 761
755 if (PromotedTotalSize() >= adjusted_allocation_limit) return true; 762 if (PromotedTotalSize() >= adjusted_allocation_limit) return true;
756 763
764 if (HighMemoryPressure()) return true;
765
757 return false; 766 return false;
758 } 767 }
759 768
760 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); 769 void VisitExternalResources(v8::ExternalResourceVisitor* visitor);
761 770
762 // An object should be promoted if the object has survived a 771 // An object should be promoted if the object has survived a
763 // scavenge operation. 772 // scavenge operation.
764 inline bool ShouldBePromoted(Address old_address, int object_size); 773 inline bool ShouldBePromoted(Address old_address, int object_size);
765 774
766 void ClearNormalizedMapCaches(); 775 void ClearNormalizedMapCaches();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 int size_in_bytes); 839 int size_in_bytes);
831 840
832 bool deserialization_complete() const { return deserialization_complete_; } 841 bool deserialization_complete() const { return deserialization_complete_; }
833 842
834 bool HasLowAllocationRate(); 843 bool HasLowAllocationRate();
835 bool HasHighFragmentation(); 844 bool HasHighFragmentation();
836 bool HasHighFragmentation(intptr_t used, intptr_t committed); 845 bool HasHighFragmentation(intptr_t used, intptr_t committed);
837 846
838 void SetOptimizeForLatency() { optimize_for_memory_usage_ = false; } 847 void SetOptimizeForLatency() { optimize_for_memory_usage_ = false; }
839 void SetOptimizeForMemoryUsage(); 848 void SetOptimizeForMemoryUsage();
840 bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; } 849 bool ShouldOptimizeForMemoryUsage() {
850 return optimize_for_memory_usage_ || HighMemoryPressure();
851 }
852 bool HighMemoryPressure() {
853 return memory_pressure_level_.Value() != MemoryPressureLevel::kNone;
854 }
841 855
842 // =========================================================================== 856 // ===========================================================================
843 // Initialization. =========================================================== 857 // Initialization. ===========================================================
844 // =========================================================================== 858 // ===========================================================================
845 859
846 // Configure heap size in MB before setup. Return false if the heap has been 860 // Configure heap size in MB before setup. Return false if the heap has been
847 // set up already. 861 // set up already.
848 bool ConfigureHeap(int max_semi_space_size, int max_old_space_size, 862 bool ConfigureHeap(int max_semi_space_size, int max_old_space_size,
849 int max_executable_size, size_t code_range_size); 863 int max_executable_size, size_t code_range_size);
850 bool ConfigureHeapDefault(); 864 bool ConfigureHeapDefault();
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 1641
1628 inline void UpdateAllocationsHash(HeapObject* object); 1642 inline void UpdateAllocationsHash(HeapObject* object);
1629 inline void UpdateAllocationsHash(uint32_t value); 1643 inline void UpdateAllocationsHash(uint32_t value);
1630 void PrintAlloctionsHash(); 1644 void PrintAlloctionsHash();
1631 1645
1632 void AddToRingBuffer(const char* string); 1646 void AddToRingBuffer(const char* string);
1633 void GetFromRingBuffer(char* buffer); 1647 void GetFromRingBuffer(char* buffer);
1634 1648
1635 void CompactRetainedMaps(ArrayList* retained_maps); 1649 void CompactRetainedMaps(ArrayList* retained_maps);
1636 1650
1651 void CollectGarbageOnMemoryPressure(const char* source);
1652
1637 // Attempt to over-approximate the weak closure by marking object groups and 1653 // Attempt to over-approximate the weak closure by marking object groups and
1638 // implicit references from global handles, but don't atomically complete 1654 // implicit references from global handles, but don't atomically complete
1639 // marking. If we continue to mark incrementally, we might have marked 1655 // marking. If we continue to mark incrementally, we might have marked
1640 // objects that die later. 1656 // objects that die later.
1641 void FinalizeIncrementalMarking(const char* gc_reason); 1657 void FinalizeIncrementalMarking(const char* gc_reason);
1642 1658
1643 // Returns the timer used for a given GC type. 1659 // Returns the timer used for a given GC type.
1644 // - GCScavenger: young generation GC 1660 // - GCScavenger: young generation GC
1645 // - GCCompactor: full GC 1661 // - GCCompactor: full GC
1646 // - GCFinalzeMC: finalization of incremental full GC 1662 // - GCFinalzeMC: finalization of incremental full GC
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 // scavenge since last new space expansion. 2009 // scavenge since last new space expansion.
1994 intptr_t survived_since_last_expansion_; 2010 intptr_t survived_since_last_expansion_;
1995 2011
1996 // ... and since the last scavenge. 2012 // ... and since the last scavenge.
1997 intptr_t survived_last_scavenge_; 2013 intptr_t survived_last_scavenge_;
1998 2014
1999 // This is not the depth of nested AlwaysAllocateScope's but rather a single 2015 // This is not the depth of nested AlwaysAllocateScope's but rather a single
2000 // count, as scopes can be acquired from multiple tasks (read: threads). 2016 // count, as scopes can be acquired from multiple tasks (read: threads).
2001 AtomicNumber<size_t> always_allocate_scope_count_; 2017 AtomicNumber<size_t> always_allocate_scope_count_;
2002 2018
2019 // Stores the memory pressure level that set by MemoryPressureNotification
2020 // and reset by a mark-compact garbage collection.
2021 AtomicValue<MemoryPressureLevel> memory_pressure_level_;
2022
2003 // For keeping track of context disposals. 2023 // For keeping track of context disposals.
2004 int contexts_disposed_; 2024 int contexts_disposed_;
2005 2025
2006 // The length of the retained_maps array at the time of context disposal. 2026 // The length of the retained_maps array at the time of context disposal.
2007 // This separates maps in the retained_maps array that were created before 2027 // This separates maps in the retained_maps array that were created before
2008 // and after context disposal. 2028 // and after context disposal.
2009 int number_of_disposed_maps_; 2029 int number_of_disposed_maps_;
2010 2030
2011 int global_ic_age_; 2031 int global_ic_age_;
2012 2032
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 friend class LargeObjectSpace; 2658 friend class LargeObjectSpace;
2639 friend class NewSpace; 2659 friend class NewSpace;
2640 friend class PagedSpace; 2660 friend class PagedSpace;
2641 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); 2661 DISALLOW_COPY_AND_ASSIGN(AllocationObserver);
2642 }; 2662 };
2643 2663
2644 } // namespace internal 2664 } // namespace internal
2645 } // namespace v8 2665 } // namespace v8
2646 2666
2647 #endif // V8_HEAP_HEAP_H_ 2667 #endif // V8_HEAP_HEAP_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698