| 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 17 matching lines...) Expand all Loading... |
| 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 #include "public/web/WebLeakDetector.h" | 31 #include "public/web/WebLeakDetector.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ScriptPromise.h" | 33 #include "bindings/core/v8/ScriptPromise.h" |
| 34 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
| 35 #include "bindings/core/v8/V8GCController.h" | 35 #include "bindings/core/v8/V8GCController.h" |
| 36 #include "core/dom/ActiveDOMObject.h" | 36 #include "core/dom/ActiveDOMObject.h" |
| 37 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 38 #include "core/editing/spellcheck/SpellChecker.h" |
| 38 #include "core/fetch/MemoryCache.h" | 39 #include "core/fetch/MemoryCache.h" |
| 39 #include "core/inspector/InstanceCounters.h" | 40 #include "core/inspector/InstanceCounters.h" |
| 40 #include "core/layout/LayoutObject.h" | 41 #include "core/layout/LayoutObject.h" |
| 41 #include "core/workers/WorkerThread.h" | 42 #include "core/workers/WorkerThread.h" |
| 42 #include "modules/webaudio/AudioNode.h" | 43 #include "modules/webaudio/AudioNode.h" |
| 43 #include "platform/Timer.h" | 44 #include "platform/Timer.h" |
| 44 #include "public/web/WebDocument.h" | 45 #include "public/web/WebDocument.h" |
| 45 #include "public/web/WebLocalFrame.h" | 46 #include "public/web/WebFrame.h" |
| 47 #include "web/WebLocalFrameImpl.h" |
| 46 | 48 |
| 47 namespace blink { | 49 namespace blink { |
| 48 | 50 |
| 49 namespace { | 51 namespace { |
| 50 | 52 |
| 51 class WebLeakDetectorImpl final : public WebLeakDetector { | 53 class WebLeakDetectorImpl final : public WebLeakDetector { |
| 52 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); | 54 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); |
| 53 public: | 55 public: |
| 54 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) | 56 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) |
| 55 : m_client(client) | 57 : m_client(client) |
| 56 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo
rt) | 58 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo
rt) |
| 57 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) | 59 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) |
| 58 , m_numberOfGCNeeded(0) | 60 , m_numberOfGCNeeded(0) |
| 59 { | 61 { |
| 60 ASSERT(m_client); | 62 ASSERT(m_client); |
| 61 } | 63 } |
| 62 | 64 |
| 63 ~WebLeakDetectorImpl() override {} | 65 ~WebLeakDetectorImpl() override {} |
| 64 | 66 |
| 65 void prepareForLeakDetection() override; | 67 void prepareForLeakDetection(WebFrame*) override; |
| 66 void collectGarbageAndReport() override; | 68 void collectGarbageAndReport() override; |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); | 71 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); |
| 70 void delayedReport(Timer<WebLeakDetectorImpl>*); | 72 void delayedReport(Timer<WebLeakDetectorImpl>*); |
| 71 | 73 |
| 72 WebLeakDetectorClient* m_client; | 74 WebLeakDetectorClient* m_client; |
| 73 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; | 75 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; |
| 74 Timer<WebLeakDetectorImpl> m_delayedReportTimer; | 76 Timer<WebLeakDetectorImpl> m_delayedReportTimer; |
| 75 int m_numberOfGCNeeded; | 77 int m_numberOfGCNeeded; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 void WebLeakDetectorImpl::prepareForLeakDetection() | 80 void WebLeakDetectorImpl::prepareForLeakDetection(WebFrame* frame) |
| 79 { | 81 { |
| 80 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 82 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 81 v8::HandleScope handleScope(isolate); | 83 v8::HandleScope handleScope(isolate); |
| 82 | 84 |
| 83 // For example, calling isValidEmailAddress in EmailInputType.cpp with a | 85 // For example, calling isValidEmailAddress in EmailInputType.cpp with a |
| 84 // non-empty string creates a static ScriptRegexp value which holds a | 86 // non-empty string creates a static ScriptRegexp value which holds a |
| 85 // V8PerContextData indirectly. This affects the number of V8PerContextData. | 87 // V8PerContextData indirectly. This affects the number of V8PerContextData. |
| 86 // To ensure that context data is created, call ensureScriptRegexpContext | 88 // To ensure that context data is created, call ensureScriptRegexpContext |
| 87 // here. | 89 // here. |
| 88 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext(); | 90 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext(); |
| 89 | 91 |
| 90 WorkerThread::terminateAndWaitForAllWorkers(); | 92 WorkerThread::terminateAndWaitForAllWorkers(); |
| 91 memoryCache()->evictResources(); | 93 memoryCache()->evictResources(); |
| 92 | 94 |
| 95 // If the spellchecker is allowed to continue issuing requests while the |
| 96 // leak detector runs, leaks may flakily be reported as the requests keep |
| 97 // their associated element (and document) alive. |
| 98 // |
| 99 // Stop the spellchecker to prevent this. |
| 100 if (frame->isWebLocalFrame()) { |
| 101 WebLocalFrameImpl* localFrame = toWebLocalFrameImpl(frame); |
| 102 SpellChecker& spellChecker = localFrame->frame()->spellChecker(); |
| 103 spellChecker.prepareForLeakDetection(); |
| 104 } |
| 105 |
| 93 // FIXME: HTML5 Notification should be closed because notification affects t
he result of number of DOM objects. | 106 // FIXME: HTML5 Notification should be closed because notification affects t
he result of number of DOM objects. |
| 94 | 107 |
| 95 V8PerIsolateData::from(isolate)->clearScriptRegexpContext(); | 108 V8PerIsolateData::from(isolate)->clearScriptRegexpContext(); |
| 96 } | 109 } |
| 97 | 110 |
| 98 void WebLeakDetectorImpl::collectGarbageAndReport() | 111 void WebLeakDetectorImpl::collectGarbageAndReport() |
| 99 { | 112 { |
| 100 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol
ate()); | 113 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol
ate()); |
| 101 // Note: Oilpan precise GC is scheduled at the end of the event loop. | 114 // Note: Oilpan precise GC is scheduled at the end of the event loop. |
| 102 | 115 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 160 } |
| 148 | 161 |
| 149 } // namespace | 162 } // namespace |
| 150 | 163 |
| 151 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) | 164 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) |
| 152 { | 165 { |
| 153 return new WebLeakDetectorImpl(client); | 166 return new WebLeakDetectorImpl(client); |
| 154 } | 167 } |
| 155 | 168 |
| 156 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |