Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/WebKit/Source/web/WebLeakDetector.cpp

Issue 1472943004: Split up leak detector into two stages for better leak reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rephrase WebLeakDetector as two-phased Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 #if ENABLE(ASSERT)
63 , m_haveReported(false)
64 #endif
62 { 65 {
63 ASSERT(m_client); 66 ASSERT(m_client);
64 } 67 }
65 68
66 ~WebLeakDetectorImpl() override {} 69 ~WebLeakDetectorImpl() override {}
67 70
68 void collectGarbageAndGetDOMCounts(WebLocalFrame*) override; 71 void collectGarbageAndGetDOMCounts(WebLocalFrame*) override;
69 72
73 void prepareForLeakDetection(WebLocalFrame*) override;
74 void collectGarbageAndReport() override;
75
70 private: 76 private:
71 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); 77 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*);
72 void delayedReport(Timer<WebLeakDetectorImpl>*); 78 void delayedReport(Timer<WebLeakDetectorImpl>*);
73 79
74 WebLeakDetectorClient* m_client; 80 WebLeakDetectorClient* m_client;
75 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; 81 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer;
76 Timer<WebLeakDetectorImpl> m_delayedReportTimer; 82 Timer<WebLeakDetectorImpl> m_delayedReportTimer;
77 int m_numberOfGCNeeded; 83 int m_numberOfGCNeeded;
84 #if ENABLE(ASSERT)
85 bool m_haveReported;
86 #endif
78 }; 87 };
79 88
80 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame) 89 void WebLeakDetectorImpl::prepareForLeakDetection(WebLocalFrame* frame)
81 { 90 {
82 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 91 v8::Isolate* isolate = v8::Isolate::GetCurrent();
83 v8::HandleScope handleScope(isolate); 92 v8::HandleScope handleScope(isolate);
84 93
85 // For example, calling isValidEmailAddress in EmailInputType.cpp with a 94 // For example, calling isValidEmailAddress in EmailInputType.cpp with a
86 // non-empty string creates a static ScriptRegexp value which holds a 95 // non-empty string creates a static ScriptRegexp value which holds a
87 // V8PerContextData indirectly. This affects the number of V8PerContextData. 96 // V8PerContextData indirectly. This affects the number of V8PerContextData.
88 // To ensure that context data is created, call ensureScriptRegexpContext 97 // To ensure that context data is created, call ensureScriptRegexpContext
89 // here. 98 // here.
90 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext(); 99 V8PerIsolateData::from(isolate)->ensureScriptRegexpContext();
91 100
92 WorkerThread::terminateAndWaitForAllWorkers(); 101 WorkerThread::terminateAndWaitForAllWorkers();
93 memoryCache()->evictResources(); 102 memoryCache()->evictResources();
94 103
95 { 104 {
96 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document()); 105 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document());
97 if (ResourceFetcher* fetcher = document->fetcher()) 106 if (ResourceFetcher* fetcher = document->fetcher())
98 fetcher->garbageCollectDocumentResources(); 107 fetcher->garbageCollectDocumentResources();
99 } 108 }
100 109
101 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects. 110 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects.
111 }
112
113 void WebLeakDetectorImpl::collectGarbageAndReport()
114 {
115 #if ENABLE(ASSERT)
116 // Repeated uses are not supported.
117 ASSERT(!m_haveReported);
118 m_haveReported = true;
119 #endif
120
121 v8::Isolate* isolate = v8::Isolate::GetCurrent();
122 v8::HandleScope handleScope(isolate);
102 123
103 V8GCController::collectAllGarbageForTesting(isolate); 124 V8GCController::collectAllGarbageForTesting(isolate);
104 // Note: Oilpan precise GC is scheduled at the end of the event loop. 125 // Note: Oilpan precise GC is scheduled at the end of the event loop.
105 126
106 V8PerIsolateData::from(isolate)->clearScriptRegexpContext(); 127 V8PerIsolateData::from(isolate)->clearScriptRegexpContext();
107 128
108 // Task queue may contain delayed object destruction tasks. 129 // Task queue may contain delayed object destruction tasks.
109 // This method is called from navigation hook inside FrameLoader, 130 // This method is called from navigation hook inside FrameLoader,
110 // so previous document is still held by the loader until the next event loo p. 131 // so previous document is still held by the loader until the next event loo p.
111 // Complete all pending tasks before proceeding to gc. 132 // Complete all pending tasks before proceeding to gc.
112 m_numberOfGCNeeded = 2; 133 m_numberOfGCNeeded = 2;
113 m_delayedGCAndReportTimer.startOneShot(0, BLINK_FROM_HERE); 134 m_delayedGCAndReportTimer.startOneShot(0, BLINK_FROM_HERE);
114 } 135 }
115 136
137 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame)
138 {
139 prepareForLeakDetection(frame);
140 collectGarbageAndReport();
141 }
142
116 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*) 143 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*)
117 { 144 {
118 // We do a second and third GC here to address flakiness 145 // 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. 146 // 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. 147 // The third GC is necessary for cleaning up Document after worker object di ed.
121 148
122 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol ate()); 149 V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsol ate());
123 // Note: Oilpan precise GC is scheduled at the end of the event loop. 150 // Note: Oilpan precise GC is scheduled at the end of the event loop.
124 151
125 // Inspect counters on the next event loop. 152 // Inspect counters on the next event loop.
(...skipping 26 matching lines...) Expand all
152 } 179 }
153 180
154 } // namespace 181 } // namespace
155 182
156 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) 183 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client)
157 { 184 {
158 return new WebLeakDetectorImpl(client); 185 return new WebLeakDetectorImpl(client);
159 } 186 }
160 187
161 } // namespace blink 188 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698