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

Side by Side Diff: src/incremental-marking.cc

Issue 11362246: Implement progress bar for large objects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more comments. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « src/incremental-marking.h ('k') | src/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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); 181 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj));
182 if (Marking::IsBlack(mark_bit)) { 182 if (Marking::IsBlack(mark_bit)) {
183 MemoryChunk::IncrementLiveBytesFromGC(heap_obj->address(), 183 MemoryChunk::IncrementLiveBytesFromGC(heap_obj->address(),
184 -heap_obj->Size()); 184 -heap_obj->Size());
185 } 185 }
186 Marking::AnyToGrey(mark_bit); 186 Marking::AnyToGrey(mark_bit);
187 } 187 }
188 } 188 }
189 189
190 190
191 static inline void MarkBlackOrKeepGrey(HeapObject* heap_object,
192 MarkBit mark_bit,
193 int size) {
194 ASSERT(!Marking::IsImpossible(mark_bit));
195 if (mark_bit.Get()) return;
196 mark_bit.Set();
197 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), size);
198 ASSERT(Marking::IsBlack(mark_bit));
199 }
200
201
202 static inline void MarkBlackOrKeepBlack(HeapObject* heap_object,
203 MarkBit mark_bit,
204 int size) {
205 ASSERT(!Marking::IsImpossible(mark_bit));
206 if (Marking::IsBlack(mark_bit)) return;
207 Marking::MarkBlack(mark_bit);
208 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), size);
209 ASSERT(Marking::IsBlack(mark_bit));
210 }
211
212
191 class IncrementalMarkingMarkingVisitor 213 class IncrementalMarkingMarkingVisitor
192 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> { 214 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> {
193 public: 215 public:
194 static void Initialize() { 216 static void Initialize() {
195 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize(); 217 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize();
196 218 table_.Register(kVisitFixedArray, &VisitFixedArrayIncremental);
197 table_.Register(kVisitNativeContext, &VisitNativeContextIncremental); 219 table_.Register(kVisitNativeContext, &VisitNativeContextIncremental);
198 table_.Register(kVisitJSRegExp, &VisitJSRegExp); 220 table_.Register(kVisitJSRegExp, &VisitJSRegExp);
199 } 221 }
200 222
223 static const int kProgressBarScanningChunk = 32 * 1024;
224
225 static void VisitFixedArrayIncremental(Map* map, HeapObject* object) {
226 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
227 // TODO(mstarzinger): Move setting of the flag to the allocation site of
228 // the array. The visitor should just check the flag.
229 if (FLAG_use_marking_progress_bar &&
230 chunk->owner()->identity() == LO_SPACE) {
231 chunk->SetFlag(MemoryChunk::HAS_PROGRESS_BAR);
232 }
233 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) {
234 Heap* heap = map->GetHeap();
235 // When using a progress bar for large fixed arrays, scan only a chunk of
236 // the array and try to push it onto the marking deque again until it is
237 // fully scanned. Fall back to scanning it through to the end in case this
238 // fails because of a full deque.
239 int object_size = FixedArray::BodyDescriptor::SizeOf(map, object);
240 int start_offset = Max(FixedArray::BodyDescriptor::kStartOffset,
241 chunk->progress_bar());
242 int end_offset = Min(object_size,
243 start_offset + kProgressBarScanningChunk);
244 bool scan_until_end = false;
245 do {
246 VisitPointersWithAnchor(heap,
247 HeapObject::RawField(object, 0),
248 HeapObject::RawField(object, start_offset),
249 HeapObject::RawField(object, end_offset));
250 start_offset = end_offset;
251 end_offset = Min(object_size, end_offset + kProgressBarScanningChunk);
252 scan_until_end = heap->incremental_marking()->marking_deque()->IsFull();
253 } while (scan_until_end && start_offset < object_size);
254 chunk->set_progress_bar(start_offset);
255 if (start_offset < object_size) {
256 heap->incremental_marking()->marking_deque()->UnshiftGrey(object);
257 }
258 } else {
259 FixedArrayVisitor::Visit(map, object);
260 }
261 }
262
201 static void VisitNativeContextIncremental(Map* map, HeapObject* object) { 263 static void VisitNativeContextIncremental(Map* map, HeapObject* object) {
202 Context* context = Context::cast(object); 264 Context* context = Context::cast(object);
203 265
204 // We will mark cache black with a separate pass 266 // We will mark cache black with a separate pass
205 // when we finish marking. 267 // when we finish marking.
206 MarkObjectGreyDoNotEnqueue(context->normalized_map_cache()); 268 MarkObjectGreyDoNotEnqueue(context->normalized_map_cache());
207 VisitNativeContext(map, context); 269 VisitNativeContext(map, context);
208 } 270 }
209 271
210 static void VisitJSWeakMap(Map* map, HeapObject* object) { 272 static void VisitJSWeakMap(Map* map, HeapObject* object) {
(...skipping 16 matching lines...) Expand all
227 INLINE(static void VisitPointers(Heap* heap, Object** start, Object** end)) { 289 INLINE(static void VisitPointers(Heap* heap, Object** start, Object** end)) {
228 for (Object** p = start; p < end; p++) { 290 for (Object** p = start; p < end; p++) {
229 Object* obj = *p; 291 Object* obj = *p;
230 if (obj->NonFailureIsHeapObject()) { 292 if (obj->NonFailureIsHeapObject()) {
231 heap->mark_compact_collector()->RecordSlot(start, p, obj); 293 heap->mark_compact_collector()->RecordSlot(start, p, obj);
232 MarkObject(heap, obj); 294 MarkObject(heap, obj);
233 } 295 }
234 } 296 }
235 } 297 }
236 298
299 INLINE(static void VisitPointersWithAnchor(Heap* heap,
300 Object** anchor,
301 Object** start,
302 Object** end)) {
303 for (Object** p = start; p < end; p++) {
304 Object* obj = *p;
305 if (obj->NonFailureIsHeapObject()) {
306 heap->mark_compact_collector()->RecordSlot(anchor, p, obj);
307 MarkObject(heap, obj);
308 }
309 }
310 }
311
237 // Marks the object grey and pushes it on the marking stack. 312 // Marks the object grey and pushes it on the marking stack.
238 INLINE(static void MarkObject(Heap* heap, Object* obj)) { 313 INLINE(static void MarkObject(Heap* heap, Object* obj)) {
239 HeapObject* heap_object = HeapObject::cast(obj); 314 HeapObject* heap_object = HeapObject::cast(obj);
240 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); 315 MarkBit mark_bit = Marking::MarkBitFrom(heap_object);
241 if (mark_bit.data_only()) { 316 if (mark_bit.data_only()) {
242 if (heap->incremental_marking()->MarkBlackOrKeepGrey(mark_bit)) { 317 MarkBlackOrKeepGrey(heap_object, mark_bit, heap_object->Size());
243 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(),
244 heap_object->Size());
245 }
246 } else if (Marking::IsWhite(mark_bit)) { 318 } else if (Marking::IsWhite(mark_bit)) {
247 heap->incremental_marking()->WhiteToGreyAndPush(heap_object, mark_bit); 319 heap->incremental_marking()->WhiteToGreyAndPush(heap_object, mark_bit);
248 } 320 }
249 } 321 }
250 322
251 // Marks the object black without pushing it on the marking stack. 323 // Marks the object black without pushing it on the marking stack.
252 // Returns true if object needed marking and false otherwise. 324 // Returns true if object needed marking and false otherwise.
253 INLINE(static bool MarkObjectWithoutPush(Heap* heap, Object* obj)) { 325 INLINE(static bool MarkObjectWithoutPush(Heap* heap, Object* obj)) {
254 HeapObject* heap_object = HeapObject::cast(obj); 326 HeapObject* heap_object = HeapObject::cast(obj);
255 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); 327 MarkBit mark_bit = Marking::MarkBitFrom(heap_object);
(...skipping 25 matching lines...) Expand all
281 } 353 }
282 354
283 private: 355 private:
284 void MarkObjectByPointer(Object** p) { 356 void MarkObjectByPointer(Object** p) {
285 Object* obj = *p; 357 Object* obj = *p;
286 if (!obj->IsHeapObject()) return; 358 if (!obj->IsHeapObject()) return;
287 359
288 HeapObject* heap_object = HeapObject::cast(obj); 360 HeapObject* heap_object = HeapObject::cast(obj);
289 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); 361 MarkBit mark_bit = Marking::MarkBitFrom(heap_object);
290 if (mark_bit.data_only()) { 362 if (mark_bit.data_only()) {
291 if (incremental_marking_->MarkBlackOrKeepGrey(mark_bit)) { 363 MarkBlackOrKeepGrey(heap_object, mark_bit, heap_object->Size());
292 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(),
293 heap_object->Size());
294 }
295 } else { 364 } else {
296 if (Marking::IsWhite(mark_bit)) { 365 if (Marking::IsWhite(mark_bit)) {
297 incremental_marking_->WhiteToGreyAndPush(heap_object, mark_bit); 366 incremental_marking_->WhiteToGreyAndPush(heap_object, mark_bit);
298 } 367 }
299 } 368 }
300 } 369 }
301 370
302 Heap* heap_; 371 Heap* heap_;
303 IncrementalMarking* incremental_marking_; 372 IncrementalMarking* incremental_marking_;
304 }; 373 };
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 #endif 678 #endif
610 } 679 }
611 } else if (obj->map() != filler_map) { 680 } else if (obj->map() != filler_map) {
612 // Skip one word filler objects that appear on the 681 // Skip one word filler objects that appear on the
613 // stack when we perform in place array shift. 682 // stack when we perform in place array shift.
614 array[new_top] = obj; 683 array[new_top] = obj;
615 new_top = ((new_top + 1) & mask); 684 new_top = ((new_top + 1) & mask);
616 ASSERT(new_top != marking_deque_.bottom()); 685 ASSERT(new_top != marking_deque_.bottom());
617 #ifdef DEBUG 686 #ifdef DEBUG
618 MarkBit mark_bit = Marking::MarkBitFrom(obj); 687 MarkBit mark_bit = Marking::MarkBitFrom(obj);
688 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
619 ASSERT(Marking::IsGrey(mark_bit) || 689 ASSERT(Marking::IsGrey(mark_bit) ||
620 (obj->IsFiller() && Marking::IsWhite(mark_bit))); 690 (obj->IsFiller() && Marking::IsWhite(mark_bit)) ||
691 (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR) &&
692 Marking::IsBlack(mark_bit)));
621 #endif 693 #endif
622 } 694 }
623 } 695 }
624 marking_deque_.set_top(new_top); 696 marking_deque_.set_top(new_top);
625 697
626 steps_took_since_last_gc_ = 0; 698 steps_took_since_last_gc_ = 0;
627 steps_count_since_last_gc_ = 0; 699 steps_count_since_last_gc_ = 0;
628 longest_step_ = 0.0; 700 longest_step_ = 0.0;
629 } 701 }
630 702
631 703
632 void IncrementalMarking::VisitObject(Map* map, HeapObject* obj, int size) { 704 void IncrementalMarking::VisitObject(Map* map, HeapObject* obj, int size) {
633 MarkBit map_mark_bit = Marking::MarkBitFrom(map); 705 MarkBit map_mark_bit = Marking::MarkBitFrom(map);
634 if (Marking::IsWhite(map_mark_bit)) { 706 if (Marking::IsWhite(map_mark_bit)) {
635 WhiteToGreyAndPush(map, map_mark_bit); 707 WhiteToGreyAndPush(map, map_mark_bit);
636 } 708 }
637 709
638 IncrementalMarkingMarkingVisitor::IterateBody(map, obj); 710 IncrementalMarkingMarkingVisitor::IterateBody(map, obj);
639 711
640 MarkBit obj_mark_bit = Marking::MarkBitFrom(obj); 712 MarkBit mark_bit = Marking::MarkBitFrom(obj);
641 SLOW_ASSERT(Marking::IsGrey(obj_mark_bit) || 713 #ifdef DEBUG
642 (obj->IsFiller() && Marking::IsWhite(obj_mark_bit))); 714 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
643 Marking::MarkBlack(obj_mark_bit); 715 SLOW_ASSERT(Marking::IsGrey(mark_bit) ||
644 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), size); 716 (obj->IsFiller() && Marking::IsWhite(mark_bit)) ||
717 (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR) &&
718 Marking::IsBlack(mark_bit)));
719 #endif
720 MarkBlackOrKeepBlack(obj, mark_bit, size);
645 } 721 }
646 722
647 723
648 void IncrementalMarking::ProcessMarkingDeque(intptr_t bytes_to_process) { 724 void IncrementalMarking::ProcessMarkingDeque(intptr_t bytes_to_process) {
649 Map* filler_map = heap_->one_pointer_filler_map(); 725 Map* filler_map = heap_->one_pointer_filler_map();
650 while (!marking_deque_.IsEmpty() && bytes_to_process > 0) { 726 while (!marking_deque_.IsEmpty() && bytes_to_process > 0) {
651 HeapObject* obj = marking_deque_.Pop(); 727 HeapObject* obj = marking_deque_.Pop();
652 728
653 // Explicitly skip one word fillers. Incremental markbit patterns are 729 // Explicitly skip one word fillers. Incremental markbit patterns are
654 // correct only for objects that occupy at least two words. 730 // correct only for objects that occupy at least two words.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 bytes_scanned_ = 0; 996 bytes_scanned_ = 0;
921 write_barriers_invoked_since_last_step_ = 0; 997 write_barriers_invoked_since_last_step_ = 0;
922 } 998 }
923 999
924 1000
925 int64_t IncrementalMarking::SpaceLeftInOldSpace() { 1001 int64_t IncrementalMarking::SpaceLeftInOldSpace() {
926 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); 1002 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects();
927 } 1003 }
928 1004
929 } } // namespace v8::internal 1005 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/incremental-marking.h ('k') | src/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698