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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 namespace { | 52 namespace { |
53 | 53 |
54 class WebLeakDetectorImpl final : public WebLeakDetector { | 54 class WebLeakDetectorImpl final : public WebLeakDetector { |
55 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); | 55 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); |
56 public: | 56 public: |
57 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) | 57 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) |
58 : m_client(client) | 58 : m_client(client) |
59 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo rt) | 59 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo rt) |
60 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) | 60 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) |
61 , m_numberOfGCNeeded(0) | 61 , m_numberOfGCNeeded(0) |
62 , m_delayFinalGarbageCollection(false) | |
62 { | 63 { |
63 ASSERT(m_client); | 64 ASSERT(m_client); |
64 } | 65 } |
65 | 66 |
66 ~WebLeakDetectorImpl() override {} | 67 ~WebLeakDetectorImpl() override {} |
67 | 68 |
68 void collectGarbageAndGetDOMCounts(WebLocalFrame*) override; | 69 void collectGarbageAndGetDOMCounts(WebLocalFrame*) override; |
69 | 70 |
71 void delayFinalGarbageCollection() override { m_delayFinalGarbageCollection = true; } | |
72 void collectFinalGarbage() override; | |
73 | |
70 private: | 74 private: |
71 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); | 75 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); |
72 void delayedReport(Timer<WebLeakDetectorImpl>*); | 76 void delayedReport(Timer<WebLeakDetectorImpl>*); |
73 | 77 |
74 WebLeakDetectorClient* m_client; | 78 WebLeakDetectorClient* m_client; |
75 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; | 79 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; |
76 Timer<WebLeakDetectorImpl> m_delayedReportTimer; | 80 Timer<WebLeakDetectorImpl> m_delayedReportTimer; |
77 int m_numberOfGCNeeded; | 81 int m_numberOfGCNeeded; |
82 bool m_delayFinalGarbageCollection; | |
78 }; | 83 }; |
79 | 84 |
85 void WebLeakDetectorImpl::collectFinalGarbage() | |
86 { | |
87 ASSERT(m_delayFinalGarbageCollection); | |
88 | |
89 // Task queue may contain delayed object destruction tasks. | |
90 // This method is called from navigation hook inside FrameLoader, | |
91 // so previous document is still held by the loader until the next event loo p. | |
92 // Complete all pending tasks before proceeding to gc. | |
93 m_numberOfGCNeeded = 2; | |
94 m_delayedGCAndReportTimer.startOneShot(0, BLINK_FROM_HERE); | |
95 } | |
96 | |
80 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame) | 97 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame) |
haraken
2015/11/24 23:54:51
Instead of introducing a notion of "delayed", I'd
| |
81 { | 98 { |
82 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 99 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
83 v8::HandleScope handleScope(isolate); | 100 v8::HandleScope handleScope(isolate); |
84 | 101 |
85 // For example, calling isValidEmailAddress in EmailInputType.cpp with a | 102 // For example, calling isValidEmailAddress in EmailInputType.cpp with a |
86 // non-empty string creates a static ScriptRegexp value which holds a | 103 // non-empty string creates a static ScriptRegexp value which holds a |
87 // V8PerContextData indirectly. This affects the number of V8PerContextData. | 104 // V8PerContextData indirectly. This affects the number of V8PerContextData. |
88 // To ensure that context data is created, call ensureScriptRegexpContext | 105 // To ensure that context data is created, call ensureScriptRegexpContext |
89 // here. | 106 // here. |
90 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext(); | 107 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext(); |
91 | 108 |
92 WorkerThread::terminateAndWaitForAllWorkers(); | 109 WorkerThread::terminateAndWaitForAllWorkers(); |
93 memoryCache()->evictResources(); | 110 memoryCache()->evictResources(); |
94 | 111 |
95 { | 112 { |
96 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document()); | 113 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document()); |
97 if (ResourceFetcher* fetcher = document->fetcher()) | 114 if (ResourceFetcher* fetcher = document->fetcher()) |
98 fetcher->garbageCollectDocumentResources(); | 115 fetcher->garbageCollectDocumentResources(); |
99 } | 116 } |
100 | 117 |
101 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects. | 118 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects. |
102 | 119 |
103 V8GCController::collectAllGarbageForTesting(isolate); | 120 V8GCController::collectAllGarbageForTesting(isolate); |
haraken
2015/11/24 23:54:51
This will run Oilpan's GC. Doesn't it need to be d
| |
104 // Note: Oilpan precise GC is scheduled at the end of the event loop. | 121 // Note: Oilpan precise GC is scheduled at the end of the event loop. |
105 | 122 |
106 V8PerIsolateData::from(isolate)->clearScriptRegexpContext(); | 123 V8PerIsolateData::from(isolate)->clearScriptRegexpContext(); |
107 | 124 |
108 // Task queue may contain delayed object destruction tasks. | 125 if (m_delayFinalGarbageCollection) |
109 // This method is called from navigation hook inside FrameLoader, | 126 return; |
110 // so previous document is still held by the loader until the next event loo p. | 127 |
111 // Complete all pending tasks before proceeding to gc. | 128 collectFinalGarbage(); |
112 m_numberOfGCNeeded = 2; | |
113 m_delayedGCAndReportTimer.startOneShot(0, BLINK_FROM_HERE); | |
114 } | 129 } |
115 | 130 |
116 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*) | 131 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*) |
117 { | 132 { |
118 // We do a second and third GC here to address flakiness | 133 // We do a second and third GC here to address flakiness |
119 // The second GC is necessary as Resource GC may have postponed clean-up tas ks to next event loop. | 134 // The second GC is necessary as Resource GC may have postponed clean-up tas ks to next event loop. |
120 // The third GC is necessary for cleaning up Document after worker object di ed. | 135 // The third GC is necessary for cleaning up Document after worker object di ed. |
121 | 136 |
122 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol ate()); | 137 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol ate()); |
123 // Note: Oilpan precise GC is scheduled at the end of the event loop. | 138 // Note: Oilpan precise GC is scheduled at the end of the event loop. |
(...skipping 28 matching lines...) Expand all Loading... | |
152 } | 167 } |
153 | 168 |
154 } // namespace | 169 } // namespace |
155 | 170 |
156 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) | 171 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) |
157 { | 172 { |
158 return new WebLeakDetectorImpl(client); | 173 return new WebLeakDetectorImpl(client); |
159 } | 174 } |
160 | 175 |
161 } // namespace blink | 176 } // namespace blink |
OLD | NEW |