@@ -81,6 +81,7 @@ enum SnapshotKind {
8181 kCoreJIT ,
8282 kApp ,
8383 kAppJIT ,
84+ kAppAOTBlobs ,
8485 kAppAOTAssembly ,
8586 kAppAOTElf ,
8687 kVMAOTAssembly ,
@@ -94,6 +95,7 @@ static const char* kSnapshotKindNames[] = {
9495 " core-jit" ,
9596 " app" ,
9697 " app-jit" ,
98+ " app-aot-blobs" ,
9799 " app-aot-assembly" ,
98100 " app-aot-elf" ,
99101 " vm-aot-assembly" ,
@@ -144,7 +146,8 @@ DEFINE_ENUM_OPTION(snapshot_kind, SnapshotKind, snapshot_kind);
144146DEFINE_CB_OPTION (ProcessEnvironmentOption);
145147
146148static bool IsSnapshottingForPrecompilation () {
147- return (snapshot_kind == kAppAOTAssembly ) || (snapshot_kind == kAppAOTElf ) ||
149+ return (snapshot_kind == kAppAOTBlobs ) ||
150+ (snapshot_kind == kAppAOTAssembly ) || (snapshot_kind == kAppAOTElf ) ||
148151 (snapshot_kind == kVMAOTAssembly );
149152}
150153
@@ -283,6 +286,34 @@ static int ParseArguments(int argc,
283286 }
284287 break ;
285288 }
289+ case kAppAOTBlobs : {
290+ if ((blobs_container_filename == NULL ) &&
291+ ((vm_snapshot_data_filename == NULL ) ||
292+ (vm_snapshot_instructions_filename == NULL ) ||
293+ (isolate_snapshot_data_filename == NULL ) ||
294+ (isolate_snapshot_instructions_filename == NULL ))) {
295+ Syslog::PrintErr (
296+ " Building an AOT snapshot as blobs requires specifying output "
297+ " file for --blobs_container_filename or "
298+ " files for --vm_snapshot_data, --vm_snapshot_instructions, "
299+ " --isolate_snapshot_data and --isolate_snapshot_instructions.\n\n " );
300+ return -1 ;
301+ }
302+ if ((blobs_container_filename != NULL ) &&
303+ ((vm_snapshot_data_filename != NULL ) ||
304+ (vm_snapshot_instructions_filename != NULL ) ||
305+ (isolate_snapshot_data_filename != NULL ) ||
306+ (isolate_snapshot_instructions_filename != NULL ))) {
307+ Syslog::PrintErr (
308+ " Building an AOT snapshot as blobs requires specifying output "
309+ " file for --blobs_container_filename or "
310+ " files for --vm_snapshot_data, --vm_snapshot_instructions, "
311+ " --isolate_snapshot_data and --isolate_snapshot_instructions"
312+ " not both.\n\n " );
313+ return -1 ;
314+ }
315+ break ;
316+ }
286317 case kAppAOTElf : {
287318 if (elf_filename == NULL ) {
288319 Syslog::PrintErr (
@@ -638,6 +669,54 @@ static void CreateAndWritePrecompiledSnapshot() {
638669 " To avoid this, use --strip to remove it and "
639670 " --save-debugging-info=<...> to save it to a separate file.\n " );
640671 }
672+ } else if (snapshot_kind == kAppAOTBlobs ) {
673+ Syslog::PrintErr (
674+ " WARNING: app-aot-blobs snapshots have been deprecated and support for "
675+ " generating them will be removed soon. Please use the app-aot-elf or "
676+ " app-aot-assembly snapshot kinds in conjunction with the portable ELF "
677+ " loader from //runtime/bin:elf_loader if necessary. See "
678+ " http://dartbug.com/38764 for more details.\n " );
679+
680+ uint8_t * vm_snapshot_data_buffer = NULL ;
681+ intptr_t vm_snapshot_data_size = 0 ;
682+ uint8_t * vm_snapshot_instructions_buffer = NULL ;
683+ intptr_t vm_snapshot_instructions_size = 0 ;
684+ uint8_t * isolate_snapshot_data_buffer = NULL ;
685+ intptr_t isolate_snapshot_data_size = 0 ;
686+ uint8_t * isolate_snapshot_instructions_buffer = NULL ;
687+ intptr_t isolate_snapshot_instructions_size = 0 ;
688+ File* debug_file = nullptr ;
689+ if (debugging_info_filename != nullptr ) {
690+ debug_file = OpenFile (debugging_info_filename);
691+ }
692+ result = Dart_CreateAppAOTSnapshotAsBlobs (
693+ &vm_snapshot_data_buffer, &vm_snapshot_data_size,
694+ &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size,
695+ &isolate_snapshot_data_buffer, &isolate_snapshot_data_size,
696+ &isolate_snapshot_instructions_buffer,
697+ &isolate_snapshot_instructions_size, StreamingWriteCallback,
698+ debug_file);
699+ if (debug_file != nullptr ) debug_file->Release ();
700+ CHECK_RESULT (result);
701+
702+ if (blobs_container_filename != NULL ) {
703+ Snapshot::WriteAppSnapshot (
704+ blobs_container_filename, vm_snapshot_data_buffer,
705+ vm_snapshot_data_size, vm_snapshot_instructions_buffer,
706+ vm_snapshot_instructions_size, isolate_snapshot_data_buffer,
707+ isolate_snapshot_data_size, isolate_snapshot_instructions_buffer,
708+ isolate_snapshot_instructions_size);
709+ } else {
710+ WriteFile (vm_snapshot_data_filename, vm_snapshot_data_buffer,
711+ vm_snapshot_data_size);
712+ WriteFile (vm_snapshot_instructions_filename,
713+ vm_snapshot_instructions_buffer, vm_snapshot_instructions_size);
714+ WriteFile (isolate_snapshot_data_filename, isolate_snapshot_data_buffer,
715+ isolate_snapshot_data_size);
716+ WriteFile (isolate_snapshot_instructions_filename,
717+ isolate_snapshot_instructions_buffer,
718+ isolate_snapshot_instructions_size);
719+ }
641720 } else {
642721 UNREACHABLE ();
643722 }
@@ -747,6 +826,7 @@ static int CreateIsolateAndSnapshot(const CommandLineOptions& inputs) {
747826 CreateAndWriteAppJITSnapshot ();
748827 break ;
749828 case kAppAOTAssembly :
829+ case kAppAOTBlobs :
750830 case kAppAOTElf :
751831 CreateAndWritePrecompiledSnapshot ();
752832 break ;
0 commit comments