Chromium Code Reviews| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 // Global flag that is used to indicate that we want to compile all the | 69 // Global flag that is used to indicate that we want to compile all the |
| 70 // dart functions and not run anything. | 70 // dart functions and not run anything. |
| 71 static bool has_compile_all = false; | 71 static bool has_compile_all = false; |
| 72 | 72 |
| 73 | 73 |
| 74 // Global flag that is used to indicate that we want to compile all the | 74 // Global flag that is used to indicate that we want to compile all the |
| 75 // dart functions before running main and not compile anything thereafter. | 75 // dart functions before running main and not compile anything thereafter. |
| 76 static bool has_precompile = false; | 76 static bool has_precompile = false; |
| 77 | 77 |
| 78 | 78 |
| 79 // Global flag that is used to indicate that we want to run from a precompiled | |
| 80 // snapshot. | |
| 81 static bool has_precompiled = false; | |
| 82 | |
| 83 | |
| 79 // Global flag that is used to indicate that we want to trace resolution of | 84 // Global flag that is used to indicate that we want to trace resolution of |
| 80 // URIs and the loading of libraries, parts and scripts. | 85 // URIs and the loading of libraries, parts and scripts. |
| 81 static bool has_trace_loading = false; | 86 static bool has_trace_loading = false; |
| 82 | 87 |
| 83 | 88 |
| 84 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 89 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
| 85 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 90 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 86 // VM Service options. | 91 // VM Service options. |
| 87 static bool start_vm_service = false; | 92 static bool start_vm_service = false; |
| 88 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 93 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 ASSERT(arg != NULL); | 299 ASSERT(arg != NULL); |
| 295 if (*arg != '\0') { | 300 if (*arg != '\0') { |
| 296 return false; | 301 return false; |
| 297 } | 302 } |
| 298 has_precompile = true; | 303 has_precompile = true; |
| 299 vm_options->AddArgument("--precompile"); | 304 vm_options->AddArgument("--precompile"); |
| 300 return true; | 305 return true; |
| 301 } | 306 } |
| 302 | 307 |
| 303 | 308 |
| 309 static bool ProcessPrecompiledOption(const char* arg, | |
| 310 CommandLineOptions* vm_options) { | |
| 311 ASSERT(arg != NULL); | |
| 312 if (*arg != '\0') { | |
| 313 return false; | |
| 314 } | |
| 315 has_precompiled = true; | |
| 316 vm_options->AddArgument("--precompile"); | |
| 317 return true; | |
| 318 } | |
| 319 | |
| 320 | |
| 304 static bool ProcessDebugOption(const char* option_value, | 321 static bool ProcessDebugOption(const char* option_value, |
| 305 CommandLineOptions* vm_options) { | 322 CommandLineOptions* vm_options) { |
| 306 ASSERT(option_value != NULL); | 323 ASSERT(option_value != NULL); |
| 307 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, | 324 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, |
| 308 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { | 325 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { |
| 309 Log::PrintErr("unrecognized --debug option syntax. " | 326 Log::PrintErr("unrecognized --debug option syntax. " |
| 310 "Use --debug[:<port number>[/<IPv4 address>]]\n"); | 327 "Use --debug[:<port number>[/<IPv4 address>]]\n"); |
| 311 return false; | 328 return false; |
| 312 } | 329 } |
| 313 | 330 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 { "-h", ProcessHelpOption }, | 422 { "-h", ProcessHelpOption }, |
| 406 { "--verbose", ProcessVerboseOption }, | 423 { "--verbose", ProcessVerboseOption }, |
| 407 { "-v", ProcessVerboseOption }, | 424 { "-v", ProcessVerboseOption }, |
| 408 { "--package-root=", ProcessPackageRootOption }, | 425 { "--package-root=", ProcessPackageRootOption }, |
| 409 { "--packages=", ProcessPackagesOption }, | 426 { "--packages=", ProcessPackagesOption }, |
| 410 { "-D", ProcessEnvironmentOption }, | 427 { "-D", ProcessEnvironmentOption }, |
| 411 // VM specific options to the standalone dart program. | 428 // VM specific options to the standalone dart program. |
| 412 { "--break-at=", ProcessBreakpointOption }, | 429 { "--break-at=", ProcessBreakpointOption }, |
| 413 { "--compile_all", ProcessCompileAllOption }, | 430 { "--compile_all", ProcessCompileAllOption }, |
| 414 { "--precompile", ProcessPrecompileOption }, | 431 { "--precompile", ProcessPrecompileOption }, |
| 432 { "--precompiled", ProcessPrecompiledOption }, | |
| 415 { "--debug", ProcessDebugOption }, | 433 { "--debug", ProcessDebugOption }, |
| 416 { "--snapshot=", ProcessGenScriptSnapshotOption }, | 434 { "--snapshot=", ProcessGenScriptSnapshotOption }, |
| 417 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 435 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 418 { "--observe", ProcessObserveOption }, | 436 { "--observe", ProcessObserveOption }, |
| 419 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, | 437 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, |
| 420 { "--trace-loading", ProcessTraceLoadingOption}, | 438 { "--trace-loading", ProcessTraceLoadingOption}, |
| 421 { NULL, NULL } | 439 { NULL, NULL } |
| 422 }; | 440 }; |
| 423 | 441 |
| 424 | 442 |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 static void ServiceStreamCancelCallback(const char* stream_id) { | 970 static void ServiceStreamCancelCallback(const char* stream_id) { |
| 953 if (strcmp(stream_id, kStdoutStreamId) == 0) { | 971 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 954 capture_stdout = false; | 972 capture_stdout = false; |
| 955 } else if (strcmp(stream_id, kStderrStreamId) == 0) { | 973 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 956 capture_stderr = false; | 974 capture_stderr = false; |
| 957 } | 975 } |
| 958 capture_stdio = (capture_stdout || capture_stderr); | 976 capture_stdio = (capture_stdout || capture_stderr); |
| 959 } | 977 } |
| 960 | 978 |
| 961 | 979 |
| 980 static void WriteSnapshotFile(const char* filename, | |
| 981 const uint8_t* buffer, | |
| 982 const intptr_t size) { | |
| 983 File* file = File::Open(filename, File::kWriteTruncate); | |
| 984 ASSERT(file != NULL); | |
| 985 if (!file->WriteFully(buffer, size)) { | |
| 986 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | |
| 987 } | |
| 988 delete file; | |
| 989 } | |
| 990 | |
| 991 | |
| 962 void main(int argc, char** argv) { | 992 void main(int argc, char** argv) { |
| 963 char* script_name; | 993 char* script_name; |
| 964 const int EXTRA_VM_ARGUMENTS = 2; | 994 const int EXTRA_VM_ARGUMENTS = 2; |
| 965 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 995 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 966 CommandLineOptions dart_options(argc); | 996 CommandLineOptions dart_options(argc); |
| 967 bool print_flags_seen = false; | 997 bool print_flags_seen = false; |
| 968 bool verbose_debug_seen = false; | 998 bool verbose_debug_seen = false; |
| 969 | 999 |
| 970 vm_options.AddArgument("--no_write_protect_code"); | 1000 vm_options.AddArgument("--no_write_protect_code"); |
| 971 // Perform platform specific initialization. | 1001 // Perform platform specific initialization. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 ASSERT(debug_port >= 0); | 1055 ASSERT(debug_port >= 0); |
| 1026 bool print_msg = verbose_debug_seen || (debug_port == 0); | 1056 bool print_msg = verbose_debug_seen || (debug_port == 0); |
| 1027 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 1057 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 1028 if (print_msg) { | 1058 if (print_msg) { |
| 1029 Log::Print("Debugger listening on port %d\n", debug_port); | 1059 Log::Print("Debugger listening on port %d\n", debug_port); |
| 1030 } | 1060 } |
| 1031 } else { | 1061 } else { |
| 1032 DebuggerConnectionHandler::InitForVmService(); | 1062 DebuggerConnectionHandler::InitForVmService(); |
| 1033 } | 1063 } |
| 1034 | 1064 |
| 1065 const uint8_t* instructions_snapshot = NULL; | |
| 1066 if (has_precompiled) { | |
|
rmacnak
2015/08/27 00:22:29
For now, load everything from files. The embedder
| |
| 1067 const char* kPrecompiledLibName = "libprecompiled.so"; | |
| 1068 const char* kPrecompiledSymName = "kInstructionsSnapshot"; | |
| 1069 const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; | |
| 1070 const char* kPrecompiledIsolateName = "precompiled.isolate"; | |
| 1071 | |
| 1072 void* precompiled_lib = | |
| 1073 Extensions::LoadExtensionLibrary(kPrecompiledLibName); | |
| 1074 if (precompiled_lib == NULL) { | |
| 1075 fprintf(stderr, "Failed to load library '%s'\n", kPrecompiledLibName); | |
| 1076 fflush(stderr); | |
| 1077 exit(kErrorExitCode); | |
| 1078 } | |
| 1079 | |
| 1080 instructions_snapshot = reinterpret_cast<const uint8_t*>( | |
| 1081 Extensions::ResolveSymbol(precompiled_lib, kPrecompiledSymName)); | |
| 1082 if (instructions_snapshot == NULL) { | |
| 1083 fprintf(stderr, "Failed to load symbol '%s'\n", kPrecompiledSymName); | |
| 1084 fflush(stderr); | |
| 1085 exit(kErrorExitCode); | |
| 1086 } | |
| 1087 | |
| 1088 void* file = DartUtils::OpenFile(kPrecompiledVmIsolateName, false); | |
| 1089 if (file == NULL) { | |
| 1090 fprintf(stderr, "Failed to open '%s'\n", kPrecompiledVmIsolateName); | |
| 1091 fflush(stderr); | |
| 1092 exit(kErrorExitCode); | |
| 1093 } | |
| 1094 intptr_t len = -1; | |
| 1095 DartUtils::ReadFile(&vm_isolate_snapshot_buffer, &len, file); | |
| 1096 if (vm_isolate_snapshot_buffer == NULL || len == -1) { | |
| 1097 fprintf(stderr, "Failed to read '%s'\n", kPrecompiledVmIsolateName); | |
| 1098 fflush(stderr); | |
| 1099 exit(kErrorExitCode); | |
| 1100 } | |
| 1101 DartUtils::CloseFile(file); | |
| 1102 | |
| 1103 file = DartUtils::OpenFile(kPrecompiledIsolateName, false); | |
| 1104 if (file == NULL) { | |
| 1105 fprintf(stderr, "Failed to open '%s'\n", kPrecompiledIsolateName); | |
| 1106 fflush(stderr); | |
| 1107 exit(kErrorExitCode); | |
| 1108 } | |
| 1109 len = -1; | |
| 1110 DartUtils::ReadFile(&isolate_snapshot_buffer, &len, file); | |
| 1111 if (isolate_snapshot_buffer == NULL || len == -1) { | |
| 1112 fprintf(stderr, "Failed to read '%s'\n", kPrecompiledVmIsolateName); | |
| 1113 fflush(stderr); | |
| 1114 exit(kErrorExitCode); | |
| 1115 } | |
| 1116 DartUtils::CloseFile(file); | |
| 1117 } | |
| 1118 | |
| 1035 // Initialize the Dart VM. | 1119 // Initialize the Dart VM. |
| 1036 if (!Dart_Initialize(vm_isolate_snapshot_buffer, NULL, | 1120 if (!Dart_Initialize(vm_isolate_snapshot_buffer, instructions_snapshot, |
| 1037 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1121 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 1038 DartUtils::OpenFile, | 1122 DartUtils::OpenFile, |
| 1039 DartUtils::ReadFile, | 1123 DartUtils::ReadFile, |
| 1040 DartUtils::WriteFile, | 1124 DartUtils::WriteFile, |
| 1041 DartUtils::CloseFile, | 1125 DartUtils::CloseFile, |
| 1042 DartUtils::EntropySource)) { | 1126 DartUtils::EntropySource)) { |
| 1043 fprintf(stderr, "%s", "VM initialization failed\n"); | 1127 fprintf(stderr, "%s", "VM initialization failed\n"); |
| 1044 fflush(stderr); | 1128 fflush(stderr); |
| 1045 exit(kErrorExitCode); | 1129 exit(kErrorExitCode); |
| 1046 } | 1130 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 // Import the root library into the builtin library so that we can easily | 1191 // Import the root library into the builtin library so that we can easily |
| 1108 // lookup the main entry point exported from the root library. | 1192 // lookup the main entry point exported from the root library. |
| 1109 Dart_Handle builtin_lib = | 1193 Dart_Handle builtin_lib = |
| 1110 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1194 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 1111 ASSERT(!Dart_IsError(builtin_lib)); | 1195 ASSERT(!Dart_IsError(builtin_lib)); |
| 1112 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); | 1196 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); |
| 1113 | 1197 |
| 1114 if (has_precompile) { | 1198 if (has_precompile) { |
| 1115 result = Dart_Precompile(); | 1199 result = Dart_Precompile(); |
| 1116 DartExitOnError(result); | 1200 DartExitOnError(result); |
| 1201 | |
| 1202 uint8_t* vm_isolate_buffer = NULL; | |
| 1203 intptr_t vm_isolate_size = 0; | |
| 1204 uint8_t* isolate_buffer = NULL; | |
| 1205 intptr_t isolate_size = 0; | |
| 1206 uint8_t* instructions_buffer = NULL; | |
| 1207 intptr_t instructions_size = 0; | |
| 1208 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, | |
| 1209 &vm_isolate_size, | |
| 1210 &isolate_buffer, | |
| 1211 &isolate_size, | |
| 1212 &instructions_buffer, | |
| 1213 &instructions_size); | |
| 1214 | |
| 1215 DartExitOnError(result); | |
| 1216 | |
| 1217 WriteSnapshotFile("precompiled.vmisolate", | |
| 1218 vm_isolate_buffer, | |
| 1219 vm_isolate_size); | |
| 1220 WriteSnapshotFile("precompiled.isolate", | |
| 1221 isolate_buffer, | |
| 1222 isolate_size); | |
| 1223 WriteSnapshotFile("precompiled.instructions", | |
| 1224 instructions_buffer, | |
| 1225 instructions_size); | |
| 1226 | |
| 1117 } else if (has_compile_all) { | 1227 } else if (has_compile_all) { |
| 1118 result = Dart_CompileAll(); | 1228 result = Dart_CompileAll(); |
| 1119 DartExitOnError(result); | 1229 DartExitOnError(result); |
| 1120 } | 1230 } |
| 1121 | 1231 |
| 1122 if (Dart_IsNull(root_lib)) { | 1232 if (Dart_IsNull(root_lib)) { |
| 1123 ErrorExit(kErrorExitCode, | 1233 ErrorExit(kErrorExitCode, |
| 1124 "Unable to find root library for '%s'\n", | 1234 "Unable to find root library for '%s'\n", |
| 1125 script_name); | 1235 script_name); |
| 1126 } | 1236 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1190 exit(Process::GlobalExitCode()); | 1300 exit(Process::GlobalExitCode()); |
| 1191 } | 1301 } |
| 1192 | 1302 |
| 1193 } // namespace bin | 1303 } // namespace bin |
| 1194 } // namespace dart | 1304 } // namespace dart |
| 1195 | 1305 |
| 1196 int main(int argc, char** argv) { | 1306 int main(int argc, char** argv) { |
| 1197 dart::bin::main(argc, argv); | 1307 dart::bin::main(argc, argv); |
| 1198 UNREACHABLE(); | 1308 UNREACHABLE(); |
| 1199 } | 1309 } |
| OLD | NEW |