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 "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "vm/timeline.h" | 24 #include "vm/timeline.h" |
25 | 25 |
26 namespace dart { | 26 namespace dart { |
27 | 27 |
28 #if !defined(DART_PRECOMPILED_RUNTIME) | 28 #if !defined(DART_PRECOMPILED_RUNTIME) |
29 | 29 |
30 #define Z (T->zone()) | 30 #define Z (T->zone()) |
31 | 31 |
32 DEFINE_FLAG(bool, trace_kernel, false, "Trace Kernel service requests."); | 32 DEFINE_FLAG(bool, trace_kernel, false, "Trace Kernel service requests."); |
33 DEFINE_FLAG(bool, | 33 DEFINE_FLAG(bool, |
34 use_dart_frontend, | |
35 false, | |
36 "Parse scripts with Dart-to-Kernel parser"); | |
37 DEFINE_FLAG(bool, | |
38 show_kernel_isolate, | 34 show_kernel_isolate, |
39 false, | 35 false, |
40 "Show Kernel service isolate as normal isolate."); | 36 "Show Kernel service isolate as normal isolate."); |
41 | 37 |
42 const char* KernelIsolate::kName = DART_KERNEL_ISOLATE_NAME; | 38 const char* KernelIsolate::kName = DART_KERNEL_ISOLATE_NAME; |
43 Dart_IsolateCreateCallback KernelIsolate::create_callback_ = NULL; | 39 Dart_IsolateCreateCallback KernelIsolate::create_callback_ = NULL; |
44 Monitor* KernelIsolate::monitor_ = new Monitor(); | 40 Monitor* KernelIsolate::monitor_ = new Monitor(); |
45 Isolate* KernelIsolate::isolate_ = NULL; | 41 Isolate* KernelIsolate::isolate_ = NULL; |
46 bool KernelIsolate::initializing_ = true; | 42 bool KernelIsolate::initializing_ = true; |
47 Dart_Port KernelIsolate::kernel_port_ = ILLEGAL_PORT; | 43 Dart_Port KernelIsolate::kernel_port_ = ILLEGAL_PORT; |
48 | 44 |
49 class RunKernelTask : public ThreadPool::Task { | 45 class RunKernelTask : public ThreadPool::Task { |
50 public: | 46 public: |
51 virtual void Run() { | 47 virtual void Run() { |
52 ASSERT(Isolate::Current() == NULL); | 48 ASSERT(Isolate::Current() == NULL); |
53 | |
54 if (!FLAG_use_dart_frontend) { | |
55 ASSERT(FLAG_use_dart_frontend); | |
56 // In release builds, make this a no-op. In debug builds, the | |
57 // assert shows that this is not supposed to happen. | |
58 return; | |
59 } | |
60 | |
61 #ifndef PRODUCT | 49 #ifndef PRODUCT |
62 TimelineDurationScope tds(Timeline::GetVMStream(), "KernelIsolateStartup"); | 50 TimelineDurationScope tds(Timeline::GetVMStream(), "KernelIsolateStartup"); |
63 #endif // !PRODUCT | 51 #endif // !PRODUCT |
64 char* error = NULL; | 52 char* error = NULL; |
65 Isolate* isolate = NULL; | 53 Isolate* isolate = NULL; |
66 | 54 |
67 Dart_IsolateCreateCallback create_callback = | 55 Dart_IsolateCreateCallback create_callback = |
68 KernelIsolate::create_callback(); | 56 KernelIsolate::create_callback(); |
69 | 57 |
70 if (create_callback == NULL) { | 58 if (create_callback == NULL) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return false; | 180 return false; |
193 } | 181 } |
194 ASSERT(result.IsReceivePort()); | 182 ASSERT(result.IsReceivePort()); |
195 const ReceivePort& rp = ReceivePort::Cast(result); | 183 const ReceivePort& rp = ReceivePort::Cast(result); |
196 KernelIsolate::SetLoadPort(rp.Id()); | 184 KernelIsolate::SetLoadPort(rp.Id()); |
197 return true; | 185 return true; |
198 } | 186 } |
199 }; | 187 }; |
200 | 188 |
201 void KernelIsolate::Run() { | 189 void KernelIsolate::Run() { |
202 if (!FLAG_use_dart_frontend) { | |
203 return; | |
204 } | |
205 // Grab the isolate create callback here to avoid race conditions with tests | 190 // Grab the isolate create callback here to avoid race conditions with tests |
206 // that change this after Dart_Initialize returns. | 191 // that change this after Dart_Initialize returns. |
207 create_callback_ = Isolate::CreateCallback(); | 192 create_callback_ = Isolate::CreateCallback(); |
208 Dart::thread_pool()->Run(new RunKernelTask()); | 193 Dart::thread_pool()->Run(new RunKernelTask()); |
209 } | 194 } |
210 | 195 |
211 void KernelIsolate::InitCallback(Isolate* I) { | 196 void KernelIsolate::InitCallback(Isolate* I) { |
212 Thread* T = Thread::Current(); | 197 Thread* T = Thread::Current(); |
213 ASSERT(I == T->isolate()); | 198 ASSERT(I == T->isolate()); |
214 ASSERT(I != NULL); | 199 ASSERT(I != NULL); |
215 ASSERT(I->name() != NULL); | 200 ASSERT(I->name() != NULL); |
216 if (!FLAG_use_dart_frontend || | 201 if (strstr(I->name(), DART_KERNEL_ISOLATE_NAME) == NULL) { |
217 (strstr(I->name(), DART_KERNEL_ISOLATE_NAME) == NULL)) { | |
218 // Not kernel isolate. | 202 // Not kernel isolate. |
219 return; | 203 return; |
220 } | 204 } |
221 ASSERT(!Exists()); | 205 ASSERT(!Exists()); |
222 if (FLAG_trace_kernel) { | 206 if (FLAG_trace_kernel) { |
223 OS::Print(DART_KERNEL_ISOLATE_NAME ": InitCallback for %s.\n", I->name()); | 207 OS::Print(DART_KERNEL_ISOLATE_NAME ": InitCallback for %s.\n", I->name()); |
224 } | 208 } |
225 SetKernelIsolate(I); | 209 SetKernelIsolate(I); |
226 } | 210 } |
227 | 211 |
(...skipping 22 matching lines...) Expand all Loading... |
250 kernel_port_ = port; | 234 kernel_port_ = port; |
251 } | 235 } |
252 | 236 |
253 void KernelIsolate::FinishedInitializing() { | 237 void KernelIsolate::FinishedInitializing() { |
254 MonitorLocker ml(monitor_); | 238 MonitorLocker ml(monitor_); |
255 initializing_ = false; | 239 initializing_ = false; |
256 ml.NotifyAll(); | 240 ml.NotifyAll(); |
257 } | 241 } |
258 | 242 |
259 Dart_Port KernelIsolate::WaitForKernelPort() { | 243 Dart_Port KernelIsolate::WaitForKernelPort() { |
260 if (!FLAG_use_dart_frontend) { | |
261 return ILLEGAL_PORT; | |
262 } | |
263 MonitorLocker ml(monitor_); | 244 MonitorLocker ml(monitor_); |
264 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) { | 245 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) { |
265 ml.Wait(); | 246 ml.Wait(); |
266 } | 247 } |
267 return kernel_port_; | 248 return kernel_port_; |
268 } | 249 } |
269 | 250 |
270 class KernelCompilationRequest : public ValueObject { | 251 class KernelCompilationRequest : public ValueObject { |
271 public: | 252 public: |
272 KernelCompilationRequest() | 253 KernelCompilationRequest() |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 } | 451 } |
471 | 452 |
472 KernelCompilationRequest request; | 453 KernelCompilationRequest request; |
473 return request.SendAndWaitForResponse(kernel_port, script_uri, | 454 return request.SendAndWaitForResponse(kernel_port, script_uri, |
474 source_file_count, source_files); | 455 source_file_count, source_files); |
475 } | 456 } |
476 | 457 |
477 #endif // DART_PRECOMPILED_RUNTIME | 458 #endif // DART_PRECOMPILED_RUNTIME |
478 | 459 |
479 } // namespace dart | 460 } // namespace dart |
OLD | NEW |