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

Unified Diff: runtime/bin/main.cc

Issue 1318803002: Toward precompiled snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/extensions.h ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/main.cc
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index 4e2b24acce608c4e11f99cce29d897f7384bef8b..b657bff5cd2dc23a9e482df11f2f1fa15d2ff094 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -76,6 +76,11 @@ static bool has_compile_all = false;
static bool has_precompile = false;
+// Global flag that is used to indicate that we want to run from a precompiled
+// snapshot.
+static bool has_precompiled = false;
+
+
// Global flag that is used to indicate that we want to trace resolution of
// URIs and the loading of libraries, parts and scripts.
static bool has_trace_loading = false;
@@ -301,6 +306,18 @@ static bool ProcessPrecompileOption(const char* arg,
}
+static bool ProcessPrecompiledOption(const char* arg,
+ CommandLineOptions* vm_options) {
+ ASSERT(arg != NULL);
+ if (*arg != '\0') {
+ return false;
+ }
+ has_precompiled = true;
+ vm_options->AddArgument("--precompile");
+ return true;
+}
+
+
static bool ProcessDebugOption(const char* option_value,
CommandLineOptions* vm_options) {
ASSERT(option_value != NULL);
@@ -412,6 +429,7 @@ static struct {
{ "--break-at=", ProcessBreakpointOption },
{ "--compile_all", ProcessCompileAllOption },
{ "--precompile", ProcessPrecompileOption },
+ { "--precompiled", ProcessPrecompiledOption },
{ "--debug", ProcessDebugOption },
{ "--snapshot=", ProcessGenScriptSnapshotOption },
{ "--enable-vm-service", ProcessEnableVmServiceOption },
@@ -959,6 +977,18 @@ static void ServiceStreamCancelCallback(const char* stream_id) {
}
+static void WriteSnapshotFile(const char* filename,
+ const uint8_t* buffer,
+ const intptr_t size) {
+ File* file = File::Open(filename, File::kWriteTruncate);
+ ASSERT(file != NULL);
+ if (!file->WriteFully(buffer, size)) {
+ Log::PrintErr("Error: Failed to write snapshot file.\n\n");
+ }
+ delete file;
+}
+
+
void main(int argc, char** argv) {
char* script_name;
const int EXTRA_VM_ARGUMENTS = 2;
@@ -1032,8 +1062,62 @@ void main(int argc, char** argv) {
DebuggerConnectionHandler::InitForVmService();
}
+ const uint8_t* instructions_snapshot = NULL;
+ if (has_precompiled) {
rmacnak 2015/08/27 00:22:29 For now, load everything from files. The embedder
+ const char* kPrecompiledLibName = "libprecompiled.so";
+ const char* kPrecompiledSymName = "kInstructionsSnapshot";
+ const char* kPrecompiledVmIsolateName = "precompiled.vmisolate";
+ const char* kPrecompiledIsolateName = "precompiled.isolate";
+
+ void* precompiled_lib =
+ Extensions::LoadExtensionLibrary(kPrecompiledLibName);
+ if (precompiled_lib == NULL) {
+ fprintf(stderr, "Failed to load library '%s'\n", kPrecompiledLibName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+
+ instructions_snapshot = reinterpret_cast<const uint8_t*>(
+ Extensions::ResolveSymbol(precompiled_lib, kPrecompiledSymName));
+ if (instructions_snapshot == NULL) {
+ fprintf(stderr, "Failed to load symbol '%s'\n", kPrecompiledSymName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+
+ void* file = DartUtils::OpenFile(kPrecompiledVmIsolateName, false);
+ if (file == NULL) {
+ fprintf(stderr, "Failed to open '%s'\n", kPrecompiledVmIsolateName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+ intptr_t len = -1;
+ DartUtils::ReadFile(&vm_isolate_snapshot_buffer, &len, file);
+ if (vm_isolate_snapshot_buffer == NULL || len == -1) {
+ fprintf(stderr, "Failed to read '%s'\n", kPrecompiledVmIsolateName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+ DartUtils::CloseFile(file);
+
+ file = DartUtils::OpenFile(kPrecompiledIsolateName, false);
+ if (file == NULL) {
+ fprintf(stderr, "Failed to open '%s'\n", kPrecompiledIsolateName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+ len = -1;
+ DartUtils::ReadFile(&isolate_snapshot_buffer, &len, file);
+ if (isolate_snapshot_buffer == NULL || len == -1) {
+ fprintf(stderr, "Failed to read '%s'\n", kPrecompiledVmIsolateName);
+ fflush(stderr);
+ exit(kErrorExitCode);
+ }
+ DartUtils::CloseFile(file);
+ }
+
// Initialize the Dart VM.
- if (!Dart_Initialize(vm_isolate_snapshot_buffer, NULL,
+ if (!Dart_Initialize(vm_isolate_snapshot_buffer, instructions_snapshot,
CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
DartUtils::OpenFile,
DartUtils::ReadFile,
@@ -1114,6 +1198,32 @@ void main(int argc, char** argv) {
if (has_precompile) {
result = Dart_Precompile();
DartExitOnError(result);
+
+ uint8_t* vm_isolate_buffer = NULL;
+ intptr_t vm_isolate_size = 0;
+ uint8_t* isolate_buffer = NULL;
+ intptr_t isolate_size = 0;
+ uint8_t* instructions_buffer = NULL;
+ intptr_t instructions_size = 0;
+ result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer,
+ &vm_isolate_size,
+ &isolate_buffer,
+ &isolate_size,
+ &instructions_buffer,
+ &instructions_size);
+
+ DartExitOnError(result);
+
+ WriteSnapshotFile("precompiled.vmisolate",
+ vm_isolate_buffer,
+ vm_isolate_size);
+ WriteSnapshotFile("precompiled.isolate",
+ isolate_buffer,
+ isolate_size);
+ WriteSnapshotFile("precompiled.instructions",
+ instructions_buffer,
+ instructions_size);
+
} else if (has_compile_all) {
result = Dart_CompileAll();
DartExitOnError(result);
« no previous file with comments | « runtime/bin/extensions.h ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698