OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 ->Increment(); | 279 ->Increment(); |
280 *reason = "scavenge might not succeed"; | 280 *reason = "scavenge might not succeed"; |
281 return MARK_COMPACTOR; | 281 return MARK_COMPACTOR; |
282 } | 282 } |
283 | 283 |
284 // Default | 284 // Default |
285 *reason = NULL; | 285 *reason = NULL; |
286 return YoungGenerationCollector(); | 286 return YoungGenerationCollector(); |
287 } | 287 } |
288 | 288 |
| 289 void Heap::SetGCState(HeapState state) { |
| 290 gc_state_ = state; |
| 291 store_buffer_->SetMode(gc_state_); |
| 292 } |
289 | 293 |
290 // TODO(1238405): Combine the infrastructure for --heap-stats and | 294 // TODO(1238405): Combine the infrastructure for --heap-stats and |
291 // --log-gc to avoid the complicated preprocessor and flag testing. | 295 // --log-gc to avoid the complicated preprocessor and flag testing. |
292 void Heap::ReportStatisticsBeforeGC() { | 296 void Heap::ReportStatisticsBeforeGC() { |
293 // Heap::ReportHeapStatistics will also log NewSpace statistics when | 297 // Heap::ReportHeapStatistics will also log NewSpace statistics when |
294 // compiled --log-gc is set. The following logic is used to avoid | 298 // compiled --log-gc is set. The following logic is used to avoid |
295 // double logging. | 299 // double logging. |
296 #ifdef DEBUG | 300 #ifdef DEBUG |
297 if (FLAG_heap_stats || FLAG_log_gc) new_space_->CollectStatistics(); | 301 if (FLAG_heap_stats || FLAG_log_gc) new_space_->CollectStatistics(); |
298 if (FLAG_heap_stats) { | 302 if (FLAG_heap_stats) { |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 gc_epilogue_callbacks_[i].callback(isolate, gc_type, gc_callback_flags); | 1426 gc_epilogue_callbacks_[i].callback(isolate, gc_type, gc_callback_flags); |
1423 } | 1427 } |
1424 } | 1428 } |
1425 } | 1429 } |
1426 } | 1430 } |
1427 | 1431 |
1428 | 1432 |
1429 void Heap::MarkCompact() { | 1433 void Heap::MarkCompact() { |
1430 PauseAllocationObserversScope pause_observers(this); | 1434 PauseAllocationObserversScope pause_observers(this); |
1431 | 1435 |
1432 gc_state_ = MARK_COMPACT; | 1436 SetGCState(MARK_COMPACT); |
| 1437 |
1433 LOG(isolate_, ResourceEvent("markcompact", "begin")); | 1438 LOG(isolate_, ResourceEvent("markcompact", "begin")); |
1434 | 1439 |
1435 uint64_t size_of_objects_before_gc = SizeOfObjects(); | 1440 uint64_t size_of_objects_before_gc = SizeOfObjects(); |
1436 | 1441 |
1437 mark_compact_collector()->Prepare(); | 1442 mark_compact_collector()->Prepare(); |
1438 | 1443 |
1439 ms_count_++; | 1444 ms_count_++; |
1440 | 1445 |
1441 MarkCompactPrologue(); | 1446 MarkCompactPrologue(); |
1442 | 1447 |
1443 mark_compact_collector()->CollectGarbage(); | 1448 mark_compact_collector()->CollectGarbage(); |
1444 | 1449 |
1445 LOG(isolate_, ResourceEvent("markcompact", "end")); | 1450 LOG(isolate_, ResourceEvent("markcompact", "end")); |
1446 | 1451 |
1447 MarkCompactEpilogue(); | 1452 MarkCompactEpilogue(); |
1448 | 1453 |
1449 if (FLAG_allocation_site_pretenuring) { | 1454 if (FLAG_allocation_site_pretenuring) { |
1450 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); | 1455 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); |
1451 } | 1456 } |
1452 } | 1457 } |
1453 | 1458 |
1454 void Heap::MinorMarkCompact() { UNREACHABLE(); } | 1459 void Heap::MinorMarkCompact() { UNREACHABLE(); } |
1455 | 1460 |
1456 void Heap::MarkCompactEpilogue() { | 1461 void Heap::MarkCompactEpilogue() { |
1457 TRACE_GC(tracer(), GCTracer::Scope::MC_EPILOGUE); | 1462 TRACE_GC(tracer(), GCTracer::Scope::MC_EPILOGUE); |
1458 gc_state_ = NOT_IN_GC; | 1463 SetGCState(NOT_IN_GC); |
1459 | 1464 |
1460 isolate_->counters()->objs_since_last_full()->Set(0); | 1465 isolate_->counters()->objs_since_last_full()->Set(0); |
1461 | 1466 |
1462 incremental_marking()->Epilogue(); | 1467 incremental_marking()->Epilogue(); |
1463 | 1468 |
1464 PreprocessStackTraces(); | 1469 PreprocessStackTraces(); |
1465 DCHECK(incremental_marking()->IsStopped()); | 1470 DCHECK(incremental_marking()->IsStopped()); |
1466 | 1471 |
1467 mark_compact_collector()->marking_deque()->StopUsing(); | 1472 mark_compact_collector()->marking_deque()->StopUsing(); |
1468 } | 1473 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 // sweep collection by failing allocations. There is no sense in trying to | 1584 // sweep collection by failing allocations. There is no sense in trying to |
1580 // trigger one during scavenge: scavenges allocation should always succeed. | 1585 // trigger one during scavenge: scavenges allocation should always succeed. |
1581 AlwaysAllocateScope scope(isolate()); | 1586 AlwaysAllocateScope scope(isolate()); |
1582 | 1587 |
1583 // Bump-pointer allocations done during scavenge are not real allocations. | 1588 // Bump-pointer allocations done during scavenge are not real allocations. |
1584 // Pause the inline allocation steps. | 1589 // Pause the inline allocation steps. |
1585 PauseAllocationObserversScope pause_observers(this); | 1590 PauseAllocationObserversScope pause_observers(this); |
1586 | 1591 |
1587 mark_compact_collector()->sweeper().EnsureNewSpaceCompleted(); | 1592 mark_compact_collector()->sweeper().EnsureNewSpaceCompleted(); |
1588 | 1593 |
1589 gc_state_ = SCAVENGE; | 1594 SetGCState(SCAVENGE); |
1590 | 1595 |
1591 // Implements Cheney's copying algorithm | 1596 // Implements Cheney's copying algorithm |
1592 LOG(isolate_, ResourceEvent("scavenge", "begin")); | 1597 LOG(isolate_, ResourceEvent("scavenge", "begin")); |
1593 | 1598 |
1594 // Used for updating survived_since_last_expansion_ at function end. | 1599 // Used for updating survived_since_last_expansion_ at function end. |
1595 size_t survived_watermark = PromotedSpaceSizeOfObjects(); | 1600 size_t survived_watermark = PromotedSpaceSizeOfObjects(); |
1596 | 1601 |
1597 scavenge_collector_->SelectScavengingVisitorsTable(); | 1602 scavenge_collector_->SelectScavengingVisitorsTable(); |
1598 | 1603 |
1599 if (UsingEmbedderHeapTracer()) { | 1604 if (UsingEmbedderHeapTracer()) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 | 1710 |
1706 ArrayBufferTracker::FreeDeadInNewSpace(this); | 1711 ArrayBufferTracker::FreeDeadInNewSpace(this); |
1707 | 1712 |
1708 // Update how much has survived scavenge. | 1713 // Update how much has survived scavenge. |
1709 DCHECK_GE(PromotedSpaceSizeOfObjects(), survived_watermark); | 1714 DCHECK_GE(PromotedSpaceSizeOfObjects(), survived_watermark); |
1710 IncrementYoungSurvivorsCounter(PromotedSpaceSizeOfObjects() + | 1715 IncrementYoungSurvivorsCounter(PromotedSpaceSizeOfObjects() + |
1711 new_space_->Size() - survived_watermark); | 1716 new_space_->Size() - survived_watermark); |
1712 | 1717 |
1713 LOG(isolate_, ResourceEvent("scavenge", "end")); | 1718 LOG(isolate_, ResourceEvent("scavenge", "end")); |
1714 | 1719 |
1715 gc_state_ = NOT_IN_GC; | 1720 SetGCState(NOT_IN_GC); |
1716 } | 1721 } |
1717 | 1722 |
1718 | 1723 |
1719 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, | 1724 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, |
1720 Object** p) { | 1725 Object** p) { |
1721 MapWord first_word = HeapObject::cast(*p)->map_word(); | 1726 MapWord first_word = HeapObject::cast(*p)->map_word(); |
1722 | 1727 |
1723 if (!first_word.IsForwardingAddress()) { | 1728 if (!first_word.IsForwardingAddress()) { |
1724 // Unreachable external string can be finalized. | 1729 // Unreachable external string can be finalized. |
1725 heap->FinalizeExternalString(String::cast(*p)); | 1730 heap->FinalizeExternalString(String::cast(*p)); |
(...skipping 4750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6476 } | 6481 } |
6477 | 6482 |
6478 | 6483 |
6479 // static | 6484 // static |
6480 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6485 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6481 return StaticVisitorBase::GetVisitorId(map); | 6486 return StaticVisitorBase::GetVisitorId(map); |
6482 } | 6487 } |
6483 | 6488 |
6484 } // namespace internal | 6489 } // namespace internal |
6485 } // namespace v8 | 6490 } // namespace v8 |
OLD | NEW |