| 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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 mark_bit.Clear(); | 557 mark_bit.Clear(); |
| 558 mark_bit.Next().Clear(); | 558 mark_bit.Next().Clear(); |
| 559 Page::FromAddress(obj->address())->ResetProgressBar(); | 559 Page::FromAddress(obj->address())->ResetProgressBar(); |
| 560 Page::FromAddress(obj->address())->ResetLiveBytes(); | 560 Page::FromAddress(obj->address())->ResetLiveBytes(); |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 | 563 |
| 564 | 564 |
| 565 void MarkCompactCollector::StartSweeperThreads() { | 565 void MarkCompactCollector::StartSweeperThreads() { |
| 566 sweeping_pending_ = true; | 566 sweeping_pending_ = true; |
| 567 for (int i = 0; i < FLAG_sweeper_threads; i++) { | 567 for (int i = 0; i < isolate()->num_sweeper_threads(); i++) { |
| 568 isolate()->sweeper_threads()[i]->StartSweeping(); | 568 isolate()->sweeper_threads()[i]->StartSweeping(); |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 | 571 |
| 572 | 572 |
| 573 void MarkCompactCollector::WaitUntilSweepingCompleted() { | 573 void MarkCompactCollector::WaitUntilSweepingCompleted() { |
| 574 ASSERT(sweeping_pending_ == true); | 574 ASSERT(sweeping_pending_ == true); |
| 575 for (int i = 0; i < FLAG_sweeper_threads; i++) { | 575 for (int i = 0; i < isolate()->num_sweeper_threads(); i++) { |
| 576 isolate()->sweeper_threads()[i]->WaitForSweeperThread(); | 576 isolate()->sweeper_threads()[i]->WaitForSweeperThread(); |
| 577 } | 577 } |
| 578 sweeping_pending_ = false; | 578 sweeping_pending_ = false; |
| 579 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_DATA_SPACE)); | 579 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_DATA_SPACE)); |
| 580 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_POINTER_SPACE)); | 580 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_POINTER_SPACE)); |
| 581 heap()->paged_space(OLD_DATA_SPACE)->ResetUnsweptFreeBytes(); | 581 heap()->paged_space(OLD_DATA_SPACE)->ResetUnsweptFreeBytes(); |
| 582 heap()->paged_space(OLD_POINTER_SPACE)->ResetUnsweptFreeBytes(); | 582 heap()->paged_space(OLD_POINTER_SPACE)->ResetUnsweptFreeBytes(); |
| 583 } | 583 } |
| 584 | 584 |
| 585 | 585 |
| 586 intptr_t MarkCompactCollector:: | 586 intptr_t MarkCompactCollector:: |
| 587 StealMemoryFromSweeperThreads(PagedSpace* space) { | 587 StealMemoryFromSweeperThreads(PagedSpace* space) { |
| 588 intptr_t freed_bytes = 0; | 588 intptr_t freed_bytes = 0; |
| 589 for (int i = 0; i < FLAG_sweeper_threads; i++) { | 589 for (int i = 0; i < isolate()->num_sweeper_threads(); i++) { |
| 590 freed_bytes += isolate()->sweeper_threads()[i]->StealMemory(space); | 590 freed_bytes += isolate()->sweeper_threads()[i]->StealMemory(space); |
| 591 } | 591 } |
| 592 space->AddToAccountingStats(freed_bytes); | 592 space->AddToAccountingStats(freed_bytes); |
| 593 space->DecrementUnsweptFreeBytes(freed_bytes); | 593 space->DecrementUnsweptFreeBytes(freed_bytes); |
| 594 return freed_bytes; | 594 return freed_bytes; |
| 595 } | 595 } |
| 596 | 596 |
| 597 | 597 |
| 598 bool MarkCompactCollector::AreSweeperThreadsActivated() { | 598 bool MarkCompactCollector::AreSweeperThreadsActivated() { |
| 599 return isolate()->sweeper_threads() != NULL; | 599 return isolate()->sweeper_threads() != NULL; |
| (...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 // otherwise kept alive by strong references. | 2534 // otherwise kept alive by strong references. |
| 2535 HeapObjectIterator cell_iterator(heap_->property_cell_space()); | 2535 HeapObjectIterator cell_iterator(heap_->property_cell_space()); |
| 2536 for (HeapObject* cell = cell_iterator.Next(); | 2536 for (HeapObject* cell = cell_iterator.Next(); |
| 2537 cell != NULL; | 2537 cell != NULL; |
| 2538 cell = cell_iterator.Next()) { | 2538 cell = cell_iterator.Next()) { |
| 2539 if (IsMarked(cell)) { | 2539 if (IsMarked(cell)) { |
| 2540 ClearNonLiveDependentCode(PropertyCell::cast(cell)->dependent_code()); | 2540 ClearNonLiveDependentCode(PropertyCell::cast(cell)->dependent_code()); |
| 2541 } | 2541 } |
| 2542 } | 2542 } |
| 2543 | 2543 |
| 2544 // Iterate over allocation sites, removing dependent code that is not |
| 2545 // otherwise kept alive by strong references. |
| 2546 Object* undefined = heap()->undefined_value(); |
| 2547 for (Object* site = heap()->allocation_sites_list(); |
| 2548 site != undefined; |
| 2549 site = AllocationSite::cast(site)->weak_next()) { |
| 2550 if (IsMarked(site)) { |
| 2551 ClearNonLiveDependentCode(AllocationSite::cast(site)->dependent_code()); |
| 2552 } |
| 2553 } |
| 2554 |
| 2544 if (heap_->weak_object_to_code_table()->IsHashTable()) { | 2555 if (heap_->weak_object_to_code_table()->IsHashTable()) { |
| 2545 WeakHashTable* table = | 2556 WeakHashTable* table = |
| 2546 WeakHashTable::cast(heap_->weak_object_to_code_table()); | 2557 WeakHashTable::cast(heap_->weak_object_to_code_table()); |
| 2547 uint32_t capacity = table->Capacity(); | 2558 uint32_t capacity = table->Capacity(); |
| 2548 for (uint32_t i = 0; i < capacity; i++) { | 2559 for (uint32_t i = 0; i < capacity; i++) { |
| 2549 uint32_t key_index = table->EntryToIndex(i); | 2560 uint32_t key_index = table->EntryToIndex(i); |
| 2550 Object* key = table->get(key_index); | 2561 Object* key = table->get(key_index); |
| 2551 if (!table->IsKey(key)) continue; | 2562 if (!table->IsKey(key)) continue; |
| 2552 uint32_t value_index = table->EntryToValueIndex(i); | 2563 uint32_t value_index = table->EntryToValueIndex(i); |
| 2553 Object* value = table->get(value_index); | 2564 Object* value = table->get(value_index); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2637 int number_of_entries = starts.number_of_entries(); | 2648 int number_of_entries = starts.number_of_entries(); |
| 2638 if (number_of_entries == 0) return; | 2649 if (number_of_entries == 0) return; |
| 2639 for (int i = 0; i < number_of_entries; i++) { | 2650 for (int i = 0; i < number_of_entries; i++) { |
| 2640 // If the entry is compilation info then the map must be alive, | 2651 // If the entry is compilation info then the map must be alive, |
| 2641 // and ClearAndDeoptimizeDependentCode shouldn't be called. | 2652 // and ClearAndDeoptimizeDependentCode shouldn't be called. |
| 2642 ASSERT(entries->is_code_at(i)); | 2653 ASSERT(entries->is_code_at(i)); |
| 2643 Code* code = entries->code_at(i); | 2654 Code* code = entries->code_at(i); |
| 2644 | 2655 |
| 2645 if (IsMarked(code) && !code->marked_for_deoptimization()) { | 2656 if (IsMarked(code) && !code->marked_for_deoptimization()) { |
| 2646 code->set_marked_for_deoptimization(true); | 2657 code->set_marked_for_deoptimization(true); |
| 2658 code->InvalidateEmbeddedObjects(); |
| 2647 have_code_to_deoptimize_ = true; | 2659 have_code_to_deoptimize_ = true; |
| 2648 } | 2660 } |
| 2649 entries->clear_at(i); | 2661 entries->clear_at(i); |
| 2650 } | 2662 } |
| 2651 } | 2663 } |
| 2652 | 2664 |
| 2653 | 2665 |
| 2654 void MarkCompactCollector::ClearNonLiveDependentCode(DependentCode* entries) { | 2666 void MarkCompactCollector::ClearNonLiveDependentCode(DependentCode* entries) { |
| 2655 DisallowHeapAllocation no_allocation; | 2667 DisallowHeapAllocation no_allocation; |
| 2656 DependentCode::GroupStartIndexes starts(entries); | 2668 DependentCode::GroupStartIndexes starts(entries); |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4094 } | 4106 } |
| 4095 | 4107 |
| 4096 | 4108 |
| 4097 void MarkCompactCollector::SweepSpaces() { | 4109 void MarkCompactCollector::SweepSpaces() { |
| 4098 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP); | 4110 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP); |
| 4099 #ifdef DEBUG | 4111 #ifdef DEBUG |
| 4100 state_ = SWEEP_SPACES; | 4112 state_ = SWEEP_SPACES; |
| 4101 #endif | 4113 #endif |
| 4102 SweeperType how_to_sweep = | 4114 SweeperType how_to_sweep = |
| 4103 FLAG_lazy_sweeping ? LAZY_CONSERVATIVE : CONSERVATIVE; | 4115 FLAG_lazy_sweeping ? LAZY_CONSERVATIVE : CONSERVATIVE; |
| 4104 if (FLAG_parallel_sweeping) how_to_sweep = PARALLEL_CONSERVATIVE; | 4116 if (isolate()->num_sweeper_threads() > 0) { |
| 4105 if (FLAG_concurrent_sweeping) how_to_sweep = CONCURRENT_CONSERVATIVE; | 4117 if (FLAG_parallel_sweeping) how_to_sweep = PARALLEL_CONSERVATIVE; |
| 4118 if (FLAG_concurrent_sweeping) how_to_sweep = CONCURRENT_CONSERVATIVE; |
| 4119 } |
| 4106 if (FLAG_expose_gc) how_to_sweep = CONSERVATIVE; | 4120 if (FLAG_expose_gc) how_to_sweep = CONSERVATIVE; |
| 4107 if (sweep_precisely_) how_to_sweep = PRECISE; | 4121 if (sweep_precisely_) how_to_sweep = PRECISE; |
| 4108 | 4122 |
| 4109 // Unlink evacuation candidates before sweeper threads access the list of | 4123 // Unlink evacuation candidates before sweeper threads access the list of |
| 4110 // pages to avoid race condition. | 4124 // pages to avoid race condition. |
| 4111 UnlinkEvacuationCandidates(); | 4125 UnlinkEvacuationCandidates(); |
| 4112 | 4126 |
| 4113 // Noncompacting collections simply sweep the spaces to clear the mark | 4127 // Noncompacting collections simply sweep the spaces to clear the mark |
| 4114 // bits and free the nonlive blocks (for old and map spaces). We sweep | 4128 // bits and free the nonlive blocks (for old and map spaces). We sweep |
| 4115 // the map space last because freeing non-live maps overwrites them and | 4129 // the map space last because freeing non-live maps overwrites them and |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4351 while (buffer != NULL) { | 4365 while (buffer != NULL) { |
| 4352 SlotsBuffer* next_buffer = buffer->next(); | 4366 SlotsBuffer* next_buffer = buffer->next(); |
| 4353 DeallocateBuffer(buffer); | 4367 DeallocateBuffer(buffer); |
| 4354 buffer = next_buffer; | 4368 buffer = next_buffer; |
| 4355 } | 4369 } |
| 4356 *buffer_address = NULL; | 4370 *buffer_address = NULL; |
| 4357 } | 4371 } |
| 4358 | 4372 |
| 4359 | 4373 |
| 4360 } } // namespace v8::internal | 4374 } } // namespace v8::internal |
| OLD | NEW |