Flutter Engine
 
Loading...
Searching...
No Matches
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 112 of file dart_vm_initializer.cc.

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

References error, FML_DCHECK, and FML_LOG.

Referenced by flutter::DartVM::~DartVM().

◆ Initialize()

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

Definition at line 81 of file dart_vm_initializer.cc.

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

References flutter::DartTimelineTicksSinceEpoch(), error, FML_DCHECK, FML_LOG, params, fml::TimePoint::SetClockSource(), tonic::SetUnhandledExceptionReporter(), fml::tracing::TraceSetTimelineEventHandler(), and fml::tracing::TraceSetTimelineMicrosSource().


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