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 |
11 #include "src/allocation.h" | 11 #include "src/allocation.h" |
12 #include "src/assert-scope.h" | 12 #include "src/assert-scope.h" |
| 13 #include "src/base/flags.h" |
13 #include "src/globals.h" | 14 #include "src/globals.h" |
14 #include "src/heap/gc-idle-time-handler.h" | 15 #include "src/heap/gc-idle-time-handler.h" |
15 #include "src/heap/incremental-marking.h" | 16 #include "src/heap/incremental-marking.h" |
16 #include "src/heap/mark-compact.h" | 17 #include "src/heap/mark-compact.h" |
17 #include "src/heap/objects-visiting.h" | 18 #include "src/heap/objects-visiting.h" |
18 #include "src/heap/spaces.h" | 19 #include "src/heap/spaces.h" |
19 #include "src/heap/store-buffer.h" | 20 #include "src/heap/store-buffer.h" |
20 #include "src/list.h" | 21 #include "src/list.h" |
21 | 22 |
22 namespace v8 { | 23 namespace v8 { |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 kStringTableRootIndex, | 603 kStringTableRootIndex, |
603 | 604 |
604 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, | 605 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, |
605 SMI_ROOT_LIST(ROOT_INDEX_DECLARATION) | 606 SMI_ROOT_LIST(ROOT_INDEX_DECLARATION) |
606 #undef ROOT_INDEX_DECLARATION | 607 #undef ROOT_INDEX_DECLARATION |
607 kRootListLength, | 608 kRootListLength, |
608 kStrongRootListLength = kStringTableRootIndex, | 609 kStrongRootListLength = kStringTableRootIndex, |
609 kSmiRootsStart = kStringTableRootIndex + 1 | 610 kSmiRootsStart = kStringTableRootIndex + 1 |
610 }; | 611 }; |
611 | 612 |
| 613 // Flags to indicate modes for a GC run. |
| 614 enum GCFlag { |
| 615 kNoGCFlags = 0u, |
| 616 kReduceMemoryFootprintMask = 1u << 0, |
| 617 kAbortIncrementalMarkingMask = 1u << 1, |
| 618 kFinalizeIncrementalMarkingMask = 1u << 2, |
| 619 |
| 620 // Making the heap iterable requires us to abort incremental marking. |
| 621 kMakeHeapIterableMask = kAbortIncrementalMarkingMask, |
| 622 }; |
| 623 typedef base::Flags<GCFlag> GCFlags; |
| 624 |
612 // Indicates whether live bytes adjustment is triggered | 625 // Indicates whether live bytes adjustment is triggered |
613 // - from within the GC code before sweeping started (SEQUENTIAL_TO_SWEEPER), | 626 // - from within the GC code before sweeping started (SEQUENTIAL_TO_SWEEPER), |
614 // - or from within GC (CONCURRENT_TO_SWEEPER), | 627 // - or from within GC (CONCURRENT_TO_SWEEPER), |
615 // - or mutator code (CONCURRENT_TO_SWEEPER). | 628 // - or mutator code (CONCURRENT_TO_SWEEPER). |
616 enum InvocationMode { SEQUENTIAL_TO_SWEEPER, CONCURRENT_TO_SWEEPER }; | 629 enum InvocationMode { SEQUENTIAL_TO_SWEEPER, CONCURRENT_TO_SWEEPER }; |
617 | 630 |
618 enum ScratchpadSlotMode { IGNORE_SCRATCHPAD_SLOT, RECORD_SCRATCHPAD_SLOT }; | 631 enum ScratchpadSlotMode { IGNORE_SCRATCHPAD_SLOT, RECORD_SCRATCHPAD_SLOT }; |
619 | 632 |
620 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; | 633 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; |
621 | 634 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // Strict mode arguments has no callee so it is smaller. | 739 // Strict mode arguments has no callee so it is smaller. |
727 static const int kStrictArgumentsObjectSize = | 740 static const int kStrictArgumentsObjectSize = |
728 JSObject::kHeaderSize + 1 * kPointerSize; | 741 JSObject::kHeaderSize + 1 * kPointerSize; |
729 | 742 |
730 // Indicies for direct access into argument objects. | 743 // Indicies for direct access into argument objects. |
731 static const int kArgumentsLengthIndex = 0; | 744 static const int kArgumentsLengthIndex = 0; |
732 | 745 |
733 // callee is only valid in sloppy mode. | 746 // callee is only valid in sloppy mode. |
734 static const int kArgumentsCalleeIndex = 1; | 747 static const int kArgumentsCalleeIndex = 1; |
735 | 748 |
736 static const int kNoGCFlags = 0; | |
737 static const int kReduceMemoryFootprintMask = 1; | |
738 static const int kAbortIncrementalMarkingMask = 2; | |
739 static const int kFinalizeIncrementalMarkingMask = 4; | |
740 | |
741 // Making the heap iterable requires us to abort incremental marking. | |
742 static const int kMakeHeapIterableMask = kAbortIncrementalMarkingMask; | |
743 | |
744 // The roots that have an index less than this are always in old space. | 749 // The roots that have an index less than this are always in old space. |
745 static const int kOldSpaceRoots = 0x20; | 750 static const int kOldSpaceRoots = 0x20; |
746 | 751 |
747 STATIC_ASSERT(kUndefinedValueRootIndex == | 752 STATIC_ASSERT(kUndefinedValueRootIndex == |
748 Internals::kUndefinedValueRootIndex); | 753 Internals::kUndefinedValueRootIndex); |
749 STATIC_ASSERT(kNullValueRootIndex == Internals::kNullValueRootIndex); | 754 STATIC_ASSERT(kNullValueRootIndex == Internals::kNullValueRootIndex); |
750 STATIC_ASSERT(kTrueValueRootIndex == Internals::kTrueValueRootIndex); | 755 STATIC_ASSERT(kTrueValueRootIndex == Internals::kTrueValueRootIndex); |
751 STATIC_ASSERT(kFalseValueRootIndex == Internals::kFalseValueRootIndex); | 756 STATIC_ASSERT(kFalseValueRootIndex == Internals::kFalseValueRootIndex); |
752 STATIC_ASSERT(kempty_stringRootIndex == Internals::kEmptyStringRootIndex); | 757 STATIC_ASSERT(kempty_stringRootIndex == Internals::kEmptyStringRootIndex); |
753 | 758 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 bool inline_allocation_disabled() { return inline_allocation_disabled_; } | 1310 bool inline_allocation_disabled() { return inline_allocation_disabled_; } |
1306 | 1311 |
1307 // Switch whether inline bump-pointer allocation should be used. | 1312 // Switch whether inline bump-pointer allocation should be used. |
1308 void EnableInlineAllocation(); | 1313 void EnableInlineAllocation(); |
1309 void DisableInlineAllocation(); | 1314 void DisableInlineAllocation(); |
1310 | 1315 |
1311 // =========================================================================== | 1316 // =========================================================================== |
1312 // Methods triggering GCs. =================================================== | 1317 // Methods triggering GCs. =================================================== |
1313 // =========================================================================== | 1318 // =========================================================================== |
1314 | 1319 |
1315 // Performs garbage collection operation. | 1320 // Perform a garbage collection operation in a given space. |
1316 // Returns whether there is a chance that another major GC could | 1321 // Returns whether there is a chance that another major GC could |
1317 // collect more garbage. | 1322 // collect more garbage. |
1318 inline bool CollectGarbage( | 1323 inline bool CollectGarbage( |
1319 AllocationSpace space, const char* gc_reason = NULL, | 1324 AllocationSpace space, const char* gc_reason = nullptr, |
1320 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1325 const GCFlags flags = kNoGCFlags, |
| 1326 const GCCallbackFlags callback_flags = kNoGCCallbackFlags); |
1321 | 1327 |
1322 // Performs a full garbage collection. If (flags & kMakeHeapIterableMask) is | 1328 // Performs a full garbage collection. |
1323 // non-zero, then the slower precise sweeper is used, which leaves the heap | |
1324 // in a state where we can iterate over the heap visiting all objects. | |
1325 void CollectAllGarbage( | 1329 void CollectAllGarbage( |
1326 int flags = kFinalizeIncrementalMarkingMask, const char* gc_reason = NULL, | 1330 const char* gc_reason = nullptr, |
| 1331 const GCFlags flags = Heap::kFinalizeIncrementalMarkingMask, |
1327 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1332 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1328 | 1333 |
1329 // Last hope GC, should try to squeeze as much as possible. | 1334 // Last hope GC, should try to squeeze as much as possible. |
1330 void CollectAllAvailableGarbage(const char* gc_reason = NULL); | 1335 void CollectAllAvailableGarbage(const char* gc_reason = nullptr); |
1331 | 1336 |
1332 // Invoked when GC was requested via the stack guard. | 1337 // Invoked when GC was requested via the stack guard. |
1333 void HandleGCRequest(); | 1338 void HandleGCRequest(); |
1334 | 1339 |
1335 // =========================================================================== | 1340 // =========================================================================== |
1336 // Iterators. ================================================================ | 1341 // Iterators. ================================================================ |
1337 // =========================================================================== | 1342 // =========================================================================== |
1338 | 1343 |
1339 // Iterates over all roots in the heap. | 1344 // Iterates over all roots in the heap. |
1340 void IterateRoots(ObjectVisitor* v, VisitMode mode); | 1345 void IterateRoots(ObjectVisitor* v, VisitMode mode); |
(...skipping 14 matching lines...) Expand all Loading... |
1355 // =========================================================================== | 1360 // =========================================================================== |
1356 // Incremental marking API. ================================================== | 1361 // Incremental marking API. ================================================== |
1357 // =========================================================================== | 1362 // =========================================================================== |
1358 | 1363 |
1359 // Start incremental marking and ensure that idle time handler can perform | 1364 // Start incremental marking and ensure that idle time handler can perform |
1360 // incremental steps. | 1365 // incremental steps. |
1361 void StartIdleIncrementalMarking(); | 1366 void StartIdleIncrementalMarking(); |
1362 | 1367 |
1363 // Starts incremental marking assuming incremental marking is currently | 1368 // Starts incremental marking assuming incremental marking is currently |
1364 // stopped. | 1369 // stopped. |
1365 void StartIncrementalMarking(int gc_flags = kNoGCFlags, | 1370 void StartIncrementalMarking(const GCFlags = kNoGCFlags, |
1366 const GCCallbackFlags gc_callback_flags = | 1371 const GCCallbackFlags gc_callback_flags = |
1367 GCCallbackFlags::kNoGCCallbackFlags, | 1372 GCCallbackFlags::kNoGCCallbackFlags, |
1368 const char* reason = nullptr); | 1373 const char* reason = nullptr); |
1369 | 1374 |
1370 // Performs incremental marking steps of step_size_in_bytes as long as | 1375 // Performs incremental marking steps of step_size_in_bytes as long as |
1371 // deadline_ins_ms is not reached. step_size_in_bytes can be 0 to compute | 1376 // deadline_ins_ms is not reached. step_size_in_bytes can be 0 to compute |
1372 // an estimate increment. Returns the remaining time that cannot be used | 1377 // an estimate increment. Returns the remaining time that cannot be used |
1373 // for incremental marking anymore because a single step would exceed the | 1378 // for incremental marking anymore because a single step would exceed the |
1374 // deadline. | 1379 // deadline. |
1375 double AdvanceIncrementalMarking( | 1380 double AdvanceIncrementalMarking( |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 static AllocationSpace SelectSpace(int object_size, PretenureFlag pretenure) { | 1669 static AllocationSpace SelectSpace(int object_size, PretenureFlag pretenure) { |
1665 if (object_size > Page::kMaxRegularHeapObjectSize) return LO_SPACE; | 1670 if (object_size > Page::kMaxRegularHeapObjectSize) return LO_SPACE; |
1666 return (pretenure == TENURED) ? OLD_SPACE : NEW_SPACE; | 1671 return (pretenure == TENURED) ? OLD_SPACE : NEW_SPACE; |
1667 } | 1672 } |
1668 | 1673 |
1669 #define ROOT_ACCESSOR(type, name, camel_name) \ | 1674 #define ROOT_ACCESSOR(type, name, camel_name) \ |
1670 inline void set_##name(type* value); | 1675 inline void set_##name(type* value); |
1671 ROOT_LIST(ROOT_ACCESSOR) | 1676 ROOT_LIST(ROOT_ACCESSOR) |
1672 #undef ROOT_ACCESSOR | 1677 #undef ROOT_ACCESSOR |
1673 | 1678 |
1674 void set_current_gc_flags(int flags) { | 1679 void set_current_gc_flags(GCFlags flags) { |
1675 current_gc_flags_ = flags; | 1680 current_gc_flags_ = flags; |
1676 DCHECK(!ShouldFinalizeIncrementalMarking() || | 1681 DCHECK(!ShouldFinalizeIncrementalMarking() || |
1677 !ShouldAbortIncrementalMarking()); | 1682 !ShouldAbortIncrementalMarking()); |
1678 } | 1683 } |
1679 | 1684 |
1680 inline bool ShouldReduceMemory() const { | 1685 inline bool ShouldReduceMemory() const { |
1681 return current_gc_flags_ & kReduceMemoryFootprintMask; | 1686 return current_gc_flags_ & kReduceMemoryFootprintMask; |
1682 } | 1687 } |
1683 | 1688 |
1684 inline bool ShouldAbortIncrementalMarking() const { | 1689 inline bool ShouldAbortIncrementalMarking() const { |
(...skipping 21 matching lines...) Expand all Loading... |
1706 // with the allocation memento of the object at the top | 1711 // with the allocation memento of the object at the top |
1707 void EnsureFillerObjectAtTop(); | 1712 void EnsureFillerObjectAtTop(); |
1708 | 1713 |
1709 // Ensure that we have swept all spaces in such a way that we can iterate | 1714 // Ensure that we have swept all spaces in such a way that we can iterate |
1710 // over all objects. May cause a GC. | 1715 // over all objects. May cause a GC. |
1711 void MakeHeapIterable(); | 1716 void MakeHeapIterable(); |
1712 | 1717 |
1713 // Performs garbage collection operation. | 1718 // Performs garbage collection operation. |
1714 // Returns whether there is a chance that another major GC could | 1719 // Returns whether there is a chance that another major GC could |
1715 // collect more garbage. | 1720 // collect more garbage. |
1716 bool CollectGarbage( | 1721 bool CollectGarbage(GarbageCollector collector, const char* gc_reason, |
1717 GarbageCollector collector, const char* gc_reason, | 1722 const char* collector_reason); |
1718 const char* collector_reason, | |
1719 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | |
1720 | 1723 |
1721 // Performs garbage collection | 1724 // Performs garbage collection |
1722 // Returns whether there is a chance another major GC could | 1725 // Returns whether there is a chance another major GC could |
1723 // collect more garbage. | 1726 // collect more garbage. |
1724 bool PerformGarbageCollection( | 1727 bool PerformGarbageCollection(GarbageCollector collector); |
1725 GarbageCollector collector, | |
1726 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | |
1727 | 1728 |
1728 inline void UpdateOldSpaceLimits(); | 1729 inline void UpdateOldSpaceLimits(); |
1729 | 1730 |
1730 // Initializes a JSObject based on its map. | 1731 // Initializes a JSObject based on its map. |
1731 void InitializeJSObjectFromMap(JSObject* obj, FixedArray* properties, | 1732 void InitializeJSObjectFromMap(JSObject* obj, FixedArray* properties, |
1732 Map* map); | 1733 Map* map); |
1733 void InitializeAllocationMemento(AllocationMemento* memento, | 1734 void InitializeAllocationMemento(AllocationMemento* memento, |
1734 AllocationSite* allocation_site); | 1735 AllocationSite* allocation_site); |
1735 | 1736 |
1736 bool CreateInitialMaps(); | 1737 bool CreateInitialMaps(); |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 size_t ring_buffer_end_; | 2337 size_t ring_buffer_end_; |
2337 | 2338 |
2338 // Shared state read by the scavenge collector and set by ScavengeObject. | 2339 // Shared state read by the scavenge collector and set by ScavengeObject. |
2339 PromotionQueue promotion_queue_; | 2340 PromotionQueue promotion_queue_; |
2340 | 2341 |
2341 // Flag is set when the heap has been configured. The heap can be repeatedly | 2342 // Flag is set when the heap has been configured. The heap can be repeatedly |
2342 // configured through the API until it is set up. | 2343 // configured through the API until it is set up. |
2343 bool configured_; | 2344 bool configured_; |
2344 | 2345 |
2345 // Currently set GC flags that are respected by all GC components. | 2346 // Currently set GC flags that are respected by all GC components. |
2346 int current_gc_flags_; | 2347 GCFlags current_gc_flags_; |
2347 | 2348 |
2348 // Currently set GC callback flags that are used to pass information between | 2349 // Currently set GC callback flags that are used to pass information between |
2349 // the embedder and V8's GC. | 2350 // the embedder and V8's GC. |
2350 GCCallbackFlags current_gc_callback_flags_; | 2351 GCCallbackFlags current_gc_callback_flags_; |
2351 | 2352 |
2352 ExternalStringTable external_string_table_; | 2353 ExternalStringTable external_string_table_; |
2353 | 2354 |
2354 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; | 2355 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
2355 | 2356 |
2356 MemoryChunk* chunks_queued_for_free_; | 2357 MemoryChunk* chunks_queued_for_free_; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2766 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2767 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2767 | 2768 |
2768 private: | 2769 private: |
2769 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2770 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2770 }; | 2771 }; |
2771 #endif // DEBUG | 2772 #endif // DEBUG |
2772 } | 2773 } |
2773 } // namespace v8::internal | 2774 } // namespace v8::internal |
2774 | 2775 |
2775 #endif // V8_HEAP_HEAP_H_ | 2776 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |