Skip to content

Commit 3ef86d2

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Use atomics for isolate group flags.
TEST=tsan Change-Id: I1aaa29046ff6808e9aa19b83a2854d31f1776757 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422542 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 5ec3686 commit 3ef86d2

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed

runtime/vm/isolate.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ IsolateGroup::IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
354354
shared_initial_field_table_(new FieldTable(/*isolate=*/nullptr,
355355
/*isolate_group=*/nullptr)),
356356
shared_field_table_(new FieldTable(/*isolate=*/nullptr, this)),
357+
isolate_group_flags_(),
357358
#if !defined(DART_PRECOMPILED_RUNTIME)
358359
background_compiler_(new BackgroundCompiler(this)),
359360
#endif
@@ -1825,7 +1826,7 @@ Isolate::Isolate(IsolateGroup* isolate_group,
18251826
finalizers_(GrowableObjectArray::null()),
18261827
isolate_group_(isolate_group),
18271828
isolate_object_store_(new IsolateObjectStore()),
1828-
isolate_flags_(0),
1829+
isolate_flags_(),
18291830
#if !defined(PRODUCT)
18301831
last_resume_timestamp_(OS::GetCurrentTimeMillis()),
18311832
vm_tag_counters_(),

runtime/vm/isolate.h

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -442,35 +442,31 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
442442
#undef DECLARE_GETTER
443443

444444
bool should_load_vmservice() const {
445-
return ShouldLoadVmServiceBit::decode(isolate_group_flags_);
445+
return isolate_group_flags_.Read<ShouldLoadVmServiceBit>();
446446
}
447447
void set_should_load_vmservice(bool value) {
448-
isolate_group_flags_ =
449-
ShouldLoadVmServiceBit::update(value, isolate_group_flags_);
448+
isolate_group_flags_.UpdateBool<ShouldLoadVmServiceBit>(value);
450449
}
451450

452451
void set_asserts(bool value) {
453-
isolate_group_flags_ =
454-
EnableAssertsBit::update(value, isolate_group_flags_);
452+
isolate_group_flags_.UpdateBool<EnableAssertsBit>(value);
455453
}
456454

457455
void set_branch_coverage(bool value) {
458-
isolate_group_flags_ =
459-
BranchCoverageBit::update(value, isolate_group_flags_);
456+
isolate_group_flags_.UpdateBool<BranchCoverageBit>(value);
460457
}
461458

462459
void set_coverage(bool value) {
463-
isolate_group_flags_ = CoverageBit::update(value, isolate_group_flags_);
460+
isolate_group_flags_.UpdateBool<CoverageBit>(value);
464461
}
465462

466463
#if !defined(PRODUCT)
467464
#if !defined(DART_PRECOMPILED_RUNTIME)
468465
bool HasAttemptedReload() const {
469-
return HasAttemptedReloadBit::decode(isolate_group_flags_);
466+
return isolate_group_flags_.Read<HasAttemptedReloadBit>();
470467
}
471468
void SetHasAttemptedReload(bool value) {
472-
isolate_group_flags_ =
473-
HasAttemptedReloadBit::update(value, isolate_group_flags_);
469+
isolate_group_flags_.UpdateBool<HasAttemptedReloadBit>(value);
474470
}
475471
void MaybeIncreaseReloadEveryNStackOverflowChecks();
476472
intptr_t reload_every_n_stack_overflow_checks() const {
@@ -482,17 +478,17 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
482478
#endif // !defined(PRODUCT)
483479

484480
bool has_seen_oom() const {
485-
return HasSeenOOMBit::decode(isolate_group_flags_);
481+
return isolate_group_flags_.Read<HasSeenOOMBit>();
486482
}
487483
void set_has_seen_oom(bool value) {
488-
isolate_group_flags_ = HasSeenOOMBit::update(value, isolate_group_flags_);
484+
isolate_group_flags_.UpdateBool<HasSeenOOMBit>(value);
489485
}
490486

491487
#if defined(PRODUCT)
492488
void set_use_osr(bool use_osr) { ASSERT(!use_osr); }
493489
#else // defined(PRODUCT)
494490
void set_use_osr(bool use_osr) {
495-
isolate_group_flags_ = UseOsrBit::update(use_osr, isolate_group_flags_);
491+
isolate_group_flags_.UpdateBool<UseOsrBit>(use_osr);
496492
}
497493
#endif // defined(PRODUCT)
498494

@@ -717,26 +713,23 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
717713

718714
// In precompilation we finalize all regular classes before compiling.
719715
bool all_classes_finalized() const {
720-
return AllClassesFinalizedBit::decode(isolate_group_flags_);
716+
return isolate_group_flags_.Read<AllClassesFinalizedBit>();
721717
}
722718
void set_all_classes_finalized(bool value) {
723-
isolate_group_flags_ =
724-
AllClassesFinalizedBit::update(value, isolate_group_flags_);
719+
isolate_group_flags_.UpdateBool<AllClassesFinalizedBit>(value);
725720
}
726721
bool has_dynamically_extendable_classes() const {
727-
return HasDynamicallyExtendableClassesBit::decode(isolate_group_flags_);
722+
return isolate_group_flags_.Read<HasDynamicallyExtendableClassesBit>();
728723
}
729724
void set_has_dynamically_extendable_classes(bool value) {
730-
isolate_group_flags_ =
731-
HasDynamicallyExtendableClassesBit::update(value, isolate_group_flags_);
725+
isolate_group_flags_.UpdateBool<HasDynamicallyExtendableClassesBit>(value);
732726
}
733727

734728
bool remapping_cids() const {
735-
return RemappingCidsBit::decode(isolate_group_flags_);
729+
return isolate_group_flags_.Read<RemappingCidsBit>();
736730
}
737731
void set_remapping_cids(bool value) {
738-
isolate_group_flags_ =
739-
RemappingCidsBit::update(value, isolate_group_flags_);
732+
isolate_group_flags_.UpdateBool<RemappingCidsBit>(value);
740733
}
741734

742735
void RememberLiveTemporaries();
@@ -904,7 +897,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
904897
std::shared_ptr<FieldTable> initial_field_table_;
905898
std::shared_ptr<FieldTable> shared_initial_field_table_;
906899
std::shared_ptr<FieldTable> shared_field_table_;
907-
uint32_t isolate_group_flags_ = 0;
900+
AtomicBitFieldContainer<uint32_t> isolate_group_flags_;
908901

909902
NOT_IN_PRECOMPILED(std::unique_ptr<BackgroundCompiler> background_compiler_);
910903

@@ -1114,9 +1107,9 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
11141107

11151108
MessageHandler* message_handler() const;
11161109

1117-
bool is_runnable() const { return LoadIsolateFlagsBit<IsRunnableBit>(); }
1110+
bool is_runnable() const { return isolate_flags_.Read<IsRunnableBit>(); }
11181111
void set_is_runnable(bool value) {
1119-
UpdateIsolateFlagsBit<IsRunnableBit>(value);
1112+
isolate_flags_.UpdateBool<IsRunnableBit>(value);
11201113
#if !defined(PRODUCT)
11211114
if (is_runnable()) {
11221115
set_last_resume_timestamp();
@@ -1165,10 +1158,10 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
11651158
return OFFSET_OF(Isolate, has_resumption_breakpoints_);
11661159
}
11671160

1168-
bool ResumeRequest() const { return LoadIsolateFlagsBit<ResumeRequestBit>(); }
1161+
bool ResumeRequest() const { return isolate_flags_.Read<ResumeRequestBit>(); }
11691162
// Lets the embedder know that a service message resulted in a resume request.
11701163
void SetResumeRequest() {
1171-
UpdateIsolateFlagsBit<ResumeRequestBit>(true);
1164+
isolate_flags_.UpdateBool<ResumeRequestBit>(true);
11721165
set_last_resume_timestamp();
11731166
}
11741167

@@ -1181,7 +1174,7 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
11811174
// Returns whether the vm service has requested that the debugger
11821175
// resume execution.
11831176
bool GetAndClearResumeRequest() {
1184-
return UpdateIsolateFlagsBit<ResumeRequestBit>(false);
1177+
return isolate_flags_.TryClear<ResumeRequestBit>();
11851178
}
11861179
#endif
11871180

@@ -1203,9 +1196,9 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
12031196
void RemoveErrorListener(const SendPort& listener);
12041197
bool NotifyErrorListeners(const char* msg, const char* stacktrace);
12051198

1206-
bool ErrorsFatal() const { return LoadIsolateFlagsBit<ErrorsFatalBit>(); }
1199+
bool ErrorsFatal() const { return isolate_flags_.Read<ErrorsFatalBit>(); }
12071200
void SetErrorsFatal(bool value) {
1208-
UpdateIsolateFlagsBit<ErrorsFatalBit>(value);
1201+
isolate_flags_.UpdateBool<ErrorsFatalBit>(value);
12091202
}
12101203

12111204
Random* random() { return &random_; }
@@ -1336,10 +1329,10 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
13361329

13371330
#if !defined(PRODUCT)
13381331
bool should_pause_post_service_request() const {
1339-
return LoadIsolateFlagsBit<ShouldPausePostServiceRequestBit>();
1332+
return isolate_flags_.Read<ShouldPausePostServiceRequestBit>();
13401333
}
13411334
void set_should_pause_post_service_request(bool value) {
1342-
UpdateIsolateFlagsBit<ShouldPausePostServiceRequestBit>(value);
1335+
isolate_flags_.UpdateBool<ShouldPausePostServiceRequestBit>(value);
13431336
}
13441337
#endif // !defined(PRODUCT)
13451338

@@ -1398,16 +1391,16 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
13981391
void PauseEventHandler();
13991392
#endif
14001393

1401-
bool is_vm_isolate() const { return LoadIsolateFlagsBit<IsVMIsolateBit>(); }
1394+
bool is_vm_isolate() const { return isolate_flags_.Read<IsVMIsolateBit>(); }
14021395
void set_is_vm_isolate(bool value) {
1403-
UpdateIsolateFlagsBit<IsVMIsolateBit>(value);
1396+
isolate_flags_.UpdateBool<IsVMIsolateBit>(value);
14041397
}
14051398

14061399
bool is_service_registered() const {
1407-
return LoadIsolateFlagsBit<IsServiceRegisteredBit>();
1400+
return isolate_flags_.Read<IsServiceRegisteredBit>();
14081401
}
14091402
void set_is_service_registered(bool value) {
1410-
UpdateIsolateFlagsBit<IsServiceRegisteredBit>(value);
1403+
isolate_flags_.UpdateBool<IsServiceRegisteredBit>(value);
14111404
}
14121405

14131406
// Isolate-specific flag handling.
@@ -1431,7 +1424,7 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
14311424

14321425
#define DECLARE_GETTER(when, name, bitname, isolate_flag_name, flag_name) \
14331426
bool name() const { \
1434-
return FLAG_FOR_##when(LoadIsolateFlagsBit<bitname##Bit>(), flag_name); \
1427+
return FLAG_FOR_##when(isolate_flags_.Read<bitname##Bit>(), flag_name); \
14351428
}
14361429
BOOL_ISOLATE_FLAG_LIST(DECLARE_GETTER)
14371430
#undef FLAG_FOR_NONPRODUCT
@@ -1440,10 +1433,10 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
14401433
#undef DECLARE_GETTER
14411434

14421435
bool has_attempted_stepping() const {
1443-
return LoadIsolateFlagsBit<HasAttemptedSteppingBit>();
1436+
return isolate_flags_.Read<HasAttemptedSteppingBit>();
14441437
}
14451438
void set_has_attempted_stepping(bool value) {
1446-
UpdateIsolateFlagsBit<HasAttemptedSteppingBit>(value);
1439+
isolate_flags_.UpdateBool<HasAttemptedSteppingBit>(value);
14471440
}
14481441

14491442
// Kills all non-system isolates.
@@ -1614,18 +1607,7 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
16141607
ISOLATE_FLAG_BITS(DECLARE_BITFIELD)
16151608
#undef DECLARE_BITFIELD
16161609

1617-
template <class T>
1618-
bool UpdateIsolateFlagsBit(bool value) {
1619-
return T::decode(value ? isolate_flags_.fetch_or(T::encode(true),
1620-
std::memory_order_relaxed)
1621-
: isolate_flags_.fetch_and(
1622-
~T::encode(true), std::memory_order_relaxed));
1623-
}
1624-
template <class T>
1625-
bool LoadIsolateFlagsBit() const {
1626-
return T::decode(isolate_flags_.load(std::memory_order_relaxed));
1627-
}
1628-
std::atomic<uint32_t> isolate_flags_;
1610+
AtomicBitFieldContainer<uint32_t> isolate_flags_;
16291611

16301612
// Fields that aren't needed in a product build go here with boolean flags at
16311613
// the top.

0 commit comments

Comments
 (0)