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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 extern const char* kPrecompiledIsolateSymbolName; | 98 extern const char* kPrecompiledIsolateSymbolName; |
99 extern const char* kPrecompiledInstructionsSymbolName; | 99 extern const char* kPrecompiledInstructionsSymbolName; |
100 extern const char* kPrecompiledDataSymbolName; | 100 extern const char* kPrecompiledDataSymbolName; |
101 | 101 |
102 | 102 |
103 // Global flag that is used to indicate that we want to trace resolution of | 103 // Global flag that is used to indicate that we want to trace resolution of |
104 // URIs and the loading of libraries, parts and scripts. | 104 // URIs and the loading of libraries, parts and scripts. |
105 static bool trace_loading = false; | 105 static bool trace_loading = false; |
106 | 106 |
107 | 107 |
| 108 static Dart_Isolate main_isolate = NULL; |
| 109 |
| 110 |
108 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 111 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
109 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 112 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
110 // VM Service options. | 113 // VM Service options. |
111 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 114 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
112 // The 0 port is a magic value which results in the first available port | 115 // The 0 port is a magic value which results in the first available port |
113 // being allocated. | 116 // being allocated. |
114 static int vm_service_server_port = -1; | 117 static int vm_service_server_port = -1; |
115 // True when we are running in development mode and cross origin security | 118 // True when we are running in development mode and cross origin security |
116 // checks are disabled. | 119 // checks are disabled. |
117 static bool vm_service_dev_mode = false; | 120 static bool vm_service_dev_mode = false; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 const bool run_service_isolate = true; | 794 const bool run_service_isolate = true; |
792 #endif // PRODUCT | 795 #endif // PRODUCT |
793 if (!run_service_isolate && | 796 if (!run_service_isolate && |
794 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { | 797 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |
795 return NULL; | 798 return NULL; |
796 } | 799 } |
797 | 800 |
798 IsolateData* isolate_data = new IsolateData(script_uri, | 801 IsolateData* isolate_data = new IsolateData(script_uri, |
799 package_root, | 802 package_root, |
800 packages_config); | 803 packages_config); |
801 if (gen_snapshot_kind == kAppJIT) { | |
802 isolate_data->set_exit_hook(SnapshotOnExitHook); | |
803 } | |
804 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 804 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, |
805 main, | 805 main, |
806 isolate_snapshot_buffer, | 806 isolate_snapshot_buffer, |
807 flags, | 807 flags, |
808 isolate_data, | 808 isolate_data, |
809 error); | 809 error); |
810 if (isolate == NULL) { | 810 if (isolate == NULL) { |
811 delete isolate_data; | 811 delete isolate_data; |
812 return NULL; | 812 return NULL; |
813 } | 813 } |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 Dart_ShutdownIsolate(); \ | 1532 Dart_ShutdownIsolate(); \ |
1533 return true; \ | 1533 return true; \ |
1534 } \ | 1534 } \ |
1535 const int exit_code = Dart_IsCompilationError(result) ? \ | 1535 const int exit_code = Dart_IsCompilationError(result) ? \ |
1536 kCompilationErrorExitCode : kErrorExitCode; \ | 1536 kCompilationErrorExitCode : kErrorExitCode; \ |
1537 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ | 1537 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ |
1538 } | 1538 } |
1539 | 1539 |
1540 | 1540 |
1541 static void SnapshotOnExitHook(int64_t exit_code) { | 1541 static void SnapshotOnExitHook(int64_t exit_code) { |
| 1542 if (Dart_CurrentIsolate() != main_isolate) { |
| 1543 Log::PrintErr("A snapshot was requested, but a secondary isolate " |
| 1544 "performed a hard exit (%" Pd64 ").\n", exit_code); |
| 1545 Platform::Exit(kErrorExitCode); |
| 1546 } |
1542 if (exit_code == 0) { | 1547 if (exit_code == 0) { |
1543 GenerateAppSnapshot(); | 1548 GenerateAppSnapshot(); |
1544 } | 1549 } |
1545 } | 1550 } |
1546 | 1551 |
1547 | 1552 |
1548 bool RunMainIsolate(const char* script_name, | 1553 bool RunMainIsolate(const char* script_name, |
1549 CommandLineOptions* dart_options) { | 1554 CommandLineOptions* dart_options) { |
1550 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1555 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1551 // the specified application script. | 1556 // the specified application script. |
(...skipping 18 matching lines...) Expand all Loading... |
1570 error = NULL; | 1575 error = NULL; |
1571 Process::TerminateExitCodeHandler(); | 1576 Process::TerminateExitCodeHandler(); |
1572 error = Dart_Cleanup(); | 1577 error = Dart_Cleanup(); |
1573 if (error != NULL) { | 1578 if (error != NULL) { |
1574 Log::PrintErr("VM cleanup failed: %s\n", error); | 1579 Log::PrintErr("VM cleanup failed: %s\n", error); |
1575 free(error); | 1580 free(error); |
1576 } | 1581 } |
1577 EventHandler::Stop(); | 1582 EventHandler::Stop(); |
1578 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1583 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); |
1579 } | 1584 } |
| 1585 main_isolate = isolate; |
1580 delete [] isolate_name; | 1586 delete [] isolate_name; |
1581 | 1587 |
1582 Dart_EnterIsolate(isolate); | 1588 Dart_EnterIsolate(isolate); |
1583 ASSERT(isolate == Dart_CurrentIsolate()); | 1589 ASSERT(isolate == Dart_CurrentIsolate()); |
1584 ASSERT(isolate != NULL); | 1590 ASSERT(isolate != NULL); |
1585 Dart_Handle result; | 1591 Dart_Handle result; |
1586 | 1592 |
1587 Dart_EnterScope(); | 1593 Dart_EnterScope(); |
1588 | 1594 |
1589 if (gen_snapshot_kind == kScript) { | 1595 if (gen_snapshot_kind == kScript) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 | 1890 |
1885 if (gen_snapshot_kind == kAppJIT) { | 1891 if (gen_snapshot_kind == kAppJIT) { |
1886 vm_options.AddArgument("--fields_may_be_reset"); | 1892 vm_options.AddArgument("--fields_may_be_reset"); |
1887 } | 1893 } |
1888 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { | 1894 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { |
1889 vm_options.AddArgument("--precompilation"); | 1895 vm_options.AddArgument("--precompilation"); |
1890 } | 1896 } |
1891 #if defined(DART_PRECOMPILED_RUNTIME) | 1897 #if defined(DART_PRECOMPILED_RUNTIME) |
1892 vm_options.AddArgument("--precompilation"); | 1898 vm_options.AddArgument("--precompilation"); |
1893 #endif | 1899 #endif |
| 1900 if (gen_snapshot_kind == kAppJIT) { |
| 1901 Process::SetExitHook(SnapshotOnExitHook); |
| 1902 } |
1894 | 1903 |
1895 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1904 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1896 | 1905 |
1897 // Start event handler. | 1906 // Start event handler. |
1898 TimerUtils::InitOnce(); | 1907 TimerUtils::InitOnce(); |
1899 EventHandler::Start(); | 1908 EventHandler::Start(); |
1900 | 1909 |
1901 // Initialize the Dart VM. | 1910 // Initialize the Dart VM. |
1902 Dart_InitializeParams init_params; | 1911 Dart_InitializeParams init_params; |
1903 memset(&init_params, 0, sizeof(init_params)); | 1912 memset(&init_params, 0, sizeof(init_params)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 Platform::Exit(Process::GlobalExitCode()); | 1974 Platform::Exit(Process::GlobalExitCode()); |
1966 } | 1975 } |
1967 | 1976 |
1968 } // namespace bin | 1977 } // namespace bin |
1969 } // namespace dart | 1978 } // namespace dart |
1970 | 1979 |
1971 int main(int argc, char** argv) { | 1980 int main(int argc, char** argv) { |
1972 dart::bin::main(argc, argv); | 1981 dart::bin::main(argc, argv); |
1973 UNREACHABLE(); | 1982 UNREACHABLE(); |
1974 } | 1983 } |
OLD | NEW |