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" |
| 8 #include "include/dart_native_api.h" |
7 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
8 #include "include/dart_native_api.h" | |
9 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
11 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
12 #include "vm/lockers.h" | 13 #include "vm/lockers.h" |
13 #include "vm/message.h" | 14 #include "vm/message.h" |
14 #include "vm/message_handler.h" | 15 #include "vm/message_handler.h" |
| 16 #include "vm/native_arguments.h" |
15 #include "vm/native_entry.h" | 17 #include "vm/native_entry.h" |
16 #include "vm/native_arguments.h" | |
17 #include "vm/object.h" | 18 #include "vm/object.h" |
18 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
19 #include "vm/port.h" | 20 #include "vm/port.h" |
20 #include "vm/service.h" | 21 #include "vm/service.h" |
21 #include "vm/symbols.h" | 22 #include "vm/symbols.h" |
22 #include "vm/thread_pool.h" | 23 #include "vm/thread_pool.h" |
23 #include "vm/timeline.h" | 24 #include "vm/timeline.h" |
24 | 25 |
25 namespace dart { | 26 namespace dart { |
26 | 27 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 result_.kernel = NULL; | 294 result_.kernel = NULL; |
294 result_.kernel_size = 0; | 295 result_.kernel_size = 0; |
295 } | 296 } |
296 | 297 |
297 ~KernelCompilationRequest() { | 298 ~KernelCompilationRequest() { |
298 UnregisterRequest(this); | 299 UnregisterRequest(this); |
299 Dart_CloseNativePort(port_); | 300 Dart_CloseNativePort(port_); |
300 delete monitor_; | 301 delete monitor_; |
301 } | 302 } |
302 | 303 |
303 Dart_KernelCompilationResult SendAndWaitForResponse(Dart_Port kernel_port, | 304 Dart_KernelCompilationResult SendAndWaitForResponse( |
304 const char* script_uri) { | 305 Dart_Port kernel_port, |
| 306 const char* script_uri, |
| 307 int source_files_count, |
| 308 Dart_SourceFile source_files[]) { |
305 // Build the [null, send_port, script_uri] message for the Kernel isolate: | 309 // Build the [null, send_port, script_uri] message for the Kernel isolate: |
306 // null tag tells it that request came from this code, instead of Loader | 310 // null tag tells it that request came from this code, instead of Loader |
307 // so that it can given a more informative response. | 311 // so that it can given a more informative response. |
308 Dart_CObject tag; | 312 Dart_CObject tag; |
309 tag.type = Dart_CObject_kNull; | 313 tag.type = Dart_CObject_kNull; |
310 | 314 |
311 Dart_CObject send_port; | 315 Dart_CObject send_port; |
312 send_port.type = Dart_CObject_kSendPort; | 316 send_port.type = Dart_CObject_kSendPort; |
313 send_port.value.as_send_port.id = port_; | 317 send_port.value.as_send_port.id = port_; |
314 send_port.value.as_send_port.origin_id = ILLEGAL_PORT; | 318 send_port.value.as_send_port.origin_id = ILLEGAL_PORT; |
315 | 319 |
316 Dart_CObject uri; | 320 Dart_CObject uri; |
317 uri.type = Dart_CObject_kString; | 321 uri.type = Dart_CObject_kString; |
318 uri.value.as_string = const_cast<char*>(script_uri); | 322 uri.value.as_string = const_cast<char*>(script_uri); |
319 | 323 |
320 static const intptr_t kMessageLen = 3; | |
321 Dart_CObject* message_arr[kMessageLen] = {&tag, &send_port, &uri}; | |
322 | |
323 Dart_CObject message; | 324 Dart_CObject message; |
324 message.type = Dart_CObject_kArray; | 325 message.type = Dart_CObject_kArray; |
325 message.value.as_array.length = kMessageLen; | |
326 message.value.as_array.values = message_arr; | |
327 | 326 |
328 // Send the message. | 327 if (source_files_count == 0) { |
329 Dart_PostCObject(kernel_port, &message); | 328 static const intptr_t message_len = 3; |
| 329 Dart_CObject* message_arr[] = {&tag, &send_port, &uri}; |
| 330 message.value.as_array.values = message_arr; |
| 331 message.value.as_array.length = message_len; |
| 332 // Send the message. |
| 333 Dart_PostCObject(kernel_port, &message); |
| 334 } else { |
| 335 Dart_CObject files; |
| 336 files.type = Dart_CObject_kArray; |
| 337 files.value.as_array.length = source_files_count * 2; |
| 338 // typedef Dart_CObject* Dart_CObjectPtr; |
| 339 Dart_CObject** fileNamePairs = new Dart_CObject*[source_files_count * 2]; |
| 340 for (int i = 0; i < source_files_count; i++) { |
| 341 Dart_CObject* source_uri = new Dart_CObject(); |
| 342 source_uri->type = Dart_CObject_kString; |
| 343 source_uri->value.as_string = const_cast<char*>(source_files[i].uri); |
| 344 fileNamePairs[i * 2] = source_uri; |
| 345 |
| 346 Dart_CObject* source_code = new Dart_CObject(); |
| 347 source_code->type = Dart_CObject_kTypedData; |
| 348 source_code->value.as_typed_data.type = Dart_TypedData_kUint8; |
| 349 source_code->value.as_typed_data.length = |
| 350 strlen(source_files[i].source); |
| 351 source_code->value.as_typed_data.values = reinterpret_cast<uint8_t*>( |
| 352 const_cast<char*>(source_files[i].source)); |
| 353 fileNamePairs[(i * 2) + 1] = source_code; |
| 354 } |
| 355 files.value.as_array.values = fileNamePairs; |
| 356 static const intptr_t message_len = 4; |
| 357 Dart_CObject* message_arr[] = {&tag, &send_port, &uri, &files}; |
| 358 message.value.as_array.values = message_arr; |
| 359 message.value.as_array.length = message_len; |
| 360 Dart_PostCObject(kernel_port, &message); |
| 361 } |
330 | 362 |
331 // Wait for reply to arrive. | 363 // Wait for reply to arrive. |
332 MonitorLocker ml(monitor_); | 364 MonitorLocker ml(monitor_); |
333 while (result_.status == Dart_KernelCompilationStatus_Unknown) { | 365 while (result_.status == Dart_KernelCompilationStatus_Unknown) { |
334 ml.Wait(); | 366 ml.Wait(); |
335 } | 367 } |
336 | 368 |
337 return result_; | 369 return result_; |
338 } | 370 } |
339 | 371 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 KernelCompilationRequest* next_; | 460 KernelCompilationRequest* next_; |
429 KernelCompilationRequest* prev_; | 461 KernelCompilationRequest* prev_; |
430 | 462 |
431 Dart_KernelCompilationResult result_; | 463 Dart_KernelCompilationResult result_; |
432 }; | 464 }; |
433 | 465 |
434 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); | 466 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); |
435 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; | 467 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; |
436 | 468 |
437 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( | 469 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( |
438 const char* script_uri) { | 470 const char* script_uri, |
| 471 int source_file_count, |
| 472 Dart_SourceFile source_files[]) { |
439 // This must be the main script to be loaded. Wait for Kernel isolate | 473 // This must be the main script to be loaded. Wait for Kernel isolate |
440 // to finish initialization. | 474 // to finish initialization. |
441 Dart_Port kernel_port = WaitForKernelPort(); | 475 Dart_Port kernel_port = WaitForKernelPort(); |
442 if (kernel_port == ILLEGAL_PORT) { | 476 if (kernel_port == ILLEGAL_PORT) { |
443 Dart_KernelCompilationResult result; | 477 Dart_KernelCompilationResult result; |
444 result.status = Dart_KernelCompilationStatus_Unknown; | 478 result.status = Dart_KernelCompilationStatus_Unknown; |
445 result.error = strdup("Error while initializing Kernel isolate"); | 479 result.error = strdup("Error while initializing Kernel isolate"); |
446 return result; | 480 return result; |
447 } | 481 } |
448 | 482 |
449 KernelCompilationRequest request; | 483 KernelCompilationRequest request; |
450 return request.SendAndWaitForResponse(kernel_port, script_uri); | 484 return request.SendAndWaitForResponse(kernel_port, script_uri, |
| 485 source_file_count, source_files); |
451 } | 486 } |
452 | 487 |
453 | 488 |
454 #endif // DART_PRECOMPILED_RUNTIME | 489 #endif // DART_PRECOMPILED_RUNTIME |
455 | 490 |
456 } // namespace dart | 491 } // namespace dart |
OLD | NEW |