Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 702a8c0f58a9cc1a99bab360867740121892661c
      
https://github.com/WebKit/WebKit/commit/702a8c0f58a9cc1a99bab360867740121892661c
  Author: Keith Miller <keith_mil...@apple.com>
  Date:   2024-11-12 (Tue, 12 Nov 2024)

  Changed paths:
    M Source/JavaScriptCore/runtime/NativeCalleeRegistry.h
    M Source/JavaScriptCore/wasm/WasmCallee.cpp
    M Source/JavaScriptCore/wasm/WasmCallee.h
    M Source/WTF/wtf/Atomics.h
    M Source/WTF/wtf/ThreadSafeWeakPtr.h
    M Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp

  Log Message:
  -----------
  ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr should be optimized for the 
case where most references are strong
https://bugs.webkit.org/show_bug.cgi?id=282623
rdar://139297882

Reviewed by Justin Michaud.

This patch optimizes ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr for the 
case that the object is
only referenced strongly. This comes up a lot for Wasm::Callees as they're only 
weakly referenced only
while they are awaiting destruction. To make this work, the pointer to the 
ControlBlock is now logically
a `union { ControlBlock*; Atomic<uintptr_t> strongOnlyRefCountAndFlag }`.

In this new world it also no longer makes sense to take a WeakPtr to an object 
during its destructor,
which IMO didn't really make sense before. The WeakPtr must report the object 
as dead since the WeakPtr
doesn't realistically have a way to know if the new strong ref is coming from 
the thread destroying the
object or not. This patch removes a test case ASSERTing this was possible.

Lastly, this patch moves m_index in Wasm::Callee above m_indexOrName since that 
reduces padding, thus
Wasm::Callee is no bigger than it was before.

* Source/JavaScriptCore/runtime/NativeCalleeRegistry.h:
(JSC::NativeCalleeRegistry::registerCallee):
* Source/JavaScriptCore/wasm/WasmCallee.cpp:
(JSC::Wasm::Callee::Callee):
* Source/JavaScriptCore/wasm/WasmCallee.h:
* Source/WTF/wtf/Atomics.h:
(WTF::Atomic::transaction):
* Source/WTF/wtf/ThreadSafeWeakPtr.h:
(WTF::ThreadSafeWeakPtrControlBlock::ThreadSafeWeakPtrControlBlock):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::ref const):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::deref const):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::refCount const):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::hasOneRef const):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::controlBlock const):
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::isStrongOnly):
* Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp:

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to