Chromium Code Reviews| Index: src/heap/heap.h |
| diff --git a/src/heap/heap.h b/src/heap/heap.h |
| index aa63a00650ea3c4e8074e0786a80fce06a84819e..4bb07e08f80ea750cdf60c90e1dc9a4f1219b128 100644 |
| --- a/src/heap/heap.h |
| +++ b/src/heap/heap.h |
| @@ -10,6 +10,7 @@ |
| #include "src/allocation.h" |
| #include "src/assert-scope.h" |
| +#include "src/base/flags.h" |
| #include "src/globals.h" |
| #include "src/heap/gc-idle-time-handler.h" |
| #include "src/heap/incremental-marking.h" |
| @@ -621,6 +622,23 @@ class Heap { |
| kSmiRootsStart = kStringTableRootIndex + 1 |
| }; |
| + // Flags to indicate modes for a GC run. |
| + enum GCFlag { |
| + kNoGCFlags = 0u, |
| + kReduceMemoryFootprintMask = 1u << 0, |
| + kAbortIncrementalMarkingMask = 1u << 1, |
| + kFinalizeIncrementalMarkingMask = 1u << 2, |
| + |
| + // Making the heap iterable requires us to abort incremental marking. |
| + kMakeHeapIterableMask = kAbortIncrementalMarkingMask, |
| + }; |
| + typedef base::Flags<GCFlag> GCFlags; |
| + |
| + enum GCFlagOverride { |
| + kOverride, |
| + kDontOverride, |
| + }; |
| + |
| // Indicates whether live bytes adjustment is triggered |
| // - from within the GC code before sweeping started (SEQUENTIAL_TO_SWEEPER), |
| // - or from within GC (CONCURRENT_TO_SWEEPER), |
| @@ -643,6 +661,36 @@ class Heap { |
| OBJECT_STATS_COUNT = FIRST_CODE_AGE_SUB_TYPE + Code::kCodeAgeCount + 1 |
| }; |
| + class GCFlagScope { |
| + public: |
| + GCFlagScope(Heap* heap, GCFlags gc_flags, GCCallbackFlags callback_flags, |
| + GCFlagOverride override) |
| + : heap_(heap), override_(override) { |
| + if (override_ == kDontOverride) { |
| + saved_gc_flags_ = heap->current_gc_flags_; |
| + saved_gc_callback_flags_ = heap->current_gc_callback_flags_; |
| + } |
| + heap->set_current_gc_flags(gc_flags); |
| + heap->current_gc_callback_flags_ = callback_flags; |
| + } |
| + |
| + ~GCFlagScope() { |
| + if (override_ == kDontOverride) { |
| + heap_->set_current_gc_flags(saved_gc_flags_); |
| + heap_->current_gc_callback_flags_ = saved_gc_callback_flags_; |
| + } else { |
| + heap_->set_current_gc_flags(kNoGCFlags); |
| + heap_->current_gc_callback_flags_ = kNoGCCallbackFlags; |
| + } |
| + } |
| + |
| + private: |
| + Heap* heap_; |
| + GCFlagOverride override_; |
| + GCFlags saved_gc_flags_; |
| + GCCallbackFlags saved_gc_callback_flags_; |
| + }; |
| + |
| // Taking this lock prevents the GC from entering a phase that relocates |
| // object references. |
| class RelocationLock { |
| @@ -745,14 +793,6 @@ class Heap { |
| // callee is only valid in sloppy mode. |
| static const int kArgumentsCalleeIndex = 1; |
| - static const int kNoGCFlags = 0; |
| - static const int kReduceMemoryFootprintMask = 1; |
| - static const int kAbortIncrementalMarkingMask = 2; |
| - static const int kFinalizeIncrementalMarkingMask = 4; |
| - |
| - // Making the heap iterable requires us to abort incremental marking. |
| - static const int kMakeHeapIterableMask = kAbortIncrementalMarkingMask; |
| - |
| // The roots that have an index less than this are always in old space. |
| static const int kOldSpaceRoots = 0x20; |
| @@ -1312,22 +1352,25 @@ class Heap { |
| // Methods triggering GCs. =================================================== |
| // =========================================================================== |
| - // Performs garbage collection operation. |
| + // Perform a garbage collection operation in a given space. |
| // Returns whether there is a chance that another major GC could |
| // collect more garbage. |
|
Hannes Payer (out of office)
2015/08/27 12:41:14
Explain in detail here how the flags work.
|
| inline bool CollectGarbage( |
| - AllocationSpace space, const char* gc_reason = NULL, |
| - const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
| + AllocationSpace space, const char* gc_reason = nullptr, |
| + const GCFlags flags = kNoGCFlags, |
| + const GCCallbackFlags callback_flags = kNoGCCallbackFlags, |
| + const GCFlagOverride override = kOverride); |
| + |
| + inline bool CollectGarbageNewSpace(const char* gc_reason = nullptr); |
|
Hannes Payer (out of office)
2015/08/27 12:41:14
Also mention here what impact the flags have.
|
| - // Performs a full garbage collection. If (flags & kMakeHeapIterableMask) is |
| - // non-zero, then the slower precise sweeper is used, which leaves the heap |
| - // in a state where we can iterate over the heap visiting all objects. |
| + // Performs a full garbage collection. |
| void CollectAllGarbage( |
| - int flags = kFinalizeIncrementalMarkingMask, const char* gc_reason = NULL, |
| + const char* gc_reason = nullptr, |
| + const GCFlags flags = Heap::kFinalizeIncrementalMarkingMask, |
| const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
| // Last hope GC, should try to squeeze as much as possible. |
| - void CollectAllAvailableGarbage(const char* gc_reason = NULL); |
| + void CollectAllAvailableGarbage(const char* gc_reason = nullptr); |
| // Invoked when GC was requested via the stack guard. |
| void HandleGCRequest(); |
| @@ -1376,7 +1419,7 @@ class Heap { |
| // Starts incremental marking assuming incremental marking is currently |
| // stopped. |
| - void StartIncrementalMarking(int gc_flags = kNoGCFlags, |
| + void StartIncrementalMarking(const GCFlags = kNoGCFlags, |
| const GCCallbackFlags gc_callback_flags = |
| GCCallbackFlags::kNoGCCallbackFlags, |
| const char* reason = nullptr); |
| @@ -1687,7 +1730,7 @@ class Heap { |
| StoreBuffer* store_buffer() { return &store_buffer_; } |
| - void set_current_gc_flags(int flags) { |
| + void set_current_gc_flags(GCFlags flags) { |
| current_gc_flags_ = flags; |
| DCHECK(!ShouldFinalizeIncrementalMarking() || |
| !ShouldAbortIncrementalMarking()); |
| @@ -1729,17 +1772,13 @@ class Heap { |
| // Performs garbage collection operation. |
| // Returns whether there is a chance that another major GC could |
| // collect more garbage. |
| - bool CollectGarbage( |
| - GarbageCollector collector, const char* gc_reason, |
| - const char* collector_reason, |
| - const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
| + bool CollectGarbage(GarbageCollector collector, const char* gc_reason, |
| + const char* collector_reason); |
| // Performs garbage collection |
| // Returns whether there is a chance another major GC could |
| // collect more garbage. |
| - bool PerformGarbageCollection( |
| - GarbageCollector collector, |
| - const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
| + bool PerformGarbageCollection(GarbageCollector collector); |
| inline void UpdateOldSpaceLimits(); |
| @@ -2359,7 +2398,7 @@ class Heap { |
| bool configured_; |
| // Currently set GC flags that are respected by all GC components. |
| - int current_gc_flags_; |
| + GCFlags current_gc_flags_; |
| // Currently set GC callback flags that are used to pass information between |
| // the embedder and V8's GC. |