Skip to content

Commit 4eeb8cf

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, gc] Remove force_growth option from RunWithStoppedMutators.
Adjust wait for sweeper to account for whether we're already under a safepoint operation. TEST=ci Bug: #61019 Change-Id: Ic30500a1348dc8a719e72be64d69e496986107aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437901 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent ab49c6e commit 4eeb8cf

File tree

10 files changed

+27
-51
lines changed

10 files changed

+27
-51
lines changed

runtime/vm/compiler/backend/il_test_helper.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ InstructionsPtr BuildInstructions(
107107
/*optimized=*/false, /*stats=*/nullptr);
108108
};
109109
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
110-
thread->isolate_group()->RunWithStoppedMutators(install_code_fun,
111-
/*use_force_growth=*/true);
110+
thread->isolate_group()->RunWithStoppedMutators(install_code_fun);
112111
return code.instructions();
113112
}
114113

runtime/vm/compiler/jit/compiler.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,7 @@ CodePtr CompileParsedFunctionHelper::Compile() {
597597
// requires updating several pointers: We have to ensure all of
598598
// those writes are observed atomically.
599599
//
600-
thread()->isolate_group()->RunWithStoppedMutators(
601-
install_code_fun, /*use_force_growth=*/true);
600+
thread()->isolate_group()->RunWithStoppedMutators(install_code_fun);
602601
}
603602
if (!result->IsNull()) {
604603
// Must be called outside of safepoint.

runtime/vm/heap/heap.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ uword Heap::AllocateOld(Thread* thread, intptr_t size, bool is_exec) {
153153
return addr;
154154
}
155155
// Wait for all of the concurrent tasks to finish before giving up.
156-
WaitForSweeperTasksAtSafepoint(thread);
156+
WaitForSweeperTasks(thread);
157157
addr = old_space_.TryAllocate(size, is_exec);
158158
if (addr != 0) {
159159
return addr;
@@ -165,7 +165,7 @@ uword Heap::AllocateOld(Thread* thread, intptr_t size, bool is_exec) {
165165
}
166166
// Before throwing an out-of-memory error try a synchronous GC.
167167
CollectOldSpaceGarbage(thread, GCType::kMarkCompact, GCReason::kOldSpace);
168-
WaitForSweeperTasksAtSafepoint(thread);
168+
WaitForSweeperTasks(thread);
169169
addr = old_space_.TryAllocate(size, is_exec, PageSpace::kForceGrowth);
170170
if (addr != 0) {
171171
return addr;
@@ -669,20 +669,14 @@ void Heap::WaitForMarkerTasks(Thread* thread) {
669669
}
670670

671671
void Heap::WaitForSweeperTasks(Thread* thread) {
672-
ASSERT(!thread->OwnsGCSafepoint());
673-
MonitorLocker ml(old_space_.tasks_lock());
674-
while ((old_space_.phase() == PageSpace::kSweepingLarge) ||
675-
(old_space_.phase() == PageSpace::kSweepingRegular)) {
676-
ml.WaitWithSafepointCheck(thread);
677-
}
678-
}
679-
680-
void Heap::WaitForSweeperTasksAtSafepoint(Thread* thread) {
681-
ASSERT(thread->OwnsGCSafepoint());
682672
MonitorLocker ml(old_space_.tasks_lock());
683673
while ((old_space_.phase() == PageSpace::kSweepingLarge) ||
684674
(old_space_.phase() == PageSpace::kSweepingRegular)) {
685-
ml.Wait();
675+
if (thread->OwnsSafepoint()) {
676+
ml.Wait();
677+
} else {
678+
ml.WaitWithSafepointCheck(thread);
679+
}
686680
}
687681
}
688682

runtime/vm/heap/heap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class Heap {
119119
void StartConcurrentMarking(Thread* thread, GCReason reason);
120120
void WaitForMarkerTasks(Thread* thread);
121121
void WaitForSweeperTasks(Thread* thread);
122-
void WaitForSweeperTasksAtSafepoint(Thread* thread);
123122

124123
// Protect access to the heap. Note: Code pages are made
125124
// executable/non-executable when 'read_only' is true/false, respectively.

runtime/vm/heap/scavenger.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ SemiSpace* Scavenger::Prologue(GCReason reason) {
10151015
heap_->isolate_group()->FlushMarkingStacks();
10161016

10171017
if (FLAG_verify_store_buffer) {
1018-
heap_->WaitForSweeperTasksAtSafepoint(Thread::Current());
1018+
heap_->WaitForSweeperTasks(Thread::Current());
10191019
VerifyStoreBuffers("Verifying remembered set before Scavenge");
10201020
}
10211021

@@ -1118,7 +1118,7 @@ void Scavenger::Epilogue(SemiSpace* from) {
11181118
// are very rare.
11191119
heap_->isolate_group()->ReleaseStoreBuffers();
11201120

1121-
heap_->WaitForSweeperTasksAtSafepoint(Thread::Current());
1121+
heap_->WaitForSweeperTasks(Thread::Current());
11221122
VerifyStoreBuffers("Verifying remembered set after Scavenge");
11231123
}
11241124

@@ -1854,7 +1854,7 @@ void Scavenger::Scavenge(Thread* thread, GCType type, GCReason reason) {
18541854
}
18551855

18561856
if (FLAG_verify_before_gc) {
1857-
heap_->WaitForSweeperTasksAtSafepoint(thread);
1857+
heap_->WaitForSweeperTasks(thread);
18581858
heap_->VerifyGC("Verifying before Scavenge",
18591859
thread->is_marking() ? kAllowMarked : kForbidMarked);
18601860
}
@@ -1928,7 +1928,7 @@ void Scavenger::Scavenge(Thread* thread, GCType type, GCReason reason) {
19281928
heap_->old_space()->ResumeConcurrentMarking();
19291929

19301930
if (FLAG_verify_after_gc) {
1931-
heap_->WaitForSweeperTasksAtSafepoint(thread);
1931+
heap_->WaitForSweeperTasks(thread);
19321932
heap_->VerifyGC("Verifying after Scavenge...",
19331933
thread->is_marking() ? kAllowMarked : kForbidMarked);
19341934
}
@@ -2030,7 +2030,7 @@ void Scavenger::ReverseScavenge(SemiSpace** from) {
20302030

20312031
// Reverse the partial forwarding from the aborted scavenge. This also
20322032
// rebuilds the remembered set.
2033-
heap_->WaitForSweeperTasksAtSafepoint(thread);
2033+
heap_->WaitForSweeperTasks(thread);
20342034
Become::FollowForwardingPointers(thread);
20352035

20362036
heap_->old_space()->ResetProgressBars();

runtime/vm/isolate.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,8 +2909,7 @@ Isolate* IsolateGroup::FirstIsolateLocked() const {
29092909
return isolates_.IsEmpty() ? nullptr : isolates_.First();
29102910
}
29112911

2912-
void IsolateGroup::RunWithStoppedMutatorsCallable(Callable* callable,
2913-
bool use_force_growth) {
2912+
void IsolateGroup::RunWithStoppedMutatorsCallable(Callable* callable) {
29142913
auto thread = Thread::Current();
29152914
StoppedMutatorsScope stopped_mutators_scope(thread);
29162915

@@ -2923,14 +2922,8 @@ void IsolateGroup::RunWithStoppedMutatorsCallable(Callable* callable,
29232922
// We use the more strict safepoint operation scope here (which ensures that
29242923
// all other threads, including auxiliary threads are at a safepoint), even
29252924
// though we only need to ensure that the mutator threads are stopped.
2926-
if (use_force_growth) {
2927-
ForceGrowthSafepointOperationScope safepoint_scope(
2928-
thread, SafepointLevel::kGCAndDeopt);
2929-
callable->Call();
2930-
} else {
2931-
DeoptSafepointOperationScope safepoint_scope(thread);
2932-
callable->Call();
2933-
}
2925+
DeoptSafepointOperationScope safepoint_scope(thread);
2926+
callable->Call();
29342927
}
29352928

29362929
void IsolateGroup::VisitObjectPointers(ObjectPointerVisitor* visitor,

runtime/vm/isolate.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,19 +599,16 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
599599
//
600600
// If the current thread is the only mutator in the isolate group,
601601
// [callable] will be called directly. Otherwise [callable] will be
602-
// called inside a [SafepointOperationsScope] (or
603-
// [ForceGrowthSafepointOperationScope] if [use_force_growth]
604-
// is set).
602+
// called inside a [SafepointOperationsScope].
605603
//
606604
// During the duration of this function, no new isolates can be added to the
607605
// isolate group.
608-
void RunWithStoppedMutatorsCallable(Callable* callable,
609-
bool use_force_growth = false);
606+
void RunWithStoppedMutatorsCallable(Callable* callable);
610607

611608
template <typename T>
612-
void RunWithStoppedMutators(T function, bool use_force_growth = false) {
609+
void RunWithStoppedMutators(T function) {
613610
LambdaCallable<T> callable(function);
614-
RunWithStoppedMutatorsCallable(&callable, use_force_growth);
611+
RunWithStoppedMutatorsCallable(&callable);
615612
}
616613

617614
#ifndef PRODUCT

runtime/vm/object.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19743,12 +19743,10 @@ void MegamorphicCache::InsertLocked(const Smi& class_id,
1974319743
// NOTE: In the future we might change the megamorphic cache insertions to
1974419744
// carefully use store-release barriers on the writer as well as
1974519745
// load-acquire barriers on the reader, ...
19746-
isolate_group->RunWithStoppedMutators(
19747-
[&]() {
19748-
EnsureCapacityLocked();
19749-
InsertEntryLocked(class_id, target);
19750-
},
19751-
/*use_force_growth=*/true);
19746+
isolate_group->RunWithStoppedMutators([&]() {
19747+
EnsureCapacityLocked();
19748+
InsertEntryLocked(class_id, target);
19749+
});
1975219750
}
1975319751

1975419752
void MegamorphicCache::EnsureCapacityLocked() const {

runtime/vm/stub_code.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ CodePtr StubCode::GetAllocationStubForClass(const Class& cls) {
282282
//
283283
// a) We allocate an instructions object, which might cause us to
284284
// temporarily flip page protections from (RX -> RW -> RX).
285-
thread->isolate_group()->RunWithStoppedMutators(mutator_fun,
286-
/*use_force_growth=*/true);
285+
thread->isolate_group()->RunWithStoppedMutators(mutator_fun);
287286

288287
// We notify code observers after finalizing the code in order to be
289288
// outside a [SafepointOperationScope].

runtime/vm/type_testing_stubs.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ CodePtr TypeTestingStubGenerator::BuildCodeForType(const AbstractType& type) {
296296
//
297297
SafepointWriteRwLocker ml(thread,
298298
thread->isolate_group()->program_lock());
299-
thread->isolate_group()->RunWithStoppedMutators(
300-
install_code_fun,
301-
/*use_force_growth=*/true);
299+
thread->isolate_group()->RunWithStoppedMutators(install_code_fun);
302300

303301
Code::NotifyCodeObservers(name, code, /*optimized=*/false);
304302

0 commit comments

Comments
 (0)