summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2023-08-10 15:36:38 +0100
committer David Srbecky <dsrbecky@google.com> 2023-08-31 14:14:09 +0100
commite423e35dbd0915e19b8938bc6440955cda70caf9 (patch)
treecf86018120429e471ee539b61b88944ca88ce5e0
parent33d57ac6d1be2127bc31fb55a5054ac84bb7d78d (diff)
Cleanup: Use File instead of file descriptor for boot class path
Test: ./art/test.py -b --host --64 Change-Id: I734b156389486b7593c049915739dc9fbf8ea30f
-rw-r--r--dex2oat/dex2oat_image_test.cc8
-rw-r--r--oatdump/oatdump.cc2
-rw-r--r--runtime/gc/heap.cc28
-rw-r--r--runtime/gc/heap.h13
-rw-r--r--runtime/gc/space/image_space.cc151
-rw-r--r--runtime/gc/space/image_space.h34
-rw-r--r--runtime/gc/space/image_space_test.cc10
-rw-r--r--runtime/interpreter/unstarted_runtime.cc15
-rw-r--r--runtime/oat_file.cc69
-rw-r--r--runtime/oat_file.h24
-rw-r--r--runtime/oat_file_assistant.cc2
-rw-r--r--runtime/oat_file_assistant_context.cc28
-rw-r--r--runtime/oat_file_assistant_context.h2
-rw-r--r--runtime/oat_file_assistant_test.cc6
-rw-r--r--runtime/runtime.cc74
-rw-r--r--runtime/runtime.h26
16 files changed, 254 insertions, 238 deletions
diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc
index 507cd541d2..7556460adf 100644
--- a/dex2oat/dex2oat_image_test.cc
+++ b/dex2oat/dex2oat_image_test.cc
@@ -424,10 +424,10 @@ TEST_F(Dex2oatImageTest, TestExtension) {
return gc::space::ImageSpace::LoadBootImage(
/*boot_class_path=*/boot_class_path,
/*boot_class_path_locations=*/libcore_dex_files,
- /*boot_class_path_fds=*/std::vector<int>(),
- /*boot_class_path_image_fds=*/std::vector<int>(),
- /*boot_class_path_vdex_fds=*/std::vector<int>(),
- /*boot_class_path_oat_fds=*/std::vector<int>(),
+ /*boot_class_path_files=*/{},
+ /*boot_class_path_image_files=*/{},
+ /*boot_class_path_vdex_files=*/{},
+ /*boot_class_path_oat_files=*/{},
android::base::Split(image_location, ":"),
kRuntimeISA,
relocate,
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 06a3ac8137..512fe335fe 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -2474,7 +2474,7 @@ static std::unique_ptr<OatFile> OpenOat(const std::string& oat_filename,
/*executable=*/false,
/*low_4gb=*/false,
dex_filenames,
- /*dex_fds=*/ArrayRef<const int>(),
+ /*dex_files=*/{},
/*reservation=*/nullptr,
error_msg));
}
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index a5cfb422ef..eabe692d7e 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -272,10 +272,10 @@ Heap::Heap(size_t initial_size,
size_t non_moving_space_capacity,
const std::vector<std::string>& boot_class_path,
const std::vector<std::string>& boot_class_path_locations,
- const std::vector<int>& boot_class_path_fds,
- const std::vector<int>& boot_class_path_image_fds,
- const std::vector<int>& boot_class_path_vdex_fds,
- const std::vector<int>& boot_class_path_oat_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_oat_files,
const std::vector<std::string>& image_file_names,
const InstructionSet image_instruction_set,
CollectorType foreground_collector_type,
@@ -367,9 +367,11 @@ Heap::Heap(size_t initial_size,
* verification is enabled, we limit the size of allocation stacks to speed up their
* searching.
*/
- max_allocation_stack_size_(kGCALotMode ? kGcAlotAllocationStackSize
- : (kVerifyObjectSupport > kVerifyObjectModeFast) ? kVerifyObjectAllocationStackSize :
- kDefaultAllocationStackSize),
+ max_allocation_stack_size_(kGCALotMode
+ ? kGcAlotAllocationStackSize
+ : (kVerifyObjectSupport > kVerifyObjectModeFast)
+ ? kVerifyObjectAllocationStackSize
+ : kDefaultAllocationStackSize),
current_allocator_(kAllocatorTypeDlMalloc),
current_non_moving_allocator_(kAllocatorTypeNonMoving),
bump_pointer_space_(nullptr),
@@ -407,8 +409,8 @@ Heap::Heap(size_t initial_size,
gc_count_last_window_(0U),
blocking_gc_count_last_window_(0U),
gc_count_rate_histogram_("gc count rate histogram", 1U, kGcCountRateMaxBucketCount),
- blocking_gc_count_rate_histogram_("blocking gc count rate histogram", 1U,
- kGcCountRateMaxBucketCount),
+ blocking_gc_count_rate_histogram_(
+ "blocking gc count rate histogram", 1U, kGcCountRateMaxBucketCount),
alloc_tracking_enabled_(false),
alloc_record_depth_(AllocRecordObjectMap::kDefaultAllocStackDepth),
backtrace_lock_(nullptr),
@@ -493,10 +495,10 @@ Heap::Heap(size_t initial_size,
MemMap heap_reservation;
if (space::ImageSpace::LoadBootImage(boot_class_path,
boot_class_path_locations,
- boot_class_path_fds,
- boot_class_path_image_fds,
- boot_class_path_vdex_fds,
- boot_class_path_oat_fds,
+ boot_class_path_files,
+ boot_class_path_image_files,
+ boot_class_path_vdex_files,
+ boot_class_path_oat_files,
image_file_names,
image_instruction_set,
runtime->ShouldRelocate(),
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 7656e73b50..98680ef418 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -17,18 +17,19 @@
#ifndef ART_RUNTIME_GC_HEAP_H_
#define ART_RUNTIME_GC_HEAP_H_
+#include <android-base/logging.h>
+
#include <iosfwd>
#include <string>
#include <unordered_set>
#include <vector>
-#include <android-base/logging.h>
-
#include "allocator_type.h"
#include "base/atomic.h"
#include "base/histogram.h"
#include "base/macros.h"
#include "base/mutex.h"
+#include "base/os.h"
#include "base/runtime_debug.h"
#include "base/safe_map.h"
#include "base/time_utils.h"
@@ -200,10 +201,10 @@ class Heap {
size_t non_moving_space_capacity,
const std::vector<std::string>& boot_class_path,
const std::vector<std::string>& boot_class_path_locations,
- const std::vector<int>& boot_class_path_fds,
- const std::vector<int>& boot_class_path_image_fds,
- const std::vector<int>& boot_class_path_vdex_fds,
- const std::vector<int>& boot_class_path_oat_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_oat_files,
const std::vector<std::string>& image_file_names,
InstructionSet image_instruction_set,
CollectorType foreground_collector_type,
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 98bf3223c7..003a319292 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include <array>
#include <memory>
#include <optional>
#include <random>
@@ -1738,16 +1739,18 @@ bool ImageSpace::BootImageLayout::ValidateOatFile(
std::string art_location = ExpandLocation(base_location, bcp_index);
std::string oat_filename = ImageHeader::GetOatLocationFromImageLocation(art_filename);
std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(art_location);
- int oat_fd =
- bcp_index < boot_class_path_oat_fds_.size() ? boot_class_path_oat_fds_[bcp_index] : -1;
- int vdex_fd =
- bcp_index < boot_class_path_vdex_fds_.size() ? boot_class_path_vdex_fds_[bcp_index] : -1;
+ int oat_fd = bcp_index < boot_class_path_oat_files_.size()
+ ? boot_class_path_oat_files_[bcp_index].Fd()
+ : -1;
+ int vdex_fd = bcp_index < boot_class_path_vdex_files_.size()
+ ? boot_class_path_vdex_files_[bcp_index].Fd()
+ : -1;
auto dex_filenames =
ArrayRef<const std::string>(boot_class_path_).SubArray(bcp_index, component_count);
- auto dex_fds =
- bcp_index + component_count < boot_class_path_fds_.size() ?
- ArrayRef<const int>(boot_class_path_fds_).SubArray(bcp_index, component_count) :
- ArrayRef<const int>();
+ ArrayRef<File> dex_files =
+ bcp_index + component_count < boot_class_path_files_.size() ?
+ ArrayRef<File>(boot_class_path_files_).SubArray(bcp_index, component_count) :
+ ArrayRef<File>();
// We open the oat file here only for validating that it's up-to-date. We don't open it as
// executable or mmap it to a reserved space. This `OatFile` object will be dropped after
// validation, and will not go into the `ImageSpace`.
@@ -1762,7 +1765,7 @@ bool ImageSpace::BootImageLayout::ValidateOatFile(
/*executable=*/ false,
/*low_4gb=*/ false,
dex_filenames,
- dex_fds,
+ dex_files,
/*reservation=*/ nullptr,
error_msg));
} else {
@@ -1773,7 +1776,7 @@ bool ImageSpace::BootImageLayout::ValidateOatFile(
/*executable=*/ false,
/*low_4gb=*/ false,
dex_filenames,
- dex_fds,
+ dex_files,
/*reservation=*/ nullptr,
error_msg));
}
@@ -1784,7 +1787,8 @@ bool ImageSpace::BootImageLayout::ValidateOatFile(
error_msg->c_str());
return false;
}
- if (!ImageSpace::ValidateOatFile(*oat_file, error_msg, dex_filenames, dex_fds, apex_versions_)) {
+ if (!ImageSpace::ValidateOatFile(
+ *oat_file, error_msg, dex_filenames, dex_files, apex_versions_)) {
return false;
}
return true;
@@ -1798,9 +1802,9 @@ bool ImageSpace::BootImageLayout::ReadHeader(const std::string& base_location,
DCHECK_LT(bcp_index, boot_class_path_.size());
std::string actual_filename = ExpandLocation(base_filename, bcp_index);
- int bcp_image_fd = bcp_index < boot_class_path_image_fds_.size()
- ? boot_class_path_image_fds_[bcp_index]
- : -1;
+ int bcp_image_fd = bcp_index < boot_class_path_image_files_.size() ?
+ boot_class_path_image_files_[bcp_index].Fd() :
+ -1;
ImageHeader header;
// When BCP image is provided as FD, it needs to be dup'ed (since it's stored in unique_fd) so
// that it can later be used in LoadComponents.
@@ -2202,10 +2206,10 @@ class ImageSpace::BootImageLoader {
// `apex_versions` is created from `Runtime::GetApexVersions` and must outlive this instance.
BootImageLoader(const std::vector<std::string>& boot_class_path,
const std::vector<std::string>& boot_class_path_locations,
- const std::vector<int>& boot_class_path_fds,
- const std::vector<int>& boot_class_path_image_fds,
- const std::vector<int>& boot_class_path_vdex_fds,
- const std::vector<int>& boot_class_path_oat_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_oat_files,
const std::vector<std::string>& image_locations,
InstructionSet image_isa,
bool relocate,
@@ -2213,10 +2217,10 @@ class ImageSpace::BootImageLoader {
const std::string* apex_versions)
: boot_class_path_(boot_class_path),
boot_class_path_locations_(boot_class_path_locations),
- boot_class_path_fds_(boot_class_path_fds),
- boot_class_path_image_fds_(boot_class_path_image_fds),
- boot_class_path_vdex_fds_(boot_class_path_vdex_fds),
- boot_class_path_oat_fds_(boot_class_path_oat_fds),
+ boot_class_path_files_(boot_class_path_files),
+ boot_class_path_image_files_(boot_class_path_image_files),
+ boot_class_path_vdex_files_(boot_class_path_vdex_files),
+ boot_class_path_oat_files_(boot_class_path_oat_files),
image_locations_(image_locations),
image_isa_(image_isa),
relocate_(relocate),
@@ -2228,10 +2232,10 @@ class ImageSpace::BootImageLoader {
BootImageLayout layout(image_locations_,
boot_class_path_,
boot_class_path_locations_,
- boot_class_path_fds_,
- boot_class_path_image_fds_,
- boot_class_path_vdex_fds_,
- boot_class_path_oat_fds_,
+ boot_class_path_files_,
+ boot_class_path_image_files_,
+ boot_class_path_vdex_files_,
+ boot_class_path_oat_files_,
apex_versions_);
std::string image_location = layout.GetPrimaryImageLocation();
std::string system_filename;
@@ -2834,12 +2838,12 @@ class ImageSpace::BootImageLoader {
android::base::unique_fd vdex_fd,
android::base::unique_fd oat_fd,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
+ ArrayRef<File> dex_files,
bool validate_oat_file,
ArrayRef<const std::unique_ptr<ImageSpace>> dependencies,
TimingLogger* logger,
- /*inout*/MemMap* image_reservation,
- /*out*/std::string* error_msg) {
+ /*inout*/ MemMap* image_reservation,
+ /*out*/ std::string* error_msg) {
// VerifyImageAllocations() will be called later in Runtime::Init()
// as some class roots like ArtMethod::java_lang_reflect_ArtMethod_
// and ArtField::java_lang_reflect_ArtField_, which are used from
@@ -2856,24 +2860,24 @@ class ImageSpace::BootImageLoader {
DCHECK_EQ(vdex_fd.get() != -1, oat_fd.get() != -1);
if (vdex_fd.get() == -1) {
- oat_file.reset(OatFile::Open(/*zip_fd=*/ -1,
+ oat_file.reset(OatFile::Open(/*zip_fd=*/-1,
oat_filename,
oat_location,
executable_,
- /*low_4gb=*/ false,
+ /*low_4gb=*/false,
dex_filenames,
- dex_fds,
+ dex_files,
image_reservation,
error_msg));
} else {
- oat_file.reset(OatFile::Open(/*zip_fd=*/ -1,
+ oat_file.reset(OatFile::Open(/*zip_fd=*/-1,
vdex_fd.get(),
oat_fd.get(),
oat_location,
executable_,
- /*low_4gb=*/ false,
+ /*low_4gb=*/false,
dex_filenames,
- dex_fds,
+ dex_files,
image_reservation,
error_msg));
// We no longer need the file descriptors and they will be closed by
@@ -3038,8 +3042,8 @@ class ImageSpace::BootImageLoader {
image_fd = std::move(chunk.art_fd);
} else {
size_t pos = chunk.start_index + i;
- int arg_image_fd = pos < boot_class_path_image_fds_.size() ? boot_class_path_image_fds_[pos]
- : -1;
+ int arg_image_fd =
+ pos < boot_class_path_image_files_.size() ? boot_class_path_image_files_[pos].Fd() : -1;
if (arg_image_fd >= 0) {
image_fd.reset(DupCloexec(arg_image_fd));
}
@@ -3110,8 +3114,10 @@ class ImageSpace::BootImageLoader {
size_t bcp_chunk_size = (chunk.image_space_count == 1u) ? chunk.component_count : 1u;
size_t pos = chunk.start_index + i;
- auto boot_class_path_fds = boot_class_path_fds_.empty() ? ArrayRef<const int>()
- : boot_class_path_fds_.SubArray(/*pos=*/ pos, bcp_chunk_size);
+ ArrayRef<File> boot_class_path_files =
+ boot_class_path_files_.empty() ?
+ ArrayRef<File>() :
+ boot_class_path_files_.SubArray(/*pos=*/pos, bcp_chunk_size);
// Select vdex and oat FD if any exists.
android::base::unique_fd vdex_fd;
@@ -3120,8 +3126,8 @@ class ImageSpace::BootImageLoader {
DCHECK_EQ(locations.size(), 1u);
vdex_fd = std::move(chunk.vdex_fd);
} else {
- int arg_vdex_fd = pos < boot_class_path_vdex_fds_.size() ? boot_class_path_vdex_fds_[pos]
- : -1;
+ int arg_vdex_fd =
+ pos < boot_class_path_vdex_files_.size() ? boot_class_path_vdex_files_[pos].Fd() : -1;
if (arg_vdex_fd >= 0) {
vdex_fd.reset(DupCloexec(arg_vdex_fd));
}
@@ -3130,8 +3136,8 @@ class ImageSpace::BootImageLoader {
DCHECK_EQ(locations.size(), 1u);
oat_fd = std::move(chunk.oat_fd);
} else {
- int arg_oat_fd = pos < boot_class_path_oat_fds_.size() ? boot_class_path_oat_fds_[pos]
- : -1;
+ int arg_oat_fd =
+ pos < boot_class_path_oat_files_.size() ? boot_class_path_oat_files_[pos].Fd() : -1;
if (arg_oat_fd >= 0) {
oat_fd.reset(DupCloexec(arg_oat_fd));
}
@@ -3140,8 +3146,8 @@ class ImageSpace::BootImageLoader {
if (!OpenOatFile(space,
std::move(vdex_fd),
std::move(oat_fd),
- boot_class_path_.SubArray(/*pos=*/ pos, bcp_chunk_size),
- boot_class_path_fds,
+ boot_class_path_.SubArray(/*pos=*/pos, bcp_chunk_size),
+ boot_class_path_files,
validate_oat_file,
dependencies,
logger,
@@ -3200,10 +3206,10 @@ class ImageSpace::BootImageLoader {
const ArrayRef<const std::string> boot_class_path_;
const ArrayRef<const std::string> boot_class_path_locations_;
- const ArrayRef<const int> boot_class_path_fds_;
- const ArrayRef<const int> boot_class_path_image_fds_;
- const ArrayRef<const int> boot_class_path_vdex_fds_;
- const ArrayRef<const int> boot_class_path_oat_fds_;
+ ArrayRef<File> boot_class_path_files_;
+ ArrayRef<File> boot_class_path_image_files_;
+ ArrayRef<File> boot_class_path_vdex_files_;
+ ArrayRef<File> boot_class_path_oat_files_;
const ArrayRef<const std::string> image_locations_;
const InstructionSet image_isa_;
const bool relocate_;
@@ -3223,10 +3229,10 @@ bool ImageSpace::BootImageLoader::LoadFromSystem(
BootImageLayout layout(image_locations_,
boot_class_path_,
boot_class_path_locations_,
- boot_class_path_fds_,
- boot_class_path_image_fds_,
- boot_class_path_vdex_fds_,
- boot_class_path_oat_fds_,
+ boot_class_path_files_,
+ boot_class_path_image_files_,
+ boot_class_path_vdex_files_,
+ boot_class_path_oat_files_,
apex_versions_);
if (!layout.LoadFromSystem(image_isa_, allow_in_memory_compilation, error_msg)) {
return false;
@@ -3257,10 +3263,10 @@ bool ImageSpace::IsBootClassPathOnDisk(InstructionSet image_isa) {
BootImageLayout layout(ArrayRef<const std::string>(runtime->GetImageLocations()),
ArrayRef<const std::string>(runtime->GetBootClassPath()),
ArrayRef<const std::string>(runtime->GetBootClassPathLocations()),
- ArrayRef<const int>(runtime->GetBootClassPathFds()),
- ArrayRef<const int>(runtime->GetBootClassPathImageFds()),
- ArrayRef<const int>(runtime->GetBootClassPathVdexFds()),
- ArrayRef<const int>(runtime->GetBootClassPathOatFds()),
+ runtime->GetBootClassPathFiles(),
+ runtime->GetBootClassPathImageFiles(),
+ runtime->GetBootClassPathVdexFiles(),
+ runtime->GetBootClassPathOatFiles(),
&runtime->GetApexVersions());
const std::string image_location = layout.GetPrimaryImageLocation();
std::unique_ptr<ImageHeader> image_header;
@@ -3282,10 +3288,10 @@ bool ImageSpace::IsBootClassPathOnDisk(InstructionSet image_isa) {
bool ImageSpace::LoadBootImage(const std::vector<std::string>& boot_class_path,
const std::vector<std::string>& boot_class_path_locations,
- const std::vector<int>& boot_class_path_fds,
- const std::vector<int>& boot_class_path_image_fds,
- const std::vector<int>& boot_class_path_vdex_fds,
- const std::vector<int>& boot_class_path_odex_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_odex_files,
const std::vector<std::string>& image_locations,
const InstructionSet image_isa,
bool relocate,
@@ -3309,10 +3315,10 @@ bool ImageSpace::LoadBootImage(const std::vector<std::string>& boot_class_path,
BootImageLoader loader(boot_class_path,
boot_class_path_locations,
- boot_class_path_fds,
- boot_class_path_image_fds,
- boot_class_path_vdex_fds,
- boot_class_path_odex_fds,
+ boot_class_path_files,
+ boot_class_path_image_files,
+ boot_class_path_vdex_files,
+ boot_class_path_odex_files,
image_locations,
image_isa,
relocate,
@@ -3428,17 +3434,13 @@ bool ImageSpace::ValidateApexVersions(const OatHeader& oat_header,
bool ImageSpace::ValidateOatFile(const OatFile& oat_file, std::string* error_msg) {
DCHECK(Runtime::Current() != nullptr);
- return ValidateOatFile(oat_file,
- error_msg,
- ArrayRef<const std::string>(),
- ArrayRef<const int>(),
- Runtime::Current()->GetApexVersions());
+ return ValidateOatFile(oat_file, error_msg, {}, {}, Runtime::Current()->GetApexVersions());
}
bool ImageSpace::ValidateOatFile(const OatFile& oat_file,
std::string* error_msg,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
+ ArrayRef<File> dex_files,
const std::string& apex_versions) {
if (!ValidateApexVersions(oat_file.GetOatHeader(),
apex_versions,
@@ -3464,7 +3466,8 @@ bool ImageSpace::ValidateOatFile(const OatFile& oat_file,
const std::string& dex_file_location = dex_filenames.empty() ?
oat_dex_files[i]->GetDexFileLocation() :
dex_filenames[dex_file_index];
- int dex_fd = dex_file_index < dex_fds.size() ? dex_fds[dex_file_index] : -1;
+ File no_file; // Invalid object.
+ File& dex_file = dex_file_index < dex_files.size() ? dex_files[dex_file_index] : no_file;
dex_file_index++;
if (DexFileLoader::IsMultiDexLocation(oat_dex_files[i]->GetDexFileLocation().c_str())) {
@@ -3474,10 +3477,8 @@ bool ImageSpace::ValidateOatFile(const OatFile& oat_file,
// Original checksum.
std::optional<uint32_t> dex_checksum;
- File file(dex_fd, /*check_usage=*/false);
- ArtDexFileLoader dex_loader(&file, dex_file_location);
+ ArtDexFileLoader dex_loader(&dex_file, dex_file_location);
bool ok = dex_loader.GetMultiDexChecksum(&dex_checksum, error_msg);
- file.Release(); // Don't close the file yet (we have only read the checksum).
if (!ok) {
*error_msg = StringPrintf(
"ValidateOatFile failed to get checksum of dex file '%s' "
diff --git a/runtime/gc/space/image_space.h b/runtime/gc/space/image_space.h
index 9ab2074cc2..5271489fc6 100644
--- a/runtime/gc/space/image_space.h
+++ b/runtime/gc/space/image_space.h
@@ -135,10 +135,10 @@ class ImageSpace : public MemMapSpace {
// extension is compiled only against the primary boot image.
static bool LoadBootImage(const std::vector<std::string>& boot_class_path,
const std::vector<std::string>& boot_class_path_locations,
- const std::vector<int>& boot_class_path_fds,
- const std::vector<int>& boot_class_path_image_fds,
- const std::vector<int>& boot_class_path_vdex_fds,
- const std::vector<int>& boot_class_path_oat_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_oat_files,
const std::vector<std::string>& image_locations,
const InstructionSet image_isa,
bool relocate,
@@ -290,7 +290,7 @@ class ImageSpace : public MemMapSpace {
static bool ValidateOatFile(const OatFile& oat_file,
std::string* error_msg,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
+ ArrayRef<File> dex_files,
const std::string& apex_versions);
// Return the end of the image which includes non-heap objects such as ArtMethods and ArtFields.
@@ -347,18 +347,18 @@ class ImageSpace : public MemMapSpace {
BootImageLayout(ArrayRef<const std::string> image_locations,
ArrayRef<const std::string> boot_class_path,
ArrayRef<const std::string> boot_class_path_locations,
- ArrayRef<const int> boot_class_path_fds,
- ArrayRef<const int> boot_class_path_image_fds,
- ArrayRef<const int> boot_class_path_vdex_fds,
- ArrayRef<const int> boot_class_path_oat_fds,
+ ArrayRef<File> boot_class_path_files,
+ ArrayRef<File> boot_class_path_image_files,
+ ArrayRef<File> boot_class_path_vdex_files,
+ ArrayRef<File> boot_class_path_oat_files,
const std::string* apex_versions)
: image_locations_(image_locations),
boot_class_path_(boot_class_path),
boot_class_path_locations_(boot_class_path_locations),
- boot_class_path_fds_(boot_class_path_fds),
- boot_class_path_image_fds_(boot_class_path_image_fds),
- boot_class_path_vdex_fds_(boot_class_path_vdex_fds),
- boot_class_path_oat_fds_(boot_class_path_oat_fds),
+ boot_class_path_files_(boot_class_path_files),
+ boot_class_path_image_files_(boot_class_path_image_files),
+ boot_class_path_vdex_files_(boot_class_path_vdex_files),
+ boot_class_path_oat_files_(boot_class_path_oat_files),
apex_versions_(*apex_versions) {}
std::string GetPrimaryImageLocation();
@@ -459,10 +459,10 @@ class ImageSpace : public MemMapSpace {
ArrayRef<const std::string> image_locations_;
ArrayRef<const std::string> boot_class_path_;
ArrayRef<const std::string> boot_class_path_locations_;
- ArrayRef<const int> boot_class_path_fds_;
- ArrayRef<const int> boot_class_path_image_fds_;
- ArrayRef<const int> boot_class_path_vdex_fds_;
- ArrayRef<const int> boot_class_path_oat_fds_;
+ ArrayRef<File> boot_class_path_files_;
+ ArrayRef<File> boot_class_path_image_files_;
+ ArrayRef<File> boot_class_path_vdex_files_;
+ ArrayRef<File> boot_class_path_oat_files_;
std::vector<ImageChunk> chunks_;
uint32_t base_address_ = 0u;
diff --git a/runtime/gc/space/image_space_test.cc b/runtime/gc/space/image_space_test.cc
index 2e5e678008..7e74015e12 100644
--- a/runtime/gc/space/image_space_test.cc
+++ b/runtime/gc/space/image_space_test.cc
@@ -132,10 +132,10 @@ TEST_F(ImageSpaceTest, StringDeduplication) {
return ImageSpace::LoadBootImage(
bcp,
bcp_locations,
- /*boot_class_path_fds=*/std::vector<int>(),
- /*boot_class_path_image_fds=*/std::vector<int>(),
- /*boot_class_path_vdex_fds=*/std::vector<int>(),
- /*boot_class_path_oat_fds=*/std::vector<int>(),
+ /*boot_class_path_files=*/{},
+ /*boot_class_path_image_files=*/{},
+ /*boot_class_path_vdex_files=*/{},
+ /*boot_class_path_oat_files=*/{},
full_image_locations,
kRuntimeISA,
/*relocate=*/false,
@@ -255,7 +255,7 @@ TEST_F(DexoptTest, ValidateOatFile) {
/*executable=*/false,
/*low_4gb=*/false,
ArrayRef<const std::string>(dex_filenames),
- /*dex_fds=*/ArrayRef<const int>(),
+ /*dex_fds=*/{},
/*reservation=*/nullptr,
&error_msg));
ASSERT_TRUE(oat2 != nullptr) << error_msg;
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 8d3d2d6a3d..608e6f3bc1 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -16,6 +16,8 @@
#include "unstarted_runtime.h"
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
@@ -25,15 +27,14 @@
#include <limits>
#include <locale>
-#include <android-base/logging.h>
-#include <android-base/stringprintf.h>
-
#include "art_method-inl.h"
#include "base/casts.h"
#include "base/enums.h"
#include "base/hash_map.h"
#include "base/macros.h"
+#include "base/os.h"
#include "base/quasi_atomic.h"
+#include "base/unix_file/fd_file.h"
#include "base/zip_archive.h"
#include "class_linker.h"
#include "common_throws.h"
@@ -574,17 +575,17 @@ static void GetResourceAsStream(Thread* self,
return;
}
- const std::vector<int>& boot_class_path_fds = Runtime::Current()->GetBootClassPathFds();
- DCHECK(boot_class_path_fds.empty() || boot_class_path_fds.size() == boot_class_path.size());
+ ArrayRef<File> boot_class_path_files = Runtime::Current()->GetBootClassPathFiles();
+ DCHECK(boot_class_path_files.empty() || boot_class_path_files.size() == boot_class_path.size());
MemMap mem_map;
size_t map_size;
std::string last_error_msg; // Only store the last message (we could concatenate).
- bool has_bcp_fds = !boot_class_path_fds.empty();
+ bool has_bcp_fds = !boot_class_path_files.empty();
for (size_t i = 0; i < boot_class_path.size(); ++i) {
const std::string& jar_file = boot_class_path[i];
- const int jar_fd = has_bcp_fds ? boot_class_path_fds[i] : -1;
+ const int jar_fd = has_bcp_fds ? boot_class_path_files[i].Fd() : -1;
mem_map = FindAndExtractEntry(jar_file, jar_fd, resource_cstr, &map_size, &last_error_msg);
if (mem_map.IsValid()) {
break;
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index ccfcc895dc..e875252d92 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -114,9 +114,9 @@ class OatFileBase : public OatFile {
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation, // Where to load if not null.
- /*out*/std::string* error_msg);
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation, // Where to load if not null.
+ /*out*/ std::string* error_msg);
template <typename kOatFileBaseSubType>
static OatFileBase* OpenOatFile(int zip_fd,
@@ -128,9 +128,9 @@ class OatFileBase : public OatFile {
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation, // Where to load if not null.
- /*out*/std::string* error_msg);
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation, // Where to load if not null.
+ /*out*/ std::string* error_msg);
protected:
OatFileBase(const std::string& filename, bool executable) : OatFile(filename, executable) {}
@@ -171,7 +171,7 @@ class OatFileBase : public OatFile {
bool Setup(int zip_fd,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
+ ArrayRef<File> dex_files,
std::string* error_msg);
bool Setup(const std::vector<const DexFile*>& dex_files, std::string* error_msg);
@@ -203,9 +203,9 @@ OatFileBase* OatFileBase::OpenOatFile(int zip_fd,
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation,
- /*out*/std::string* error_msg) {
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation,
+ /*out*/ std::string* error_msg) {
std::unique_ptr<OatFileBase> ret(new kOatFileBaseSubType(location, executable));
ret->PreLoad();
@@ -229,7 +229,7 @@ OatFileBase* OatFileBase::OpenOatFile(int zip_fd,
return nullptr;
}
- if (!ret->Setup(zip_fd, dex_filenames, dex_fds, error_msg)) {
+ if (!ret->Setup(zip_fd, dex_filenames, dex_files, error_msg)) {
return nullptr;
}
@@ -246,9 +246,9 @@ OatFileBase* OatFileBase::OpenOatFile(int zip_fd,
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation,
- /*out*/std::string* error_msg) {
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation,
+ /*out*/ std::string* error_msg) {
std::unique_ptr<OatFileBase> ret(new kOatFileBaseSubType(oat_location, executable));
if (!ret->Load(oat_fd,
@@ -270,7 +270,7 @@ OatFileBase* OatFileBase::OpenOatFile(int zip_fd,
return nullptr;
}
- if (!ret->Setup(zip_fd, dex_filenames, dex_fds, error_msg)) {
+ if (!ret->Setup(zip_fd, dex_filenames, dex_files, error_msg)) {
return nullptr;
}
@@ -574,7 +574,7 @@ bool OatFileBase::Setup(const std::vector<const DexFile*>& dex_files, std::strin
bool OatFileBase::Setup(int zip_fd,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
+ ArrayRef<File> dex_files,
std::string* error_msg) {
if (!GetOatHeader().IsValid()) {
std::string cause = GetOatHeader().GetValidationErrorMessage();
@@ -658,7 +658,8 @@ bool OatFileBase::Setup(int zip_fd,
std::string_view primary_location;
std::string_view primary_location_replacement;
- int dex_fd = -1;
+ File no_file;
+ File* dex_file = &no_file;
size_t dex_filenames_pos = 0u;
uint32_t dex_file_count = GetOatHeader().GetDexFileCount();
oat_dex_files_storage_.reserve(dex_file_count);
@@ -715,7 +716,7 @@ bool OatFileBase::Setup(int zip_fd,
return false;
}
primary_location_replacement = dex_filenames[dex_filenames_pos];
- dex_fd = dex_filenames_pos < dex_fds.size() ? dex_fds[dex_filenames_pos] : -1;
+ dex_file = dex_filenames_pos < dex_files.size() ? &dex_files[dex_filenames_pos] : &no_file;
++dex_filenames_pos;
}
}
@@ -809,7 +810,7 @@ bool OatFileBase::Setup(int zip_fd,
std::vector<std::unique_ptr<const DexFile>> new_dex_files;
// No dex files, load it from location.
bool loaded = false;
- CHECK(zip_fd == -1 || dex_fds.empty()); // Allow only the supported combinations.
+ CHECK(zip_fd == -1 || dex_files.empty()); // Allow only the supported combinations.
if (zip_fd != -1) {
File file(zip_fd, /*check_usage=*/false);
ArtDexFileLoader dex_file_loader(&file, dex_file_location);
@@ -817,15 +818,13 @@ bool OatFileBase::Setup(int zip_fd,
/*verify_checksum=*/false,
error_msg,
&new_dex_files);
- } else if (dex_fd != -1) {
+ } else if (dex_file->IsValid()) {
// Note that we assume dex_fds are backing by jars.
- File file(dex_fd, /*check_usage=*/false);
- ArtDexFileLoader dex_file_loader(&file, dex_file_location);
+ ArtDexFileLoader dex_file_loader(dex_file, dex_file_location);
loaded = dex_file_loader.Open(/*verify=*/false,
/*verify_checksum=*/false,
error_msg,
&new_dex_files);
- file.Release(); // Don't close the file.
} else {
ArtDexFileLoader dex_file_loader(dex_file_name.c_str(), dex_file_location);
loaded = dex_file_loader.Open(/*verify=*/false,
@@ -863,8 +862,8 @@ bool OatFileBase::Setup(int zip_fd,
dex_file_location.c_str());
return false;
}
- for (std::unique_ptr<const DexFile>& dex_file : new_dex_files) {
- external_dex_files_.push_back(std::move(dex_file));
+ for (std::unique_ptr<const DexFile>& dex_file_ptr : new_dex_files) {
+ external_dex_files_.push_back(std::move(dex_file_ptr));
}
}
// Defensively verify external dex file checksum. `OatFileAssistant`
@@ -1659,7 +1658,7 @@ bool ElfOatFile::InitializeFromElfFile(int zip_fd,
SetBegin(elf_file->Begin() + offset);
SetEnd(elf_file->Begin() + size + offset);
// Ignore the optional .bss section when opening non-executable.
- return Setup(zip_fd, dex_filenames, /*dex_fds=*/ArrayRef<const int>(), error_msg);
+ return Setup(zip_fd, dex_filenames, /*dex_fds=*/{}, error_msg);
}
bool ElfOatFile::Load(const std::string& elf_filename,
@@ -1930,9 +1929,9 @@ OatFile* OatFile::Open(int zip_fd,
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation,
- /*out*/std::string* error_msg) {
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation,
+ /*out*/ std::string* error_msg) {
ScopedTrace trace("Open oat file " + oat_location);
CHECK(!oat_filename.empty()) << oat_location;
CheckLocation(oat_location);
@@ -1957,7 +1956,7 @@ OatFile* OatFile::Open(int zip_fd,
executable,
low_4gb,
dex_filenames,
- dex_fds,
+ dex_files,
reservation,
error_msg);
if (with_dlopen != nullptr) {
@@ -1987,7 +1986,7 @@ OatFile* OatFile::Open(int zip_fd,
executable,
low_4gb,
dex_filenames,
- dex_fds,
+ dex_files,
reservation,
error_msg);
return with_internal;
@@ -2000,9 +1999,9 @@ OatFile* OatFile::Open(int zip_fd,
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation,
- /*out*/std::string* error_msg) {
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation,
+ /*out*/ std::string* error_msg) {
CHECK(!oat_location.empty()) << oat_location;
std::string vdex_location = GetVdexFilename(oat_location);
@@ -2016,7 +2015,7 @@ OatFile* OatFile::Open(int zip_fd,
executable,
low_4gb,
dex_filenames,
- dex_fds,
+ dex_files,
reservation,
error_msg);
return with_internal;
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 0fa740c1c2..8ad1ac0723 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -106,9 +106,9 @@ class OatFile {
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation, // Where to load if not null.
- /*out*/std::string* error_msg);
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation, // Where to load if not null.
+ /*out*/ std::string* error_msg);
// Helper overload that takes a single dex filename and no reservation.
static OatFile* Open(int zip_fd,
const std::string& filename,
@@ -122,9 +122,9 @@ class OatFile {
location,
executable,
low_4gb,
- ArrayRef<const std::string>(&dex_filename, /*size=*/ 1u),
- /*dex_fds=*/ ArrayRef<const int>(), // not currently supported
- /*reservation=*/ nullptr,
+ ArrayRef<const std::string>(&dex_filename, /*size=*/1u),
+ /*dex_files=*/{}, // not currently supported
+ /*reservation=*/nullptr,
error_msg);
}
// Helper overload that takes no dex filename and no reservation.
@@ -139,9 +139,9 @@ class OatFile {
location,
executable,
low_4gb,
- /*dex_filenames=*/ ArrayRef<const std::string>(),
- /*dex_fds=*/ ArrayRef<const int>(), // not currently supported
- /*reservation=*/ nullptr,
+ /*dex_filenames=*/{},
+ /*dex_files=*/{}, // not currently supported
+ /*reservation=*/nullptr,
error_msg);
}
@@ -155,9 +155,9 @@ class OatFile {
bool executable,
bool low_4gb,
ArrayRef<const std::string> dex_filenames,
- ArrayRef<const int> dex_fds,
- /*inout*/MemMap* reservation, // Where to load if not null.
- /*out*/std::string* error_msg);
+ ArrayRef<File> dex_files,
+ /*inout*/ MemMap* reservation, // Where to load if not null.
+ /*out*/ std::string* error_msg);
// Initialize OatFile instance from an already loaded VdexFile. This assumes
// the vdex does not have a dex section and accepts a vector of DexFiles separately.
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 1843cc8535..ed36df4091 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -1135,7 +1135,7 @@ const OatFile* OatFileAssistant::OatFileInfo::GetFile() {
executable,
/*low_4gb=*/false,
dex_locations,
- /*dex_fds=*/ArrayRef<const int>(),
+ /*dex_fds=*/{},
/*reservation=*/nullptr,
&error_msg));
}
diff --git a/runtime/oat_file_assistant_context.cc b/runtime/oat_file_assistant_context.cc
index e0e8a3d808..0e53c5cf38 100644
--- a/runtime/oat_file_assistant_context.cc
+++ b/runtime/oat_file_assistant_context.cc
@@ -44,8 +44,8 @@ OatFileAssistantContext::OatFileAssistantContext(
DCHECK_EQ(runtime_options_->boot_class_path.size(),
runtime_options_->boot_class_path_locations.size());
DCHECK_IMPLIES(
- runtime_options_->boot_class_path_fds != nullptr,
- runtime_options_->boot_class_path.size() == runtime_options_->boot_class_path_fds->size());
+ runtime_options_->boot_class_path_files.has_value(),
+ runtime_options_->boot_class_path.size() == runtime_options_->boot_class_path_files->size());
// Opening dex files and boot images require MemMap.
MemMap::Init();
}
@@ -56,9 +56,9 @@ OatFileAssistantContext::OatFileAssistantContext(Runtime* runtime)
.image_locations = runtime->GetImageLocations(),
.boot_class_path = runtime->GetBootClassPath(),
.boot_class_path_locations = runtime->GetBootClassPathLocations(),
- .boot_class_path_fds = !runtime->GetBootClassPathFds().empty() ?
- &runtime->GetBootClassPathFds() :
- nullptr,
+ .boot_class_path_files = !runtime->GetBootClassPathFiles().empty() ?
+ runtime->GetBootClassPathFiles() :
+ std::optional<ArrayRef<File>>(),
.deny_art_apex_data_files = runtime->DenyArtApexDataFiles(),
})) {
// Fetch boot image info from the runtime.
@@ -123,12 +123,10 @@ OatFileAssistantContext::GetBootImageInfoList(InstructionSet isa) {
ArrayRef<const std::string>(runtime_options_->image_locations),
ArrayRef<const std::string>(runtime_options_->boot_class_path),
ArrayRef<const std::string>(runtime_options_->boot_class_path_locations),
- runtime_options_->boot_class_path_fds != nullptr ?
- ArrayRef<const int>(*runtime_options_->boot_class_path_fds) :
- ArrayRef<const int>(),
- /*boot_class_path_image_fds=*/ArrayRef<const int>(),
- /*boot_class_path_vdex_fds=*/ArrayRef<const int>(),
- /*boot_class_path_oat_fds=*/ArrayRef<const int>(),
+ runtime_options_->boot_class_path_files.value_or(ArrayRef<File>()),
+ /*boot_class_path_image_files=*/{},
+ /*boot_class_path_vdex_files=*/{},
+ /*boot_class_path_oat_files=*/{},
&GetApexVersions());
std::string error_msg;
@@ -158,12 +156,12 @@ const std::vector<std::string>* OatFileAssistantContext::GetBcpChecksums(size_t
return &it->second;
}
- const std::vector<int>* fds = runtime_options_->boot_class_path_fds;
- File file(fds != nullptr ? (*fds)[bcp_index] : -1, /*check_usage=*/false);
- ArtDexFileLoader dex_loader(&file, runtime_options_->boot_class_path[bcp_index]);
+ std::optional<ArrayRef<File>> bcp_files = runtime_options_->boot_class_path_files;
+ File noFile;
+ File* file = bcp_files.has_value() ? &(*bcp_files)[bcp_index] : &noFile;
+ ArtDexFileLoader dex_loader(file, runtime_options_->boot_class_path[bcp_index]);
std::optional<uint32_t> checksum;
bool ok = dex_loader.GetMultiDexChecksum(&checksum, error_msg);
- file.Release(); // Don't close the file yet (we have only read the checksum).
if (!ok) {
return nullptr;
}
diff --git a/runtime/oat_file_assistant_context.h b/runtime/oat_file_assistant_context.h
index cc98c594d9..d1dd920800 100644
--- a/runtime/oat_file_assistant_context.h
+++ b/runtime/oat_file_assistant_context.h
@@ -44,7 +44,7 @@ class OatFileAssistantContext {
// Required. See `-Xbootclasspath-locations`.
const std::vector<std::string>& boot_class_path_locations;
// Optional. See `-Xbootclasspathfds`.
- const std::vector<int>* const boot_class_path_fds = nullptr;
+ std::optional<ArrayRef<File>> boot_class_path_files = {};
// Optional. See `-Xdeny-art-apex-data-files`.
const bool deny_art_apex_data_files = false;
};
diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc
index e162ec98e7..c1f2d3e674 100644
--- a/runtime/oat_file_assistant_test.cc
+++ b/runtime/oat_file_assistant_test.cc
@@ -190,9 +190,9 @@ class OatFileAssistantTest : public OatFileAssistantBaseTest,
.image_locations = runtime_->GetImageLocations(),
.boot_class_path = runtime_->GetBootClassPath(),
.boot_class_path_locations = runtime_->GetBootClassPathLocations(),
- .boot_class_path_fds = !runtime_->GetBootClassPathFds().empty() ?
- &runtime_->GetBootClassPathFds() :
- nullptr,
+ .boot_class_path_files = !runtime_->GetBootClassPathFiles().empty() ?
+ runtime_->GetBootClassPathFiles() :
+ std::optional<ArrayRef<File>>(),
.deny_art_apex_data_files = runtime_->DenyArtApexDataFiles(),
}));
}
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 5dbe73fb15..6b4f18851f 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1277,27 +1277,32 @@ void Runtime::StartDaemonThreads() {
static size_t OpenBootDexFiles(ArrayRef<const std::string> dex_filenames,
ArrayRef<const std::string> dex_locations,
- ArrayRef<const int> dex_fds,
- std::vector<std::unique_ptr<const DexFile>>* dex_files) {
- DCHECK(dex_files != nullptr) << "OpenDexFiles: out-param is nullptr";
+ ArrayRef<File> dex_files,
+ std::vector<std::unique_ptr<const DexFile>>* out_dex_files) {
+ DCHECK(out_dex_files != nullptr) << "OpenDexFiles: out-param is nullptr";
size_t failure_count = 0;
for (size_t i = 0; i < dex_filenames.size(); i++) {
const char* dex_filename = dex_filenames[i].c_str();
const char* dex_location = dex_locations[i].c_str();
- File file = File(i < dex_fds.size() ? dex_fds[i] : -1, /*check_usage=*/false);
+ File noFile;
+ File* file = i < dex_files.size() ? &dex_files[i] : &noFile;
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
- if (!OS::FileExists(dex_filename) && file.IsValid()) {
+ if (!OS::FileExists(dex_filename) && file->IsValid()) {
LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'";
continue;
}
bool verify = Runtime::Current()->IsVerificationEnabled();
- ArtDexFileLoader dex_file_loader(dex_filename, &file, dex_location);
- if (!dex_file_loader.Open(verify, kVerifyChecksum, &error_msg, dex_files)) {
- LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "' / fd " << file.Fd()
+ ArtDexFileLoader dex_file_loader(dex_filename, file, dex_location);
+ if (!dex_file_loader.Open(verify, kVerifyChecksum, &error_msg, out_dex_files)) {
+ LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "' / fd " << file->Fd()
<< ": " << error_msg;
++failure_count;
}
+ if (file->IsValid()) {
+ bool close_ok = file->Close();
+ DCHECK(close_ok) << dex_filename;
+ }
}
return failure_count;
}
@@ -1401,6 +1406,15 @@ void Runtime::ReloadAllFlags(const std::string& caller) {
FlagBase::ReloadAllFlags(caller);
}
+static std::vector<File> FileFdsToFileObjects(std::vector<int>&& fds) {
+ std::vector<File> files;
+ files.reserve(fds.size());
+ for (int fd : fds) {
+ files.push_back(File(fd, /*check_usage=*/false));
+ }
+ return files;
+}
+
bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
// (b/30160149): protect subprocesses from modifications to LD_LIBRARY_PATH, etc.
// Take a snapshot of the environment at the time the runtime was created, for use by Exec, etc.
@@ -1481,22 +1495,26 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
return false;
}
- boot_class_path_fds_ = runtime_options.ReleaseOrDefault(Opt::BootClassPathFds);
- if (!boot_class_path_fds_.empty() && boot_class_path_fds_.size() != boot_class_path_.size()) {
+ boot_class_path_files_ =
+ FileFdsToFileObjects(runtime_options.ReleaseOrDefault(Opt::BootClassPathFds));
+ if (!boot_class_path_files_.empty() && boot_class_path_files_.size() != boot_class_path_.size()) {
LOG(ERROR) << "Number of FDs specified in -Xbootclasspathfds must match the number of JARs in "
<< "-Xbootclasspath.";
return false;
}
- boot_class_path_image_fds_ = runtime_options.ReleaseOrDefault(Opt::BootClassPathImageFds);
- boot_class_path_vdex_fds_ = runtime_options.ReleaseOrDefault(Opt::BootClassPathVdexFds);
- boot_class_path_oat_fds_ = runtime_options.ReleaseOrDefault(Opt::BootClassPathOatFds);
- CHECK(boot_class_path_image_fds_.empty() ||
- boot_class_path_image_fds_.size() == boot_class_path_.size());
- CHECK(boot_class_path_vdex_fds_.empty() ||
- boot_class_path_vdex_fds_.size() == boot_class_path_.size());
- CHECK(boot_class_path_oat_fds_.empty() ||
- boot_class_path_oat_fds_.size() == boot_class_path_.size());
+ boot_class_path_image_files_ =
+ FileFdsToFileObjects(runtime_options.ReleaseOrDefault(Opt::BootClassPathImageFds));
+ boot_class_path_vdex_files_ =
+ FileFdsToFileObjects(runtime_options.ReleaseOrDefault(Opt::BootClassPathVdexFds));
+ boot_class_path_oat_files_ =
+ FileFdsToFileObjects(runtime_options.ReleaseOrDefault(Opt::BootClassPathOatFds));
+ CHECK(boot_class_path_image_files_.empty() ||
+ boot_class_path_image_files_.size() == boot_class_path_.size());
+ CHECK(boot_class_path_vdex_files_.empty() ||
+ boot_class_path_vdex_files_.size() == boot_class_path_.size());
+ CHECK(boot_class_path_oat_files_.empty() ||
+ boot_class_path_oat_files_.size() == boot_class_path_.size());
class_path_string_ = runtime_options.ReleaseOrDefault(Opt::ClassPath);
properties_ = runtime_options.ReleaseOrDefault(Opt::PropertiesList);
@@ -1639,10 +1657,10 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
runtime_options.GetOrDefault(Opt::NonMovingSpaceCapacity),
GetBootClassPath(),
GetBootClassPathLocations(),
- GetBootClassPathFds(),
- GetBootClassPathImageFds(),
- GetBootClassPathVdexFds(),
- GetBootClassPathOatFds(),
+ GetBootClassPathFiles(),
+ GetBootClassPathImageFiles(),
+ GetBootClassPathVdexFiles(),
+ GetBootClassPathOatFiles(),
image_locations_,
instruction_set_,
// Override the collector type to CC if the read barrier config.
@@ -1863,12 +1881,12 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
if (runtime_options.Exists(Opt::BootClassPathDexList)) {
extra_boot_class_path.swap(*runtime_options.GetOrDefault(Opt::BootClassPathDexList));
} else {
- ArrayRef<const int> bcp_fds = start < GetBootClassPathFds().size()
- ? ArrayRef<const int>(GetBootClassPathFds()).SubArray(start)
- : ArrayRef<const int>();
+ ArrayRef<File> bcp_files = start < GetBootClassPathFiles().size() ?
+ ArrayRef<File>(GetBootClassPathFiles()).SubArray(start) :
+ ArrayRef<File>();
OpenBootDexFiles(ArrayRef<const std::string>(GetBootClassPath()).SubArray(start),
ArrayRef<const std::string>(GetBootClassPathLocations()).SubArray(start),
- bcp_fds,
+ bcp_files,
&extra_boot_class_path);
}
class_linker_->AddExtraBootDexFiles(self, std::move(extra_boot_class_path));
@@ -1887,7 +1905,7 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
} else {
OpenBootDexFiles(ArrayRef<const std::string>(GetBootClassPath()),
ArrayRef<const std::string>(GetBootClassPathLocations()),
- ArrayRef<const int>(GetBootClassPathFds()),
+ ArrayRef<File>(GetBootClassPathFiles()),
&boot_class_path);
}
if (!class_linker_->InitWithoutImage(std::move(boot_class_path), &error_msg)) {
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 335ba546ab..feb9cb3b7f 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -33,7 +33,9 @@
#include "base/macros.h"
#include "base/mem_map.h"
#include "base/metrics/metrics.h"
+#include "base/os.h"
#include "base/string_view_cpp20.h"
+#include "base/unix_file/fd_file.h"
#include "compat_framework.h"
#include "deoptimization_kind.h"
#include "dex/dex_file_types.h"
@@ -347,21 +349,15 @@ class Runtime {
const std::string& location,
std::vector<std::unique_ptr<const art::DexFile>>&& dex_files);
- const std::vector<int>& GetBootClassPathFds() const {
- return boot_class_path_fds_;
- }
+ ArrayRef<File> GetBootClassPathFiles() { return ArrayRef<File>(boot_class_path_files_); }
- const std::vector<int>& GetBootClassPathImageFds() const {
- return boot_class_path_image_fds_;
+ ArrayRef<File> GetBootClassPathImageFiles() {
+ return ArrayRef<File>(boot_class_path_image_files_);
}
- const std::vector<int>& GetBootClassPathVdexFds() const {
- return boot_class_path_vdex_fds_;
- }
+ ArrayRef<File> GetBootClassPathVdexFiles() { return ArrayRef<File>(boot_class_path_vdex_files_); }
- const std::vector<int>& GetBootClassPathOatFds() const {
- return boot_class_path_oat_fds_;
- }
+ ArrayRef<File> GetBootClassPathOatFiles() { return ArrayRef<File>(boot_class_path_oat_files_); }
// Returns the checksums for the boot image, extensions and extra boot class path dex files,
// based on the image spaces and boot class path dex files loaded in memory.
@@ -1275,10 +1271,10 @@ class Runtime {
std::vector<std::string> boot_class_path_;
std::vector<std::string> boot_class_path_locations_;
std::string boot_class_path_checksums_;
- std::vector<int> boot_class_path_fds_;
- std::vector<int> boot_class_path_image_fds_;
- std::vector<int> boot_class_path_vdex_fds_;
- std::vector<int> boot_class_path_oat_fds_;
+ std::vector<File> boot_class_path_files_;
+ std::vector<File> boot_class_path_image_files_;
+ std::vector<File> boot_class_path_vdex_files_;
+ std::vector<File> boot_class_path_oat_files_;
std::string class_path_string_;
std::vector<std::string> properties_;