Skip to content

Commit 3ecbfd9

Browse files
a-sivabkonyi
authored andcommitted
Revert "[ VM ] Ensure shared timeline objects are protected by locks"
This reverts commit a62e144. Reason for revert: Flutter engine shell tests are timing out because of deadlock. Original change's description: > [ VM ] Ensure shared timeline objects are protected by locks > > Timeline::Clear() could cause an user after free error if trying to allocate a timeline > event immediately after clearing the timeline buffer. > > Timeline::Cleanup() could result in recorder_ being freed while timeline events are still > being processed. > > Should fix flutter/flutter#78076 > > TEST=tests/lib/developer/timeline_recorders_test.dart > > Change-Id: Ia61b9c93986788c79ef6f2ff1907625b66fb4ea1 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191802 > Commit-Queue: Ben Konyi <[email protected]> > Reviewed-by: Siva Annamalai <[email protected]> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Iac2c19147a3e73df37418e11106f0c5132a35302 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192482 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent ddcb60a commit 3ecbfd9

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

runtime/vm/timeline.cc

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ DEFINE_FLAG(charp,
8686
//
8787
// Locking notes:
8888
// The following locks are used by the timeline system:
89-
// - |Timeline::recorder_lock_| This lock is held whenever Timeline::recorder()
90-
// is accessed or modified.
9189
// - |TimelineEventRecorder::lock_| This lock is held whenever a
9290
// |TimelineEventBlock| is being requested or reclaimed.
9391
// - |Thread::timeline_block_lock_| This lock is held whenever a |Thread|'s
@@ -96,10 +94,9 @@ DEFINE_FLAG(charp,
9694
// |Thread|s.
9795
//
9896
// Locks must always be taken in the following order:
99-
// |Timeline::recorder_lock_|
100-
// |Thread::thread_list_lock_|
101-
// |Thread::timeline_block_lock_|
102-
// |TimelineEventRecorder::lock_|
97+
// |Thread::thread_list_lock_|
98+
// |Thread::timeline_block_lock_|
99+
// |TimelineEventRecorder::lock_|
103100
//
104101

105102
static TimelineEventRecorder* CreateTimelineRecorder() {
@@ -208,10 +205,6 @@ static bool HasStream(MallocGrowableArray<char*>* streams, const char* stream) {
208205
}
209206

210207
void Timeline::Init() {
211-
if (recorder_lock_ == nullptr) {
212-
recorder_lock_ = new Mutex();
213-
}
214-
MutexLocker ml(recorder_lock_);
215208
ASSERT(recorder_ == NULL);
216209
recorder_ = CreateTimelineRecorder();
217210
ASSERT(recorder_ != NULL);
@@ -224,8 +217,6 @@ void Timeline::Init() {
224217
}
225218

226219
void Timeline::Cleanup() {
227-
ASSERT(recorder_lock_ != nullptr);
228-
MutexLocker ml(recorder_lock_);
229220
ASSERT(recorder_ != NULL);
230221

231222
#ifndef PRODUCT
@@ -252,12 +243,6 @@ TimelineEventRecorder* Timeline::recorder() {
252243
}
253244

254245
void Timeline::ReclaimCachedBlocksFromThreads() {
255-
ASSERT(recorder_lock_ != nullptr);
256-
MutexLocker ml(recorder_lock_);
257-
ReclaimCachedBlocksFromThreadsLocked();
258-
}
259-
260-
void Timeline::ReclaimCachedBlocksFromThreadsLocked() {
261246
TimelineEventRecorder* recorder = Timeline::recorder();
262247
if (recorder == NULL) {
263248
return;
@@ -289,8 +274,6 @@ void Timeline::PrintFlagsToJSONArray(JSONArray* arr) {
289274
}
290275

291276
void Timeline::PrintFlagsToJSON(JSONStream* js) {
292-
ASSERT(recorder_lock_ != nullptr);
293-
MutexLocker ml(recorder_lock_);
294277
JSONObject obj(js);
295278
obj.AddProperty("type", "TimelineFlags");
296279
TimelineEventRecorder* recorder = Timeline::recorder();
@@ -318,13 +301,11 @@ void Timeline::PrintFlagsToJSON(JSONStream* js) {
318301
#endif
319302

320303
void Timeline::Clear() {
321-
ASSERT(recorder_lock_ != nullptr);
322-
MutexLocker ml(recorder_lock_);
323304
TimelineEventRecorder* recorder = Timeline::recorder();
324305
if (recorder == NULL) {
325306
return;
326307
}
327-
ReclaimCachedBlocksFromThreadsLocked();
308+
ReclaimCachedBlocksFromThreads();
328309
recorder->Clear();
329310
}
330311

@@ -409,7 +390,6 @@ void TimelineEventArguments::Free() {
409390

410391
TimelineEventRecorder* Timeline::recorder_ = NULL;
411392
MallocGrowableArray<char*>* Timeline::enabled_streams_ = NULL;
412-
Mutex* Timeline::recorder_lock_ = nullptr;
413393

414394
#define TIMELINE_STREAM_DEFINE(name, fuchsia_name) \
415395
TimelineStream Timeline::stream_##name##_(#name, fuchsia_name, false);
@@ -576,8 +556,6 @@ void TimelineEvent::FormatArgument(intptr_t i,
576556
}
577557

578558
void TimelineEvent::Complete() {
579-
ASSERT(Timeline::recorder_lock() != nullptr);
580-
MutexLocker ml(Timeline::recorder_lock());
581559
TimelineEventRecorder* recorder = Timeline::recorder();
582560
if (recorder != NULL) {
583561
recorder->CompleteEvent(this);
@@ -797,10 +775,6 @@ TimelineStream::TimelineStream(const char* name,
797775
}
798776

799777
TimelineEvent* TimelineStream::StartEvent() {
800-
if (Timeline::recorder_lock() == nullptr) {
801-
return nullptr;
802-
}
803-
MutexLocker ml(Timeline::recorder_lock());
804778
TimelineEventRecorder* recorder = Timeline::recorder();
805779
if (!enabled() || (recorder == NULL)) {
806780
return NULL;
@@ -1163,7 +1137,6 @@ TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder(
11631137
}
11641138

11651139
TimelineEventFixedBufferRecorder::~TimelineEventFixedBufferRecorder() {
1166-
MutexLocker ml(&lock_);
11671140
// Delete all blocks.
11681141
for (intptr_t i = 0; i < num_blocks_; i++) {
11691142
blocks_[i].Reset();
@@ -1361,7 +1334,6 @@ TimelineEventEndlessRecorder::TimelineEventEndlessRecorder()
13611334
: head_(nullptr), tail_(nullptr), block_index_(0) {}
13621335

13631336
TimelineEventEndlessRecorder::~TimelineEventEndlessRecorder() {
1364-
MutexLocker ml(&lock_);
13651337
TimelineEventBlock* current = head_;
13661338
head_ = tail_ = nullptr;
13671339

@@ -1452,18 +1424,15 @@ void TimelineEventEndlessRecorder::PrintJSONEvents(
14521424
#endif
14531425

14541426
void TimelineEventEndlessRecorder::Clear() {
1455-
OSThread* thread = OSThread::Current();
1456-
MutexLocker ml(thread->timeline_block_lock());
1457-
MutexLocker ml2(&lock_);
14581427
TimelineEventBlock* current = head_;
14591428
while (current != NULL) {
14601429
TimelineEventBlock* next = current->next();
14611430
delete current;
14621431
current = next;
14631432
}
14641433
head_ = NULL;
1465-
tail_ = NULL;
14661434
block_index_ = 0;
1435+
OSThread* thread = OSThread::Current();
14671436
thread->set_timeline_block(NULL);
14681437
}
14691438

runtime/vm/timeline.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#if defined(__MAC_10_14) || defined (__IPHONE_12_0)
2424
#define HOST_OS_SUPPORTS_SIGNPOST 1
2525
#endif
26-
// signpost.h exists in macOS 10.14, iOS 12 or above
26+
//signpost.h exists in macOS 10.14, iOS 12 or above
2727
#if defined(HOST_OS_SUPPORTS_SIGNPOST)
2828
#include <os/signpost.h>
2929
#else
@@ -123,18 +123,15 @@ class TimelineStream {
123123

124124
class Timeline : public AllStatic {
125125
public:
126-
// Initialize timeline system.
126+
// Initialize timeline system. Not thread safe.
127127
static void Init();
128128

129-
// Cleanup timeline system.
129+
// Cleanup timeline system. Not thread safe.
130130
static void Cleanup();
131131

132-
// Access the global recorder. recorder_lock() must be held when accessing
133-
// the returned |TimelineEventRecorder|.
132+
// Access the global recorder. Not thread safe.
134133
static TimelineEventRecorder* recorder();
135134

136-
static Mutex* recorder_lock() { return recorder_lock_; }
137-
138135
// Reclaim all |TimelineEventBlocks|s that are cached by threads.
139136
static void ReclaimCachedBlocksFromThreads();
140137

@@ -161,13 +158,8 @@ class Timeline : public AllStatic {
161158
#undef TIMELINE_STREAM_FLAGS
162159

163160
private:
164-
// Reclaims all |TimelineEventBlocks|s that are cached by threads, assuming
165-
// that lock_ is held.
166-
static void ReclaimCachedBlocksFromThreadsLocked();
167-
168161
static TimelineEventRecorder* recorder_;
169162
static MallocGrowableArray<char*>* enabled_streams_;
170-
static Mutex* recorder_lock_;
171163

172164
#define TIMELINE_STREAM_DECLARE(name, fuchsia_name) \
173165
static TimelineStream stream_##name##_;

0 commit comments

Comments
 (0)