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 <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 116 |
117 // Global flag that is used to indicate that we want to compile all the | 117 // Global flag that is used to indicate that we want to compile all the |
118 // dart functions and not run anything. | 118 // dart functions and not run anything. |
119 static bool compile_all = false; | 119 static bool compile_all = false; |
120 static bool parse_all = false; | 120 static bool parse_all = false; |
121 | 121 |
122 // Global flag that is used to indicate that we want to use blobs/mmap instead | 122 // Global flag that is used to indicate that we want to use blobs/mmap instead |
123 // of assembly/shared libraries for precompilation. | 123 // of assembly/shared libraries for precompilation. |
124 static bool use_blobs = false; | 124 static bool use_blobs = false; |
125 | 125 |
126 // Global flag is used to indicate that we want to obfuscate identifiers. | |
127 static bool obfuscate = false; | |
rmacnak
2017/08/24 01:00:27
Flutter will want these options on gen_snapshot.
Vyacheslav Egorov (Google)
2017/08/24 14:27:19
I have added these options to the gen_snapshot. I
| |
128 | |
129 // Value of the --save-obfuscation-map= flag. | |
130 static const char* obfuscation_map_filename = NULL; | |
131 | |
126 // Global flag that is used to indicate that we want to trace resolution of | 132 // Global flag that is used to indicate that we want to trace resolution of |
127 // URIs and the loading of libraries, parts and scripts. | 133 // URIs and the loading of libraries, parts and scripts. |
128 static bool trace_loading = false; | 134 static bool trace_loading = false; |
129 | 135 |
130 static char* app_script_uri = NULL; | 136 static char* app_script_uri = NULL; |
131 static const uint8_t* app_isolate_snapshot_data = NULL; | 137 static const uint8_t* app_isolate_snapshot_data = NULL; |
132 static const uint8_t* app_isolate_snapshot_instructions = NULL; | 138 static const uint8_t* app_isolate_snapshot_instructions = NULL; |
133 | 139 |
134 static Dart_Isolate main_isolate = NULL; | 140 static Dart_Isolate main_isolate = NULL; |
135 | 141 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 static bool ProcessUseBlobsOption(const char* arg, | 377 static bool ProcessUseBlobsOption(const char* arg, |
372 CommandLineOptions* vm_options) { | 378 CommandLineOptions* vm_options) { |
373 ASSERT(arg != NULL); | 379 ASSERT(arg != NULL); |
374 if (*arg != '\0') { | 380 if (*arg != '\0') { |
375 return false; | 381 return false; |
376 } | 382 } |
377 use_blobs = true; | 383 use_blobs = true; |
378 return true; | 384 return true; |
379 } | 385 } |
380 | 386 |
387 static bool ProcessObfuscateOption(const char* arg, | |
388 CommandLineOptions* vm_options) { | |
389 ASSERT(arg != NULL); | |
390 if (*arg != '\0') { | |
391 return false; | |
392 } | |
393 obfuscate = true; | |
394 return true; | |
395 } | |
396 | |
397 static bool ProcessObfuscationMapFilenameOption( | |
398 const char* filename, | |
399 CommandLineOptions* vm_options) { | |
400 obfuscation_map_filename = filename; | |
401 return true; | |
402 } | |
403 | |
381 static bool ProcessSnapshotFilenameOption(const char* filename, | 404 static bool ProcessSnapshotFilenameOption(const char* filename, |
382 CommandLineOptions* vm_options) { | 405 CommandLineOptions* vm_options) { |
383 snapshot_filename = filename; | 406 snapshot_filename = filename; |
384 if (gen_snapshot_kind == kNone) { | 407 if (gen_snapshot_kind == kNone) { |
385 gen_snapshot_kind = kScript; // Default behavior. | 408 gen_snapshot_kind = kScript; // Default behavior. |
386 } | 409 } |
387 return true; | 410 return true; |
388 } | 411 } |
389 | 412 |
390 static bool ProcessSnapshotKindOption(const char* kind, | 413 static bool ProcessSnapshotKindOption(const char* kind, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 {"--dfe=", ProcessFrontendOption}, | 603 {"--dfe=", ProcessFrontendOption}, |
581 {"--kernel-binaries=", ProcessKernelBinariesOption}, | 604 {"--kernel-binaries=", ProcessKernelBinariesOption}, |
582 #endif | 605 #endif |
583 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 606 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
584 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 607 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
585 {"--observe", ProcessObserveOption}, | 608 {"--observe", ProcessObserveOption}, |
586 {"--snapshot=", ProcessSnapshotFilenameOption}, | 609 {"--snapshot=", ProcessSnapshotFilenameOption}, |
587 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 610 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
588 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, | 611 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, |
589 {"--use-blobs", ProcessUseBlobsOption}, | 612 {"--use-blobs", ProcessUseBlobsOption}, |
613 {"--obfuscate", ProcessObfuscateOption}, | |
614 {"--save-obfuscation-map=", ProcessObfuscationMapFilenameOption}, | |
590 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption}, | 615 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption}, |
591 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, | 616 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, |
592 {"--save-feedback=", ProcessSaveFeedbackOption}, | 617 {"--save-feedback=", ProcessSaveFeedbackOption}, |
593 {"--load-feedback=", ProcessLoadFeedbackOption}, | 618 {"--load-feedback=", ProcessLoadFeedbackOption}, |
594 {"--trace-loading", ProcessTraceLoadingOption}, | 619 {"--trace-loading", ProcessTraceLoadingOption}, |
595 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, | 620 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, |
596 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, | 621 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, |
597 {"--short_socket_read", ProcessShortSocketReadOption}, | 622 {"--short_socket_read", ProcessShortSocketReadOption}, |
598 {"--short_socket_write", ProcessShortSocketWriteOption}, | 623 {"--short_socket_write", ProcessShortSocketWriteOption}, |
599 {"--root-certs-file=", ProcessRootCertsFileOption}, | 624 {"--root-certs-file=", ProcessRootCertsFileOption}, |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); | 1432 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); |
1408 } | 1433 } |
1409 *size = file->Length(); | 1434 *size = file->Length(); |
1410 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); | 1435 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); |
1411 if (!file->ReadFully(*buffer, *size)) { | 1436 if (!file->ReadFully(*buffer, *size)) { |
1412 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename); | 1437 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename); |
1413 } | 1438 } |
1414 file->Release(); | 1439 file->Release(); |
1415 } | 1440 } |
1416 | 1441 |
1442 static Dart_QualifiedFunctionName standalone_entry_points[] = { | |
1443 // Functions. | |
1444 {"dart:_builtin", "::", "_getPrintClosure"}, | |
1445 {"dart:_builtin", "::", "_getUriBaseClosure"}, | |
1446 {"dart:_builtin", "::", "_libraryFilePath"}, | |
1447 {"dart:_builtin", "::", "_resolveInWorkingDirectory"}, | |
1448 {"dart:_builtin", "::", "_setPackageRoot"}, | |
1449 {"dart:_builtin", "::", "_setPackagesMap"}, | |
1450 {"dart:_builtin", "::", "_setWorkingDirectory"}, | |
1451 {"dart:async", "::", "_setScheduleImmediateClosure"}, | |
1452 {"dart:io", "::", "_getWatchSignalInternal"}, | |
1453 {"dart:io", "::", "_makeDatagram"}, | |
1454 {"dart:io", "::", "_makeUint8ListView"}, | |
1455 {"dart:io", "::", "_setupHooks"}, | |
1456 {"dart:io", "CertificateException", "CertificateException."}, | |
1457 {"dart:io", "Directory", "Directory."}, | |
1458 {"dart:io", "File", "File."}, | |
1459 {"dart:io", "FileSystemException", "FileSystemException."}, | |
1460 {"dart:io", "HandshakeException", "HandshakeException."}, | |
1461 {"dart:io", "Link", "Link."}, | |
1462 {"dart:io", "OSError", "OSError."}, | |
1463 {"dart:io", "TlsException", "TlsException."}, | |
1464 {"dart:io", "X509Certificate", "X509Certificate._"}, | |
1465 {"dart:io", "_ExternalBuffer", "get:end"}, | |
1466 {"dart:io", "_ExternalBuffer", "get:start"}, | |
1467 {"dart:io", "_ExternalBuffer", "set:data"}, | |
1468 {"dart:io", "_ExternalBuffer", "set:end"}, | |
1469 {"dart:io", "_ExternalBuffer", "set:start"}, | |
1470 {"dart:io", "_Platform", "set:_nativeScript"}, | |
1471 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, | |
1472 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, | |
1473 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, | |
1474 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, | |
1475 {"dart:io", "_SecureFilterImpl", "get:buffers"}, | |
1476 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"}, | |
1477 {"dart:isolate", "::", "_setupHooks"}, | |
1478 {"dart:isolate", "::", "_startMainIsolate"}, | |
1479 {"dart:vmservice_io", "::", "main"}, | |
1480 // Fields | |
1481 {"dart:_builtin", "::", "_isolateId"}, | |
1482 {"dart:_builtin", "::", "_loadPort"}, | |
1483 {"dart:_internal", "::", "_printClosure"}, | |
1484 {"dart:vmservice_io", "::", "_autoStart"}, | |
1485 {"dart:vmservice_io", "::", "_ip"}, | |
1486 {"dart:vmservice_io", "::", "_isFuchsia"}, | |
1487 {"dart:vmservice_io", "::", "_isWindows"}, | |
1488 {"dart:vmservice_io", "::", "_originCheckDisabled"}, | |
1489 {"dart:vmservice_io", "::", "_port"}, | |
1490 {"dart:vmservice_io", "::", "_signalWatch"}, | |
1491 {"dart:vmservice_io", "::", "_traceLoading"}, | |
1492 {NULL, NULL, NULL} // Must be terminated with NULL entries. | |
1493 }; | |
1494 | |
1417 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { | 1495 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { |
1418 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1496 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1419 // the specified application script. | 1497 // the specified application script. |
1420 char* error = NULL; | 1498 char* error = NULL; |
1421 bool is_main_isolate = true; | 1499 bool is_main_isolate = true; |
1422 int exit_code = 0; | 1500 int exit_code = 0; |
1423 char* isolate_name = BuildIsolateName(script_name, "main"); | 1501 char* isolate_name = BuildIsolateName(script_name, "main"); |
1502 Dart_IsolateFlags flags; | |
1503 Dart_IsolateFlagsInitialize(&flags); | |
1504 | |
1505 if (gen_snapshot_kind == kAppAOT) { | |
1506 flags.obfuscate = obfuscate; | |
1507 flags.entry_points = standalone_entry_points; | |
1508 } | |
1509 | |
1424 Dart_Isolate isolate = CreateIsolateAndSetupHelper( | 1510 Dart_Isolate isolate = CreateIsolateAndSetupHelper( |
1425 is_main_isolate, script_name, "main", commandline_package_root, | 1511 is_main_isolate, script_name, "main", commandline_package_root, |
1426 commandline_packages_file, NULL, &error, &exit_code); | 1512 commandline_packages_file, &flags, &error, &exit_code); |
1427 if (isolate == NULL) { | 1513 if (isolate == NULL) { |
1428 delete[] isolate_name; | 1514 delete[] isolate_name; |
1429 Log::PrintErr("%s\n", error); | 1515 Log::PrintErr("%s\n", error); |
1430 free(error); | 1516 free(error); |
1431 error = NULL; | 1517 error = NULL; |
1432 Process::TerminateExitCodeHandler(); | 1518 Process::TerminateExitCodeHandler(); |
1433 error = Dart_Cleanup(); | 1519 error = Dart_Cleanup(); |
1434 if (error != NULL) { | 1520 if (error != NULL) { |
1435 Log::PrintErr("VM cleanup failed: %s\n", error); | 1521 Log::PrintErr("VM cleanup failed: %s\n", error); |
1436 free(error); | 1522 free(error); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1490 if (parse_all) { | 1576 if (parse_all) { |
1491 result = Dart_ParseAll(); | 1577 result = Dart_ParseAll(); |
1492 CHECK_RESULT(result); | 1578 CHECK_RESULT(result); |
1493 Dart_ExitScope(); | 1579 Dart_ExitScope(); |
1494 // Shutdown the isolate. | 1580 // Shutdown the isolate. |
1495 Dart_ShutdownIsolate(); | 1581 Dart_ShutdownIsolate(); |
1496 return false; | 1582 return false; |
1497 } | 1583 } |
1498 | 1584 |
1499 if (gen_snapshot_kind == kAppAOT) { | 1585 if (gen_snapshot_kind == kAppAOT) { |
1500 Dart_QualifiedFunctionName standalone_entry_points[] = { | |
1501 {"dart:_builtin", "::", "_getPrintClosure"}, | |
1502 {"dart:_builtin", "::", "_getUriBaseClosure"}, | |
1503 {"dart:_builtin", "::", "_libraryFilePath"}, | |
1504 {"dart:_builtin", "::", "_resolveInWorkingDirectory"}, | |
1505 {"dart:_builtin", "::", "_setPackageRoot"}, | |
1506 {"dart:_builtin", "::", "_setPackagesMap"}, | |
1507 {"dart:_builtin", "::", "_setWorkingDirectory"}, | |
1508 {"dart:async", "::", "_setScheduleImmediateClosure"}, | |
1509 {"dart:io", "::", "_getWatchSignalInternal"}, | |
1510 {"dart:io", "::", "_makeDatagram"}, | |
1511 {"dart:io", "::", "_makeUint8ListView"}, | |
1512 {"dart:io", "::", "_setupHooks"}, | |
1513 {"dart:io", "CertificateException", "CertificateException."}, | |
1514 {"dart:io", "Directory", "Directory."}, | |
1515 {"dart:io", "File", "File."}, | |
1516 {"dart:io", "FileSystemException", "FileSystemException."}, | |
1517 {"dart:io", "HandshakeException", "HandshakeException."}, | |
1518 {"dart:io", "Link", "Link."}, | |
1519 {"dart:io", "OSError", "OSError."}, | |
1520 {"dart:io", "TlsException", "TlsException."}, | |
1521 {"dart:io", "X509Certificate", "X509Certificate._"}, | |
1522 {"dart:io", "_ExternalBuffer", "get:end"}, | |
1523 {"dart:io", "_ExternalBuffer", "get:start"}, | |
1524 {"dart:io", "_ExternalBuffer", "set:data"}, | |
1525 {"dart:io", "_ExternalBuffer", "set:end"}, | |
1526 {"dart:io", "_ExternalBuffer", "set:start"}, | |
1527 {"dart:io", "_Platform", "set:_nativeScript"}, | |
1528 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, | |
1529 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, | |
1530 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, | |
1531 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, | |
1532 {"dart:io", "_SecureFilterImpl", "get:buffers"}, | |
1533 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"}, | |
1534 {"dart:isolate", "::", "_setupHooks"}, | |
1535 {"dart:isolate", "::", "_startMainIsolate"}, | |
1536 {"dart:vmservice_io", "::", "main"}, | |
1537 {NULL, NULL, NULL} // Must be terminated with NULL entries. | |
1538 }; | |
1539 | |
1540 uint8_t* feedback_buffer = NULL; | 1586 uint8_t* feedback_buffer = NULL; |
1541 intptr_t feedback_length = 0; | 1587 intptr_t feedback_length = 0; |
1542 if (load_feedback_filename != NULL) { | 1588 if (load_feedback_filename != NULL) { |
1543 File* file = File::Open(load_feedback_filename, File::kRead); | 1589 File* file = File::Open(load_feedback_filename, File::kRead); |
1544 if (file == NULL) { | 1590 if (file == NULL) { |
1545 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 1591 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); |
1546 } | 1592 } |
1547 feedback_length = file->Length(); | 1593 feedback_length = file->Length(); |
1548 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); | 1594 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); |
1549 if (!file->ReadFully(feedback_buffer, feedback_length)) { | 1595 if (!file->ReadFully(feedback_buffer, feedback_length)) { |
1550 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 1596 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); |
1551 } | 1597 } |
1552 file->Release(); | 1598 file->Release(); |
1553 } | 1599 } |
1554 | 1600 |
1555 result = Dart_Precompile(standalone_entry_points, feedback_buffer, | 1601 result = Dart_Precompile(standalone_entry_points, feedback_buffer, |
1556 feedback_length); | 1602 feedback_length); |
1557 if (feedback_buffer != NULL) { | 1603 if (feedback_buffer != NULL) { |
1558 free(feedback_buffer); | 1604 free(feedback_buffer); |
1559 } | 1605 } |
1560 CHECK_RESULT(result); | 1606 CHECK_RESULT(result); |
1607 | |
1608 if (obfuscate && obfuscation_map_filename != NULL) { | |
1609 uint8_t* buffer = NULL; | |
1610 intptr_t size = 0; | |
1611 result = Dart_GetObfuscationMap(&buffer, &size); | |
1612 CHECK_RESULT(result); | |
1613 WriteFile(obfuscation_map_filename, buffer, size); | |
1614 } | |
1561 } | 1615 } |
1562 | 1616 |
1563 if (gen_snapshot_kind == kAppAOT) { | 1617 if (gen_snapshot_kind == kAppAOT) { |
1564 GenerateAppAOTSnapshot(); | 1618 GenerateAppAOTSnapshot(); |
1565 } else { | 1619 } else { |
1566 if (Dart_IsNull(root_lib)) { | 1620 if (Dart_IsNull(root_lib)) { |
1567 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", | 1621 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", |
1568 script_name); | 1622 script_name); |
1569 } | 1623 } |
1570 | 1624 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1868 Platform::Exit(Process::GlobalExitCode()); | 1922 Platform::Exit(Process::GlobalExitCode()); |
1869 } | 1923 } |
1870 | 1924 |
1871 } // namespace bin | 1925 } // namespace bin |
1872 } // namespace dart | 1926 } // namespace dart |
1873 | 1927 |
1874 int main(int argc, char** argv) { | 1928 int main(int argc, char** argv) { |
1875 dart::bin::main(argc, argv); | 1929 dart::bin::main(argc, argv); |
1876 UNREACHABLE(); | 1930 UNREACHABLE(); |
1877 } | 1931 } |
OLD | NEW |