[vm/concurrency] Add NoActiveIsolateScope to precompiler & bg compiler

With --enable-isolate-groups we will start sharing JITed code. The JITed
code - which will be executed by all isolates - should therefore not
depend on a particular isolate's state, flags or any other
isolate-specific information.

To avoid accidental bugs where the compiler starts using
isolate-specific information, we ensure the compiler runs without a
current isolate.

This CL doesn't add NoActiveIsolateScope because on unoptimized compiles
of natives, the compiler calls out to embedder for eager native
resolution of native functions. This API forces embedder to callback
into VM atm.

Issue https://github.com/dart-lang/sdk/issues/36097

TEST=Adds more checking.

Change-Id: I6c86674c010b74c15855652415706dbaa8749d33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183692
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Martin Kustermann 2021-02-12 05:59:05 +00:00 committed by commit-bot@chromium.org
parent 8e887672f4
commit c95714d069
4 changed files with 29 additions and 20 deletions

View file

@ -57,7 +57,6 @@
namespace dart {
#define T (thread())
#define I (isolate())
#define IG (isolate_group())
#define Z (zone())
@ -1004,7 +1003,8 @@ void Precompiler::AddField(const Field& field) {
fields_to_retain_.Insert(&Field::ZoneHandle(Z, field.ptr()));
if (field.is_static()) {
const Object& value = Object::Handle(Z, field.StaticValue());
const Object& value =
Object::Handle(Z, IG->initial_field_table()->At(field.field_id()));
// Should not be in the middle of initialization while precompiling.
ASSERT(value.ptr() != Object::transition_sentinel().ptr());
@ -2878,6 +2878,8 @@ ErrorPtr Precompiler::CompileFunction(Precompiler* precompiler,
Thread* thread,
Zone* zone,
const Function& function) {
NoActiveIsolateScope no_isolate_scope;
VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId);
TIMELINE_FUNCTION_COMPILATION_DURATION(thread, "CompileFunction", function);

View file

@ -631,7 +631,11 @@ CodePtr CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
#if !defined(PRODUCT)
if (!function.HasOptimizedCode()) {
isolate()->debugger()->NotifyCompilation(function);
// TODO(dartbug.com/36097): We might need to adjust this once we start
// adding debugging support to --enable-isolate-groups.
thread()->isolate_group()->ForEachIsolate([&](Isolate* isolate) {
isolate->debugger()->NotifyCompilation(function);
});
}
#endif
if (FLAG_disassemble && FlowGraphPrinter::ShouldPrint(function)) {

View file

@ -40,23 +40,6 @@ DEFINE_FLAG(bool,
false,
"Explicitly disable heap verification.");
// We ensure that the GC does not use the current isolate.
class NoActiveIsolateScope {
public:
NoActiveIsolateScope() : thread_(Thread::Current()) {
saved_isolate_ = thread_->isolate_;
thread_->isolate_ = nullptr;
}
~NoActiveIsolateScope() {
ASSERT(thread_->isolate_ == nullptr);
thread_->isolate_ = saved_isolate_;
}
private:
Thread* thread_;
Isolate* saved_isolate_;
};
Heap::Heap(IsolateGroup* isolate_group,
bool is_vm_isolate,
intptr_t max_new_gen_semi_words,

View file

@ -1771,6 +1771,26 @@ class EnterIsolateGroupScope {
DISALLOW_COPY_AND_ASSIGN(EnterIsolateGroupScope);
};
// Ensure that isolate is not available for the duration of this scope.
//
// This can be used in code (e.g. GC, Kernel Loader) that should not operate on
// an individual isolate.
class NoActiveIsolateScope {
public:
NoActiveIsolateScope() : thread_(Thread::Current()) {
saved_isolate_ = thread_->isolate_;
thread_->isolate_ = nullptr;
}
~NoActiveIsolateScope() {
ASSERT(thread_->isolate_ == nullptr);
thread_->isolate_ = saved_isolate_;
}
private:
Thread* thread_;
Isolate* saved_isolate_;
};
} // namespace dart
#endif // RUNTIME_VM_ISOLATE_H_