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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp

Issue 2625093002: [wrapper-tracing] Add heap snapshot generator infrastructure (Closed)
Patch Set: Move the scope to V8PerIsolateData Created 3 years, 11 months 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); 141 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
142 return; 142 return;
143 } 143 }
144 } 144 }
145 } 145 }
146 146
147 private: 147 private:
148 v8::Isolate* m_isolate; 148 v8::Isolate* m_isolate;
149 }; 149 };
150 150
151 class HeapSnaphotWrapperVisitor : public ScriptWrappableVisitor {
152 public:
153 explicit HeapSnaphotWrapperVisitor(v8::Isolate* isolate)
154 : ScriptWrappableVisitor(isolate) {}
155
156 // Trace through the blink heap to find all V8 wrappers reachable from
157 // ActiveScriptWrappables.
158 WTF::HashSet<const v8::PersistentBase<v8::Value>*> findPendingWrappers() {
159 m_foundV8Wrappers.clear();
160
161 TracePrologue();
162 ActiveScriptWrappableBase::traceActiveScriptWrappables(m_isolate, this);
163 AdvanceTracing(
164 0,
165 v8::EmbedderHeapTracer::AdvanceTracingActions(
166 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION));
167 // Abort instead of Epilogue as we want to finish synchronously.
168 AbortTracing();
169
170 return std::move(m_foundV8Wrappers);
171 }
172
173 // Trace through the blink heap to find all V8 wrappers reachable from
174 // |traceable|.
175 WTF::HashSet<const v8::PersistentBase<v8::Value>*>
176 findV8WrappersReachableFrom(ScriptWrappable* traceable) {
177 m_foundV8Wrappers.clear();
178
179 TracePrologue();
180 traceable->wrapperTypeInfo()->traceWrappers(this, traceable);
181 AdvanceTracing(
182 0,
183 v8::EmbedderHeapTracer::AdvanceTracingActions(
184 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION));
185 // Abort instead of Epilogue as we want to finish synchronously.
186 AbortTracing();
187
188 return std::move(m_foundV8Wrappers);
189 }
190
191 void markWrapper(const v8::PersistentBase<v8::Value>* value) const override {
192 if (!m_tracingInProgress || m_foundV8Wrappers.contains(value))
193 return;
194 m_foundV8Wrappers.add(value);
195 }
196
197 private:
198 mutable WTF::HashSet<const v8::PersistentBase<v8::Value>*> m_foundV8Wrappers;
alph 2017/01/12 08:59:00 I wonder why not std::unordered_set ?
Michael Lippautz 2017/01/12 12:23:19 Done. Actually I changed the API type to unodred_s
199 };
200
201 class HeapSnapshotHandlesVisitor : public v8::PersistentHandleVisitor {
202 public:
203 explicit HeapSnapshotHandlesVisitor(v8::Isolate* isolate) {}
204
205 void VisitPersistentHandle(v8::Persistent<v8::Value>* value,
206 uint16_t classId) override {
207 // TODO: Fill m_nodesRequiringTracing.
208 }
209
210 WTF::HashSet<UntracedMember<Node>> nodesRequiringTracing() {
211 return std::move(m_nodesRequiringTracing);
212 }
213
214 private:
215 WTF::HashSet<UntracedMember<Node>> m_nodesRequiringTracing;
216 };
217
218 v8::HeapProfiler::RetainerInfos V8GCController::getRetainerInfos(
219 v8::Isolate* isolate) {
220 v8::HeapProfiler::RetainerInfos infos;
221 HeapSnaphotWrapperVisitor tracer(isolate);
222
223 // Find wrappers for pending activities.
224 {
225 V8PerIsolateData::TemporaryScriptWrappableVisitorScope scope(isolate,
226 &tracer);
227 std::vector<const v8::PersistentBase<v8::Value>*> wrappers;
228 for (auto& wrapper : tracer.findPendingWrappers()) {
229 wrappers.push_back(wrapper);
230 }
231 infos.push_back(std::make_pair(new SuspendableObjectsInfo(wrappers.size()),
232 std::move(wrappers)));
233 }
234
235 // Find wrappers for DOM trees.
236 {
237 HeapSnapshotHandlesVisitor visitor(isolate);
238 // TODO
239 }
240
241 return infos;
242 }
243
151 class MajorGCWrapperVisitor : public v8::PersistentHandleVisitor { 244 class MajorGCWrapperVisitor : public v8::PersistentHandleVisitor {
152 public: 245 public:
153 explicit MajorGCWrapperVisitor(v8::Isolate* isolate, 246 explicit MajorGCWrapperVisitor(v8::Isolate* isolate,
154 bool constructRetainedObjectInfos) 247 bool constructRetainedObjectInfos)
155 : m_isolate(isolate), 248 : m_isolate(isolate),
156 m_domObjectsWithPendingActivity(0), 249 m_domObjectsWithPendingActivity(0),
157 m_liveRootGroupIdSet(false), 250 m_liveRootGroupIdSet(false),
158 m_constructRetainedObjectInfos(constructRetainedObjectInfos) {} 251 m_constructRetainedObjectInfos(constructRetainedObjectInfos) {}
159 252
160 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, 253 void VisitPersistentHandle(v8::Persistent<v8::Value>* value,
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 double startTime = WTF::currentTimeMS(); 637 double startTime = WTF::currentTimeMS();
545 v8::HandleScope scope(isolate); 638 v8::HandleScope scope(isolate);
546 PendingActivityVisitor visitor(isolate, executionContext); 639 PendingActivityVisitor visitor(isolate, executionContext);
547 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); 640 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor);
548 scanPendingActivityHistogram.count( 641 scanPendingActivityHistogram.count(
549 static_cast<int>(WTF::currentTimeMS() - startTime)); 642 static_cast<int>(WTF::currentTimeMS() - startTime));
550 return visitor.pendingActivityFound(); 643 return visitor.pendingActivityFound();
551 } 644 }
552 645
553 } // namespace blink 646 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698