Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: runtime/bin/main.cc

Issue 1373873004: Make --noopt behave like an in-place precompilation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync + enable checked mode Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_gen_precompiled_snapshot = false; 76 static bool has_gen_precompiled_snapshot = false;
77 77
78 78
79 // Global flag that is used to indicate that we want to run from a precompiled 79 // Global flag that is used to indicate that we want to run from a precompiled
80 // snapshot. 80 // snapshot.
81 static bool has_run_precompiled_snapshot = false; 81 static bool has_run_precompiled_snapshot = false;
82 82
83 83
84 // Global flag that is used to indicate that we want to compile everything in
85 // the same way as precompilation before main, then continue running in the
86 // same process.
87 static bool has_noopt = false;
88
89
84 extern const char* kPrecompiledLibraryName; 90 extern const char* kPrecompiledLibraryName;
85 extern const char* kPrecompiledSymbolName; 91 extern const char* kPrecompiledSymbolName;
86 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; 92 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate";
87 static const char* kPrecompiledIsolateName = "precompiled.isolate"; 93 static const char* kPrecompiledIsolateName = "precompiled.isolate";
88 static const char* kPrecompiledInstructionsName = "precompiled.S"; 94 static const char* kPrecompiledInstructionsName = "precompiled.S";
89 95
90 96
91 // Global flag that is used to indicate that we want to trace resolution of 97 // Global flag that is used to indicate that we want to trace resolution of
92 // URIs and the loading of libraries, parts and scripts. 98 // URIs and the loading of libraries, parts and scripts.
93 static bool has_trace_loading = false; 99 static bool has_trace_loading = false;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (*arg != '\0') { 325 if (*arg != '\0') {
320 return false; 326 return false;
321 } 327 }
322 // Ensure that we are not already running using a full snapshot. 328 // Ensure that we are not already running using a full snapshot.
323 if (isolate_snapshot_buffer != NULL) { 329 if (isolate_snapshot_buffer != NULL) {
324 Log::PrintErr("Precompiled snapshots must be generated with" 330 Log::PrintErr("Precompiled snapshots must be generated with"
325 " dart_no_snapshot.\n"); 331 " dart_no_snapshot.\n");
326 return false; 332 return false;
327 } 333 }
328 has_gen_precompiled_snapshot = true; 334 has_gen_precompiled_snapshot = true;
329 vm_options->AddArgument("--precompile"); 335 vm_options->AddArgument("--precompilation");
330 return true; 336 return true;
331 } 337 }
332 338
333 339
334 static bool ProcessRunPrecompiledSnapshotOption( 340 static bool ProcessRunPrecompiledSnapshotOption(
335 const char* arg, 341 const char* arg,
336 CommandLineOptions* vm_options) { 342 CommandLineOptions* vm_options) {
337 ASSERT(arg != NULL); 343 ASSERT(arg != NULL);
338 if (*arg != '\0') { 344 if (*arg != '\0') {
339 return false; 345 return false;
340 } 346 }
341 has_run_precompiled_snapshot = true; 347 has_run_precompiled_snapshot = true;
342 vm_options->AddArgument("--precompile"); 348 vm_options->AddArgument("--precompilation");
343 return true; 349 return true;
344 } 350 }
345 351
352
353 static bool ProcessNooptOption(
354 const char* arg,
355 CommandLineOptions* vm_options) {
356 ASSERT(arg != NULL);
357 if (*arg != '\0') {
358 return false;
359 }
360 has_noopt = true;
361 vm_options->AddArgument("--precompilation");
362 return true;
363 }
364
346 365
347 static bool ProcessDebugOption(const char* option_value, 366 static bool ProcessDebugOption(const char* option_value,
348 CommandLineOptions* vm_options) { 367 CommandLineOptions* vm_options) {
349 ASSERT(option_value != NULL); 368 ASSERT(option_value != NULL);
350 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, 369 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip,
351 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { 370 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) {
352 Log::PrintErr("unrecognized --debug option syntax. " 371 Log::PrintErr("unrecognized --debug option syntax. "
353 "Use --debug[:<port number>[/<IPv4 address>]]\n"); 372 "Use --debug[:<port number>[/<IPv4 address>]]\n");
354 return false; 373 return false;
355 } 374 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 { "-v", ProcessVerboseOption }, 495 { "-v", ProcessVerboseOption },
477 { "--verbose", ProcessVerboseOption }, 496 { "--verbose", ProcessVerboseOption },
478 { "--version", ProcessVersionOption }, 497 { "--version", ProcessVersionOption },
479 498
480 // VM specific options to the standalone dart program. 499 // VM specific options to the standalone dart program.
481 { "--break-at=", ProcessBreakpointOption }, 500 { "--break-at=", ProcessBreakpointOption },
482 { "--compile_all", ProcessCompileAllOption }, 501 { "--compile_all", ProcessCompileAllOption },
483 { "--debug", ProcessDebugOption }, 502 { "--debug", ProcessDebugOption },
484 { "--enable-vm-service", ProcessEnableVmServiceOption }, 503 { "--enable-vm-service", ProcessEnableVmServiceOption },
485 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, 504 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption },
505 { "--noopt", ProcessNooptOption },
486 { "--observe", ProcessObserveOption }, 506 { "--observe", ProcessObserveOption },
487 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, 507 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption },
488 { "--shutdown", ProcessShutdownOption }, 508 { "--shutdown", ProcessShutdownOption },
489 { "--snapshot=", ProcessGenScriptSnapshotOption }, 509 { "--snapshot=", ProcessGenScriptSnapshotOption },
490 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, 510 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption },
491 { "--trace-loading", ProcessTraceLoadingOption }, 511 { "--trace-loading", ProcessTraceLoadingOption },
492 { NULL, NULL } 512 { NULL, NULL }
493 }; 513 };
494 514
495 515
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 "--snapshot=<file_name>\n" 900 "--snapshot=<file_name>\n"
881 " loads Dart script and generates a snapshot in the specified file\n" 901 " loads Dart script and generates a snapshot in the specified file\n"
882 "\n" 902 "\n"
883 "--trace-loading\n" 903 "--trace-loading\n"
884 " enables tracing of library and script loading\n" 904 " enables tracing of library and script loading\n"
885 "\n" 905 "\n"
886 "--enable-vm-service[:<port number>]\n" 906 "--enable-vm-service[:<port number>]\n"
887 " enables the VM service and listens on specified port for connections\n" 907 " enables the VM service and listens on specified port for connections\n"
888 " (default port number is 8181)\n" 908 " (default port number is 8181)\n"
889 "\n" 909 "\n"
890 "--noopt\n"
891 " run unoptimized code only\n"
892 "\n"
893 "The following options are only used for VM development and may\n" 910 "The following options are only used for VM development and may\n"
894 "be changed in any future version:\n"); 911 "be changed in any future version:\n");
895 const char* print_flags = "--print_flags"; 912 const char* print_flags = "--print_flags";
896 Dart_SetVMFlags(1, &print_flags); 913 Dart_SetVMFlags(1, &print_flags);
897 } 914 }
898 } 915 }
899 916
900 917
901 static Dart_Handle SetBreakpoint(const char* breakpoint_at, 918 static Dart_Handle SetBreakpoint(const char* breakpoint_at,
902 Dart_Handle library) { 919 Dart_Handle library) {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } else { 1264 } else {
1248 // Lookup the library of the root script. 1265 // Lookup the library of the root script.
1249 Dart_Handle root_lib = Dart_RootLibrary(); 1266 Dart_Handle root_lib = Dart_RootLibrary();
1250 // Import the root library into the builtin library so that we can easily 1267 // Import the root library into the builtin library so that we can easily
1251 // lookup the main entry point exported from the root library. 1268 // lookup the main entry point exported from the root library.
1252 Dart_Handle builtin_lib = 1269 Dart_Handle builtin_lib =
1253 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 1270 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
1254 ASSERT(!Dart_IsError(builtin_lib)); 1271 ASSERT(!Dart_IsError(builtin_lib));
1255 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); 1272 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null());
1256 1273
1257 if (has_gen_precompiled_snapshot) { 1274 if (has_noopt || has_gen_precompiled_snapshot) {
1258 Dart_QualifiedFunctionName standalone_entry_points[] = { 1275 Dart_QualifiedFunctionName standalone_entry_points[] = {
1259 { "dart:_builtin", "::", "_getMainClosure" }, 1276 { "dart:_builtin", "::", "_getMainClosure" },
1260 { "dart:_builtin", "::", "_getPrintClosure" }, 1277 { "dart:_builtin", "::", "_getPrintClosure" },
1261 { "dart:_builtin", "::", "_getUriBaseClosure" }, 1278 { "dart:_builtin", "::", "_getUriBaseClosure" },
1262 { "dart:_builtin", "::", "_resolveUri" }, 1279 { "dart:_builtin", "::", "_resolveUri" },
1263 { "dart:_builtin", "::", "_setWorkingDirectory" }, 1280 { "dart:_builtin", "::", "_setWorkingDirectory" },
1264 { "dart:_builtin", "::", "_loadDataAsync" }, 1281 { "dart:_builtin", "::", "_loadDataAsync" },
1265 { "dart:io", "::", "_makeUint8ListView" }, 1282 { "dart:io", "::", "_makeUint8ListView" },
1266 { "dart:io", "::", "_makeDatagram" }, 1283 { "dart:io", "::", "_makeDatagram" },
1267 { "dart:io", "::", "_setupHooks" }, 1284 { "dart:io", "::", "_setupHooks" },
1268 { "dart:io", "CertificateException", "CertificateException." }, 1285 { "dart:io", "CertificateException", "CertificateException." },
1269 { "dart:io", "HandshakeException", "HandshakeException." }, 1286 { "dart:io", "HandshakeException", "HandshakeException." },
1270 { "dart:io", "TlsException", "TlsException." }, 1287 { "dart:io", "TlsException", "TlsException." },
1271 { "dart:io", "X509Certificate", "X509Certificate." }, 1288 { "dart:io", "X509Certificate", "X509Certificate." },
1272 { "dart:io", "_ExternalBuffer", "set:data" }, 1289 { "dart:io", "_ExternalBuffer", "set:data" },
1273 { "dart:io", "_Platform", "set:_nativeScript" }, 1290 { "dart:io", "_Platform", "set:_nativeScript" },
1274 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, 1291 { "dart:io", "_ProcessStartStatus", "set:_errorCode" },
1275 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, 1292 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" },
1276 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, 1293 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" },
1277 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, 1294 { "dart:io", "_SecureFilterImpl", "get:SIZE" },
1278 { "dart:vmservice_io", "::", "_addResource" }, 1295 { "dart:vmservice_io", "::", "_addResource" },
1279 { "dart:vmservice_io", "::", "main" }, 1296 { "dart:vmservice_io", "::", "main" },
1280 { NULL, NULL, NULL } // Must be terminated with NULL entries. 1297 { NULL, NULL, NULL } // Must be terminated with NULL entries.
1281 }; 1298 };
1282 1299
1283 result = Dart_Precompile(standalone_entry_points); 1300 const bool reset_fields = has_gen_precompiled_snapshot;
1301 result = Dart_Precompile(standalone_entry_points, reset_fields);
1284 DartExitOnError(result); 1302 DartExitOnError(result);
1303 }
1285 1304
1305 if (has_gen_precompiled_snapshot) {
1286 uint8_t* vm_isolate_buffer = NULL; 1306 uint8_t* vm_isolate_buffer = NULL;
1287 intptr_t vm_isolate_size = 0; 1307 intptr_t vm_isolate_size = 0;
1288 uint8_t* isolate_buffer = NULL; 1308 uint8_t* isolate_buffer = NULL;
1289 intptr_t isolate_size = 0; 1309 intptr_t isolate_size = 0;
1290 uint8_t* instructions_buffer = NULL; 1310 uint8_t* instructions_buffer = NULL;
1291 intptr_t instructions_size = 0; 1311 intptr_t instructions_size = 0;
1292 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, 1312 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer,
1293 &vm_isolate_size, 1313 &vm_isolate_size,
1294 &isolate_buffer, 1314 &isolate_buffer,
1295 &isolate_size, 1315 &isolate_size,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 exit(Process::GlobalExitCode()); 1411 exit(Process::GlobalExitCode());
1392 } 1412 }
1393 1413
1394 } // namespace bin 1414 } // namespace bin
1395 } // namespace dart 1415 } // namespace dart
1396 1416
1397 int main(int argc, char** argv) { 1417 int main(int argc, char** argv) {
1398 dart::bin::main(argc, argv); 1418 dart::bin::main(argc, argv);
1399 UNREACHABLE(); 1419 UNREACHABLE();
1400 } 1420 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698