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

Side by Side Diff: src/mark-compact.cc

Issue 11085070: Enable --verify-heap in release mode (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: After rebase plus one new issue fix Created 8 years, 2 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 | Annotate | Revision Log
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 abort_incremental_marking_(false), 64 abort_incremental_marking_(false),
65 compacting_(false), 65 compacting_(false),
66 was_marked_incrementally_(false), 66 was_marked_incrementally_(false),
67 tracer_(NULL), 67 tracer_(NULL),
68 migration_slots_buffer_(NULL), 68 migration_slots_buffer_(NULL),
69 heap_(NULL), 69 heap_(NULL),
70 code_flusher_(NULL), 70 code_flusher_(NULL),
71 encountered_weak_maps_(NULL) { } 71 encountered_weak_maps_(NULL) { }
72 72
73 73
74 #ifdef DEBUG 74 // bool g_unmarked = false;
75 class VerifyMarkingVisitor: public ObjectVisitor { 75 class VerifyMarkingVisitor: public ObjectVisitor {
76 public: 76 public:
77 void VisitPointers(Object** start, Object** end) { 77 void VisitPointers(Object** start, Object** end) {
78 for (Object** current = start; current < end; current++) { 78 for (Object** current = start; current < end; current++) {
79 if ((*current)->IsHeapObject()) { 79 if ((*current)->IsHeapObject()) {
80 HeapObject* object = HeapObject::cast(*current); 80 HeapObject* object = HeapObject::cast(*current);
81 ASSERT(HEAP->mark_compact_collector()->IsMarked(object)); 81 /*
mvstanton1 2012/10/11 12:22:45 debugging...will revert.
82 bool isMarked = HEAP->mark_compact_collector()->IsMarked(object);
83 if(!isMarked) {
84 printf("Found unmarked object at %p\n",(void *) current);
85 object->Print();
86 g_unmarked = true;
87 }
88 */
89 CHECK(HEAP->mark_compact_collector()->IsMarked(object));
82 } 90 }
83 } 91 }
84 } 92 }
85 }; 93 };
86 94
87 95
88 static void VerifyMarking(Address bottom, Address top) { 96 static void VerifyMarking(Address bottom, Address top) {
89 VerifyMarkingVisitor visitor; 97 VerifyMarkingVisitor visitor;
90 HeapObject* object; 98 HeapObject* object;
91 Address next_object_must_be_here_or_later = bottom; 99 Address next_object_must_be_here_or_later = bottom;
92 100
93 for (Address current = bottom; 101 for (Address current = bottom;
94 current < top; 102 current < top;
95 current += kPointerSize) { 103 current += kPointerSize) {
96 object = HeapObject::FromAddress(current); 104 object = HeapObject::FromAddress(current);
97 if (MarkCompactCollector::IsMarked(object)) { 105 if (MarkCompactCollector::IsMarked(object)) {
98 ASSERT(current >= next_object_must_be_here_or_later); 106 CHECK(current >= next_object_must_be_here_or_later);
99 object->Iterate(&visitor); 107 object->Iterate(&visitor);
108 /*
109 if(g_unmarked) {
110 printf("The parent object is at %p\n",(void *) current);
mvstanton1 2012/10/11 12:22:45 same here
111 object->Print();
112 g_unmarked = false;
113 }
114 */
100 next_object_must_be_here_or_later = current + object->Size(); 115 next_object_must_be_here_or_later = current + object->Size();
101 } 116 }
102 } 117 }
103 } 118 }
104 119
105 120
106 static void VerifyMarking(NewSpace* space) { 121 static void VerifyMarking(NewSpace* space) {
107 Address end = space->top(); 122 Address end = space->top();
108 NewSpacePageIterator it(space->bottom(), end); 123 NewSpacePageIterator it(space->bottom(), end);
109 // The bottom position is at the start of its page. Allows us to use 124 // The bottom position is at the start of its page. Allows us to use
110 // page->area_start() as start of range on all pages. 125 // page->area_start() as start of range on all pages.
111 ASSERT_EQ(space->bottom(), 126 CHECK_EQ(space->bottom(),
112 NewSpacePage::FromAddress(space->bottom())->area_start()); 127 NewSpacePage::FromAddress(space->bottom())->area_start());
128
129 // printf("VerifyMarking of NewSpace\n");
mvstanton1 2012/10/11 12:22:45 and here!
130 // printf("top: %p\t bottom: %p\n",space->top(),space->bottom());
113 while (it.has_next()) { 131 while (it.has_next()) {
114 NewSpacePage* page = it.next(); 132 NewSpacePage* page = it.next();
115 Address limit = it.has_next() ? page->area_end() : end; 133 Address limit = it.has_next() ? page->area_end() : end;
116 ASSERT(limit == end || !page->Contains(end)); 134 CHECK(limit == end || !page->Contains(end));
117 VerifyMarking(page->area_start(), limit); 135 VerifyMarking(page->area_start(), limit);
118 } 136 }
137 // printf("End VerifyMarking of NewSpace\n");
119 } 138 }
120 139
121 140
122 static void VerifyMarking(PagedSpace* space) { 141 static void VerifyMarking(PagedSpace* space) {
123 PageIterator it(space); 142 PageIterator it(space);
124 143
125 while (it.has_next()) { 144 while (it.has_next()) {
126 Page* p = it.next(); 145 Page* p = it.next();
127 VerifyMarking(p->area_start(), p->area_end()); 146 VerifyMarking(p->area_start(), p->area_end());
128 } 147 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 static void VerifyEvacuation(Address bottom, Address top) { 185 static void VerifyEvacuation(Address bottom, Address top) {
167 VerifyEvacuationVisitor visitor; 186 VerifyEvacuationVisitor visitor;
168 HeapObject* object; 187 HeapObject* object;
169 Address next_object_must_be_here_or_later = bottom; 188 Address next_object_must_be_here_or_later = bottom;
170 189
171 for (Address current = bottom; 190 for (Address current = bottom;
172 current < top; 191 current < top;
173 current += kPointerSize) { 192 current += kPointerSize) {
174 object = HeapObject::FromAddress(current); 193 object = HeapObject::FromAddress(current);
175 if (MarkCompactCollector::IsMarked(object)) { 194 if (MarkCompactCollector::IsMarked(object)) {
176 ASSERT(current >= next_object_must_be_here_or_later); 195 CHECK(current >= next_object_must_be_here_or_later);
177 object->Iterate(&visitor); 196 object->Iterate(&visitor);
178 next_object_must_be_here_or_later = current + object->Size(); 197 next_object_must_be_here_or_later = current + object->Size();
179 } 198 }
180 } 199 }
181 } 200 }
182 201
183 202
184 static void VerifyEvacuation(NewSpace* space) { 203 static void VerifyEvacuation(NewSpace* space) {
185 NewSpacePageIterator it(space->bottom(), space->top()); 204 NewSpacePageIterator it(space->bottom(), space->top());
186 VerifyEvacuationVisitor visitor; 205 VerifyEvacuationVisitor visitor;
187 206
188 while (it.has_next()) { 207 while (it.has_next()) {
189 NewSpacePage* page = it.next(); 208 NewSpacePage* page = it.next();
190 Address current = page->area_start(); 209 Address current = page->area_start();
191 Address limit = it.has_next() ? page->area_end() : space->top(); 210 Address limit = it.has_next() ? page->area_end() : space->top();
192 ASSERT(limit == space->top() || !page->Contains(space->top())); 211 CHECK(limit == space->top() || !page->Contains(space->top()));
193 while (current < limit) { 212 while (current < limit) {
194 HeapObject* object = HeapObject::FromAddress(current); 213 HeapObject* object = HeapObject::FromAddress(current);
195 object->Iterate(&visitor); 214 object->Iterate(&visitor);
196 current += object->Size(); 215 current += object->Size();
197 } 216 }
198 } 217 }
199 } 218 }
200 219
201 220
202 static void VerifyEvacuation(PagedSpace* space) { 221 static void VerifyEvacuation(PagedSpace* space) {
(...skipping 12 matching lines...) Expand all
215 VerifyEvacuation(heap->old_data_space()); 234 VerifyEvacuation(heap->old_data_space());
216 VerifyEvacuation(heap->code_space()); 235 VerifyEvacuation(heap->code_space());
217 VerifyEvacuation(heap->cell_space()); 236 VerifyEvacuation(heap->cell_space());
218 VerifyEvacuation(heap->map_space()); 237 VerifyEvacuation(heap->map_space());
219 VerifyEvacuation(heap->new_space()); 238 VerifyEvacuation(heap->new_space());
220 239
221 VerifyEvacuationVisitor visitor; 240 VerifyEvacuationVisitor visitor;
222 heap->IterateStrongRoots(&visitor, VISIT_ALL); 241 heap->IterateStrongRoots(&visitor, VISIT_ALL);
223 } 242 }
224 243
225 244 #ifdef DEBUG
226 class VerifyNativeContextSeparationVisitor: public ObjectVisitor { 245 class VerifyNativeContextSeparationVisitor: public ObjectVisitor {
227 public: 246 public:
228 VerifyNativeContextSeparationVisitor() : current_native_context_(NULL) {} 247 VerifyNativeContextSeparationVisitor() : current_native_context_(NULL) {}
229 248
230 void VisitPointers(Object** start, Object** end) { 249 void VisitPointers(Object** start, Object** end) {
231 for (Object** current = start; current < end; current++) { 250 for (Object** current = start; current < end; current++) {
232 if ((*current)->IsHeapObject()) { 251 if ((*current)->IsHeapObject()) {
233 HeapObject* object = HeapObject::cast(*current); 252 HeapObject* object = HeapObject::cast(*current);
234 if (object->IsString()) continue; 253 if (object->IsString()) continue;
235 switch (object->map()->instance_type()) { 254 switch (object->map()->instance_type()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 ASSERT(state_ == PREPARE_GC); 396 ASSERT(state_ == PREPARE_GC);
378 ASSERT(encountered_weak_maps_ == Smi::FromInt(0)); 397 ASSERT(encountered_weak_maps_ == Smi::FromInt(0));
379 398
380 MarkLiveObjects(); 399 MarkLiveObjects();
381 ASSERT(heap_->incremental_marking()->IsStopped()); 400 ASSERT(heap_->incremental_marking()->IsStopped());
382 401
383 if (FLAG_collect_maps) ClearNonLiveTransitions(); 402 if (FLAG_collect_maps) ClearNonLiveTransitions();
384 403
385 ClearWeakMaps(); 404 ClearWeakMaps();
386 405
387 #ifdef DEBUG
388 if (FLAG_verify_heap) { 406 if (FLAG_verify_heap) {
389 VerifyMarking(heap_); 407 VerifyMarking(heap_);
390 } 408 }
391 #endif
392 409
393 SweepSpaces(); 410 SweepSpaces();
394 411
395 if (!FLAG_collect_maps) ReattachInitialMaps(); 412 if (!FLAG_collect_maps) ReattachInitialMaps();
396 413
397 #ifdef DEBUG 414 #ifdef DEBUG
398 if (FLAG_verify_native_context_separation) { 415 if (FLAG_verify_native_context_separation) {
399 VerifyNativeContextSeparation(heap_); 416 VerifyNativeContextSeparation(heap_);
400 } 417 }
401 #endif 418 #endif
402 419
403 Finish(); 420 Finish();
404 421
405 tracer_ = NULL; 422 tracer_ = NULL;
406 } 423 }
407 424
408 425
409 #ifdef DEBUG
410 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { 426 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) {
411 PageIterator it(space); 427 PageIterator it(space);
412 428
413 while (it.has_next()) { 429 while (it.has_next()) {
414 Page* p = it.next(); 430 Page* p = it.next();
415 CHECK(p->markbits()->IsClean()); 431 CHECK(p->markbits()->IsClean());
416 CHECK_EQ(0, p->LiveBytes()); 432 CHECK_EQ(0, p->LiveBytes());
417 } 433 }
418 } 434 }
419 435
(...skipping 11 matching lines...) Expand all
431 VerifyMarkbitsAreClean(heap_->old_pointer_space()); 447 VerifyMarkbitsAreClean(heap_->old_pointer_space());
432 VerifyMarkbitsAreClean(heap_->old_data_space()); 448 VerifyMarkbitsAreClean(heap_->old_data_space());
433 VerifyMarkbitsAreClean(heap_->code_space()); 449 VerifyMarkbitsAreClean(heap_->code_space());
434 VerifyMarkbitsAreClean(heap_->cell_space()); 450 VerifyMarkbitsAreClean(heap_->cell_space());
435 VerifyMarkbitsAreClean(heap_->map_space()); 451 VerifyMarkbitsAreClean(heap_->map_space());
436 VerifyMarkbitsAreClean(heap_->new_space()); 452 VerifyMarkbitsAreClean(heap_->new_space());
437 453
438 LargeObjectIterator it(heap_->lo_space()); 454 LargeObjectIterator it(heap_->lo_space());
439 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { 455 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
440 MarkBit mark_bit = Marking::MarkBitFrom(obj); 456 MarkBit mark_bit = Marking::MarkBitFrom(obj);
441 ASSERT(Marking::IsWhite(mark_bit)); 457 CHECK(Marking::IsWhite(mark_bit));
442 ASSERT_EQ(0, Page::FromAddress(obj->address())->LiveBytes()); 458 CHECK_EQ(0, Page::FromAddress(obj->address())->LiveBytes());
443 } 459 }
444 } 460 }
445 #endif
446 461
447 462
448 static void ClearMarkbitsInPagedSpace(PagedSpace* space) { 463 static void ClearMarkbitsInPagedSpace(PagedSpace* space) {
449 PageIterator it(space); 464 PageIterator it(space);
450 465
451 while (it.has_next()) { 466 while (it.has_next()) {
452 Bitmap::Clear(it.next()); 467 Bitmap::Clear(it.next());
453 } 468 }
454 } 469 }
455 470
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 StartCompaction(NON_INCREMENTAL_COMPACTION); 812 StartCompaction(NON_INCREMENTAL_COMPACTION);
798 } 813 }
799 814
800 PagedSpaces spaces; 815 PagedSpaces spaces;
801 for (PagedSpace* space = spaces.next(); 816 for (PagedSpace* space = spaces.next();
802 space != NULL; 817 space != NULL;
803 space = spaces.next()) { 818 space = spaces.next()) {
804 space->PrepareForMarkCompact(); 819 space->PrepareForMarkCompact();
805 } 820 }
806 821
807 #ifdef DEBUG
808 if (!was_marked_incrementally_ && FLAG_verify_heap) { 822 if (!was_marked_incrementally_ && FLAG_verify_heap) {
809 VerifyMarkbitsAreClean(); 823 VerifyMarkbitsAreClean();
810 } 824 }
811 #endif
812 } 825 }
813 826
814 827
815 void MarkCompactCollector::Finish() { 828 void MarkCompactCollector::Finish() {
816 #ifdef DEBUG 829 #ifdef DEBUG
817 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS); 830 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS);
818 state_ = IDLE; 831 state_ = IDLE;
819 #endif 832 #endif
820 // The stub cache is not traversed during GC; clear the cache to 833 // The stub cache is not traversed during GC; clear the cache to
821 // force lazy re-initialization of it. This must be done after the 834 // force lazy re-initialization of it. This must be done after the
(...skipping 2520 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 3355
3343 EvacuationWeakObjectRetainer evacuation_object_retainer; 3356 EvacuationWeakObjectRetainer evacuation_object_retainer;
3344 heap()->ProcessWeakReferences(&evacuation_object_retainer); 3357 heap()->ProcessWeakReferences(&evacuation_object_retainer);
3345 3358
3346 // Visit invalidated code (we ignored all slots on it) and clear mark-bits 3359 // Visit invalidated code (we ignored all slots on it) and clear mark-bits
3347 // under it. 3360 // under it.
3348 ProcessInvalidatedCode(&updating_visitor); 3361 ProcessInvalidatedCode(&updating_visitor);
3349 3362
3350 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); 3363 heap_->isolate()->inner_pointer_to_code_cache()->Flush();
3351 3364
3352 #ifdef DEBUG
3353 if (FLAG_verify_heap) { 3365 if (FLAG_verify_heap) {
3354 VerifyEvacuation(heap_); 3366 VerifyEvacuation(heap_);
3355 } 3367 }
3356 #endif
3357 3368
3358 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); 3369 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_);
3359 ASSERT(migration_slots_buffer_ == NULL); 3370 ASSERT(migration_slots_buffer_ == NULL);
3360 for (int i = 0; i < npages; i++) { 3371 for (int i = 0; i < npages; i++) {
3361 Page* p = evacuation_candidates_[i]; 3372 Page* p = evacuation_candidates_[i];
3362 if (!p->IsEvacuationCandidate()) continue; 3373 if (!p->IsEvacuationCandidate()) continue;
3363 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); 3374 PagedSpace* space = static_cast<PagedSpace*>(p->owner());
3364 space->Free(p->area_start(), p->area_size()); 3375 space->Free(p->area_start(), p->area_size());
3365 p->set_scan_on_scavenge(false); 3376 p->set_scan_on_scavenge(false);
3366 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); 3377 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address());
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
4077 while (buffer != NULL) { 4088 while (buffer != NULL) {
4078 SlotsBuffer* next_buffer = buffer->next(); 4089 SlotsBuffer* next_buffer = buffer->next();
4079 DeallocateBuffer(buffer); 4090 DeallocateBuffer(buffer);
4080 buffer = next_buffer; 4091 buffer = next_buffer;
4081 } 4092 }
4082 *buffer_address = NULL; 4093 *buffer_address = NULL;
4083 } 4094 }
4084 4095
4085 4096
4086 } } // namespace v8::internal 4097 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698