[vm, gc] Refactor PageSpace::CollectGarbage to ensure the safepoint and task count remain well-scoped even with early exits.

Landing this separately makes it easier to see the changes for concurrent marking.

Bug: https://github.com/dart-lang/sdk/issues/34002
Change-Id: I8e2e2ca0cddbaba079cf54b6e8cff65c42e21684
Reviewed-on: https://dart-review.googlesource.com/68980
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2018-08-08 22:59:08 +00:00 committed by commit-bot@chromium.org
parent 8195fd8c64
commit bd45ec0c4b
2 changed files with 156 additions and 145 deletions

View file

@ -901,8 +901,6 @@ bool PageSpace::ShouldPerformIdleMarkCompact(int64_t deadline) {
void PageSpace::CollectGarbage(bool compact) {
Thread* thread = Thread::Current();
Isolate* isolate = heap_->isolate();
ASSERT(isolate == Isolate::Current());
const int64_t pre_wait_for_sweepers = OS::GetCurrentMonotonicMicros();
@ -923,6 +921,24 @@ void PageSpace::CollectGarbage(bool compact) {
// loser skips collection and goes straight to allocation.
{
SafepointOperationScope safepoint_scope(thread);
CollectGarbageAtSafepoint(compact, pre_wait_for_sweepers, pre_safe_point);
}
// Done, reset the task count.
{
MonitorLocker ml(tasks_lock());
set_tasks(tasks() - 1);
ml.NotifyAll();
}
}
void PageSpace::CollectGarbageAtSafepoint(bool compact,
int64_t pre_wait_for_sweepers,
int64_t pre_safe_point) {
Thread* thread = Thread::Current();
ASSERT(thread->IsAtSafepoint());
Isolate* isolate = heap_->isolate();
ASSERT(isolate == Isolate::Current());
const int64_t start = OS::GetCurrentMonotonicMicros();
@ -1068,14 +1084,6 @@ void PageSpace::CollectGarbage(bool compact) {
}
}
// Done, reset the task count.
{
MonitorLocker ml(tasks_lock());
set_tasks(tasks() - 1);
ml.NotifyAll();
}
}
void PageSpace::BlockingSweep() {
TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "Sweep");

View file

@ -387,6 +387,9 @@ class PageSpace {
void FreeLargePage(HeapPage* page, HeapPage* previous_page);
void FreePages(HeapPage* pages);
void CollectGarbageAtSafepoint(bool compact,
int64_t pre_wait_for_sweepers,
int64_t pre_safe_point);
void BlockingSweep();
void ConcurrentSweep(Isolate* isolate);
void Compact(Thread* thread);