Bug 1948068 - Make ChaosMode::isActive cheaper when disabled. r=glandium,nika
This changes a bit the semantics of .enterChaosMode(), but only when already combined with MOZ_CHAOSMODE, to respect the MOZ_CHAOSMODE feature set, which seems in general like a sensible and more flexible behavior? Differential Revision: https://phabricator.services.mozilla.com/D238078
This commit is contained in:
@@ -1063,14 +1063,16 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
|
|||||||
PR_SetEnv("MOZ_DISABLE_ASAN_REPORTER=1");
|
PR_SetEnv("MOZ_DISABLE_ASAN_REPORTER=1");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (PR_GetEnv("MOZ_CHAOSMODE")) {
|
if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||||
ChaosFeature feature = ChaosFeature::Any;
|
ChaosFeature feature = ChaosFeature::Any;
|
||||||
long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16);
|
long featureInt = strtol(featureStr, nullptr, 16);
|
||||||
if (featureInt) {
|
if (featureInt) {
|
||||||
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
||||||
feature = static_cast<ChaosFeature>(featureInt);
|
feature = static_cast<ChaosFeature>(featureInt);
|
||||||
}
|
}
|
||||||
ChaosMode::SetChaosFeature(feature);
|
ChaosMode::SetChaosFeature(feature);
|
||||||
|
ChaosMode::enterChaosMode();
|
||||||
|
MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChaosMode::isActive(ChaosFeature::Any)) {
|
if (ChaosMode::isActive(ChaosFeature::Any)) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace mozilla {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
Atomic<uint32_t, SequentiallyConsistent> gChaosModeCounter(0);
|
Atomic<uint32_t, Relaxed> gChaosModeCounter(0);
|
||||||
ChaosFeature gChaosFeatures = None;
|
ChaosFeature gChaosFeatures = ChaosFeature::Any;
|
||||||
|
|
||||||
} /* namespace detail */
|
} /* namespace detail */
|
||||||
} /* namespace mozilla */
|
} /* namespace mozilla */
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ enum ChaosFeature {
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
extern MFBT_DATA Atomic<uint32_t, SequentiallyConsistent> gChaosModeCounter;
|
extern MFBT_DATA Atomic<uint32_t, Relaxed> gChaosModeCounter;
|
||||||
extern MFBT_DATA ChaosFeature gChaosFeatures;
|
extern MFBT_DATA ChaosFeature gChaosFeatures;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
@@ -53,17 +53,13 @@ class ChaosMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool isActive(ChaosFeature aFeature) {
|
static bool isActive(ChaosFeature aFeature) {
|
||||||
if (detail::gChaosModeCounter > 0) {
|
return detail::gChaosModeCounter > 0 && (detail::gChaosFeatures & aFeature);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return detail::gChaosFeatures & aFeature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increase the chaos mode activation level. An equivalent number of
|
* Increase the chaos mode activation level. An equivalent number of
|
||||||
* calls to leaveChaosMode must be made in order to restore the original
|
* calls to leaveChaosMode must be made in order to restore the original
|
||||||
* chaos mode state. If the activation level is nonzero all chaos mode
|
* chaos mode state.
|
||||||
* features are activated.
|
|
||||||
*/
|
*/
|
||||||
static void enterChaosMode() { detail::gChaosModeCounter++; }
|
static void enterChaosMode() { detail::gChaosModeCounter++; }
|
||||||
|
|
||||||
|
|||||||
@@ -3999,14 +3999,16 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
|
|||||||
}
|
}
|
||||||
#endif // ANDROID
|
#endif // ANDROID
|
||||||
|
|
||||||
if (PR_GetEnv("MOZ_CHAOSMODE")) {
|
if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||||
ChaosFeature feature = ChaosFeature::Any;
|
ChaosFeature feature = ChaosFeature::Any;
|
||||||
long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16);
|
long featureInt = strtol(featureStr, nullptr, 16);
|
||||||
if (featureInt) {
|
if (featureInt) {
|
||||||
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
||||||
feature = static_cast<ChaosFeature>(featureInt);
|
feature = static_cast<ChaosFeature>(featureInt);
|
||||||
}
|
}
|
||||||
ChaosMode::SetChaosFeature(feature);
|
ChaosMode::SetChaosFeature(feature);
|
||||||
|
ChaosMode::enterChaosMode();
|
||||||
|
MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckArgExists("fxr")) {
|
if (CheckArgExists("fxr")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user