Commit 760e52fd authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Replace IsActive() with AssertActive()

IsActive() is only supposed to be used in DCHECKs and supporting
this is going to get harder when introducing safepoints across multiple
isolates because there won't be this single counter anymore to check.
With AssertActive() we can just invoke AssertHold() on our mutex.

No functional changes.

Bug: v8:11708
Change-Id: Ic8d17738afdc90e92e6b54f615ec9757a826cc64
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3207903
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77272}
parent c8f9853e
......@@ -122,7 +122,7 @@ void PersistentHandlesList::Remove(PersistentHandles* persistent_handles) {
}
void PersistentHandlesList::Iterate(RootVisitor* visitor, Isolate* isolate) {
DCHECK(isolate->heap()->safepoint()->IsActive());
isolate->heap()->safepoint()->AssertActive();
base::MutexGuard guard(&persistent_handles_mutex_);
for (PersistentHandles* current = persistent_handles_head_; current;
current = current->next_) {
......
......@@ -429,7 +429,7 @@ void NewSpace::ResetParkedAllocationBuffers() {
void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); }
void NewSpace::Grow() {
DCHECK(heap()->safepoint()->IsActive());
heap()->safepoint()->AssertActive();
// Double the semispace size but only up to maximum capacity.
DCHECK(TotalCapacity() < MaximumCapacity());
size_t new_capacity = std::min(
......
......@@ -184,7 +184,7 @@ bool IsolateSafepoint::ContainsAnyLocalHeap() {
}
void IsolateSafepoint::Iterate(RootVisitor* visitor) {
DCHECK(IsActive());
AssertActive();
for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) {
current->handles()->Iterate(visitor);
......
......@@ -42,14 +42,14 @@ class IsolateSafepoint final {
// Iterate local heaps
template <typename Callback>
void IterateLocalHeaps(Callback callback) {
DCHECK(IsActive());
AssertActive();
for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) {
callback(current);
}
}
bool IsActive() { return active_safepoint_scopes_ > 0; }
void AssertActive() { local_heaps_mutex_.AssertHeld(); }
private:
class Barrier {
......
......@@ -327,13 +327,8 @@ void StringTable::Data::Print(PtrComprCageBase cage_base) const {
}
StringTable::StringTable(Isolate* isolate)
: data_(Data::New(kStringTableMinCapacity).release())
#ifdef DEBUG
,
isolate_(isolate)
#endif
{
}
: data_(Data::New(kStringTableMinCapacity).release()), isolate_(isolate) {}
StringTable::~StringTable() { delete data_; }
int StringTable::Capacity() const {
......@@ -663,14 +658,14 @@ size_t StringTable::GetCurrentMemoryUsage() const {
void StringTable::IterateElements(RootVisitor* visitor) {
// This should only happen during garbage collection when background threads
// are paused, so the load can be relaxed.
DCHECK(isolate_->heap()->safepoint()->IsActive());
isolate_->heap()->safepoint()->AssertActive();
data_.load(std::memory_order_relaxed)->IterateElements(visitor);
}
void StringTable::DropOldData() {
// This should only happen during garbage collection when background threads
// are paused, so the load can be relaxed.
DCHECK(isolate_->heap()->safepoint()->IsActive());
isolate_->heap()->safepoint()->AssertActive();
DCHECK_NE(isolate_->heap()->gc_state(), Heap::NOT_IN_GC);
data_.load(std::memory_order_relaxed)->DropPreviousData();
}
......@@ -678,7 +673,7 @@ void StringTable::DropOldData() {
void StringTable::NotifyElementsRemoved(int count) {
// This should only happen during garbage collection when background threads
// are paused, so the load can be relaxed.
DCHECK(isolate_->heap()->safepoint()->IsActive());
isolate_->heap()->safepoint()->AssertActive();
DCHECK_NE(isolate_->heap()->gc_state(), Heap::NOT_IN_GC);
data_.load(std::memory_order_relaxed)->ElementsRemoved(count);
}
......
......@@ -90,9 +90,7 @@ class V8_EXPORT_PRIVATE StringTable {
// Write mutex is mutable so that readers of concurrently mutated values (e.g.
// NumberOfElements) are allowed to lock it while staying const.
mutable base::Mutex write_mutex_;
#ifdef DEBUG
Isolate* isolate_;
#endif
};
} // namespace internal
......
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