[vm/concurrency] Move AllClassesFinalized/RemappingCids bits from Isolate to IsolateGroup
Those bits are used by parts of the VM that should be independent of the
current isolate (e.g. class finalizer, compiler).
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I25c8340304d21fdfa77fa5ab4a5f77a4884d0bba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182620
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc
index cc14ad3..ec47b19 100644
--- a/runtime/vm/class_finalizer.cc
+++ b/runtime/vm/class_finalizer.cc
@@ -1452,11 +1452,8 @@
HeapIterationScope his(T);
IG->shared_class_table()->Remap(old_to_new_cid);
- IG->ForEachIsolate(
- [&](Isolate* I) {
- I->set_remapping_cids(true);
- },
- /*is_at_safepoint=*/true);
+ IG->set_remapping_cids(true);
+
// Update the class table. Do it before rewriting cids in headers, as
// the heap walkers load an object's size *after* calling the visitor.
IG->class_table()->Remap(old_to_new_cid);
@@ -1468,11 +1465,7 @@
IG->heap()->VisitObjects(&visitor);
}
- IG->ForEachIsolate(
- [&](Isolate* I) {
- I->set_remapping_cids(false);
- },
- /*is_at_safepoint=*/true);
+ IG->set_remapping_cids(false);
#if defined(DEBUG)
IG->class_table()->Validate();
#endif
diff --git a/runtime/vm/compiler/aot/precompiler.cc b/runtime/vm/compiler/aot/precompiler.cc
index 392fd84..855cdca 100644
--- a/runtime/vm/compiler/aot/precompiler.cc
+++ b/runtime/vm/compiler/aot/precompiler.cc
@@ -2504,7 +2504,7 @@
if (!error_.IsNull()) {
Jump(error_);
}
- I->set_all_classes_finalized(true);
+ IG->set_all_classes_finalized(true);
}
void PrecompileParsedFunctionHelper::FinalizeCompilation(
diff --git a/runtime/vm/compiler/backend/flow_graph.cc b/runtime/vm/compiler/backend/flow_graph.cc
index 5b8b058..26198ca 100644
--- a/runtime/vm/compiler/backend/flow_graph.cc
+++ b/runtime/vm/compiler/backend/flow_graph.cc
@@ -482,7 +482,7 @@
FlowGraph::ToCheck FlowGraph::CheckForInstanceCall(
InstanceCallInstr* call,
UntaggedFunction::Kind kind) const {
- if (!FLAG_use_cha_deopt && !isolate()->all_classes_finalized()) {
+ if (!FLAG_use_cha_deopt && !isolate_group()->all_classes_finalized()) {
// Even if class or function are private, lazy class finalization
// may later add overriding methods.
return ToCheck::kCheckCid;
diff --git a/runtime/vm/compiler/backend/type_propagator.cc b/runtime/vm/compiler/backend/type_propagator.cc
index c8a7549..075f0cf 100644
--- a/runtime/vm/compiler/backend/type_propagator.cc
+++ b/runtime/vm/compiler/backend/type_propagator.cc
@@ -731,7 +731,7 @@
// Type of a private class cannot change through later loaded libs.
cid_ = type_class.id();
} else if (FLAG_use_cha_deopt ||
- thread->isolate()->all_classes_finalized()) {
+ thread->isolate_group()->all_classes_finalized()) {
if (FLAG_trace_cha) {
THR_Print(" **(CHA) Compile type not subclassed: %s\n",
type_class.ToCString());
@@ -1096,7 +1096,7 @@
cid = type_class.id();
} else {
if (FLAG_use_cha_deopt ||
- thread->isolate()->all_classes_finalized()) {
+ thread->isolate_group()->all_classes_finalized()) {
if (FLAG_trace_cha) {
THR_Print(
" **(CHA) Computing exact type of receiver, "
diff --git a/runtime/vm/compiler/call_specializer.cc b/runtime/vm/compiler/call_specializer.cc
index b6f5265..f81fd02 100644
--- a/runtime/vm/compiler/call_specializer.cc
+++ b/runtime/vm/compiler/call_specializer.cc
@@ -1161,7 +1161,7 @@
if (!type_class.IsPrivate()) {
// In AOT mode we can't use CHA deoptimizations.
ASSERT(!CompilerState::Current().is_aot() || !FLAG_use_cha_deopt);
- if (FLAG_use_cha_deopt || isolate()->all_classes_finalized()) {
+ if (FLAG_use_cha_deopt || isolate_group()->all_classes_finalized()) {
if (FLAG_trace_cha) {
THR_Print(
" **(CHA) Typecheck as class equality since no "
diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc
index 0e7cc2b..8ee2201 100644
--- a/runtime/vm/isolate.cc
+++ b/runtime/vm/isolate.cc
@@ -2815,7 +2815,7 @@
raw_class = group()->class_table()->At(cid);
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
ASSERT(raw_class != nullptr);
- ASSERT(remapping_cids() || raw_class->untag()->id_ == cid);
+ ASSERT(group()->remapping_cids() || raw_class->untag()->id_ == cid);
return raw_class;
}
diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h
index ddb50a7..2eb9f41 100644
--- a/runtime/vm/isolate.h
+++ b/runtime/vm/isolate.h
@@ -704,6 +704,23 @@
CompactionInProgressBit::update(value, isolate_group_flags_);
}
+ // In precompilation we finalize all regular classes before compiling.
+ bool all_classes_finalized() const {
+ return AllClassesFinalizedBit::decode(isolate_group_flags_);
+ }
+ void set_all_classes_finalized(bool value) {
+ isolate_group_flags_ =
+ AllClassesFinalizedBit::update(value, isolate_group_flags_);
+ }
+
+ bool remapping_cids() const {
+ return RemappingCidsBit::decode(isolate_group_flags_);
+ }
+ void set_remapping_cids(bool value) {
+ isolate_group_flags_ =
+ RemappingCidsBit::update(value, isolate_group_flags_);
+ }
+
uword FindPendingDeoptAtSafepoint(uword fp);
// Used by background compiler which field became boxed and must trigger
@@ -753,10 +770,12 @@
friend class NoReloadScope; // no_reload_scope_depth_
#define ISOLATE_GROUP_FLAG_BITS(V) \
+ V(AllClassesFinalized) \
V(CompactionInProgress) \
V(EnableAsserts) \
V(HasAttemptedReload) \
V(NullSafety) \
+ V(RemappingCids) \
V(NullSafetySet) \
V(Obfuscate) \
V(UseFieldGuards) \
@@ -1311,21 +1330,6 @@
ErrorPtr sticky_error() const { return sticky_error_; }
DART_WARN_UNUSED_RESULT ErrorPtr StealStickyError();
- // In precompilation we finalize all regular classes before compiling.
- bool all_classes_finalized() const {
- return AllClassesFinalizedBit::decode(isolate_flags_);
- }
- void set_all_classes_finalized(bool value) {
- isolate_flags_ = AllClassesFinalizedBit::update(value, isolate_flags_);
- }
-
- bool remapping_cids() const {
- return RemappingCidsBit::decode(isolate_flags_);
- }
- void set_remapping_cids(bool value) {
- isolate_flags_ = RemappingCidsBit::update(value, isolate_flags_);
- }
-
#ifndef PRODUCT
ErrorPtr InvokePendingServiceExtensionCalls();
void AppendServiceExtensionCall(const Instance& closure,
@@ -1572,8 +1576,6 @@
V(IsRunnable) \
V(IsServiceIsolate) \
V(IsKernelIsolate) \
- V(AllClassesFinalized) \
- V(RemappingCids) \
V(ResumeRequest) \
V(HasAttemptedStepping) \
V(ShouldPausePostServiceRequest) \
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 608ded3..7ad3137 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -3806,7 +3806,7 @@
void Class::Finalize() const {
auto thread = Thread::Current();
auto isolate_group = thread->isolate_group();
- ASSERT(!thread->isolate()->all_classes_finalized());
+ ASSERT(!thread->isolate_group()->all_classes_finalized());
ASSERT(!is_finalized());
// Prefinalized classes have a VM internal representation and no Dart fields.
// Their instance size is precomputed and field offsets are known.