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

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

Issue 2922913004: Add Dart_Save/LoadCompilationTrace. (Closed)
Patch Set: . Created 3 years, 6 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 | « runtime/bin/gen_snapshot.cc ('k') | 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 kScript, 77 kScript,
78 kAppAOT, 78 kAppAOT,
79 kAppJIT, 79 kAppJIT,
80 }; 80 };
81 static SnapshotKind gen_snapshot_kind = kNone; 81 static SnapshotKind gen_snapshot_kind = kNone;
82 static const char* snapshot_deps_filename = NULL; 82 static const char* snapshot_deps_filename = NULL;
83 #if !defined(DART_PRECOMPILED_RUNTIME) 83 #if !defined(DART_PRECOMPILED_RUNTIME)
84 DFE dfe; 84 DFE dfe;
85 #endif 85 #endif
86 86
87 // Value of the --save-compilation-trace flag.
88 // (This pointer points into an argv buffer and does not need to be
89 // free'd.)
90 static const char* save_compilation_trace_filename = NULL;
91
92 // Value of the --load-compilation-trace flag.
93 // (This pointer points into an argv buffer and does not need to be
94 // free'd.)
95 static const char* load_compilation_trace_filename = NULL;
96
87 // Value of the --save-feedback flag. 97 // Value of the --save-feedback flag.
88 // (This pointer points into an argv buffer and does not need to be 98 // (This pointer points into an argv buffer and does not need to be
89 // free'd.) 99 // free'd.)
90 static const char* save_feedback_filename = NULL; 100 static const char* save_feedback_filename = NULL;
91 101
92 // Value of the --load-feedback flag. 102 // Value of the --load-feedback flag.
93 // (This pointer points into an argv buffer and does not need to be 103 // (This pointer points into an argv buffer and does not need to be
94 // free'd.) 104 // free'd.)
95 static const char* load_feedback_filename = NULL; 105 static const char* load_feedback_filename = NULL;
96 106
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 CommandLineOptions* vm_options) { 210 CommandLineOptions* vm_options) {
201 ASSERT(arg != NULL); 211 ASSERT(arg != NULL);
202 if (*arg == '-') { 212 if (*arg == '-') {
203 return false; 213 return false;
204 } 214 }
205 commandline_packages_file = arg; 215 commandline_packages_file = arg;
206 return true; 216 return true;
207 } 217 }
208 218
209 219
220 static bool ProcessSaveCompilationTraceOption(const char* arg,
221 CommandLineOptions* vm_options) {
222 ASSERT(arg != NULL);
223 if (*arg == '-') {
224 return false;
225 }
226 save_compilation_trace_filename = arg;
227 return true;
228 }
229
230
231 static bool ProcessLoadCompilationTraceOption(const char* arg,
232 CommandLineOptions* vm_options) {
233 ASSERT(arg != NULL);
234 if (*arg == '-') {
235 return false;
236 }
237 load_compilation_trace_filename = arg;
238 return true;
239 }
240
241
210 static bool ProcessSaveFeedbackOption(const char* arg, 242 static bool ProcessSaveFeedbackOption(const char* arg,
211 CommandLineOptions* vm_options) { 243 CommandLineOptions* vm_options) {
212 ASSERT(arg != NULL); 244 ASSERT(arg != NULL);
213 if (*arg == '-') { 245 if (*arg == '-') {
214 return false; 246 return false;
215 } 247 }
216 save_feedback_filename = arg; 248 save_feedback_filename = arg;
217 return true; 249 return true;
218 } 250 }
219 251
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 {"--dfe=", ProcessFrontendOption}, 620 {"--dfe=", ProcessFrontendOption},
589 {"--platform=", ProcessPlatformOption}, 621 {"--platform=", ProcessPlatformOption},
590 #endif 622 #endif
591 {"--enable-vm-service", ProcessEnableVmServiceOption}, 623 {"--enable-vm-service", ProcessEnableVmServiceOption},
592 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, 624 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption},
593 {"--observe", ProcessObserveOption}, 625 {"--observe", ProcessObserveOption},
594 {"--snapshot=", ProcessSnapshotFilenameOption}, 626 {"--snapshot=", ProcessSnapshotFilenameOption},
595 {"--snapshot-kind=", ProcessSnapshotKindOption}, 627 {"--snapshot-kind=", ProcessSnapshotKindOption},
596 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, 628 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption},
597 {"--use-blobs", ProcessUseBlobsOption}, 629 {"--use-blobs", ProcessUseBlobsOption},
630 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption},
631 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption},
598 {"--save-feedback=", ProcessSaveFeedbackOption}, 632 {"--save-feedback=", ProcessSaveFeedbackOption},
599 {"--load-feedback=", ProcessLoadFeedbackOption}, 633 {"--load-feedback=", ProcessLoadFeedbackOption},
600 {"--trace-loading", ProcessTraceLoadingOption}, 634 {"--trace-loading", ProcessTraceLoadingOption},
601 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, 635 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption},
602 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, 636 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption},
603 {"--short_socket_read", ProcessShortSocketReadOption}, 637 {"--short_socket_read", ProcessShortSocketReadOption},
604 {"--short_socket_write", ProcessShortSocketWriteOption}, 638 {"--short_socket_write", ProcessShortSocketWriteOption},
605 #if !defined(HOST_OS_MACOS) 639 #if !defined(HOST_OS_MACOS)
606 {"--root-certs-file=", ProcessRootCertsFileOption}, 640 {"--root-certs-file=", ProcessRootCertsFileOption},
607 {"--root-certs-cache=", ProcessRootCertsCacheOption}, 641 {"--root-certs-cache=", ProcessRootCertsCacheOption},
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 if (file == NULL) { 1431 if (file == NULL) {
1398 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); 1432 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
1399 } 1433 }
1400 if (!file->WriteFully(buffer, size)) { 1434 if (!file->WriteFully(buffer, size)) {
1401 ErrorExit(kErrorExitCode, "Unable to write file %s\n", filename); 1435 ErrorExit(kErrorExitCode, "Unable to write file %s\n", filename);
1402 } 1436 }
1403 file->Release(); 1437 file->Release();
1404 } 1438 }
1405 1439
1406 1440
1441 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) {
1442 File* file = File::Open(filename, File::kRead);
1443 if (file == NULL) {
1444 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
1445 }
1446 *size = file->Length();
1447 *buffer = reinterpret_cast<uint8_t*>(malloc(*size));
1448 if (!file->ReadFully(*buffer, *size)) {
1449 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename);
1450 }
1451 file->Release();
1452 }
1453
1454
1407 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { 1455 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
1408 // Call CreateIsolateAndSetup which creates an isolate and loads up 1456 // Call CreateIsolateAndSetup which creates an isolate and loads up
1409 // the specified application script. 1457 // the specified application script.
1410 char* error = NULL; 1458 char* error = NULL;
1411 bool is_main_isolate = true; 1459 bool is_main_isolate = true;
1412 int exit_code = 0; 1460 int exit_code = 0;
1413 char* isolate_name = BuildIsolateName(script_name, "main"); 1461 char* isolate_name = BuildIsolateName(script_name, "main");
1414 Dart_Isolate isolate = CreateIsolateAndSetupHelper( 1462 Dart_Isolate isolate = CreateIsolateAndSetupHelper(
1415 is_main_isolate, script_name, "main", commandline_package_root, 1463 is_main_isolate, script_name, "main", commandline_package_root,
1416 commandline_packages_file, NULL, &error, &exit_code); 1464 commandline_packages_file, NULL, &error, &exit_code);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 } 1588 }
1541 1589
1542 if (gen_snapshot_kind == kAppAOT) { 1590 if (gen_snapshot_kind == kAppAOT) {
1543 GenerateAppAOTSnapshot(); 1591 GenerateAppAOTSnapshot();
1544 } else { 1592 } else {
1545 if (Dart_IsNull(root_lib)) { 1593 if (Dart_IsNull(root_lib)) {
1546 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", 1594 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n",
1547 script_name); 1595 script_name);
1548 } 1596 }
1549 1597
1550 if (gen_snapshot_kind == kAppJIT) Dart_SortClasses(); 1598 if (gen_snapshot_kind == kAppJIT) {
1599 result = Dart_SortClasses();
1600 CHECK_RESULT(result);
1601 }
1602
1603 if (load_compilation_trace_filename != NULL) {
1604 uint8_t* buffer = NULL;
1605 intptr_t size = 0;
1606 ReadFile(load_compilation_trace_filename, &buffer, &size);
1607 result = Dart_LoadCompilationTrace(buffer, size);
1608 CHECK_RESULT(result);
1609 }
1551 1610
1552 // The helper function _getMainClosure creates a closure for the main 1611 // The helper function _getMainClosure creates a closure for the main
1553 // entry point which is either explicitly or implictly exported from the 1612 // entry point which is either explicitly or implictly exported from the
1554 // root library. 1613 // root library.
1555 Dart_Handle main_closure = 1614 Dart_Handle main_closure =
1556 Dart_Invoke(isolate_data->builtin_lib(), 1615 Dart_Invoke(isolate_data->builtin_lib(),
1557 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); 1616 Dart_NewStringFromCString("_getMainClosure"), 0, NULL);
1558 CHECK_RESULT(main_closure); 1617 CHECK_RESULT(main_closure);
1559 1618
1560 // Call _startIsolate in the isolate library to enable dispatching the 1619 // Call _startIsolate in the isolate library to enable dispatching the
(...skipping 17 matching lines...) Expand all
1578 if (!Dart_IsCompilationError(result)) { 1637 if (!Dart_IsCompilationError(result)) {
1579 Snapshot::GenerateAppJIT(snapshot_filename); 1638 Snapshot::GenerateAppJIT(snapshot_filename);
1580 } 1639 }
1581 } 1640 }
1582 CHECK_RESULT(result); 1641 CHECK_RESULT(result);
1583 1642
1584 if (save_feedback_filename != NULL) { 1643 if (save_feedback_filename != NULL) {
1585 uint8_t* buffer = NULL; 1644 uint8_t* buffer = NULL;
1586 intptr_t size = 0; 1645 intptr_t size = 0;
1587 result = Dart_SaveJITFeedback(&buffer, &size); 1646 result = Dart_SaveJITFeedback(&buffer, &size);
1588 if (Dart_IsError(result)) { 1647 CHECK_RESULT(result);
1589 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1590 }
1591 WriteFile(save_feedback_filename, buffer, size); 1648 WriteFile(save_feedback_filename, buffer, size);
1592 } 1649 }
1650
1651 if (save_compilation_trace_filename != NULL) {
1652 uint8_t* buffer = NULL;
1653 intptr_t size = 0;
1654 result = Dart_SaveCompilationTrace(&buffer, &size);
1655 CHECK_RESULT(result);
1656 WriteFile(save_compilation_trace_filename, buffer, size);
1657 }
1593 } 1658 }
1594 } 1659 }
1595 1660
1596 if (snapshot_deps_filename != NULL) { 1661 if (snapshot_deps_filename != NULL) {
1597 Loader::ResolveDependenciesAsFilePaths(); 1662 Loader::ResolveDependenciesAsFilePaths();
1598 IsolateData* isolate_data = 1663 IsolateData* isolate_data =
1599 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); 1664 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
1600 ASSERT(isolate_data != NULL); 1665 ASSERT(isolate_data != NULL);
1601 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); 1666 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
1602 ASSERT(dependencies != NULL); 1667 ASSERT(dependencies != NULL);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 Platform::Exit(Process::GlobalExitCode()); 1940 Platform::Exit(Process::GlobalExitCode());
1876 } 1941 }
1877 1942
1878 } // namespace bin 1943 } // namespace bin
1879 } // namespace dart 1944 } // namespace dart
1880 1945
1881 int main(int argc, char** argv) { 1946 int main(int argc, char** argv) {
1882 dart::bin::main(argc, argv); 1947 dart::bin::main(argc, argv);
1883 UNREACHABLE(); 1948 UNREACHABLE();
1884 } 1949 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698