From ab2cd5732d9afc13ce64304b162306923c290e8f Mon Sep 17 00:00:00 2001 From: Csoregi Natalia Date: Tue, 9 Jun 2020 20:39:47 +0300 Subject: [PATCH] Backed out 5 changesets (bug 1641231) for assertion failures on FlippedOnce.h. CLOSED TREE Backed out changeset f91248e16c71 (bug 1641231) Backed out changeset 3c4db99ba498 (bug 1641231) Backed out changeset 125533344189 (bug 1641231) Backed out changeset 203e3ec45022 (bug 1641231) Backed out changeset 84668b82ebee (bug 1641231) --- dom/quota/ActorsParent.cpp | 167 ++++++++++++++++++------------------- dom/quota/QuotaManager.h | 11 ++- 2 files changed, 88 insertions(+), 90 deletions(-) diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index d73b9fe9ec06..c7b969e7f358 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -660,18 +660,16 @@ nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection, } // namespace class DirectoryLockImpl final : public DirectoryLock { - const NotNull> mQuotaManager; + RefPtr mQuotaManager; const Nullable mPersistenceType; const nsCString mGroup; const OriginScope mOriginScope; const Nullable mClientType; - LazyInitializedOnceEarlyDestructible< - const NotNull>> - mOpenListener; + RefPtr mOpenListener; - nsTArray> mBlocking; - nsTArray> mBlockedOn; + nsTArray mBlocking; + nsTArray mBlockedOn; const int64_t mId; @@ -682,16 +680,14 @@ class DirectoryLockImpl final : public DirectoryLock { const bool mInternal; bool mRegistered; - FlippedOnce mInvalidated; + bool mInvalidated; public: - DirectoryLockImpl(MovingNotNull> aQuotaManager, - const int64_t aId, + DirectoryLockImpl(QuotaManager* aQuotaManager, const int64_t aId, const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, bool aExclusive, - bool aInternal, - RefPtr aOpenListener); + bool aInternal, OpenDirectoryListener* aOpenListener); void AssertIsOnOwningThread() const #ifdef DEBUG @@ -738,26 +734,24 @@ class DirectoryLockImpl final : public DirectoryLock { // Test whether this DirectoryLock needs to wait for the given lock. bool MustWaitFor(const DirectoryLockImpl& aLock) const; - void AddBlockingLock(DirectoryLockImpl& aLock) { + void AddBlockingLock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); - mBlocking.AppendElement(WrapNotNull(&aLock)); + mBlocking.AppendElement(aLock); } - const nsTArray>& GetBlockedOnLocks() { - return mBlockedOn; - } + const nsTArray& GetBlockedOnLocks() { return mBlockedOn; } - void AddBlockedOnLock(DirectoryLockImpl& aLock) { + void AddBlockedOnLock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); - mBlockedOn.AppendElement(WrapNotNull(&aLock)); + mBlockedOn.AppendElement(aLock); } - void MaybeUnblock(DirectoryLockImpl& aLock) { + void MaybeUnblock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); - mBlockedOn.RemoveElement(&aLock); + mBlockedOn.RemoveElement(aLock); if (mBlockedOn.IsEmpty()) { NotifyOpenListener(); } @@ -768,7 +762,7 @@ class DirectoryLockImpl final : public DirectoryLock { void Invalidate() { AssertIsOnOwningThread(); - mInvalidated.Flip(); + mInvalidated = true; } NS_INLINE_DECL_REFCOUNTING(DirectoryLockImpl, override) @@ -2859,21 +2853,23 @@ already_AddRefed DirectoryLock::Specialize( void DirectoryLock::Log() const { GetDirectoryLockImpl(this)->Log(); } DirectoryLockImpl::DirectoryLockImpl( - MovingNotNull> aQuotaManager, const int64_t aId, + QuotaManager* aQuotaManager, const int64_t aId, const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, - bool aExclusive, bool aInternal, - RefPtr aOpenListener) - : mQuotaManager(std::move(aQuotaManager)), + bool aExclusive, bool aInternal, OpenDirectoryListener* aOpenListener) + : mQuotaManager(aQuotaManager), mPersistenceType(aPersistenceType), mGroup(aGroup), mOriginScope(aOriginScope), mClientType(aClientType), + mOpenListener(aOpenListener), mId(aId), mExclusive(aExclusive), mInternal(aInternal), - mRegistered(false) { + mRegistered(false), + mInvalidated(false) { AssertIsOnOwningThread(); + MOZ_ASSERT(aQuotaManager); MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty()); MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull()); MOZ_ASSERT_IF(!aInternal, @@ -2883,23 +2879,20 @@ DirectoryLockImpl::DirectoryLockImpl( MOZ_ASSERT_IF(!aInternal, !aClientType.IsNull()); MOZ_ASSERT_IF(!aInternal, aClientType.Value() < Client::TypeMax()); MOZ_ASSERT_IF(!aInternal, aOpenListener); - - if (aOpenListener) { - mOpenListener.init(WrapNotNullUnchecked(std::move(aOpenListener))); - } } DirectoryLockImpl::~DirectoryLockImpl() { AssertIsOnOwningThread(); + MOZ_ASSERT(mQuotaManager); for (DirectoryLockImpl* blockingLock : mBlocking) { - blockingLock->MaybeUnblock(*this); + blockingLock->MaybeUnblock(this); } mBlocking.Clear(); if (mRegistered) { - mQuotaManager->UnregisterDirectoryLock(*this); + mQuotaManager->UnregisterDirectoryLock(this); } MOZ_ASSERT(!mRegistered); @@ -2908,6 +2901,7 @@ DirectoryLockImpl::~DirectoryLockImpl() { #ifdef DEBUG void DirectoryLockImpl::AssertIsOnOwningThread() const { + MOZ_ASSERT(mQuotaManager); mQuotaManager->AssertIsOnOwningThread(); } @@ -2953,16 +2947,18 @@ bool DirectoryLockImpl::MustWaitFor(const DirectoryLockImpl& aLock) const { void DirectoryLockImpl::NotifyOpenListener() { AssertIsOnOwningThread(); + MOZ_ASSERT(mQuotaManager); + MOZ_ASSERT(mOpenListener); if (mInvalidated) { - (*mOpenListener)->DirectoryLockFailed(); + mOpenListener->DirectoryLockFailed(); } else { - (*mOpenListener)->DirectoryLockAcquired(this); + mOpenListener->DirectoryLockAcquired(this); } - mOpenListener.destroy(); + mOpenListener = nullptr; - mQuotaManager->RemovePendingDirectoryLock(*this); + mQuotaManager->RemovePendingDirectoryLock(this); } already_AddRefed DirectoryLockImpl::Specialize( @@ -2973,6 +2969,7 @@ already_AddRefed DirectoryLockImpl::Specialize( MOZ_ASSERT(!aGroup.IsEmpty()); MOZ_ASSERT(!aOrigin.IsEmpty()); MOZ_ASSERT(aClientType < Client::TypeMax()); + MOZ_ASSERT(mQuotaManager); MOZ_ASSERT(!mOpenListener); MOZ_ASSERT(mBlockedOn.IsEmpty()); @@ -3001,13 +2998,15 @@ already_AddRefed DirectoryLockImpl::Specialize( #endif for (const auto& blockedLock : mBlocking) { + MOZ_ASSERT(blockedLock); + if (blockedLock->MustWaitFor(*lock)) { - lock->AddBlockingLock(*blockedLock); - blockedLock->AddBlockedOnLock(*lock); + lock->AddBlockingLock(blockedLock); + blockedLock->AddBlockedOnLock(lock); } } - mQuotaManager->RegisterDirectoryLock(*lock); + mQuotaManager->RegisterDirectoryLock(lock); if (mInvalidated) { lock->Invalidate(); @@ -3061,8 +3060,7 @@ void DirectoryLockImpl::Log() const { nsCString blockedOnString; for (auto blockedOn : mBlockedOn) { - blockedOnString.Append( - nsPrintfCString(" [%p]", static_cast(blockedOn))); + blockedOnString.Append(nsPrintfCString(" [%p]", blockedOn)); } QM_LOG((" mBlockedOn:%s", blockedOnString.get())); @@ -3070,7 +3068,7 @@ void DirectoryLockImpl::Log() const { QM_LOG((" mInternal: %d", mInternal)); - QM_LOG((" mInvalidated: %d", static_cast(mInvalidated))); + QM_LOG((" mInvalidated: %d", mInvalidated)); for (auto blockedOn : mBlockedOn) { blockedOn->Log(); @@ -3686,9 +3684,8 @@ bool QuotaManager::IsDotFile(const nsAString& aFileName) { auto QuotaManager::CreateDirectoryLock( const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, - bool aExclusive, bool aInternal, - RefPtr aOpenListener, bool& aBlockedOut) - -> already_AddRefed { + bool aExclusive, bool aInternal, OpenDirectoryListener* aOpenListener, + bool& aBlockedOut) -> already_AddRefed { AssertIsOnOwningThread(); MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty()); MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull()); @@ -3701,9 +3698,8 @@ auto QuotaManager::CreateDirectoryLock( MOZ_ASSERT_IF(!aInternal, aOpenListener); RefPtr lock = new DirectoryLockImpl( - WrapNotNullUnchecked(this), GenerateDirectoryLockId(), aPersistenceType, - aGroup, aOriginScope, aClientType, aExclusive, aInternal, - std::move(aOpenListener)); + this, GenerateDirectoryLockId(), aPersistenceType, aGroup, aOriginScope, + aClientType, aExclusive, aInternal, aOpenListener); mPendingDirectoryLocks.AppendElement(lock); @@ -3712,13 +3708,13 @@ auto QuotaManager::CreateDirectoryLock( for (uint32_t index = mDirectoryLocks.Length(); index > 0; index--) { DirectoryLockImpl* existingLock = mDirectoryLocks[index - 1]; if (lock->MustWaitFor(*existingLock)) { - existingLock->AddBlockingLock(*lock); - lock->AddBlockedOnLock(*existingLock); + existingLock->AddBlockingLock(lock); + lock->AddBlockedOnLock(existingLock); blocked = true; } } - RegisterDirectoryLock(*lock); + RegisterDirectoryLock(lock); // Otherwise, notify the open listener immediately. if (!blocked) { @@ -3737,8 +3733,7 @@ auto QuotaManager::CreateDirectoryLockForEviction( MOZ_ASSERT(!aOrigin.IsEmpty()); RefPtr lock = new DirectoryLockImpl( - WrapNotNullUnchecked(this), - /* aDirectoryLockId */ kBypassDirectoryLockIdTableId, + this, /* aDirectoryLockId */ kBypassDirectoryLockIdTableId, Nullable(aPersistenceType), aGroup, OriginScope::FromOrigin(aOrigin), Nullable(), /* aExclusive */ true, /* aInternal */ true, nullptr); @@ -3750,80 +3745,83 @@ auto QuotaManager::CreateDirectoryLockForEviction( } #endif - RegisterDirectoryLock(*lock); + RegisterDirectoryLock(lock); return lock.forget(); } -void QuotaManager::RegisterDirectoryLock(DirectoryLockImpl& aLock) { +void QuotaManager::RegisterDirectoryLock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); + MOZ_ASSERT(aLock); - mDirectoryLocks.AppendElement(&aLock); + mDirectoryLocks.AppendElement(aLock); - if (aLock.ShouldUpdateLockIdTable()) { + if (aLock->ShouldUpdateLockIdTable()) { MutexAutoLock lock(mQuotaMutex); - MOZ_DIAGNOSTIC_ASSERT(!mDirectoryLockIdTable.Get(aLock.Id())); - mDirectoryLockIdTable.Put(aLock.Id(), &aLock); + MOZ_DIAGNOSTIC_ASSERT(!mDirectoryLockIdTable.Get(aLock->Id())); + mDirectoryLockIdTable.Put(aLock->Id(), aLock); } - if (aLock.ShouldUpdateLockTable()) { + if (aLock->ShouldUpdateLockTable()) { DirectoryLockTable& directoryLockTable = - GetDirectoryLockTable(aLock.GetPersistenceType()); + GetDirectoryLockTable(aLock->GetPersistenceType()); nsTArray* array; - if (!directoryLockTable.Get(aLock.Origin(), &array)) { + if (!directoryLockTable.Get(aLock->Origin(), &array)) { array = new nsTArray(); - directoryLockTable.Put(aLock.Origin(), array); + directoryLockTable.Put(aLock->Origin(), array); if (!IsShuttingDown()) { - UpdateOriginAccessTime(aLock.GetPersistenceType(), aLock.Group(), - aLock.Origin()); + UpdateOriginAccessTime(aLock->GetPersistenceType(), aLock->Group(), + aLock->Origin()); } } - array->AppendElement(&aLock); + array->AppendElement(aLock); } - aLock.SetRegistered(true); + aLock->SetRegistered(true); } -void QuotaManager::UnregisterDirectoryLock(DirectoryLockImpl& aLock) { +void QuotaManager::UnregisterDirectoryLock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); + MOZ_ASSERT(aLock); - MOZ_ALWAYS_TRUE(mDirectoryLocks.RemoveElement(&aLock)); + MOZ_ALWAYS_TRUE(mDirectoryLocks.RemoveElement(aLock)); - if (aLock.ShouldUpdateLockIdTable()) { + if (aLock->ShouldUpdateLockIdTable()) { MutexAutoLock lock(mQuotaMutex); - MOZ_DIAGNOSTIC_ASSERT(mDirectoryLockIdTable.Get(aLock.Id())); - mDirectoryLockIdTable.Remove(aLock.Id()); + MOZ_DIAGNOSTIC_ASSERT(mDirectoryLockIdTable.Get(aLock->Id())); + mDirectoryLockIdTable.Remove(aLock->Id()); } - if (aLock.ShouldUpdateLockTable()) { + if (aLock->ShouldUpdateLockTable()) { DirectoryLockTable& directoryLockTable = - GetDirectoryLockTable(aLock.GetPersistenceType()); + GetDirectoryLockTable(aLock->GetPersistenceType()); nsTArray* array; - MOZ_ALWAYS_TRUE(directoryLockTable.Get(aLock.Origin(), &array)); + MOZ_ALWAYS_TRUE(directoryLockTable.Get(aLock->Origin(), &array)); - MOZ_ALWAYS_TRUE(array->RemoveElement(&aLock)); + MOZ_ALWAYS_TRUE(array->RemoveElement(aLock)); if (array->IsEmpty()) { - directoryLockTable.Remove(aLock.Origin()); + directoryLockTable.Remove(aLock->Origin()); if (!IsShuttingDown()) { - UpdateOriginAccessTime(aLock.GetPersistenceType(), aLock.Group(), - aLock.Origin()); + UpdateOriginAccessTime(aLock->GetPersistenceType(), aLock->Group(), + aLock->Origin()); } } } - aLock.SetRegistered(false); + aLock->SetRegistered(false); } -void QuotaManager::RemovePendingDirectoryLock(DirectoryLockImpl& aLock) { +void QuotaManager::RemovePendingDirectoryLock(DirectoryLockImpl* aLock) { AssertIsOnOwningThread(); + MOZ_ASSERT(aLock); - MOZ_ALWAYS_TRUE(mPendingDirectoryLocks.RemoveElement(&aLock)); + MOZ_ALWAYS_TRUE(mPendingDirectoryLocks.RemoveElement(aLock)); } uint64_t QuotaManager::CollectOriginsForEviction( @@ -6768,7 +6766,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() { already_AddRefed QuotaManager::OpenDirectory( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin, Client::Type aClientType, bool aExclusive, - RefPtr aOpenListener) { + OpenDirectoryListener* aOpenListener) { AssertIsOnOwningThread(); bool blocked; @@ -6804,7 +6802,8 @@ already_AddRefed QuotaManager::OpenDirectoryInternal( origins; origins.SetLength(Client::TypeMax()); - const auto& blockedOnLocks = lock->GetBlockedOnLocks(); + const nsTArray& blockedOnLocks = + lock->GetBlockedOnLocks(); for (DirectoryLockImpl* blockedOnLock : blockedOnLocks) { if (!blockedOnLock->IsInternal()) { diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h index c9ebdae27d1a..d0c4c2416e62 100644 --- a/dom/quota/QuotaManager.h +++ b/dom/quota/QuotaManager.h @@ -297,7 +297,7 @@ class QuotaManager final : public BackgroundThreadObject { already_AddRefed OpenDirectory( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin, Client::Type aClientType, bool aExclusive, - RefPtr aOpenListener); + OpenDirectoryListener* aOpenListener); // XXX RemoveMe once bug 1170279 gets fixed. already_AddRefed OpenDirectoryInternal( @@ -481,18 +481,17 @@ class QuotaManager final : public BackgroundThreadObject { const Nullable& aPersistenceType, const nsACString& aGroup, const OriginScope& aOriginScope, const Nullable& aClientType, bool aExclusive, - bool aInternal, RefPtr aOpenListener, - bool& aBlockedOut); + bool aInternal, OpenDirectoryListener* aOpenListener, bool& aBlockedOut); already_AddRefed CreateDirectoryLockForEviction( PersistenceType aPersistenceType, const nsACString& aGroup, const nsACString& aOrigin); - void RegisterDirectoryLock(DirectoryLockImpl& aLock); + void RegisterDirectoryLock(DirectoryLockImpl* aLock); - void UnregisterDirectoryLock(DirectoryLockImpl& aLock); + void UnregisterDirectoryLock(DirectoryLockImpl* aLock); - void RemovePendingDirectoryLock(DirectoryLockImpl& aLock); + void RemovePendingDirectoryLock(DirectoryLockImpl* aLock); uint64_t LockedCollectOriginsForEviction( uint64_t aMinSizeToBeFreed, nsTArray>& aLocks);