Flutter Engine
The Flutter Engine
dart.h
Go to the documentation of this file.
1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_DART_H_
6#define RUNTIME_VM_DART_H_
7
8#include "include/dart_api.h"
10#include "vm/allocation.h"
11#include "vm/isolate.h"
12#include "vm/lockers.h"
13#include "vm/os_thread.h"
14#include "vm/snapshot.h"
15
16namespace dart {
17
18// Forward declarations.
19class DebugInfo;
20class Isolate;
21class LocalHandle;
22class ReadOnlyHandles;
23class ThreadPool;
24namespace kernel {
25class Program;
26}
27
28class Dart : public AllStatic {
29 public:
30 // Returns null if initialization succeeds, otherwise returns an error message
31 // (caller owns error message and has to free it).
32 static char* Init(const Dart_InitializeParams* params);
33
34 // Returns null if cleanup succeeds, otherwise returns an error message
35 // (caller owns error message and has to free it).
36 static char* Cleanup();
37
38 // Returns true if the VM is initialized.
39 static bool IsInitialized();
40
41 // Used to Indicate that a Dart API call is active.
42 static bool SetActiveApiCall();
43 static void ResetActiveApiCall();
44
45 static Isolate* CreateIsolate(const char* name_prefix,
46 const Dart_IsolateFlags& api_flags,
47 IsolateGroup* isolate_group);
48
49 // Initialize an isolate group either from a snapshot or from a Kernel binary.
50 static ErrorPtr InitializeIsolateGroup(Thread* T,
51 const uint8_t* snapshot_data,
52 const uint8_t* snapshot_instructions,
53 const uint8_t* kernel_buffer,
54 intptr_t kernel_buffer_size);
55 static ErrorPtr InitIsolateGroupFromSnapshot(
56 Thread* T,
57 const uint8_t* snapshot_data,
58 const uint8_t* snapshot_instructions,
59 const uint8_t* kernel_buffer,
60 intptr_t kernel_buffer_size);
61 static ErrorPtr InitializeIsolate(Thread* T,
62 bool is_first_isolate_in_group,
63 void* isolate_data);
64
65 static void RunShutdownCallback();
66 static void ShutdownIsolate(Thread* T);
67
68 static Isolate* vm_isolate() { return vm_isolate_; }
70 if (vm_isolate_ == nullptr) return nullptr;
71 return vm_isolate_->group();
72 }
73 static ThreadPool* thread_pool() { return thread_pool_; }
74
75 static int64_t UptimeMicros();
76 static int64_t UptimeMillis() {
78 }
79
80 static void set_pprof_symbol_generator(DebugInfo* value) {
81 pprof_symbol_generator_ = value;
82 }
83 static DebugInfo* pprof_symbol_generator() { return pprof_symbol_generator_; }
84
86 static bool IsReadOnlyApiHandle(Dart_Handle handle);
87
89 static bool IsReadOnlyHandle(uword address);
90
91 // The returned string has to be free()ed.
92 static char* FeaturesString(IsolateGroup* isolate_group,
93 bool is_vm_snapshot,
94 Snapshot::Kind kind);
95 static Snapshot::Kind vm_snapshot_kind() { return vm_snapshot_kind_; }
96
98 return thread_start_callback_;
99 }
101 thread_start_callback_ = cback;
102 }
104 return thread_exit_callback_;
105 }
107 thread_exit_callback_ = cback;
108 }
110 Dart_FileReadCallback file_read,
111 Dart_FileWriteCallback file_write,
112 Dart_FileCloseCallback file_close) {
113 file_open_callback_ = file_open;
114 file_read_callback_ = file_read;
115 file_write_callback_ = file_write;
116 file_close_callback_ = file_close;
117 }
118
120 return file_open_callback_;
121 }
123 return file_read_callback_;
124 }
126 return file_write_callback_;
127 }
129 return file_close_callback_;
130 }
131
133 entropy_source_callback_ = entropy_source;
134 }
136 return entropy_source_callback_;
137 }
138
141 dwarf_stacktrace_footnote_callback_ = cb;
142 }
143
146 return dwarf_stacktrace_footnote_callback_;
147 }
148
149 private:
150 static char* DartInit(const Dart_InitializeParams* params);
151
152 static constexpr const char* kVmIsolateName = "vm-isolate";
153
154 static void WaitForIsolateShutdown();
155 static void WaitForApplicationIsolateShutdown();
156
157 static Isolate* vm_isolate_;
158 static int64_t start_time_micros_;
159 static ThreadPool* thread_pool_;
160 static DebugInfo* pprof_symbol_generator_;
161 static ReadOnlyHandles* predefined_handles_;
162 static Snapshot::Kind vm_snapshot_kind_;
163 static Dart_ThreadStartCallback thread_start_callback_;
164 static Dart_ThreadExitCallback thread_exit_callback_;
165 static Dart_FileOpenCallback file_open_callback_;
166 static Dart_FileReadCallback file_read_callback_;
167 static Dart_FileWriteCallback file_write_callback_;
168 static Dart_FileCloseCallback file_close_callback_;
169 static Dart_EntropySource entropy_source_callback_;
171 dwarf_stacktrace_footnote_callback_;
172};
173
174} // namespace dart
175
176#endif // RUNTIME_VM_DART_H_
static ErrorPtr InitializeIsolateGroup(Thread *T, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition: dart.cc:908
static ThreadPool * thread_pool()
Definition: dart.h:73
static bool IsReadOnlyHandle(uword address)
Definition: dart.cc:1147
static char * Cleanup()
Definition: dart.cc:629
static Dart_FileWriteCallback file_write_callback()
Definition: dart.h:125
static void set_thread_start_callback(Dart_ThreadStartCallback cback)
Definition: dart.h:100
static Dart_FileReadCallback file_read_callback()
Definition: dart.h:122
static bool IsInitialized()
Definition: dart.cc:799
static void ShutdownIsolate(Thread *T)
Definition: dart.cc:1123
static IsolateGroup * vm_isolate_group()
Definition: dart.h:69
static Dart_FileOpenCallback file_open_callback()
Definition: dart.h:119
static Dart_EntropySource entropy_source_callback()
Definition: dart.h:135
static void set_entropy_source_callback(Dart_EntropySource entropy_source)
Definition: dart.h:132
static bool SetActiveApiCall()
Definition: dart.cc:803
static int64_t UptimeMillis()
Definition: dart.h:76
static Dart_DwarfStackTraceFootnoteCallback dwarf_stacktrace_footnote_callback()
Definition: dart.h:145
static DebugInfo * pprof_symbol_generator()
Definition: dart.h:83
static Dart_ThreadStartCallback thread_start_callback()
Definition: dart.h:97
static Isolate * vm_isolate()
Definition: dart.h:68
static char * Init(const Dart_InitializeParams *params)
Definition: dart.cc:526
static void SetFileCallbacks(Dart_FileOpenCallback file_open, Dart_FileReadCallback file_read, Dart_FileWriteCallback file_write, Dart_FileCloseCallback file_close)
Definition: dart.h:109
static int64_t UptimeMicros()
Definition: dart.cc:1127
static Dart_ThreadExitCallback thread_exit_callback()
Definition: dart.h:103
static char * FeaturesString(IsolateGroup *isolate_group, bool is_vm_snapshot, Snapshot::Kind kind)
Definition: dart.cc:1004
static Isolate * CreateIsolate(const char *name_prefix, const Dart_IsolateFlags &api_flags, IsolateGroup *isolate_group)
Definition: dart.cc:811
static bool IsReadOnlyApiHandle(Dart_Handle handle)
Definition: dart.cc:1152
static uword AllocateReadOnlyHandle()
Definition: dart.cc:1131
static void ResetActiveApiCall()
Definition: dart.cc:807
static Snapshot::Kind vm_snapshot_kind()
Definition: dart.h:95
static void RunShutdownCallback()
Definition: dart.cc:1110
static LocalHandle * AllocateReadOnlyApiHandle()
Definition: dart.cc:1141
static ErrorPtr InitializeIsolate(Thread *T, bool is_first_isolate_in_group, void *isolate_data)
Definition: dart.cc:950
static void set_thread_exit_callback(Dart_ThreadExitCallback cback)
Definition: dart.h:106
static Dart_FileCloseCallback file_close_callback()
Definition: dart.h:128
static void set_pprof_symbol_generator(DebugInfo *value)
Definition: dart.h:80
static ErrorPtr InitIsolateGroupFromSnapshot(Thread *T, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition: dart.cc:820
static void set_dwarf_stacktrace_footnote_callback(Dart_DwarfStackTraceFootnoteCallback cb)
Definition: dart.h:139
IsolateGroup * group() const
Definition: isolate.h:1037
void(* Dart_FileWriteCallback)(const void *data, intptr_t length, void *stream)
Definition: dart_api.h:807
void(* Dart_FileCloseCallback)(void *stream)
Definition: dart_api.h:820
void(* Dart_FileReadCallback)(uint8_t **data, intptr_t *file_length, void *stream)
Definition: dart_api.h:792
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
bool(* Dart_EntropySource)(uint8_t *buffer, intptr_t length)
Definition: dart_api.h:822
void(* Dart_ThreadStartCallback)(void)
Definition: dart_api.h:754
void *(* Dart_FileOpenCallback)(const char *name, bool write)
Definition: dart_api.h:776
void(* Dart_ThreadExitCallback)(void)
Definition: dart_api.h:763
char *(* Dart_DwarfStackTraceFootnoteCallback)(void *addresses[], intptr_t count)
Definition: dart_api.h:4145
const EmbeddedViewParams * params
uint8_t value
Definition: dart_vm.cc:33
constexpr intptr_t kMicrosecondsPerMillisecond
Definition: globals.h:561
uintptr_t uword
Definition: globals.h:501
#define T
Definition: precompiler.cc:65