[log] Remove is_listening_to_code_events cache

V8FileLogger has a dynamic behaviour when listening to
code events, i.e., it can stop listening without removing
itself from the Logger, which invalidates the field
is_listening_to_code_events_. This field is only updated
when adding/removing an event listener.

This cache was recently introduced in a refactoring
https://crrev.com/c/3582125

Bug: chromium:1400809
Change-Id: If93c88a6a64f5bf2c10265ac1db455ea498733a0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4136726
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Reviewed-by: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85113}
This commit is contained in:
Victor Gomes 2023-01-05 11:20:46 +01:00 committed by V8 LUCI CQ
parent 73aaf18f36
commit 59136c6045
2 changed files with 15 additions and 18 deletions

View File

@ -124,10 +124,6 @@ class Logger {
if (position != listeners_.end()) return false;
// Add the listener to the end and update the element
listeners_.push_back(listener);
if (!_is_listening_to_code_events) {
_is_listening_to_code_events |= listener->is_listening_to_code_events();
}
DCHECK_EQ(_is_listening_to_code_events, IsListeningToCodeEvents());
return true;
}
void RemoveListener(LogEventListener* listener) {
@ -135,15 +131,13 @@ class Logger {
auto position = std::find(listeners_.begin(), listeners_.end(), listener);
if (position == listeners_.end()) return;
listeners_.erase(position);
if (listener->is_listening_to_code_events()) {
_is_listening_to_code_events = IsListeningToCodeEvents();
}
DCHECK_EQ(_is_listening_to_code_events, IsListeningToCodeEvents());
}
bool is_listening_to_code_events() const {
DCHECK_EQ(_is_listening_to_code_events, IsListeningToCodeEvents());
return _is_listening_to_code_events;
for (auto listener : listeners_) {
if (listener->is_listening_to_code_events()) return true;
}
return false;
}
void CodeCreateEvent(CodeTag tag, Handle<AbstractCode> code,
@ -264,16 +258,8 @@ class Logger {
}
private:
bool IsListeningToCodeEvents() const {
for (auto listener : listeners_) {
if (listener->is_listening_to_code_events()) return true;
}
return false;
}
std::vector<LogEventListener*> listeners_;
base::Mutex mutex_;
bool _is_listening_to_code_events = false;
};
} // namespace internal

View File

@ -0,0 +1,11 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc --logfile='+' --log
const log = d8.log.getAndStop();
gc();
function __f_6() {
}
__v_1 = __f_6();