| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 | 70 |
| 71 // Global flag that is used to indicate that we want to compile all the | 71 // Global flag that is used to indicate that we want to compile all the |
| 72 // dart functions and not run anything. | 72 // dart functions and not run anything. |
| 73 static bool compile_all = false; | 73 static bool compile_all = false; |
| 74 | 74 |
| 75 | 75 |
| 76 // Global flag that is used to indicate that we want to compile all the | 76 // Global flag that is used to indicate that we want to compile all the |
| 77 // dart functions before running main and not compile anything thereafter. | 77 // dart functions before running main and not compile anything thereafter. |
| 78 static bool gen_precompiled_snapshot = false; | 78 static bool gen_precompiled_snapshot = false; |
| 79 static bool gen_precompiled_jit_snapshot = false; |
| 79 | 80 |
| 80 | 81 |
| 81 // Global flag that is used to indicate that we want to run from a precompiled | 82 // Global flag that is used to indicate that we want to run from a precompiled |
| 82 // snapshot. | 83 // snapshot. |
| 83 static bool run_precompiled_snapshot = false; | 84 static bool run_precompiled_snapshot = false; |
| 85 static bool run_precompiled_jit_snapshot = false; |
| 84 | 86 |
| 85 | 87 |
| 86 // Global flag that is used to indicate that we want to use blobs/mmap instead | 88 // Global flag that is used to indicate that we want to use blobs/mmap instead |
| 87 // of assembly/shared libraries for precompilation. | 89 // of assembly/shared libraries for precompilation. |
| 88 static bool use_blobs = false; | 90 static bool use_blobs = false; |
| 89 | 91 |
| 90 | 92 |
| 91 // Value of the --gen/run_precompiled_snapshot flag. | 93 // Value of the --gen/run_precompiled_snapshot flag. |
| 92 // (This pointer points into an argv buffer and does not need to be | 94 // (This pointer points into an argv buffer and does not need to be |
| 93 // free'd.) | 95 // free'd.) |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } else { | 361 } else { |
| 360 precompiled_snapshot_directory = arg; | 362 precompiled_snapshot_directory = arg; |
| 361 } | 363 } |
| 362 gen_precompiled_snapshot = true; | 364 gen_precompiled_snapshot = true; |
| 363 vm_options->AddArgument("--precompilation"); | 365 vm_options->AddArgument("--precompilation"); |
| 364 return true; | 366 return true; |
| 365 #endif // defined(DART_PRECOMPILER) | 367 #endif // defined(DART_PRECOMPILER) |
| 366 } | 368 } |
| 367 | 369 |
| 368 | 370 |
| 371 static bool ProcessGenPrecompiledJITSnapshotOption( |
| 372 const char* arg, |
| 373 CommandLineOptions* vm_options) { |
| 374 ASSERT(arg != NULL); |
| 375 if ((arg[0] == '=') || (arg[0] == ':')) { |
| 376 precompiled_snapshot_directory = &arg[1]; |
| 377 } else { |
| 378 precompiled_snapshot_directory = arg; |
| 379 } |
| 380 gen_precompiled_jit_snapshot = true; |
| 381 return true; |
| 382 } |
| 383 |
| 384 |
| 369 static bool ProcessRunPrecompiledSnapshotOption( | 385 static bool ProcessRunPrecompiledSnapshotOption( |
| 370 const char* arg, | 386 const char* arg, |
| 371 CommandLineOptions* vm_options) { | 387 CommandLineOptions* vm_options) { |
| 372 ASSERT(arg != NULL); | 388 ASSERT(arg != NULL); |
| 373 precompiled_snapshot_directory = arg; | 389 precompiled_snapshot_directory = arg; |
| 374 if ((precompiled_snapshot_directory[0] == '=') || | 390 if ((precompiled_snapshot_directory[0] == '=') || |
| 375 (precompiled_snapshot_directory[0] == ':')) { | 391 (precompiled_snapshot_directory[0] == ':')) { |
| 376 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; | 392 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| 377 } | 393 } |
| 378 run_precompiled_snapshot = true; | 394 run_precompiled_snapshot = true; |
| 379 vm_options->AddArgument("--precompilation"); | 395 vm_options->AddArgument("--precompilation"); |
| 380 return true; | 396 return true; |
| 381 } | 397 } |
| 382 | 398 |
| 383 | 399 |
| 400 static bool ProcessRunPrecompiledJITSnapshotOption( |
| 401 const char* arg, |
| 402 CommandLineOptions* vm_options) { |
| 403 ASSERT(arg != NULL); |
| 404 precompiled_snapshot_directory = arg; |
| 405 if ((precompiled_snapshot_directory[0] == '=') || |
| 406 (precompiled_snapshot_directory[0] == ':')) { |
| 407 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| 408 } |
| 409 run_precompiled_jit_snapshot = true; |
| 410 return true; |
| 411 } |
| 412 |
| 413 |
| 384 static bool ProcessSnapshotOptionHelper(const char* filename, | 414 static bool ProcessSnapshotOptionHelper(const char* filename, |
| 385 bool* snapshot_option) { | 415 bool* snapshot_option) { |
| 386 ASSERT((filename != NULL) && (strlen(filename) != 0)); | 416 ASSERT((filename != NULL) && (strlen(filename) != 0)); |
| 387 snapshot_filename = filename; | 417 snapshot_filename = filename; |
| 388 *snapshot_option = true; | 418 *snapshot_option = true; |
| 389 if (generate_script_snapshot && generate_full_snapshot_after_run) { | 419 if (generate_script_snapshot && generate_full_snapshot_after_run) { |
| 390 Log::PrintErr("--snapshot and --snapshot-after-run options" | 420 Log::PrintErr("--snapshot and --snapshot-after-run options" |
| 391 " cannot be specified at the same time\n"); | 421 " cannot be specified at the same time\n"); |
| 392 *snapshot_option = false; | 422 *snapshot_option = false; |
| 393 return false; | 423 return false; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 { "--package-root=", ProcessPackageRootOption }, | 558 { "--package-root=", ProcessPackageRootOption }, |
| 529 { "-v", ProcessVerboseOption }, | 559 { "-v", ProcessVerboseOption }, |
| 530 { "--verbose", ProcessVerboseOption }, | 560 { "--verbose", ProcessVerboseOption }, |
| 531 { "--version", ProcessVersionOption }, | 561 { "--version", ProcessVersionOption }, |
| 532 | 562 |
| 533 // VM specific options to the standalone dart program. | 563 // VM specific options to the standalone dart program. |
| 534 { "--compile_all", ProcessCompileAllOption }, | 564 { "--compile_all", ProcessCompileAllOption }, |
| 535 { "--use_blobs", ProcessUseBlobsOption }, | 565 { "--use_blobs", ProcessUseBlobsOption }, |
| 536 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 566 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 537 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, | 567 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, |
| 568 { "--gen-precompiled-jit-snapshot", ProcessGenPrecompiledJITSnapshotOption }, |
| 538 { "--observe", ProcessObserveOption }, | 569 { "--observe", ProcessObserveOption }, |
| 539 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, | 570 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, |
| 571 { "--run-precompiled-jit-snapshot", ProcessRunPrecompiledJITSnapshotOption }, |
| 540 { "--shutdown", ProcessShutdownOption }, | 572 { "--shutdown", ProcessShutdownOption }, |
| 541 { "--snapshot=", ProcessScriptSnapshotOption }, | 573 { "--snapshot=", ProcessScriptSnapshotOption }, |
| 542 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, | 574 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, |
| 543 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, | 575 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, |
| 544 { "--trace-loading", ProcessTraceLoadingOption }, | 576 { "--trace-loading", ProcessTraceLoadingOption }, |
| 545 { NULL, NULL } | 577 { NULL, NULL } |
| 546 }; | 578 }; |
| 547 | 579 |
| 548 | 580 |
| 549 static bool ProcessMainOptions(const char* option, | 581 static bool ProcessMainOptions(const char* option, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 832 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 801 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 833 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 802 } | 834 } |
| 803 | 835 |
| 804 // Set up the library tag handler for this isolate. | 836 // Set up the library tag handler for this isolate. |
| 805 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 837 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 806 CHECK_RESULT(result); | 838 CHECK_RESULT(result); |
| 807 | 839 |
| 808 if (Dart_IsServiceIsolate(isolate)) { | 840 if (Dart_IsServiceIsolate(isolate)) { |
| 809 // If this is the service isolate, load embedder specific bits and return. | 841 // If this is the service isolate, load embedder specific bits and return. |
| 842 bool skip_library_load = run_precompiled_snapshot || |
| 843 run_precompiled_jit_snapshot; |
| 810 if (!VmService::Setup(vm_service_server_ip, | 844 if (!VmService::Setup(vm_service_server_ip, |
| 811 vm_service_server_port, | 845 vm_service_server_port, |
| 812 run_precompiled_snapshot)) { | 846 skip_library_load)) { |
| 813 *error = strdup(VmService::GetErrorMessage()); | 847 *error = strdup(VmService::GetErrorMessage()); |
| 814 return NULL; | 848 return NULL; |
| 815 } | 849 } |
| 816 if (compile_all) { | 850 if (compile_all) { |
| 817 result = Dart_CompileAll(); | 851 result = Dart_CompileAll(); |
| 818 CHECK_RESULT(result); | 852 CHECK_RESULT(result); |
| 819 } | 853 } |
| 820 Dart_ExitScope(); | 854 Dart_ExitScope(); |
| 821 Dart_ExitIsolate(); | 855 Dart_ExitIsolate(); |
| 822 return isolate; | 856 return isolate; |
| 823 } | 857 } |
| 824 | 858 |
| 825 // Prepare builtin and other core libraries for use to resolve URIs. | 859 // Prepare builtin and other core libraries for use to resolve URIs. |
| 826 // Set up various closures, e.g: printing, timers etc. | 860 // Set up various closures, e.g: printing, timers etc. |
| 827 // Set up 'package root' for URI resolution. | 861 // Set up 'package root' for URI resolution. |
| 828 result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 862 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
| 829 CHECK_RESULT(result); | 863 CHECK_RESULT(result); |
| 830 | 864 |
| 831 if (!run_precompiled_snapshot && !run_full_snapshot) { | 865 if (!run_precompiled_snapshot && |
| 866 !run_precompiled_jit_snapshot && |
| 867 !run_full_snapshot) { |
| 832 // Set up the load port provided by the service isolate so that we can | 868 // Set up the load port provided by the service isolate so that we can |
| 833 // load scripts. | 869 // load scripts. |
| 834 // With a full snapshot or a precompiled snapshot in product mode, there is | 870 // With a full snapshot or a precompiled snapshot in product mode, there is |
| 835 // no service isolate. A precompiled snapshot in release or debug mode does | 871 // no service isolate. A precompiled snapshot in release or debug mode does |
| 836 // have the service isolate, but it doesn't use it for loading. | 872 // have the service isolate, but it doesn't use it for loading. |
| 837 result = DartUtils::SetupServiceLoadPort(); | 873 result = DartUtils::SetupServiceLoadPort(); |
| 838 CHECK_RESULT(result); | 874 CHECK_RESULT(result); |
| 839 } | 875 } |
| 840 | 876 |
| 841 // Setup package root if specified. | 877 // Setup package root if specified. |
| 842 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 878 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
| 843 CHECK_RESULT(result); | 879 CHECK_RESULT(result); |
| 844 | 880 |
| 845 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 881 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 846 CHECK_RESULT(result); | 882 CHECK_RESULT(result); |
| 847 | 883 |
| 848 if (!run_precompiled_snapshot && !run_full_snapshot) { | 884 if (run_precompiled_snapshot) { |
| 885 // No setup. |
| 886 } else if (run_full_snapshot || run_precompiled_jit_snapshot) { |
| 887 result = DartUtils::SetupIOLibrary(script_uri); |
| 888 CHECK_RESULT(result); |
| 889 } else { |
| 849 // Load the specified application script into the newly created isolate. | 890 // Load the specified application script into the newly created isolate. |
| 850 result = DartUtils::LoadScript(script_uri); | 891 result = DartUtils::LoadScript(script_uri); |
| 851 CHECK_RESULT(result); | 892 CHECK_RESULT(result); |
| 852 | 893 |
| 853 // Run event-loop and wait for script loading to complete. | 894 // Run event-loop and wait for script loading to complete. |
| 854 result = Dart_RunLoop(); | 895 result = Dart_RunLoop(); |
| 855 CHECK_RESULT(result); | 896 CHECK_RESULT(result); |
| 856 | 897 |
| 857 Dart_TimelineEvent("LoadScript", | 898 Dart_TimelineEvent("LoadScript", |
| 858 Dart_TimelineGetMicros(), | 899 Dart_TimelineGetMicros(), |
| 859 Dart_GetMainPortId(), | 900 Dart_GetMainPortId(), |
| 860 Dart_Timeline_Event_Async_End, | 901 Dart_Timeline_Event_Async_End, |
| 861 0, NULL, NULL); | 902 0, NULL, NULL); |
| 862 | 903 |
| 863 result = DartUtils::SetupIOLibrary(script_uri); | 904 result = DartUtils::SetupIOLibrary(script_uri); |
| 864 CHECK_RESULT(result); | 905 CHECK_RESULT(result); |
| 865 } else if (run_full_snapshot) { | |
| 866 result = DartUtils::SetupIOLibrary(script_uri); | |
| 867 CHECK_RESULT(result); | |
| 868 } | 906 } |
| 869 | 907 |
| 870 // Make the isolate runnable so that it is ready to handle messages. | 908 // Make the isolate runnable so that it is ready to handle messages. |
| 871 Dart_ExitScope(); | 909 Dart_ExitScope(); |
| 872 Dart_ExitIsolate(); | 910 Dart_ExitIsolate(); |
| 873 bool retval = Dart_IsolateMakeRunnable(isolate); | 911 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 874 if (!retval) { | 912 if (!retval) { |
| 875 *error = strdup("Invalid isolate state - Unable to make it runnable"); | 913 *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| 876 Dart_EnterIsolate(isolate); | 914 Dart_EnterIsolate(isolate); |
| 877 Dart_ShutdownIsolate(); | 915 Dart_ShutdownIsolate(); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 intptr_t len = snprintf(NULL, 0, "%s.%s", filename, kVMIsolateSuffix); | 1279 intptr_t len = snprintf(NULL, 0, "%s.%s", filename, kVMIsolateSuffix); |
| 1242 *vm_snapshot_fname = new char[len + 1]; | 1280 *vm_snapshot_fname = new char[len + 1]; |
| 1243 snprintf(*vm_snapshot_fname, len + 1, "%s.%s", filename, kVMIsolateSuffix); | 1281 snprintf(*vm_snapshot_fname, len + 1, "%s.%s", filename, kVMIsolateSuffix); |
| 1244 | 1282 |
| 1245 len = snprintf(NULL, 0, "%s.%s", filename, kIsolateSuffix); | 1283 len = snprintf(NULL, 0, "%s.%s", filename, kIsolateSuffix); |
| 1246 *isolate_snapshot_fname = new char[len + 1]; | 1284 *isolate_snapshot_fname = new char[len + 1]; |
| 1247 snprintf(*isolate_snapshot_fname, len + 1, "%s.%s", filename, kIsolateSuffix); | 1285 snprintf(*isolate_snapshot_fname, len + 1, "%s.%s", filename, kIsolateSuffix); |
| 1248 } | 1286 } |
| 1249 | 1287 |
| 1250 | 1288 |
| 1289 static void GeneratePrecompiledSnapshot() { |
| 1290 uint8_t* vm_isolate_buffer = NULL; |
| 1291 intptr_t vm_isolate_size = 0; |
| 1292 uint8_t* isolate_buffer = NULL; |
| 1293 intptr_t isolate_size = 0; |
| 1294 uint8_t* assembly_buffer = NULL; |
| 1295 intptr_t assembly_size = 0; |
| 1296 uint8_t* instructions_blob_buffer = NULL; |
| 1297 intptr_t instructions_blob_size = 0; |
| 1298 uint8_t* rodata_blob_buffer = NULL; |
| 1299 intptr_t rodata_blob_size = 0; |
| 1300 Dart_Handle result; |
| 1301 if (use_blobs) { |
| 1302 result = Dart_CreatePrecompiledSnapshotBlob( |
| 1303 &vm_isolate_buffer, |
| 1304 &vm_isolate_size, |
| 1305 &isolate_buffer, |
| 1306 &isolate_size, |
| 1307 &instructions_blob_buffer, |
| 1308 &instructions_blob_size, |
| 1309 &rodata_blob_buffer, |
| 1310 &rodata_blob_size); |
| 1311 } else { |
| 1312 result = Dart_CreatePrecompiledSnapshotAssembly( |
| 1313 &vm_isolate_buffer, |
| 1314 &vm_isolate_size, |
| 1315 &isolate_buffer, |
| 1316 &isolate_size, |
| 1317 &assembly_buffer, |
| 1318 &assembly_size); |
| 1319 } |
| 1320 if (Dart_IsError(result)) { |
| 1321 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1322 } |
| 1323 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1324 kPrecompiledVmIsolateName, |
| 1325 false, |
| 1326 vm_isolate_buffer, |
| 1327 vm_isolate_size); |
| 1328 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1329 kPrecompiledIsolateName, |
| 1330 false, |
| 1331 isolate_buffer, |
| 1332 isolate_size); |
| 1333 if (use_blobs) { |
| 1334 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1335 kPrecompiledInstructionsBlobName, |
| 1336 false, |
| 1337 instructions_blob_buffer, |
| 1338 instructions_blob_size); |
| 1339 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1340 kPrecompiledRodataBlobName, |
| 1341 false, |
| 1342 rodata_blob_buffer, |
| 1343 rodata_blob_size); |
| 1344 } else { |
| 1345 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1346 kPrecompiledAssemblyName, |
| 1347 false, |
| 1348 assembly_buffer, |
| 1349 assembly_size); |
| 1350 } |
| 1351 } |
| 1352 |
| 1353 |
| 1354 static void GeneratePrecompiledJITSnapshot() { |
| 1355 uint8_t* vm_isolate_buffer = NULL; |
| 1356 intptr_t vm_isolate_size = 0; |
| 1357 uint8_t* isolate_buffer = NULL; |
| 1358 intptr_t isolate_size = 0; |
| 1359 uint8_t* instructions_blob_buffer = NULL; |
| 1360 intptr_t instructions_blob_size = 0; |
| 1361 uint8_t* rodata_blob_buffer = NULL; |
| 1362 intptr_t rodata_blob_size = 0; |
| 1363 Dart_Handle result = Dart_CreatePrecompiledJITSnapshotBlob( |
| 1364 &vm_isolate_buffer, |
| 1365 &vm_isolate_size, |
| 1366 &isolate_buffer, |
| 1367 &isolate_size, |
| 1368 &instructions_blob_buffer, |
| 1369 &instructions_blob_size, |
| 1370 &rodata_blob_buffer, |
| 1371 &rodata_blob_size); |
| 1372 if (Dart_IsError(result)) { |
| 1373 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1374 } |
| 1375 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1376 kPrecompiledVmIsolateName, |
| 1377 false, |
| 1378 vm_isolate_buffer, |
| 1379 vm_isolate_size); |
| 1380 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1381 kPrecompiledIsolateName, |
| 1382 false, |
| 1383 isolate_buffer, |
| 1384 isolate_size); |
| 1385 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1386 kPrecompiledInstructionsBlobName, |
| 1387 false, |
| 1388 instructions_blob_buffer, |
| 1389 instructions_blob_size); |
| 1390 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1391 kPrecompiledRodataBlobName, |
| 1392 false, |
| 1393 rodata_blob_buffer, |
| 1394 rodata_blob_size); |
| 1395 } |
| 1396 |
| 1397 |
| 1251 static void GenerateFullSnapshot() { | 1398 static void GenerateFullSnapshot() { |
| 1252 // Create a full snapshot of the script. | 1399 // Create a full snapshot of the script. |
| 1253 Dart_Handle result; | 1400 Dart_Handle result; |
| 1254 uint8_t* vm_isolate_buffer = NULL; | 1401 uint8_t* vm_isolate_buffer = NULL; |
| 1255 intptr_t vm_isolate_size = 0; | 1402 intptr_t vm_isolate_size = 0; |
| 1256 uint8_t* isolate_buffer = NULL; | 1403 uint8_t* isolate_buffer = NULL; |
| 1257 intptr_t isolate_size = 0; | 1404 intptr_t isolate_size = 0; |
| 1258 char* vm_snapshot_fname = NULL; | 1405 char* vm_snapshot_fname = NULL; |
| 1259 char* isolate_snapshot_fname = NULL; | 1406 char* isolate_snapshot_fname = NULL; |
| 1260 | 1407 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 } else { | 1491 } else { |
| 1345 // Lookup the library of the root script. | 1492 // Lookup the library of the root script. |
| 1346 Dart_Handle root_lib = Dart_RootLibrary(); | 1493 Dart_Handle root_lib = Dart_RootLibrary(); |
| 1347 // Import the root library into the builtin library so that we can easily | 1494 // Import the root library into the builtin library so that we can easily |
| 1348 // lookup the main entry point exported from the root library. | 1495 // lookup the main entry point exported from the root library. |
| 1349 IsolateData* isolate_data = | 1496 IsolateData* isolate_data = |
| 1350 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1497 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 1351 result = Dart_LibraryImportLibrary( | 1498 result = Dart_LibraryImportLibrary( |
| 1352 isolate_data->builtin_lib(), root_lib, Dart_Null()); | 1499 isolate_data->builtin_lib(), root_lib, Dart_Null()); |
| 1353 #if !defined(PRODUCT) | 1500 #if !defined(PRODUCT) |
| 1354 if (is_noopt || gen_precompiled_snapshot) { | 1501 if (is_noopt || gen_precompiled_snapshot || gen_precompiled_jit_snapshot) { |
| 1355 // Load the embedder's portion of the VM service's Dart code so it will | 1502 // Load the embedder's portion of the VM service's Dart code so it will |
| 1356 // be included in the precompiled snapshot. | 1503 // be included in the precompiled snapshot. |
| 1357 if (!VmService::LoadForGenPrecompiled()) { | 1504 if (!VmService::LoadForGenPrecompiled()) { |
| 1358 fprintf(stderr, | 1505 fprintf(stderr, |
| 1359 "VM service loading failed: %s\n", | 1506 "VM service loading failed: %s\n", |
| 1360 VmService::GetErrorMessage()); | 1507 VmService::GetErrorMessage()); |
| 1361 fflush(stderr); | 1508 fflush(stderr); |
| 1362 exit(kErrorExitCode); | 1509 exit(kErrorExitCode); |
| 1363 } | 1510 } |
| 1364 } | 1511 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 #endif // !PRODUCT | 1550 #endif // !PRODUCT |
| 1404 { NULL, NULL, NULL } // Must be terminated with NULL entries. | 1551 { NULL, NULL, NULL } // Must be terminated with NULL entries. |
| 1405 }; | 1552 }; |
| 1406 | 1553 |
| 1407 const bool reset_fields = gen_precompiled_snapshot; | 1554 const bool reset_fields = gen_precompiled_snapshot; |
| 1408 result = Dart_Precompile(standalone_entry_points, reset_fields); | 1555 result = Dart_Precompile(standalone_entry_points, reset_fields); |
| 1409 CHECK_RESULT(result); | 1556 CHECK_RESULT(result); |
| 1410 } | 1557 } |
| 1411 | 1558 |
| 1412 if (gen_precompiled_snapshot) { | 1559 if (gen_precompiled_snapshot) { |
| 1413 uint8_t* vm_isolate_buffer = NULL; | 1560 GeneratePrecompiledSnapshot(); |
| 1414 intptr_t vm_isolate_size = 0; | |
| 1415 uint8_t* isolate_buffer = NULL; | |
| 1416 intptr_t isolate_size = 0; | |
| 1417 uint8_t* assembly_buffer = NULL; | |
| 1418 intptr_t assembly_size = 0; | |
| 1419 uint8_t* instructions_blob_buffer = NULL; | |
| 1420 intptr_t instructions_blob_size = 0; | |
| 1421 uint8_t* rodata_blob_buffer = NULL; | |
| 1422 intptr_t rodata_blob_size = 0; | |
| 1423 if (use_blobs) { | |
| 1424 result = Dart_CreatePrecompiledSnapshotBlob( | |
| 1425 &vm_isolate_buffer, | |
| 1426 &vm_isolate_size, | |
| 1427 &isolate_buffer, | |
| 1428 &isolate_size, | |
| 1429 &instructions_blob_buffer, | |
| 1430 &instructions_blob_size, | |
| 1431 &rodata_blob_buffer, | |
| 1432 &rodata_blob_size); | |
| 1433 CHECK_RESULT(result); | |
| 1434 } else { | |
| 1435 result = Dart_CreatePrecompiledSnapshotAssembly( | |
| 1436 &vm_isolate_buffer, | |
| 1437 &vm_isolate_size, | |
| 1438 &isolate_buffer, | |
| 1439 &isolate_size, | |
| 1440 &assembly_buffer, | |
| 1441 &assembly_size); | |
| 1442 CHECK_RESULT(result); | |
| 1443 } | |
| 1444 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1445 kPrecompiledVmIsolateName, | |
| 1446 false, | |
| 1447 vm_isolate_buffer, | |
| 1448 vm_isolate_size); | |
| 1449 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1450 kPrecompiledIsolateName, | |
| 1451 false, | |
| 1452 isolate_buffer, | |
| 1453 isolate_size); | |
| 1454 if (use_blobs) { | |
| 1455 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1456 kPrecompiledInstructionsBlobName, | |
| 1457 false, | |
| 1458 instructions_blob_buffer, | |
| 1459 instructions_blob_size); | |
| 1460 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1461 kPrecompiledRodataBlobName, | |
| 1462 false, | |
| 1463 rodata_blob_buffer, | |
| 1464 rodata_blob_size); | |
| 1465 } else { | |
| 1466 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1467 kPrecompiledAssemblyName, | |
| 1468 false, | |
| 1469 assembly_buffer, | |
| 1470 assembly_size); | |
| 1471 } | |
| 1472 } else { | 1561 } else { |
| 1473 if (Dart_IsNull(root_lib)) { | 1562 if (Dart_IsNull(root_lib)) { |
| 1474 ErrorExit(kErrorExitCode, | 1563 ErrorExit(kErrorExitCode, |
| 1475 "Unable to find root library for '%s'\n", | 1564 "Unable to find root library for '%s'\n", |
| 1476 script_name); | 1565 script_name); |
| 1477 } | 1566 } |
| 1478 | 1567 |
| 1479 // The helper function _getMainClosure creates a closure for the main | 1568 // The helper function _getMainClosure creates a closure for the main |
| 1480 // entry point which is either explicitly or implictly exported from the | 1569 // entry point which is either explicitly or implictly exported from the |
| 1481 // root library. | 1570 // root library. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1493 Dart_Handle isolate_lib = | 1582 Dart_Handle isolate_lib = |
| 1494 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); | 1583 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
| 1495 result = Dart_Invoke(isolate_lib, | 1584 result = Dart_Invoke(isolate_lib, |
| 1496 Dart_NewStringFromCString("_startMainIsolate"), | 1585 Dart_NewStringFromCString("_startMainIsolate"), |
| 1497 kNumIsolateArgs, isolate_args); | 1586 kNumIsolateArgs, isolate_args); |
| 1498 CHECK_RESULT(result); | 1587 CHECK_RESULT(result); |
| 1499 | 1588 |
| 1500 // Keep handling messages until the last active receive port is closed. | 1589 // Keep handling messages until the last active receive port is closed. |
| 1501 result = Dart_RunLoop(); | 1590 result = Dart_RunLoop(); |
| 1502 // Generate a full snapshot after execution if specified. | 1591 // Generate a full snapshot after execution if specified. |
| 1503 if (generate_full_snapshot_after_run) { | 1592 if (generate_full_snapshot_after_run || gen_precompiled_jit_snapshot) { |
| 1504 if (!Dart_IsCompilationError(result) && | 1593 if (!Dart_IsCompilationError(result) && |
| 1505 !Dart_IsVMRestartRequest(result)) { | 1594 !Dart_IsVMRestartRequest(result)) { |
| 1506 GenerateFullSnapshot(); | 1595 if (generate_full_snapshot_after_run) { |
| 1596 GenerateFullSnapshot(); |
| 1597 } else { |
| 1598 Dart_Handle prepare_result = Dart_PrecompileJIT(); |
| 1599 CHECK_RESULT(prepare_result); |
| 1600 GeneratePrecompiledJITSnapshot(); |
| 1601 } |
| 1507 } | 1602 } |
| 1508 } | 1603 } |
| 1509 CHECK_RESULT(result); | 1604 CHECK_RESULT(result); |
| 1510 } | 1605 } |
| 1511 } | 1606 } |
| 1512 | 1607 |
| 1513 Dart_ExitScope(); | 1608 Dart_ExitScope(); |
| 1514 // Shutdown the isolate. | 1609 // Shutdown the isolate. |
| 1515 Dart_ShutdownIsolate(); | 1610 Dart_ShutdownIsolate(); |
| 1516 | 1611 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 OSError err; | 1753 OSError err; |
| 1659 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1754 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
| 1660 fflush(stderr); | 1755 fflush(stderr); |
| 1661 Platform::Exit(kErrorExitCode); | 1756 Platform::Exit(kErrorExitCode); |
| 1662 } | 1757 } |
| 1663 | 1758 |
| 1664 #if !defined(PRODUCT) | 1759 #if !defined(PRODUCT) |
| 1665 // Constant true in PRODUCT mode. | 1760 // Constant true in PRODUCT mode. |
| 1666 if (generate_script_snapshot || | 1761 if (generate_script_snapshot || |
| 1667 generate_full_snapshot_after_run || | 1762 generate_full_snapshot_after_run || |
| 1668 run_full_snapshot) { | 1763 run_full_snapshot || |
| 1764 gen_precompiled_jit_snapshot || |
| 1765 run_precompiled_jit_snapshot) { |
| 1669 vm_options.AddArgument("--load_deferred_eagerly"); | 1766 vm_options.AddArgument("--load_deferred_eagerly"); |
| 1670 } | 1767 } |
| 1671 #endif | 1768 #endif |
| 1672 | 1769 |
| 1673 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 1770 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
| 1674 // Always set --precompilation with dart_noopt. | 1771 // Always set --precompilation with dart_noopt. |
| 1675 ASSERT(!gen_precompiled_snapshot && !run_precompiled_snapshot); | 1772 ASSERT(!gen_precompiled_snapshot && !run_precompiled_snapshot); |
| 1676 vm_options.AddArgument("--precompilation"); | 1773 vm_options.AddArgument("--precompilation"); |
| 1677 #endif | 1774 #endif |
| 1678 | 1775 |
| 1679 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1776 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1680 | 1777 |
| 1681 // Start event handler. | 1778 // Start event handler. |
| 1682 TimerUtils::InitOnce(); | 1779 TimerUtils::InitOnce(); |
| 1683 EventHandler::Start(); | 1780 EventHandler::Start(); |
| 1684 | 1781 |
| 1685 const uint8_t* instructions_snapshot = NULL; | 1782 const uint8_t* instructions_snapshot = NULL; |
| 1686 const uint8_t* data_snapshot = NULL; | 1783 const uint8_t* data_snapshot = NULL; |
| 1687 if (run_precompiled_snapshot) { | 1784 if (run_precompiled_snapshot || run_precompiled_jit_snapshot) { |
| 1688 ReadSnapshotFile(precompiled_snapshot_directory, | 1785 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1689 kPrecompiledVmIsolateName, | 1786 kPrecompiledVmIsolateName, |
| 1690 &vm_isolate_snapshot_buffer); | 1787 &vm_isolate_snapshot_buffer); |
| 1691 ReadSnapshotFile(precompiled_snapshot_directory, | 1788 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1692 kPrecompiledIsolateName, | 1789 kPrecompiledIsolateName, |
| 1693 &isolate_snapshot_buffer); | 1790 &isolate_snapshot_buffer); |
| 1694 if (use_blobs) { | 1791 if (use_blobs) { |
| 1695 ReadExecutableSnapshotFile(precompiled_snapshot_directory, | 1792 ReadExecutableSnapshotFile(precompiled_snapshot_directory, |
| 1696 kPrecompiledInstructionsBlobName, | 1793 kPrecompiledInstructionsBlobName, |
| 1697 &instructions_snapshot); | 1794 &instructions_snapshot); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 Platform::Exit(Process::GlobalExitCode()); | 1884 Platform::Exit(Process::GlobalExitCode()); |
| 1788 } | 1885 } |
| 1789 | 1886 |
| 1790 } // namespace bin | 1887 } // namespace bin |
| 1791 } // namespace dart | 1888 } // namespace dart |
| 1792 | 1889 |
| 1793 int main(int argc, char** argv) { | 1890 int main(int argc, char** argv) { |
| 1794 dart::bin::main(argc, argv); | 1891 dart::bin::main(argc, argv); |
| 1795 UNREACHABLE(); | 1892 UNREACHABLE(); |
| 1796 } | 1893 } |
| OLD | NEW |