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 | |
| 84 extern const char* kPrecompiledLibraryName; | |
| 85 extern const char* kPrecompiledSymbolName; | |
| 86 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; | |
| 87 static const char* kPrecompiledIsolateName = "precompiled.isolate"; | |
| 88 static const char* kPrecompiledInstructionsName = "precompiled.instructions"; | |
| 89 | |
| 90 | |
| 79 // Global flag that is used to indicate that we want to trace resolution of | 91 // Global flag that is used to indicate that we want to trace resolution of |
| 80 // URIs and the loading of libraries, parts and scripts. | 92 // URIs and the loading of libraries, parts and scripts. |
| 81 static bool has_trace_loading = false; | 93 static bool has_trace_loading = false; |
| 82 | 94 |
| 83 | 95 |
| 84 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 96 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
| 85 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 97 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 86 // VM Service options. | 98 // VM Service options. |
| 87 static bool start_vm_service = false; | 99 static bool start_vm_service = false; |
| 88 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 100 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 return true; | 303 return true; |
| 292 } | 304 } |
| 293 | 305 |
| 294 | 306 |
| 295 static bool ProcessPrecompileOption(const char* arg, | 307 static bool ProcessPrecompileOption(const char* arg, |
| 296 CommandLineOptions* vm_options) { | 308 CommandLineOptions* vm_options) { |
| 297 ASSERT(arg != NULL); | 309 ASSERT(arg != NULL); |
| 298 if (*arg != '\0') { | 310 if (*arg != '\0') { |
| 299 return false; | 311 return false; |
| 300 } | 312 } |
| 313 // Ensure that we are not already running using a full snapshot. | |
| 314 if (isolate_snapshot_buffer != NULL) { | |
| 315 Log::PrintErr("Precompiled snapshots must be generated with" | |
| 316 " dart_no_snapshot."); | |
| 317 return false; | |
| 318 } | |
| 301 has_precompile = true; | 319 has_precompile = true; |
| 302 vm_options->AddArgument("--precompile"); | 320 vm_options->AddArgument("--precompile"); |
| 303 return true; | 321 return true; |
| 304 } | 322 } |
| 305 | 323 |
| 306 | 324 |
| 325 static bool ProcessPrecompiledOption(const char* arg, | |
| 326 CommandLineOptions* vm_options) { | |
| 327 ASSERT(arg != NULL); | |
| 328 if (*arg != '\0') { | |
| 329 return false; | |
| 330 } | |
| 331 has_precompiled = true; | |
| 332 vm_options->AddArgument("--precompile"); | |
| 333 return true; | |
| 334 } | |
| 335 | |
| 336 | |
| 307 static bool ProcessDebugOption(const char* option_value, | 337 static bool ProcessDebugOption(const char* option_value, |
| 308 CommandLineOptions* vm_options) { | 338 CommandLineOptions* vm_options) { |
| 309 ASSERT(option_value != NULL); | 339 ASSERT(option_value != NULL); |
| 310 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, | 340 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, |
| 311 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { | 341 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { |
| 312 Log::PrintErr("unrecognized --debug option syntax. " | 342 Log::PrintErr("unrecognized --debug option syntax. " |
| 313 "Use --debug[:<port number>[/<IPv4 address>]]\n"); | 343 "Use --debug[:<port number>[/<IPv4 address>]]\n"); |
| 314 return false; | 344 return false; |
| 315 } | 345 } |
| 316 | 346 |
| 317 breakpoint_at = "main"; | 347 breakpoint_at = "main"; |
| 318 start_debugger = true; | 348 start_debugger = true; |
| 319 return true; | 349 return true; |
| 320 } | 350 } |
| 321 | 351 |
| 322 | 352 |
| 323 static bool ProcessGenScriptSnapshotOption(const char* filename, | 353 static bool ProcessGenScriptSnapshotOption(const char* filename, |
| 324 CommandLineOptions* vm_options) { | 354 CommandLineOptions* vm_options) { |
| 325 if (filename != NULL && strlen(filename) != 0) { | 355 if (filename != NULL && strlen(filename) != 0) { |
| 326 // Ensure that are already running using a full snapshot. | 356 // Ensure that we are already running using a full snapshot. |
| 327 if (isolate_snapshot_buffer == NULL) { | 357 if (isolate_snapshot_buffer == NULL) { |
| 328 Log::PrintErr("Script snapshots cannot be generated in this version of" | 358 Log::PrintErr("Script snapshots cannot be generated in this version of" |
| 329 " dart\n"); | 359 " dart\n"); |
| 330 return false; | 360 return false; |
| 331 } | 361 } |
| 332 snapshot_filename = filename; | 362 snapshot_filename = filename; |
| 333 generate_script_snapshot = true; | 363 generate_script_snapshot = true; |
| 334 return true; | 364 return true; |
| 335 } | 365 } |
| 336 return false; | 366 return false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 { "-h", ProcessHelpOption }, | 438 { "-h", ProcessHelpOption }, |
| 409 { "--verbose", ProcessVerboseOption }, | 439 { "--verbose", ProcessVerboseOption }, |
| 410 { "-v", ProcessVerboseOption }, | 440 { "-v", ProcessVerboseOption }, |
| 411 { "--package-root=", ProcessPackageRootOption }, | 441 { "--package-root=", ProcessPackageRootOption }, |
| 412 { "--packages=", ProcessPackagesOption }, | 442 { "--packages=", ProcessPackagesOption }, |
| 413 { "-D", ProcessEnvironmentOption }, | 443 { "-D", ProcessEnvironmentOption }, |
| 414 // VM specific options to the standalone dart program. | 444 // VM specific options to the standalone dart program. |
| 415 { "--break-at=", ProcessBreakpointOption }, | 445 { "--break-at=", ProcessBreakpointOption }, |
| 416 { "--compile_all", ProcessCompileAllOption }, | 446 { "--compile_all", ProcessCompileAllOption }, |
| 417 { "--precompile", ProcessPrecompileOption }, | 447 { "--precompile", ProcessPrecompileOption }, |
| 448 { "--precompiled", ProcessPrecompiledOption }, | |
|
siva
2015/09/02 21:16:37
maybe we should call these
--gen-precompiled-snaps
rmacnak
2015/09/02 22:58:50
Done.
| |
| 418 { "--debug", ProcessDebugOption }, | 449 { "--debug", ProcessDebugOption }, |
| 419 { "--snapshot=", ProcessGenScriptSnapshotOption }, | 450 { "--snapshot=", ProcessGenScriptSnapshotOption }, |
| 420 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 451 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 421 { "--observe", ProcessObserveOption }, | 452 { "--observe", ProcessObserveOption }, |
| 422 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, | 453 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, |
| 423 { "--trace-loading", ProcessTraceLoadingOption}, | 454 { "--trace-loading", ProcessTraceLoadingOption}, |
| 424 { NULL, NULL } | 455 { NULL, NULL } |
| 425 }; | 456 }; |
| 426 | 457 |
| 427 | 458 |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 static void ServiceStreamCancelCallback(const char* stream_id) { | 986 static void ServiceStreamCancelCallback(const char* stream_id) { |
| 956 if (strcmp(stream_id, kStdoutStreamId) == 0) { | 987 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 957 capture_stdout = false; | 988 capture_stdout = false; |
| 958 } else if (strcmp(stream_id, kStderrStreamId) == 0) { | 989 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 959 capture_stderr = false; | 990 capture_stderr = false; |
| 960 } | 991 } |
| 961 capture_stdio = (capture_stdout || capture_stderr); | 992 capture_stdio = (capture_stdout || capture_stderr); |
| 962 } | 993 } |
| 963 | 994 |
| 964 | 995 |
| 996 static void WriteSnapshotFile(const char* filename, | |
| 997 const uint8_t* buffer, | |
| 998 const intptr_t size) { | |
| 999 File* file = File::Open(filename, File::kWriteTruncate); | |
| 1000 ASSERT(file != NULL); | |
| 1001 if (!file->WriteFully(buffer, size)) { | |
| 1002 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | |
| 1003 } | |
| 1004 delete file; | |
| 1005 } | |
| 1006 | |
| 1007 | |
| 1008 static void ReadSnapshotFile(const char* filename, | |
| 1009 const uint8_t** buffer) { | |
| 1010 void* file = DartUtils::OpenFile(filename, false); | |
| 1011 if (file == NULL) { | |
| 1012 Log::PrintErr("Error: Failed to open '%s'.\n\n", filename); | |
| 1013 exit(kErrorExitCode); | |
| 1014 } | |
| 1015 intptr_t len = -1; | |
| 1016 DartUtils::ReadFile(buffer, &len, file); | |
| 1017 if (*buffer == NULL || len == -1) { | |
| 1018 Log::PrintErr("Error: Failed to read '%s'.\n\n", filename); | |
| 1019 exit(kErrorExitCode); | |
| 1020 } | |
| 1021 DartUtils::CloseFile(file); | |
| 1022 } | |
| 1023 | |
| 1024 | |
| 1025 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | |
| 1026 void* library = Extensions::LoadExtensionLibrary(libname); | |
| 1027 if (library == NULL) { | |
| 1028 Log::PrintErr("Error: Failed to load library '%s'.\n\n", libname); | |
| 1029 exit(kErrorExitCode); | |
| 1030 } | |
| 1031 void* symbol = Extensions::ResolveSymbol(library, symname); | |
| 1032 if (symbol == NULL) { | |
| 1033 Log::PrintErr("Failed to load symbol '%s'\n", symname); | |
| 1034 exit(kErrorExitCode); | |
| 1035 } | |
| 1036 return symbol; | |
| 1037 } | |
| 1038 | |
| 1039 | |
| 965 void main(int argc, char** argv) { | 1040 void main(int argc, char** argv) { |
| 966 char* script_name; | 1041 char* script_name; |
| 967 const int EXTRA_VM_ARGUMENTS = 2; | 1042 const int EXTRA_VM_ARGUMENTS = 2; |
| 968 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1043 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 969 CommandLineOptions dart_options(argc); | 1044 CommandLineOptions dart_options(argc); |
| 970 bool print_flags_seen = false; | 1045 bool print_flags_seen = false; |
| 971 bool verbose_debug_seen = false; | 1046 bool verbose_debug_seen = false; |
| 972 | 1047 |
| 973 vm_options.AddArgument("--no_write_protect_code"); | 1048 vm_options.AddArgument("--no_write_protect_code"); |
| 974 // Perform platform specific initialization. | 1049 // Perform platform specific initialization. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 ASSERT(debug_port >= 0); | 1103 ASSERT(debug_port >= 0); |
| 1029 bool print_msg = verbose_debug_seen || (debug_port == 0); | 1104 bool print_msg = verbose_debug_seen || (debug_port == 0); |
| 1030 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 1105 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 1031 if (print_msg) { | 1106 if (print_msg) { |
| 1032 Log::Print("Debugger listening on port %d\n", debug_port); | 1107 Log::Print("Debugger listening on port %d\n", debug_port); |
| 1033 } | 1108 } |
| 1034 } else { | 1109 } else { |
| 1035 DebuggerConnectionHandler::InitForVmService(); | 1110 DebuggerConnectionHandler::InitForVmService(); |
| 1036 } | 1111 } |
| 1037 | 1112 |
| 1113 const uint8_t* instructions_snapshot = NULL; | |
| 1114 if (has_precompiled) { | |
| 1115 instructions_snapshot = reinterpret_cast<const uint8_t*>( | |
| 1116 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); | |
| 1117 ReadSnapshotFile(kPrecompiledVmIsolateName, &vm_isolate_snapshot_buffer); | |
| 1118 ReadSnapshotFile(kPrecompiledIsolateName, &isolate_snapshot_buffer); | |
| 1119 } | |
| 1120 | |
| 1038 // Initialize the Dart VM. | 1121 // Initialize the Dart VM. |
| 1039 if (!Dart_Initialize(vm_isolate_snapshot_buffer, NULL, | 1122 if (!Dart_Initialize(vm_isolate_snapshot_buffer, instructions_snapshot, |
| 1040 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1123 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 1041 DartUtils::OpenFile, | 1124 DartUtils::OpenFile, |
| 1042 DartUtils::ReadFile, | 1125 DartUtils::ReadFile, |
| 1043 DartUtils::WriteFile, | 1126 DartUtils::WriteFile, |
| 1044 DartUtils::CloseFile, | 1127 DartUtils::CloseFile, |
| 1045 DartUtils::EntropySource)) { | 1128 DartUtils::EntropySource)) { |
| 1046 fprintf(stderr, "%s", "VM initialization failed\n"); | 1129 fprintf(stderr, "%s", "VM initialization failed\n"); |
| 1047 fflush(stderr); | 1130 fflush(stderr); |
| 1048 DebuggerConnectionHandler::StopHandler(); | 1131 DebuggerConnectionHandler::StopHandler(); |
| 1049 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. | 1132 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 // Import the root library into the builtin library so that we can easily | 1199 // Import the root library into the builtin library so that we can easily |
| 1117 // lookup the main entry point exported from the root library. | 1200 // lookup the main entry point exported from the root library. |
| 1118 Dart_Handle builtin_lib = | 1201 Dart_Handle builtin_lib = |
| 1119 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1202 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 1120 ASSERT(!Dart_IsError(builtin_lib)); | 1203 ASSERT(!Dart_IsError(builtin_lib)); |
| 1121 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); | 1204 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); |
| 1122 | 1205 |
| 1123 if (has_precompile) { | 1206 if (has_precompile) { |
| 1124 result = Dart_Precompile(); | 1207 result = Dart_Precompile(); |
| 1125 DartExitOnError(result); | 1208 DartExitOnError(result); |
| 1209 | |
| 1210 uint8_t* vm_isolate_buffer = NULL; | |
| 1211 intptr_t vm_isolate_size = 0; | |
| 1212 uint8_t* isolate_buffer = NULL; | |
| 1213 intptr_t isolate_size = 0; | |
| 1214 uint8_t* instructions_buffer = NULL; | |
| 1215 intptr_t instructions_size = 0; | |
| 1216 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, | |
| 1217 &vm_isolate_size, | |
| 1218 &isolate_buffer, | |
| 1219 &isolate_size, | |
| 1220 &instructions_buffer, | |
| 1221 &instructions_size); | |
| 1222 DartExitOnError(result); | |
| 1223 WriteSnapshotFile(kPrecompiledVmIsolateName, | |
| 1224 vm_isolate_buffer, | |
| 1225 vm_isolate_size); | |
| 1226 WriteSnapshotFile(kPrecompiledIsolateName, | |
| 1227 isolate_buffer, | |
| 1228 isolate_size); | |
| 1229 WriteSnapshotFile(kPrecompiledInstructionsName, | |
| 1230 instructions_buffer, | |
| 1231 instructions_size); | |
| 1126 } else if (has_compile_all) { | 1232 } else if (has_compile_all) { |
| 1127 result = Dart_CompileAll(); | 1233 result = Dart_CompileAll(); |
| 1128 DartExitOnError(result); | 1234 DartExitOnError(result); |
| 1129 } | 1235 } |
| 1130 | 1236 |
| 1131 if (Dart_IsNull(root_lib)) { | 1237 if (Dart_IsNull(root_lib)) { |
| 1132 ErrorExit(kErrorExitCode, | 1238 ErrorExit(kErrorExitCode, |
| 1133 "Unable to find root library for '%s'\n", | 1239 "Unable to find root library for '%s'\n", |
| 1134 script_name); | 1240 script_name); |
| 1135 } | 1241 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 exit(Process::GlobalExitCode()); | 1309 exit(Process::GlobalExitCode()); |
| 1204 } | 1310 } |
| 1205 | 1311 |
| 1206 } // namespace bin | 1312 } // namespace bin |
| 1207 } // namespace dart | 1313 } // namespace dart |
| 1208 | 1314 |
| 1209 int main(int argc, char** argv) { | 1315 int main(int argc, char** argv) { |
| 1210 dart::bin::main(argc, argv); | 1316 dart::bin::main(argc, argv); |
| 1211 UNREACHABLE(); | 1317 UNREACHABLE(); |
| 1212 } | 1318 } |
| OLD | NEW |