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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (!FLAG_use_dart_frontend) { | 260 if (!FLAG_use_dart_frontend) { |
261 return ILLEGAL_PORT; | 261 return ILLEGAL_PORT; |
262 } | 262 } |
263 MonitorLocker ml(monitor_); | 263 MonitorLocker ml(monitor_); |
264 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) { | 264 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) { |
265 ml.Wait(); | 265 ml.Wait(); |
266 } | 266 } |
267 return kernel_port_; | 267 return kernel_port_; |
268 } | 268 } |
269 | 269 |
| 270 static Dart_CObject BuildFilesPairs(int source_files_count, |
| 271 Dart_SourceFile source_files[]) { |
| 272 Dart_CObject files; |
| 273 files.type = Dart_CObject_kArray; |
| 274 files.value.as_array.length = source_files_count * 2; |
| 275 // typedef Dart_CObject* Dart_CObjectPtr; |
| 276 Dart_CObject** fileNamePairs = new Dart_CObject*[source_files_count * 2]; |
| 277 for (int i = 0; i < source_files_count; i++) { |
| 278 Dart_CObject* source_uri = new Dart_CObject(); |
| 279 source_uri->type = Dart_CObject_kString; |
| 280 source_uri->value.as_string = const_cast<char*>(source_files[i].uri); |
| 281 fileNamePairs[i * 2] = source_uri; |
| 282 |
| 283 Dart_CObject* source_code = new Dart_CObject(); |
| 284 source_code->type = Dart_CObject_kTypedData; |
| 285 source_code->value.as_typed_data.type = Dart_TypedData_kUint8; |
| 286 source_code->value.as_typed_data.length = strlen(source_files[i].source); |
| 287 source_code->value.as_typed_data.values = |
| 288 reinterpret_cast<uint8_t*>(const_cast<char*>(source_files[i].source)); |
| 289 fileNamePairs[(i * 2) + 1] = source_code; |
| 290 } |
| 291 files.value.as_array.values = fileNamePairs; |
| 292 return files; |
| 293 } |
| 294 |
270 class KernelCompilationRequest : public ValueObject { | 295 class KernelCompilationRequest : public ValueObject { |
271 public: | 296 public: |
272 KernelCompilationRequest() | 297 KernelCompilationRequest() |
273 : monitor_(new Monitor()), | 298 : monitor_(new Monitor()), |
274 port_(Dart_NewNativePort("kernel-compilation-port", | 299 port_(Dart_NewNativePort("kernel-compilation-port", |
275 &HandleResponse, | 300 &HandleResponse, |
276 false)), | 301 false)), |
277 next_(NULL), | 302 next_(NULL), |
278 prev_(NULL) { | 303 prev_(NULL) { |
279 ASSERT(port_ != ILLEGAL_PORT); | 304 ASSERT(port_ != ILLEGAL_PORT); |
280 RegisterRequest(this); | 305 RegisterRequest(this); |
281 result_.status = Dart_KernelCompilationStatus_Unknown; | 306 result_.status = Dart_KernelCompilationStatus_Unknown; |
282 result_.error = NULL; | 307 result_.error = NULL; |
283 result_.kernel = NULL; | 308 result_.kernel = NULL; |
284 result_.kernel_size = 0; | 309 result_.kernel_size = 0; |
285 } | 310 } |
286 | 311 |
287 ~KernelCompilationRequest() { | 312 ~KernelCompilationRequest() { |
288 UnregisterRequest(this); | 313 UnregisterRequest(this); |
289 Dart_CloseNativePort(port_); | 314 Dart_CloseNativePort(port_); |
290 delete monitor_; | 315 delete monitor_; |
291 } | 316 } |
292 | 317 |
293 Dart_KernelCompilationResult SendAndWaitForResponse( | 318 Dart_KernelCompilationResult SendAndWaitForResponse( |
294 Dart_Port kernel_port, | 319 Dart_Port kernel_port, |
295 const char* script_uri, | 320 const char* script_uri, |
296 int source_files_count, | 321 int source_files_count, |
297 Dart_SourceFile source_files[]) { | 322 Dart_SourceFile source_files[], |
298 // Build the [null, send_port, script_uri] message for the Kernel isolate: | 323 bool incremental_compile) { |
299 // null tag tells it that request came from this code, instead of Loader | 324 // Build the [null, send_port, script_uri, incremental_compile, isolate_id, |
300 // so that it can given a more informative response. | 325 // [files]] message for the Kernel isolate: null tag tells it that request |
| 326 // came from this code, instead of Loader so that it can given a more |
| 327 // informative response. |
301 Dart_CObject tag; | 328 Dart_CObject tag; |
302 tag.type = Dart_CObject_kNull; | 329 tag.type = Dart_CObject_kNull; |
303 | 330 |
304 Dart_CObject send_port; | 331 Dart_CObject send_port; |
305 send_port.type = Dart_CObject_kSendPort; | 332 send_port.type = Dart_CObject_kSendPort; |
306 send_port.value.as_send_port.id = port_; | 333 send_port.value.as_send_port.id = port_; |
307 send_port.value.as_send_port.origin_id = ILLEGAL_PORT; | 334 send_port.value.as_send_port.origin_id = ILLEGAL_PORT; |
308 | 335 |
309 Dart_CObject uri; | 336 Dart_CObject uri; |
310 uri.type = Dart_CObject_kString; | 337 uri.type = Dart_CObject_kString; |
311 uri.value.as_string = const_cast<char*>(script_uri); | 338 uri.value.as_string = const_cast<char*>(script_uri); |
312 | 339 |
| 340 Dart_CObject dart_incremental; |
| 341 dart_incremental.type = Dart_CObject_kBool; |
| 342 dart_incremental.value.as_bool = incremental_compile; |
| 343 |
| 344 Dart_CObject isolate_id; |
| 345 isolate_id.type = Dart_CObject_kInt64; |
| 346 isolate_id.value.as_int64 = |
| 347 static_cast<int64_t>(Thread::Current()->isolate()->main_port()); |
| 348 |
313 Dart_CObject message; | 349 Dart_CObject message; |
314 message.type = Dart_CObject_kArray; | 350 message.type = Dart_CObject_kArray; |
315 | 351 |
316 if (source_files_count == 0) { | 352 intptr_t message_len = 5; |
317 static const intptr_t message_len = 3; | 353 Dart_CObject files; |
318 Dart_CObject* message_arr[] = {&tag, &send_port, &uri}; | 354 if (source_files_count != 0) { |
319 message.value.as_array.values = message_arr; | 355 files = BuildFilesPairs(source_files_count, source_files); |
320 message.value.as_array.length = message_len; | 356 message_len++; |
321 // Send the message. | |
322 Dart_PostCObject(kernel_port, &message); | |
323 } else { | |
324 Dart_CObject files; | |
325 files.type = Dart_CObject_kArray; | |
326 files.value.as_array.length = source_files_count * 2; | |
327 // typedef Dart_CObject* Dart_CObjectPtr; | |
328 Dart_CObject** fileNamePairs = new Dart_CObject*[source_files_count * 2]; | |
329 for (int i = 0; i < source_files_count; i++) { | |
330 Dart_CObject* source_uri = new Dart_CObject(); | |
331 source_uri->type = Dart_CObject_kString; | |
332 source_uri->value.as_string = const_cast<char*>(source_files[i].uri); | |
333 fileNamePairs[i * 2] = source_uri; | |
334 | |
335 Dart_CObject* source_code = new Dart_CObject(); | |
336 source_code->type = Dart_CObject_kTypedData; | |
337 source_code->value.as_typed_data.type = Dart_TypedData_kUint8; | |
338 source_code->value.as_typed_data.length = | |
339 strlen(source_files[i].source); | |
340 source_code->value.as_typed_data.values = reinterpret_cast<uint8_t*>( | |
341 const_cast<char*>(source_files[i].source)); | |
342 fileNamePairs[(i * 2) + 1] = source_code; | |
343 } | |
344 files.value.as_array.values = fileNamePairs; | |
345 static const intptr_t message_len = 4; | |
346 Dart_CObject* message_arr[] = {&tag, &send_port, &uri, &files}; | |
347 message.value.as_array.values = message_arr; | |
348 message.value.as_array.length = message_len; | |
349 Dart_PostCObject(kernel_port, &message); | |
350 } | 357 } |
| 358 Dart_CObject* message_arr[] = { |
| 359 &tag, &send_port, &uri, &dart_incremental, &isolate_id, &files}; |
| 360 message.value.as_array.values = message_arr; |
| 361 message.value.as_array.length = message_len; |
| 362 // Send the message. |
| 363 Dart_PostCObject(kernel_port, &message); |
351 | 364 |
352 // Wait for reply to arrive. | 365 // Wait for reply to arrive. |
353 MonitorLocker ml(monitor_); | 366 MonitorLocker ml(monitor_); |
354 while (result_.status == Dart_KernelCompilationStatus_Unknown) { | 367 while (result_.status == Dart_KernelCompilationStatus_Unknown) { |
355 ml.Wait(); | 368 ml.Wait(); |
356 } | 369 } |
357 | 370 |
358 return result_; | 371 return result_; |
359 } | 372 } |
360 | 373 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 464 |
452 Dart_KernelCompilationResult result_; | 465 Dart_KernelCompilationResult result_; |
453 }; | 466 }; |
454 | 467 |
455 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); | 468 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); |
456 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; | 469 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; |
457 | 470 |
458 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( | 471 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( |
459 const char* script_uri, | 472 const char* script_uri, |
460 int source_file_count, | 473 int source_file_count, |
461 Dart_SourceFile source_files[]) { | 474 Dart_SourceFile source_files[], |
| 475 bool incremental_compile) { |
462 // This must be the main script to be loaded. Wait for Kernel isolate | 476 // This must be the main script to be loaded. Wait for Kernel isolate |
463 // to finish initialization. | 477 // to finish initialization. |
464 Dart_Port kernel_port = WaitForKernelPort(); | 478 Dart_Port kernel_port = WaitForKernelPort(); |
465 if (kernel_port == ILLEGAL_PORT) { | 479 if (kernel_port == ILLEGAL_PORT) { |
466 Dart_KernelCompilationResult result; | 480 Dart_KernelCompilationResult result; |
467 result.status = Dart_KernelCompilationStatus_Unknown; | 481 result.status = Dart_KernelCompilationStatus_Unknown; |
468 result.error = strdup("Error while initializing Kernel isolate"); | 482 result.error = strdup("Error while initializing Kernel isolate"); |
469 return result; | 483 return result; |
470 } | 484 } |
471 | 485 |
472 KernelCompilationRequest request; | 486 KernelCompilationRequest request; |
473 return request.SendAndWaitForResponse(kernel_port, script_uri, | 487 return request.SendAndWaitForResponse(kernel_port, script_uri, |
474 source_file_count, source_files); | 488 source_file_count, source_files, |
| 489 incremental_compile); |
475 } | 490 } |
476 | 491 |
477 #endif // DART_PRECOMPILED_RUNTIME | 492 #endif // DART_PRECOMPILED_RUNTIME |
478 | 493 |
479 } // namespace dart | 494 } // namespace dart |
OLD | NEW |