Index: runtime/bin/gen_snapshot.cc |
diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc |
index 3f2940dc74b91486fbfbe31f3883063498e5a768..36c521a771147f98edc1a7c359cc81f2429f3513 100644 |
--- a/runtime/bin/gen_snapshot.cc |
+++ b/runtime/bin/gen_snapshot.cc |
@@ -42,7 +42,7 @@ static const int kRestartRequestExitCode = 1000; |
#define CHECK_RESULT(result) \ |
if (Dart_IsError(result)) { \ |
intptr_t exit_code = 0; \ |
- Log::PrintErr("Error: %s", Dart_GetError(result)); \ |
+ Log::PrintErr("Error: %s\n", Dart_GetError(result)); \ |
if (Dart_IsCompilationError(result)) { \ |
exit_code = kCompilationErrorExitCode; \ |
} else if (Dart_IsApiError(result)) { \ |
@@ -58,13 +58,26 @@ static const int kRestartRequestExitCode = 1000; |
} |
+// The core snapshot to use when creating isolates. Normally NULL, but loaded |
+// from a file when creating script snapshots. |
+const uint8_t* isolate_snapshot_data = NULL; |
+ |
+ |
// Global state that indicates whether a snapshot is to be created and |
// if so which file to write the snapshot into. |
+enum SnapshotKind { |
+ kCore, |
+ kScript, |
+ kAppAOTBlobs, |
+ kAppAOTAssembly, |
+}; |
+static SnapshotKind snapshot_kind = kCore; |
static const char* vm_snapshot_data_filename = NULL; |
static const char* vm_snapshot_instructions_filename = NULL; |
static const char* isolate_snapshot_data_filename = NULL; |
static const char* isolate_snapshot_instructions_filename = NULL; |
static const char* assembly_filename = NULL; |
+static const char* script_snapshot_filename = NULL; |
// Value of the --package-root flag. |
@@ -189,6 +202,32 @@ static const char* ProcessOption(const char* option, const char* name) { |
} |
+static bool ProcessSnapshotKindOption(const char* option) { |
+ const char* kind = ProcessOption(option, "--snapshot_kind="); |
+ if (kind == NULL) { |
+ return false; |
+ } |
+ if (strcmp(kind, "core") == 0) { |
+ snapshot_kind = kCore; |
+ return true; |
+ } else if (strcmp(kind, "script") == 0) { |
+ snapshot_kind = kScript; |
+ return true; |
+ } else if (strcmp(kind, "app-aot-blobs") == 0) { |
+ snapshot_kind = kAppAOTBlobs; |
+ return true; |
+ } else if (strcmp(kind, "app-aot-assembly") == 0) { |
+ snapshot_kind = kAppAOTAssembly; |
+ return true; |
+ } |
+ Log::PrintErr( |
+ "Unrecognized snapshot kind: '%s'\nValid kinds are: " |
+ "core, script, app-aot-blobs, app-aot-assembly\n", |
+ kind); |
+ return false; |
+} |
+ |
+ |
static bool ProcessVmSnapshotDataOption(const char* option) { |
const char* name = ProcessOption(option, "--vm_snapshot_data="); |
if (name != NULL) { |
@@ -239,6 +278,16 @@ static bool ProcessAssemblyOption(const char* option) { |
} |
+static bool ProcessScriptSnapshotOption(const char* option) { |
+ const char* name = ProcessOption(option, "--script_snapshot="); |
+ if (name != NULL) { |
+ script_snapshot_filename = name; |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+ |
static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { |
const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); |
if (name != NULL) { |
@@ -286,8 +335,7 @@ static bool ProcessURLmappingOption(const char* option) { |
static bool IsSnapshottingForPrecompilation() { |
- return (assembly_filename != NULL) || |
- (vm_snapshot_instructions_filename != NULL); |
+ return (snapshot_kind == kAppAOTBlobs) || (snapshot_kind == kAppAOTAssembly); |
} |
@@ -305,11 +353,13 @@ static int ParseArguments(int argc, |
// Parse out the vm options. |
while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
- if (ProcessVmSnapshotDataOption(argv[i]) || |
+ if (ProcessSnapshotKindOption(argv[i]) || |
+ ProcessVmSnapshotDataOption(argv[i]) || |
ProcessVmSnapshotInstructionsOption(argv[i]) || |
ProcessIsolateSnapshotDataOption(argv[i]) || |
ProcessIsolateSnapshotInstructionsOption(argv[i]) || |
ProcessAssemblyOption(argv[i]) || |
+ ProcessScriptSnapshotOption(argv[i]) || |
ProcessEmbedderEntryPointsManifestOption(argv[i]) || |
ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || |
ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { |
@@ -333,43 +383,63 @@ static int ParseArguments(int argc, |
(commandline_packages_file != NULL)) { |
Log::PrintErr( |
"Specifying both a packages directory and a packages " |
- "file is invalid.\n"); |
- return -1; |
- } |
- |
- if (vm_snapshot_data_filename == NULL) { |
- Log::PrintErr("No vm snapshot output file specified.\n\n"); |
+ "file is invalid.\n\n"); |
return -1; |
} |
- if (isolate_snapshot_data_filename == NULL) { |
- Log::PrintErr("No isolate snapshot output file specified.\n\n"); |
- return -1; |
+ switch (snapshot_kind) { |
+ case kCore: { |
+ if ((vm_snapshot_data_filename == NULL) || |
+ (isolate_snapshot_data_filename == NULL)) { |
+ Log::PrintErr( |
+ "Building a core snapshot requires specifying output files for " |
+ "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); |
+ return -1; |
+ } |
+ break; |
+ } |
+ case kScript: { |
+ if ((vm_snapshot_data_filename == NULL) || |
+ (isolate_snapshot_data_filename == NULL) || |
+ (script_snapshot_filename == NULL) || (script_name == NULL)) { |
+ Log::PrintErr( |
+ "Building a script snapshot requires specifying input files for " |
+ "--vm_snapshot_data and --isolate_snapshot_data, an output file " |
+ "for --script-snapshot, and a Dart script.\n\n"); |
+ return -1; |
+ } |
+ break; |
+ } |
+ case kAppAOTBlobs: { |
+ if ((vm_snapshot_data_filename == NULL) || |
+ (vm_snapshot_instructions_filename == NULL) || |
+ (isolate_snapshot_data_filename == NULL) || |
+ (isolate_snapshot_instructions_filename == NULL) || |
+ (script_name == NULL)) { |
+ Log::PrintErr( |
+ "Building an AOT snapshot as blobs requires specifying output " |
+ "files for --vm_snapshot_data, --vm_snapshot_instructions, " |
+ "--isolate_snapshot_data and --isolate_snapshot_instructions and a " |
+ "Dart script.\n\n"); |
+ return -1; |
+ } |
+ break; |
+ } |
+ case kAppAOTAssembly: { |
+ if ((assembly_filename == NULL) || (script_name == NULL)) { |
+ Log::PrintErr( |
+ "Building an AOT snapshot as assembly requires specifying " |
+ "an output file for --assembly and a Dart script.\n\n"); |
+ return -1; |
+ } |
+ break; |
+ } |
} |
- bool precompiled_as_assembly = assembly_filename != NULL; |
- bool precompiled_as_blobs = (vm_snapshot_instructions_filename != NULL) || |
- (isolate_snapshot_instructions_filename != NULL); |
- if (precompiled_as_assembly && precompiled_as_blobs) { |
- Log::PrintErr( |
- "Cannot request a precompiled snapshot simultaneously as " |
- "assembly (--assembly=<output.file>) and as blobs " |
- "(--instructions-blob=<output.file> and " |
- "--rodata-blob=<output.file>)\n\n"); |
- return -1; |
- } |
- if ((vm_snapshot_instructions_filename != NULL) != |
- (isolate_snapshot_instructions_filename != NULL)) { |
- Log::PrintErr( |
- "Requesting a precompiled snapshot as blobs requires both " |
- "(--vm_snapshot_instructions=<output.file> and " |
- "--isolate_snapshot_instructions=<output.file>)\n\n"); |
- return -1; |
- } |
if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { |
Log::PrintErr( |
- "Specifying an instructions snapshot filename indicates precompilation" |
- ". But no embedder entry points manifest was specified.\n\n"); |
+ "Building an AOT snapshot requires at least one embedder " |
+ "entry points manifest.\n\n"); |
return -1; |
} |
@@ -379,17 +449,24 @@ static int ParseArguments(int argc, |
static void WriteSnapshotFile(const char* filename, |
const uint8_t* buffer, |
- const intptr_t size) { |
+ const intptr_t size, |
+ bool write_magic_number = false) { |
File* file = File::Open(filename, File::kWriteTruncate); |
if (file == NULL) { |
Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
Dart_ExitScope(); |
Dart_ShutdownIsolate(); |
- Dart_Cleanup(); |
exit(kErrorExitCode); |
} |
+ if (write_magic_number) { |
+ // Write the magic number to indicate file is a script snapshot. |
+ DartUtils::WriteMagicNumber(file); |
+ } |
if (!file->WriteFully(buffer, size)) { |
- Log::PrintErr("Error: Failed to write snapshot file.\n\n"); |
+ Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
+ Dart_ExitScope(); |
+ Dart_ShutdownIsolate(); |
+ exit(kErrorExitCode); |
} |
file->Release(); |
} |
@@ -495,10 +572,10 @@ static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
if (Dart_IsError(source)) { |
return source; |
} |
- if (IsSnapshottingForPrecompilation()) { |
- return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
- } else { |
+ if (snapshot_kind == kCore) { |
return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); |
+ } else { |
+ return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
} |
} |
@@ -614,61 +691,65 @@ static void PrintUsage() { |
"Usage: \n" |
" gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
" \n" |
-" Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
-" If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" |
-" is created. It is required to specify the VM isolate snapshot and the \n" |
-" isolate snapshot. The other flags are related to precompilation and are \n" |
-" optional. \n" |
+" Global options: \n" |
+" --package_root=<path> Where to find packages, that is, \n" |
+" package:... imports. \n" |
+" \n" |
+" --packages=<packages_file> Where to find a package spec file \n" |
" \n" |
-" Precompilation: \n" |
-" In order to configure the snapshotter for precompilation, either \n" |
-" --assembly=outputfile or --instructions_blob=outputfile1 and \n" |
-" --rodata_blob=outputfile2 must be specified. If the former is choosen, \n" |
-" assembly for the target architecture will be output into the given file, \n" |
-" which must be compiled separately and either statically linked or \n" |
-" dynamically loaded in the target executable. The symbols \n" |
-" kInstructionsSnapshot and kDataSnapshot must be passed to Dart_Initialize.\n" |
-" If the latter is choosen, binary data is output into the given files, \n" |
-" which should be mmapped and passed to Dart_Initialize, with the \n" |
-" instruction blob being mapped as executable. \n" |
-" In both cases, a entry points manifest must be given to list the places \n" |
-" in the Dart program the embedder calls from the C API (Dart_Invoke, etc). \n" |
-" Not specifying these may cause the tree shaker to remove them from the \n" |
-" program. The format of this manifest is as follows. Each line in the \n" |
-" manifest is a comma separated list of three elements. The first entry is \n" |
-" the library URI, the second entry is the class name and the final entry \n" |
-" the function name. The file must be terminated with a newline charater. \n" |
+" --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" |
+" the command line to load the \n" |
+" libraries. \n" |
" \n" |
-" Example: \n" |
-" dart:something,SomeClass,doSomething \n" |
+" To create a core snapshot: \n" |
+" --snapshot-kind=core \n" |
+" --vm_snapshot_data=<output-file> \n" |
+" --isolate_snapshot_data=<output-file> \n" |
+" [<dart-script-file>] \n" |
" \n" |
-" Supported options: \n" |
-" --vm_snapshot_data=<file> A full snapshot is a compact \n" |
-" --isolate_snapshot_data=<file> representation of the dart vm isolate \n" |
-" heap and dart isolate heap states. \n" |
-" Both these options are required \n" |
+" Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
+" If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" |
+" is created. \n" |
" \n" |
-" --package_root=<path> Where to find packages, that is, \n" |
-" package:... imports. \n" |
+" To create a script snapshot with respect to a given core snapshot: \n" |
+" --snapshot-kind=script \n" |
+" --vm_snapshot_data=<intput-file> \n" |
+" --isolate_snapshot_data=<intput-file> \n" |
+" --script_snapshot=<output-file> \n" |
+" <dart-script-file> \n" |
" \n" |
-" --packages=<packages_file> Where to find a package spec file \n" |
+" Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
+" If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" |
+" is created. \n" |
" \n" |
-" --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" |
-" the command line to load the \n" |
-" libraries. \n" |
+" To create an AOT application snapshot as blobs suitable for loading with \n" |
+" mmap: \n" |
+" --snapshot-kind=app-aot-blobs \n" |
+" --vm_snapshot_data=<output-file> \n" |
+" --vm_snapshot_instructions=<output-file> \n" |
+" --isolate_snapshot_data=<output-file> \n" |
+" --isolate_snapshot_instructions=<output-file> \n" |
+" {--embedder_entry_points_manifest=<input-file>} \n" |
+" <dart-script-file> \n" |
" \n" |
-" --assembly=<file> (Precompilation only) Contains the \n" |
-" assembly that must be linked into \n" |
-" the target binary \n" |
+" To create an AOT application snapshot as assembly suitable for compilation \n" |
+" as a static or dynamic library: \n" |
+" mmap: \n" |
+" --snapshot-kind=app-aot-blobs \n" |
+" --assembly=<output-file> \n" |
+" {--embedder_entry_points_manifest=<input-file>} \n" |
+" <dart-script-file> \n" |
" \n" |
-" --vm_snapshot_instructions=<file> (Precompilation only) Contains the \n" |
-" --isolate_snapshot_instructions=<file> instructions and read-only data \n" |
-" that must be mapped into the target \n" |
-" binary \n" |
+" AOT snapshots require entry points manifest files, which list the places \n" |
+" in the Dart program the embedder calls from the C API (Dart_Invoke, etc). \n" |
+" Not specifying these may cause the tree shaker to remove them from the \n" |
+" program. The format of this manifest is as follows. Each line in the \n" |
+" manifest is a comma separated list of three elements. The first entry is \n" |
+" the library URI, the second entry is the class name and the final entry \n" |
+" the function name. The file must be terminated with a newline charater. \n" |
" \n" |
-" --embedder_entry_points_manifest=<file> (Precompilation or app \n" |
-" snapshots) Contains embedder's entry \n" |
-" points into Dart code from the C API. \n" |
+" Example: \n" |
+" dart:something,SomeClass,doSomething \n" |
"\n"); |
} |
// clang-format on |
@@ -1018,8 +1099,11 @@ static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { |
} |
-static void CreateAndWriteSnapshot() { |
- ASSERT(!IsSnapshottingForPrecompilation()); |
+static void CreateAndWriteCoreSnapshot() { |
+ ASSERT(snapshot_kind == kCore); |
+ ASSERT(vm_snapshot_data_filename != NULL); |
+ ASSERT(isolate_snapshot_data_filename != NULL); |
+ |
Dart_Handle result; |
uint8_t* vm_snapshot_data_buffer = NULL; |
intptr_t vm_snapshot_data_size = 0; |
@@ -1038,10 +1122,21 @@ static void CreateAndWriteSnapshot() { |
vm_snapshot_data_size); |
WriteSnapshotFile(isolate_snapshot_data_filename, |
isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
- Dart_ExitScope(); |
+} |
+ |
- // Shutdown the isolate. |
- Dart_ShutdownIsolate(); |
+static void CreateAndWriteScriptSnapshot() { |
+ ASSERT(snapshot_kind == kScript); |
+ ASSERT(script_snapshot_filename != NULL); |
+ |
+ // First create a snapshot. |
+ uint8_t* buffer = NULL; |
+ intptr_t size = 0; |
+ Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
+ CHECK_RESULT(result); |
+ |
+ // Now write it out to the specified file. |
+ WriteSnapshotFile(script_snapshot_filename, buffer, size, true); |
} |
@@ -1057,13 +1152,18 @@ static void CreateAndWritePrecompiledSnapshot( |
// Create a precompiled snapshot. |
bool as_assembly = assembly_filename != NULL; |
if (as_assembly) { |
+ ASSERT(snapshot_kind == kAppAOTAssembly); |
+ |
uint8_t* assembly_buffer = NULL; |
intptr_t assembly_size = 0; |
result = |
Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); |
CHECK_RESULT(result); |
+ |
WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); |
} else { |
+ ASSERT(snapshot_kind == kAppAOTBlobs); |
+ |
uint8_t* vm_snapshot_data_buffer = NULL; |
intptr_t vm_snapshot_data_size = 0; |
uint8_t* vm_snapshot_instructions_buffer = NULL; |
@@ -1079,6 +1179,7 @@ static void CreateAndWritePrecompiledSnapshot( |
&isolate_snapshot_instructions_buffer, |
&isolate_snapshot_instructions_size); |
CHECK_RESULT(result); |
+ |
WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
vm_snapshot_data_size); |
WriteSnapshotFile(vm_snapshot_instructions_filename, |
@@ -1090,11 +1191,6 @@ static void CreateAndWritePrecompiledSnapshot( |
isolate_snapshot_instructions_buffer, |
isolate_snapshot_instructions_size); |
} |
- |
- Dart_ExitScope(); |
- |
- // Shutdown the isolate. |
- Dart_ShutdownIsolate(); |
} |
@@ -1102,7 +1198,7 @@ static void SetupForUriResolution() { |
// Set up the library tag handler for this isolate. |
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
if (Dart_IsError(result)) { |
- Log::PrintErr("%s", Dart_GetError(result)); |
+ Log::PrintErr("%s\n", Dart_GetError(result)); |
Dart_ExitScope(); |
Dart_ShutdownIsolate(); |
exit(kErrorExitCode); |
@@ -1140,28 +1236,28 @@ static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
IsolateData* isolate_data = |
new IsolateData(script_uri, package_root, package_config); |
Dart_Isolate isolate = NULL; |
- isolate = Dart_CreateIsolate(script_uri, main, NULL, NULL, NULL, isolate_data, |
- error); |
+ isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL, |
+ NULL, isolate_data, error); |
if (isolate == NULL) { |
- Log::PrintErr("Error: Could not create service isolate"); |
+ Log::PrintErr("Error: Could not create service isolate\n"); |
return NULL; |
} |
Dart_EnterScope(); |
if (!Dart_IsServiceIsolate(isolate)) { |
- Log::PrintErr("Error: We only expect to create the service isolate"); |
+ Log::PrintErr("Error: We only expect to create the service isolate\n"); |
return NULL; |
} |
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
- // Setup the native resolver. |
- Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
- Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
if (Dart_IsError(result)) { |
- Log::PrintErr("Error: Could not set tag handler for service isolate"); |
+ Log::PrintErr("Error: Could not set tag handler for service isolate\n"); |
return NULL; |
} |
- CHECK_RESULT(result); |
+ // Setup the native resolver. |
+ Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
+ Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
+ |
ASSERT(Dart_IsServiceIsolate(isolate)); |
// Load embedder specific bits and return. Will not start http server. |
if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, |
@@ -1234,6 +1330,34 @@ int main(int argc, char** argv) { |
init_params.file_close = DartUtils::CloseFile; |
init_params.entropy_source = DartUtils::EntropySource; |
+ if (snapshot_kind == kScript) { |
+ File* file = File::Open(vm_snapshot_data_filename, File::kRead); |
+ if (file == NULL) { |
+ Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); |
+ return kErrorExitCode; |
+ } |
+ void* buffer = file->Map(File::kReadOnly, 0, file->Length()); |
+ if (buffer == NULL) { |
+ Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); |
+ return kErrorExitCode; |
+ } |
+ file->Close(); |
+ init_params.vm_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); |
+ |
+ file = File::Open(isolate_snapshot_data_filename, File::kRead); |
+ if (file == NULL) { |
+ Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); |
+ return kErrorExitCode; |
+ } |
+ buffer = file->Map(File::kReadOnly, 0, file->Length()); |
+ if (buffer == NULL) { |
+ Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); |
+ return kErrorExitCode; |
+ } |
+ file->Close(); |
+ isolate_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); |
+ } |
+ |
char* error = Dart_Initialize(&init_params); |
if (error != NULL) { |
Log::PrintErr("VM initialization failed: %s\n", error); |
@@ -1243,10 +1367,10 @@ int main(int argc, char** argv) { |
IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, |
commandline_packages_file); |
- Dart_Isolate isolate = |
- Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, &error); |
+ Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
+ NULL, NULL, isolate_data, &error); |
if (isolate == NULL) { |
- Log::PrintErr("Error: %s", error); |
+ Log::PrintErr("Error: %s\n", error); |
free(error); |
exit(kErrorExitCode); |
} |
@@ -1306,10 +1430,10 @@ int main(int argc, char** argv) { |
is_kernel_file |
? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
isolate_data, &error) |
- : Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, |
- &error); |
+ : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, |
+ isolate_data, &error); |
if (isolate == NULL) { |
- Log::PrintErr("%s", error); |
+ Log::PrintErr("%s\n", error); |
free(error); |
exit(kErrorExitCode); |
} |
@@ -1351,19 +1475,34 @@ int main(int argc, char** argv) { |
result = Dart_FinalizeLoading(false); |
CHECK_RESULT(result); |
- if (!IsSnapshottingForPrecompilation()) { |
- CreateAndWriteSnapshot(); |
- } else { |
- CreateAndWritePrecompiledSnapshot(entry_points); |
+ switch (snapshot_kind) { |
+ case kCore: |
+ CreateAndWriteCoreSnapshot(); |
+ break; |
+ case kScript: |
+ CreateAndWriteScriptSnapshot(); |
+ break; |
+ case kAppAOTBlobs: |
+ case kAppAOTAssembly: |
+ CreateAndWritePrecompiledSnapshot(entry_points); |
+ break; |
+ default: |
+ UNREACHABLE(); |
} |
+ Dart_ExitScope(); |
+ Dart_ShutdownIsolate(); |
+ |
CleanupEntryPointsCollection(entry_points); |
Dart_EnterIsolate(UriResolverIsolateScope::isolate); |
Dart_ShutdownIsolate(); |
} else { |
SetupForGenericSnapshotCreation(); |
- CreateAndWriteSnapshot(); |
+ CreateAndWriteCoreSnapshot(); |
+ |
+ Dart_ExitScope(); |
+ Dart_ShutdownIsolate(); |
} |
error = Dart_Cleanup(); |
if (error != NULL) { |