Fix Task Executor/Runner flakiness and lifecycles.
Problems this is addressing: 1. The TaskRunnerImpl hierarchy is currently too complicated, with derived classes changing how base classes function in ways that require the two classes to update in sync without breaking each other. 2. BrowserTaskExecutor holds onto WeakReferences to SingleThreadTaskRunnerImpls, allowing them to leak the native memory if the caller doesn't destroy, or continuing to return destroyed runners if the caller does destroy but GC hasn't cleaned up the runner. 3. SequencedTaskRunnerImpl creates and deletes the native side potentially with every posted task, taking time. 4. TaskExecutors aren't reset between tests leading to tasks flakily failing to run, or crashes in native code (haven't figured out what's not holding onto what it should hold onto, it was too complicated, so I fixed the caching instead). 5. UnitTestUtils#pollUiThread could time out if nothing posts tasks to the UI thread while waiting on an AtomicBoolean or similar. TaskRunnerImpl is now in full control of its native pointer, not exposing it or its lock to derived classes, and only creates its native side if a task is posted to it, as many task runners are created statically and may never actually have a task posted to them. A ReferenceQueue is used to detect when the TaskRunner is GC'd (or about to be), and that queue is polled when creating new TaskRunners, or when initializing native for a TaskRunner (basically the two operations that aren't performance critical). In practice when running Chrome we have approximately 5-10 TaskRunners alive at any given time, and we can't build up many TaskRunners without creating them, so polling for deletion at creation time should be sufficient to keep the number of dead but in memory task runners small. PostTask now also holds a Strong Reference to the PreNativeTaskRunners so that they can't be deleted before their tasks are placed on the refcounted native runner. Bug: 1058790 Change-Id: Ib58320e6f23d83ff95dc52c52bbdcf5bf7435968 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091899Reviewed-by:Yaron Friedman <yfriedman@chromium.org> Reviewed-by:
Sami Kyöstilä <skyostil@chromium.org> Reviewed-by:
Sam Maier <smaier@chromium.org> Commit-Queue: Michael Thiessen <mthiesse@chromium.org> Cr-Commit-Position: refs/heads/master@{#749731}
Showing
Please register or sign in to comment