Commit 17fe92fa authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Oilpan: Introduce GCPhase

Introducing the GCPhase enum. In the future, this will be used to simplify the GCState into just handling the next scheduled GC. Right now this isn't connected to anything yet.

Bug: 757440
Change-Id: If91c6d11c2ee0f53e50633b9c74475f8dc256952
Reviewed-on: https://chromium-review.googlesource.com/979374Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545764}
parent 3c4c7fde
......@@ -508,12 +508,15 @@ void ThreadHeap::ReportMemoryUsageForTracing() {
size_t ThreadHeap::ObjectPayloadSizeForTesting() {
size_t object_payload_size = 0;
thread_state_->SetGCState(ThreadState::kGCRunning);
thread_state_->SetGCPhase(ThreadState::GCPhase::kMarking);
thread_state_->Heap().MakeConsistentForGC();
thread_state_->Heap().PrepareForSweep();
for (int i = 0; i < BlinkGC::kNumberOfArenas; ++i)
object_payload_size += arenas_[i]->ObjectPayloadSizeForTesting();
MakeConsistentForMutator();
thread_state_->SetGCPhase(ThreadState::GCPhase::kSweeping);
thread_state_->SetGCState(ThreadState::kSweeping);
thread_state_->SetGCPhase(ThreadState::GCPhase::kNone);
thread_state_->SetGCState(ThreadState::kNoGCScheduled);
return object_payload_size;
}
......
......@@ -156,6 +156,7 @@ ThreadState::ThreadState()
object_resurrection_forbidden_(false),
gc_mixin_marker_(nullptr),
gc_state_(kNoGCScheduled),
gc_phase_(GCPhase::kNone),
isolate_(nullptr),
trace_dom_wrappers_(nullptr),
invalidate_dead_objects_in_wrappers_marking_deque_(nullptr),
......@@ -810,6 +811,21 @@ void ThreadState::SetGCState(GCState gc_state) {
#undef VERIFY_STATE_TRANSITION
void ThreadState::SetGCPhase(GCPhase gc_phase) {
switch (gc_phase) {
case GCPhase::kNone:
DCHECK_EQ(gc_phase_, GCPhase::kSweeping);
break;
case GCPhase::kMarking:
DCHECK_EQ(gc_phase_, GCPhase::kNone);
break;
case GCPhase::kSweeping:
DCHECK_EQ(gc_phase_, GCPhase::kMarking);
break;
}
gc_phase_ = gc_phase;
}
void ThreadState::RunScheduledGC(BlinkGC::StackState stack_state) {
DCHECK(CheckThread());
if (stack_state != BlinkGC::kNoHeapPointersOnStack)
......@@ -872,12 +888,15 @@ void ThreadState::PreSweep(BlinkGC::MarkingType marking_type,
// Force setting NoGCScheduled to circumvent checkThread()
// in setGCState().
gc_state_ = kNoGCScheduled;
SetGCPhase(GCPhase::kSweeping);
SetGCPhase(GCPhase::kNone);
return;
}
// We have to set the GCState to Sweeping before calling pre-finalizers
// to disallow a GC during the pre-finalizers.
SetGCState(kSweeping);
SetGCPhase(GCPhase::kSweeping);
// Allocation is allowed during the pre-finalizers and destructors.
// However, they must not mutate an object graph in a way in which
......@@ -1032,6 +1051,7 @@ void ThreadState::PostSweep() {
}
}
SetGCPhase(GCPhase::kNone);
switch (GcState()) {
case kSweeping:
SetGCState(kNoGCScheduled);
......@@ -1333,6 +1353,7 @@ void ThreadState::CollectGarbage(BlinkGC::StackState stack_state,
void ThreadState::MarkPhasePrologue(BlinkGC::StackState stack_state,
BlinkGC::MarkingType marking_type,
BlinkGC::GCReason reason) {
SetGCPhase(GCPhase::kMarking);
Heap().CommitCallbackStacks();
current_gc_data_.stack_state = stack_state;
......
......@@ -155,6 +155,18 @@ class PLATFORM_EXPORT ThreadState {
kSweepingAndPreciseGCScheduled,
};
// The phase that the GC is in. The GCPhase will not return kNone for mutators
// running during incremental marking and lazy sweeping. See SetGCPhase() for
// possible state transitions.
enum class GCPhase {
// GC is doing nothing.
kNone,
// GC is in marking phase.
kMarking,
// GC is in sweeping phase.
kSweeping,
};
// The NoAllocationScope class is used in debug mode to catch unwanted
// allocations. E.g. allocations during GC.
class NoAllocationScope final {
......@@ -253,7 +265,9 @@ class PLATFORM_EXPORT ThreadState {
void WillStartV8GC(BlinkGC::V8GCType);
void SetGCState(GCState);
GCState GcState() const { return gc_state_; }
void SetGCPhase(GCPhase);
bool IsInGC() const { return GcState() == kGCRunning; }
bool IsMarkingInProgress() const { return gc_phase_ == GCPhase::kMarking; }
bool IsSweepingInProgress() const {
return GcState() == kSweeping ||
GcState() == kSweepingAndPreciseGCScheduled ||
......@@ -644,6 +658,7 @@ class PLATFORM_EXPORT ThreadState {
GarbageCollectedMixinConstructorMarkerBase* gc_mixin_marker_;
GCState gc_state_;
GCPhase gc_phase_;
using PreFinalizerCallback = bool (*)(void*);
using PreFinalizer = std::pair<void*, PreFinalizerCallback>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment