flutter_flutter/runtime/dart_isolate.h
Siva b3bb39b0b1
Roll src/third_party/dart 06c3d7ad3a...09fc76bc51 (#9728)
* Roll src/third_party/dart 06c3d7ad3a...09fc76bc51

dart-lang/sdk@09fc76bc51 [vm, compiler] Remove dead _classRangeCheckNegative.
dart-lang/sdk@b472d7a9be Unnecessary null aware spread hint
dart-lang/sdk@f939ad3964 library scope extensions
dart-lang/sdk@9503969664 [vm/bytecode] Add DebugCheck bytecode instruction
dart-lang/sdk@fc542be6b4 Issue 36682. Check that selection offset/length is valid in Extract Method refactoring.
dart-lang/sdk@803658a6d8 [corelib_2] fix bigint_from_test for web platforms
dart-lang/sdk@ad6b1ebbd6 Support for 'double' fields in protocol.
dart-lang/sdk@5479175012 Remove incorrect test.
dart-lang/sdk@058092b5f6 [vm] Fix simarm_x64 build on mac
dart-lang/sdk@307ca3f3b6 [vm/bytecode] Improve single stepping and breakpoint setting in bytecode.
dart-lang/sdk@855830f324 Update LSP spec
dart-lang/sdk@d992f55094 [dartfix] Bump pedantic dep to v1.8.0 and cleanup lint violations
dart-lang/sdk@41330f3e34 gitignore .clangd
dart-lang/sdk@8d07009931 [ VM / Gardening ] Mark disassemble_determinism_test as slow on Windows
dart-lang/sdk@1b82367ed6 Update CHANGELOG to reflect breaking change #36765
dart-lang/sdk@a86db84e0a [fasta] Preserve information about const constructors in outline.
dart-lang/sdk@25319ef7a6 Fix bug in codegen/string_escapes_test.dart.
dart-lang/sdk@7acecda2cc [vm/ffi] Fix FFI Utf8 example.
dart-lang/sdk@e3b3c6fa28 [vm] Rename 3head flutter patch after re-land of concurrency change
dart-lang/sdk@2cb5303782 [infra] Update checked in SDKs to 2.4.0
dart-lang/sdk@fce43ebc4e [ddk] Pass environmentDefines to CFE through CompilerOptions
dart-lang/sdk@5450d08ca1 Add support for analyzer static error tests.
dart-lang/sdk@0425997b31 Second attempt to reland "[vm/concurrency] Introduce concept of Isolate Groups"
dart-lang/sdk@5470159054 [vm, gc] Produce a proper error message when crashing due to lack of memory at isolate startup.
dart-lang/sdk@bfc7d21da6 Remove useless dart2js_extra/class_test
dart-lang/sdk@572619b639 [vm, bytecode] Fix vm/cc/CompileFunctionOnHelperThread.
dart-lang/sdk@4de495fccc [vm, compiler] Remove dead stub ICCallThroughFunction.
dart-lang/sdk@8a1dcdae68 Graduate 'flutter' domain from experimental, remove unused methods and fields.
dart-lang/sdk@a945888627 Discard constructors and fields temporarily to get valid code compiling

* Fix analyzer warning.
2019-07-09 16:12:06 -07:00

204 lines
6.4 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_DART_ISOLATE_H_
#define FLUTTER_RUNTIME_DART_ISOLATE_H_
#include <memory>
#include <set>
#include <string>
#include "flutter/common/task_runners.h"
#include "flutter/fml/compiler_specific.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/lib/ui/io_manager.h"
#include "flutter/lib/ui/snapshot_delegate.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/runtime/dart_snapshot.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/dart_state.h"
namespace flutter {
class DartVM;
class DartIsolate : public UIDartState {
public:
enum class Phase {
Unknown,
Uninitialized,
Initialized,
LibrariesSetup,
Ready,
Running,
Shutdown,
};
using ChildIsolatePreparer = std::function<bool(DartIsolate*)>;
// The root isolate of a Flutter application is special because it gets Window
// bindings. From the VM's perspective, this isolate is not special in any
// way.
static std::weak_ptr<DartIsolate> CreateRootIsolate(
const Settings& settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
fml::RefPtr<const DartSnapshot> shared_snapshot,
TaskRunners task_runners,
std::unique_ptr<Window> window,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<IOManager> io_manager,
fml::WeakPtr<ImageDecoder> image_decoder,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
Dart_IsolateFlags* flags,
fml::closure isolate_create_callback,
fml::closure isolate_shutdown_callback);
DartIsolate(const Settings& settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
fml::RefPtr<const DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<IOManager> io_manager,
fml::WeakPtr<ImageDecoder> image_decoder,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
ChildIsolatePreparer child_isolate_preparer,
fml::closure isolate_create_callback,
fml::closure isolate_shutdown_callback);
~DartIsolate() override;
const Settings& GetSettings() const;
Phase GetPhase() const;
std::string GetServiceId();
FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromPrecompiledCode();
FML_WARN_UNUSED_RESULT
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,
const std::vector<std::string>& args,
fml::closure on_run = nullptr);
FML_WARN_UNUSED_RESULT
bool RunFromLibrary(const std::string& library_name,
const std::string& entrypoint,
const std::vector<std::string>& args,
fml::closure on_run = nullptr);
FML_WARN_UNUSED_RESULT
bool Shutdown();
void AddIsolateShutdownCallback(fml::closure closure);
fml::RefPtr<const DartSnapshot> GetIsolateSnapshot() const;
fml::RefPtr<const DartSnapshot> GetSharedSnapshot() const;
std::weak_ptr<DartIsolate> GetWeakIsolatePtr();
fml::RefPtr<fml::TaskRunner> GetMessageHandlingTaskRunner() const;
private:
bool LoadKernel(std::shared_ptr<const fml::Mapping> mapping, bool last_piece);
class AutoFireClosure {
public:
AutoFireClosure(fml::closure closure);
~AutoFireClosure();
private:
fml::closure closure_;
FML_DISALLOW_COPY_AND_ASSIGN(AutoFireClosure);
};
friend class DartVM;
Phase phase_ = Phase::Unknown;
const Settings settings_;
const fml::RefPtr<const DartSnapshot> isolate_snapshot_;
const fml::RefPtr<const DartSnapshot> shared_snapshot_;
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_;
const fml::closure isolate_create_callback_;
const fml::closure isolate_shutdown_callback_;
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);
bool UpdateThreadPoolNames() const;
FML_WARN_UNUSED_RESULT
bool MarkIsolateRunnable();
void OnShutdownCallback();
// |Dart_IsolateGroupCreateCallback|
static Dart_Isolate DartIsolateGroupCreateCallback(
const char* advisory_script_uri,
const char* advisory_script_entrypoint,
const char* package_root,
const char* package_config,
Dart_IsolateFlags* flags,
std::shared_ptr<DartIsolate>* embedder_isolate,
char** error);
static Dart_Isolate DartCreateAndStartServiceIsolate(
const char* package_root,
const char* package_config,
Dart_IsolateFlags* flags,
char** error);
static std::pair<Dart_Isolate /* vm */,
std::weak_ptr<DartIsolate> /* embedder */>
CreateDartVMAndEmbedderObjectPair(
const char* advisory_script_uri,
const char* advisory_script_entrypoint,
const char* package_root,
const char* package_config,
Dart_IsolateFlags* flags,
std::shared_ptr<DartIsolate>* parent_embedder_isolate,
bool is_root_isolate,
char** error);
// |Dart_IsolateShutdownCallback|
static void DartIsolateShutdownCallback(
std::shared_ptr<DartIsolate>* isolate_group_data,
std::shared_ptr<DartIsolate>* isolate_data);
// |Dart_IsolateGroupCleanupCallback|
static void DartIsolateGroupCleanupCallback(
std::shared_ptr<DartIsolate>* isolate_group_data);
FML_DISALLOW_COPY_AND_ASSIGN(DartIsolate);
};
} // namespace flutter
#endif // FLUTTER_RUNTIME_DART_ISOLATE_H_