Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: src/heap/heap.h

Issue 1314863003: [heap] More flag cleanup. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added more comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap-snapshot-generator.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index a4ecdf7c79a55d913fe5d9b2eaaae261940eca8e..8cc286c7596b13986d2e3f005a6f116991fff7ff 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"
@@ -576,6 +577,26 @@ 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;
+
+ // A GC invocation always respects the passed flags. Upon finished the current
+ // cycle the previously set flags are either restored (kDontOverride), or
+ // overriden with the flags indicating no special behavior (kOverride).
+ 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),
@@ -598,6 +619,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 {
@@ -700,14 +751,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;
@@ -1267,22 +1310,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.
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);
- // 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();
@@ -1331,7 +1377,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);
@@ -1695,7 +1741,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());
@@ -1737,17 +1783,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();
@@ -2368,7 +2410,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.
« no previous file with comments | « src/heap-snapshot-generator.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698