Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Make image test multi image
Browse files Browse the repository at this point in the history
Required for testing multi image layout in future CLs.

Bug: 28640955

Test: clean-oat-hos, test-art-host, device booting

Change-Id: I14809f56e711b4a87e01056c327eddbbd087f4ee
  • Loading branch information
Mathieu Chartier committed Sep 22, 2016
1 parent 949ce9c commit 25adcfb
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 179 deletions.
319 changes: 197 additions & 122 deletions compiler/image_test.cc

Large diffs are not rendered by default.

48 changes: 4 additions & 44 deletions dex2oat/dex2oat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,10 @@ class Dex2Oat FINAL {
if (IsBootImage() && image_filenames_.size() > 1) {
// If we're compiling the boot image, store the boot classpath into the Key-Value store.
// We need this for the multi-image case.
key_value_store_->Put(OatHeader::kBootClassPathKey, GetMultiImageBootClassPath());
key_value_store_->Put(OatHeader::kBootClassPathKey,
gc::space::ImageSpace::GetMultiImageBootClassPath(dex_locations_,
oat_filenames_,
image_filenames_));
}

if (!IsBootImage()) {
Expand Down Expand Up @@ -1960,49 +1963,6 @@ class Dex2Oat FINAL {
return result;
}

std::string GetMultiImageBootClassPath() {
DCHECK(IsBootImage());
DCHECK_GT(oat_filenames_.size(), 1u);
// If the image filename was adapted (e.g., for our tests), we need to change this here,
// too, but need to strip all path components (they will be re-established when loading).
std::ostringstream bootcp_oss;
bool first_bootcp = true;
for (size_t i = 0; i < dex_locations_.size(); ++i) {
if (!first_bootcp) {
bootcp_oss << ":";
}

std::string dex_loc = dex_locations_[i];
std::string image_filename = image_filenames_[i];

// Use the dex_loc path, but the image_filename name (without path elements).
size_t dex_last_slash = dex_loc.rfind('/');

// npos is max(size_t). That makes this a bit ugly.
size_t image_last_slash = image_filename.rfind('/');
size_t image_last_at = image_filename.rfind('@');
size_t image_last_sep = (image_last_slash == std::string::npos)
? image_last_at
: (image_last_at == std::string::npos)
? std::string::npos
: std::max(image_last_slash, image_last_at);
// Note: whenever image_last_sep == npos, +1 overflow means using the full string.

if (dex_last_slash == std::string::npos) {
dex_loc = image_filename.substr(image_last_sep + 1);
} else {
dex_loc = dex_loc.substr(0, dex_last_slash + 1) +
image_filename.substr(image_last_sep + 1);
}

// Image filenames already end with .art, no need to replace.

bootcp_oss << dex_loc;
first_bootcp = false;
}
return bootcp_oss.str();
}

std::vector<std::string> GetClassPathLocations(const std::string& class_path) {
// This function is used only for apps and for an app we have exactly one oat file.
DCHECK(!IsBootImage());
Expand Down
19 changes: 16 additions & 3 deletions runtime/common_runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ ScratchFile::ScratchFile() {
file_.reset(new File(fd, GetFilename(), true));
}

ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) {
filename_ = other.GetFilename();
filename_ += suffix;
ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix)
: ScratchFile(other.GetFilename() + suffix) {}

ScratchFile::ScratchFile(const std::string& filename) : filename_(filename) {
int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666);
CHECK_NE(-1, fd);
file_.reset(new File(fd, GetFilename(), true));
Expand All @@ -90,6 +91,18 @@ ScratchFile::ScratchFile(File* file) {
file_.reset(file);
}

ScratchFile::ScratchFile(ScratchFile&& other) {
*this = std::move(other);
}

ScratchFile& ScratchFile::operator=(ScratchFile&& other) {
if (GetFile() != other.GetFile()) {
std::swap(filename_, other.filename_);
std::swap(file_, other.file_);
}
return *this;
}

ScratchFile::~ScratchFile() {
Unlink();
}
Expand Down
6 changes: 6 additions & 0 deletions runtime/common_runtime_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ class ScratchFile {
public:
ScratchFile();

explicit ScratchFile(const std::string& filename);

ScratchFile(const ScratchFile& other, const char* suffix);

explicit ScratchFile(ScratchFile&& other);

ScratchFile& operator=(ScratchFile&& other);

explicit ScratchFile(File* file);

~ScratchFile();
Expand Down
6 changes: 3 additions & 3 deletions runtime/gc/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ Heap::Heap(size_t initial_size,
continue;
}

space::ImageSpace::CreateMultiImageLocations(image_file_name,
boot_classpath,
&image_file_names);
space::ImageSpace::ExtractMultiImageLocations(image_file_name,
boot_classpath,
&image_file_names);
}
} else {
LOG(ERROR) << "Could not create image space with image file '" << image_file_name << "'. "
Expand Down
51 changes: 48 additions & 3 deletions runtime/gc/space/image_space.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1508,9 +1508,54 @@ void ImageSpace::Dump(std::ostream& os) const {
<< ",name=\"" << GetName() << "\"]";
}

void ImageSpace::CreateMultiImageLocations(const std::string& input_image_file_name,
const std::string& boot_classpath,
std::vector<std::string>* image_file_names) {
std::string ImageSpace::GetMultiImageBootClassPath(
const std::vector<const char*>& dex_locations,
const std::vector<const char*>& oat_filenames,
const std::vector<const char*>& image_filenames) {
DCHECK_GT(oat_filenames.size(), 1u);
// If the image filename was adapted (e.g., for our tests), we need to change this here,
// too, but need to strip all path components (they will be re-established when loading).
std::ostringstream bootcp_oss;
bool first_bootcp = true;
for (size_t i = 0; i < dex_locations.size(); ++i) {
if (!first_bootcp) {
bootcp_oss << ":";
}

std::string dex_loc = dex_locations[i];
std::string image_filename = image_filenames[i];

// Use the dex_loc path, but the image_filename name (without path elements).
size_t dex_last_slash = dex_loc.rfind('/');

// npos is max(size_t). That makes this a bit ugly.
size_t image_last_slash = image_filename.rfind('/');
size_t image_last_at = image_filename.rfind('@');
size_t image_last_sep = (image_last_slash == std::string::npos)
? image_last_at
: (image_last_at == std::string::npos)
? std::string::npos
: std::max(image_last_slash, image_last_at);
// Note: whenever image_last_sep == npos, +1 overflow means using the full string.

if (dex_last_slash == std::string::npos) {
dex_loc = image_filename.substr(image_last_sep + 1);
} else {
dex_loc = dex_loc.substr(0, dex_last_slash + 1) +
image_filename.substr(image_last_sep + 1);
}

// Image filenames already end with .art, no need to replace.

bootcp_oss << dex_loc;
first_bootcp = false;
}
return bootcp_oss.str();
}

void ImageSpace::ExtractMultiImageLocations(const std::string& input_image_file_name,
const std::string& boot_classpath,
std::vector<std::string>* image_file_names) {
DCHECK(image_file_names != nullptr);

std::vector<std::string> images;
Expand Down
6 changes: 5 additions & 1 deletion runtime/gc/space/image_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ class ImageSpace : public MemMapSpace {

// Use the input image filename to adapt the names in the given boot classpath to establish
// complete locations for secondary images.
static void CreateMultiImageLocations(const std::string& input_image_file_name,
static void ExtractMultiImageLocations(const std::string& input_image_file_name,
const std::string& boot_classpath,
std::vector<std::string>* image_filenames);

static std::string GetMultiImageBootClassPath(const std::vector<const char*>& dex_locations,
const std::vector<const char*>& oat_filenames,
const std::vector<const char*>& image_filenames);

// Return the end of the image which includes non-heap objects such as ArtMethods and ArtFields.
uint8_t* GetImageEnd() const {
return Begin() + GetImageHeader().GetImageSize();
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ static bool OpenDexFilesFromImage(const std::string& image_location,
const OatHeader& boot_oat_header = oat_file->GetOatHeader();
const char* boot_cp = boot_oat_header.GetStoreValueByKey(OatHeader::kBootClassPathKey);
if (boot_cp != nullptr) {
gc::space::ImageSpace::CreateMultiImageLocations(image_locations[0],
boot_cp,
&image_locations);
gc::space::ImageSpace::ExtractMultiImageLocations(image_locations[0],
boot_cp,
&image_locations);
}
}

Expand Down

0 comments on commit 25adcfb

Please sign in to comment.