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

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

Issue 1805843002: [v8 gc] Introduce a base class for all objects that can have pending activity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 4 years, 9 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/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
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() && type->hasPendingActivity(wrapper)) {
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
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() && type->hasPendingActivity(wrapper)) {
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
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 && type->hasPendingActivity(wrapper)
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)
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 v8::HandleScope scope(isolate);
496 PendingActivityVisitor visitor(isolate, executionContext);
492 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); 497 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor);
493 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); 498 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime));
494 return visitor.pendingActivityFound(); 499 return visitor.pendingActivityFound();
495 } 500 }
496 501
497 } // namespace blink 502 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698