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

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

Issue 1609343002: Move hasPendingActivity from ActiveDOMObject to ScriptWrappable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 "bindings/core/v8/V8GCController.h" 31 #include "bindings/core/v8/V8GCController.h"
32 32
33 #include "bindings/core/v8/NPV8Object.h"
33 #include "bindings/core/v8/RetainedDOMInfo.h" 34 #include "bindings/core/v8/RetainedDOMInfo.h"
34 #include "bindings/core/v8/V8AbstractEventListener.h" 35 #include "bindings/core/v8/V8AbstractEventListener.h"
35 #include "bindings/core/v8/V8Binding.h" 36 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8MutationObserver.h" 37 #include "bindings/core/v8/V8MutationObserver.h"
37 #include "bindings/core/v8/V8Node.h" 38 #include "bindings/core/v8/V8Node.h"
38 #include "bindings/core/v8/V8ScriptRunner.h" 39 #include "bindings/core/v8/V8ScriptRunner.h"
39 #include "bindings/core/v8/WrapperTypeInfo.h" 40 #include "bindings/core/v8/WrapperTypeInfo.h"
40 #include "core/dom/Attr.h" 41 #include "core/dom/Attr.h"
41 #include "core/dom/Document.h" 42 #include "core/dom/Document.h"
42 #include "core/dom/NodeTraversal.h" 43 #include "core/dom/NodeTraversal.h"
43 #include "core/dom/TemplateContentDocumentFragment.h" 44 #include "core/dom/TemplateContentDocumentFragment.h"
44 #include "core/dom/shadow/ElementShadow.h" 45 #include "core/dom/shadow/ElementShadow.h"
45 #include "core/dom/shadow/ShadowRoot.h" 46 #include "core/dom/shadow/ShadowRoot.h"
46 #include "core/html/HTMLImageElement.h" 47 #include "core/html/HTMLImageElement.h"
47 #include "core/html/HTMLTemplateElement.h" 48 #include "core/html/HTMLTemplateElement.h"
48 #include "core/html/imports/HTMLImportsController.h" 49 #include "core/html/imports/HTMLImportsController.h"
49 #include "core/inspector/InspectorTraceEvents.h" 50 #include "core/inspector/InspectorTraceEvents.h"
50 #include "core/svg/SVGElement.h" 51 #include "core/svg/SVGElement.h"
52 #include "platform/Histogram.h"
51 #include "platform/TraceEvent.h" 53 #include "platform/TraceEvent.h"
52 #include "wtf/Partitions.h" 54 #include "wtf/Partitions.h"
53 #include "wtf/Vector.h" 55 #include "wtf/Vector.h"
54 #include <algorithm> 56 #include <algorithm>
55 57
56 namespace blink { 58 namespace blink {
57 59
58 // FIXME: This should use opaque GC roots. 60 // FIXME: This should use opaque GC roots.
59 static void addReferencesForNodeWithEventListeners(v8::Isolate* isolate, Node* n ode, const v8::Persistent<v8::Object>& wrapper) 61 static void addReferencesForNodeWithEventListeners(v8::Isolate* isolate, Node* n ode, const v8::Persistent<v8::Object>& wrapper)
60 { 62 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // MinorGC does not collect objects because it may be expensive to 116 // MinorGC does not collect objects because it may be expensive to
115 // update references during minorGC 117 // update references during minorGC
116 if (classId == WrapperTypeInfo::ObjectClassId) { 118 if (classId == WrapperTypeInfo::ObjectClassId) {
117 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); 119 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
118 return; 120 return;
119 } 121 }
120 122
121 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); 123 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value));
122 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); 124 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper));
123 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); 125 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
124 ActiveDOMObject* activeDOMObject = type->toActiveDOMObject(wrapper); 126 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity())
125 if (activeDOMObject && activeDOMObject->hasPendingActivity()) {
126 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
127 return; 127 return;
128 }
129 128
130 if (classId == WrapperTypeInfo::NodeClassId) { 129 if (classId == WrapperTypeInfo::NodeClassId) {
131 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); 130 ASSERT(V8Node::hasInstance(wrapper, m_isolate));
132 Node* node = V8Node::toImpl(wrapper); 131 Node* node = V8Node::toImpl(wrapper);
133 if (node->hasEventListeners()) { 132 if (node->hasEventListeners()) {
134 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); 133 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
135 return; 134 return;
136 } 135 }
137 // FIXME: Remove the special handling for image elements. 136 // FIXME: Remove the special handling for image elements.
138 // The same special handling is in V8GCController::opaqueRootForGC() . 137 // The same special handling is in V8GCController::opaqueRootForGC() .
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return; 171 return;
173 172
174 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); 173 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value));
175 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); 174 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper));
176 175
177 if (value->IsIndependent()) 176 if (value->IsIndependent())
178 return; 177 return;
179 178
180 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); 179 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
181 180
182 ActiveDOMObject* activeDOMObject = type->toActiveDOMObject(wrapper); 181 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity()) {
183 if (activeDOMObject && activeDOMObject->hasPendingActivity()) {
184 m_isolate->SetObjectGroupId(*value, liveRootId()); 182 m_isolate->SetObjectGroupId(*value, liveRootId());
185 ++m_domObjectsWithPendingActivity; 183 ++m_domObjectsWithPendingActivity;
186 } 184 }
187 185
188 if (classId == WrapperTypeInfo::NodeClassId) { 186 if (classId == WrapperTypeInfo::NodeClassId) {
189 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); 187 ASSERT(V8Node::hasInstance(wrapper, m_isolate));
190 Node* node = V8Node::toImpl(wrapper); 188 Node* node = V8Node::toImpl(wrapper);
191 if (node->hasEventListeners()) 189 if (node->hasEventListeners())
192 addReferencesForNodeWithEventListeners(m_isolate, node, v8::Pers istent<v8::Object>::Cast(*value)); 190 addReferencesForNodeWithEventListeners(m_isolate, node, v8::Pers istent<v8::Object>::Cast(*value));
193 Node* root = V8GCController::opaqueRootForGC(m_isolate, node); 191 Node* root = V8GCController::opaqueRootForGC(m_isolate, node);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 private: 453 private:
456 Visitor* m_visitor; 454 Visitor* m_visitor;
457 }; 455 };
458 456
459 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) 457 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor)
460 { 458 {
461 DOMWrapperTracer tracer(visitor); 459 DOMWrapperTracer tracer(visitor);
462 isolate->VisitHandlesWithClassIds(&tracer); 460 isolate->VisitHandlesWithClassIds(&tracer);
463 } 461 }
464 462
463 class PendingActivityVisitor : public v8::PersistentHandleVisitor {
464 public:
465 explicit PendingActivityVisitor(ExecutionContext* executionContext)
466 : m_executionContext(executionContext)
467 , m_pendingActivityFound(false)
468 {
469 }
470
471 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override
472 {
473 // If we have already found any wrapper that has a pending activity,
474 // we don't need to check other wrappers.
475 if (m_pendingActivityFound)
476 return;
477
478 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId)
479 return;
480
481 const v8::Persistent<v8::Object>& wrapper = v8::Persistent<v8::Object>:: Cast(*value);
482 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
483 // The ExecutionContext check is heavy, so it should be done at the last .
484 if (type != npObjectTypeInfo()
485 && toScriptWrappable(wrapper)->hasPendingActivity()
486 // TODO(haraken): Currently we don't have a way to get a creation
487 // context from a wrapper. We should implement the way and enable
488 // the following condition.
489 //
490 // This condition affects only compositor workers, where one isolate
491 // is shared by multiple workers. If we don't have the condition,
492 // a worker object for a compositor worker doesn't get collected
493 // until all compositor workers in the same isolate lose pending
494 // activities. In other words, not having the condition delays
495 // destruction of a worker object of a compositor worker.
496 //
497 /* && toExecutionContext(wrapper->creationContext()) == m_executionC ontext */
haraken 2016/02/08 05:42:45 This needs a new V8 API (v8::Object::CreationConte
498 )
499 m_pendingActivityFound = true;
500 }
501
502 bool pendingActivityFound() const { return m_pendingActivityFound; }
503
504 private:
505 RawPtrWillBePersistent<ExecutionContext> m_executionContext;
506 bool m_pendingActivityFound;
507 };
508
509 bool V8GCController::hasPendingActivity(ExecutionContext* executionContext)
510 {
511 // V8GCController::hasPendingActivity is used only when a worker checks if
512 // the worker contains any wrapper that has pending activities.
513 ASSERT(!isMainThread());
514
515 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityHistogram", 1, 1000, 50));
516 double startTime = WTF::currentTimeMS();
517 PendingActivityVisitor visitor(executionContext);
518 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor);
519 scanPendingActivityHistogram.count(WTF::currentTimeMS() - startTime);
Ilya Sherman 2016/02/09 22:07:00 Hrm, you seem to be passing a double into a functi
520 return visitor.pendingActivityFound();
521 }
522
465 } // namespace blink 523 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698