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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // Please see comment in Heap::collectAllGarbage() | 54 // Please see comment in Heap::collectAllGarbage() |
55 static const int kNumberOfGCsToClaimChains = 5; | 55 static const int kNumberOfGCsToClaimChains = 5; |
56 | 56 |
57 class WebLeakDetectorImpl FINAL : public WebLeakDetector { | 57 class WebLeakDetectorImpl FINAL : public WebLeakDetector { |
58 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); | 58 WTF_MAKE_NONCOPYABLE(WebLeakDetectorImpl); |
59 public: | 59 public: |
60 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) | 60 explicit WebLeakDetectorImpl(WebLeakDetectorClient* client) |
61 : m_client(client) | 61 : m_client(client) |
62 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo rt) | 62 , m_delayedGCAndReportTimer(this, &WebLeakDetectorImpl::delayedGCAndRepo rt) |
63 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) | 63 , m_delayedReportTimer(this, &WebLeakDetectorImpl::delayedReport) |
64 , m_numberOfGCNeeded(0) | |
tkent
2014/06/27 00:10:55
We can initialize it with 2.
tkent
2014/06/27 00:11:56
maybe no. We may call collectGarbageAndGetDOMCoun
| |
64 { | 65 { |
65 ASSERT(m_client); | 66 ASSERT(m_client); |
66 } | 67 } |
67 | 68 |
68 virtual ~WebLeakDetectorImpl() { } | 69 virtual ~WebLeakDetectorImpl() { } |
69 | 70 |
70 virtual void collectGarbageAndGetDOMCounts(WebLocalFrame*) OVERRIDE; | 71 virtual void collectGarbageAndGetDOMCounts(WebLocalFrame*) OVERRIDE; |
71 | 72 |
72 private: | 73 private: |
73 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); | 74 void delayedGCAndReport(Timer<WebLeakDetectorImpl>*); |
74 void delayedReport(Timer<WebLeakDetectorImpl>*); | 75 void delayedReport(Timer<WebLeakDetectorImpl>*); |
75 | 76 |
76 WebLeakDetectorClient* m_client; | 77 WebLeakDetectorClient* m_client; |
77 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; | 78 Timer<WebLeakDetectorImpl> m_delayedGCAndReportTimer; |
78 Timer<WebLeakDetectorImpl> m_delayedReportTimer; | 79 Timer<WebLeakDetectorImpl> m_delayedReportTimer; |
80 int m_numberOfGCNeeded; | |
79 }; | 81 }; |
80 | 82 |
81 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame) | 83 void WebLeakDetectorImpl::collectGarbageAndGetDOMCounts(WebLocalFrame* frame) |
82 { | 84 { |
83 memoryCache()->evictResources(); | 85 memoryCache()->evictResources(); |
84 | 86 |
85 { | 87 { |
86 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document()); | 88 RefPtrWillBeRawPtr<Document> document = PassRefPtrWillBeRawPtr<Document> (frame->document()); |
87 if (ResourceFetcher* fetcher = document->fetcher()) | 89 if (ResourceFetcher* fetcher = document->fetcher()) |
88 fetcher->garbageCollectDocumentResources(); | 90 fetcher->garbageCollectDocumentResources(); |
89 } | 91 } |
90 | 92 |
91 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects. | 93 // FIXME: HTML5 Notification should be closed because notification affects t he result of number of DOM objects. |
92 | 94 |
93 for (int i = 0; i < kNumberOfGCsToClaimChains; ++i) | 95 for (int i = 0; i < kNumberOfGCsToClaimChains; ++i) |
94 V8GCController::collectGarbage(v8::Isolate::GetCurrent()); | 96 V8GCController::collectGarbage(v8::Isolate::GetCurrent()); |
95 // Note: Oilpan precise GC is scheduled at the end of the event loop. | 97 // Note: Oilpan precise GC is scheduled at the end of the event loop. |
96 | 98 |
97 // Task queue may contain delayed object destruction tasks. | 99 // Task queue may contain delayed object destruction tasks. |
98 // This method is called from navigation hook inside FrameLoader, | 100 // This method is called from navigation hook inside FrameLoader, |
99 // so previous document is still held by the loader until the next event loo p. | 101 // so previous document is still held by the loader until the next event loo p. |
100 // Complete all pending tasks before proceeding to gc. | 102 // Complete all pending tasks before proceeding to gc. |
103 m_numberOfGCNeeded = 2; | |
101 m_delayedGCAndReportTimer.startOneShot(0, FROM_HERE); | 104 m_delayedGCAndReportTimer.startOneShot(0, FROM_HERE); |
102 } | 105 } |
103 | 106 |
104 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*) | 107 void WebLeakDetectorImpl::delayedGCAndReport(Timer<WebLeakDetectorImpl>*) |
105 { | 108 { |
106 // We do a second GC here to address flakiness: Resource GC may have postpon ed clean-up tasks to next event loop. | 109 // We do a second and third GC here to address flakiness |
110 // The second GC is necessary as Resource GC may have postponed clean-up tas ks to next event loop. | |
111 // The third GC is necessary for cleaning up Document after worker object di ed. | |
107 | 112 |
108 for (int i = 0; i < kNumberOfGCsToClaimChains; ++i) | 113 for (int i = 0; i < kNumberOfGCsToClaimChains; ++i) |
109 V8GCController::collectGarbage(V8PerIsolateData::mainThreadIsolate()); | 114 V8GCController::collectGarbage(V8PerIsolateData::mainThreadIsolate()); |
110 // Note: Oilpan precise GC is scheduled at the end of the event loop. | 115 // Note: Oilpan precise GC is scheduled at the end of the event loop. |
111 | 116 |
112 // Inspect counters on the next event loop. | 117 // Inspect counters on the next event loop. |
113 m_delayedReportTimer.startOneShot(0, FROM_HERE); | 118 if (--m_numberOfGCNeeded) |
119 m_delayedGCAndReportTimer.startOneShot(0, FROM_HERE); | |
120 else | |
121 m_delayedReportTimer.startOneShot(0, FROM_HERE); | |
114 } | 122 } |
115 | 123 |
116 void WebLeakDetectorImpl::delayedReport(Timer<WebLeakDetectorImpl>*) | 124 void WebLeakDetectorImpl::delayedReport(Timer<WebLeakDetectorImpl>*) |
117 { | 125 { |
118 ASSERT(m_client); | 126 ASSERT(m_client); |
119 | 127 |
120 WebLeakDetectorClient::Result result; | 128 WebLeakDetectorClient::Result result; |
121 result.numberOfLiveDocuments = InspectorCounters::counterValue(InspectorCoun ters::DocumentCounter); | 129 result.numberOfLiveDocuments = InspectorCounters::counterValue(InspectorCoun ters::DocumentCounter); |
122 result.numberOfLiveNodes = InspectorCounters::counterValue(InspectorCounters ::NodeCounter); | 130 result.numberOfLiveNodes = InspectorCounters::counterValue(InspectorCounters ::NodeCounter); |
123 | 131 |
124 m_client->onLeakDetectionComplete(result); | 132 m_client->onLeakDetectionComplete(result); |
125 } | 133 } |
126 | 134 |
127 } // namespace | 135 } // namespace |
128 | 136 |
129 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) | 137 WebLeakDetector* WebLeakDetector::create(WebLeakDetectorClient* client) |
130 { | 138 { |
131 return new WebLeakDetectorImpl(client); | 139 return new WebLeakDetectorImpl(client); |
132 } | 140 } |
133 | 141 |
134 } // namespace blink | 142 } // namespace blink |
OLD | NEW |