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