Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: runtime/vm/kernel_isolate.cc

Issue 2993013002: Introduce IKG into kernel-service to support incremental compilation. (Closed)
Patch Set: Use new acceptDelta api. Safe guard against no thread/isolate Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/kernel_isolate.h ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Isolate* isolate =
345 Thread::Current() != NULL ? Thread::Current()->isolate() : NULL;
346 if (incremental_compile) {
347 ASSERT(isolate != NULL);
348 }
siva 2017/08/14 20:50:32 As discussed offline we should be able to assert t
aam 2017/08/14 21:01:27 Done.
349 Dart_CObject isolate_id;
350 isolate_id.type = Dart_CObject_kInt64;
351 isolate_id.value.as_int64 =
352 isolate != NULL ? static_cast<int64_t>(isolate->main_port()) : 0;
353
313 Dart_CObject message; 354 Dart_CObject message;
314 message.type = Dart_CObject_kArray; 355 message.type = Dart_CObject_kArray;
315 356
316 if (source_files_count == 0) { 357 intptr_t message_len = 5;
317 static const intptr_t message_len = 3; 358 Dart_CObject files;
318 Dart_CObject* message_arr[] = {&tag, &send_port, &uri}; 359 if (source_files_count != 0) {
319 message.value.as_array.values = message_arr; 360 files = BuildFilesPairs(source_files_count, source_files);
320 message.value.as_array.length = message_len; 361 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 } 362 }
363 Dart_CObject* message_arr[] = {
364 &tag, &send_port, &uri, &dart_incremental, &isolate_id, &files};
365 message.value.as_array.values = message_arr;
366 message.value.as_array.length = message_len;
367 // Send the message.
368 Dart_PostCObject(kernel_port, &message);
351 369
352 // Wait for reply to arrive. 370 // Wait for reply to arrive.
353 MonitorLocker ml(monitor_); 371 MonitorLocker ml(monitor_);
354 while (result_.status == Dart_KernelCompilationStatus_Unknown) { 372 while (result_.status == Dart_KernelCompilationStatus_Unknown) {
355 ml.Wait(); 373 ml.Wait();
356 } 374 }
357 375
358 return result_; 376 return result_;
359 } 377 }
360 378
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 469
452 Dart_KernelCompilationResult result_; 470 Dart_KernelCompilationResult result_;
453 }; 471 };
454 472
455 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); 473 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor();
456 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; 474 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL;
457 475
458 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( 476 Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
459 const char* script_uri, 477 const char* script_uri,
460 int source_file_count, 478 int source_file_count,
461 Dart_SourceFile source_files[]) { 479 Dart_SourceFile source_files[],
480 bool incremental_compile) {
462 // This must be the main script to be loaded. Wait for Kernel isolate 481 // This must be the main script to be loaded. Wait for Kernel isolate
463 // to finish initialization. 482 // to finish initialization.
464 Dart_Port kernel_port = WaitForKernelPort(); 483 Dart_Port kernel_port = WaitForKernelPort();
465 if (kernel_port == ILLEGAL_PORT) { 484 if (kernel_port == ILLEGAL_PORT) {
466 Dart_KernelCompilationResult result; 485 Dart_KernelCompilationResult result;
467 result.status = Dart_KernelCompilationStatus_Unknown; 486 result.status = Dart_KernelCompilationStatus_Unknown;
468 result.error = strdup("Error while initializing Kernel isolate"); 487 result.error = strdup("Error while initializing Kernel isolate");
469 return result; 488 return result;
470 } 489 }
471 490
472 KernelCompilationRequest request; 491 KernelCompilationRequest request;
473 return request.SendAndWaitForResponse(kernel_port, script_uri, 492 return request.SendAndWaitForResponse(kernel_port, script_uri,
474 source_file_count, source_files); 493 source_file_count, source_files,
494 incremental_compile);
475 } 495 }
476 496
477 #endif // DART_PRECOMPILED_RUNTIME 497 #endif // DART_PRECOMPILED_RUNTIME
478 498
479 } // namespace dart 499 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/kernel_isolate.h ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698