Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
dart::RunKernelTask Class Reference
Inheritance diagram for dart::RunKernelTask:
dart::ThreadPool::Task dart::IntrusiveDListEntry< Task >

Public Member Functions

virtual void Run ()
 
- Public Member Functions inherited from dart::ThreadPool::Task
virtual ~Task ()
 
virtual void Run ()=0
 
- Public Member Functions inherited from dart::IntrusiveDListEntry< Task >
 IntrusiveDListEntry ()
 
 ~IntrusiveDListEntry ()
 

Protected Member Functions

bool RunMain (Isolate *I)
 
- Protected Member Functions inherited from dart::ThreadPool::Task
 Task ()
 

Static Protected Member Functions

static void ShutdownIsolate (uword parameter)
 

Detailed Description

Definition at line 52 of file kernel_isolate.cc.

Member Function Documentation

◆ Run()

virtual void dart::RunKernelTask::Run ( )
inlinevirtual

Implements dart::ThreadPool::Task.

Definition at line 54 of file kernel_isolate.cc.

54 {
55 ASSERT(Isolate::Current() == nullptr);
56#ifdef SUPPORT_TIMELINE
57 TimelineBeginEndScope tbes(Timeline::GetVMStream(), "KernelIsolateStartup");
58#endif // SUPPORT_TIMELINE
59 char* error = nullptr;
60 Isolate* isolate = nullptr;
61
62 Dart_IsolateGroupCreateCallback create_group_callback =
64 ASSERT(create_group_callback != nullptr);
65
66 // Note: these flags must match those passed to the VM during
67 // the app-jit training run (see //utils/kernel-service/BUILD.gn).
68 Dart_IsolateFlags api_flags;
69 Isolate::FlagsInitialize(&api_flags);
70 api_flags.enable_asserts = false;
71 api_flags.null_safety = true;
72 api_flags.is_system_isolate = true;
73 api_flags.is_kernel_isolate = true;
74#if !defined(DART_PRECOMPILER)
75 api_flags.use_field_guards = true;
76#endif
77#if !defined(DART_PRECOMPILER)
78 api_flags.use_osr = true;
79#endif
80
81 isolate = reinterpret_cast<Isolate*>(
82 create_group_callback(KernelIsolate::kName, KernelIsolate::kName,
83 nullptr, nullptr, &api_flags, nullptr, &error));
84 if (isolate == nullptr) {
85 if (FLAG_trace_kernel) {
86 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": Isolate creation error: %s\n",
87 error);
88 }
89 free(error);
90 error = nullptr;
93 return;
94 }
95
96 bool got_unwind;
97 {
98 ASSERT(Isolate::Current() == nullptr);
99 StartIsolateScope start_scope(isolate);
100 got_unwind = RunMain(isolate);
101 }
103
104 if (got_unwind) {
105 ShutdownIsolate(reinterpret_cast<uword>(isolate));
106 return;
107 }
108
109 // isolate_ was set as side effect of create callback.
110 ASSERT(isolate->is_kernel_isolate());
111
112 isolate->message_handler()->Run(isolate->group()->thread_pool(), nullptr,
114 reinterpret_cast<uword>(isolate));
115 }
static Isolate * Current()
Definition: isolate.h:986
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
Definition: isolate.cc:1648
static void InitializingFailed()
static void FinishedInitializing()
static Dart_IsolateGroupCreateCallback create_group_callback()
static void SetKernelIsolate(Isolate *isolate)
static const char * kName
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
bool RunMain(Isolate *I)
static void ShutdownIsolate(uword parameter)
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
Definition: dart_api.h:654
#define DART_KERNEL_ISOLATE_NAME
Definition: dart_api.h:3880
#define ASSERT(E)
const uint8_t uint32_t uint32_t GError ** error
uintptr_t uword
Definition: globals.h:501
bool is_kernel_isolate
Definition: dart_api.h:594
bool use_field_guards
Definition: dart_api.h:587
bool is_system_isolate
Definition: dart_api.h:592

◆ RunMain()

bool dart::RunKernelTask::RunMain ( Isolate I)
inlineprotected

Definition at line 154 of file kernel_isolate.cc.

154 {
155 Thread* T = Thread::Current();
156 ASSERT(I == T->isolate());
157 StackZone zone(T);
158 // Invoke main which will return the port to which load requests are sent.
159 const Library& root_library =
160 Library::Handle(Z, I->group()->object_store()->root_library());
161 if (root_library.IsNull()) {
163 ": Embedder did not install a script.");
164 // Kernel isolate is not supported by embedder.
165 return false;
166 }
167 ASSERT(!root_library.IsNull());
168 const String& entry_name = String::Handle(Z, String::New("main"));
169 ASSERT(!entry_name.IsNull());
170 const Function& entry = Function::Handle(
171 Z, root_library.LookupFunctionAllowPrivate(entry_name));
172 if (entry.IsNull()) {
173 // Kernel isolate is not supported by embedder.
175 ": Embedder did not provide a main function.");
176 return false;
177 }
178 ASSERT(!entry.IsNull());
179 const Object& result = Object::Handle(
180 Z, DartEntry::InvokeFunction(entry, Object::empty_array()));
181 ASSERT(!result.IsNull());
182 if (result.IsError()) {
183 // Kernel isolate did not initialize properly.
184 if (FLAG_trace_kernel) {
185 const Error& error = Error::Cast(result);
187 ": Calling main resulted in an error: %s",
188 error.ToErrorCString());
189 }
190 if (result.IsUnwindError()) {
191 return true;
192 }
193 return false;
194 }
195 ASSERT(result.IsReceivePort());
196 const ReceivePort& rp = ReceivePort::Cast(result);
198 return false;
199 }
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
Definition: dart_entry.cc:31
static void SetLoadPort(Dart_Port port)
static Object & Handle()
Definition: object.h:407
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static Thread * Current()
Definition: thread.h:362
GAsyncResult * result
#define Z
#define T
Definition: precompiler.cc:65
Definition: SkMD5.cpp:134

◆ ShutdownIsolate()

static void dart::RunKernelTask::ShutdownIsolate ( uword  parameter)
inlinestaticprotected

Definition at line 118 of file kernel_isolate.cc.

118 {
119 if (FLAG_trace_kernel) {
120 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": ShutdownIsolate\n");
121 }
123 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(parameter));
124 {
125 auto T = Thread::Current();
126 TransitionNativeToVM transition(T);
127 StackZone zone(T);
128 HandleScope handle_scope(T);
129
130 auto I = T->isolate();
131 ASSERT(I->is_kernel_isolate());
132
133 // Print the error if there is one. This may execute dart code to
134 // print the exception object, so we need to use a StartIsolateScope.
135 Error& error = Error::Handle(Z);
136 error = T->sticky_error();
137 if (!error.IsNull() && !error.IsUnwindError()) {
139 error.ToErrorCString());
140 }
141 error = I->sticky_error();
142 if (!error.IsNull() && !error.IsUnwindError()) {
144 error.ToErrorCString());
145 }
146 }
148 if (FLAG_trace_kernel) {
149 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": Shutdown.\n");
150 }
152 }
static void FinishedExiting()
#define ILLEGAL_PORT
Definition: dart_api.h:1535
struct _Dart_Isolate * Dart_Isolate
Definition: dart_api.h:88
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
DART_EXPORT void Dart_ShutdownIsolate()

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