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)
This commit is contained in:
Csoregi Natalia 2020-06-09 20:39:47 +03:00
Родитель 468d520bfa
Коммит ab2cd5732d
2 изменённых файлов: 88 добавлений и 90 удалений

Просмотреть файл

@ -660,18 +660,16 @@ nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
} // namespace
class DirectoryLockImpl final : public DirectoryLock {
const NotNull<RefPtr<QuotaManager>> mQuotaManager;
RefPtr<QuotaManager> mQuotaManager;
const Nullable<PersistenceType> mPersistenceType;
const nsCString mGroup;
const OriginScope mOriginScope;
const Nullable<Client::Type> mClientType;
LazyInitializedOnceEarlyDestructible<
const NotNull<RefPtr<OpenDirectoryListener>>>
mOpenListener;
RefPtr<OpenDirectoryListener> mOpenListener;
nsTArray<NotNull<DirectoryLockImpl*>> mBlocking;
nsTArray<NotNull<DirectoryLockImpl*>> mBlockedOn;
nsTArray<DirectoryLockImpl*> mBlocking;
nsTArray<DirectoryLockImpl*> mBlockedOn;
const int64_t mId;
@ -682,16 +680,14 @@ class DirectoryLockImpl final : public DirectoryLock {
const bool mInternal;
bool mRegistered;
FlippedOnce<false> mInvalidated;
bool mInvalidated;
public:
DirectoryLockImpl(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const int64_t aId,
DirectoryLockImpl(QuotaManager* aQuotaManager, const int64_t aId,
const Nullable<PersistenceType>& aPersistenceType,
const nsACString& aGroup, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
bool aInternal,
RefPtr<OpenDirectoryListener> 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<NotNull<DirectoryLockImpl*>>& GetBlockedOnLocks() {
return mBlockedOn;
}
const nsTArray<DirectoryLockImpl*>& 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> DirectoryLock::Specialize(
void DirectoryLock::Log() const { GetDirectoryLockImpl(this)->Log(); }
DirectoryLockImpl::DirectoryLockImpl(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager, const int64_t aId,
QuotaManager* aQuotaManager, const int64_t aId,
const Nullable<PersistenceType>& aPersistenceType, const nsACString& aGroup,
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
bool aExclusive, bool aInternal,
RefPtr<OpenDirectoryListener> 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<DirectoryLock> DirectoryLockImpl::Specialize(
@ -2973,6 +2969,7 @@ already_AddRefed<DirectoryLock> 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<DirectoryLock> 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<void*>(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<bool>(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<PersistenceType>& aPersistenceType, const nsACString& aGroup,
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
bool aExclusive, bool aInternal,
RefPtr<OpenDirectoryListener> aOpenListener, bool& aBlockedOut)
-> already_AddRefed<DirectoryLockImpl> {
bool aExclusive, bool aInternal, OpenDirectoryListener* aOpenListener,
bool& aBlockedOut) -> already_AddRefed<DirectoryLockImpl> {
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<DirectoryLockImpl> 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<DirectoryLockImpl> lock = new DirectoryLockImpl(
WrapNotNullUnchecked(this),
/* aDirectoryLockId */ kBypassDirectoryLockIdTableId,
this, /* aDirectoryLockId */ kBypassDirectoryLockIdTableId,
Nullable<PersistenceType>(aPersistenceType), aGroup,
OriginScope::FromOrigin(aOrigin), Nullable<Client::Type>(),
/* 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<DirectoryLockImpl*>* array;
if (!directoryLockTable.Get(aLock.Origin(), &array)) {
if (!directoryLockTable.Get(aLock->Origin(), &array)) {
array = new nsTArray<DirectoryLockImpl*>();
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<DirectoryLockImpl*>* 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<DirectoryLock> QuotaManager::OpenDirectory(
PersistenceType aPersistenceType, const nsACString& aGroup,
const nsACString& aOrigin, Client::Type aClientType, bool aExclusive,
RefPtr<OpenDirectoryListener> aOpenListener) {
OpenDirectoryListener* aOpenListener) {
AssertIsOnOwningThread();
bool blocked;
@ -6804,7 +6802,8 @@ already_AddRefed<DirectoryLock> QuotaManager::OpenDirectoryInternal(
origins;
origins.SetLength(Client::TypeMax());
const auto& blockedOnLocks = lock->GetBlockedOnLocks();
const nsTArray<DirectoryLockImpl*>& blockedOnLocks =
lock->GetBlockedOnLocks();
for (DirectoryLockImpl* blockedOnLock : blockedOnLocks) {
if (!blockedOnLock->IsInternal()) {

Просмотреть файл

@ -297,7 +297,7 @@ class QuotaManager final : public BackgroundThreadObject {
already_AddRefed<DirectoryLock> OpenDirectory(
PersistenceType aPersistenceType, const nsACString& aGroup,
const nsACString& aOrigin, Client::Type aClientType, bool aExclusive,
RefPtr<OpenDirectoryListener> aOpenListener);
OpenDirectoryListener* aOpenListener);
// XXX RemoveMe once bug 1170279 gets fixed.
already_AddRefed<DirectoryLock> OpenDirectoryInternal(
@ -481,18 +481,17 @@ class QuotaManager final : public BackgroundThreadObject {
const Nullable<PersistenceType>& aPersistenceType,
const nsACString& aGroup, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
bool aInternal, RefPtr<OpenDirectoryListener> aOpenListener,
bool& aBlockedOut);
bool aInternal, OpenDirectoryListener* aOpenListener, bool& aBlockedOut);
already_AddRefed<DirectoryLockImpl> 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<RefPtr<DirectoryLockImpl>>& aLocks);