[VM/Timeline] Delete unsafe versions of Clear() and ReclaimCachedBlocksFromThreads()
TEST=Recorded traces using the file recorder on ASAN and TSAN builds. Change-Id: I2251a8373d952d6e3ef1803e9a79de85522f518a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312720 Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
+5
-19
@@ -126,7 +126,7 @@ DEFINE_FLAG(charp,
|
||||
|
||||
std::atomic<RecorderSynchronizationLock::RecorderState>
|
||||
RecorderSynchronizationLock::recorder_state_ = {
|
||||
RecorderSynchronizationLock::kUnInitialized};
|
||||
RecorderSynchronizationLock::kUninitialized};
|
||||
std::atomic<intptr_t> RecorderSynchronizationLock::outstanding_event_writes_ = {
|
||||
0};
|
||||
|
||||
@@ -316,11 +316,7 @@ void Timeline::Cleanup() {
|
||||
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DISABLE)
|
||||
#undef TIMELINE_STREAM_DISABLE
|
||||
RecorderSynchronizationLock::WaitForShutdown();
|
||||
// Timeline::Clear() is guarded by the recorder lock and will return
|
||||
// immediately if we've started the shutdown sequence, leaking the recorder.
|
||||
// All outstanding work has already been completed, so we're safe to call this
|
||||
// without explicitly grabbing a recorder lock.
|
||||
Timeline::ClearUnsafe();
|
||||
Timeline::Clear();
|
||||
delete recorder_;
|
||||
recorder_ = nullptr;
|
||||
if (enabled_streams_ != nullptr) {
|
||||
@@ -332,14 +328,9 @@ void Timeline::Cleanup() {
|
||||
void Timeline::ReclaimCachedBlocksFromThreads() {
|
||||
RecorderSynchronizationLockScope ls;
|
||||
TimelineEventRecorder* recorder = Timeline::recorder();
|
||||
if (recorder == nullptr || !ls.IsActive()) {
|
||||
if (recorder == nullptr || ls.IsUninitialized()) {
|
||||
return;
|
||||
}
|
||||
ReclaimCachedBlocksFromThreadsUnsafe();
|
||||
}
|
||||
|
||||
void Timeline::ReclaimCachedBlocksFromThreadsUnsafe() {
|
||||
TimelineEventRecorder* recorder = Timeline::recorder();
|
||||
ASSERT(recorder != nullptr);
|
||||
// Iterate over threads.
|
||||
OSThreadIterator it;
|
||||
@@ -397,16 +388,11 @@ void Timeline::PrintFlagsToJSON(JSONStream* js) {
|
||||
void Timeline::Clear() {
|
||||
RecorderSynchronizationLockScope ls;
|
||||
TimelineEventRecorder* recorder = Timeline::recorder();
|
||||
if (recorder == nullptr || !ls.IsActive()) {
|
||||
if (recorder == nullptr || ls.IsUninitialized()) {
|
||||
return;
|
||||
}
|
||||
ClearUnsafe();
|
||||
}
|
||||
|
||||
void Timeline::ClearUnsafe() {
|
||||
TimelineEventRecorder* recorder = Timeline::recorder();
|
||||
ASSERT(recorder != nullptr);
|
||||
ReclaimCachedBlocksFromThreadsUnsafe();
|
||||
ReclaimCachedBlocksFromThreads();
|
||||
recorder->Clear();
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -164,6 +164,10 @@ class RecorderSynchronizationLock : public AllStatic {
|
||||
ASSERT(count >= 0);
|
||||
}
|
||||
|
||||
static bool IsUninitialized() {
|
||||
return (recorder_state_.load(std::memory_order_acquire) == kUninitialized);
|
||||
}
|
||||
|
||||
static bool IsActive() {
|
||||
return (recorder_state_.load(std::memory_order_acquire) == kActive);
|
||||
}
|
||||
@@ -176,7 +180,7 @@ class RecorderSynchronizationLock : public AllStatic {
|
||||
}
|
||||
|
||||
private:
|
||||
typedef enum { kUnInitialized = 0, kActive, kShuttingDown } RecorderState;
|
||||
typedef enum { kUninitialized = 0, kActive, kShuttingDown } RecorderState;
|
||||
static std::atomic<RecorderState> recorder_state_;
|
||||
static std::atomic<intptr_t> outstanding_event_writes_;
|
||||
|
||||
@@ -196,7 +200,11 @@ class RecorderSynchronizationLockScope {
|
||||
RecorderSynchronizationLock::ExitLock();
|
||||
}
|
||||
|
||||
bool IsActive() { return RecorderSynchronizationLock::IsActive(); }
|
||||
bool IsUninitialized() const {
|
||||
return RecorderSynchronizationLock::IsUninitialized();
|
||||
}
|
||||
|
||||
bool IsActive() const { return RecorderSynchronizationLock::IsActive(); }
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(RecorderSynchronizationLockScope);
|
||||
@@ -251,9 +259,6 @@ class Timeline : public AllStatic {
|
||||
#undef TIMELINE_STREAM_FLAGS
|
||||
|
||||
private:
|
||||
static void ClearUnsafe();
|
||||
static void ReclaimCachedBlocksFromThreadsUnsafe();
|
||||
|
||||
static TimelineEventRecorder* recorder_;
|
||||
static Dart_TimelineRecorderCallback callback_;
|
||||
static MallocGrowableArray<char*>* enabled_streams_;
|
||||
|
||||
Reference in New Issue
Block a user