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

Side by Side Diff: src/heap/mark-compact.h

Issue 2454723002: Reland "[heap] Uncommit marking deque in concurrent task." (Closed)
Patch Set: one more ce fix Created 4 years, 1 month 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/cancelable-task.cc ('k') | src/heap/mark-compact.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_MARK_COMPACT_H_ 5 #ifndef V8_HEAP_MARK_COMPACT_H_
6 #define V8_HEAP_MARK_COMPACT_H_ 6 #define V8_HEAP_MARK_COMPACT_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
11 #include "src/base/platform/condition-variable.h"
12 #include "src/cancelable-task.h"
11 #include "src/heap/marking.h" 13 #include "src/heap/marking.h"
12 #include "src/heap/spaces.h" 14 #include "src/heap/spaces.h"
13 #include "src/heap/store-buffer.h" 15 #include "src/heap/store-buffer.h"
14 16
15 namespace v8 { 17 namespace v8 {
16 namespace internal { 18 namespace internal {
17 19
18 // Callback function, returns whether an object is alive. The heap size 20 // Callback function, returns whether an object is alive. The heap size
19 // of the object is returned in size. It optionally updates the offset 21 // of the object is returned in size. It optionally updates the offset
20 // to the first live object in the page (only used for old and map objects). 22 // to the first live object in the page (only used for old and map objects).
(...skipping 24 matching lines...) Expand all
45 } 47 }
46 48
47 private: 49 private:
48 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking); 50 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking);
49 }; 51 };
50 52
51 // ---------------------------------------------------------------------------- 53 // ----------------------------------------------------------------------------
52 // Marking deque for tracing live objects. 54 // Marking deque for tracing live objects.
53 class MarkingDeque { 55 class MarkingDeque {
54 public: 56 public:
55 MarkingDeque() 57 explicit MarkingDeque(Heap* heap)
56 : backing_store_(nullptr), 58 : backing_store_(nullptr),
57 backing_store_committed_size_(0), 59 backing_store_committed_size_(0),
58 array_(nullptr), 60 array_(nullptr),
59 top_(0), 61 top_(0),
60 bottom_(0), 62 bottom_(0),
61 mask_(0), 63 mask_(0),
62 overflowed_(false), 64 overflowed_(false),
63 in_use_(false) {} 65 in_use_(false),
66 uncommit_task_pending_(false),
67 uncommit_task_id_(0),
68 heap_(heap) {}
64 69
65 void SetUp(); 70 void SetUp();
66 void TearDown(); 71 void TearDown();
67 72
73 // Ensures that the marking deque is committed and will stay committed until
74 // StopUsing() is called.
68 void StartUsing(); 75 void StartUsing();
69 void StopUsing(); 76 void StopUsing();
70 void Clear(); 77 void Clear();
71 78
72 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } 79 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; }
73 80
74 inline bool IsEmpty() { return top_ == bottom_; } 81 inline bool IsEmpty() { return top_ == bottom_; }
75 82
76 bool overflowed() const { return overflowed_; } 83 bool overflowed() const { return overflowed_; }
77 84
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 122 }
116 } 123 }
117 124
118 HeapObject** array() { return array_; } 125 HeapObject** array() { return array_; }
119 int bottom() { return bottom_; } 126 int bottom() { return bottom_; }
120 int top() { return top_; } 127 int top() { return top_; }
121 int mask() { return mask_; } 128 int mask() { return mask_; }
122 void set_top(int top) { top_ = top; } 129 void set_top(int top) { top_ = top; }
123 130
124 private: 131 private:
132 // This task uncommits the marking_deque backing store if
133 // markin_deque->in_use_ is false.
134 class UncommitTask : public CancelableTask {
135 public:
136 explicit UncommitTask(Isolate* isolate, MarkingDeque* marking_deque)
137 : CancelableTask(isolate), marking_deque_(marking_deque) {}
138
139 private:
140 // CancelableTask override.
141 void RunInternal() override {
142 base::LockGuard<base::Mutex> guard(&marking_deque_->mutex_);
143 if (!marking_deque_->in_use_) {
144 marking_deque_->Uncommit();
145 }
146 marking_deque_->uncommit_task_pending_ = false;
147 marking_deque_->uncommit_task_barrier_.NotifyOne();
148 }
149
150 MarkingDeque* marking_deque_;
151 DISALLOW_COPY_AND_ASSIGN(UncommitTask);
152 };
153
125 static const size_t kMaxSize = 4 * MB; 154 static const size_t kMaxSize = 4 * MB;
126 static const size_t kMinSize = 256 * KB; 155 static const size_t kMinSize = 256 * KB;
127 156
157 // Must be called with mutex lock.
128 void EnsureCommitted(); 158 void EnsureCommitted();
159
160 // Must be called with mutex lock.
129 void Uncommit(); 161 void Uncommit();
130 162
163 // Must be called with mutex lock.
164 void StartUncommitTask();
165
166 void CancelOrWaitForUncommitTask();
167
168 base::Mutex mutex_;
169 base::ConditionVariable uncommit_task_barrier_;
170
131 base::VirtualMemory* backing_store_; 171 base::VirtualMemory* backing_store_;
132 size_t backing_store_committed_size_; 172 size_t backing_store_committed_size_;
133 HeapObject** array_; 173 HeapObject** array_;
134 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is 174 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is
135 // empty when top_ == bottom_. It is full when top_ + 1 == bottom 175 // empty when top_ == bottom_. It is full when top_ + 1 == bottom
136 // (mod mask + 1). 176 // (mod mask + 1).
137 int top_; 177 int top_;
138 int bottom_; 178 int bottom_;
139 int mask_; 179 int mask_;
140 bool overflowed_; 180 bool overflowed_;
181 // in_use_ == true after taking mutex lock implies that the marking deque is
182 // committed and will stay committed at least until in_use_ == false.
141 bool in_use_; 183 bool in_use_;
184 bool uncommit_task_pending_;
185 uint32_t uncommit_task_id_;
186 Heap* heap_;
142 187
143 DISALLOW_COPY_AND_ASSIGN(MarkingDeque); 188 DISALLOW_COPY_AND_ASSIGN(MarkingDeque);
144 }; 189 };
145 190
146 191
147 // CodeFlusher collects candidates for code flushing during marking and 192 // CodeFlusher collects candidates for code flushing during marking and
148 // processes those candidates after marking has completed in order to 193 // processes those candidates after marking has completed in order to
149 // reset those functions referencing code objects that would otherwise 194 // reset those functions referencing code objects that would otherwise
150 // be unreachable. Code objects can be referenced in two ways: 195 // be unreachable. Code objects can be referenced in two ways:
151 // - SharedFunctionInfo references unoptimized code. 196 // - SharedFunctionInfo references unoptimized code.
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 775
731 private: 776 private:
732 MarkCompactCollector* collector_; 777 MarkCompactCollector* collector_;
733 }; 778 };
734 779
735 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); 780 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space);
736 } // namespace internal 781 } // namespace internal
737 } // namespace v8 782 } // namespace v8
738 783
739 #endif // V8_HEAP_MARK_COMPACT_H_ 784 #endif // V8_HEAP_MARK_COMPACT_H_
OLDNEW
« no previous file with comments | « src/cancelable-task.cc ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698