Commit ffabcbe8 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[test] Manually restore changed flags in SaveFlags

SaveFlags previously worked by re-setting the flags using the command
line. Unfortunately, this could reset flags being used by concurrent
processes, which would cause TSAN issues.

Now, SaveFlags stores a copy of the state of all flags on creation, and
only resets changed flags in its destructor. It does this by (ab)using
the flag-definitions.h pseudo-header, adding a new mode to that header
which applies an includer-defined macro to each flag definition.

Change-Id: I4c156ecb36b4b7c05402138088266465d31e33b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1530809Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60350}
parent 701eb086
......@@ -72,6 +72,11 @@
#define DEFINE_NEG_VALUE_IMPLICATION(whenflag, thenflag, value) \
if (!FLAG_##whenflag) FLAG_##thenflag = value;
// We apply a generic macro to the flags.
#elif defined(FLAG_MODE_APPLY)
#define FLAG_FULL FLAG_MODE_APPLY
#else
#error No mode supplied when including flags.defs
#endif
......@@ -114,6 +119,10 @@ struct MaybeBoolFlag {
}
bool has_value;
bool value;
bool operator!=(const MaybeBoolFlag& other) const {
return has_value != other.has_value || value != other.value;
}
};
#endif
......@@ -1558,5 +1567,6 @@ DEFINE_BOOL(lite_mode, V8_LITE_BOOL,
#undef FLAG_MODE_DEFINE_DEFAULTS
#undef FLAG_MODE_META
#undef FLAG_MODE_DEFINE_IMPLICATIONS
#undef FLAG_MODE_APPLY
#undef COMMA
......@@ -43,19 +43,22 @@ v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
namespace internal {
SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
SaveFlags::SaveFlags() {
// For each flag, save the current flag value.
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) SAVED_##nam = FLAG_##nam;
#include "src/flag-definitions.h" // NOLINT
#undef FLAG_MODE_APPLY
}
SaveFlags::~SaveFlags() {
FlagList::ResetAllFlags();
int argc = static_cast<int>(non_default_flags_->size());
FlagList::SetFlagsFromCommandLine(
&argc, const_cast<char**>(non_default_flags_->data()),
false /* remove_flags */);
for (auto flag = non_default_flags_->begin();
flag != non_default_flags_->end(); ++flag) {
delete[] * flag;
// For each flag, set back the old flag value if it changed (don't write the
// flag if it didn't change, to keep TSAN happy).
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) \
if (SAVED_##nam != FLAG_##nam) { \
FLAG_##nam = SAVED_##nam; \
}
delete non_default_flags_;
#include "src/flag-definitions.h" // NOLINT
#undef FLAG_MODE_APPLY
}
} // namespace internal
......
......@@ -309,7 +309,9 @@ class SaveFlags {
~SaveFlags();
private:
std::vector<const char*>* non_default_flags_;
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) ctype SAVED_##nam;
#include "src/flag-definitions.h" // NOLINT
#undef FLAG_MODE_APPLY
DISALLOW_COPY_AND_ASSIGN(SaveFlags);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment