summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context.cc
diff options
context:
space:
mode:
author David Brazdil <dbrazdil@google.com> 2019-03-25 17:04:47 +0000
committer David Brazdil <dbrazdil@google.com> 2019-03-26 10:13:05 +0000
commit1a1398ec15accbd905d802e1391c8efbd2d80f98 (patch)
treec058d429874230eb71c2eb5e136426957720c6c6 /runtime/class_loader_context.cc
parentf57f2ed8c3f75c8d8c2c051f2961ca4e8330a698 (diff)
InMemoryDexClassLoader in ClassLoaderContext follow-up
Address follow-up comments on Ic64065819018a1e56dee0f65405d26beb8fd7bbd. In particular, the classpath elements of IMC are replaced with "<unknown>" magic value to make it clear that the dex location is bogus, and a clarifying comment is added. Test: m test-art-gtest-class_loader_context_test Bug: 72131483 Change-Id: I0225c288a07af589a3f3d85a69ef908eeab38cb2
Diffstat (limited to 'runtime/class_loader_context.cc')
-rw-r--r--runtime/class_loader_context.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 165b42d9bb..8949f5a324 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -53,6 +53,7 @@ static constexpr char kClassLoaderSharedLibrarySeparator = '#';
static constexpr char kClassLoaderSeparator = ';';
static constexpr char kClasspathSeparator = ':';
static constexpr char kDexFileChecksumSeparator = '*';
+static constexpr char kInMemoryDexClassLoaderClasspathMagic[] = "<unknown>";
ClassLoaderContext::ClassLoaderContext()
: special_shared_library_(false),
@@ -169,6 +170,8 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
// Checksums are not provided and dex locations themselves have no meaning
// (although we keep them in the spec to simplify parsing). Treat this as
// an unknown class loader.
+ // We can hit this case if dex2oat is invoked with a spec containing IMC.
+ // Because the dex file data is only available at runtime, we cannot proceed.
return nullptr;
}
}
@@ -197,6 +200,7 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
std::unique_ptr<ClassLoaderInfo> info(new ClassLoaderInfo(class_loader_type));
if (!parse_checksums) {
+ DCHECK(class_loader_type != kInMemoryDexClassLoader);
Split(classpath, kClasspathSeparator, &info->classpath);
} else {
std::vector<std::string> classpath_elements;
@@ -211,6 +215,10 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
if (!android::base::ParseUint(dex_file_with_checksum[1].c_str(), &checksum)) {
return nullptr;
}
+ if ((class_loader_type == kInMemoryDexClassLoader) &&
+ (dex_file_with_checksum[0] != kInMemoryDexClassLoaderClasspathMagic)) {
+ return nullptr;
+ }
info->classpath.push_back(dex_file_with_checksum[0]);
info->checksums.push_back(checksum);
@@ -416,6 +424,8 @@ bool ClassLoaderContext::OpenDexFiles(InstructionSet isa,
while (!work_list.empty()) {
ClassLoaderInfo* info = work_list.back();
work_list.pop_back();
+ DCHECK(info->type != kInMemoryDexClassLoader) << __FUNCTION__ << " not supported for IMC";
+
size_t opened_dex_files_index = info->opened_dex_files.size();
for (const std::string& cp_elem : info->classpath) {
// If path is relative, append it to the provided base directory.
@@ -624,8 +634,10 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info,
if (k > 0) {
out << kClasspathSeparator;
}
- // Find paths that were relative and convert them back from absolute.
- if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) {
+ if (info.type == kInMemoryDexClassLoader) {
+ out << kInMemoryDexClassLoaderClasspathMagic;
+ } else if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) {
+ // Find paths that were relative and convert them back from absolute.
out << location.substr(base_dir.length() + 1).c_str();
} else {
out << location.c_str();