Do not allow input-vdex with dexlayout.
input-vdex and dexlayout are incompatible with each other.
bug: 36084905
bug: 36076104
bug: 36059948
bug: 35872504
Test: device boots, vdex works on OTA, input-vdex is not passed
for speed-profile.
Change-Id: I630c90acf0a8f49f50b7909e2dec995dd4a4d13f
diff --git a/compiler/dex/dex_to_dex_decompiler.cc b/compiler/dex/dex_to_dex_decompiler.cc
index 5360103..85d5784 100644
--- a/compiler/dex/dex_to_dex_decompiler.cc
+++ b/compiler/dex/dex_to_dex_decompiler.cc
@@ -185,7 +185,7 @@
}
if (quickened_info_ptr_ != quickened_info_end_) {
- LOG(ERROR) << "Failed to use all values in quickening info."
+ LOG(FATAL) << "Failed to use all values in quickening info."
<< " Actual: " << std::hex << quickened_info_ptr_
<< " Expected: " << quickened_info_end_;
return false;
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 057e3c9..9950987 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -480,7 +480,9 @@
DCHECK(!it.HasNext());
}
}
- DCHECK_EQ(quickening_info_ptr, quickening_info_end) << "Failed to use all quickening info";
+ if (quickening_info_ptr != quickening_info_end) {
+ LOG(FATAL) << "Failed to use all quickening info";
+ }
}
void CompilerDriver::CompileAll(jobject class_loader,
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index 43f606a..afcdf5e 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -2270,28 +2270,11 @@
/* verify */ true,
/* verify_checksum */ true,
&error_msg);
- } else if (oat_dex_file->source_.IsRawFile()) {
+ } else {
+ CHECK(oat_dex_file->source_.IsRawFile())
+ << static_cast<size_t>(oat_dex_file->source_.GetType());
File* raw_file = oat_dex_file->source_.GetRawFile();
dex_file = DexFile::OpenDex(raw_file->Fd(), location, /* verify_checksum */ true, &error_msg);
- } else {
- // The source data is a vdex file.
- CHECK(oat_dex_file->source_.IsRawData())
- << static_cast<size_t>(oat_dex_file->source_.GetType());
- const uint8_t* raw_dex_file = oat_dex_file->source_.GetRawData();
- // Note: The raw data has already been checked to contain the header
- // and all the data that the header specifies as the file size.
- DCHECK(raw_dex_file != nullptr);
- DCHECK(ValidateDexFileHeader(raw_dex_file, oat_dex_file->GetLocation()));
- const UnalignedDexFileHeader* header = AsUnalignedDexFileHeader(raw_dex_file);
- // Since the source may have had its layout changed, don't verify the checksum.
- dex_file = DexFile::Open(raw_dex_file,
- header->file_size_,
- location,
- oat_dex_file->dex_file_location_checksum_,
- nullptr,
- /* verify */ true,
- /* verify_checksum */ false,
- &error_msg);
}
if (dex_file == nullptr) {
LOG(ERROR) << "Failed to open dex file for layout: " << error_msg;
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 2684f3d..3fa30fa 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2100,6 +2100,10 @@
return DoProfileGuidedOptimizations();
}
+ bool HasInputVdexFile() const {
+ return input_vdex_file_ != nullptr || input_vdex_fd_ != -1 || !input_vdex_.empty();
+ }
+
bool LoadProfile() {
DCHECK(UseProfile());
@@ -2885,6 +2889,13 @@
}
}
+ if (dex2oat->DoDexLayoutOptimizations()) {
+ if (dex2oat->HasInputVdexFile()) {
+ LOG(ERROR) << "Dexlayout is incompatible with an input VDEX";
+ return EXIT_FAILURE;
+ }
+ }
+
art::MemMap::Init(); // For ZipEntry::ExtractToMemMap, and vdex.
// Check early that the result of compilation can be written
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index e7277bc..289b8ab 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -604,7 +604,8 @@
const std::string& app_image_file_name,
bool use_fd,
size_t num_profile_classes,
- const std::vector<std::string>& extra_args = {}) {
+ const std::vector<std::string>& extra_args = {},
+ bool expect_success = true) {
const std::string profile_location = GetScratchDir() + "/primary.prof";
const char* location = dex_location.c_str();
std::string error_msg;
@@ -631,7 +632,7 @@
odex_location,
CompilerFilter::kSpeedProfile,
copy,
- /* expect_success */ true,
+ expect_success,
use_fd);
if (app_image_file != nullptr) {
ASSERT_EQ(app_image_file->FlushCloseOrErase(), 0) << "Could not flush and close art file";
@@ -709,6 +710,7 @@
EXPECT_GT(vdex_file1->GetLength(), 0u);
}
{
+ // Test that vdex and dexlayout fail gracefully.
std::string input_vdex = StringPrintf("--input-vdex-fd=%d", vdex_file1->Fd());
std::string output_vdex = StringPrintf("--output-vdex-fd=%d", vdex_file2.GetFd());
CompileProfileOdex(dex_location,
@@ -716,13 +718,13 @@
app_image_file_name,
/* use_fd */ true,
/* num_profile_classes */ 1,
- { input_vdex, output_vdex });
- EXPECT_GT(vdex_file2.GetFile()->GetLength(), 0u);
+ { input_vdex, output_vdex },
+ /* expect_success */ false);
+ EXPECT_EQ(vdex_file2.GetFile()->GetLength(), 0u);
}
ASSERT_EQ(vdex_file1->FlushCloseOrErase(), 0) << "Could not flush and close vdex file";
CheckValidity();
- ASSERT_TRUE(success_);
- CheckResult(dex_location, odex_location, app_image_file_name);
+ ASSERT_FALSE(success_);
}
void CheckResult(const std::string& dex_location,
diff --git a/runtime/vdex_file.h b/runtime/vdex_file.h
index 7daf2f8..5048bad 100644
--- a/runtime/vdex_file.h
+++ b/runtime/vdex_file.h
@@ -61,7 +61,7 @@
private:
static constexpr uint8_t kVdexMagic[] = { 'v', 'd', 'e', 'x' };
- static constexpr uint8_t kVdexVersion[] = { '0', '0', '3', '\0' }; // Remove verify-profile
+ static constexpr uint8_t kVdexVersion[] = { '0', '0', '4', '\0' }; // dexlayout incompatibility
uint8_t magic_[4];
uint8_t version_[4];