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 #ifndef V8_HEAP_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 341 |
342 enum ArrayStorageAllocationMode { | 342 enum ArrayStorageAllocationMode { |
343 DONT_INITIALIZE_ARRAY_ELEMENTS, | 343 DONT_INITIALIZE_ARRAY_ELEMENTS, |
344 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 344 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
345 }; | 345 }; |
346 | 346 |
347 enum class ClearRecordedSlots { kYes, kNo }; | 347 enum class ClearRecordedSlots { kYes, kNo }; |
348 | 348 |
349 enum class ClearBlackArea { kYes, kNo }; | 349 enum class ClearBlackArea { kYes, kNo }; |
350 | 350 |
| 351 enum class GarbageCollectionReason { |
| 352 kUnknown, |
| 353 kAllocationFailure, |
| 354 kAllocationLimit, |
| 355 kContextDisposal, |
| 356 kCountersExtension, |
| 357 kDebugger, |
| 358 kDeserializer, |
| 359 kExternalMemoryPressure, |
| 360 kFinalizeMarkingViaStackGuard, |
| 361 kFinalizeMarkingViaTask, |
| 362 kFullHashtable, |
| 363 kHeapProfiler, |
| 364 kIdleTask, |
| 365 kLastResort, |
| 366 kLowMemoryNotification, |
| 367 kMakeHeapIterable, |
| 368 kMemoryPressure, |
| 369 kMemoryReducer, |
| 370 kRuntime, |
| 371 kSamplingProfiler, |
| 372 kSnapshotCreator, |
| 373 kTesting |
| 374 }; |
| 375 |
351 // A queue of objects promoted during scavenge. Each object is accompanied by | 376 // A queue of objects promoted during scavenge. Each object is accompanied by |
352 // its size to avoid dereferencing a map pointer for scanning. The last page in | 377 // its size to avoid dereferencing a map pointer for scanning. The last page in |
353 // to-space is used for the promotion queue. On conflict during scavenge, the | 378 // to-space is used for the promotion queue. On conflict during scavenge, the |
354 // promotion queue is allocated externally and all entries are copied to the | 379 // promotion queue is allocated externally and all entries are copied to the |
355 // external queue. | 380 // external queue. |
356 class PromotionQueue { | 381 class PromotionQueue { |
357 public: | 382 public: |
358 explicit PromotionQueue(Heap* heap) | 383 explicit PromotionQueue(Heap* heap) |
359 : front_(nullptr), | 384 : front_(nullptr), |
360 rear_(nullptr), | 385 rear_(nullptr), |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 void DisableInlineAllocation(); | 1097 void DisableInlineAllocation(); |
1073 | 1098 |
1074 // =========================================================================== | 1099 // =========================================================================== |
1075 // Methods triggering GCs. =================================================== | 1100 // Methods triggering GCs. =================================================== |
1076 // =========================================================================== | 1101 // =========================================================================== |
1077 | 1102 |
1078 // Performs garbage collection operation. | 1103 // Performs garbage collection operation. |
1079 // Returns whether there is a chance that another major GC could | 1104 // Returns whether there is a chance that another major GC could |
1080 // collect more garbage. | 1105 // collect more garbage. |
1081 inline bool CollectGarbage( | 1106 inline bool CollectGarbage( |
1082 AllocationSpace space, const char* gc_reason = NULL, | 1107 AllocationSpace space, GarbageCollectionReason gc_reason, |
1083 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1108 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1084 | 1109 |
1085 // Performs a full garbage collection. If (flags & kMakeHeapIterableMask) is | 1110 // Performs a full garbage collection. If (flags & kMakeHeapIterableMask) is |
1086 // non-zero, then the slower precise sweeper is used, which leaves the heap | 1111 // non-zero, then the slower precise sweeper is used, which leaves the heap |
1087 // in a state where we can iterate over the heap visiting all objects. | 1112 // in a state where we can iterate over the heap visiting all objects. |
1088 void CollectAllGarbage( | 1113 void CollectAllGarbage( |
1089 int flags = kFinalizeIncrementalMarkingMask, const char* gc_reason = NULL, | 1114 int flags, GarbageCollectionReason gc_reason, |
1090 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1115 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1091 | 1116 |
1092 // Last hope GC, should try to squeeze as much as possible. | 1117 // Last hope GC, should try to squeeze as much as possible. |
1093 void CollectAllAvailableGarbage(const char* gc_reason = NULL); | 1118 void CollectAllAvailableGarbage(GarbageCollectionReason gc_reason); |
1094 | 1119 |
1095 // Reports and external memory pressure event, either performs a major GC or | 1120 // Reports and external memory pressure event, either performs a major GC or |
1096 // completes incremental marking in order to free external resources. | 1121 // completes incremental marking in order to free external resources. |
1097 void ReportExternalMemoryPressure(const char* gc_reason = NULL); | 1122 void ReportExternalMemoryPressure(); |
1098 | 1123 |
1099 // Invoked when GC was requested via the stack guard. | 1124 // Invoked when GC was requested via the stack guard. |
1100 void HandleGCRequest(); | 1125 void HandleGCRequest(); |
1101 | 1126 |
1102 // =========================================================================== | 1127 // =========================================================================== |
1103 // Iterators. ================================================================ | 1128 // Iterators. ================================================================ |
1104 // =========================================================================== | 1129 // =========================================================================== |
1105 | 1130 |
1106 // Iterates over all roots in the heap. | 1131 // Iterates over all roots in the heap. |
1107 void IterateRoots(ObjectVisitor* v, VisitMode mode); | 1132 void IterateRoots(ObjectVisitor* v, VisitMode mode); |
(...skipping 30 matching lines...) Expand all Loading... |
1138 | 1163 |
1139 void ClearRecordedSlot(HeapObject* object, Object** slot); | 1164 void ClearRecordedSlot(HeapObject* object, Object** slot); |
1140 void ClearRecordedSlotRange(Address start, Address end); | 1165 void ClearRecordedSlotRange(Address start, Address end); |
1141 | 1166 |
1142 // =========================================================================== | 1167 // =========================================================================== |
1143 // Incremental marking API. ================================================== | 1168 // Incremental marking API. ================================================== |
1144 // =========================================================================== | 1169 // =========================================================================== |
1145 | 1170 |
1146 // Start incremental marking and ensure that idle time handler can perform | 1171 // Start incremental marking and ensure that idle time handler can perform |
1147 // incremental steps. | 1172 // incremental steps. |
1148 void StartIdleIncrementalMarking(); | 1173 void StartIdleIncrementalMarking(GarbageCollectionReason gc_reason); |
1149 | 1174 |
1150 // Starts incremental marking assuming incremental marking is currently | 1175 // Starts incremental marking assuming incremental marking is currently |
1151 // stopped. | 1176 // stopped. |
1152 void StartIncrementalMarking(int gc_flags = kNoGCFlags, | 1177 void StartIncrementalMarking( |
1153 const GCCallbackFlags gc_callback_flags = | 1178 int gc_flags, GarbageCollectionReason gc_reason, |
1154 GCCallbackFlags::kNoGCCallbackFlags, | 1179 GCCallbackFlags gc_callback_flags = GCCallbackFlags::kNoGCCallbackFlags); |
1155 const char* reason = nullptr); | |
1156 | 1180 |
1157 void StartIncrementalMarkingIfNeeded(int gc_flags = kNoGCFlags, | 1181 void StartIncrementalMarkingIfAllocationLimitIsReached( |
1158 const GCCallbackFlags gc_callback_flags = | 1182 int gc_flags, |
1159 GCCallbackFlags::kNoGCCallbackFlags, | 1183 GCCallbackFlags gc_callback_flags = GCCallbackFlags::kNoGCCallbackFlags); |
1160 const char* reason = nullptr); | |
1161 | 1184 |
1162 void FinalizeIncrementalMarkingIfComplete(const char* comment); | 1185 void FinalizeIncrementalMarkingIfComplete(GarbageCollectionReason gc_reason); |
1163 | 1186 |
1164 bool TryFinalizeIdleIncrementalMarking(double idle_time_in_ms); | 1187 bool TryFinalizeIdleIncrementalMarking(double idle_time_in_ms, |
| 1188 GarbageCollectionReason gc_reason); |
1165 | 1189 |
1166 void RegisterReservationsForBlackAllocation(Reservation* reservations); | 1190 void RegisterReservationsForBlackAllocation(Reservation* reservations); |
1167 | 1191 |
1168 IncrementalMarking* incremental_marking() { return incremental_marking_; } | 1192 IncrementalMarking* incremental_marking() { return incremental_marking_; } |
1169 | 1193 |
1170 // =========================================================================== | 1194 // =========================================================================== |
1171 // Embedder heap tracer support. ============================================= | 1195 // Embedder heap tracer support. ============================================= |
1172 // =========================================================================== | 1196 // =========================================================================== |
1173 | 1197 |
1174 void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); | 1198 void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 void TracePathToGlobal(); | 1475 void TracePathToGlobal(); |
1452 | 1476 |
1453 void Print(); | 1477 void Print(); |
1454 void PrintHandles(); | 1478 void PrintHandles(); |
1455 | 1479 |
1456 // Report heap statistics. | 1480 // Report heap statistics. |
1457 void ReportHeapStatistics(const char* title); | 1481 void ReportHeapStatistics(const char* title); |
1458 void ReportCodeStatistics(const char* title); | 1482 void ReportCodeStatistics(const char* title); |
1459 #endif | 1483 #endif |
1460 | 1484 |
| 1485 static const char* GarbageCollectionReasonToString( |
| 1486 GarbageCollectionReason gc_reason); |
| 1487 |
1461 private: | 1488 private: |
1462 class PretenuringScope; | 1489 class PretenuringScope; |
1463 | 1490 |
1464 // External strings table is a place where all external strings are | 1491 // External strings table is a place where all external strings are |
1465 // registered. We need to keep track of such strings to properly | 1492 // registered. We need to keep track of such strings to properly |
1466 // finalize them. | 1493 // finalize them. |
1467 class ExternalStringTable { | 1494 class ExternalStringTable { |
1468 public: | 1495 public: |
1469 // Registers an external string. | 1496 // Registers an external string. |
1470 inline void AddString(String* string); | 1497 inline void AddString(String* string); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 void EnsureFillerObjectAtTop(); | 1633 void EnsureFillerObjectAtTop(); |
1607 | 1634 |
1608 // Ensure that we have swept all spaces in such a way that we can iterate | 1635 // Ensure that we have swept all spaces in such a way that we can iterate |
1609 // over all objects. May cause a GC. | 1636 // over all objects. May cause a GC. |
1610 void MakeHeapIterable(); | 1637 void MakeHeapIterable(); |
1611 | 1638 |
1612 // Performs garbage collection operation. | 1639 // Performs garbage collection operation. |
1613 // Returns whether there is a chance that another major GC could | 1640 // Returns whether there is a chance that another major GC could |
1614 // collect more garbage. | 1641 // collect more garbage. |
1615 bool CollectGarbage( | 1642 bool CollectGarbage( |
1616 GarbageCollector collector, const char* gc_reason, | 1643 GarbageCollector collector, GarbageCollectionReason gc_reason, |
1617 const char* collector_reason, | 1644 const char* collector_reason, |
1618 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1645 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1619 | 1646 |
1620 // Performs garbage collection | 1647 // Performs garbage collection |
1621 // Returns whether there is a chance another major GC could | 1648 // Returns whether there is a chance another major GC could |
1622 // collect more garbage. | 1649 // collect more garbage. |
1623 bool PerformGarbageCollection( | 1650 bool PerformGarbageCollection( |
1624 GarbageCollector collector, | 1651 GarbageCollector collector, |
1625 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1652 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1626 | 1653 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 | 1708 |
1682 void ConfigureInitialOldGenerationSize(); | 1709 void ConfigureInitialOldGenerationSize(); |
1683 | 1710 |
1684 bool HasLowYoungGenerationAllocationRate(); | 1711 bool HasLowYoungGenerationAllocationRate(); |
1685 bool HasLowOldGenerationAllocationRate(); | 1712 bool HasLowOldGenerationAllocationRate(); |
1686 double YoungGenerationMutatorUtilization(); | 1713 double YoungGenerationMutatorUtilization(); |
1687 double OldGenerationMutatorUtilization(); | 1714 double OldGenerationMutatorUtilization(); |
1688 | 1715 |
1689 void ReduceNewSpaceSize(); | 1716 void ReduceNewSpaceSize(); |
1690 | 1717 |
1691 bool TryFinalizeIdleIncrementalMarking( | |
1692 double idle_time_in_ms, size_t size_of_objects, | |
1693 size_t mark_compact_speed_in_bytes_per_ms); | |
1694 | |
1695 GCIdleTimeHeapState ComputeHeapState(); | 1718 GCIdleTimeHeapState ComputeHeapState(); |
1696 | 1719 |
1697 bool PerformIdleTimeAction(GCIdleTimeAction action, | 1720 bool PerformIdleTimeAction(GCIdleTimeAction action, |
1698 GCIdleTimeHeapState heap_state, | 1721 GCIdleTimeHeapState heap_state, |
1699 double deadline_in_ms); | 1722 double deadline_in_ms); |
1700 | 1723 |
1701 void IdleNotificationEpilogue(GCIdleTimeAction action, | 1724 void IdleNotificationEpilogue(GCIdleTimeAction action, |
1702 GCIdleTimeHeapState heap_state, double start_ms, | 1725 GCIdleTimeHeapState heap_state, double start_ms, |
1703 double deadline_in_ms); | 1726 double deadline_in_ms); |
1704 | 1727 |
1705 inline void UpdateAllocationsHash(HeapObject* object); | 1728 inline void UpdateAllocationsHash(HeapObject* object); |
1706 inline void UpdateAllocationsHash(uint32_t value); | 1729 inline void UpdateAllocationsHash(uint32_t value); |
1707 void PrintAlloctionsHash(); | 1730 void PrintAlloctionsHash(); |
1708 | 1731 |
1709 void AddToRingBuffer(const char* string); | 1732 void AddToRingBuffer(const char* string); |
1710 void GetFromRingBuffer(char* buffer); | 1733 void GetFromRingBuffer(char* buffer); |
1711 | 1734 |
1712 void CompactRetainedMaps(ArrayList* retained_maps); | 1735 void CompactRetainedMaps(ArrayList* retained_maps); |
1713 | 1736 |
1714 void CollectGarbageOnMemoryPressure(const char* source); | 1737 void CollectGarbageOnMemoryPressure(); |
1715 | 1738 |
1716 // Attempt to over-approximate the weak closure by marking object groups and | 1739 // Attempt to over-approximate the weak closure by marking object groups and |
1717 // implicit references from global handles, but don't atomically complete | 1740 // implicit references from global handles, but don't atomically complete |
1718 // marking. If we continue to mark incrementally, we might have marked | 1741 // marking. If we continue to mark incrementally, we might have marked |
1719 // objects that die later. | 1742 // objects that die later. |
1720 void FinalizeIncrementalMarking(const char* gc_reason); | 1743 void FinalizeIncrementalMarking(GarbageCollectionReason gc_reason); |
1721 | 1744 |
1722 // Returns the timer used for a given GC type. | 1745 // Returns the timer used for a given GC type. |
1723 // - GCScavenger: young generation GC | 1746 // - GCScavenger: young generation GC |
1724 // - GCCompactor: full GC | 1747 // - GCCompactor: full GC |
1725 // - GCFinalzeMC: finalization of incremental full GC | 1748 // - GCFinalzeMC: finalization of incremental full GC |
1726 // - GCFinalizeMCReduceMemory: finalization of incremental full GC with | 1749 // - GCFinalizeMCReduceMemory: finalization of incremental full GC with |
1727 // memory reduction | 1750 // memory reduction |
1728 HistogramTimer* GCTypeTimer(GarbageCollector collector); | 1751 HistogramTimer* GCTypeTimer(GarbageCollector collector); |
1729 | 1752 |
1730 // =========================================================================== | 1753 // =========================================================================== |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2612 friend class LargeObjectSpace; | 2635 friend class LargeObjectSpace; |
2613 friend class NewSpace; | 2636 friend class NewSpace; |
2614 friend class PagedSpace; | 2637 friend class PagedSpace; |
2615 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); | 2638 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); |
2616 }; | 2639 }; |
2617 | 2640 |
2618 } // namespace internal | 2641 } // namespace internal |
2619 } // namespace v8 | 2642 } // namespace v8 |
2620 | 2643 |
2621 #endif // V8_HEAP_HEAP_H_ | 2644 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |