Chromium Code Reviews| 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/ActiveScriptWrappable.h" | |
| 33 #include "bindings/core/v8/NPV8Object.h" | 34 #include "bindings/core/v8/NPV8Object.h" |
| 34 #include "bindings/core/v8/RetainedDOMInfo.h" | 35 #include "bindings/core/v8/RetainedDOMInfo.h" |
| 35 #include "bindings/core/v8/V8AbstractEventListener.h" | 36 #include "bindings/core/v8/V8AbstractEventListener.h" |
| 36 #include "bindings/core/v8/V8Binding.h" | 37 #include "bindings/core/v8/V8Binding.h" |
| 37 #include "bindings/core/v8/V8MutationObserver.h" | 38 #include "bindings/core/v8/V8MutationObserver.h" |
| 38 #include "bindings/core/v8/V8Node.h" | 39 #include "bindings/core/v8/V8Node.h" |
| 39 #include "bindings/core/v8/V8ScriptRunner.h" | 40 #include "bindings/core/v8/V8ScriptRunner.h" |
| 40 #include "bindings/core/v8/WrapperTypeInfo.h" | 41 #include "bindings/core/v8/WrapperTypeInfo.h" |
| 41 #include "core/dom/Attr.h" | 42 #include "core/dom/Attr.h" |
| 42 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 // MinorGC does not collect objects because it may be expensive to | 113 // MinorGC does not collect objects because it may be expensive to |
| 113 // update references during minorGC | 114 // update references during minorGC |
| 114 if (classId == WrapperTypeInfo::ObjectClassId) { | 115 if (classId == WrapperTypeInfo::ObjectClassId) { |
| 115 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); | 116 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); |
| 116 return; | 117 return; |
| 117 } | 118 } |
| 118 | 119 |
| 119 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); | 120 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); |
| 120 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); | 121 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); |
| 121 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); | 122 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); |
| 122 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity()) { | 123 if (type != npObjectTypeInfo() && toActiveScriptWrappable(wrapper) && to ActiveScriptWrappable(wrapper)->hasPendingActivity()) { |
|
Yuki
2016/03/18 06:59:40
I think you can do:
type != npObjectTypeInfo()
jochen (gone - plz use gerrit)
2016/03/18 13:18:01
added hasPendingActivity()
| |
| 123 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); | 124 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); |
| 124 return; | 125 return; |
| 125 } | 126 } |
| 126 | 127 |
| 127 if (classId == WrapperTypeInfo::NodeClassId) { | 128 if (classId == WrapperTypeInfo::NodeClassId) { |
| 128 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); | 129 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); |
| 129 Node* node = V8Node::toImpl(wrapper); | 130 Node* node = V8Node::toImpl(wrapper); |
| 130 if (node->hasEventListeners()) { | 131 if (node->hasEventListeners()) { |
| 131 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); | 132 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); |
| 132 return; | 133 return; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 157 | 158 |
| 158 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override | 159 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override |
| 159 { | 160 { |
| 160 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId) | 161 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId) |
| 161 return; | 162 return; |
| 162 | 163 |
| 163 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); | 164 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); |
| 164 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); | 165 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); |
| 165 | 166 |
| 166 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); | 167 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); |
| 167 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity()) { | 168 if (type != npObjectTypeInfo() && toActiveScriptWrappable(wrapper) && to ActiveScriptWrappable(wrapper)->hasPendingActivity()) { |
| 168 // If you hit this assert, you'll need to add a [DependentiLifetime] | 169 // If you hit this assert, you'll need to add a [DependentiLifetime] |
| 169 // extended attribute to the DOM interface. A DOM interface that | 170 // extended attribute to the DOM interface. A DOM interface that |
| 170 // overrides hasPendingActivity must be marked as [DependentiLifetim e]. | 171 // overrides hasPendingActivity must be marked as [DependentiLifetim e]. |
| 171 RELEASE_ASSERT(!value->IsIndependent()); | 172 RELEASE_ASSERT(!value->IsIndependent()); |
| 172 m_isolate->SetObjectGroupId(*value, liveRootId()); | 173 m_isolate->SetObjectGroupId(*value, liveRootId()); |
| 173 ++m_domObjectsWithPendingActivity; | 174 ++m_domObjectsWithPendingActivity; |
| 174 } | 175 } |
| 175 | 176 |
| 176 if (value->IsIndependent()) | 177 if (value->IsIndependent()) |
| 177 return; | 178 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 }; | 430 }; |
| 430 | 431 |
| 431 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) | 432 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) |
| 432 { | 433 { |
| 433 DOMWrapperTracer tracer(visitor); | 434 DOMWrapperTracer tracer(visitor); |
| 434 isolate->VisitHandlesWithClassIds(&tracer); | 435 isolate->VisitHandlesWithClassIds(&tracer); |
| 435 } | 436 } |
| 436 | 437 |
| 437 class PendingActivityVisitor : public v8::PersistentHandleVisitor { | 438 class PendingActivityVisitor : public v8::PersistentHandleVisitor { |
| 438 public: | 439 public: |
| 439 explicit PendingActivityVisitor(ExecutionContext* executionContext) | 440 PendingActivityVisitor(v8::Isolate* isolate, ExecutionContext* executionCont ext) |
| 440 : m_executionContext(executionContext) | 441 : m_isolate(isolate) |
| 442 , m_executionContext(executionContext) | |
| 441 , m_pendingActivityFound(false) | 443 , m_pendingActivityFound(false) |
| 442 { | 444 { |
| 443 } | 445 } |
| 444 | 446 |
| 445 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override | 447 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override |
| 446 { | 448 { |
| 447 // If we have already found any wrapper that has a pending activity, | 449 // If we have already found any wrapper that has a pending activity, |
| 448 // we don't need to check other wrappers. | 450 // we don't need to check other wrappers. |
| 449 if (m_pendingActivityFound) | 451 if (m_pendingActivityFound) |
| 450 return; | 452 return; |
| 451 | 453 |
| 452 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId) | 454 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId) |
| 453 return; | 455 return; |
| 454 | 456 |
| 455 const v8::Persistent<v8::Object>& wrapper = v8::Persistent<v8::Object>:: Cast(*value); | 457 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); |
| 458 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); | |
| 456 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); | 459 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); |
| 457 // The ExecutionContext check is heavy, so it should be done at the last . | 460 // The ExecutionContext check is heavy, so it should be done at the last . |
| 458 if (type != npObjectTypeInfo() | 461 if (type != npObjectTypeInfo() |
| 459 && toScriptWrappable(wrapper)->hasPendingActivity() | 462 && toActiveScriptWrappable(wrapper) && toActiveScriptWrappable(wrapp er)->hasPendingActivity() |
| 460 // TODO(haraken): Currently we don't have a way to get a creation | 463 // TODO(haraken): Currently we don't have a way to get a creation |
| 461 // context from a wrapper. We should implement the way and enable | 464 // context from a wrapper. We should implement the way and enable |
| 462 // the following condition. | 465 // the following condition. |
| 463 // | 466 // |
| 464 // This condition affects only compositor workers, where one isolate | 467 // This condition affects only compositor workers, where one isolate |
| 465 // is shared by multiple workers. If we don't have the condition, | 468 // is shared by multiple workers. If we don't have the condition, |
| 466 // a worker object for a compositor worker doesn't get collected | 469 // a worker object for a compositor worker doesn't get collected |
| 467 // until all compositor workers in the same isolate lose pending | 470 // until all compositor workers in the same isolate lose pending |
| 468 // activities. In other words, not having the condition delays | 471 // activities. In other words, not having the condition delays |
| 469 // destruction of a worker object of a compositor worker. | 472 // destruction of a worker object of a compositor worker. |
| 470 // | 473 // |
| 471 /* && toExecutionContext(wrapper->creationContext()) == m_executionC ontext */ | 474 /* && toExecutionContext(wrapper->creationContext()) == m_executionC ontext */ |
| 472 ) | 475 ) |
| 473 m_pendingActivityFound = true; | 476 m_pendingActivityFound = true; |
| 474 } | 477 } |
| 475 | 478 |
| 476 bool pendingActivityFound() const { return m_pendingActivityFound; } | 479 bool pendingActivityFound() const { return m_pendingActivityFound; } |
| 477 | 480 |
| 478 private: | 481 private: |
| 482 v8::Isolate* m_isolate; | |
| 479 RawPtrWillBePersistent<ExecutionContext> m_executionContext; | 483 RawPtrWillBePersistent<ExecutionContext> m_executionContext; |
| 480 bool m_pendingActivityFound; | 484 bool m_pendingActivityFound; |
| 481 }; | 485 }; |
| 482 | 486 |
| 483 bool V8GCController::hasPendingActivity(ExecutionContext* executionContext) | 487 bool V8GCController::hasPendingActivity(v8::Isolate* isolate, ExecutionContext* executionContext) |
|
Marcel Hlopko
2016/03/18 08:34:40
Pardon my lack of knowledge of the system, but I'm
jochen (gone - plz use gerrit)
2016/03/18 13:18:02
the embedder should always know which isolate it w
| |
| 484 { | 488 { |
| 485 // V8GCController::hasPendingActivity is used only when a worker checks if | 489 // V8GCController::hasPendingActivity is used only when a worker checks if |
| 486 // the worker contains any wrapper that has pending activities. | 490 // the worker contains any wrapper that has pending activities. |
| 487 ASSERT(!isMainThread()); | 491 ASSERT(!isMainThread()); |
| 488 | 492 |
| 489 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0)); | 493 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0)); |
| 490 double startTime = WTF::currentTimeMS(); | 494 double startTime = WTF::currentTimeMS(); |
| 491 PendingActivityVisitor visitor(executionContext); | 495 PendingActivityVisitor visitor(isolate, executionContext); |
| 492 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); | 496 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); |
| 493 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); | 497 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); |
| 494 return visitor.pendingActivityFound(); | 498 return visitor.pendingActivityFound(); |
| 495 } | 499 } |
| 496 | 500 |
| 497 } // namespace blink | 501 } // namespace blink |
| OLD | NEW |