[webkit-changes] [WebKit/WebKit] 00f31c: Unable to fully adopt smart pointers because some ...

Chris Dumez noreply at github.com
Tue Jan 30 19:39:51 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 00f31cb9801c034c0dc99866eba889ea7acae394
      https://github.com/WebKit/WebKit/commit/00f31cb9801c034c0dc99866eba889ea7acae394
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2024-01-30 (Tue, 30 Jan 2024)

  Changed paths:
    M Source/WTF/wtf/Forward.h
    M Source/WTF/wtf/Ref.h
    M Source/WTF/wtf/RefCounted.h
    M Source/WTF/wtf/RefPtr.h
    M Source/WTF/wtf/SizeLimits.cpp
    M Source/WTF/wtf/ThreadSafeRefCounted.h
    M Source/WebCore/dom/ActiveDOMObject.cpp
    M Source/WebCore/dom/ContainerNodeAlgorithms.cpp
    M Source/WebCore/dom/CustomElementReactionQueue.cpp
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/EmptyScriptExecutionContext.h
    M Source/WebCore/dom/MessagePort.cpp
    M Source/WebCore/dom/Node.cpp
    M Source/WebCore/dom/Node.h
    M Source/WebCore/dom/ScriptExecutionContext.cpp
    M Source/WebCore/dom/ScriptExecutionContext.h
    M Source/WebCore/html/HTMLElement.cpp
    M Source/WebCore/loader/FrameLoader.cpp
    M Source/WebCore/page/EventHandler.cpp
    M Source/WebCore/page/LocalFrame.cpp
    M Source/WebCore/page/csp/ContentSecurityPolicy.cpp
    M Source/WebCore/svg/properties/SVGAttributeAnimator.cpp
    M Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp
    M Source/WebCore/workers/WorkerOrWorkletGlobalScope.h
    M Source/WebCore/workers/service/server/SWServerWorker.cpp
    M Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
    M Source/WebKit/Shared/API/APIObject.h
    M Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm
    M Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.cpp
    M Source/WebKit/UIProcess/WebProcessProxy.cpp
    M Tools/TestWebKitAPI/Tests/WTF/Ref.cpp
    M Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp

  Log Message:
  -----------
  Unable to fully adopt smart pointers because some objects may have started destruction
https://bugs.webkit.org/show_bug.cgi?id=268132

Reviewed by Ryosuke Niwa.

Unable to fully adopt smart pointers because some objects may have started
destruction at the time we call member functions on them or pass them to other
functions. We've found many such instances while adopting smart pointers and
we've had to revert back to raw pointers to address assertion hits on the debug
bots.

To address the issue, this patch introduces a new RefDerefTraitsAllowingPartiallyDestroyed
RefDerefTraits struct for Ref / RefPtr, which calls a variant of ref() / deref()
which bypasses the `!m_deletionHasBegun` check to avoid crashes in debug if the
object has started destruction at the time it gets ref'd. The patch also
introduces new RefAllowingPartiallyDestroyed / RefPtrAllowingPartiallyDestroyed
aliases for using Ref / RefPtr with RefDerefTraitsAllowingPartiallyDestroyed.

For safety, RefDerefTraitsAllowingPartiallyDestroyed will still check in debug builds
if the object has not *finished* destruction.

Finally, this patch adopts the new smart pointers in many of the places where
we could not previously adopt Ref / RefPtr. There are more places we can adopt
the new smart pointers but those will require performance A/B testing so I plan
to do that separately.

* Source/WTF/wtf/Forward.h:
* Source/WTF/wtf/Ref.h:
(WTF::DefaultRefDerefTraits::refIfNotNull):
(WTF::DefaultRefDerefTraits::ref):
(WTF::DefaultRefDerefTraits::derefIfNotNull):
(WTF::Ref::~Ref):
(WTF::Ref::Ref):
(WTF::=):
(WTF::operator==):
(WTF::RefDerefTraits>::swap):
(WTF::swap):
(WTF::RefDerefTraits>::replace):
(WTF::static_reference_cast):
(WTF::adoptRef):
(WTF::is):
(WTF::checkedDowncast):
(WTF::uncheckedDowncast):
(WTF::downcast):
(WTF::dynamicDowncast):
(WTF::RefDerefTraitsAllowingPartiallyDestroyed::refIfNotNull):
(WTF::RefDerefTraitsAllowingPartiallyDestroyed::ref):
(WTF::RefDerefTraitsAllowingPartiallyDestroyed::derefIfNotNull):
(WTF::U>::swap): Deleted.
(WTF::U>::replace): Deleted.
* Source/WTF/wtf/RefCounted.h:
(WTF::RefCountedBase::refAllowingPartiallyDestroyed const):
(WTF::RefCountedBase::ref const):
(WTF::RefCountedBase::RefCountedBase):
(WTF::RefCountedBase::applyRefDerefThreadingCheck const):
(WTF::RefCountedBase::~RefCountedBase):
(WTF::RefCountedBase::derefAllowingPartiallyDestroyedBase const):
(WTF::RefCountedBase::derefBase const):
(WTF::RefCountedBase::deletionHasEnded const):
(WTF::RefCounted::derefAllowingPartiallyDestroyed const):
* Source/WTF/wtf/RefPtr.h:
(WTF::DefaultRefDerefTraits::refIfNotNull): Deleted.
(WTF::DefaultRefDerefTraits::derefIfNotNull): Deleted.
* Source/WTF/wtf/SizeLimits.cpp:
* Source/WTF/wtf/ThreadSafeRefCounted.h:
(WTF::ThreadSafeRefCountedBase::~ThreadSafeRefCountedBase):
(WTF::ThreadSafeRefCountedBase::ref const):
(WTF::ThreadSafeRefCountedBase::refAllowingPartiallyDestroyed const):
(WTF::ThreadSafeRefCountedBase::derefBaseAllowingPartiallyDestroyed const):
(WTF::ThreadSafeRefCountedBase::derefBase const):
(WTF::ThreadSafeRefCountedBase::deletionHasEnded const):
(WTF::ThreadSafeRefCounted::derefAllowingPartiallyDestroyed const):
* Source/WebCore/dom/ActiveDOMObject.cpp:
(WebCore::ActiveDOMObject::~ActiveDOMObject):
(WebCore::ActiveDOMObject::suspendIfNeeded):
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::willBeRemovedFromFrame):
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/EmptyScriptExecutionContext.h:
* Source/WebCore/dom/MessagePort.cpp:
(WebCore::MessagePort::dispatchMessages):
* Source/WebCore/dom/Node.cpp:
(WebCore::Node::~Node):
* Source/WebCore/dom/Node.h:
(WebCore::Node::deletionHasEnded const):
(WebCore::Node::ref const):
(WebCore::Node::refAllowingPartiallyDestroyed const):
(WebCore::Node::deref const):
(WebCore::Node::derefAllowingPartiallyDestroyed const):
* Source/WebCore/dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::refAllowingPartiallyDestroyed):
(WebCore::ScriptExecutionContext::derefAllowingPartiallyDestroyed):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::hidePopoverInternal):
* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::stopLoading):
(WebCore::FrameLoader::setOpener):
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::clearLatchedState):
* Source/WebCore/page/LocalFrame.cpp:
(WebCore::LocalFrame::willDetachPage):
* Source/WebCore/page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportViolation const):
* Source/WebCore/workers/WorkerOrWorkletGlobalScope.h:
* Source/WebCore/workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::contextConnection):
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::~WebSWServerConnection):
* Source/WebKit/Shared/API/APIObject.h:
(API::Object::refAllowingPartiallyDestroyed const):
(API::Object::derefAllowingPartiallyDestroyed const):
* Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm:
(WebKit::AudioSessionRoutingArbitratorProxy::~AudioSessionRoutingArbitratorProxy):
* Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.cpp:
(WebKit::LegacyCustomProtocolManagerProxy::~LegacyCustomProtocolManagerProxy):
(WebKit::LegacyCustomProtocolManagerProxy::invalidate):
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::~WebProcessProxy):
(WebKit::WebProcessProxy::processWillShutDown):
(WebKit::WebProcessProxy::shutDown):

Canonical link: https://commits.webkit.org/273805@main




More information about the webkit-changes mailing list