| OLD | NEW |
| 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 Loading... |
| 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 #ifdef VERIFY_HEAP |
| 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 CHECK(HEAP->mark_compact_collector()->IsMarked(object)); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 | 87 |
| 88 static void VerifyMarking(Address bottom, Address top) { | 88 static void VerifyMarking(Address bottom, Address top) { |
| 89 VerifyMarkingVisitor visitor; | 89 VerifyMarkingVisitor visitor; |
| 90 HeapObject* object; | 90 HeapObject* object; |
| 91 Address next_object_must_be_here_or_later = bottom; | 91 Address next_object_must_be_here_or_later = bottom; |
| 92 | 92 |
| 93 for (Address current = bottom; | 93 for (Address current = bottom; |
| 94 current < top; | 94 current < top; |
| 95 current += kPointerSize) { | 95 current += kPointerSize) { |
| 96 object = HeapObject::FromAddress(current); | 96 object = HeapObject::FromAddress(current); |
| 97 if (MarkCompactCollector::IsMarked(object)) { | 97 if (MarkCompactCollector::IsMarked(object)) { |
| 98 ASSERT(current >= next_object_must_be_here_or_later); | 98 CHECK(current >= next_object_must_be_here_or_later); |
| 99 object->Iterate(&visitor); | 99 object->Iterate(&visitor); |
| 100 next_object_must_be_here_or_later = current + object->Size(); | 100 next_object_must_be_here_or_later = current + object->Size(); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 static void VerifyMarking(NewSpace* space) { | 106 static void VerifyMarking(NewSpace* space) { |
| 107 Address end = space->top(); | 107 Address end = space->top(); |
| 108 NewSpacePageIterator it(space->bottom(), end); | 108 NewSpacePageIterator it(space->bottom(), end); |
| 109 // The bottom position is at the start of its page. Allows us to use | 109 // 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. | 110 // page->area_start() as start of range on all pages. |
| 111 ASSERT_EQ(space->bottom(), | 111 CHECK_EQ(space->bottom(), |
| 112 NewSpacePage::FromAddress(space->bottom())->area_start()); | 112 NewSpacePage::FromAddress(space->bottom())->area_start()); |
| 113 while (it.has_next()) { | 113 while (it.has_next()) { |
| 114 NewSpacePage* page = it.next(); | 114 NewSpacePage* page = it.next(); |
| 115 Address limit = it.has_next() ? page->area_end() : end; | 115 Address limit = it.has_next() ? page->area_end() : end; |
| 116 ASSERT(limit == end || !page->Contains(end)); | 116 CHECK(limit == end || !page->Contains(end)); |
| 117 VerifyMarking(page->area_start(), limit); | 117 VerifyMarking(page->area_start(), limit); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 static void VerifyMarking(PagedSpace* space) { | 122 static void VerifyMarking(PagedSpace* space) { |
| 123 PageIterator it(space); | 123 PageIterator it(space); |
| 124 | 124 |
| 125 while (it.has_next()) { | 125 while (it.has_next()) { |
| 126 Page* p = it.next(); | 126 Page* p = it.next(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 static void VerifyEvacuation(Address bottom, Address top) { | 166 static void VerifyEvacuation(Address bottom, Address top) { |
| 167 VerifyEvacuationVisitor visitor; | 167 VerifyEvacuationVisitor visitor; |
| 168 HeapObject* object; | 168 HeapObject* object; |
| 169 Address next_object_must_be_here_or_later = bottom; | 169 Address next_object_must_be_here_or_later = bottom; |
| 170 | 170 |
| 171 for (Address current = bottom; | 171 for (Address current = bottom; |
| 172 current < top; | 172 current < top; |
| 173 current += kPointerSize) { | 173 current += kPointerSize) { |
| 174 object = HeapObject::FromAddress(current); | 174 object = HeapObject::FromAddress(current); |
| 175 if (MarkCompactCollector::IsMarked(object)) { | 175 if (MarkCompactCollector::IsMarked(object)) { |
| 176 ASSERT(current >= next_object_must_be_here_or_later); | 176 CHECK(current >= next_object_must_be_here_or_later); |
| 177 object->Iterate(&visitor); | 177 object->Iterate(&visitor); |
| 178 next_object_must_be_here_or_later = current + object->Size(); | 178 next_object_must_be_here_or_later = current + object->Size(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 static void VerifyEvacuation(NewSpace* space) { | 184 static void VerifyEvacuation(NewSpace* space) { |
| 185 NewSpacePageIterator it(space->bottom(), space->top()); | 185 NewSpacePageIterator it(space->bottom(), space->top()); |
| 186 VerifyEvacuationVisitor visitor; | 186 VerifyEvacuationVisitor visitor; |
| 187 | 187 |
| 188 while (it.has_next()) { | 188 while (it.has_next()) { |
| 189 NewSpacePage* page = it.next(); | 189 NewSpacePage* page = it.next(); |
| 190 Address current = page->area_start(); | 190 Address current = page->area_start(); |
| 191 Address limit = it.has_next() ? page->area_end() : space->top(); | 191 Address limit = it.has_next() ? page->area_end() : space->top(); |
| 192 ASSERT(limit == space->top() || !page->Contains(space->top())); | 192 CHECK(limit == space->top() || !page->Contains(space->top())); |
| 193 while (current < limit) { | 193 while (current < limit) { |
| 194 HeapObject* object = HeapObject::FromAddress(current); | 194 HeapObject* object = HeapObject::FromAddress(current); |
| 195 object->Iterate(&visitor); | 195 object->Iterate(&visitor); |
| 196 current += object->Size(); | 196 current += object->Size(); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 static void VerifyEvacuation(PagedSpace* space) { | 202 static void VerifyEvacuation(PagedSpace* space) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 214 VerifyEvacuation(heap->old_pointer_space()); | 214 VerifyEvacuation(heap->old_pointer_space()); |
| 215 VerifyEvacuation(heap->old_data_space()); | 215 VerifyEvacuation(heap->old_data_space()); |
| 216 VerifyEvacuation(heap->code_space()); | 216 VerifyEvacuation(heap->code_space()); |
| 217 VerifyEvacuation(heap->cell_space()); | 217 VerifyEvacuation(heap->cell_space()); |
| 218 VerifyEvacuation(heap->map_space()); | 218 VerifyEvacuation(heap->map_space()); |
| 219 VerifyEvacuation(heap->new_space()); | 219 VerifyEvacuation(heap->new_space()); |
| 220 | 220 |
| 221 VerifyEvacuationVisitor visitor; | 221 VerifyEvacuationVisitor visitor; |
| 222 heap->IterateStrongRoots(&visitor, VISIT_ALL); | 222 heap->IterateStrongRoots(&visitor, VISIT_ALL); |
| 223 } | 223 } |
| 224 #endif // VERIFY_HEAP |
| 224 | 225 |
| 225 | 226 |
| 227 #ifdef DEBUG |
| 226 class VerifyNativeContextSeparationVisitor: public ObjectVisitor { | 228 class VerifyNativeContextSeparationVisitor: public ObjectVisitor { |
| 227 public: | 229 public: |
| 228 VerifyNativeContextSeparationVisitor() : current_native_context_(NULL) {} | 230 VerifyNativeContextSeparationVisitor() : current_native_context_(NULL) {} |
| 229 | 231 |
| 230 void VisitPointers(Object** start, Object** end) { | 232 void VisitPointers(Object** start, Object** end) { |
| 231 for (Object** current = start; current < end; current++) { | 233 for (Object** current = start; current < end; current++) { |
| 232 if ((*current)->IsHeapObject()) { | 234 if ((*current)->IsHeapObject()) { |
| 233 HeapObject* object = HeapObject::cast(*current); | 235 HeapObject* object = HeapObject::cast(*current); |
| 234 if (object->IsString()) continue; | 236 if (object->IsString()) continue; |
| 235 switch (object->map()->instance_type()) { | 237 switch (object->map()->instance_type()) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 ASSERT(state_ == PREPARE_GC); | 379 ASSERT(state_ == PREPARE_GC); |
| 378 ASSERT(encountered_weak_maps_ == Smi::FromInt(0)); | 380 ASSERT(encountered_weak_maps_ == Smi::FromInt(0)); |
| 379 | 381 |
| 380 MarkLiveObjects(); | 382 MarkLiveObjects(); |
| 381 ASSERT(heap_->incremental_marking()->IsStopped()); | 383 ASSERT(heap_->incremental_marking()->IsStopped()); |
| 382 | 384 |
| 383 if (FLAG_collect_maps) ClearNonLiveTransitions(); | 385 if (FLAG_collect_maps) ClearNonLiveTransitions(); |
| 384 | 386 |
| 385 ClearWeakMaps(); | 387 ClearWeakMaps(); |
| 386 | 388 |
| 387 #ifdef DEBUG | 389 #ifdef VERIFY_HEAP |
| 388 if (FLAG_verify_heap) { | 390 if (FLAG_verify_heap) { |
| 389 VerifyMarking(heap_); | 391 VerifyMarking(heap_); |
| 390 } | 392 } |
| 391 #endif | 393 #endif |
| 392 | 394 |
| 393 SweepSpaces(); | 395 SweepSpaces(); |
| 394 | 396 |
| 395 if (!FLAG_collect_maps) ReattachInitialMaps(); | 397 if (!FLAG_collect_maps) ReattachInitialMaps(); |
| 396 | 398 |
| 397 #ifdef DEBUG | 399 #ifdef DEBUG |
| 398 if (FLAG_verify_native_context_separation) { | 400 if (FLAG_verify_native_context_separation) { |
| 399 VerifyNativeContextSeparation(heap_); | 401 VerifyNativeContextSeparation(heap_); |
| 400 } | 402 } |
| 401 #endif | 403 #endif |
| 402 | 404 |
| 403 Finish(); | 405 Finish(); |
| 404 | 406 |
| 405 tracer_ = NULL; | 407 tracer_ = NULL; |
| 406 } | 408 } |
| 407 | 409 |
| 408 | 410 |
| 409 #ifdef DEBUG | 411 #ifdef VERIFY_HEAP |
| 410 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { | 412 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { |
| 411 PageIterator it(space); | 413 PageIterator it(space); |
| 412 | 414 |
| 413 while (it.has_next()) { | 415 while (it.has_next()) { |
| 414 Page* p = it.next(); | 416 Page* p = it.next(); |
| 415 CHECK(p->markbits()->IsClean()); | 417 CHECK(p->markbits()->IsClean()); |
| 416 CHECK_EQ(0, p->LiveBytes()); | 418 CHECK_EQ(0, p->LiveBytes()); |
| 417 } | 419 } |
| 418 } | 420 } |
| 419 | 421 |
| 422 |
| 420 void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) { | 423 void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) { |
| 421 NewSpacePageIterator it(space->bottom(), space->top()); | 424 NewSpacePageIterator it(space->bottom(), space->top()); |
| 422 | 425 |
| 423 while (it.has_next()) { | 426 while (it.has_next()) { |
| 424 NewSpacePage* p = it.next(); | 427 NewSpacePage* p = it.next(); |
| 425 CHECK(p->markbits()->IsClean()); | 428 CHECK(p->markbits()->IsClean()); |
| 426 CHECK_EQ(0, p->LiveBytes()); | 429 CHECK_EQ(0, p->LiveBytes()); |
| 427 } | 430 } |
| 428 } | 431 } |
| 429 | 432 |
| 433 |
| 430 void MarkCompactCollector::VerifyMarkbitsAreClean() { | 434 void MarkCompactCollector::VerifyMarkbitsAreClean() { |
| 431 VerifyMarkbitsAreClean(heap_->old_pointer_space()); | 435 VerifyMarkbitsAreClean(heap_->old_pointer_space()); |
| 432 VerifyMarkbitsAreClean(heap_->old_data_space()); | 436 VerifyMarkbitsAreClean(heap_->old_data_space()); |
| 433 VerifyMarkbitsAreClean(heap_->code_space()); | 437 VerifyMarkbitsAreClean(heap_->code_space()); |
| 434 VerifyMarkbitsAreClean(heap_->cell_space()); | 438 VerifyMarkbitsAreClean(heap_->cell_space()); |
| 435 VerifyMarkbitsAreClean(heap_->map_space()); | 439 VerifyMarkbitsAreClean(heap_->map_space()); |
| 436 VerifyMarkbitsAreClean(heap_->new_space()); | 440 VerifyMarkbitsAreClean(heap_->new_space()); |
| 437 | 441 |
| 438 LargeObjectIterator it(heap_->lo_space()); | 442 LargeObjectIterator it(heap_->lo_space()); |
| 439 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 443 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { |
| 440 MarkBit mark_bit = Marking::MarkBitFrom(obj); | 444 MarkBit mark_bit = Marking::MarkBitFrom(obj); |
| 441 ASSERT(Marking::IsWhite(mark_bit)); | 445 CHECK(Marking::IsWhite(mark_bit)); |
| 442 ASSERT_EQ(0, Page::FromAddress(obj->address())->LiveBytes()); | 446 CHECK_EQ(0, Page::FromAddress(obj->address())->LiveBytes()); |
| 443 } | 447 } |
| 444 } | 448 } |
| 445 #endif | 449 #endif // VERIFY_HEAP |
| 446 | 450 |
| 447 | 451 |
| 448 static void ClearMarkbitsInPagedSpace(PagedSpace* space) { | 452 static void ClearMarkbitsInPagedSpace(PagedSpace* space) { |
| 449 PageIterator it(space); | 453 PageIterator it(space); |
| 450 | 454 |
| 451 while (it.has_next()) { | 455 while (it.has_next()) { |
| 452 Bitmap::Clear(it.next()); | 456 Bitmap::Clear(it.next()); |
| 453 } | 457 } |
| 454 } | 458 } |
| 455 | 459 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 StartCompaction(NON_INCREMENTAL_COMPACTION); | 801 StartCompaction(NON_INCREMENTAL_COMPACTION); |
| 798 } | 802 } |
| 799 | 803 |
| 800 PagedSpaces spaces; | 804 PagedSpaces spaces; |
| 801 for (PagedSpace* space = spaces.next(); | 805 for (PagedSpace* space = spaces.next(); |
| 802 space != NULL; | 806 space != NULL; |
| 803 space = spaces.next()) { | 807 space = spaces.next()) { |
| 804 space->PrepareForMarkCompact(); | 808 space->PrepareForMarkCompact(); |
| 805 } | 809 } |
| 806 | 810 |
| 807 #ifdef DEBUG | 811 #ifdef VERIFY_HEAP |
| 808 if (!was_marked_incrementally_ && FLAG_verify_heap) { | 812 if (!was_marked_incrementally_ && FLAG_verify_heap) { |
| 809 VerifyMarkbitsAreClean(); | 813 VerifyMarkbitsAreClean(); |
| 810 } | 814 } |
| 811 #endif | 815 #endif |
| 812 } | 816 } |
| 813 | 817 |
| 814 | 818 |
| 815 void MarkCompactCollector::Finish() { | 819 void MarkCompactCollector::Finish() { |
| 816 #ifdef DEBUG | 820 #ifdef DEBUG |
| 817 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS); | 821 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS); |
| (...skipping 2524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 | 3346 |
| 3343 EvacuationWeakObjectRetainer evacuation_object_retainer; | 3347 EvacuationWeakObjectRetainer evacuation_object_retainer; |
| 3344 heap()->ProcessWeakReferences(&evacuation_object_retainer); | 3348 heap()->ProcessWeakReferences(&evacuation_object_retainer); |
| 3345 | 3349 |
| 3346 // Visit invalidated code (we ignored all slots on it) and clear mark-bits | 3350 // Visit invalidated code (we ignored all slots on it) and clear mark-bits |
| 3347 // under it. | 3351 // under it. |
| 3348 ProcessInvalidatedCode(&updating_visitor); | 3352 ProcessInvalidatedCode(&updating_visitor); |
| 3349 | 3353 |
| 3350 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); | 3354 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); |
| 3351 | 3355 |
| 3352 #ifdef DEBUG | 3356 #ifdef VERIFY_HEAP |
| 3353 if (FLAG_verify_heap) { | 3357 if (FLAG_verify_heap) { |
| 3354 VerifyEvacuation(heap_); | 3358 VerifyEvacuation(heap_); |
| 3355 } | 3359 } |
| 3356 #endif | 3360 #endif |
| 3357 | 3361 |
| 3358 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); | 3362 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); |
| 3359 ASSERT(migration_slots_buffer_ == NULL); | 3363 ASSERT(migration_slots_buffer_ == NULL); |
| 3360 for (int i = 0; i < npages; i++) { | 3364 for (int i = 0; i < npages; i++) { |
| 3361 Page* p = evacuation_candidates_[i]; | 3365 Page* p = evacuation_candidates_[i]; |
| 3362 if (!p->IsEvacuationCandidate()) continue; | 3366 if (!p->IsEvacuationCandidate()) continue; |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4077 while (buffer != NULL) { | 4081 while (buffer != NULL) { |
| 4078 SlotsBuffer* next_buffer = buffer->next(); | 4082 SlotsBuffer* next_buffer = buffer->next(); |
| 4079 DeallocateBuffer(buffer); | 4083 DeallocateBuffer(buffer); |
| 4080 buffer = next_buffer; | 4084 buffer = next_buffer; |
| 4081 } | 4085 } |
| 4082 *buffer_address = NULL; | 4086 *buffer_address = NULL; |
| 4083 } | 4087 } |
| 4084 | 4088 |
| 4085 | 4089 |
| 4086 } } // namespace v8::internal | 4090 } } // namespace v8::internal |
| OLD | NEW |