mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
The shell was already designed to cleanly shut down the VM but it couldnt earlier as |Dart_Initialize| could never be called after a |Dart_Cleanup|. This meant that shutting down an engine instance could not shut down the VM to save memory because newly created engines in the process after that point couldn't restart the VM. There can only be one VM running in a process at a time. This patch separate the previous DartVM object into one that references a running instance of the DartVM and a set of immutable dependencies that components can reference even as the VM is shutting down. Unit tests have been added to assert that non-overlapping engine launches use difference VM instances.
69 lines
2.0 KiB
C++
69 lines
2.0 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_VM_H_
|
|
#define FLUTTER_RUNTIME_DART_VM_H_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "flutter/common/settings.h"
|
|
#include "flutter/fml/build_config.h"
|
|
#include "flutter/fml/closure.h"
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/fml/memory/ref_counted.h"
|
|
#include "flutter/fml/memory/ref_ptr.h"
|
|
#include "flutter/fml/memory/weak_ptr.h"
|
|
#include "flutter/lib/ui/isolate_name_server/isolate_name_server.h"
|
|
#include "flutter/runtime/dart_isolate.h"
|
|
#include "flutter/runtime/dart_snapshot.h"
|
|
#include "flutter/runtime/dart_vm_data.h"
|
|
#include "flutter/runtime/service_protocol.h"
|
|
#include "third_party/dart/runtime/include/dart_api.h"
|
|
|
|
namespace blink {
|
|
|
|
class DartVM {
|
|
public:
|
|
~DartVM();
|
|
|
|
static bool IsRunningPrecompiledCode();
|
|
|
|
static bool IsKernelMapping(const fml::FileMapping* mapping);
|
|
|
|
static size_t GetVMLaunchCount();
|
|
|
|
const Settings& GetSettings() const;
|
|
|
|
std::shared_ptr<const DartVMData> GetVMData() const;
|
|
|
|
std::shared_ptr<ServiceProtocol> GetServiceProtocol() const;
|
|
|
|
std::shared_ptr<IsolateNameServer> GetIsolateNameServer() const;
|
|
|
|
private:
|
|
const Settings settings_;
|
|
std::shared_ptr<const DartVMData> vm_data_;
|
|
const std::shared_ptr<IsolateNameServer> isolate_name_server_;
|
|
const std::shared_ptr<ServiceProtocol> service_protocol_;
|
|
|
|
friend class DartVMRef;
|
|
|
|
static std::shared_ptr<DartVM> Create(
|
|
Settings settings,
|
|
fml::RefPtr<DartSnapshot> vm_snapshot,
|
|
fml::RefPtr<DartSnapshot> isolate_snapshot,
|
|
fml::RefPtr<DartSnapshot> shared_snapshot,
|
|
std::shared_ptr<IsolateNameServer> isolate_name_server);
|
|
|
|
DartVM(std::shared_ptr<const DartVMData> data,
|
|
std::shared_ptr<IsolateNameServer> isolate_name_server);
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(DartVM);
|
|
};
|
|
|
|
} // namespace blink
|
|
|
|
#endif // FLUTTER_RUNTIME_DART_VM_H_
|