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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 79 |
80 | 80 |
81 // Global flag that is used to indicate that we want to run from a precompiled | 81 // Global flag that is used to indicate that we want to run from a precompiled |
82 // snapshot. | 82 // snapshot. |
83 static bool run_precompiled_snapshot = false; | 83 static bool run_precompiled_snapshot = false; |
84 | 84 |
85 | 85 |
| 86 // Global flag that is used to indicate that we want to use blobs/mmap instead |
| 87 // of assembly/shared libraries for precompilation. |
| 88 static bool use_blobs = false; |
| 89 |
| 90 |
86 // Value of the --gen/run_precompiled_snapshot flag. | 91 // Value of the --gen/run_precompiled_snapshot flag. |
87 // (This pointer points into an argv buffer and does not need to be | 92 // (This pointer points into an argv buffer and does not need to be |
88 // free'd.) | 93 // free'd.) |
89 static const char* precompiled_snapshot_directory = NULL; | 94 static const char* precompiled_snapshot_directory = NULL; |
90 | 95 |
91 | 96 |
92 // Global flag that is used to indicate that we want to compile everything in | 97 // Global flag that is used to indicate that we want to compile everything in |
93 // the same way as precompilation before main, then continue running in the | 98 // the same way as precompilation before main, then continue running in the |
94 // same process. | 99 // same process. |
95 // Always set this with dart_noopt. | 100 // Always set this with dart_noopt. |
96 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 101 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
97 static const bool is_noopt = true; | 102 static const bool is_noopt = true; |
98 #else | 103 #else |
99 static const bool is_noopt = false; | 104 static const bool is_noopt = false; |
100 #endif | 105 #endif |
101 | 106 |
102 | 107 |
103 extern const char* kPrecompiledLibraryName; | 108 extern const char* kPrecompiledLibraryName; |
104 extern const char* kPrecompiledInstructionsSymbolName; | 109 extern const char* kPrecompiledInstructionsSymbolName; |
105 extern const char* kPrecompiledDataSymbolName; | 110 extern const char* kPrecompiledDataSymbolName; |
106 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; | 111 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; |
107 static const char* kPrecompiledIsolateName = "precompiled.isolate"; | 112 static const char* kPrecompiledIsolateName = "precompiled.isolate"; |
108 static const char* kPrecompiledInstructionsName = "precompiled.S"; | 113 static const char* kPrecompiledAssemblyName = "precompiled.S"; |
| 114 static const char* kPrecompiledInstructionsBlobName = |
| 115 "precompiled.instructions"; |
| 116 static const char* kPrecompiledRodataBlobName = "precompiled.rodata"; |
109 static const char* kVMIsolateSuffix = "vmisolate"; | 117 static const char* kVMIsolateSuffix = "vmisolate"; |
110 static const char* kIsolateSuffix = "isolate"; | 118 static const char* kIsolateSuffix = "isolate"; |
111 | 119 |
112 // Global flag that is used to indicate that we want to trace resolution of | 120 // Global flag that is used to indicate that we want to trace resolution of |
113 // URIs and the loading of libraries, parts and scripts. | 121 // URIs and the loading of libraries, parts and scripts. |
114 static bool trace_loading = false; | 122 static bool trace_loading = false; |
115 | 123 |
116 | 124 |
117 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 125 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
118 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 126 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 CommandLineOptions* vm_options) { | 327 CommandLineOptions* vm_options) { |
320 ASSERT(arg != NULL); | 328 ASSERT(arg != NULL); |
321 if (*arg != '\0') { | 329 if (*arg != '\0') { |
322 return false; | 330 return false; |
323 } | 331 } |
324 compile_all = true; | 332 compile_all = true; |
325 return true; | 333 return true; |
326 } | 334 } |
327 | 335 |
328 | 336 |
| 337 static bool ProcessUseBlobsOption(const char* arg, |
| 338 CommandLineOptions* vm_options) { |
| 339 ASSERT(arg != NULL); |
| 340 if (*arg != '\0') { |
| 341 return false; |
| 342 } |
| 343 use_blobs = true; |
| 344 return true; |
| 345 } |
| 346 |
| 347 |
329 static bool ProcessGenPrecompiledSnapshotOption( | 348 static bool ProcessGenPrecompiledSnapshotOption( |
330 const char* arg, | 349 const char* arg, |
331 CommandLineOptions* vm_options) { | 350 CommandLineOptions* vm_options) { |
332 #if !defined(DART_PRECOMPILER) | 351 #if !defined(DART_PRECOMPILER) |
333 Log::PrintErr("Precompiled snapshots must be generated with " | 352 Log::PrintErr("Precompiled snapshots must be generated with " |
334 "dart_bootstrap.\n"); | 353 "dart_bootstrap.\n"); |
335 return false; | 354 return false; |
336 #else // defined(DART_PRECOMPILER) | 355 #else // defined(DART_PRECOMPILER) |
337 ASSERT(arg != NULL); | 356 ASSERT(arg != NULL); |
338 if ((arg[0] == '=') || (arg[0] == ':')) { | 357 if ((arg[0] == '=') || (arg[0] == ':')) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 { "-h", ProcessHelpOption }, | 525 { "-h", ProcessHelpOption }, |
507 { "--help", ProcessHelpOption }, | 526 { "--help", ProcessHelpOption }, |
508 { "--packages=", ProcessPackagesOption }, | 527 { "--packages=", ProcessPackagesOption }, |
509 { "--package-root=", ProcessPackageRootOption }, | 528 { "--package-root=", ProcessPackageRootOption }, |
510 { "-v", ProcessVerboseOption }, | 529 { "-v", ProcessVerboseOption }, |
511 { "--verbose", ProcessVerboseOption }, | 530 { "--verbose", ProcessVerboseOption }, |
512 { "--version", ProcessVersionOption }, | 531 { "--version", ProcessVersionOption }, |
513 | 532 |
514 // VM specific options to the standalone dart program. | 533 // VM specific options to the standalone dart program. |
515 { "--compile_all", ProcessCompileAllOption }, | 534 { "--compile_all", ProcessCompileAllOption }, |
| 535 { "--use_blobs", ProcessUseBlobsOption }, |
516 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 536 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
517 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, | 537 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, |
518 { "--observe", ProcessObserveOption }, | 538 { "--observe", ProcessObserveOption }, |
519 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, | 539 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, |
520 { "--shutdown", ProcessShutdownOption }, | 540 { "--shutdown", ProcessShutdownOption }, |
521 { "--snapshot=", ProcessScriptSnapshotOption }, | 541 { "--snapshot=", ProcessScriptSnapshotOption }, |
522 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, | 542 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, |
523 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, | 543 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, |
524 { "--trace-loading", ProcessTraceLoadingOption }, | 544 { "--trace-loading", ProcessTraceLoadingOption }, |
525 { NULL, NULL } | 545 { NULL, NULL } |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 fflush(stderr); | 1156 fflush(stderr); |
1137 Platform::Exit(kErrorExitCode); | 1157 Platform::Exit(kErrorExitCode); |
1138 } | 1158 } |
1139 DartUtils::CloseFile(file); | 1159 DartUtils::CloseFile(file); |
1140 if (concat != NULL) { | 1160 if (concat != NULL) { |
1141 delete concat; | 1161 delete concat; |
1142 } | 1162 } |
1143 } | 1163 } |
1144 | 1164 |
1145 | 1165 |
| 1166 static void ReadExecutableSnapshotFile(const char* snapshot_directory, |
| 1167 const char* filename, |
| 1168 const uint8_t** buffer) { |
| 1169 char* concat = NULL; |
| 1170 const char* qualified_filename; |
| 1171 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { |
| 1172 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
| 1173 concat = new char[len + 1]; |
| 1174 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1175 qualified_filename = concat; |
| 1176 } else { |
| 1177 qualified_filename = filename; |
| 1178 } |
| 1179 |
| 1180 intptr_t len = -1; |
| 1181 *buffer = reinterpret_cast<uint8_t*>( |
| 1182 DartUtils::MapExecutable(qualified_filename, &len)); |
| 1183 if ((*buffer == NULL) || (len == -1)) { |
| 1184 fprintf(stderr, |
| 1185 "Error: Unable to read snapshot file %s\n", qualified_filename); |
| 1186 fflush(stderr); |
| 1187 Platform::Exit(kErrorExitCode); |
| 1188 } |
| 1189 if (concat != NULL) { |
| 1190 delete concat; |
| 1191 } |
| 1192 } |
| 1193 |
| 1194 |
1146 static void* LoadLibrarySymbol(const char* snapshot_directory, | 1195 static void* LoadLibrarySymbol(const char* snapshot_directory, |
1147 const char* libname, | 1196 const char* libname, |
1148 const char* symname) { | 1197 const char* symname) { |
1149 char* concat = NULL; | 1198 char* concat = NULL; |
1150 const char* qualified_libname; | 1199 const char* qualified_libname; |
1151 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { | 1200 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { |
1152 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); | 1201 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); |
1153 concat = new char[len + 1]; | 1202 concat = new char[len + 1]; |
1154 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); | 1203 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); |
1155 qualified_libname = concat; | 1204 qualified_libname = concat; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 const bool reset_fields = gen_precompiled_snapshot; | 1407 const bool reset_fields = gen_precompiled_snapshot; |
1359 result = Dart_Precompile(standalone_entry_points, reset_fields); | 1408 result = Dart_Precompile(standalone_entry_points, reset_fields); |
1360 CHECK_RESULT(result); | 1409 CHECK_RESULT(result); |
1361 } | 1410 } |
1362 | 1411 |
1363 if (gen_precompiled_snapshot) { | 1412 if (gen_precompiled_snapshot) { |
1364 uint8_t* vm_isolate_buffer = NULL; | 1413 uint8_t* vm_isolate_buffer = NULL; |
1365 intptr_t vm_isolate_size = 0; | 1414 intptr_t vm_isolate_size = 0; |
1366 uint8_t* isolate_buffer = NULL; | 1415 uint8_t* isolate_buffer = NULL; |
1367 intptr_t isolate_size = 0; | 1416 intptr_t isolate_size = 0; |
1368 uint8_t* instructions_buffer = NULL; | 1417 uint8_t* assembly_buffer = NULL; |
1369 intptr_t instructions_size = 0; | 1418 intptr_t assembly_size = 0; |
1370 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, | 1419 uint8_t* instructions_blob_buffer = NULL; |
1371 &vm_isolate_size, | 1420 intptr_t instructions_blob_size = NULL; |
1372 &isolate_buffer, | 1421 uint8_t* rodata_blob_buffer = NULL; |
1373 &isolate_size, | 1422 intptr_t rodata_blob_size = NULL; |
1374 &instructions_buffer, | 1423 if (use_blobs) { |
1375 &instructions_size); | 1424 result = Dart_CreatePrecompiledSnapshotBlob( |
1376 CHECK_RESULT(result); | 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 } |
1377 WriteSnapshotFile(precompiled_snapshot_directory, | 1444 WriteSnapshotFile(precompiled_snapshot_directory, |
1378 kPrecompiledVmIsolateName, | 1445 kPrecompiledVmIsolateName, |
1379 false, | 1446 false, |
1380 vm_isolate_buffer, | 1447 vm_isolate_buffer, |
1381 vm_isolate_size); | 1448 vm_isolate_size); |
1382 WriteSnapshotFile(precompiled_snapshot_directory, | 1449 WriteSnapshotFile(precompiled_snapshot_directory, |
1383 kPrecompiledIsolateName, | 1450 kPrecompiledIsolateName, |
1384 false, | 1451 false, |
1385 isolate_buffer, | 1452 isolate_buffer, |
1386 isolate_size); | 1453 isolate_size); |
1387 WriteSnapshotFile(precompiled_snapshot_directory, | 1454 if (use_blobs) { |
1388 kPrecompiledInstructionsName, | 1455 WriteSnapshotFile(precompiled_snapshot_directory, |
1389 false, | 1456 kPrecompiledInstructionsBlobName, |
1390 instructions_buffer, | 1457 false, |
1391 instructions_size); | 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 } |
1392 } else { | 1472 } else { |
1393 if (Dart_IsNull(root_lib)) { | 1473 if (Dart_IsNull(root_lib)) { |
1394 ErrorExit(kErrorExitCode, | 1474 ErrorExit(kErrorExitCode, |
1395 "Unable to find root library for '%s'\n", | 1475 "Unable to find root library for '%s'\n", |
1396 script_name); | 1476 script_name); |
1397 } | 1477 } |
1398 | 1478 |
1399 // The helper function _getMainClosure creates a closure for the main | 1479 // The helper function _getMainClosure creates a closure for the main |
1400 // entry point which is either explicitly or implictly exported from the | 1480 // entry point which is either explicitly or implictly exported from the |
1401 // root library. | 1481 // root library. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 | 1678 |
1599 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1679 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1600 | 1680 |
1601 // Start event handler. | 1681 // Start event handler. |
1602 TimerUtils::InitOnce(); | 1682 TimerUtils::InitOnce(); |
1603 EventHandler::Start(); | 1683 EventHandler::Start(); |
1604 | 1684 |
1605 const uint8_t* instructions_snapshot = NULL; | 1685 const uint8_t* instructions_snapshot = NULL; |
1606 const uint8_t* data_snapshot = NULL; | 1686 const uint8_t* data_snapshot = NULL; |
1607 if (run_precompiled_snapshot) { | 1687 if (run_precompiled_snapshot) { |
1608 instructions_snapshot = reinterpret_cast<const uint8_t*>( | |
1609 LoadLibrarySymbol(precompiled_snapshot_directory, | |
1610 kPrecompiledLibraryName, | |
1611 kPrecompiledInstructionsSymbolName)); | |
1612 data_snapshot = reinterpret_cast<const uint8_t*>( | |
1613 LoadLibrarySymbol(precompiled_snapshot_directory, | |
1614 kPrecompiledLibraryName, | |
1615 kPrecompiledDataSymbolName)); | |
1616 ReadSnapshotFile(precompiled_snapshot_directory, | 1688 ReadSnapshotFile(precompiled_snapshot_directory, |
1617 kPrecompiledVmIsolateName, | 1689 kPrecompiledVmIsolateName, |
1618 &vm_isolate_snapshot_buffer); | 1690 &vm_isolate_snapshot_buffer); |
1619 ReadSnapshotFile(precompiled_snapshot_directory, | 1691 ReadSnapshotFile(precompiled_snapshot_directory, |
1620 kPrecompiledIsolateName, | 1692 kPrecompiledIsolateName, |
1621 &isolate_snapshot_buffer); | 1693 &isolate_snapshot_buffer); |
1622 | 1694 if (use_blobs) { |
| 1695 ReadExecutableSnapshotFile(precompiled_snapshot_directory, |
| 1696 kPrecompiledInstructionsBlobName, |
| 1697 &instructions_snapshot); |
| 1698 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1699 kPrecompiledRodataBlobName, |
| 1700 &data_snapshot); |
| 1701 } else { |
| 1702 instructions_snapshot = reinterpret_cast<const uint8_t*>( |
| 1703 LoadLibrarySymbol(precompiled_snapshot_directory, |
| 1704 kPrecompiledLibraryName, |
| 1705 kPrecompiledInstructionsSymbolName)); |
| 1706 data_snapshot = reinterpret_cast<const uint8_t*>( |
| 1707 LoadLibrarySymbol(precompiled_snapshot_directory, |
| 1708 kPrecompiledLibraryName, |
| 1709 kPrecompiledDataSymbolName)); |
| 1710 } |
1623 } else if (run_full_snapshot) { | 1711 } else if (run_full_snapshot) { |
1624 char* vm_snapshot_fname; | 1712 char* vm_snapshot_fname; |
1625 char* isolate_snapshot_fname; | 1713 char* isolate_snapshot_fname; |
1626 | 1714 |
1627 // Compute file names. | 1715 // Compute file names. |
1628 ComputeSnapshotFilenames(snapshot_filename, | 1716 ComputeSnapshotFilenames(snapshot_filename, |
1629 &vm_snapshot_fname, | 1717 &vm_snapshot_fname, |
1630 &isolate_snapshot_fname); | 1718 &isolate_snapshot_fname); |
1631 | 1719 |
1632 ReadSnapshotFile(NULL, vm_snapshot_fname, &vm_isolate_snapshot_buffer); | 1720 ReadSnapshotFile(NULL, vm_snapshot_fname, &vm_isolate_snapshot_buffer); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 Platform::Exit(Process::GlobalExitCode()); | 1787 Platform::Exit(Process::GlobalExitCode()); |
1700 } | 1788 } |
1701 | 1789 |
1702 } // namespace bin | 1790 } // namespace bin |
1703 } // namespace dart | 1791 } // namespace dart |
1704 | 1792 |
1705 int main(int argc, char** argv) { | 1793 int main(int argc, char** argv) { |
1706 dart::bin::main(argc, argv); | 1794 dart::bin::main(argc, argv); |
1707 UNREACHABLE(); | 1795 UNREACHABLE(); |
1708 } | 1796 } |
OLD | NEW |