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

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

Issue 2998963002: Revert "Revert "Introduce IKG into kernel-service to support incremental compilation."" (Closed)
Patch Set: 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 241 }
242 242
243 Dart_Port KernelIsolate::WaitForKernelPort() { 243 Dart_Port KernelIsolate::WaitForKernelPort() {
244 MonitorLocker ml(monitor_); 244 MonitorLocker ml(monitor_);
245 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) { 245 while (initializing_ && (kernel_port_ == ILLEGAL_PORT)) {
246 ml.Wait(); 246 ml.Wait();
247 } 247 }
248 return kernel_port_; 248 return kernel_port_;
249 } 249 }
250 250
251 static Dart_CObject BuildFilesPairs(int source_files_count,
252 Dart_SourceFile source_files[]) {
253 Dart_CObject files;
254 files.type = Dart_CObject_kArray;
255 files.value.as_array.length = source_files_count * 2;
256 // typedef Dart_CObject* Dart_CObjectPtr;
257 Dart_CObject** fileNamePairs = new Dart_CObject*[source_files_count * 2];
258 for (int i = 0; i < source_files_count; i++) {
259 Dart_CObject* source_uri = new Dart_CObject();
260 source_uri->type = Dart_CObject_kString;
261 source_uri->value.as_string = const_cast<char*>(source_files[i].uri);
262 fileNamePairs[i * 2] = source_uri;
263
264 Dart_CObject* source_code = new Dart_CObject();
265 source_code->type = Dart_CObject_kTypedData;
266 source_code->value.as_typed_data.type = Dart_TypedData_kUint8;
267 source_code->value.as_typed_data.length = strlen(source_files[i].source);
268 source_code->value.as_typed_data.values =
269 reinterpret_cast<uint8_t*>(const_cast<char*>(source_files[i].source));
270 fileNamePairs[(i * 2) + 1] = source_code;
271 }
272 files.value.as_array.values = fileNamePairs;
273 return files;
274 }
275
251 class KernelCompilationRequest : public ValueObject { 276 class KernelCompilationRequest : public ValueObject {
252 public: 277 public:
253 KernelCompilationRequest() 278 KernelCompilationRequest()
254 : monitor_(new Monitor()), 279 : monitor_(new Monitor()),
255 port_(Dart_NewNativePort("kernel-compilation-port", 280 port_(Dart_NewNativePort("kernel-compilation-port",
256 &HandleResponse, 281 &HandleResponse,
257 false)), 282 false)),
258 next_(NULL), 283 next_(NULL),
259 prev_(NULL) { 284 prev_(NULL) {
260 ASSERT(port_ != ILLEGAL_PORT); 285 ASSERT(port_ != ILLEGAL_PORT);
261 RegisterRequest(this); 286 RegisterRequest(this);
262 result_.status = Dart_KernelCompilationStatus_Unknown; 287 result_.status = Dart_KernelCompilationStatus_Unknown;
263 result_.error = NULL; 288 result_.error = NULL;
264 result_.kernel = NULL; 289 result_.kernel = NULL;
265 result_.kernel_size = 0; 290 result_.kernel_size = 0;
266 } 291 }
267 292
268 ~KernelCompilationRequest() { 293 ~KernelCompilationRequest() {
269 UnregisterRequest(this); 294 UnregisterRequest(this);
270 Dart_CloseNativePort(port_); 295 Dart_CloseNativePort(port_);
271 delete monitor_; 296 delete monitor_;
272 } 297 }
273 298
274 Dart_KernelCompilationResult SendAndWaitForResponse( 299 Dart_KernelCompilationResult SendAndWaitForResponse(
275 Dart_Port kernel_port, 300 Dart_Port kernel_port,
276 const char* script_uri, 301 const char* script_uri,
277 int source_files_count, 302 int source_files_count,
278 Dart_SourceFile source_files[]) { 303 Dart_SourceFile source_files[],
279 // Build the [null, send_port, script_uri] message for the Kernel isolate: 304 bool incremental_compile) {
280 // null tag tells it that request came from this code, instead of Loader 305 // Build the [null, send_port, script_uri, incremental_compile, isolate_id,
281 // so that it can given a more informative response. 306 // [files]] message for the Kernel isolate: null tag tells it that request
307 // came from this code, instead of Loader so that it can given a more
308 // informative response.
282 Dart_CObject tag; 309 Dart_CObject tag;
283 tag.type = Dart_CObject_kNull; 310 tag.type = Dart_CObject_kNull;
284 311
285 Dart_CObject send_port; 312 Dart_CObject send_port;
286 send_port.type = Dart_CObject_kSendPort; 313 send_port.type = Dart_CObject_kSendPort;
287 send_port.value.as_send_port.id = port_; 314 send_port.value.as_send_port.id = port_;
288 send_port.value.as_send_port.origin_id = ILLEGAL_PORT; 315 send_port.value.as_send_port.origin_id = ILLEGAL_PORT;
289 316
290 Dart_CObject uri; 317 Dart_CObject uri;
291 uri.type = Dart_CObject_kString; 318 uri.type = Dart_CObject_kString;
292 uri.value.as_string = const_cast<char*>(script_uri); 319 uri.value.as_string = const_cast<char*>(script_uri);
293 320
321 Dart_CObject dart_incremental;
322 dart_incremental.type = Dart_CObject_kBool;
323 dart_incremental.value.as_bool = incremental_compile;
324
325 // TODO(aam): Assert that isolate exists once we move CompileAndReadScript
326 // compilation logic out of CreateIsolateAndSetupHelper and into
327 // IsolateSetupHelper in main.cc.
328 Isolate* isolate =
329 Thread::Current() != NULL ? Thread::Current()->isolate() : NULL;
330 if (incremental_compile) {
331 ASSERT(isolate != NULL);
332 }
333 Dart_CObject isolate_id;
334 isolate_id.type = Dart_CObject_kInt64;
335 isolate_id.value.as_int64 =
336 isolate != NULL ? static_cast<int64_t>(isolate->main_port()) : 0;
337
294 Dart_CObject message; 338 Dart_CObject message;
295 message.type = Dart_CObject_kArray; 339 message.type = Dart_CObject_kArray;
296 340
297 if (source_files_count == 0) { 341 intptr_t message_len = 5;
298 static const intptr_t message_len = 3; 342 Dart_CObject files;
299 Dart_CObject* message_arr[] = {&tag, &send_port, &uri}; 343 if (source_files_count != 0) {
300 message.value.as_array.values = message_arr; 344 files = BuildFilesPairs(source_files_count, source_files);
301 message.value.as_array.length = message_len; 345 message_len++;
302 // Send the message.
303 Dart_PostCObject(kernel_port, &message);
304 } else {
305 Dart_CObject files;
306 files.type = Dart_CObject_kArray;
307 files.value.as_array.length = source_files_count * 2;
308 // typedef Dart_CObject* Dart_CObjectPtr;
309 Dart_CObject** fileNamePairs = new Dart_CObject*[source_files_count * 2];
310 for (int i = 0; i < source_files_count; i++) {
311 Dart_CObject* source_uri = new Dart_CObject();
312 source_uri->type = Dart_CObject_kString;
313 source_uri->value.as_string = const_cast<char*>(source_files[i].uri);
314 fileNamePairs[i * 2] = source_uri;
315
316 Dart_CObject* source_code = new Dart_CObject();
317 source_code->type = Dart_CObject_kTypedData;
318 source_code->value.as_typed_data.type = Dart_TypedData_kUint8;
319 source_code->value.as_typed_data.length =
320 strlen(source_files[i].source);
321 source_code->value.as_typed_data.values = reinterpret_cast<uint8_t*>(
322 const_cast<char*>(source_files[i].source));
323 fileNamePairs[(i * 2) + 1] = source_code;
324 }
325 files.value.as_array.values = fileNamePairs;
326 static const intptr_t message_len = 4;
327 Dart_CObject* message_arr[] = {&tag, &send_port, &uri, &files};
328 message.value.as_array.values = message_arr;
329 message.value.as_array.length = message_len;
330 Dart_PostCObject(kernel_port, &message);
331 } 346 }
347 Dart_CObject* message_arr[] = {
348 &tag, &send_port, &uri, &dart_incremental, &isolate_id, &files};
349 message.value.as_array.values = message_arr;
350 message.value.as_array.length = message_len;
351 // Send the message.
352 Dart_PostCObject(kernel_port, &message);
332 353
333 // Wait for reply to arrive. 354 // Wait for reply to arrive.
334 MonitorLocker ml(monitor_); 355 MonitorLocker ml(monitor_);
335 while (result_.status == Dart_KernelCompilationStatus_Unknown) { 356 while (result_.status == Dart_KernelCompilationStatus_Unknown) {
336 ml.Wait(); 357 ml.Wait();
337 } 358 }
338 359
339 return result_; 360 return result_;
340 } 361 }
341 362
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 453
433 Dart_KernelCompilationResult result_; 454 Dart_KernelCompilationResult result_;
434 }; 455 };
435 456
436 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor(); 457 Monitor* KernelCompilationRequest::requests_monitor_ = new Monitor();
437 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL; 458 KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL;
438 459
439 Dart_KernelCompilationResult KernelIsolate::CompileToKernel( 460 Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
440 const char* script_uri, 461 const char* script_uri,
441 int source_file_count, 462 int source_file_count,
442 Dart_SourceFile source_files[]) { 463 Dart_SourceFile source_files[],
464 bool incremental_compile) {
443 // This must be the main script to be loaded. Wait for Kernel isolate 465 // This must be the main script to be loaded. Wait for Kernel isolate
444 // to finish initialization. 466 // to finish initialization.
445 Dart_Port kernel_port = WaitForKernelPort(); 467 Dart_Port kernel_port = WaitForKernelPort();
446 if (kernel_port == ILLEGAL_PORT) { 468 if (kernel_port == ILLEGAL_PORT) {
447 Dart_KernelCompilationResult result; 469 Dart_KernelCompilationResult result;
448 result.status = Dart_KernelCompilationStatus_Unknown; 470 result.status = Dart_KernelCompilationStatus_Unknown;
449 result.error = strdup("Error while initializing Kernel isolate"); 471 result.error = strdup("Error while initializing Kernel isolate");
450 return result; 472 return result;
451 } 473 }
452 474
453 KernelCompilationRequest request; 475 KernelCompilationRequest request;
454 return request.SendAndWaitForResponse(kernel_port, script_uri, 476 return request.SendAndWaitForResponse(kernel_port, script_uri,
455 source_file_count, source_files); 477 source_file_count, source_files,
478 incremental_compile);
456 } 479 }
457 480
458 #endif // DART_PRECOMPILED_RUNTIME 481 #endif // DART_PRECOMPILED_RUNTIME
459 482
460 } // namespace dart 483 } // 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