Skip to content

Commit

Permalink
cppgc: Fix compaction cancellation
Browse files Browse the repository at this point in the history
Bug: chromium:1056170
Change-Id: I6b77c06b8c787a00be00b84490155588608c75da
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2764464
Reviewed-by: Michael Lippautz <[email protected]>
Commit-Queue: Omer Katz <[email protected]>
Cr-Commit-Position: refs/heads/master@{#73448}
  • Loading branch information
omerktz authored and Commit Bot committed Mar 16, 2021
1 parent e7dc772 commit 2d13cc9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/heap/cppgc/compactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ void Compactor::InitializeIfShouldCompact(
compaction_worklists_ = std::make_unique<CompactionWorklists>();

is_enabled_ = true;
enable_for_next_gc_for_testing_ = false;
}

bool Compactor::CancelIfShouldNotCompact(
Expand Down Expand Up @@ -506,9 +505,15 @@ Compactor::CompactableSpaceHandling Compactor::CompactSpacesIfEnabled() {
CompactSpace(space, movable_references);
}

enable_for_next_gc_for_testing_ = false;
is_enabled_ = false;
return CompactableSpaceHandling::kIgnore;
}

void Compactor::EnableForNextGCForTesting() {
DCHECK_NULL(heap_.heap()->marker());
enable_for_next_gc_for_testing_ = true;
}

} // namespace internal
} // namespace cppgc
2 changes: 1 addition & 1 deletion src/heap/cppgc/compactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class V8_EXPORT_PRIVATE Compactor final {
return compaction_worklists_.get();
}

void EnableForNextGCForTesting() { enable_for_next_gc_for_testing_ = true; }
void EnableForNextGCForTesting();
bool IsEnabledForTesting() const { return is_enabled_; }

private:
Expand Down
12 changes: 0 additions & 12 deletions test/unittests/heap/cppgc/compactor-unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class CompactorTest : public testing::TestWithPlatform {
EXPECT_TRUE(compactor().IsEnabledForTesting());
}

void CancelCompaction() {
bool cancelled = compactor().CancelIfShouldNotCompact(
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::StackState::kMayContainHeapPointers);
EXPECT_TRUE(cancelled);
}

void FinishCompaction() { compactor().CompactSpacesIfEnabled(); }

void StartGC() {
Expand Down Expand Up @@ -134,11 +127,6 @@ TEST_F(CompactorTest, NothingToCompact) {
heap()->stats_collector()->NotifySweepingCompleted();
}

TEST_F(CompactorTest, CancelledNothingToCompact) {
StartCompaction();
CancelCompaction();
}

TEST_F(CompactorTest, NonEmptySpaceAllLive) {
static constexpr int kNumObjects = 10;
Persistent<CompactableHolder<kNumObjects>> holder =
Expand Down

0 comments on commit 2d13cc9

Please sign in to comment.