Bug 1745613 - Change nsID::GenerateUUID() to not use NSS's RNG off the main thread. r=keeler

Calling NSS_IsInitialized() off the main thread caused intermittent tsan failures because NSS_IsInitialized() reads global variable nssIsInitted without acquiring the nssInitLock lock.

During Firefox startup, about 1000 nsIDs are generated, but only about 10 are generated off the main thread, so this change has very little impact on how often nsID::GenerateUUID() will use NSS's RNG. Of the nsIDs generated on the main thread during startup, about 600 are generated before NSS is initialized (so they use MFBT's RNG) and 400 are generated after NSS is initialized.

After Firefox reaches a steady state, loading a light web page like google.com generates about 300 nsIDs and a heavy web page like cnn.com generates about 2000 nsIDs. All these nsIDs are generated on the main thread using NSS's RNG.

Differential Revision: https://phabricator.services.mozilla.com/D134233
This commit is contained in:
Chris Peterson 2022-01-05 03:26:38 +00:00
Родитель de0df1009a
Коммит 963950be54
1 изменённых файлов: 3 добавлений и 1 удалений

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

@ -8,6 +8,7 @@
#include <limits.h>
#include "MainThreadUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/RandomNum.h"
#include "mozilla/Sprintf.h"
@ -25,7 +26,8 @@
}
int len = static_cast<int>(aLength);
if (!NSS_IsInitialized()) {
// Only try to use NSS on the main thread.
if (!NS_IsMainThread() || !NSS_IsInitialized()) {
return false;
}