Skip to content

Commit 29268ba

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Move no-reload-scope counter to Thread
Whether a given isolate allows reloading is really a property of the thread not the isolate (where it was before) or isolate group (where it was moved to), so this CL moves it to Thread. As the thread's stack is going down and up, NoReloadScope's might be entered or exited, just as with our many other scopes, such as NoOOBMessageScope/... Longer term we might need to find a better mechanism to deal with different OOB messages. For example: Reload as well as OOB messages are disabled during static field initialization. Though that means *all* OOB messages cannot reach the isolate during initialization of a static field (which can do arbitrary amount of work). This is part of making hot-reload work with isolate groups. Issue #36097 TEST=Refactoring of existing code. Change-Id: I9e80c6d4a184c54c0373fef13af3264cc3f27ece Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187002 Reviewed-by: Alexander Aprelev <[email protected]> Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent f3740ce commit 29268ba

File tree

8 files changed

+38
-41
lines changed

8 files changed

+38
-41
lines changed

runtime/lib/mirrors.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ DEFINE_NATIVE_ENTRY(IsolateMirror_loadUri, 0, 1) {
666666
ThrowLanguageError("no library handler registered");
667667
}
668668

669-
NoReloadScope no_reload(isolate->group(), thread);
669+
NoReloadScope no_reload(thread);
670670

671671
// Canonicalize library URI.
672672
String& canonical_uri = String::Handle(zone);

runtime/vm/exceptions.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ ObjectPtr Exceptions::Create(ExceptionType type, const Array& arguments) {
11911191
}
11921192

11931193
Thread* thread = Thread::Current();
1194-
NoReloadScope no_reload_scope(thread->isolate_group(), thread);
1194+
NoReloadScope no_reload_scope(thread);
11951195
return DartLibraryCalls::InstanceCreate(library, *class_name,
11961196
*constructor_name, arguments);
11971197
}

runtime/vm/isolate.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -866,22 +866,6 @@ NoOOBMessageScope::~NoOOBMessageScope() {
866866
}
867867
}
868868

869-
NoReloadScope::NoReloadScope(IsolateGroup* isolate_group, Thread* thread)
870-
: ThreadStackResource(thread), isolate_group_(isolate_group) {
871-
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
872-
ASSERT(isolate_group_ != NULL);
873-
isolate_group_->no_reload_scope_depth_.fetch_add(1);
874-
ASSERT(isolate_group_->no_reload_scope_depth_ >= 0);
875-
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
876-
}
877-
878-
NoReloadScope::~NoReloadScope() {
879-
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
880-
isolate_group_->no_reload_scope_depth_.fetch_sub(1);
881-
ASSERT(isolate_group_->no_reload_scope_depth_ >= 0);
882-
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
883-
}
884-
885869
Bequest::~Bequest() {
886870
IsolateGroup* isolate_group = IsolateGroup::Current();
887871
CHECK_ISOLATE_GROUP(isolate_group);
@@ -1500,7 +1484,7 @@ MessageHandler::MessageStatus IsolateMessageHandler::ProcessUnhandledException(
15001484
T->isolate()->name(), result.ToErrorCString());
15011485
}
15021486

1503-
NoReloadScope no_reload_scope(T->isolate_group(), T);
1487+
NoReloadScope no_reload(T);
15041488
// Generate the error and stacktrace strings for the error message.
15051489
const char* exception_cstr = nullptr;
15061490
const char* stacktrace_cstr = nullptr;
@@ -2002,13 +1986,14 @@ void Isolate::BuildName(const char* name_prefix) {
20021986

20031987
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
20041988
bool IsolateGroup::CanReload() {
1989+
auto thread = Thread::Current();
20051990
// TODO(dartbug.com/36097): As part of implementing hot-reload support for
20061991
// --enable-isolate-groups, we should make the reload implementation wait for
20071992
// any outstanding isolates to "check-in" (which should only be done after
20081993
// making them runnable) instead of refusing the reload.
20091994
bool all_runnable = true;
20101995
{
2011-
SafepointReadRwLocker ml(Thread::Current(), isolates_lock_.get());
1996+
SafepointReadRwLocker ml(thread, isolates_lock_.get());
20121997
for (Isolate* isolate : isolates_) {
20131998
if (!isolate->is_runnable()) {
20141999
all_runnable = false;
@@ -2017,7 +2002,7 @@ bool IsolateGroup::CanReload() {
20172002
}
20182003
}
20192004
return !IsolateGroup::IsSystemIsolateGroup(this) && all_runnable &&
2020-
!IsReloading() && (no_reload_scope_depth_ == 0) &&
2005+
!IsReloading() && (thread->no_reload_scope_depth_ == 0) &&
20212006
Isolate::IsolateCreationEnabled() &&
20222007
OSThread::Current()->HasStackHeadroom(64 * KB);
20232008
}

runtime/vm/isolate.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,6 @@ class NoOOBMessageScope : public ThreadStackResource {
154154
DISALLOW_COPY_AND_ASSIGN(NoOOBMessageScope);
155155
};
156156

157-
// Disallow isolate reload.
158-
class NoReloadScope : public ThreadStackResource {
159-
public:
160-
NoReloadScope(IsolateGroup* isolate_group, Thread* thread);
161-
~NoReloadScope();
162-
163-
private:
164-
IsolateGroup* isolate_group_;
165-
DISALLOW_COPY_AND_ASSIGN(NoReloadScope);
166-
};
167-
168157
// Fixed cache for exception handler lookup.
169158
typedef FixedCache<intptr_t, ExceptionHandlerInfo, 16> HandlerInfoCache;
170159
// Fixed cache for catch entry state lookup.
@@ -826,7 +815,6 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
826815
friend class StackFrame; // For `[isolates_].First()`.
827816
// For `object_store_shared_untag()`, `class_table_shared_untag()`
828817
friend class Isolate;
829-
friend class NoReloadScope; // no_reload_scope_depth_
830818

831819
#define ISOLATE_GROUP_FLAG_BITS(V) \
832820
V(AllClassesFinalized) \
@@ -882,8 +870,6 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
882870
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
883871
int64_t last_reload_timestamp_;
884872
std::shared_ptr<IsolateGroupReloadContext> group_reload_context_;
885-
RelaxedAtomic<intptr_t> no_reload_scope_depth_ =
886-
0; // we can only reload when this is 0.
887873
// Per-isolate-group copy of FLAG_reload_every.
888874
RelaxedAtomic<intptr_t> reload_every_n_stack_overflow_checks_;
889875
ProgramReloadContext* program_reload_context_ = nullptr;

runtime/vm/kernel_loader.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void KernelLoader::EvaluateDelayedPragmas() {
500500

501501
Thread* thread = Thread::Current();
502502
NoOOBMessageScope no_msg_scope(thread);
503-
NoReloadScope no_reload_scope(thread->isolate_group(), thread);
503+
NoReloadScope no_reload_scope(thread);
504504

505505
Function& function = Function::Handle();
506506
Library& library = Library::Handle();
@@ -2096,7 +2096,7 @@ void KernelLoader::LoadProcedure(const Library& library,
20962096
} else {
20972097
Thread* thread = Thread::Current();
20982098
NoOOBMessageScope no_msg_scope(thread);
2099-
NoReloadScope no_reload_scope(thread->isolate_group(), thread);
2099+
NoReloadScope no_reload_scope(thread);
21002100
library.GetMetadata(function);
21012101
}
21022102
}

runtime/vm/object.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10842,7 +10842,7 @@ ObjectPtr Field::EvaluateInitializer() const {
1084210842
#endif // !defined(DART_PRECOMPILED_RUNTIME)
1084310843

1084410844
NoOOBMessageScope no_msg_scope(thread);
10845-
NoReloadScope no_reload_scope(thread->isolate_group(), thread);
10845+
NoReloadScope no_reload_scope(thread);
1084610846
const Function& initializer = Function::Handle(EnsureInitializerFunction());
1084710847
return DartEntry::InvokeFunction(initializer, Object::empty_array());
1084810848
}
@@ -18063,7 +18063,7 @@ StringPtr LanguageError::FormatMessage() const {
1806318063

1806418064
const char* LanguageError::ToErrorCString() const {
1806518065
Thread* thread = Thread::Current();
18066-
NoReloadScope no_reload_scope(thread->isolate_group(), thread);
18066+
NoReloadScope no_reload_scope(thread);
1806718067
const String& msg_str = String::Handle(FormatMessage());
1806818068
return msg_str.ToCString();
1806918069
}
@@ -18113,7 +18113,7 @@ void UnhandledException::set_stacktrace(const Instance& stacktrace) const {
1811318113
const char* UnhandledException::ToErrorCString() const {
1811418114
Thread* thread = Thread::Current();
1811518115
auto isolate_group = thread->isolate_group();
18116-
NoReloadScope no_reload_scope(isolate_group, thread);
18116+
NoReloadScope no_reload_scope(thread);
1811718117
HANDLESCOPE(thread);
1811818118
Object& strtmp = Object::Handle();
1811918119
const char* exc_str;

runtime/vm/runtime_entry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ static void HandleStackOverflowTestCases(Thread* thread) {
25522552

25532553
const char* script_uri;
25542554
{
2555-
NoReloadScope no_reload(isolate_group, thread);
2555+
NoReloadScope no_reload(thread);
25562556
const Library& lib =
25572557
Library::Handle(isolate_group->object_store()->_internal_library());
25582558
const Class& cls = Class::Handle(

runtime/vm/thread.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ class Thread : public ThreadState {
565565
#endif
566566
}
567567

568+
bool IsInNoReloadScope() const { return no_reload_scope_depth_ > 0; }
569+
568570
#define DEFINE_OFFSET_METHOD(type_name, member_name, expr, default_init_value) \
569571
static intptr_t member_name##offset() { \
570572
return OFFSET_OF(Thread, member_name); \
@@ -1000,6 +1002,7 @@ class Thread : public ThreadState {
10001002
mutable Monitor thread_lock_;
10011003
ApiLocalScope* api_reusable_scope_;
10021004
int32_t no_callback_scope_depth_;
1005+
intptr_t no_reload_scope_depth_ = 0;
10031006
#if defined(DEBUG)
10041007
int32_t no_safepoint_scope_depth_;
10051008
#endif
@@ -1088,6 +1091,7 @@ class Thread : public ThreadState {
10881091
friend class IsolateGroup;
10891092
friend class IsolateTestHelper;
10901093
friend class NoOOBMessageScope;
1094+
friend class NoReloadScope;
10911095
friend class Simulator;
10921096
friend class StackZone;
10931097
friend class ThreadRegistry;
@@ -1137,6 +1141,28 @@ class NoSafepointScope : public ValueObject {
11371141
};
11381142
#endif // defined(DEBUG)
11391143

1144+
class NoReloadScope : public ThreadStackResource {
1145+
public:
1146+
explicit NoReloadScope(Thread* thread)
1147+
: ThreadStackResource(thread), thread_(thread) {
1148+
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1149+
thread->no_reload_scope_depth_++;
1150+
ASSERT(thread->no_reload_scope_depth_ >= 0);
1151+
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1152+
}
1153+
1154+
~NoReloadScope() {
1155+
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1156+
thread_->no_reload_scope_depth_ -= 1;
1157+
ASSERT(thread_->no_reload_scope_depth_ >= 0);
1158+
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1159+
}
1160+
1161+
private:
1162+
Thread* thread_;
1163+
DISALLOW_COPY_AND_ASSIGN(NoReloadScope);
1164+
};
1165+
11401166
// Within a EnterCompilerScope, the thread must operate on cloned fields.
11411167
#if defined(DEBUG)
11421168
class EnterCompilerScope : public ThreadStackResource {

0 commit comments

Comments
 (0)