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

Unified Diff: bin/main.cc

Issue 8970004: Changes to create an application snapshot which can be layered on top (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/vm/vm.status » ('j') | vm/dart_api_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/main.cc
===================================================================
--- bin/main.cc (revision 2543)
+++ bin/main.cc (working copy)
@@ -24,6 +24,11 @@
static char* canonical_script_name = NULL;
+// Global state that stores a pointer to the application script snapshot.
+static bool use_script_snapshot = false;
+static uint8_t* script_snapshot_buffer = NULL;
+
+
// Global state that indicates whether pprof symbol information is
// to be generated or not.
static const char* generate_pprof_symbols_filename = NULL;
@@ -44,32 +49,48 @@
}
-static const char* ProcessOption(const char* option, const char* name) {
- const intptr_t length = strlen(name);
- if (strncmp(option, name, length) == 0) {
- return (option + length);
- }
- return NULL;
+static void ProcessPprofOption(const char* filename) {
+ ASSERT(filename != NULL);
+ generate_pprof_symbols_filename = filename;
}
-static bool ProcessPprofOption(const char* option) {
- const char* kProfOption = "--generate_pprof_symbols=";
- const char* filename = ProcessOption(option, kProfOption);
- if (filename != NULL) {
- generate_pprof_symbols_filename = filename;
- }
- return filename != NULL;
+static void ProcessBreakpointOption(const char* funcname) {
+ ASSERT(funcname != NULL);
+ breakpoint_at = funcname;
}
-static bool ProcessDebugOption(const char* option) {
- const char* kDebugOption = "--break_at=";
- const char* func_name = ProcessOption(option, kDebugOption);
- if (func_name != NULL) {
- breakpoint_at = func_name;
+static void ProcessSnapshotOption(const char* snapshot) {
+ ASSERT(snapshot != NULL);
+ use_script_snapshot = true;
+}
+
+
+static struct {
+ const char* option_name;
+ void (*process)(const char* option);
+} main_options[] = {
+ { "--generate_pprof_symbols=", ProcessPprofOption },
+ { "--break_at=", ProcessBreakpointOption },
+ { "--use_script_snapshot", ProcessSnapshotOption },
Ivan Posva 2011/12/19 21:32:42 What about compile-all? In general we should figur
siva 2011/12/19 23:50:00 Added --compile_all to this list. As discussed off
+ { NULL, NULL }
+};
+
+
+static bool ProcessMainOptions(const char* option) {
+ int i = 0;
+ const char* name = main_options[0].option_name;
+ while (name != NULL) {
+ int length = strlen(name);
+ if (strncmp(option, name, length) == 0) {
+ main_options[i].process(option + length);
+ return true;
+ }
+ i += 1;
+ name = main_options[i].option_name;
}
- return func_name != NULL;
+ return false;
}
@@ -88,10 +109,8 @@
// Parse out the vm options.
while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
- if (ProcessPprofOption(argv[i])) {
+ if (ProcessMainOptions(argv[i])) {
i += 1;
- } else if (ProcessDebugOption(argv[i])) {
- i += 1;
} else {
vm_options->AddArgument(argv[i]);
i += 1;
@@ -237,7 +256,11 @@
Dart_EnterScope();
// Load the specified application script into the newly created isolate.
- library = LoadScript(canonical_script_name);
+ if (script_snapshot_buffer != NULL) {
+ library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer);
+ } else {
+ library = LoadScript(canonical_script_name);
+ }
if (Dart_IsError(library)) {
*error = strdup(Dart_GetError(library));
Dart_ExitScope();
@@ -254,7 +277,9 @@
Dart_ShutdownIsolate();
return false;
}
- Builtin::ImportLibrary(library); // Implicitly import builtin into app.
+ if (script_snapshot_buffer == NULL) {
+ Builtin::ImportLibrary(library); // Implicitly import builtin into app.
+ }
if (snapshot_buffer != NULL) {
// Setup the native resolver as the snapshot does not carry it.
Builtin::SetNativeResolver();
@@ -264,6 +289,54 @@
}
+static bool CaptureScriptSnapshot() {
+ char* error = NULL;
+ Dart_Handle result;
+
+ // First create an isolate and load up the specified script in it.
+ if (!CreateIsolateAndSetup(NULL, &error)) {
+ fprintf(stderr, "%s\n", error);
+ free(canonical_script_name);
+ free(error);
+ return false; // Indicates we encountered an error.
+ }
+
+ Dart_EnterScope();
+
+ // Lookup the library of the main script.
+ Dart_Handle script_url = Dart_NewString(canonical_script_name);
+ Dart_Handle library = Dart_LookupLibrary(script_url);
+ if (Dart_IsError(library)) {
+ fprintf(stderr, "%s\n", Dart_GetError(library));
+ Dart_ExitScope();
+ Dart_ShutdownIsolate();
+ free(canonical_script_name);
+ return false; // Indicates we encountered an error.
+ }
+
+ // Now create the script snapshot and save into a buffer.
+ uint8_t* buffer;
+ intptr_t size;
+ result = Dart_CreateScriptSnapshot(library, &buffer, &size);
+ if (Dart_IsError(result)) {
+ fprintf(stderr, "%s\n", Dart_GetError(result));
+ Dart_ExitScope();
+ Dart_ShutdownIsolate();
+ return false; // Indicates we encountered an error.
+ }
+
+ // Save the script snapshot as we are about to shutdown isolate.
Ivan Posva 2011/12/19 21:32:42 shutdown the isolate.
siva 2011/12/19 23:50:00 Done.
+ script_snapshot_buffer = reinterpret_cast<uint8_t*>(malloc(size));
+ ASSERT(script_snapshot_buffer != NULL);
+ memmove(script_snapshot_buffer, buffer, size);
+
+ // Shutdown this isolate.
+ Dart_ExitScope();
+ Dart_ShutdownIsolate();
+ return true;
+}
+
+
static void PrintUsage() {
fprintf(stderr,
"dart [<vm-flags>] <dart-script-file> [<dart-options>]\n");
@@ -311,6 +384,15 @@
return 255; // Indicates we encountered an error.
}
+ // If application snapshot option is specified, first create the
+ // application snapshot and then load the script using the snapshot
+ // created.
+ if (use_script_snapshot) {
+ if (!CaptureScriptSnapshot()) {
+ return 255; // Error capturing script snapshot, error already reported.
+ }
+ }
+
// Call CreateIsolateAndSetup which creates an isolate and loads up
// the specified application script.
char* error = NULL;
@@ -318,9 +400,11 @@
fprintf(stderr, "%s\n", error);
free(canonical_script_name);
free(error);
+ free(script_snapshot_buffer);
return 255; // Indicates we encountered an error.
}
+ free(script_snapshot_buffer); // Don't need it anymore.
Dart_Isolate isolate = Dart_CurrentIsolate();
ASSERT(isolate != NULL);
Dart_Handle result;
« no previous file with comments | « no previous file | tests/vm/vm.status » ('j') | vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698