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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 *exit_code = kRestartRequestExitCode; \ | 768 *exit_code = kRestartRequestExitCode; \ |
769 } else { \ | 769 } else { \ |
770 *exit_code = kErrorExitCode; \ | 770 *exit_code = kErrorExitCode; \ |
771 } \ | 771 } \ |
772 Dart_ExitScope(); \ | 772 Dart_ExitScope(); \ |
773 Dart_ShutdownIsolate(); \ | 773 Dart_ShutdownIsolate(); \ |
774 return NULL; \ | 774 return NULL; \ |
775 } \ | 775 } \ |
776 | 776 |
777 | 777 |
| 778 static void SnapshotOnExitHook(int64_t exit_code); |
| 779 |
| 780 |
778 // Returns true on success, false on failure. | 781 // Returns true on success, false on failure. |
779 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 782 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
780 const char* main, | 783 const char* main, |
781 const char* package_root, | 784 const char* package_root, |
782 const char* packages_config, | 785 const char* packages_config, |
783 Dart_IsolateFlags* flags, | 786 Dart_IsolateFlags* flags, |
784 char** error, | 787 char** error, |
785 int* exit_code) { | 788 int* exit_code) { |
786 ASSERT(script_uri != NULL); | 789 ASSERT(script_uri != NULL); |
787 | 790 |
788 const bool needs_load_port = true; | 791 const bool needs_load_port = true; |
789 #if defined(PRODUCT) | 792 #if defined(PRODUCT) |
790 const bool run_service_isolate = needs_load_port; | 793 const bool run_service_isolate = needs_load_port; |
791 #else | 794 #else |
792 // Always create the service isolate in DEBUG and RELEASE modes for profiling, | 795 // Always create the service isolate in DEBUG and RELEASE modes for profiling, |
793 // even if we don't need it for loading. | 796 // even if we don't need it for loading. |
794 const bool run_service_isolate = true; | 797 const bool run_service_isolate = true; |
795 #endif // PRODUCT | 798 #endif // PRODUCT |
796 if (!run_service_isolate && | 799 if (!run_service_isolate && |
797 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { | 800 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |
798 return NULL; | 801 return NULL; |
799 } | 802 } |
800 | 803 |
801 IsolateData* isolate_data = new IsolateData(script_uri, | 804 IsolateData* isolate_data = new IsolateData(script_uri, |
802 package_root, | 805 package_root, |
803 packages_config); | 806 packages_config); |
| 807 if ((gen_snapshot_kind == kAppAfterRun) || |
| 808 (gen_snapshot_kind == kAppJITAfterRun)) { |
| 809 isolate_data->set_exit_hook(SnapshotOnExitHook); |
| 810 } |
804 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 811 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, |
805 main, | 812 main, |
806 isolate_snapshot_buffer, | 813 isolate_snapshot_buffer, |
807 flags, | 814 flags, |
808 isolate_data, | 815 isolate_data, |
809 error); | 816 error); |
810 if (isolate == NULL) { | 817 if (isolate == NULL) { |
811 delete isolate_data; | 818 delete isolate_data; |
812 return NULL; | 819 return NULL; |
813 } | 820 } |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 Dart_ExitScope(); \ | 1521 Dart_ExitScope(); \ |
1515 Dart_ShutdownIsolate(); \ | 1522 Dart_ShutdownIsolate(); \ |
1516 return true; \ | 1523 return true; \ |
1517 } \ | 1524 } \ |
1518 const int exit_code = Dart_IsCompilationError(result) ? \ | 1525 const int exit_code = Dart_IsCompilationError(result) ? \ |
1519 kCompilationErrorExitCode : kErrorExitCode; \ | 1526 kCompilationErrorExitCode : kErrorExitCode; \ |
1520 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ | 1527 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ |
1521 } | 1528 } |
1522 | 1529 |
1523 | 1530 |
| 1531 static void SnapshotOnExitHook(int64_t exit_code) { |
| 1532 if (gen_snapshot_kind == kAppAfterRun) { |
| 1533 GenerateFullSnapshot(); |
| 1534 } else { |
| 1535 Dart_PrecompileJIT(); |
| 1536 GeneratePrecompiledJITSnapshot(); |
| 1537 } |
| 1538 } |
| 1539 |
| 1540 |
1524 bool RunMainIsolate(const char* script_name, | 1541 bool RunMainIsolate(const char* script_name, |
1525 CommandLineOptions* dart_options) { | 1542 CommandLineOptions* dart_options) { |
1526 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1543 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1527 // the specified application script. | 1544 // the specified application script. |
1528 char* error = NULL; | 1545 char* error = NULL; |
1529 int exit_code = 0; | 1546 int exit_code = 0; |
1530 char* isolate_name = BuildIsolateName(script_name, "main"); | 1547 char* isolate_name = BuildIsolateName(script_name, "main"); |
1531 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1548 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
1532 "main", | 1549 "main", |
1533 commandline_package_root, | 1550 commandline_package_root, |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 Platform::Exit(Process::GlobalExitCode()); | 1966 Platform::Exit(Process::GlobalExitCode()); |
1950 } | 1967 } |
1951 | 1968 |
1952 } // namespace bin | 1969 } // namespace bin |
1953 } // namespace dart | 1970 } // namespace dart |
1954 | 1971 |
1955 int main(int argc, char** argv) { | 1972 int main(int argc, char** argv) { |
1956 dart::bin::main(argc, argv); | 1973 dart::bin::main(argc, argv); |
1957 UNREACHABLE(); | 1974 UNREACHABLE(); |
1958 } | 1975 } |
OLD | NEW |