OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 MarkCompactCollector::MarkCompactCollector() : // NOLINT | 58 MarkCompactCollector::MarkCompactCollector() : // NOLINT |
59 #ifdef DEBUG | 59 #ifdef DEBUG |
60 state_(IDLE), | 60 state_(IDLE), |
61 #endif | 61 #endif |
62 sweep_precisely_(false), | 62 sweep_precisely_(false), |
63 compacting_(false), | 63 compacting_(false), |
64 was_marked_incrementally_(false), | 64 was_marked_incrementally_(false), |
65 collect_maps_(FLAG_collect_maps), | 65 collect_maps_(FLAG_collect_maps), |
66 tracer_(NULL), | 66 tracer_(NULL), |
67 migration_slots_buffer_(NULL), | 67 migration_slots_buffer_(NULL), |
68 #ifdef DEBUG | |
69 live_young_objects_size_(0), | |
70 live_old_pointer_objects_size_(0), | |
71 live_old_data_objects_size_(0), | |
72 live_code_objects_size_(0), | |
73 live_map_objects_size_(0), | |
74 live_cell_objects_size_(0), | |
75 live_lo_objects_size_(0), | |
76 live_bytes_(0), | |
77 #endif | |
78 heap_(NULL), | 68 heap_(NULL), |
79 code_flusher_(NULL), | 69 code_flusher_(NULL), |
80 encountered_weak_maps_(NULL) { } | 70 encountered_weak_maps_(NULL) { } |
81 | 71 |
82 | 72 |
83 #ifdef DEBUG | 73 #ifdef DEBUG |
84 class VerifyMarkingVisitor: public ObjectVisitor { | 74 class VerifyMarkingVisitor: public ObjectVisitor { |
85 public: | 75 public: |
86 void VisitPointers(Object** start, Object** end) { | 76 void VisitPointers(Object** start, Object** end) { |
87 for (Object** current = start; current < end; current++) { | 77 for (Object** current = start; current < end; current++) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 313 |
324 LargeObjectIterator it(heap_->lo_space()); | 314 LargeObjectIterator it(heap_->lo_space()); |
325 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 315 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { |
326 MarkBit mark_bit = Marking::MarkBitFrom(obj); | 316 MarkBit mark_bit = Marking::MarkBitFrom(obj); |
327 ASSERT(Marking::IsWhite(mark_bit)); | 317 ASSERT(Marking::IsWhite(mark_bit)); |
328 } | 318 } |
329 } | 319 } |
330 #endif | 320 #endif |
331 | 321 |
332 | 322 |
333 static void ClearMarkbits(PagedSpace* space) { | 323 static void ClearMarkbitsInPagedSpace(PagedSpace* space) { |
334 PageIterator it(space); | 324 PageIterator it(space); |
335 | 325 |
336 while (it.has_next()) { | 326 while (it.has_next()) { |
337 Bitmap::Clear(it.next()); | 327 Bitmap::Clear(it.next()); |
338 } | 328 } |
339 } | 329 } |
340 | 330 |
341 | 331 |
342 static void ClearMarkbits(NewSpace* space) { | 332 static void ClearMarkbitsInNewSpace(NewSpace* space) { |
343 NewSpacePageIterator it(space->ToSpaceStart(), space->ToSpaceEnd()); | 333 NewSpacePageIterator it(space->ToSpaceStart(), space->ToSpaceEnd()); |
344 | 334 |
345 while (it.has_next()) { | 335 while (it.has_next()) { |
346 Bitmap::Clear(it.next()); | 336 Bitmap::Clear(it.next()); |
347 } | 337 } |
348 } | 338 } |
349 | 339 |
350 | 340 |
351 static void ClearMarkbits(Heap* heap) { | 341 void MarkCompactCollector::ClearMarkbits() { |
352 ClearMarkbits(heap->code_space()); | 342 ClearMarkbitsInPagedSpace(heap_->code_space()); |
353 ClearMarkbits(heap->map_space()); | 343 ClearMarkbitsInPagedSpace(heap_->map_space()); |
354 ClearMarkbits(heap->old_pointer_space()); | 344 ClearMarkbitsInPagedSpace(heap_->old_pointer_space()); |
355 ClearMarkbits(heap->old_data_space()); | 345 ClearMarkbitsInPagedSpace(heap_->old_data_space()); |
356 ClearMarkbits(heap->cell_space()); | 346 ClearMarkbitsInPagedSpace(heap_->cell_space()); |
357 ClearMarkbits(heap->new_space()); | 347 ClearMarkbitsInNewSpace(heap_->new_space()); |
358 | 348 |
359 LargeObjectIterator it(heap->lo_space()); | 349 LargeObjectIterator it(heap_->lo_space()); |
360 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 350 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { |
361 MarkBit mark_bit = Marking::MarkBitFrom(obj); | 351 MarkBit mark_bit = Marking::MarkBitFrom(obj); |
362 mark_bit.Clear(); | 352 mark_bit.Clear(); |
363 mark_bit.Next().Clear(); | 353 mark_bit.Next().Clear(); |
364 } | 354 } |
365 } | 355 } |
366 | 356 |
367 | 357 |
368 bool Marking::TransferMark(Address old_start, Address new_start) { | 358 bool Marking::TransferMark(Address old_start, Address new_start) { |
369 // This is only used when resizing an object. | 359 // This is only used when resizing an object. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 #ifdef ENABLE_GDB_JIT_INTERFACE | 487 #ifdef ENABLE_GDB_JIT_INTERFACE |
498 if (FLAG_gdbjit) { | 488 if (FLAG_gdbjit) { |
499 // If GDBJIT interface is active disable compaction. | 489 // If GDBJIT interface is active disable compaction. |
500 compacting_collection_ = false; | 490 compacting_collection_ = false; |
501 } | 491 } |
502 #endif | 492 #endif |
503 | 493 |
504 // Clear marking bits for precise sweeping to collect all garbage. | 494 // Clear marking bits for precise sweeping to collect all garbage. |
505 if (was_marked_incrementally_ && PreciseSweepingRequired()) { | 495 if (was_marked_incrementally_ && PreciseSweepingRequired()) { |
506 heap()->incremental_marking()->Abort(); | 496 heap()->incremental_marking()->Abort(); |
507 ClearMarkbits(heap_); | 497 ClearMarkbits(); |
508 AbortCompaction(); | 498 AbortCompaction(); |
509 was_marked_incrementally_ = false; | 499 was_marked_incrementally_ = false; |
510 } | 500 } |
511 | 501 |
512 // Don't start compaction if we are in the middle of incremental | 502 // Don't start compaction if we are in the middle of incremental |
513 // marking cycle. We did not collect any slots. | 503 // marking cycle. We did not collect any slots. |
514 if (!FLAG_never_compact && !was_marked_incrementally_) { | 504 if (!FLAG_never_compact && !was_marked_incrementally_) { |
515 StartCompaction(); | 505 StartCompaction(); |
516 } | 506 } |
517 | 507 |
518 PagedSpaces spaces; | 508 PagedSpaces spaces; |
519 for (PagedSpace* space = spaces.next(); | 509 for (PagedSpace* space = spaces.next(); |
520 space != NULL; | 510 space != NULL; |
521 space = spaces.next()) { | 511 space = spaces.next()) { |
522 space->PrepareForMarkCompact(); | 512 space->PrepareForMarkCompact(); |
523 } | 513 } |
524 | 514 |
525 #ifdef DEBUG | 515 #ifdef DEBUG |
526 if (!was_marked_incrementally_) { | 516 if (!was_marked_incrementally_ && FLAG_verify_heap) { |
527 VerifyMarkbitsAreClean(); | 517 VerifyMarkbitsAreClean(); |
528 } | 518 } |
529 #endif | 519 #endif |
530 | |
531 #ifdef DEBUG | |
532 live_bytes_ = 0; | |
533 live_young_objects_size_ = 0; | |
534 live_old_pointer_objects_size_ = 0; | |
535 live_old_data_objects_size_ = 0; | |
536 live_code_objects_size_ = 0; | |
537 live_map_objects_size_ = 0; | |
538 live_cell_objects_size_ = 0; | |
539 live_lo_objects_size_ = 0; | |
540 #endif | |
541 } | 520 } |
542 | 521 |
543 | 522 |
544 void MarkCompactCollector::Finish() { | 523 void MarkCompactCollector::Finish() { |
545 #ifdef DEBUG | 524 #ifdef DEBUG |
546 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS); | 525 ASSERT(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS); |
547 state_ = IDLE; | 526 state_ = IDLE; |
548 #endif | 527 #endif |
549 // The stub cache is not traversed during GC; clear the cache to | 528 // The stub cache is not traversed during GC; clear the cache to |
550 // force lazy re-initialization of it. This must be done after the | 529 // force lazy re-initialization of it. This must be done after the |
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2169 } | 2148 } |
2170 } | 2149 } |
2171 } | 2150 } |
2172 // Move to next element in the list. | 2151 // Move to next element in the list. |
2173 raw_context = context->get(Context::NEXT_CONTEXT_LINK); | 2152 raw_context = context->get(Context::NEXT_CONTEXT_LINK); |
2174 } | 2153 } |
2175 ProcessMarkingDeque(); | 2154 ProcessMarkingDeque(); |
2176 } | 2155 } |
2177 | 2156 |
2178 | 2157 |
2179 #ifdef DEBUG | |
2180 void MarkCompactCollector::UpdateLiveObjectCount(HeapObject* obj) { | |
2181 live_bytes_ += obj->Size(); | |
2182 if (heap()->new_space()->Contains(obj)) { | |
2183 live_young_objects_size_ += obj->Size(); | |
2184 } else if (heap()->map_space()->Contains(obj)) { | |
2185 ASSERT(obj->IsMap()); | |
2186 live_map_objects_size_ += obj->Size(); | |
2187 } else if (heap()->cell_space()->Contains(obj)) { | |
2188 ASSERT(obj->IsJSGlobalPropertyCell()); | |
2189 live_cell_objects_size_ += obj->Size(); | |
2190 } else if (heap()->old_pointer_space()->Contains(obj)) { | |
2191 live_old_pointer_objects_size_ += obj->Size(); | |
2192 } else if (heap()->old_data_space()->Contains(obj)) { | |
2193 live_old_data_objects_size_ += obj->Size(); | |
2194 } else if (heap()->code_space()->Contains(obj)) { | |
2195 live_code_objects_size_ += obj->Size(); | |
2196 } else if (heap()->lo_space()->Contains(obj)) { | |
2197 live_lo_objects_size_ += obj->Size(); | |
2198 } else { | |
2199 UNREACHABLE(); | |
2200 } | |
2201 } | |
2202 #endif // DEBUG | |
2203 | |
2204 | |
2205 void MarkCompactCollector::ReattachInitialMaps() { | 2158 void MarkCompactCollector::ReattachInitialMaps() { |
2206 HeapObjectIterator map_iterator(heap()->map_space()); | 2159 HeapObjectIterator map_iterator(heap()->map_space()); |
2207 for (HeapObject* obj = map_iterator.Next(); | 2160 for (HeapObject* obj = map_iterator.Next(); |
2208 obj != NULL; | 2161 obj != NULL; |
2209 obj = map_iterator.Next()) { | 2162 obj = map_iterator.Next()) { |
2210 if (obj->IsFreeSpace()) continue; | 2163 if (obj->IsFreeSpace()) continue; |
2211 Map* map = Map::cast(obj); | 2164 Map* map = Map::cast(obj); |
2212 | 2165 |
2213 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); | 2166 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
2214 if (map->instance_type() < FIRST_JS_RECEIVER_TYPE) continue; | 2167 if (map->instance_type() < FIRST_JS_RECEIVER_TYPE) continue; |
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3642 | 3595 |
3643 { GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP_NEWSPACE); | 3596 { GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP_NEWSPACE); |
3644 EvacuateNewSpaceAndCandidates(); | 3597 EvacuateNewSpaceAndCandidates(); |
3645 } | 3598 } |
3646 | 3599 |
3647 // ClearNonLiveTransitions depends on precise sweeping of map space to | 3600 // ClearNonLiveTransitions depends on precise sweeping of map space to |
3648 // detect whether unmarked map became dead in this collection or in one | 3601 // detect whether unmarked map became dead in this collection or in one |
3649 // of the previous ones. | 3602 // of the previous ones. |
3650 SweepSpace(heap()->map_space(), PRECISE); | 3603 SweepSpace(heap()->map_space(), PRECISE); |
3651 | 3604 |
3652 ASSERT(live_map_objects_size_ <= heap()->map_space()->Size()); | |
3653 | |
3654 // Deallocate unmarked objects and clear marked bits for marked objects. | 3605 // Deallocate unmarked objects and clear marked bits for marked objects. |
3655 heap_->lo_space()->FreeUnmarkedObjects(); | 3606 heap_->lo_space()->FreeUnmarkedObjects(); |
3656 } | 3607 } |
3657 | 3608 |
3658 | 3609 |
3659 void MarkCompactCollector::EnableCodeFlushing(bool enable) { | 3610 void MarkCompactCollector::EnableCodeFlushing(bool enable) { |
3660 if (enable) { | 3611 if (enable) { |
3661 if (code_flusher_ != NULL) return; | 3612 if (code_flusher_ != NULL) return; |
3662 code_flusher_ = new CodeFlusher(heap()->isolate()); | 3613 code_flusher_ = new CodeFlusher(heap()->isolate()); |
3663 } else { | 3614 } else { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3823 while (buffer != NULL) { | 3774 while (buffer != NULL) { |
3824 SlotsBuffer* next_buffer = buffer->next(); | 3775 SlotsBuffer* next_buffer = buffer->next(); |
3825 DeallocateBuffer(buffer); | 3776 DeallocateBuffer(buffer); |
3826 buffer = next_buffer; | 3777 buffer = next_buffer; |
3827 } | 3778 } |
3828 *buffer_address = NULL; | 3779 *buffer_address = NULL; |
3829 } | 3780 } |
3830 | 3781 |
3831 | 3782 |
3832 } } // namespace v8::internal | 3783 } } // namespace v8::internal |
OLD | NEW |