OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 private: | 421 private: |
424 Visitor* m_visitor; | 422 Visitor* m_visitor; |
425 }; | 423 }; |
426 | 424 |
427 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) | 425 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) |
428 { | 426 { |
429 DOMWrapperTracer tracer(visitor); | 427 DOMWrapperTracer tracer(visitor); |
430 isolate->VisitHandlesWithClassIds(&tracer); | 428 isolate->VisitHandlesWithClassIds(&tracer); |
431 } | 429 } |
432 | 430 |
| 431 class PendingActivityVisitor : public v8::PersistentHandleVisitor { |
| 432 public: |
| 433 explicit PendingActivityVisitor(ExecutionContext* executionContext) |
| 434 : m_executionContext(executionContext) |
| 435 , m_pendingActivityFound(false) |
| 436 { |
| 437 } |
| 438 |
| 439 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI
d) override |
| 440 { |
| 441 // If we have already found any wrapper that has a pending activity, |
| 442 // we don't need to check other wrappers. |
| 443 if (m_pendingActivityFound) |
| 444 return; |
| 445 |
| 446 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf
o::ObjectClassId) |
| 447 return; |
| 448 |
| 449 const v8::Persistent<v8::Object>& wrapper = v8::Persistent<v8::Object>::
Cast(*value); |
| 450 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); |
| 451 // The ExecutionContext check is heavy, so it should be done at the last
. |
| 452 if (type != npObjectTypeInfo() |
| 453 && toScriptWrappable(wrapper)->hasPendingActivity() |
| 454 // TODO(haraken): Currently we don't have a way to get a creation |
| 455 // context from a wrapper. We should implement the way and enable |
| 456 // the following condition. |
| 457 // |
| 458 // This condition affects only compositor workers, where one isolate |
| 459 // is shared by multiple workers. If we don't have the condition, |
| 460 // a worker object for a compositor worker doesn't get collected |
| 461 // until all compositor workers in the same isolate lose pending |
| 462 // activities. In other words, not having the condition delays |
| 463 // destruction of a worker object of a compositor worker. |
| 464 // |
| 465 /* && toExecutionContext(wrapper->creationContext()) == m_executionC
ontext */ |
| 466 ) |
| 467 m_pendingActivityFound = true; |
| 468 } |
| 469 |
| 470 bool pendingActivityFound() const { return m_pendingActivityFound; } |
| 471 |
| 472 private: |
| 473 RawPtrWillBePersistent<ExecutionContext> m_executionContext; |
| 474 bool m_pendingActivityFound; |
| 475 }; |
| 476 |
| 477 bool V8GCController::hasPendingActivity(ExecutionContext* executionContext) |
| 478 { |
| 479 // V8GCController::hasPendingActivity is used only when a worker checks if |
| 480 // the worker contains any wrapper that has pending activities. |
| 481 ASSERT(!isMainThread()); |
| 482 |
| 483 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis
togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5
0)); |
| 484 double startTime = WTF::currentTimeMS(); |
| 485 PendingActivityVisitor visitor(executionContext); |
| 486 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); |
| 487 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s
tartTime)); |
| 488 return visitor.pendingActivityFound(); |
| 489 } |
| 490 |
433 } // namespace blink | 491 } // namespace blink |
OLD | NEW |