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

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

Issue 1507943002: Add ./tools/test.py -c precompiler -r dart_precompiled. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/bin/platform.cc » ('j') | tests/co19/co19-runtime.status » ('J')
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Global flag that is used to indicate that we want to compile all the 63 // Global flag that is used to indicate that we want to compile all the
64 // dart functions before running main and not compile anything thereafter. 64 // dart functions before running main and not compile anything thereafter.
65 static bool has_gen_precompiled_snapshot = false; 65 static bool has_gen_precompiled_snapshot = false;
66 66
67 67
68 // Global flag that is used to indicate that we want to run from a precompiled 68 // Global flag that is used to indicate that we want to run from a precompiled
69 // snapshot. 69 // snapshot.
70 static bool has_run_precompiled_snapshot = false; 70 static bool has_run_precompiled_snapshot = false;
71 71
72 72
73 // Value of the --gen/run_precompiled_snapshot flag.
74 // (This pointer points into an argv buffer and does not need to be
75 // free'd.)
76 static const char* precompiled_snapshot_directory = NULL;
77
78
73 // Global flag that is used to indicate that we want to compile everything in 79 // Global flag that is used to indicate that we want to compile everything in
74 // the same way as precompilation before main, then continue running in the 80 // the same way as precompilation before main, then continue running in the
75 // same process. 81 // same process.
76 static bool has_noopt = false; 82 static bool has_noopt = false;
77 83
78 84
79 extern const char* kPrecompiledLibraryName; 85 extern const char* kPrecompiledLibraryName;
80 extern const char* kPrecompiledSymbolName; 86 extern const char* kPrecompiledSymbolName;
81 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; 87 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate";
82 static const char* kPrecompiledIsolateName = "precompiled.isolate"; 88 static const char* kPrecompiledIsolateName = "precompiled.isolate";
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return false; 302 return false;
297 } 303 }
298 has_compile_all = true; 304 has_compile_all = true;
299 return true; 305 return true;
300 } 306 }
301 307
302 308
303 static bool ProcessGenPrecompiledSnapshotOption( 309 static bool ProcessGenPrecompiledSnapshotOption(
304 const char* arg, 310 const char* arg,
305 CommandLineOptions* vm_options) { 311 CommandLineOptions* vm_options) {
306 ASSERT(arg != NULL);
307 if (*arg != '\0') {
308 return false;
309 }
310 // Ensure that we are not already running using a full snapshot. 312 // Ensure that we are not already running using a full snapshot.
311 if (isolate_snapshot_buffer != NULL) { 313 if (isolate_snapshot_buffer != NULL) {
312 Log::PrintErr("Precompiled snapshots must be generated with" 314 Log::PrintErr("Precompiled snapshots must be generated with"
313 " dart_no_snapshot.\n"); 315 " dart_no_snapshot.\n");
314 return false; 316 return false;
315 } 317 }
318 ASSERT(arg != NULL);
319 precompiled_snapshot_directory = arg;
320 if ((precompiled_snapshot_directory[0] == '=') ||
321 (precompiled_snapshot_directory[0] == ':')) {
322 precompiled_snapshot_directory = &precompiled_snapshot_directory[1];
323 }
316 has_gen_precompiled_snapshot = true; 324 has_gen_precompiled_snapshot = true;
317 vm_options->AddArgument("--precompilation"); 325 vm_options->AddArgument("--precompilation");
318 return true; 326 return true;
319 } 327 }
320 328
321 329
322 static bool ProcessRunPrecompiledSnapshotOption( 330 static bool ProcessRunPrecompiledSnapshotOption(
323 const char* arg, 331 const char* arg,
324 CommandLineOptions* vm_options) { 332 CommandLineOptions* vm_options) {
325 ASSERT(arg != NULL); 333 ASSERT(arg != NULL);
326 if (*arg != '\0') { 334 precompiled_snapshot_directory = arg;
327 return false; 335 if ((precompiled_snapshot_directory[0] == '=') ||
336 (precompiled_snapshot_directory[0] == ':')) {
337 precompiled_snapshot_directory = &precompiled_snapshot_directory[1];
328 } 338 }
329 has_run_precompiled_snapshot = true; 339 has_run_precompiled_snapshot = true;
330 vm_options->AddArgument("--precompilation"); 340 vm_options->AddArgument("--precompilation");
331 return true; 341 return true;
332 } 342 }
333 343
334 344
335 static bool ProcessNooptOption( 345 static bool ProcessNooptOption(
336 const char* arg, 346 const char* arg,
337 CommandLineOptions* vm_options) { 347 CommandLineOptions* vm_options) {
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1013
1004 static void ServiceStreamCancelCallback(const char* stream_id) { 1014 static void ServiceStreamCancelCallback(const char* stream_id) {
1005 if (strcmp(stream_id, kStdoutStreamId) == 0) { 1015 if (strcmp(stream_id, kStdoutStreamId) == 0) {
1006 SetCaptureStdout(false); 1016 SetCaptureStdout(false);
1007 } else if (strcmp(stream_id, kStderrStreamId) == 0) { 1017 } else if (strcmp(stream_id, kStderrStreamId) == 0) {
1008 SetCaptureStderr(false); 1018 SetCaptureStderr(false);
1009 } 1019 }
1010 } 1020 }
1011 1021
1012 1022
1013 static void WriteSnapshotFile(const char* filename, 1023 static void WritePrecompiledSnapshotFile(const char* filename,
1014 const uint8_t* buffer, 1024 const uint8_t* buffer,
1015 const intptr_t size) { 1025 const intptr_t size) {
1016 File* file = File::Open(filename, File::kWriteTruncate); 1026 const char* qualified_filename;
1027 if (strlen(precompiled_snapshot_directory) > 0) {
1028 intptr_t len = snprintf(NULL, 0, "%s/%s",
1029 precompiled_snapshot_directory, filename);
1030 char* concat = reinterpret_cast<char*>(alloca(len + 1));
Florian Schneider 2015/12/17 12:53:25 I would avoid alloca - it is not standard C++, and
rmacnak 2015/12/17 19:20:51 Done.
1031 snprintf(concat, len + 1, "%s/%s",
1032 precompiled_snapshot_directory, filename);
1033 qualified_filename = concat;
1034 } else {
1035 qualified_filename = filename;
1036 }
1037
1038 File* file = File::Open(qualified_filename, File::kWriteTruncate);
1017 ASSERT(file != NULL); 1039 ASSERT(file != NULL);
1018 if (!file->WriteFully(buffer, size)) { 1040 if (!file->WriteFully(buffer, size)) {
1019 ErrorExit(kErrorExitCode, 1041 ErrorExit(kErrorExitCode,
1020 "Unable to open file %s for writing snapshot\n", 1042 "Unable to open file %s for writing snapshot\n",
1021 filename); 1043 qualified_filename);
1022 } 1044 }
1023 delete file; 1045 delete file;
1024 } 1046 }
1025 1047
1026 1048
1027 static void ReadSnapshotFile(const char* filename, 1049 static void ReadPrecompiledSnapshotFile(const char* filename,
1028 const uint8_t** buffer) { 1050 const uint8_t** buffer) {
1029 void* file = DartUtils::OpenFile(filename, false); 1051 const char* qualified_filename;
1052 if (strlen(precompiled_snapshot_directory) > 0) {
1053 intptr_t len = snprintf(NULL, 0, "%s/%s",
1054 precompiled_snapshot_directory, filename);
1055 char* concat = reinterpret_cast<char*>(alloca(len + 1));
Florian Schneider 2015/12/17 12:53:25 Same here. Maybe something like this: char* conca
rmacnak 2015/12/17 19:20:51 Done.
1056 snprintf(concat, len + 1, "%s/%s",
1057 precompiled_snapshot_directory, filename);
1058 qualified_filename = concat;
1059 } else {
1060 qualified_filename = filename;
1061 }
1062
1063 void* file = DartUtils::OpenFile(qualified_filename, false);
1030 if (file == NULL) { 1064 if (file == NULL) {
1031 ErrorExit(kErrorExitCode, 1065 ErrorExit(kErrorExitCode,
1032 "Error: Unable to open file %s for reading snapshot\n", filename); 1066 "Error: Unable to open file %s for reading snapshot\n",
1067 qualified_filename);
1033 } 1068 }
1034 intptr_t len = -1; 1069 intptr_t len = -1;
1035 DartUtils::ReadFile(buffer, &len, file); 1070 DartUtils::ReadFile(buffer, &len, file);
1036 if (*buffer == NULL || len == -1) { 1071 if (*buffer == NULL || len == -1) {
1037 ErrorExit(kErrorExitCode, 1072 ErrorExit(kErrorExitCode,
1038 "Error: Unable to read snapshot file %s\n", filename); 1073 "Error: Unable to read snapshot file %s\n", qualified_filename);
1039 } 1074 }
1040 DartUtils::CloseFile(file); 1075 DartUtils::CloseFile(file);
1041 } 1076 }
1042 1077
1043 1078
1044 static void* LoadLibrarySymbol(const char* libname, const char* symname) { 1079 static void* LoadLibrarySymbol(const char* libname, const char* symname) {
1045 void* library = Extensions::LoadExtensionLibrary(libname); 1080 void* library = Extensions::LoadExtensionLibrary(libname);
1046 if (library == NULL) { 1081 if (library == NULL) {
1047 Log::PrintErr("Error: Failed to load library '%s'\n", libname); 1082 Log::PrintErr("Error: Failed to load library '%s'\n", libname);
1048 Platform::Exit(kErrorExitCode); 1083 Platform::Exit(kErrorExitCode);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 intptr_t isolate_size = 0; 1244 intptr_t isolate_size = 0;
1210 uint8_t* instructions_buffer = NULL; 1245 uint8_t* instructions_buffer = NULL;
1211 intptr_t instructions_size = 0; 1246 intptr_t instructions_size = 0;
1212 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, 1247 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer,
1213 &vm_isolate_size, 1248 &vm_isolate_size,
1214 &isolate_buffer, 1249 &isolate_buffer,
1215 &isolate_size, 1250 &isolate_size,
1216 &instructions_buffer, 1251 &instructions_buffer,
1217 &instructions_size); 1252 &instructions_size);
1218 CHECK_RESULT(result); 1253 CHECK_RESULT(result);
1219 WriteSnapshotFile(kPrecompiledVmIsolateName, 1254 WritePrecompiledSnapshotFile(kPrecompiledVmIsolateName,
1220 vm_isolate_buffer, 1255 vm_isolate_buffer,
1221 vm_isolate_size); 1256 vm_isolate_size);
1222 WriteSnapshotFile(kPrecompiledIsolateName, 1257 WritePrecompiledSnapshotFile(kPrecompiledIsolateName,
1223 isolate_buffer, 1258 isolate_buffer,
1224 isolate_size); 1259 isolate_size);
1225 WriteSnapshotFile(kPrecompiledInstructionsName, 1260 WritePrecompiledSnapshotFile(kPrecompiledInstructionsName,
1226 instructions_buffer, 1261 instructions_buffer,
1227 instructions_size); 1262 instructions_size);
1228 } else { 1263 } else {
1229 if (has_compile_all) { 1264 if (has_compile_all) {
1230 result = Dart_CompileAll(); 1265 result = Dart_CompileAll();
1231 CHECK_RESULT(result); 1266 CHECK_RESULT(result);
1232 } 1267 }
1233 1268
1234 if (Dart_IsNull(root_lib)) { 1269 if (Dart_IsNull(root_lib)) {
1235 ErrorExit(kErrorExitCode, 1270 ErrorExit(kErrorExitCode,
1236 "Unable to find root library for '%s'\n", 1271 "Unable to find root library for '%s'\n",
1237 script_name); 1272 script_name);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1382
1348 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1383 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1349 1384
1350 // Start event handler. 1385 // Start event handler.
1351 EventHandler::Start(); 1386 EventHandler::Start();
1352 1387
1353 const uint8_t* instructions_snapshot = NULL; 1388 const uint8_t* instructions_snapshot = NULL;
1354 if (has_run_precompiled_snapshot) { 1389 if (has_run_precompiled_snapshot) {
1355 instructions_snapshot = reinterpret_cast<const uint8_t*>( 1390 instructions_snapshot = reinterpret_cast<const uint8_t*>(
1356 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); 1391 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName));
1357 ReadSnapshotFile(kPrecompiledVmIsolateName, &vm_isolate_snapshot_buffer); 1392 ReadPrecompiledSnapshotFile(kPrecompiledVmIsolateName,
1358 ReadSnapshotFile(kPrecompiledIsolateName, &isolate_snapshot_buffer); 1393 &vm_isolate_snapshot_buffer);
1394 ReadPrecompiledSnapshotFile(kPrecompiledIsolateName,
1395 &isolate_snapshot_buffer);
1359 } 1396 }
1360 1397
1361 // Initialize the Dart VM. 1398 // Initialize the Dart VM.
1362 char* error = Dart_Initialize( 1399 char* error = Dart_Initialize(
1363 vm_isolate_snapshot_buffer, instructions_snapshot, 1400 vm_isolate_snapshot_buffer, instructions_snapshot,
1364 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 1401 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
1365 DartUtils::OpenFile, 1402 DartUtils::OpenFile,
1366 DartUtils::ReadFile, 1403 DartUtils::ReadFile,
1367 DartUtils::WriteFile, 1404 DartUtils::WriteFile,
1368 DartUtils::CloseFile, 1405 DartUtils::CloseFile,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 Platform::Exit(Process::GlobalExitCode()); 1456 Platform::Exit(Process::GlobalExitCode());
1420 } 1457 }
1421 1458
1422 } // namespace bin 1459 } // namespace bin
1423 } // namespace dart 1460 } // namespace dart
1424 1461
1425 int main(int argc, char** argv) { 1462 int main(int argc, char** argv) {
1426 dart::bin::main(argc, argv); 1463 dart::bin::main(argc, argv);
1427 UNREACHABLE(); 1464 UNREACHABLE();
1428 } 1465 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/platform.cc » ('j') | tests/co19/co19-runtime.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698