Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
flutter::DartVMRef Class Reference

#include <dart_vm_lifecycle.h>

Public Member Functions

 DartVMRef (const DartVMRef &)=default
 
 DartVMRef (DartVMRef &&)
 
 ~DartVMRef ()
 
 operator bool () const
 
DartVMget ()
 
const DartVMget () const
 
DartVMoperator-> ()
 
const DartVMoperator-> () const
 
DartVMoperator& ()
 

Static Public Member Functions

static DartVMRef Create (const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
 
static bool IsInstanceRunning ()
 
static std::shared_ptr< const DartVMDataGetVMData ()
 
static std::shared_ptr< ServiceProtocolGetServiceProtocol ()
 
static std::shared_ptr< IsolateNameServerGetIsolateNameServer ()
 

Friends

class DartIsolate
 

Detailed Description

Definition at line 28 of file dart_vm_lifecycle.h.

Constructor & Destructor Documentation

◆ DartVMRef() [1/2]

flutter::DartVMRef::DartVMRef ( const DartVMRef )
default

◆ DartVMRef() [2/2]

flutter::DartVMRef::DartVMRef ( DartVMRef &&  )
default

◆ ~DartVMRef()

flutter::DartVMRef::~DartVMRef ( )

Definition at line 33 of file dart_vm_lifecycle.cc.

33 {
34 if (!vm_) {
35 // If there is no valid VM (possible via a move), there is no way that the
36 // decrement on the shared pointer can cause a collection. Avoid acquiring
37 // the lifecycle lock in this case. This is just working around a
38 // pessimization and not required for correctness.
39 return;
40 }
41 std::scoped_lock lifecycle_lock(gVMMutex);
42 vm_.reset();
43}
static std::mutex gVMMutex

Member Function Documentation

◆ Create()

DartVMRef flutter::DartVMRef::Create ( const Settings settings,
fml::RefPtr< const DartSnapshot vm_snapshot = nullptr,
fml::RefPtr< const DartSnapshot isolate_snapshot = nullptr 
)
static

Definition at line 45 of file dart_vm_lifecycle.cc.

47 {
48 std::scoped_lock lifecycle_lock(gVMMutex);
49
50 if (!settings.leak_vm) {
52 << "Launch settings indicated that the VM should shut down in the "
53 "process when done but a previous launch asked the VM to leak in "
54 "the same process. For proper VM shutdown, all VM launches must "
55 "indicate that they should shut down when done.";
56 }
57
58 // If there is already a running VM in the process, grab a strong reference to
59 // it.
60 if (auto vm = gVM.lock()) {
61 FML_DLOG(WARNING) << "Attempted to create a VM in a process where one was "
62 "already running. Ignoring arguments for current VM "
63 "create call and reusing the old VM.";
64 // There was already a running VM in the process,
65 return DartVMRef{std::move(vm)};
66 }
67
68 std::scoped_lock dependents_lock(gVMDependentsMutex);
69
70 gVMData.reset();
71 gVMServiceProtocol.reset();
73 gVM.reset();
74
75 // If there is no VM in the process. Initialize one, hold the weak reference
76 // and pass a strong reference to the caller.
77 auto isolate_name_server = std::make_shared<IsolateNameServer>();
78 auto vm = DartVM::Create(settings, //
79 std::move(vm_snapshot), //
80 std::move(isolate_snapshot), //
81 isolate_name_server //
82 );
83
84 if (!vm) {
85 FML_LOG(ERROR) << "Could not create Dart VM instance.";
86 return DartVMRef{nullptr};
87 }
88
89 gVMData = vm->GetVMData();
90 gVMServiceProtocol = vm->GetServiceProtocol();
91 gVMIsolateNameServer = isolate_name_server;
92 gVM = vm;
93
94 if (settings.leak_vm) {
95 gVMLeak = new std::shared_ptr<DartVM>(vm);
96 }
97
98 return DartVMRef{std::move(vm)};
99}
DartVMRef(const DartVMRef &)=default
#define FML_DLOG(severity)
Definition logging.h:102
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
static std::weak_ptr< IsolateNameServer > gVMIsolateNameServer
static std::weak_ptr< ServiceProtocol > gVMServiceProtocol
static std::mutex gVMDependentsMutex
static std::weak_ptr< DartVM > gVM
static std::weak_ptr< const DartVMData > gVMData
static std::shared_ptr< DartVM > * gVMLeak
#define ERROR(message)

◆ get() [1/2]

DartVM * flutter::DartVMRef::get ( )
inline

Definition at line 54 of file dart_vm_lifecycle.h.

54 {
55 FML_DCHECK(vm_);
56 return vm_.get();
57 }
#define FML_DCHECK(condition)
Definition logging.h:103

◆ get() [2/2]

const DartVM * flutter::DartVMRef::get ( ) const
inline

Definition at line 59 of file dart_vm_lifecycle.h.

59 {
60 FML_DCHECK(vm_);
61 return vm_.get();
62 }

◆ GetIsolateNameServer()

std::shared_ptr< IsolateNameServer > flutter::DartVMRef::GetIsolateNameServer ( )
static

Definition at line 116 of file dart_vm_lifecycle.cc.

116 {
117 std::scoped_lock lock(gVMDependentsMutex);
118 return gVMIsolateNameServer.lock();
119}

◆ GetServiceProtocol()

std::shared_ptr< ServiceProtocol > flutter::DartVMRef::GetServiceProtocol ( )
static

Definition at line 111 of file dart_vm_lifecycle.cc.

111 {
112 std::scoped_lock lock(gVMDependentsMutex);
113 return gVMServiceProtocol.lock();
114}

◆ GetVMData()

std::shared_ptr< const DartVMData > flutter::DartVMRef::GetVMData ( )
static

Definition at line 106 of file dart_vm_lifecycle.cc.

106 {
107 std::scoped_lock lock(gVMDependentsMutex);
108 return gVMData.lock();
109}

◆ IsInstanceRunning()

bool flutter::DartVMRef::IsInstanceRunning ( )
static

Definition at line 101 of file dart_vm_lifecycle.cc.

101 {
102 std::scoped_lock lock(gVMMutex);
103 return !gVM.expired();
104}

◆ operator bool()

flutter::DartVMRef::operator bool ( ) const
inlineexplicit

Definition at line 52 of file dart_vm_lifecycle.h.

52{ return static_cast<bool>(vm_); }

◆ operator&()

DartVM * flutter::DartVMRef::operator& ( )
inline

Definition at line 75 of file dart_vm_lifecycle.h.

75 {
76 FML_DCHECK(vm_);
77 return vm_.get();
78 }

◆ operator->() [1/2]

DartVM * flutter::DartVMRef::operator-> ( )
inline

Definition at line 64 of file dart_vm_lifecycle.h.

64 {
65 FML_DCHECK(vm_);
66 return vm_.get();
67 }

◆ operator->() [2/2]

const DartVM * flutter::DartVMRef::operator-> ( ) const
inline

Definition at line 69 of file dart_vm_lifecycle.h.

69 {
70 FML_DCHECK(vm_);
71 return vm_.get();
72 }

Friends And Related Symbol Documentation

◆ DartIsolate

friend class DartIsolate
friend

Definition at line 81 of file dart_vm_lifecycle.h.


The documentation for this class was generated from the following files: