Load service isolate from a .dill file.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2925203002 .
This commit is contained in:
Siva Chandra 2017-06-21 12:16:41 -07:00
parent fcb23e967c
commit b0c2a382ca
3 changed files with 92 additions and 30 deletions

View file

@ -13,12 +13,15 @@ namespace dart {
namespace bin {
const char kPlatformBinaryName[] = "platform.dill";
const char kVMServiceIOBinaryName[] = "vmservice_io.dill";
DFE::DFE()
: frontend_filename_(NULL),
platform_binary_filename_(NULL),
kernel_platform_(NULL) {}
vmservice_io_binary_filename_(NULL),
kernel_platform_(NULL),
kernel_vmservice_io_(NULL) {}
DFE::~DFE() {
@ -33,6 +36,11 @@ DFE::~DFE() {
delete reinterpret_cast<kernel::Program*>(kernel_platform_);
kernel_platform_ = NULL;
}
if (kernel_vmservice_io_ != NULL) {
delete reinterpret_cast<kernel::Program*>(kernel_vmservice_io_);
kernel_vmservice_io_ = NULL;
}
}
@ -43,6 +51,13 @@ void DFE::SetKernelBinaries(const char* name) {
platform_binary_filename_ = new char[len];
snprintf(platform_binary_filename_, len, "%s%s%s", name,
File::PathSeparator(), kPlatformBinaryName);
len = snprintf(NULL, 0, "%s%s%s", name, File::PathSeparator(),
kVMServiceIOBinaryName) +
1;
vmservice_io_binary_filename_ = new char[len];
snprintf(vmservice_io_binary_filename_, len, "%s%s%s", name,
File::PathSeparator(), kVMServiceIOBinaryName);
}
@ -109,6 +124,11 @@ void* DFE::ReadPlatform() {
}
void* DFE::ReadVMServiceIO() {
return kernel_vmservice_io_ = ReadScript(vmservice_io_binary_filename_);
}
void* DFE::ReadScript(const char* script_uri) {
const uint8_t* buffer = NULL;
intptr_t buffer_length = -1;

View file

@ -32,6 +32,8 @@ class DFE {
void* kernel_platform() const { return kernel_platform_; }
void* kernel_vmservice_io() const { return kernel_vmservice_io_; }
// Method to reload a script into a running a isolate.
// If the specified script [url] is not a kernel IR, compile it first using
// DFE and then reload the resulting kernel IR into the isolate.
@ -50,6 +52,10 @@ class DFE {
// Returns an in memory kernel representation of the platform kernel file.
void* ReadPlatform();
// Reads the vmservice_io kernel file.
// Returns the in memory representation of the vmservice_io kernel file.
void* ReadVMServiceIO();
// Reads the script kernel file if specified 'script_uri' is a kernel file.
// Returns an in memory kernel representation of the specified script is a
// valid kernel file, false otherwise.
@ -67,7 +73,9 @@ class DFE {
const char* frontend_filename_;
char* platform_binary_filename_;
char* vmservice_io_binary_filename_;
void* kernel_platform_;
void* kernel_vmservice_io_;
DISALLOW_COPY_AND_ASSIGN(DFE);
};

View file

@ -826,19 +826,30 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
}
#define SAVE_ERROR_AND_EXIT(result) \
*error = strdup(Dart_GetError(result)); \
if (Dart_IsCompilationError(result)) { \
*exit_code = kCompilationErrorExitCode; \
} else if (Dart_IsApiError(result)) { \
*exit_code = kApiErrorExitCode; \
} else { \
*exit_code = kErrorExitCode; \
} \
Dart_ExitScope(); \
Dart_ShutdownIsolate(); \
return NULL;
#define CHECK_RESULT(result) \
if (Dart_IsError(result)) { \
*error = strdup(Dart_GetError(result)); \
if (Dart_IsCompilationError(result)) { \
*exit_code = kCompilationErrorExitCode; \
} else if (Dart_IsApiError(result)) { \
*exit_code = kApiErrorExitCode; \
} else { \
*exit_code = kErrorExitCode; \
} \
Dart_ExitScope(); \
Dart_ShutdownIsolate(); \
return NULL; \
SAVE_ERROR_AND_EXIT(result); \
}
#define CHECK_RESULT_CLEANUP(result, cleanup) \
if (Dart_IsError(result)) { \
delete (cleanup); \
SAVE_ERROR_AND_EXIT(result); \
}
@ -1028,23 +1039,35 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
#if defined(DART_PRECOMPILED_RUNTIME)
// AOT: All isolates start from the app snapshot.
bool isolate_run_app_snapshot = true;
bool skip_library_load = true;
const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data;
const uint8_t* isolate_snapshot_instructions =
app_isolate_snapshot_instructions;
#else
// JIT: Service isolate uses the core libraries snapshot.
bool isolate_run_app_snapshot = false;
bool skip_library_load = false;
const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data;
const uint8_t* isolate_snapshot_instructions =
core_isolate_snapshot_instructions;
#endif // !defined(DART_PRECOMPILED_RUNTIME)
Dart_Isolate isolate = NULL;
IsolateData* isolate_data =
new IsolateData(script_uri, package_root, packages_config, NULL);
Dart_Isolate isolate = Dart_CreateIsolate(
script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions,
flags, isolate_data, error);
#if defined(DART_PRECOMPILED_RUNTIME)
isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
isolate_snapshot_instructions, flags,
isolate_data, error);
#else
if (dfe.UsePlatformBinary()) {
isolate = Dart_CreateIsolateFromKernel(
script_uri, NULL, dfe.kernel_platform(), flags, isolate_data, error);
} else {
isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
isolate_snapshot_instructions, flags,
isolate_data, error);
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
if (isolate == NULL) {
delete isolate_data;
return NULL;
@ -1055,8 +1078,15 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
CHECK_RESULT(result);
#if !defined(DART_PRECOMPILED_RUNTIME)
if (dfe.UsePlatformBinary()) {
Dart_Handle library = Dart_LoadKernel(dfe.kernel_vmservice_io());
CHECK_RESULT_CLEANUP(library, isolate_data);
skip_library_load = true;
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
// Load embedder specific bits and return.
bool skip_library_load = isolate_run_app_snapshot;
if (!VmService::Setup(vm_service_server_ip, vm_service_server_port,
skip_library_load, vm_service_dev_mode,
trace_loading)) {
@ -1832,6 +1862,22 @@ void main(int argc, char** argv) {
Process::SetExitHook(SnapshotOnExitHook);
}
#if !defined(DART_PRECOMPILED_RUNTIME)
// If a kernel platform binary file is specified, read it. This
// step will become redundant once we have the snapshot version
// of the kernel core/platform libraries.
if (dfe.UsePlatformBinary()) {
if (dfe.ReadPlatform() == NULL) {
Log::PrintErr("The platform binary is not a valid Dart Kernel file.");
Platform::Exit(kErrorExitCode);
}
if (dfe.ReadVMServiceIO() == NULL) {
Log::PrintErr("Could not read dart:vmservice_io binary file.");
Platform::Exit(kErrorExitCode);
}
}
#endif
Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
// Start event handler.
@ -1866,18 +1912,6 @@ void main(int argc, char** argv) {
&ServiceStreamCancelCallback);
Dart_SetFileModifiedCallback(&FileModifiedCallback);
#if !defined(DART_PRECOMPILED_RUNTIME)
// If a kernel platform binary file is specified, read it. This
// step will become redundant once we have the snapshot version
// of the kernel core/platform libraries.
if (dfe.UsePlatformBinary()) {
if (dfe.ReadPlatform() == NULL) {
Log::PrintErr("The platform binary is not a valid Dart Kernel file.");
Platform::Exit(kErrorExitCode);
}
}
#endif
// Run the main isolate until we aren't told to restart.
while (RunMainIsolate(script_name, &dart_options)) {
Log::PrintErr("Restarting VM\n");