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 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 uint8_t* isolate_buffer = NULL; | 1473 uint8_t* isolate_buffer = NULL; |
1474 intptr_t isolate_size = 0; | 1474 intptr_t isolate_size = 0; |
1475 uint8_t* assembly_buffer = NULL; | 1475 uint8_t* assembly_buffer = NULL; |
1476 intptr_t assembly_size = 0; | 1476 intptr_t assembly_size = 0; |
1477 uint8_t* instructions_blob_buffer = NULL; | 1477 uint8_t* instructions_blob_buffer = NULL; |
1478 intptr_t instructions_blob_size = 0; | 1478 intptr_t instructions_blob_size = 0; |
1479 uint8_t* rodata_blob_buffer = NULL; | 1479 uint8_t* rodata_blob_buffer = NULL; |
1480 intptr_t rodata_blob_size = 0; | 1480 intptr_t rodata_blob_size = 0; |
1481 Dart_Handle result; | 1481 Dart_Handle result; |
1482 if (use_blobs) { | 1482 if (use_blobs) { |
1483 result = Dart_CreatePrecompiledSnapshotBlob( | 1483 result = Dart_CreateAppAOTSnapshotAsBlobs( |
1484 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, | 1484 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, |
1485 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, | 1485 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, |
1486 &rodata_blob_size); | 1486 &rodata_blob_size); |
1487 } else { | 1487 } else { |
1488 result = Dart_CreatePrecompiledSnapshotAssembly(&assembly_buffer, | 1488 result = |
1489 &assembly_size); | 1489 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); |
1490 } | 1490 } |
1491 if (Dart_IsError(result)) { | 1491 if (Dart_IsError(result)) { |
1492 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1492 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1493 } | 1493 } |
1494 if (use_blobs) { | 1494 if (use_blobs) { |
1495 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, | 1495 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
1496 isolate_buffer, isolate_size, instructions_blob_buffer, | 1496 isolate_buffer, isolate_size, instructions_blob_buffer, |
1497 instructions_blob_size, rodata_blob_buffer, | 1497 instructions_blob_size, rodata_blob_buffer, |
1498 rodata_blob_size); | 1498 rodata_blob_size); |
1499 } else { | 1499 } else { |
1500 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); | 1500 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); |
1501 } | 1501 } |
1502 } | 1502 } |
1503 | 1503 |
1504 | 1504 |
| 1505 static void GenerateAppJITSnapshot() { |
1505 #if defined(TARGET_ARCH_X64) | 1506 #if defined(TARGET_ARCH_X64) |
1506 static void GenerateAppJITSnapshot() { | |
1507 uint8_t* vm_isolate_buffer = NULL; | 1507 uint8_t* vm_isolate_buffer = NULL; |
1508 intptr_t vm_isolate_size = 0; | 1508 intptr_t vm_isolate_size = 0; |
1509 uint8_t* isolate_buffer = NULL; | 1509 uint8_t* isolate_buffer = NULL; |
1510 intptr_t isolate_size = 0; | 1510 intptr_t isolate_size = 0; |
1511 uint8_t* instructions_blob_buffer = NULL; | 1511 uint8_t* instructions_blob_buffer = NULL; |
1512 intptr_t instructions_blob_size = 0; | 1512 intptr_t instructions_blob_size = 0; |
1513 uint8_t* rodata_blob_buffer = NULL; | 1513 uint8_t* rodata_blob_buffer = NULL; |
1514 intptr_t rodata_blob_size = 0; | 1514 intptr_t rodata_blob_size = 0; |
1515 Dart_Handle result = Dart_CreateAppJITSnapshot( | 1515 Dart_Handle result = Dart_CreateAppJITSnapshotAsBlobs( |
1516 &isolate_buffer, &isolate_size, &instructions_blob_buffer, | 1516 &isolate_buffer, &isolate_size, &instructions_blob_buffer, |
1517 &instructions_blob_size, &rodata_blob_buffer, &rodata_blob_size); | 1517 &instructions_blob_size, &rodata_blob_buffer, &rodata_blob_size); |
1518 if (Dart_IsError(result)) { | 1518 if (Dart_IsError(result)) { |
1519 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1519 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1520 } | 1520 } |
1521 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, | 1521 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
1522 isolate_buffer, isolate_size, instructions_blob_buffer, | 1522 isolate_buffer, isolate_size, instructions_blob_buffer, |
1523 instructions_blob_size, rodata_blob_buffer, | 1523 instructions_blob_size, rodata_blob_buffer, |
1524 rodata_blob_size); | 1524 rodata_blob_size); |
1525 } | |
1526 #endif // defined(TARGET_ARCH_X64) | |
1527 | |
1528 | |
1529 static void GenerateAppSnapshot() { | |
1530 Dart_Handle result; | |
1531 #if defined(TARGET_ARCH_X64) | |
1532 result = Dart_PrecompileJIT(); | |
1533 if (Dart_IsError(result)) { | |
1534 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | |
1535 } | |
1536 GenerateAppJITSnapshot(); | |
1537 #else | 1525 #else |
1538 // Create an application snapshot of the script. | |
1539 uint8_t* vm_isolate_buffer = NULL; | 1526 uint8_t* vm_isolate_buffer = NULL; |
1540 intptr_t vm_isolate_size = 0; | 1527 intptr_t vm_isolate_size = 0; |
1541 uint8_t* isolate_buffer = NULL; | 1528 uint8_t* isolate_buffer = NULL; |
1542 intptr_t isolate_size = 0; | 1529 intptr_t isolate_size = 0; |
1543 | 1530 |
1544 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, | 1531 Dart_Handle result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, |
1545 &isolate_buffer, &isolate_size); | 1532 &isolate_buffer, &isolate_size); |
1546 if (Dart_IsError(result)) { | 1533 if (Dart_IsError(result)) { |
1547 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1534 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1548 } | 1535 } |
1549 | 1536 |
1550 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, | 1537 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
1551 isolate_buffer, isolate_size, NULL, 0, NULL, 0); | 1538 isolate_buffer, isolate_size, NULL, 0, NULL, 0); |
1552 #endif // defined(TARGET_ARCH_X64) | 1539 #endif // defined(TARGET_ARCH_X64) |
1553 } | 1540 } |
1554 | 1541 |
1555 | 1542 |
(...skipping 13 matching lines...) Expand all Loading... |
1569 | 1556 |
1570 static void SnapshotOnExitHook(int64_t exit_code) { | 1557 static void SnapshotOnExitHook(int64_t exit_code) { |
1571 if (Dart_CurrentIsolate() != main_isolate) { | 1558 if (Dart_CurrentIsolate() != main_isolate) { |
1572 Log::PrintErr( | 1559 Log::PrintErr( |
1573 "A snapshot was requested, but a secondary isolate " | 1560 "A snapshot was requested, but a secondary isolate " |
1574 "performed a hard exit (%" Pd64 ").\n", | 1561 "performed a hard exit (%" Pd64 ").\n", |
1575 exit_code); | 1562 exit_code); |
1576 Platform::Exit(kErrorExitCode); | 1563 Platform::Exit(kErrorExitCode); |
1577 } | 1564 } |
1578 if (exit_code == 0) { | 1565 if (exit_code == 0) { |
1579 GenerateAppSnapshot(); | 1566 GenerateAppJITSnapshot(); |
1580 } | 1567 } |
1581 } | 1568 } |
1582 | 1569 |
1583 | 1570 |
1584 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { | 1571 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { |
1585 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1572 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1586 // the specified application script. | 1573 // the specified application script. |
1587 char* error = NULL; | 1574 char* error = NULL; |
1588 int exit_code = 0; | 1575 int exit_code = 0; |
1589 char* isolate_name = BuildIsolateName(script_name, "main"); | 1576 char* isolate_name = BuildIsolateName(script_name, "main"); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 Dart_NewStringFromCString("_startMainIsolate"), | 1730 Dart_NewStringFromCString("_startMainIsolate"), |
1744 kNumIsolateArgs, isolate_args); | 1731 kNumIsolateArgs, isolate_args); |
1745 CHECK_RESULT(result); | 1732 CHECK_RESULT(result); |
1746 | 1733 |
1747 // Keep handling messages until the last active receive port is closed. | 1734 // Keep handling messages until the last active receive port is closed. |
1748 result = Dart_RunLoop(); | 1735 result = Dart_RunLoop(); |
1749 // Generate an app snapshot after execution if specified. | 1736 // Generate an app snapshot after execution if specified. |
1750 if (gen_snapshot_kind == kAppJIT) { | 1737 if (gen_snapshot_kind == kAppJIT) { |
1751 if (!Dart_IsCompilationError(result) && | 1738 if (!Dart_IsCompilationError(result) && |
1752 !Dart_IsVMRestartRequest(result)) { | 1739 !Dart_IsVMRestartRequest(result)) { |
1753 GenerateAppSnapshot(); | 1740 GenerateAppJITSnapshot(); |
1754 } | 1741 } |
1755 } | 1742 } |
1756 CHECK_RESULT(result); | 1743 CHECK_RESULT(result); |
1757 | 1744 |
1758 if (save_feedback_filename != NULL) { | 1745 if (save_feedback_filename != NULL) { |
1759 uint8_t* buffer = NULL; | 1746 uint8_t* buffer = NULL; |
1760 intptr_t size = 0; | 1747 intptr_t size = 0; |
1761 result = Dart_SaveJITFeedback(&buffer, &size); | 1748 result = Dart_SaveJITFeedback(&buffer, &size); |
1762 if (Dart_IsError(result)) { | 1749 if (Dart_IsError(result)) { |
1763 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1750 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 Platform::Exit(Process::GlobalExitCode()); | 2003 Platform::Exit(Process::GlobalExitCode()); |
2017 } | 2004 } |
2018 | 2005 |
2019 } // namespace bin | 2006 } // namespace bin |
2020 } // namespace dart | 2007 } // namespace dart |
2021 | 2008 |
2022 int main(int argc, char** argv) { | 2009 int main(int argc, char** argv) { |
2023 dart::bin::main(argc, argv); | 2010 dart::bin::main(argc, argv); |
2024 UNREACHABLE(); | 2011 UNREACHABLE(); |
2025 } | 2012 } |
OLD | NEW |