Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
DartVMInitializer Class Reference

#include <dart_vm_initializer.h>

Static Public Member Functions

static void Initialize (Dart_InitializeParams *params, bool enable_timeline_event_handler, bool trace_systrace)
 
static void Cleanup ()
 

Detailed Description

Definition at line 11 of file dart_vm_initializer.h.

Member Function Documentation

◆ Cleanup()

void DartVMInitializer::Cleanup ( )
static

Definition at line 113 of file dart_vm_initializer.cc.

113 {
114 FML_DCHECK(gDartInitialized);
115
116 // Dart_RecordTimelineEvent is unsafe during a concurrent call to Dart_Cleanup
117 // because Dart_Cleanup will destroy the timeline recorder. Clear the
118 // initialized flag so that future calls to LogDartTimelineEvent will not
119 // call Dart_RecordTimelineEvent.
120 //
121 // Note that this is inherently racy. If a thread sees that gDartInitialized
122 // is set and proceeds to call Dart_RecordTimelineEvent shortly before another
123 // thread calls Dart_Cleanup, then the Dart_RecordTimelineEvent call may crash
124 // if Dart_Cleanup deletes the timeline before Dart_RecordTimelineEvent
125 // completes. In practice this is unlikely because Dart_Cleanup does
126 // significant other work before deleting the timeline.
127 //
128 // The engine can not safely guard Dart_Cleanup and LogDartTimelineEvent with
129 // a lock due to the risk of deadlocks. Dart_Cleanup waits for various
130 // Dart-owned threads to shut down. If one of those threads invokes an engine
131 // callback that calls LogDartTimelineEvent while the Dart_Cleanup thread owns
132 // the lock, then Dart_Cleanup would deadlock.
133 gDartInitialized = false;
134
135 char* error = Dart_Cleanup();
136 if (error) {
137 FML_LOG(FATAL) << "Error while cleaning up the Dart VM: " << error;
138 ::free(error);
139 }
140}
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_Cleanup(void)
#define FATAL(error)
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ Initialize()

void DartVMInitializer::Initialize ( Dart_InitializeParams params,
bool  enable_timeline_event_handler,
bool  trace_systrace 
)
static

Definition at line 82 of file dart_vm_initializer.cc.

84 {
85 FML_DCHECK(!gDartInitialized);
86
88 if (error) {
89 FML_LOG(FATAL) << "Error while initializing the Dart VM: " << error;
90 ::free(error);
91 } else {
92 gDartInitialized = true;
93 }
94
95 if (enable_timeline_event_handler) {
96 if (!trace_systrace) {
97 // Systrace on all platforms except Fuchsia ignores the timestamp provided
98 // here. On Android in particular, calls to get the system clock show up
99 // in profiles.
100 // Fuchsia does not use the TraceSetTimelineMicrosSource.
102 } else {
104 []() -> int64_t { return -1; });
105 }
106 fml::tracing::TraceSetTimelineEventHandler(LogDartTimelineEvent);
107 }
108
110 tonic::SetUnhandledExceptionReporter(&ReportUnhandledException);
111}
static void SetClockSource(ClockSource source)
Definition: time_point.cc:45
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_Initialize(Dart_InitializeParams *params)
DART_EXPORT int64_t Dart_TimelineGetMicros()
const EmbeddedViewParams * params
fml::TimePoint DartTimelineTicksSinceEpoch()
void TraceSetTimelineEventHandler(TimelineEventHandler handler)
Definition: trace_event.cc:373
void TraceSetTimelineMicrosSource(TimelineMicrosSource source)
Definition: trace_event.cc:383
void SetUnhandledExceptionReporter(DartError::UnhandledExceptionReporter reporter)
Definition: dart_error.cc:28

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