-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick 339bfd3. rdar://122509050
[WTF] Add LazyRef & LazyUniqueRef https://bugs.webkit.org/show_bug.cgi?id=267830 rdar://121328458 Reviewed by Ryosuke Niwa. This patch adds LazyRef and LazyUniqueRef. This is similar to LazyProperty in JSC. We can set *stateless* lambda in the constructor side of the owner object so that it offers clean interface for lazy initialization, which does not mess up the owner object's interface. For example, LazyUniqueRef<VM, Property> m_property; Property& property() { return m_property.get(*this); } First parameter is owner, which needs to be passed to `get`. And then, this `get` will automatically initialize if it is not initialized. And the initialization code can be freely customized, but you do not need to define it as a VM's member! Instead, you can define it as a lambda inside VM.cpp. // This lambda needs to be stateless. So it must not capture anything (otherwise, it hits crash because of RELEASE_ASSERT anyway). m_property.initLater( [](VM& vm, auto& ref) { // You can do whatever. Even you can invoke the other property which can be further lazily initialized (so, it implicitly creates dependency graph of initialization). ref.set(Property::create()); // And further, you can do anything after setting it. So these operations can see Property& via `vm.property()`. }); Or you can set lambda in constructor, so like, VM's constructor list, : m_property( [](VM& vm, auto& ref) { // You can do whatever. Even you can invoke the other property which can be further lazily initialized (so, it implicitly creates dependency graph of initialization). ref.set(Property::create()); // And further, you can do anything after setting it. So these operations can see Property& via `vm.property()`. }) , m_other() , ... This patch applies this to some of JSC::VM's fields, making definitions much cleaner by moving all messy parts into VM.cpp side and clean up VM.h's interface. * Source/JavaScriptCore/runtime/HasOwnPropertyCache.h: (JSC::HasOwnPropertyCache::Entry::offsetOfStructureID): Deleted. (JSC::HasOwnPropertyCache::Entry::offsetOfImpl): Deleted. (JSC::HasOwnPropertyCache::Entry::offsetOfResult): Deleted. (JSC::HasOwnPropertyCache::operator delete): Deleted. (JSC::HasOwnPropertyCache::create): Deleted. (JSC::HasOwnPropertyCache::hash): Deleted. (JSC::HasOwnPropertyCache::get): Deleted. (JSC::HasOwnPropertyCache::tryAdd): Deleted. (JSC::HasOwnPropertyCache::clear): Deleted. (JSC::HasOwnPropertyCache::clearBuffer): Deleted. (JSC::VM::ensureHasOwnPropertyCache): Deleted. * Source/JavaScriptCore/runtime/LazyPropertyInlines.h: (JSC::ElementType>::initLater): * Source/JavaScriptCore/runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): (JSC::VM::invalidateStructureChainIntegrity): (JSC::VM::ensureWatchdog): Deleted. (JSC::VM::ensureHeapProfiler): Deleted. (JSC::VM::ensureShadowChicken): Deleted. (JSC::VM::ensureMegamorphicCacheSlow): Deleted. * Source/JavaScriptCore/runtime/VM.h: (JSC::VM::watchdog): (JSC::VM::ensureWatchdog): (JSC::VM::heapProfiler): (JSC::VM::ensureHeapProfiler): (JSC::VM::hasOwnPropertyCache): (JSC::VM::ensureHasOwnPropertyCache): (JSC::VM::megamorphicCache): (JSC::VM::ensureMegamorphicCache): (JSC::VM::shadowChicken): (JSC::VM::ensureShadowChicken): (JSC::VM::heapProfiler const): Deleted. * Source/WTF/WTF.xcodeproj/project.pbxproj: * Source/WTF/wtf/CMakeLists.txt: * Source/WTF/wtf/LazyRef.h: Added. (WTF::LazyRef::~LazyRef): (WTF::LazyRef::isInitialized const): (WTF::LazyRef::get const): (WTF::LazyRef::get): (WTF::LazyRef::getIfExists const): (WTF::LazyRef::getIfExists): (WTF::LazyRef::initLater): (WTF::LazyRef::set): (WTF::LazyRef::callFunc): * Source/WTF/wtf/LazyUniqueRef.h: Added. (WTF::LazyUniqueRef::~LazyUniqueRef): (WTF::LazyUniqueRef::isInitialized const): (WTF::LazyUniqueRef::get const): (WTF::LazyUniqueRef::get): (WTF::LazyUniqueRef::getIfExists const): (WTF::LazyUniqueRef::getIfExists): (WTF::LazyUniqueRef::initLater): (WTF::LazyUniqueRef::set): (WTF::LazyUniqueRef::callFunc): Canonical link: https://commits.webkit.org/273287@main Identifier: 272448.544@safari-7618-branch
- Loading branch information
1 parent
984ca90
commit 483d4b2
Showing
12 changed files
with
473 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.