Skip to content

Commit

Permalink
Revert "Enable shutting down all root isolates in a VM. (#8402)" (#8431)
Browse files Browse the repository at this point in the history
This reverts commit b59c443.
  • Loading branch information
chinmaygarde committed Apr 4, 2019
1 parent b59c443 commit 800ea0a
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 372 deletions.
1 change: 0 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ FILE: ../../../flutter/lib/ui/window/window.h
FILE: ../../../flutter/runtime/dart_isolate.cc
FILE: ../../../flutter/runtime/dart_isolate.h
FILE: ../../../flutter/runtime/dart_isolate_unittests.cc
FILE: ../../../flutter/runtime/dart_lifecycle_unittests.cc
FILE: ../../../flutter/runtime/dart_service_isolate.cc
FILE: ../../../flutter/runtime/dart_service_isolate.h
FILE: ../../../flutter/runtime/dart_service_isolate_unittests.cc
Expand Down
8 changes: 2 additions & 6 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ using UnhandledExceptionCallback =
// callback that generates the mapping from these paths.
// https://github.com/flutter/flutter/issues/26783
using MappingCallback = std::function<std::unique_ptr<fml::Mapping>(void)>;
using MappingsCallback =
std::function<std::vector<std::unique_ptr<const fml::Mapping>>(void)>;

struct Settings {
Settings();
Expand All @@ -55,10 +53,8 @@ struct Settings {
MappingCallback dart_library_sources_kernel;

std::string application_library_path;

std::string application_kernel_asset; // deprecated
std::string application_kernel_list_asset; // deprecated
MappingsCallback application_kernels;
std::string application_kernel_asset;
std::string application_kernel_list_asset;

std::string temp_directory_path;
std::vector<std::string> dart_flags;
Expand Down
39 changes: 5 additions & 34 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,18 @@ test_fixtures("runtime_fixtures") {
fixtures = [ "fixtures/simple_main.dart" ]
}

source_set("runtime_unittests_common") {
visibility = [ ":*" ]

executable("runtime_unittests") {
testonly = true

sources = [
"dart_isolate_unittests.cc",
"dart_service_isolate_unittests.cc",
"dart_vm_unittests.cc",
"runtime_test.cc",
"runtime_test.h",
]

public_deps = [
deps = [
":libdart",
":runtime",
":runtime_fixtures",
Expand All @@ -123,36 +124,6 @@ source_set("runtime_unittests_common") {
"//third_party/skia",
"//third_party/tonic",
]
}

executable("runtime_unittests") {
testonly = true

sources = [
"dart_isolate_unittests.cc",
"dart_service_isolate_unittests.cc",
"dart_vm_unittests.cc",
]

deps = [
":runtime_unittests_common",
]

if (is_linux) {
ldflags = [ "-rdynamic" ]
}
}

executable("runtime_lifecycle_unittests") {
testonly = true

sources = [
"dart_lifecycle_unittests.cc",
]

deps = [
":runtime_unittests_common",
]

if (is_linux) {
ldflags = [ "-rdynamic" ]
Expand Down
71 changes: 13 additions & 58 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,17 @@ bool DartIsolate::Initialize(Dart_Isolate dart_isolate, bool is_root_isolate) {

tonic::DartIsolateScope scope(isolate());

SetMessageHandlingTaskRunner(GetTaskRunners().GetUITaskRunner(),
is_root_isolate);
if (is_root_isolate) {
if (auto task_runner = GetTaskRunners().GetUITaskRunner()) {
// Isolates may not have any particular thread affinity. Only initialize
// the task dispatcher if a task runner is explicitly specified.
tonic::DartMessageHandler::TaskDispatcher dispatcher =
[task_runner](std::function<void()> task) {
task_runner->PostTask(task);
};
message_handler().Initialize(dispatcher);
}
}

if (tonic::LogIfError(
Dart_SetLibraryTagHandler(tonic::DartState::HandleLibraryTag))) {
Expand All @@ -178,23 +187,6 @@ bool DartIsolate::Initialize(Dart_Isolate dart_isolate, bool is_root_isolate) {
return true;
}

fml::RefPtr<fml::TaskRunner> DartIsolate::GetMessageHandlingTaskRunner() const {
return message_handling_task_runner_;
}

void DartIsolate::SetMessageHandlingTaskRunner(
fml::RefPtr<fml::TaskRunner> runner,
bool is_root_isolate) {
if (!is_root_isolate || !runner) {
return;
}

message_handling_task_runner_ = runner;

message_handler().Initialize(
[runner](std::function<void()> task) { runner->PostTask(task); });
}

// Updating thread names here does not change the underlying OS thread names.
// Instead, this is just additional metadata for the Observatory to show the
// thread name of the isolate.
Expand Down Expand Up @@ -369,34 +361,6 @@ bool DartIsolate::PrepareForRunningFromKernel(
return true;
}

FML_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromKernels(
std::vector<std::shared_ptr<const fml::Mapping>> kernels) {
const auto count = kernels.size();
if (count == 0) {
return false;
}

for (size_t i = 0; i < count; ++i) {
bool last = (i == (count - 1));
if (!PrepareForRunningFromKernel(kernels[i], last)) {
return false;
}
}

return true;
}

FML_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromKernels(
std::vector<std::unique_ptr<const fml::Mapping>> kernels) {
std::vector<std::shared_ptr<const fml::Mapping>> shared_kernels;
for (auto& kernel : kernels) {
shared_kernels.emplace_back(std::move(kernel));
}
return PrepareForRunningFromKernels(shared_kernels);
}

bool DartIsolate::MarkIsolateRunnable() {
TRACE_EVENT0("flutter", "DartIsolate::MarkIsolateRunnable");
if (phase_ != Phase::LibrariesSetup) {
Expand Down Expand Up @@ -520,6 +484,7 @@ bool DartIsolate::Shutdown() {
// the isolate to shutdown as a parameter.
FML_DCHECK(Dart_CurrentIsolate() == nullptr);
Dart_EnterIsolate(vm_isolate);
shutdown_callbacks_.clear();
Dart_ShutdownIsolate();
FML_DCHECK(Dart_CurrentIsolate() == nullptr);
}
Expand Down Expand Up @@ -721,8 +686,6 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
}
}

DartVMRef::GetRunningVM()->RegisterActiveIsolate(*embedder_isolate);

// The ownership of the embedder object is controlled by the Dart VM. So the
// only reference returned to the caller is weak.
embedder_isolate.release();
Expand All @@ -731,9 +694,7 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(

// |Dart_IsolateShutdownCallback|
void DartIsolate::DartIsolateShutdownCallback(
std::shared_ptr<DartIsolate>* embedder_isolate) {
embedder_isolate->get()->OnShutdownCallback();
}
std::shared_ptr<DartIsolate>* embedder_isolate) {}

// |Dart_IsolateCleanupCallback|
void DartIsolate::DartIsolateCleanupCallback(
Expand All @@ -758,12 +719,6 @@ void DartIsolate::AddIsolateShutdownCallback(fml::closure closure) {
std::make_unique<AutoFireClosure>(std::move(closure)));
}

void DartIsolate::OnShutdownCallback() {
shutdown_callbacks_.clear();
DartVMRef::GetRunningVM()->UnregisterActiveIsolate(
std::static_pointer_cast<DartIsolate>(shared_from_this()));
}

DartIsolate::AutoFireClosure::AutoFireClosure(fml::closure closure)
: closure_(std::move(closure)) {}

Expand Down
17 changes: 0 additions & 17 deletions runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef FLUTTER_RUNTIME_DART_ISOLATE_H_
#define FLUTTER_RUNTIME_DART_ISOLATE_H_

#include <memory>
#include <set>
#include <string>

Expand Down Expand Up @@ -76,14 +75,6 @@ class DartIsolate : public UIDartState {
bool PrepareForRunningFromKernel(std::shared_ptr<const fml::Mapping> kernel,
bool last_piece = true);

FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromKernels(
std::vector<std::shared_ptr<const fml::Mapping>> kernels);

FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromKernels(
std::vector<std::unique_ptr<const fml::Mapping>> kernels);

FML_WARN_UNUSED_RESULT
bool Run(const std::string& entrypoint, fml::closure on_run = nullptr);

Expand All @@ -103,8 +94,6 @@ class DartIsolate : public UIDartState {

std::weak_ptr<DartIsolate> GetWeakIsolatePtr();

fml::RefPtr<fml::TaskRunner> GetMessageHandlingTaskRunner() const;

private:
bool LoadKernel(std::shared_ptr<const fml::Mapping> mapping, bool last_piece);

Expand All @@ -127,14 +116,10 @@ class DartIsolate : public UIDartState {
std::vector<std::shared_ptr<const fml::Mapping>> kernel_buffers_;
std::vector<std::unique_ptr<AutoFireClosure>> shutdown_callbacks_;
ChildIsolatePreparer child_isolate_preparer_ = nullptr;
fml::RefPtr<fml::TaskRunner> message_handling_task_runner_;

FML_WARN_UNUSED_RESULT
bool Initialize(Dart_Isolate isolate, bool is_root_isolate);

void SetMessageHandlingTaskRunner(fml::RefPtr<fml::TaskRunner> runner,
bool is_root_isolate);

FML_WARN_UNUSED_RESULT
bool LoadLibraries(bool is_root_isolate);

Expand All @@ -143,8 +128,6 @@ class DartIsolate : public UIDartState {
FML_WARN_UNUSED_RESULT
bool MarkIsolateRunnable();

void OnShutdownCallback();

// |Dart_IsolateCreateCallback|
static Dart_Isolate DartIsolateCreateCallback(
const char* advisory_script_uri,
Expand Down
Loading

0 comments on commit 800ea0a

Please sign in to comment.