Use the default microtask scheduler on all isolates except the UI isolate (flutter/engine#5068)
See https://github.com/flutter/flutter/issues/16846
This commit is contained in:
@@ -62,8 +62,7 @@ static Dart_Handle GetClosure(Dart_Handle builtin_library, const char* name) {
|
||||
return closure;
|
||||
}
|
||||
|
||||
static void InitDartInternal(Dart_Handle builtin_library,
|
||||
DartRuntimeHooks::IsolateType isolate_type) {
|
||||
static void InitDartInternal(Dart_Handle builtin_library, bool is_ui_isolate) {
|
||||
Dart_Handle print = GetClosure(builtin_library, "_getPrintClosure");
|
||||
|
||||
Dart_Handle internal_library = Dart_LookupLibrary(ToDart("dart:_internal"));
|
||||
@@ -71,7 +70,7 @@ static void InitDartInternal(Dart_Handle builtin_library,
|
||||
DART_CHECK_VALID(
|
||||
Dart_SetField(internal_library, ToDart("_printClosure"), print));
|
||||
|
||||
if (isolate_type == DartRuntimeHooks::MainIsolate) {
|
||||
if (is_ui_isolate) {
|
||||
// Call |_setupHooks| to configure |VMLibraryHooks|.
|
||||
Dart_Handle method_name = Dart_NewStringFromCString("_setupHooks");
|
||||
DART_CHECK_VALID(Dart_Invoke(builtin_library, method_name, 0, NULL))
|
||||
@@ -97,14 +96,12 @@ static void InitDartCore(Dart_Handle builtin, const std::string& script_uri) {
|
||||
Dart_SetField(core_library, ToDart("_uriBaseClosure"), get_base_url));
|
||||
}
|
||||
|
||||
static void InitDartAsync(Dart_Handle builtin_library,
|
||||
DartRuntimeHooks::IsolateType isolate_type) {
|
||||
static void InitDartAsync(Dart_Handle builtin_library, bool is_ui_isolate) {
|
||||
Dart_Handle schedule_microtask;
|
||||
if (isolate_type == DartRuntimeHooks::MainIsolate) {
|
||||
if (is_ui_isolate) {
|
||||
schedule_microtask =
|
||||
GetClosure(builtin_library, "_getScheduleMicrotaskClosure");
|
||||
} else {
|
||||
FXL_CHECK(isolate_type == DartRuntimeHooks::SecondaryIsolate);
|
||||
Dart_Handle isolate_lib = Dart_LookupLibrary(ToDart("dart:isolate"));
|
||||
Dart_Handle method_name =
|
||||
Dart_NewStringFromCString("_getIsolateScheduleImmediateClosure");
|
||||
@@ -132,13 +129,13 @@ static void InitDartIO(Dart_Handle builtin_library,
|
||||
Dart_SetField(platform_type, ToDart("_localeClosure"), locale_closure));
|
||||
}
|
||||
|
||||
void DartRuntimeHooks::Install(IsolateType isolate_type,
|
||||
void DartRuntimeHooks::Install(bool is_ui_isolate,
|
||||
const std::string& script_uri) {
|
||||
Dart_Handle builtin = Dart_LookupLibrary(ToDart("dart:ui"));
|
||||
DART_CHECK_VALID(builtin);
|
||||
InitDartInternal(builtin, isolate_type);
|
||||
InitDartInternal(builtin, is_ui_isolate);
|
||||
InitDartCore(builtin, script_uri);
|
||||
InitDartAsync(builtin, isolate_type);
|
||||
InitDartAsync(builtin, is_ui_isolate);
|
||||
InitDartIO(builtin, script_uri);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,7 @@ namespace blink {
|
||||
|
||||
class DartRuntimeHooks {
|
||||
public:
|
||||
enum IsolateType {
|
||||
MainIsolate,
|
||||
SecondaryIsolate,
|
||||
};
|
||||
|
||||
static void Install(IsolateType isolate_type, const std::string& script_uri);
|
||||
static void Install(bool is_ui_isolate, const std::string& script_uri);
|
||||
static void RegisterNatives(tonic::DartLibraryNatives* natives);
|
||||
|
||||
private:
|
||||
|
||||
@@ -220,7 +220,7 @@ bool DartIsolate::UpdateThreadPoolNames() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DartIsolate::LoadLibraries() {
|
||||
bool DartIsolate::LoadLibraries(bool is_root_isolate) {
|
||||
TRACE_EVENT0("flutter", "DartIsolate::LoadLibraries");
|
||||
if (phase_ != Phase::Initialized) {
|
||||
return false;
|
||||
@@ -234,9 +234,7 @@ bool DartIsolate::LoadLibraries() {
|
||||
|
||||
const bool is_service_isolate = Dart_IsServiceIsolate(isolate());
|
||||
|
||||
DartRuntimeHooks::Install(is_service_isolate
|
||||
? DartRuntimeHooks::SecondaryIsolate
|
||||
: DartRuntimeHooks::MainIsolate,
|
||||
DartRuntimeHooks::Install(is_root_isolate && !is_service_isolate,
|
||||
GetAdvisoryScriptURI());
|
||||
|
||||
if (!is_service_isolate) {
|
||||
@@ -675,7 +673,7 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
|
||||
return {nullptr, {}};
|
||||
}
|
||||
|
||||
if (!embedder_isolate->LoadLibraries()) {
|
||||
if (!embedder_isolate->LoadLibraries(is_root_isolate)) {
|
||||
*error =
|
||||
strdup("Embedder could not load libraries in the new Dart isolate.");
|
||||
FXL_DLOG(ERROR) << *error;
|
||||
|
||||
@@ -114,7 +114,7 @@ class DartIsolate : public UIDartState {
|
||||
bool Initialize(Dart_Isolate isolate, bool is_root_isolate);
|
||||
|
||||
FXL_WARN_UNUSED_RESULT
|
||||
bool LoadLibraries();
|
||||
bool LoadLibraries(bool is_root_isolate);
|
||||
|
||||
bool UpdateThreadPoolNames() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user