|
|
Chromium Code Reviews|
Created:
4 years, 2 months ago by hongchan Modified:
4 years, 1 month ago CC:
Raymond Toy, blink-reviews, blink-worker-reviews_chromium.org, chromium-reviews, falken+watch_chromium.org, horo+watch_chromium.org, kinuko+worker_chromium.org, shimazu+worker_chromium.org Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionRefactoring WorkletThreadBackingHolder with template pattern
The current design of WorkletBackingThreadHolder has too many duplicated
components. Refactor it with the template pattern.
BUG=657101
TEST=NONE (The CL passes AudioWorkletThread unit tests.)
Committed: https://crrev.com/b6660c6d8bb364f1122c94db9f19a98f38b42a7a
Cr-Commit-Position: refs/heads/master@{#428131}
Patch Set 1 : Using Template #
Total comments: 9
Patch Set 2 : Applying template to AudioWorkletThread directly #Patch Set 3 : Applying nhiroki`s design #Patch Set 4 : Add destructor for WorkletThreadHolder #
Total comments: 2
Patch Set 5 : Compiles and passes tests #Patch Set 6 : Refactor AbstractAnimationWorkletThread #Patch Set 7 : Clean up and rename template class file #
Total comments: 11
Patch Set 8 : Fixing typos #Messages
Total messages: 50 (28 generated)
hongchan@chromium.org changed reviewers: + haraken@chromium.org, nhiroki@chromium.org
PTAL at the overall design and let me know what you think.
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: chromium_presubmit on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/chromium_presub...)
Thank you for working on this :) https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... File third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h (right): https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:34: // instance of DereivedWorkletThreadHolder (i.e. AnimationWorkletThreadHolder, s/Dereived/Derived/ https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:61: DCHECK_EQ(nullptr, s_holderInstance); DCHECK(!s_holderInstance)? https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:78: DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); Just to confirm: Each template class instance's holderInstanceMutex() has its own function-level static variable |holderMutex|, so this isn't shared among AnimationWorkletThreadHolder and AudioWorkletThreadHolder, right? https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:109: static DerivedWorkletThreadHolder* s_holderInstance; Just to confirm: Each template class instance has its own static member |s_holderInstance|, so this isn't shared among AnimationWorkletThreadHolder and AudioWorkletThreadHolder, right? https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/m... File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp (right): https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/m... third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:28: : public WorkletThreadHolder<AudioWorkletThreadHolder> { I'd prefer to avoid class inheritance as much as possible because WorkerThread classes already have deep inheritance hierarchy. Instead of inheritance, how about like this? 1) Make WorkletThreadHolder receive client's WorkerThread name (AudioWorkletThread) as a template parameter instead of a derived class name (AudioWorkletThreadHolder). WorkletThreadHolder<AudioWorkletThreadHolder> -> WorkletThreadHolder<AudioWorkletThread> 2) Define createWorkletThreadHolder() on AudioWorkletThread like this: static WorkletThreadHolder<AudioWorkletThread>* AudioWorkletThread::createWorkletThreadHolder(std::unique_ptr<WorkerBackingThread> backingThread = nullptr) { ... } 3) Make WorkletThreadHolder<AudioWorkletThread>::ensureInstance()/createForTest() call AudioWorkletThread::createWorkletThreadHolder() instead of the derived class's ctor. WDYT?
nhiroki@ Unfortunately, I am not sure how to make it work with your suggestion. They are not supposed to be initialized/constructed at the same time - I believe the worklet thread holder is design to be initialized lazily. Applying/inheriting forces two objects to be initialized through the single construction process, and I think this makes our goal of using the template directly to AudioWorkletThread difficult. Perhaps I am not understanding your intention correctly, so please advise. The PS2 compiles, but it causes seg fault in the first unit test. (Basic) https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... File third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h (right): https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:34: // instance of DereivedWorkletThreadHolder (i.e. AnimationWorkletThreadHolder, On 2016/10/19 01:36:49, nhiroki wrote: > s/Dereived/Derived/ Done. https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:61: DCHECK_EQ(nullptr, s_holderInstance); On 2016/10/19 01:36:49, nhiroki wrote: > DCHECK(!s_holderInstance)? Done. https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:78: DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); On 2016/10/19 01:36:49, nhiroki wrote: > Just to confirm: Each template class instance's holderInstanceMutex() has its > own function-level static variable |holderMutex|, so this isn't shared among > AnimationWorkletThreadHolder and AudioWorkletThreadHolder, right? Yes. That is the intention. The same type/class will share the static instance, but not with the different types/classes. https://codereview.chromium.org/2432543002/diff/1/third_party/WebKit/Source/c... third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.h:109: static DerivedWorkletThreadHolder* s_holderInstance; On 2016/10/19 01:36:49, nhiroki wrote: > Just to confirm: Each template class instance has its own static member > |s_holderInstance|, so this isn't shared among AnimationWorkletThreadHolder and > AudioWorkletThreadHolder, right? Yes. As discussed above.
On 2016/10/24 18:39:21, hongchan wrote: > nhiroki@ > > Unfortunately, I am not sure how to make it work with your suggestion. They are > not supposed to be initialized/constructed at the same time - I believe the > worklet thread holder is design to be initialized lazily. > > Applying/inheriting forces two objects to be initialized through the single > construction process, and I think this makes our goal of using the template > directly to AudioWorkletThread difficult. Perhaps I am not understanding your > intention correctly, so please advise. I copied this patch and tweaked it to check feasibility: https://codereview.chromium.org/2448863002/ Can you see this? Note that I haven't tested it well, so there may be a corner case. > The PS2 compiles, but it causes seg fault in the first unit test. (Basic) It looks like that s_threadHolderInstance is never created.
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: chromium_presubmit on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/chromium_presub...)
Description was changed from ========== Refacotring WorkletThreadBackingHolder with template pattern * WIP : DO NOT SUBMIT * The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ========== to ========== Refacotring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ==========
On 2016/10/25 04:29:24, nhiroki (slow until Oct. 31) wrote: > On 2016/10/24 18:39:21, hongchan wrote: > > nhiroki@ > > > > Unfortunately, I am not sure how to make it work with your suggestion. They > are > > not supposed to be initialized/constructed at the same time - I believe the > > worklet thread holder is design to be initialized lazily. > > > > Applying/inheriting forces two objects to be initialized through the single > > construction process, and I think this makes our goal of using the template > > directly to AudioWorkletThread difficult. Perhaps I am not understanding your > > intention correctly, so please advise. > > I copied this patch and tweaked it to check feasibility: > https://codereview.chromium.org/2448863002/ > > Can you see this? Note that I haven't tested it well, so there may be a corner > case. > > > The PS2 compiles, but it causes seg fault in the first unit test. (Basic) > > It looks like that s_threadHolderInstance is never created. The ASAN says unit tests are leaking. I am looking into the issue, but any help would be appreciated - I am not familiar with the worker infrastructure.
https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp (left): https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:52: new AudioWorkletThreadHolder(WorkerBackingThread::createForTest( Ah, we removed this part :p In unit tests, we need to create WorkerBackingThread by WorkerBackingThread::createForTest(). This suppresses leak reports. See https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/workers/W...
On 2016/10/25 22:39:34, nhiroki (slow until Oct. 31) wrote: > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp (left): > > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:52: new > AudioWorkletThreadHolder(WorkerBackingThread::createForTest( > Ah, we removed this part :p > > In unit tests, we need to create WorkerBackingThread by > WorkerBackingThread::createForTest(). This suppresses leak reports. See > https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/workers/W... Good catch! I'll try to fix it. One issue: this template class also needs to support the AnimationWorkletThread. The instantiation is a bit different - AnimationWorklet runs off the compositor thread. The current ensureInstance() method assumes that we create a worker backing thread when it's needed, but for the AnimationWorklet we just use the existing compositor thread. I guess we can always pass platform()->compositorThread() to ensureInstance(), but not sure if it's ideal.
On 2016/10/25 23:04:55, hongchan wrote: > One issue: this template class also needs to support the AnimationWorkletThread. > The instantiation is a bit different - AnimationWorklet runs off the compositor > thread. The current ensureInstance() method assumes that we create a worker > backing thread when it's needed, but for the AnimationWorklet we just use the > existing compositor thread. I guess we can always pass > platform()->compositorThread() to ensureInstance(), but not sure if it's ideal. I'm fine with always passing compositorThread().
I think this is going in a right direction.
https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp (right): https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:70: void AudioWorkletThread::clearSharedBackingThread() { Copied from https://codereview.chromium.org/2448863002/ On 2016/10/26 07:41:49, haraken wrote: > > Are you sure that this method is called? > > As far as I look at the leak log, it looks like WorkletGlobalScope is not > released. Good point. It looks like that this is correctly called in unit tests, but it's not called in production codes.
On 2016/10/26 08:08:18, nhiroki (slow until Oct. 31) wrote: > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp (right): > > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:70: void > AudioWorkletThread::clearSharedBackingThread() { > Copied from https://codereview.chromium.org/2448863002/ > > On 2016/10/26 07:41:49, haraken wrote: > > > > Are you sure that this method is called? > > > > As far as I look at the leak log, it looks like WorkletGlobalScope is not > > released. > > Good point. It looks like that this is correctly called in unit tests, but it's > not called in production codes. We don't have the actual usage of this class in the production code yet. Right?
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
On 2016/10/26 18:35:38, hongchan wrote: > On 2016/10/26 08:08:18, nhiroki (slow until Oct. 31) wrote: > > > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > > File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp > (right): > > > > > https://codereview.chromium.org/2432543002/diff/60001/third_party/WebKit/Sour... > > third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp:70: void > > AudioWorkletThread::clearSharedBackingThread() { > > Copied from https://codereview.chromium.org/2448863002/ > > > > On 2016/10/26 07:41:49, haraken wrote: > > > > > > Are you sure that this method is called? > > > > > > As far as I look at the leak log, it looks like WorkletGlobalScope is not > > > released. > > > > Good point. It looks like that this is correctly called in unit tests, but > it's > > not called in production codes. > > We don't have the actual usage of this class in the production code yet. Right? Ah, OK. I assumed we have layout tests for AudioWorklet.
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
hongchan@chromium.org changed reviewers: + ikilpatrick@chromium.org, rtoy@chromium.org
PTAL. I believe the CL is ready for the actual review. - Applying the new template to AbstractAnimationWorkletThread - Renaming the template class file to WorkletThreadHolder.h - Removing unnecessary files/codes after the refactoring.
LGTM! Thank you for working on this :) https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/workers/WorkletThreadHolder.h (right): https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:17: class WaitableEvent; There are header inclusions for these classes. https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:31: BlinkGC::ThreadHeapMode ThreadHeapMode) { s/ThreadHeapMode/threadHeapMode/ https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:51: BlinkGC::ThreadHeapMode ThreadHeapMode) { s/ThreadHeapMode/threadHeapMode/ https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:53: DCHECK_EQ(nullptr, s_threadHolderInstance); DCHECK(s_threadHolderInstace) would be simpler https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h (right): https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h:51: explicit AudioWorkletThread(PassRefPtr<WorkerLoaderProxy>, Can you remove 'explicit'?
https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/workers/WorkletThreadHolder.h (right): https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:53: DCHECK_EQ(nullptr, s_threadHolderInstance); On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > DCHECK(s_threadHolderInstace) would be simpler DCHECK(!s_threadHolderInstace)
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
LGTM
lgtm
Thanks for the review! https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/workers/WorkletThreadHolder.h (right): https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:17: class WaitableEvent; On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > There are header inclusions for these classes. Done. https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:31: BlinkGC::ThreadHeapMode ThreadHeapMode) { On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > s/ThreadHeapMode/threadHeapMode/ Done. https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:51: BlinkGC::ThreadHeapMode ThreadHeapMode) { On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > s/ThreadHeapMode/threadHeapMode/ Done. https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/core/workers/WorkletThreadHolder.h:53: DCHECK_EQ(nullptr, s_threadHolderInstance); On 2016/10/27 00:04:20, nhiroki (slow until Oct. 31) wrote: > On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > > DCHECK(s_threadHolderInstace) would be simpler > > DCHECK(!s_threadHolderInstace) Done. https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... File third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h (right): https://codereview.chromium.org/2432543002/diff/120001/third_party/WebKit/Sou... third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h:51: explicit AudioWorkletThread(PassRefPtr<WorkerLoaderProxy>, On 2016/10/27 00:03:35, nhiroki (slow until Oct. 31) wrote: > Can you remove 'explicit'? Done.
The CQ bit was checked by hongchan@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
lgtm for webaudio parts.
Please fix the typo in the description ("Refacotring")
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
Description was changed from ========== Refacotring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ========== to ========== Refactoring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ==========
The CQ bit was checked by hongchan@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from haraken@chromium.org, ikilpatrick@chromium.org, nhiroki@chromium.org Link to the patchset: https://codereview.chromium.org/2432543002/#ps140001 (title: "Fixing typos")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Message was sent while issue was closed.
Description was changed from ========== Refactoring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ========== to ========== Refactoring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ==========
Message was sent while issue was closed.
Committed patchset #8 (id:140001)
Message was sent while issue was closed.
Description was changed from ========== Refactoring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) ========== to ========== Refactoring WorkletThreadBackingHolder with template pattern The current design of WorkletBackingThreadHolder has too many duplicated components. Refactor it with the template pattern. BUG=657101 TEST=NONE (The CL passes AudioWorkletThread unit tests.) Committed: https://crrev.com/b6660c6d8bb364f1122c94db9f19a98f38b42a7a Cr-Commit-Position: refs/heads/master@{#428131} ==========
Message was sent while issue was closed.
Patchset 8 (id:??) landed as https://crrev.com/b6660c6d8bb364f1122c94db9f19a98f38b42a7a Cr-Commit-Position: refs/heads/master@{#428131} |
