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

Unified Diff: runtime/bin/main.cc

Issue 2786083002: Read platform.dill in the VM. (Closed)
Patch Set: Incorporate review comments and merge. Created 3 years, 8 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 | « pkg/kernel/lib/binary/ast_to_binary.dart ('k') | runtime/vm/bootstrap.cc » ('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 9ebbcd12eb2c9fe60a2894234a536cf53852882c..8e0a59543394eceb6e686bac39fe3da2ceadd4d4 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -34,6 +34,8 @@
#include "zlib/zlib.h"
#endif
+#include "vm/kernel.h"
+
namespace dart {
namespace bin {
@@ -67,6 +69,11 @@ static bool use_dart_frontend = false;
static const char* frontend_filename = NULL;
+// True if the VM should boostrap the SDK from a binary (.dill) file. The
+// filename points into an argv buffer and does not need to be freed.
+static bool use_platform_binary = false;
+static const char* platform_binary_filename = NULL;
+
// Value of the --save-feedback flag.
// (This pointer points into an argv buffer and does not need to be
// free'd.)
@@ -333,6 +340,18 @@ static bool ProcessFrontendOption(const char* filename,
}
+static bool ProcessPlatformOption(const char* filename,
+ CommandLineOptions* vm_options) {
+ ASSERT(filename != NULL);
+ if (filename[0] == '\0') {
+ return false;
+ }
+ use_platform_binary = true;
+ platform_binary_filename = filename;
+ return true;
+}
+
+
static bool ProcessUseBlobsOption(const char* arg,
CommandLineOptions* vm_options) {
ASSERT(arg != NULL);
@@ -557,6 +576,7 @@ static struct {
{"--compile_all", ProcessCompileAllOption},
{"--parse_all", ProcessParseAllOption},
{"--dfe=", ProcessFrontendOption},
+ {"--platform=", ProcessPlatformOption},
{"--enable-vm-service", ProcessEnableVmServiceOption},
{"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption},
{"--observe", ProcessObserveOption},
@@ -853,11 +873,25 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
}
#endif
- const uint8_t* kernel_file = NULL;
- intptr_t kernel_length = -1;
- bool is_kernel = false;
-
+ void* kernel_platform = NULL;
+ void* kernel_program = NULL;
if (!is_kernel_isolate && !is_service_isolate) {
+ const uint8_t* platform_file = NULL;
+ if (use_platform_binary) {
+ intptr_t platform_length = -1;
+ bool success = TryReadKernel(platform_binary_filename, &platform_file,
+ &platform_length);
+ if (!success) {
+ *error = strdup("The platform binary is not a valid Dart Kernel file.");
+ *exit_code = kErrorExitCode;
+ return NULL;
+ }
+ kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length);
+ }
+
+ bool is_kernel = false;
+ const uint8_t* kernel_file = NULL;
+ intptr_t kernel_length = -1;
if (use_dart_frontend) {
Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri);
*error = result.error; // Copy error message (if any).
@@ -869,22 +903,26 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
break;
case Dart_KernelCompilationStatus_Error:
*exit_code = kCompilationErrorExitCode;
- return NULL;
+ break;
case Dart_KernelCompilationStatus_Crash:
*exit_code = kDartFrontendErrorExitCode;
- return NULL;
+ break;
case Dart_KernelCompilationStatus_Unknown:
*exit_code = kErrorExitCode;
- return NULL;
+ break;
+ }
+ if (!is_kernel) {
+ free(const_cast<uint8_t*>(platform_file));
+ delete reinterpret_cast<kernel::Program*>(kernel_platform);
+ return NULL;
}
} else if (!isolate_run_app_snapshot) {
is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length);
}
- }
- void* kernel_program = NULL;
- if (is_kernel) {
- kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
+ if (is_kernel) {
+ kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
+ }
}
IsolateData* isolate_data =
@@ -892,14 +930,13 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
if (is_main_isolate && (snapshot_deps_filename != NULL)) {
isolate_data->set_dependencies(new MallocGrowableArray<char*>());
}
- // If the script is a Kernel binary, then we will try to bootstrap from the
- // script.
Dart_Isolate isolate =
- is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program,
- flags, isolate_data, error)
- : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
- isolate_snapshot_instructions, flags,
- isolate_data, error);
+ kernel_platform != NULL
+ ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform,
+ flags, isolate_data, error)
+ : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
+ isolate_snapshot_instructions, flags,
+ isolate_data, error);
if (isolate == NULL) {
delete isolate_data;
return NULL;
@@ -911,11 +948,11 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
CHECK_RESULT(result);
- if (is_kernel) {
+ if (kernel_program != NULL) {
Dart_Handle result = Dart_LoadKernel(kernel_program);
CHECK_RESULT(result);
}
- if (is_kernel || (isolate_snapshot_data != NULL)) {
+ if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) {
// Setup the native resolver as the snapshot does not carry it.
Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
Builtin::SetNativeResolver(Builtin::kIOLibrary);
@@ -985,7 +1022,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
Dart_Handle uri =
DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri));
CHECK_RESULT(uri);
- if (!is_kernel) {
+ if (kernel_platform == NULL) {
result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri);
CHECK_RESULT(result);
} else {
« no previous file with comments | « pkg/kernel/lib/binary/ast_to_binary.dart ('k') | runtime/vm/bootstrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698