Skip to content

Commit cd66003

Browse files
a-sivaCommit Queue
authored and
Commit Queue
committed
Fix snapshot sniffing code to give better error messages.
TEST=ci Change-Id: If5097c74e7e4f85de2ca8cfc2cab3283f8328ae3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402202 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
1 parent 0d63c97 commit cd66003

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

runtime/bin/main_impl.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,10 +1296,22 @@ void main(int argc, char** argv) {
12961296
script_name);
12971297
Platform::Exit(kErrorExitCode);
12981298
}
1299+
if (app_snapshot->IsJIT() && Dart_IsPrecompiledRuntime()) {
1300+
Syslog::PrintErr(
1301+
"%s is a JIT snapshot, it cannot be run with 'dartaotruntime'\n",
1302+
script_name);
1303+
Platform::Exit(kErrorExitCode);
1304+
}
12991305
vm_run_app_snapshot = true;
13001306
app_snapshot->SetBuffers(&vm_snapshot_data, &vm_snapshot_instructions,
13011307
&app_isolate_snapshot_data,
13021308
&app_isolate_snapshot_instructions);
1309+
} else if (app_snapshot == nullptr && Dart_IsPrecompiledRuntime()) {
1310+
Syslog::PrintErr(
1311+
"%s is not an AOT snapshot,"
1312+
" it cannot be run with 'dartaotruntime'\n",
1313+
script_name);
1314+
Platform::Exit(kErrorExitCode);
13031315
}
13041316
};
13051317

runtime/bin/snapshot_utils.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class DummySnapshot : public AppSnapshot {
4848

4949
private:
5050
};
51-
#endif // !defined(DART_PRECOMPILED_RUNTIME)
5251

5352
class MappedAppSnapshot : public AppSnapshot {
5453
public:
@@ -143,6 +142,7 @@ static AppSnapshot* TryReadAppSnapshotBlobs(const char* script_name,
143142
nullptr, nullptr, isolate_data_mapping, isolate_instr_mapping);
144143
return app_snapshot;
145144
}
145+
#endif // !defined(DART_PRECOMPILED_RUNTIME)
146146

147147
#if defined(DART_PRECOMPILED_RUNTIME)
148148
class ElfAppSnapshot : public AppSnapshot {
@@ -594,10 +594,6 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
594594
}
595595
DartUtils::MagicNumber magic_number =
596596
DartUtils::SniffForMagicNumber(header, sizeof(header));
597-
if (magic_number == DartUtils::kAppJITMagicNumber) {
598-
// Return the JIT snapshot.
599-
return TryReadAppSnapshotBlobs(script_name, file);
600-
}
601597
#if defined(DART_PRECOMPILED_RUNTIME)
602598
if (!DartUtils::IsAotMagicNumber(magic_number)) {
603599
return nullptr;
@@ -623,6 +619,10 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
623619
return TryReadAppSnapshotElf(script_name, /*file_offset=*/0,
624620
force_load_elf_from_memory);
625621
#else
622+
if (magic_number == DartUtils::kAppJITMagicNumber) {
623+
// Return the JIT snapshot.
624+
return TryReadAppSnapshotBlobs(script_name, file);
625+
}
626626
// We create a dummy snapshot object just to remember the type which
627627
// has already been identified by sniffing the magic number.
628628
return new DummySnapshot(magic_number);

0 commit comments

Comments
 (0)