[vm/concurrency] Ensure library tag handler is set up on the isolate group, shared by all isolates in the group.

The library tag handler needs to be available during set up of child isolate, during kernel loading for the isolate(due to usage of native extensions).
Setting up library tag handler in initialize_isolate callback is too late for that.

Change-Id: Ie152d2c699ce3318e90325e693b6c66d30267d7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110160
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2019-07-23 20:03:42 +00:00 committed by commit-bot@chromium.org
parent ce7232cd0f
commit f66964c66d
6 changed files with 37 additions and 17 deletions

View file

@ -200,10 +200,6 @@ static Dart_Handle SetupCoreLibraries(Dart_Isolate isolate,
Dart_Handle result;
// Set up the library tag handler for this isolate.
result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
if (Dart_IsError(result)) return result;
// Prepare builtin and other core libraries for use to resolve URIs.
// Set up various closures, e.g: printing, timers etc.
// Set up 'package root' for URI resolution.
@ -329,12 +325,17 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
int* exit_code) {
Dart_EnterScope();
// Set up the library tag handler for the isolate group shared by all
// isolates in the group.
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
CHECK_RESULT(result);
auto isolate_data = reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
const char* resolved_packages_config = nullptr;
Dart_Handle result = SetupCoreLibraries(isolate, isolate_data,
/*is_isolate_group_start=*/true,
&resolved_packages_config);
result = SetupCoreLibraries(isolate, isolate_data,
/*is_isolate_group_start=*/true,
&resolved_packages_config);
CHECK_RESULT(result);
#if !defined(DART_PRECOMPILED_RUNTIME)

View file

@ -5095,7 +5095,7 @@ DART_EXPORT Dart_Handle
Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
isolate->set_library_tag_handler(handler);
isolate->group()->set_library_tag_handler(handler);
return Api::Success();
}

View file

@ -1337,7 +1337,8 @@ RawObject* Isolate::CallTagHandler(Dart_LibraryTag tag,
Dart_Handle api_result;
{
TransitionVMToNative transition(thread);
api_result = library_tag_handler_(tag, api_arg1, api_arg2);
ASSERT(HasTagHandler());
api_result = group()->library_tag_handler()(tag, api_arg1, api_arg2);
}
return Api::UnwrapHandle(api_result);
}

View file

@ -252,6 +252,13 @@ class IsolateGroup {
bool is_mutator,
bool bypass_safepoint = false);
Dart_LibraryTagHandler library_tag_handler() const {
return library_tag_handler_;
}
void set_library_tag_handler(Dart_LibraryTagHandler handler) {
library_tag_handler_ = handler;
}
private:
std::unique_ptr<IsolateGroupSource> source_;
void* embedder_data_ = nullptr;
@ -261,6 +268,7 @@ class IsolateGroup {
IntrusiveDList<Isolate> isolates_;
intptr_t isolate_count_ = 0;
bool initial_spawn_successful_ = false;
Dart_LibraryTagHandler library_tag_handler_ = nullptr;
};
class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
@ -403,13 +411,12 @@ class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
environment_callback_ = value;
}
bool HasTagHandler() const { return library_tag_handler_ != nullptr; }
bool HasTagHandler() const {
return group()->library_tag_handler() != nullptr;
}
RawObject* CallTagHandler(Dart_LibraryTag tag,
const Object& arg1,
const Object& arg2);
void set_library_tag_handler(Dart_LibraryTagHandler value) {
library_tag_handler_ = value;
}
void SetupImagePage(const uint8_t* snapshot_buffer, bool is_executable);
@ -1127,7 +1134,6 @@ class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
uint64_t terminate_capability_ = 0;
void* init_callback_data_ = nullptr;
Dart_EnvironmentCallback environment_callback_ = nullptr;
Dart_LibraryTagHandler library_tag_handler_ = nullptr;
ApiState* api_state_ = nullptr;
Random random_;
Simulator* simulator_ = nullptr;

View file

@ -3,6 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
#if !defined(DART_PRECOMPILED_RUNTIME)
#include <memory>
#include "vm/kernel_binary.h"
#include "platform/globals.h"
#include "vm/compiler/frontend/kernel_to_il.h"
@ -166,14 +168,18 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
std::unique_ptr<Program> Program::ReadFromFile(
const char* script_uri, const char** error /* = nullptr */) {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
if (script_uri == NULL) {
return nullptr;
}
if (!isolate->HasTagHandler()) {
return nullptr;
}
std::unique_ptr<kernel::Program> kernel_program;
const String& uri = String::Handle(String::New(script_uri));
const Object& ret = Object::Handle(thread->isolate()->CallTagHandler(
Dart_kKernelTag, Object::null_object(), uri));
const Object& ret = Object::Handle(
isolate->CallTagHandler(Dart_kKernelTag, Object::null_object(), uri));
Api::Scope api_scope(thread);
Dart_Handle retval = Api::NewHandle(thread, ret.raw());
{

View file

@ -4,6 +4,8 @@
library test_extension_test;
import 'dart:isolate';
import "test_extension.dart";
class Expect {
@ -22,7 +24,9 @@ class Expect {
}
}
main() {
isolateHandler(_) {}
main() async {
Expect.equals('cat 13', new Cat(13).toString(), 'new Cat(13).toString()');
Expect.equals(3, Cat.ifNull(null, 3), 'Cat.ifNull(null, 3)');
@ -35,4 +39,6 @@ main() {
} on String catch (e) {
Expect.equals("ball", e);
}
await Isolate.spawn(isolateHandler, []);
}