| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef MessageLoopInterruptor_h | 31 #ifndef GCTaskRunner_h |
| 32 #define MessageLoopInterruptor_h | 32 #define GCTaskRunner_h |
| 33 | 33 |
| 34 #include "platform/heap/BlinkGCInterruptor.h" | 34 #include "platform/heap/ThreadState.h" |
| 35 #include "public/platform/WebTaskRunner.h" | 35 #include "public/platform/WebTaskRunner.h" |
| 36 #include "public/platform/WebThread.h" |
| 36 #include "public/platform/WebTraceLocation.h" | 37 #include "public/platform/WebTraceLocation.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 class MessageLoopInterruptor : public BlinkGCInterruptor { | 41 class MessageLoopInterruptor final : public BlinkGCInterruptor { |
| 41 public: | 42 public: |
| 42 explicit MessageLoopInterruptor(WebTaskRunner* taskRunner) : m_taskRunner(ta
skRunner) { } | 43 explicit MessageLoopInterruptor(WebTaskRunner* taskRunner) : m_taskRunner(ta
skRunner) { } |
| 43 | 44 |
| 44 void requestInterrupt() override | 45 void requestInterrupt() override |
| 45 { | 46 { |
| 46 // GCTask has an empty run() method. Its only purpose is to guarantee | 47 // GCTask has an empty run() method. Its only purpose is to guarantee |
| 47 // that MessageLoop will have a task to process which will result | 48 // that MessageLoop will have a task to process which will result |
| 48 // in PendingGCRunner::didProcessTask being executed. | 49 // in GCTaskRunner::didProcessTask being executed. |
| 49 m_taskRunner->postTask(BLINK_FROM_HERE, new GCTask); | 50 m_taskRunner->postTask(BLINK_FROM_HERE, new GCTask); |
| 50 } | 51 } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 class GCTask : public WebTaskRunner::Task { | 54 class GCTask : public WebTaskRunner::Task { |
| 54 public: | 55 public: |
| 55 virtual ~GCTask() { } | 56 virtual ~GCTask() { } |
| 56 | 57 |
| 57 void run() override | 58 void run() override |
| 58 { | 59 { |
| 59 // Don't do anything here because we don't know if this is | 60 // Don't do anything here because we don't know if this is |
| 60 // a nested event loop or not. PendingGCRunner::didProcessTask | 61 // a nested event loop or not. GCTaskRunner::didProcessTask |
| 61 // will enter correct safepoint for us. | 62 // will enter correct safepoint for us. |
| 62 // We are not calling onInterrupted() because that always | 63 // We are not calling onInterrupted() because that always |
| 63 // conservatively enters safepoint with pointers on stack. | 64 // conservatively enters safepoint with pointers on stack. |
| 64 } | 65 } |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 WebTaskRunner* m_taskRunner; | 68 WebTaskRunner* m_taskRunner; |
| 68 }; | 69 }; |
| 69 | 70 |
| 71 class GCTaskObserver final : public WebThread::TaskObserver { |
| 72 public: |
| 73 GCTaskObserver() : m_nesting(0) { } |
| 74 |
| 75 ~GCTaskObserver() |
| 76 { |
| 77 // m_nesting can be 1 if this was unregistered in a task and |
| 78 // didProcessTask was not called. |
| 79 ASSERT(!m_nesting || m_nesting == 1); |
| 80 } |
| 81 |
| 82 virtual void willProcessTask() |
| 83 { |
| 84 m_nesting++; |
| 85 } |
| 86 |
| 87 virtual void didProcessTask() |
| 88 { |
| 89 // In the production code WebKit::initialize is called from inside the |
| 90 // message loop so we can get didProcessTask() without corresponding |
| 91 // willProcessTask once. This is benign. |
| 92 if (m_nesting) |
| 93 m_nesting--; |
| 94 |
| 95 ThreadState::current()->safePoint(m_nesting ? BlinkGC::HeapPointersOnSta
ck : BlinkGC::NoHeapPointersOnStack); |
| 96 } |
| 97 |
| 98 private: |
| 99 int m_nesting; |
| 100 }; |
| 101 |
| 102 class GCTaskRunner final { |
| 103 public: |
| 104 explicit GCTaskRunner(WebThread* thread) |
| 105 : m_gcTaskObserver(adoptPtr(new GCTaskObserver)) |
| 106 , m_thread(thread) |
| 107 { |
| 108 m_thread->addTaskObserver(m_gcTaskObserver.get()); |
| 109 ThreadState::current()->addInterruptor(adoptPtr(new MessageLoopInterrupt
or(thread->taskRunner()))); |
| 110 } |
| 111 |
| 112 ~GCTaskRunner() |
| 113 { |
| 114 m_thread->removeTaskObserver(m_gcTaskObserver.get()); |
| 115 } |
| 116 |
| 117 private: |
| 118 OwnPtr<GCTaskObserver> m_gcTaskObserver; |
| 119 WebThread* m_thread; |
| 120 }; |
| 121 |
| 70 } // namespace blink | 122 } // namespace blink |
| 71 | 123 |
| 72 #endif | 124 #endif |
| OLD | NEW |