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

Side by Side Diff: runtime/vm/scavenger.h

Issue 2951333002: Moves the top_ and end_ words of the Scavenger into mutator thread. (Closed)
Patch Set: Adds and uses function that checks if mutator is scheduled in GC Created 3 years, 5 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_SCAVENGER_H_ 5 #ifndef RUNTIME_VM_SCAVENGER_H_
6 #define RUNTIME_VM_SCAVENGER_H_ 6 #define RUNTIME_VM_SCAVENGER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ~Scavenger(); 116 ~Scavenger();
117 117
118 // Check whether this Scavenger contains this address. 118 // Check whether this Scavenger contains this address.
119 // During scavenging both the to and from spaces contain "legal" objects. 119 // During scavenging both the to and from spaces contain "legal" objects.
120 // During a scavenge this function only returns true for addresses that will 120 // During a scavenge this function only returns true for addresses that will
121 // be part of the surviving objects. 121 // be part of the surviving objects.
122 bool Contains(uword addr) const { return to_->Contains(addr); } 122 bool Contains(uword addr) const { return to_->Contains(addr); }
123 123
124 RawObject* FindObject(FindObjectVisitor* visitor) const; 124 RawObject* FindObject(FindObjectVisitor* visitor) const;
125 125
126 uword TryAllocate(intptr_t size) { 126 uword TryAllocate(intptr_t size) { return TryAllocateGC(size); }
rmacnak 2017/07/12 20:30:06 Dead code, remove.
danunez 2017/07/12 21:02:12 Done.
127
128 uword TryAllocateGC(intptr_t size) {
rmacnak 2017/07/12 20:30:06 No "Try". Allocation during a scavenge always succ
danunez 2017/07/12 21:02:12 Done.
127 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 129 ASSERT(Utils::IsAligned(size, kObjectAlignment));
128 ASSERT(heap_ != Dart::vm_isolate()->heap()); 130 ASSERT(heap_ != Dart::vm_isolate()->heap());
131
129 #if defined(DEBUG) 132 #if defined(DEBUG)
130 if (FLAG_gc_at_alloc && !scavenging_) { 133 if (FLAG_gc_at_alloc && !scavenging_) {
rmacnak 2017/07/12 20:30:06 Remove, this is always called during a GC. ASSERT
danunez 2017/07/12 21:02:12 Done.
131 Scavenge(); 134 Scavenge();
132 } 135 }
133 #endif 136 #endif
134 uword result = top_; 137 uword result = top_;
135 intptr_t remaining = end_ - top_; 138 intptr_t remaining = end_ - top_;
136 if (remaining < size) { 139 if (remaining < size) {
rmacnak 2017/07/12 20:30:06 ASSERT(size <= remaining);
danunez 2017/07/12 21:02:12 Done.
137 return 0; 140 return 0;
138 } 141 }
139 ASSERT(to_->Contains(result)); 142 ASSERT(to_->Contains(result));
140 ASSERT((result & kObjectAlignmentMask) == object_alignment_); 143 ASSERT((result & kObjectAlignmentMask) == object_alignment_);
141
142 top_ += size; 144 top_ += size;
143 ASSERT(to_->Contains(top_) || (top_ == to_->end())); 145 ASSERT(to_->Contains(top_) || (top_ == to_->end()));
144 return result; 146 return result;
145 } 147 }
146 148
149 uword TryAllocateInTLAB(Thread* thread, intptr_t size) {
150 ASSERT(Utils::IsAligned(size, kObjectAlignment));
151 ASSERT(heap_ != Dart::vm_isolate()->heap());
152 ASSERT(thread->IsMutatorThread());
153 ASSERT(thread->heap() == heap_);
154 #if defined(DEBUG)
155 if (FLAG_gc_at_alloc && !scavenging_) {
156 Scavenge();
157 }
158 #endif
159 uword top = thread->top();
160 uword end = thread->end();
161 uword result = top;
162 intptr_t remaining = end - top;
163 if (remaining < size) {
164 return 0;
165 }
166 ASSERT(to_->Contains(result));
167 ASSERT((result & kObjectAlignmentMask) == object_alignment_);
168 top += size;
169 ASSERT(to_->Contains(top) || (top == to_->end()));
170 thread->set_top(top);
171 return result;
172 }
173
147 // Collect the garbage in this scavenger. 174 // Collect the garbage in this scavenger.
148 void Scavenge(); 175 void Scavenge();
149 void Scavenge(bool invoke_api_callbacks); 176 void Scavenge(bool invoke_api_callbacks);
150 177
151 // Promote all live objects. 178 // Promote all live objects.
152 void Evacuate(); 179 void Evacuate();
153 180
154 // Accessors to generate code for inlined allocation. 181 uword top() { return top_; }
155 uword* TopAddress() { return &top_; } 182 uword end() { return end_; }
156 uword* EndAddress() { return &end_; } 183
157 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } 184 void set_top(uword value) { top_ = value; }
158 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } 185 void set_end(uword value) {
186 ASSERT(to_->end() == value);
187 end_ = value;
188 }
159 189
160 int64_t UsedInWords() const { 190 int64_t UsedInWords() const {
161 return (top_ - FirstObjectStart()) >> kWordSizeLog2; 191 return (top_ - FirstObjectStart()) >> kWordSizeLog2;
162 } 192 }
163 int64_t CapacityInWords() const { return to_->size_in_words(); } 193 int64_t CapacityInWords() const { return to_->size_in_words(); }
164 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; } 194 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; }
165 SpaceUsage GetCurrentUsage() const { 195 SpaceUsage GetCurrentUsage() const {
166 SpaceUsage usage; 196 SpaceUsage usage;
167 usage.used_in_words = UsedInWords(); 197 usage.used_in_words = UsedInWords();
168 usage.capacity_in_words = CapacityInWords(); 198 usage.capacity_in_words = CapacityInWords();
(...skipping 16 matching lines...) Expand all
185 215
186 intptr_t collections() const { return collections_; } 216 intptr_t collections() const { return collections_; }
187 217
188 #ifndef PRODUCT 218 #ifndef PRODUCT
189 void PrintToJSONObject(JSONObject* object) const; 219 void PrintToJSONObject(JSONObject* object) const;
190 #endif // !PRODUCT 220 #endif // !PRODUCT
191 221
192 void AllocateExternal(intptr_t size); 222 void AllocateExternal(intptr_t size);
193 void FreeExternal(intptr_t size); 223 void FreeExternal(intptr_t size);
194 224
225 void FlushTLS() const;
226
195 private: 227 private:
196 // Ids for time and data records in Heap::GCStats. 228 // Ids for time and data records in Heap::GCStats.
197 enum { 229 enum {
198 // Time 230 // Time
199 kDummyScavengeTime = 0, 231 kDummyScavengeTime = 0,
200 kSafePoint = 1, 232 kSafePoint = 1,
201 kVisitIsolateRoots = 2, 233 kVisitIsolateRoots = 2,
202 kIterateStoreBuffers = 3, 234 kIterateStoreBuffers = 3,
203 kProcessToSpace = 4, 235 kProcessToSpace = 4,
204 kIterateWeaks = 5, 236 kIterateWeaks = 5,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return end_ < to_->end(); 279 return end_ < to_->end();
248 } 280 }
249 281
250 void UpdateMaxHeapCapacity(); 282 void UpdateMaxHeapCapacity();
251 void UpdateMaxHeapUsage(); 283 void UpdateMaxHeapUsage();
252 284
253 void ProcessWeakReferences(); 285 void ProcessWeakReferences();
254 286
255 intptr_t NewSizeInWords(intptr_t old_size_in_words) const; 287 intptr_t NewSizeInWords(intptr_t old_size_in_words) const;
256 288
257 // Accessed from generated code.
258 // ** This block of fields must come first! **
259 // For AOT cross-compilation, we rely on these members having the same offsets
260 // in SIMARM(IA32) and ARM, and the same offsets in SIMARM64(X64) and ARM64.
261 // We use only word-sized fields to avoid differences in struct packing on the
262 // different architectures. See also CheckOffsets in dart.cc.
263 uword top_; 289 uword top_;
264 uword end_; 290 uword end_;
265 291
266 SemiSpace* to_; 292 SemiSpace* to_;
267 293
268 Heap* heap_; 294 Heap* heap_;
269 295
270 // A pointer to the first unscanned object. Scanning completes when 296 // A pointer to the first unscanned object. Scanning completes when
271 // this value meets the allocation top. 297 // this value meets the allocation top.
272 uword resolved_top_; 298 uword resolved_top_;
(...skipping 24 matching lines...) Expand all
297 323
298 friend class ScavengerVisitor; 324 friend class ScavengerVisitor;
299 friend class ScavengerWeakVisitor; 325 friend class ScavengerWeakVisitor;
300 326
301 DISALLOW_COPY_AND_ASSIGN(Scavenger); 327 DISALLOW_COPY_AND_ASSIGN(Scavenger);
302 }; 328 };
303 329
304 } // namespace dart 330 } // namespace dart
305 331
306 #endif // RUNTIME_VM_SCAVENGER_H_ 332 #endif // RUNTIME_VM_SCAVENGER_H_
OLDNEW
« runtime/vm/heap.cc ('K') | « runtime/vm/isolate.cc ('k') | runtime/vm/scavenger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698