OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/kernel_isolate.h" | 5 #include "vm/kernel_isolate.h" |
6 | 6 |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 KernelIsolate::FinishedInitializing(); | 67 KernelIsolate::FinishedInitializing(); |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 Dart_IsolateFlags api_flags; | 71 Dart_IsolateFlags api_flags; |
72 Isolate::FlagsInitialize(&api_flags); | 72 Isolate::FlagsInitialize(&api_flags); |
73 | 73 |
74 isolate = reinterpret_cast<Isolate*>(create_callback( | 74 isolate = reinterpret_cast<Isolate*>(create_callback( |
75 KernelIsolate::kName, NULL, NULL, NULL, &api_flags, NULL, &error)); | 75 KernelIsolate::kName, NULL, NULL, NULL, &api_flags, NULL, &error)); |
76 if (isolate == NULL) { | 76 if (isolate == NULL) { |
77 if (FLAG_trace_kernel) { | 77 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": Isolate creation error: %s\n", |
78 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": Isolate creation error: %s\n", | 78 error); |
79 error); | |
80 } | |
81 KernelIsolate::SetKernelIsolate(NULL); | 79 KernelIsolate::SetKernelIsolate(NULL); |
82 KernelIsolate::FinishedInitializing(); | 80 KernelIsolate::FinishedInitializing(); |
83 return; | 81 return; |
84 } | 82 } |
85 | 83 |
86 bool init_success = false; | 84 bool init_success = false; |
87 { | 85 { |
88 ASSERT(Isolate::Current() == NULL); | 86 ASSERT(Isolate::Current() == NULL); |
89 StartIsolateScope start_scope(isolate); | 87 StartIsolateScope start_scope(isolate); |
90 init_success = RunMain(isolate); | 88 init_success = RunMain(isolate); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 142 |
145 bool RunMain(Isolate* I) { | 143 bool RunMain(Isolate* I) { |
146 Thread* T = Thread::Current(); | 144 Thread* T = Thread::Current(); |
147 ASSERT(I == T->isolate()); | 145 ASSERT(I == T->isolate()); |
148 StackZone zone(T); | 146 StackZone zone(T); |
149 HANDLESCOPE(T); | 147 HANDLESCOPE(T); |
150 // Invoke main which will return the port to which load requests are sent. | 148 // Invoke main which will return the port to which load requests are sent. |
151 const Library& root_library = | 149 const Library& root_library = |
152 Library::Handle(Z, I->object_store()->root_library()); | 150 Library::Handle(Z, I->object_store()->root_library()); |
153 if (root_library.IsNull()) { | 151 if (root_library.IsNull()) { |
154 if (FLAG_trace_kernel) { | 152 OS::Print(DART_KERNEL_ISOLATE_NAME |
155 OS::Print(DART_KERNEL_ISOLATE_NAME | 153 ": Embedder did not install a script."); |
156 ": Embedder did not install a script."); | |
157 } | |
158 // Kernel isolate is not supported by embedder. | 154 // Kernel isolate is not supported by embedder. |
159 return false; | 155 return false; |
160 } | 156 } |
161 ASSERT(!root_library.IsNull()); | 157 ASSERT(!root_library.IsNull()); |
162 const String& entry_name = String::Handle(Z, String::New("main")); | 158 const String& entry_name = String::Handle(Z, String::New("main")); |
163 ASSERT(!entry_name.IsNull()); | 159 ASSERT(!entry_name.IsNull()); |
164 const Function& entry = Function::Handle( | 160 const Function& entry = Function::Handle( |
165 Z, root_library.LookupFunctionAllowPrivate(entry_name)); | 161 Z, root_library.LookupFunctionAllowPrivate(entry_name)); |
166 if (entry.IsNull()) { | 162 if (entry.IsNull()) { |
167 // Kernel isolate is not supported by embedder. | 163 // Kernel isolate is not supported by embedder. |
168 if (FLAG_trace_kernel) { | 164 OS::Print(DART_KERNEL_ISOLATE_NAME |
169 OS::Print(DART_KERNEL_ISOLATE_NAME | 165 ": Embedder did not provide a main function."); |
170 ": Embedder did not provide a main function."); | |
171 } | |
172 return false; | 166 return false; |
173 } | 167 } |
174 ASSERT(!entry.IsNull()); | 168 ASSERT(!entry.IsNull()); |
175 const Object& result = Object::Handle( | 169 const Object& result = Object::Handle( |
176 Z, DartEntry::InvokeFunction(entry, Object::empty_array())); | 170 Z, DartEntry::InvokeFunction(entry, Object::empty_array())); |
177 ASSERT(!result.IsNull()); | 171 ASSERT(!result.IsNull()); |
178 if (result.IsError()) { | 172 if (result.IsError()) { |
179 // Kernel isolate did not initialize properly. | 173 // Kernel isolate did not initialize properly. |
180 if (FLAG_trace_kernel) { | 174 const Error& error = Error::Cast(result); |
181 const Error& error = Error::Cast(result); | 175 OS::Print(DART_KERNEL_ISOLATE_NAME |
182 OS::Print(DART_KERNEL_ISOLATE_NAME | 176 ": Calling main resulted in an error: %s", |
183 ": Calling main resulted in an error: %s", | 177 error.ToErrorCString()); |
184 error.ToErrorCString()); | |
185 } | |
186 return false; | 178 return false; |
187 } | 179 } |
188 ASSERT(result.IsReceivePort()); | 180 ASSERT(result.IsReceivePort()); |
189 const ReceivePort& rp = ReceivePort::Cast(result); | 181 const ReceivePort& rp = ReceivePort::Cast(result); |
190 KernelIsolate::SetLoadPort(rp.Id()); | 182 KernelIsolate::SetLoadPort(rp.Id()); |
191 return true; | 183 return true; |
192 } | 184 } |
193 }; | 185 }; |
194 | 186 |
195 | 187 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 433 } |
442 | 434 |
443 KernelCompilationRequest request; | 435 KernelCompilationRequest request; |
444 return request.SendAndWaitForResponse(kernel_port, script_uri); | 436 return request.SendAndWaitForResponse(kernel_port, script_uri); |
445 } | 437 } |
446 | 438 |
447 | 439 |
448 #endif // DART_PRECOMPILED_RUNTIME | 440 #endif // DART_PRECOMPILED_RUNTIME |
449 | 441 |
450 } // namespace dart | 442 } // namespace dart |
OLD | NEW |