Skip to content

Commit 1cbbd11

Browse files
authored
Revert "Fix memory leak and bug in the RunsOnCreationTaskRunner check (flutter#24690)" (flutter#24874)
This reverts commit 735876e.
1 parent 7764b5c commit 1cbbd11

File tree

11 files changed

+6
-181
lines changed

11 files changed

+6
-181
lines changed

fml/memory/task_runner_checker.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
namespace fml {
88

99
TaskRunnerChecker::TaskRunnerChecker()
10-
: initialized_queue_id_(InitTaskQueueId()),
11-
subsumed_queue_id_(
12-
MessageLoopTaskQueues::GetInstance()->GetSubsumedTaskQueueId(
13-
initialized_queue_id_)){};
10+
: initialized_queue_id_(InitTaskQueueId()){};
1411

1512
TaskRunnerChecker::~TaskRunnerChecker() = default;
1613

1714
bool TaskRunnerChecker::RunsOnCreationTaskRunner() const {
1815
FML_CHECK(fml::MessageLoop::IsInitializedForCurrentThread());
1916
const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId();
20-
return RunsOnTheSameThread(current_queue_id, initialized_queue_id_) ||
21-
RunsOnTheSameThread(current_queue_id, subsumed_queue_id_);
17+
return RunsOnTheSameThread(current_queue_id, initialized_queue_id_);
2218
};
2319

2420
bool TaskRunnerChecker::RunsOnTheSameThread(TaskQueueId queue_a,

fml/memory/task_runner_checker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class TaskRunnerChecker final {
2222

2323
private:
2424
TaskQueueId initialized_queue_id_;
25-
TaskQueueId subsumed_queue_id_;
2625

2726
TaskQueueId InitTaskQueueId();
2827
};

fml/memory/task_runner_checker_unittest.cc

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -115,57 +115,5 @@ TEST(TaskRunnerCheckerTests, MergedTaskRunnersRunsOnTheSameThread) {
115115
thread2.join();
116116
}
117117

118-
TEST(TaskRunnerCheckerTests,
119-
PassesRunsOnCreationTaskRunnerIfOnDifferentTaskRunner) {
120-
fml::MessageLoop* loop1 = nullptr;
121-
fml::AutoResetWaitableEvent latch1;
122-
std::thread thread1([&]() {
123-
fml::MessageLoop::EnsureInitializedForCurrentThread();
124-
loop1 = &fml::MessageLoop::GetCurrent();
125-
latch1.Signal();
126-
loop1->Run();
127-
});
128-
129-
fml::MessageLoop* loop2 = nullptr;
130-
fml::AutoResetWaitableEvent latch2;
131-
std::thread thread2([&]() {
132-
fml::MessageLoop::EnsureInitializedForCurrentThread();
133-
loop2 = &fml::MessageLoop::GetCurrent();
134-
latch2.Signal();
135-
loop2->Run();
136-
});
137-
138-
latch1.Wait();
139-
latch2.Wait();
140-
141-
fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
142-
fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
143-
fml::MessageLoopTaskQueues::GetInstance()->Merge(qid1, qid2);
144-
145-
std::unique_ptr<TaskRunnerChecker> checker;
146-
147-
fml::AutoResetWaitableEvent latch3;
148-
loop2->GetTaskRunner()->PostTask([&]() {
149-
checker = std::make_unique<TaskRunnerChecker>();
150-
EXPECT_EQ(checker->RunsOnCreationTaskRunner(), true);
151-
latch3.Signal();
152-
});
153-
latch3.Wait();
154-
155-
fml::MessageLoopTaskQueues::GetInstance()->Unmerge(qid1);
156-
157-
fml::AutoResetWaitableEvent latch4;
158-
loop2->GetTaskRunner()->PostTask([&]() {
159-
EXPECT_EQ(checker->RunsOnCreationTaskRunner(), true);
160-
latch4.Signal();
161-
});
162-
latch4.Wait();
163-
164-
loop1->Terminate();
165-
loop2->Terminate();
166-
thread1.join();
167-
thread2.join();
168-
}
169-
170118
} // namespace testing
171119
} // namespace fml

fml/message_loop_task_queues.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,7 @@ bool MessageLoopTaskQueues::Unmerge(TaskQueueId owner) {
238238
bool MessageLoopTaskQueues::Owns(TaskQueueId owner,
239239
TaskQueueId subsumed) const {
240240
std::lock_guard guard(queue_mutex_);
241-
return owner != _kUnmerged && subsumed != _kUnmerged &&
242-
subsumed == queue_entries_.at(owner)->owner_of;
243-
}
244-
245-
TaskQueueId MessageLoopTaskQueues::GetSubsumedTaskQueueId(
246-
TaskQueueId owner) const {
247-
std::lock_guard guard(queue_mutex_);
248-
return queue_entries_.at(owner)->owner_of;
241+
return subsumed == queue_entries_.at(owner)->owner_of;
249242
}
250243

251244
// Subsumed queues will never have pending tasks.

fml/message_loop_task_queues.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ class MessageLoopTaskQueues
122122
// Returns true if owner owns the subsumed task queue.
123123
bool Owns(TaskQueueId owner, TaskQueueId subsumed) const;
124124

125-
// Returns the subsumed task queue if any or |TaskQueueId::kUnmerged|
126-
// otherwise.
127-
TaskQueueId GetSubsumedTaskQueueId(TaskQueueId owner) const;
128-
129125
private:
130126
class MergedQueuesRunner;
131127

fml/message_loop_task_queues_unittests.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,6 @@ TEST(MessageLoopTaskQueue, QueueDoNotOwnItself) {
185185
ASSERT_FALSE(task_queue->Owns(queue_id, queue_id));
186186
}
187187

188-
TEST(MessageLoopTaskQueue, QueueDoNotOwnUnmergedTaskQueueId) {
189-
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
190-
ASSERT_FALSE(task_queue->Owns(task_queue->CreateTaskQueue(), _kUnmerged));
191-
ASSERT_FALSE(task_queue->Owns(_kUnmerged, task_queue->CreateTaskQueue()));
192-
ASSERT_FALSE(task_queue->Owns(_kUnmerged, _kUnmerged));
193-
}
194-
195188
// TODO(chunhtai): This unit-test is flaky and sometimes fails asynchronizely
196189
// after the test has finished.
197190
// https://github.com/flutter/flutter/issues/43858

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ public void detach() {
458458
if (platformViewsChannel != null) {
459459
platformViewsChannel.setPlatformViewsHandler(null);
460460
}
461-
destroyOverlaySurfaces();
462461
platformViewsChannel = null;
463462
context = null;
464463
textureRegistry = null;
@@ -762,9 +761,6 @@ public void onDisplayPlatformView(
762761
}
763762

764763
public void onDisplayOverlaySurface(int id, int x, int y, int width, int height) {
765-
if (overlayLayerViews.get(id) == null) {
766-
throw new IllegalStateException("The overlay surface (id:" + id + ") doesn't exist");
767-
}
768764
initializeRootImageViewIfNeeded();
769765

770766
final FlutterImageView overlayView = overlayLayerViews.get(id);

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -498,61 +498,6 @@ public void onEndFrame__removesPlatformViewParent() {
498498
assertEquals(flutterView.getChildCount(), 1);
499499
}
500500

501-
@Test
502-
@Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
503-
public void detach__destroysOverlaySurfaces() {
504-
final PlatformViewsController platformViewsController = new PlatformViewsController();
505-
506-
final int platformViewId = 0;
507-
assertNull(platformViewsController.getPlatformViewById(platformViewId));
508-
509-
final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
510-
final PlatformView platformView = mock(PlatformView.class);
511-
when(platformView.getView()).thenReturn(mock(View.class));
512-
when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
513-
514-
platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
515-
516-
final FlutterJNI jni = new FlutterJNI();
517-
jni.attachToNative(false);
518-
attach(jni, platformViewsController);
519-
520-
jni.onFirstFrame();
521-
522-
// Simulate create call from the framework.
523-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
524-
525-
// Produce a frame that displays a platform view and an overlay surface.
526-
platformViewsController.onBeginFrame();
527-
platformViewsController.onDisplayPlatformView(
528-
platformViewId,
529-
/* x=*/ 0,
530-
/* y=*/ 0,
531-
/* width=*/ 10,
532-
/* height=*/ 10,
533-
/* viewWidth=*/ 10,
534-
/* viewHeight=*/ 10,
535-
/* mutatorsStack=*/ new FlutterMutatorsStack());
536-
537-
final FlutterImageView overlayImageView = mock(FlutterImageView.class);
538-
when(overlayImageView.acquireLatestImage()).thenReturn(true);
539-
540-
final FlutterOverlaySurface overlaySurface =
541-
platformViewsController.createOverlaySurface(overlayImageView);
542-
// This is OK.
543-
platformViewsController.onDisplayOverlaySurface(
544-
overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
545-
546-
platformViewsController.detach();
547-
548-
assertThrows(
549-
IllegalStateException.class,
550-
() -> {
551-
platformViewsController.onDisplayOverlaySurface(
552-
overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
553-
});
554-
}
555-
556501
@Test
557502
public void checkInputConnectionProxy__falseIfViewIsNull() {
558503
final PlatformViewsController platformViewsController = new PlatformViewsController();

testing/scenario_app/android/app/build.gradle

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'com.facebook.testing.screenshot'
33

4-
def leakcanary_version = '2.6'
5-
64
screenshots {
75
failureDir = "${rootProject.buildDir}/reports/diff_failures"
86
recordDir = "${rootProject.projectDir}/reports/screenshots"
@@ -15,14 +13,12 @@ android {
1513
targetCompatibility JavaVersion.VERSION_1_8
1614
}
1715
defaultConfig {
18-
applicationId 'dev.flutter.scenarios'
16+
applicationId "dev.flutter.scenarios"
1917
minSdkVersion 18
2018
targetSdkVersion 30
2119
versionCode 1
22-
versionName '1.0'
23-
testInstrumentationRunner 'dev.flutter.TestRunner'
24-
testInstrumentationRunnerArgument 'listener', 'leakcanary.FailTestOnLeakRunListener'
25-
testInstrumentationRunnerArguments clearPackageData: 'true'
20+
versionName "1.0"
21+
testInstrumentationRunner "dev.flutter.TestRunner"
2622
}
2723
buildTypes {
2824
release {
@@ -42,10 +38,8 @@ dependencies {
4238
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4339
implementation 'com.google.android.material:material:1.0.0'
4440
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha01'
45-
implementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
4641
testImplementation 'junit:junit:4.12'
4742
androidTestImplementation 'androidx.test:runner:1.2.0'
4843
androidTestImplementation 'androidx.test:rules:1.2.0'
4944
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
50-
androidTestImplementation "com.squareup.leakcanary:leakcanary-android-instrumentation:$leakcanary_version"
5145
}

testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/MemoryLeakTests.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)